Search in sources :

Example 16 with ScopeInfo

use of org.wso2.carbon.apimgt.core.auth.dto.ScopeInfo in project carbon-apimgt by wso2.

the class DefaultScopeRegistrationImplTest method testScopeRegistrationFailed.

@Test
public void testScopeRegistrationFailed() {
    DefaultScopeRegistrationServiceStub defaultScopeRegistrationServiceStub = Mockito.mock(DefaultScopeRegistrationServiceStub.class);
    DefaultScopeRegistrationImpl defaultScopeRegistration = new DefaultScopeRegistrationImpl(defaultScopeRegistrationServiceStub);
    ScopeInfo scopeInfo = new ScopeInfo();
    scopeInfo.setName("abc");
    scopeInfo.setDescription("cde");
    Mockito.when(defaultScopeRegistrationServiceStub.registerScope(scopeInfo)).thenReturn(Response.builder().status(400).headers(new HashMap<>()).body(new Gson().toJson(scopeInfo), feign.Util.UTF_8).build());
    Scope scope = new Scope();
    scope.setName("abc");
    scope.setDescription("cde");
    try {
        defaultScopeRegistration.registerScope(scope);
        Assert.fail();
    } catch (KeyManagementException e) {
        Assert.assertEquals(e.getMessage(), "Scope Registration Failed");
    }
}
Also used : Scope(org.wso2.carbon.apimgt.core.models.Scope) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) ScopeInfo(org.wso2.carbon.apimgt.core.auth.dto.ScopeInfo) KeyManagementException(org.wso2.carbon.apimgt.core.exception.KeyManagementException) Test(org.testng.annotations.Test)

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