use of org.wso2.carbon.apimgt.core.auth.dto.ScopeInfo in project carbon-apimgt by wso2.
the class DefaultScopeRegistrationImplTest method testRegisterScope.
@Test
public void testRegisterScope() throws KeyManagementException {
DefaultScopeRegistrationServiceStub defaultScopeRegistrationServiceStub = Mockito.mock(DefaultScopeRegistrationServiceStub.class);
DefaultScopeRegistrationImpl defaultScopeRegistration = new DefaultScopeRegistrationImpl(defaultScopeRegistrationServiceStub);
Scope scopeInfo = new Scope();
scopeInfo.setName("abc");
scopeInfo.setDescription("cde");
Mockito.when(defaultScopeRegistrationServiceStub.registerScope(getScopeInfo(scopeInfo))).thenReturn(Response.builder().status(201).headers(new HashMap<>()).body(new Gson().toJson(scopeInfo), feign.Util.UTF_8).build());
Scope scope = new Scope();
scope.setName("abc");
scope.setDescription("cde");
Assert.assertTrue(defaultScopeRegistration.registerScope(scope));
}
use of org.wso2.carbon.apimgt.core.auth.dto.ScopeInfo in project carbon-apimgt by wso2.
the class WSO2ISScopeRegistrationImpl method getScope.
private Scope getScope(Response response) throws IOException {
Scope scope = new Scope();
ScopeInfo scopeInfoResponse = (ScopeInfo) new GsonDecoder().decode(response, ScopeInfo.class);
scope.setName(scopeInfoResponse.getName());
scope.setDescription(scopeInfoResponse.getDescription());
if (scopeInfoResponse.getBindings() != null) {
scope.setBindings(scopeInfoResponse.getBindings());
} else {
scope.setBindings(Collections.emptyList());
}
return scope;
}
use of org.wso2.carbon.apimgt.core.auth.dto.ScopeInfo in project carbon-apimgt by wso2.
the class WSO2ISScopeRegistrationImpl method updateScope.
@Override
public boolean updateScope(Scope scope) throws KeyManagementException {
ScopeInfo scopeInfo = getScopeInfoForUpdate(scope);
Response response = wso2ISScopeRegistrationServiceStub.updateScope(scopeInfo, scope.getName());
if (response.status() == APIMgtConstants.HTTPStatusCodes.SC_200_OK) {
return true;
} else {
throw new KeyManagementException("Scope Couldn't get updated", ExceptionCodes.INTERNAL_ERROR);
}
}
use of org.wso2.carbon.apimgt.core.auth.dto.ScopeInfo in project carbon-apimgt by wso2.
the class WSO2ISScopeRegistrationImpl method registerScope.
@Override
public boolean registerScope(Scope scope) throws KeyManagementException {
ScopeInfo scopeInfo = getScopeInfo(scope);
Response response = wso2ISScopeRegistrationServiceStub.registerScope(scopeInfo);
if (response.status() == APIMgtConstants.HTTPStatusCodes.SC_201_CREATED) {
return true;
} else {
throw new KeyManagementException("Scope Registration Failed", ExceptionCodes.SCOPE_REGISTRATION_FAILED);
}
}
use of org.wso2.carbon.apimgt.core.auth.dto.ScopeInfo in project carbon-apimgt by wso2.
the class DefaultScopeRegistrationImpl method getScope.
private Scope getScope(Response response) throws IOException {
Scope scope = new Scope();
ScopeInfo scopeInfoResponse = (ScopeInfo) new GsonDecoder().decode(response, ScopeInfo.class);
scope.setName(scopeInfoResponse.getName());
scope.setDescription(scopeInfoResponse.getDescription());
if (scopeInfoResponse.getBindings() != null) {
scope.setBindings(scopeInfoResponse.getBindings());
} else {
scope.setBindings(Collections.emptyList());
}
return scope;
}
Aggregations