Search in sources :

Example 6 with ScopeInfo

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));
}
Also used : Scope(org.wso2.carbon.apimgt.core.models.Scope) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) Test(org.testng.annotations.Test)

Example 7 with ScopeInfo

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;
}
Also used : Scope(org.wso2.carbon.apimgt.core.models.Scope) GsonDecoder(feign.gson.GsonDecoder) ScopeInfo(org.wso2.carbon.apimgt.core.auth.dto.ScopeInfo)

Example 8 with ScopeInfo

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);
    }
}
Also used : Response(feign.Response) ScopeInfo(org.wso2.carbon.apimgt.core.auth.dto.ScopeInfo) KeyManagementException(org.wso2.carbon.apimgt.core.exception.KeyManagementException)

Example 9 with ScopeInfo

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);
    }
}
Also used : Response(feign.Response) ScopeInfo(org.wso2.carbon.apimgt.core.auth.dto.ScopeInfo) KeyManagementException(org.wso2.carbon.apimgt.core.exception.KeyManagementException)

Example 10 with ScopeInfo

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;
}
Also used : Scope(org.wso2.carbon.apimgt.core.models.Scope) GsonDecoder(feign.gson.GsonDecoder) ScopeInfo(org.wso2.carbon.apimgt.core.auth.dto.ScopeInfo)

Aggregations

ScopeInfo (org.wso2.carbon.apimgt.core.auth.dto.ScopeInfo)15 Scope (org.wso2.carbon.apimgt.core.models.Scope)8 Test (org.testng.annotations.Test)6 KeyManagementException (org.wso2.carbon.apimgt.core.exception.KeyManagementException)6 Gson (com.google.gson.Gson)5 HashMap (java.util.HashMap)5 Response (feign.Response)4 GsonDecoder (feign.gson.GsonDecoder)2 ArrayList (java.util.ArrayList)1