Search in sources :

Example 6 with Scope

use of org.wso2.carbon.apimgt.api.model.Scope in project carbon-apimgt by wso2.

the class MappingUtil method toScope.

/**
 * This method convert {@link ScopeDTO} to {@link Scope}
 * @param body scopeDto Object
 * @return scope object
 */
public static Scope toScope(ScopeDTO body) {
    Scope scope = new Scope();
    scope.setName(body.getName());
    scope.setDescription(body.getDescription());
    Scope_bindingsDTO scopeBindingsDTO = body.getBindings();
    if (scopeBindingsDTO != null) {
        scope.setBindings(scopeBindingsDTO.getValues());
    }
    return scope;
}
Also used : Scope(org.wso2.carbon.apimgt.core.models.Scope) Scope_bindingsDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.Scope_bindingsDTO)

Example 7 with Scope

use of org.wso2.carbon.apimgt.api.model.Scope in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method testApisApiIdScopesPostWithInvalidscopebindingType.

@Test
public void testApisApiIdScopesPostWithInvalidscopebindingType() throws Exception {
    printTestMethodName();
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    String apiId = UUID.randomUUID().toString();
    Scope scope = new Scope("api_view", "api view");
    Mockito.doNothing().when(apiPublisher).addScopeToTheApi(apiId, scope);
    Response response = apisApiService.apisApiIdScopesPost(apiId, MappingUtil.scopeDto(scope, "permission"), null, null, getRequest());
    assertEquals(response.getStatus(), 412);
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Response(javax.ws.rs.core.Response) Scope(org.wso2.carbon.apimgt.core.models.Scope) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with Scope

use of org.wso2.carbon.apimgt.api.model.Scope in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method testApisApiIdScopesNameDeleteException.

@Test
public void testApisApiIdScopesNameDeleteException() throws Exception {
    printTestMethodName();
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    String apiId = UUID.randomUUID().toString();
    Mockito.doThrow(new APIManagementException("Scope couldn't found by name: apim:api_view", ExceptionCodes.SCOPE_NOT_FOUND)).when(apiPublisher).deleteScopeFromApi(apiId, "apim:api_view");
    Response response = apisApiService.apisApiIdScopesNameDelete(apiId, "apim:api_view", null, null, getRequest());
    assertEquals(response.getStatus(), 404);
    assertTrue(response.getEntity().toString().contains("Scope not found"));
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Response(javax.ws.rs.core.Response) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with Scope

use of org.wso2.carbon.apimgt.api.model.Scope in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method testApisApiIdScopesNamePutException.

@Test
public void testApisApiIdScopesNamePutException() throws Exception {
    printTestMethodName();
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    String apiId = UUID.randomUUID().toString();
    Scope scope = new Scope("apim:api_view", "api view");
    Mockito.doThrow(new APIManagementException("Scope couldn't found by name: apim:api_view", ExceptionCodes.SCOPE_NOT_FOUND)).when(apiPublisher).updateScopeOfTheApi(apiId, scope);
    Response response = apisApiService.apisApiIdScopesNamePut(apiId, "apim:api_view", MappingUtil.scopeDto(scope, "role"), null, null, getRequest());
    assertEquals(response.getStatus(), 404);
    assertTrue(response.getEntity().toString().contains("Scope not found"));
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Response(javax.ws.rs.core.Response) Scope(org.wso2.carbon.apimgt.core.models.Scope) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with Scope

use of org.wso2.carbon.apimgt.api.model.Scope in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method testApisApiIdScopesNameGet.

@Test
public void testApisApiIdScopesNameGet() throws Exception {
    printTestMethodName();
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    String apiId = UUID.randomUUID().toString();
    Mockito.when(apiPublisher.getScopeInformationOfApi(apiId, "apim:api_view")).thenReturn(new Scope("apim:api_view", "api create"));
    Response response = apisApiService.apisApiIdScopesNameGet(apiId, "apim:api_view", null, null, getRequest());
    assertEquals(response.getStatus(), 200);
    assertTrue(response.getEntity().toString().contains("apim:api_view"));
    assertTrue(response.getEntity().toString().contains("api create"));
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Response(javax.ws.rs.core.Response) Scope(org.wso2.carbon.apimgt.core.models.Scope) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Scope (org.wso2.carbon.apimgt.api.model.Scope)97 HashMap (java.util.HashMap)76 ArrayList (java.util.ArrayList)58 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)50 Scope (org.wso2.carbon.apimgt.core.models.Scope)41 Map (java.util.Map)39 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)39 LinkedHashSet (java.util.LinkedHashSet)32 LinkedHashMap (java.util.LinkedHashMap)29 HashSet (java.util.HashSet)26 RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)25 List (java.util.List)24 Test (org.testng.annotations.Test)23 JSONObject (org.json.simple.JSONObject)22 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)19 PreparedStatement (java.sql.PreparedStatement)17 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)17 SQLException (java.sql.SQLException)16 Gson (com.google.gson.Gson)15 Connection (java.sql.Connection)15