use of org.wso2.carbon.apimgt.core.auth.dto.ScopeInfo in project carbon-apimgt by wso2.
the class DefaultScopeRegistrationImpl method updateScope.
@Override
public boolean updateScope(Scope scope) throws KeyManagementException {
ScopeInfo scopeInfo = getScopeInfo(scope);
Response response = scopeRegistrationServiceStub.updateScope(scopeInfo, scope.getName());
if (response.status() == APIMgtConstants.HTTPStatusCodes.SC_200_OK) {
return true;
} else {
throw new KeyManagementException("Scope update failed", ExceptionCodes.INTERNAL_ERROR);
}
}
use of org.wso2.carbon.apimgt.core.auth.dto.ScopeInfo in project carbon-apimgt by wso2.
the class WSO2ISScopeRegistrationImpl method getScopeInfoForUpdate.
private ScopeInfo getScopeInfoForUpdate(Scope scope) {
ScopeInfo scopeInfo = new ScopeInfo();
scopeInfo.setDisplayName(scope.getName());
scopeInfo.setDescription(scope.getDescription());
scopeInfo.setBindings(scope.getBindings());
return scopeInfo;
}
use of org.wso2.carbon.apimgt.core.auth.dto.ScopeInfo in project carbon-apimgt by wso2.
the class DefaultScopeRegistrationImplTest method testUpdateScopeWhileAuthorizationServerThrowsInternalError.
@Test
public void testUpdateScopeWhileAuthorizationServerThrowsInternalError() {
DefaultScopeRegistrationServiceStub defaultScopeRegistrationServiceStub = Mockito.mock(DefaultScopeRegistrationServiceStub.class);
DefaultScopeRegistrationImpl defaultScopeRegistration = new DefaultScopeRegistrationImpl(defaultScopeRegistrationServiceStub);
ScopeInfo scopeInfo = new ScopeInfo();
scopeInfo.setDescription("cde");
scopeInfo.setDisplayName("abc");
Scope scope = new Scope();
scope.setName("abc");
scope.setDescription("cde");
Mockito.when(defaultScopeRegistrationServiceStub.updateScope(Mockito.any(ScopeInfo.class), Mockito.anyString())).thenReturn(Response.builder().status(500).headers(new HashMap<>()).build());
try {
defaultScopeRegistration.updateScope(scope);
} catch (KeyManagementException e) {
Assert.assertEquals(e.getErrorHandler().getErrorCode(), 900967);
}
}
use of org.wso2.carbon.apimgt.core.auth.dto.ScopeInfo in project carbon-apimgt by wso2.
the class DefaultScopeRegistrationImplTest method testRetrievescope.
@Test
public void testRetrievescope() throws KeyManagementException {
DefaultScopeRegistrationServiceStub defaultScopeRegistrationServiceStub = Mockito.mock(DefaultScopeRegistrationServiceStub.class);
DefaultScopeRegistrationImpl defaultScopeRegistration = new DefaultScopeRegistrationImpl(defaultScopeRegistrationServiceStub);
ScopeInfo scopeInfo = new ScopeInfo();
scopeInfo.setName("abc");
scopeInfo.setDescription("cde");
Mockito.when(defaultScopeRegistrationServiceStub.getScopeByName(scopeInfo.getName())).thenReturn(Response.builder().status(200).headers(new HashMap<>()).body(new Gson().toJson(scopeInfo), feign.Util.UTF_8).build());
Scope retrievedScope = defaultScopeRegistration.getScopeByName(scopeInfo.getName());
Assert.assertEquals(scopeInfo.getName(), retrievedScope.getName());
Assert.assertEquals(scopeInfo.getDescription(), retrievedScope.getDescription());
Assert.assertEquals(Collections.emptyList(), retrievedScope.getBindings());
}
use of org.wso2.carbon.apimgt.core.auth.dto.ScopeInfo in project carbon-apimgt by wso2.
the class DefaultScopeRegistrationImplTest method testRetrieveScopeWithBindings.
@Test
public void testRetrieveScopeWithBindings() throws KeyManagementException {
DefaultScopeRegistrationServiceStub defaultScopeRegistrationServiceStub = Mockito.mock(DefaultScopeRegistrationServiceStub.class);
DefaultScopeRegistrationImpl defaultScopeRegistration = new DefaultScopeRegistrationImpl(defaultScopeRegistrationServiceStub);
ScopeInfo scopeInfo = new ScopeInfo();
scopeInfo.setName("abc");
scopeInfo.setDescription("cde");
List<String> list = new ArrayList<>();
list.add("apim:api_create");
scopeInfo.setBindings(list);
Mockito.when(defaultScopeRegistrationServiceStub.getScopeByName(scopeInfo.getName())).thenReturn(Response.builder().status(200).headers(new HashMap<>()).body(new Gson().toJson(scopeInfo), feign.Util.UTF_8).build());
Scope retrievedScope = defaultScopeRegistration.getScopeByName(scopeInfo.getName());
Assert.assertEquals(scopeInfo.getName(), retrievedScope.getName());
Assert.assertEquals(scopeInfo.getDescription(), retrievedScope.getDescription());
Assert.assertEquals(list, retrievedScope.getBindings());
}
Aggregations