Search in sources :

Example 96 with User

use of org.wso2.charon3.core.objects.User in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method testApisApiIdDocumentsDocumentIdGetNotFound.

@Test
public void testApisApiIdDocumentsDocumentIdGetNotFound() 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 documentId = UUID.randomUUID().toString();
    String apiId = UUID.randomUUID().toString();
    Mockito.doReturn(null).doThrow(new IllegalArgumentException()).when(apiPublisher).getDocumentationSummary(documentId);
    Response response = apisApiService.apisApiIdDocumentsDocumentIdGet(apiId, documentId, null, null, getRequest());
    assertEquals(response.getStatus(), 404);
    assertTrue(response.getEntity().toString().contains("Documntation 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) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 97 with User

use of org.wso2.charon3.core.objects.User in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method testApisChangeLifecyclePostWithChecklistItemChange.

@Test
public void testApisChangeLifecyclePostWithChecklistItemChange() throws Exception {
    printTestMethodName();
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    String checklist = "test1:test1,test2:test2";
    String action = "CheckListItemChange";
    WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
    workflowResponse.setWorkflowStatus(WorkflowStatus.APPROVED);
    Map<String, Boolean> lifecycleChecklistMap = new HashMap<>();
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    String apiId = UUID.randomUUID().toString();
    Mockito.doNothing().doThrow(new IllegalArgumentException()).when(apiPublisher).updateCheckListItem(apiId, action, lifecycleChecklistMap);
    Response response = apisApiService.apisChangeLifecyclePost(action, apiId, checklist, null, null, getRequest());
    assertEquals(response.getStatus(), 200);
    assertTrue(response.getEntity().toString().contains("APPROVED"));
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Response(javax.ws.rs.core.Response) HashMap(java.util.HashMap) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 98 with User

use of org.wso2.charon3.core.objects.User 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 99 with User

use of org.wso2.charon3.core.objects.User in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method testApisChangeLifecyclePostWithoutChecklistItemNonChange.

@Test
public void testApisChangeLifecyclePostWithoutChecklistItemNonChange() throws Exception {
    printTestMethodName();
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    String checklist = "test1:test1,test2:test2";
    String action = "CheckListItemChangeDifferent";
    Map<String, Boolean> lifecycleChecklistMap = new HashMap<>();
    if (checklist != null) {
        String[] checkList = checklist.split(",");
        for (String checkList1 : checkList) {
            StringTokenizer attributeTokens = new StringTokenizer(checkList1, ":");
            String attributeName = attributeTokens.nextToken();
            Boolean attributeValue = Boolean.valueOf(attributeTokens.nextToken());
            lifecycleChecklistMap.put(attributeName, attributeValue);
        }
    }
    WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
    workflowResponse.setWorkflowStatus(WorkflowStatus.CREATED);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    String apiId = UUID.randomUUID().toString();
    Mockito.doReturn(workflowResponse).doThrow(new IllegalArgumentException()).when(apiPublisher).updateAPIStatus(apiId, action, lifecycleChecklistMap);
    Response response = apisApiService.apisChangeLifecyclePost(action, apiId, checklist, null, null, getRequest());
    assertEquals(response.getStatus(), 202);
    assertTrue(response.getEntity().toString().contains("CREATED"));
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Response(javax.ws.rs.core.Response) StringTokenizer(java.util.StringTokenizer) HashMap(java.util.HashMap) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 100 with User

use of org.wso2.charon3.core.objects.User in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method testApisImportDefinitionPostException.

@Test
public void testApisImportDefinitionPostException() throws Exception {
    ClassLoader classLoader = getClass().getClassLoader();
    File file = new File(classLoader.getResource("swagger.json").getFile());
    FileInputStream fis = null;
    fis = new FileInputStream(file);
    printTestMethodName();
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    Mockito.doThrow(new APIManagementException("Error occurred", ExceptionCodes.API_TYPE_INVALID)).when(apiPublisher).addApiFromDefinition(fis);
    Response response = apisApiService.apisImportDefinitionPost(null, fis, null, null, null, null, null, null, getRequest());
    fis.close();
    assertEquals(response.getStatus(), 400);
    assertTrue(response.getEntity().toString().contains("API Type specified is invalid"));
}
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) File(java.io.File) FileInputStream(java.io.FileInputStream) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)225 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)225 Response (javax.ws.rs.core.Response)217 Test (org.testng.annotations.Test)150 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)130 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)114 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)112 Request (org.wso2.msf4j.Request)105 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)98 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)88 ArrayList (java.util.ArrayList)73 API (org.wso2.carbon.apimgt.core.models.API)73 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)65 HashMap (java.util.HashMap)59 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)51 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)51 Event (org.wso2.siddhi.core.event.Event)45 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)45 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)44 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)41