Search in sources :

Example 96 with Response

use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method testApisApiIdWsdlGetNone.

@Test
public void testApisApiIdWsdlGetNone() throws Exception {
    printTestMethodName();
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIPublisher apiPublisher = powerMockDefaultAPIPublisher();
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    Mockito.doReturn(false).when(apiPublisher).isWSDLExists(api.getId());
    Response response = apisApiService.apisApiIdWsdlGet(api.getId(), null, null, getRequest());
    assertEquals(response.getStatus(), 204);
}
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) API(org.wso2.carbon.apimgt.core.models.API) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 97 with Response

use of org.wso2.msf4j.Response 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 98 with Response

use of org.wso2.msf4j.Response 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)

Example 99 with Response

use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method testApisApiIdThumbnailGet.

@Test
public void testApisApiIdThumbnailGet() throws Exception {
    printTestMethodName();
    ClassLoader classLoader = getClass().getClassLoader();
    File file = new File(classLoader.getResource("api1_thumbnail.png").getFile());
    FileInputStream fis = null;
    fis = new FileInputStream(file);
    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.doReturn(fis).doThrow(new IllegalArgumentException()).when(apiPublisher).getThumbnailImage(apiId);
    Response response = apisApiService.apisApiIdThumbnailGet(apiId, null, null, getRequest());
    fis.close();
    assertEquals(response.getStatus(), 200);
    assertTrue(response.getStringHeaders().get("Content-Disposition").toString().contains("filename"));
}
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) File(java.io.File) FileInputStream(java.io.FileInputStream) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 100 with Response

use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method testApisGet.

@Test
public void testApisGet() throws Exception {
    printTestMethodName();
    List<API> apis = new ArrayList<>();
    apis.add(SampleTestObjectCreator.createDefaultAPI().name("newAPI1").build());
    apis.add(SampleTestObjectCreator.createDefaultAPI().name("newAPI2").build());
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    Mockito.doReturn(apis).doThrow(new IllegalArgumentException()).when(apiPublisher).searchAPIs(10, 0, "");
    Response response = apisApiService.apisGet(10, 0, "", null, getRequest());
    assertEquals(response.getStatus(), 200);
    assertTrue(response.getEntity().toString().contains("newAPI1"));
    assertTrue(response.getEntity().toString().contains("newAPI2"));
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Response(javax.ws.rs.core.Response) ArrayList(java.util.ArrayList) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) API(org.wso2.carbon.apimgt.core.models.API) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Response (javax.ws.rs.core.Response)344 Test (org.testng.annotations.Test)329 Test (org.junit.Test)317 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)317 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)248 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)217 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)201 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)189 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)153 HashMap (java.util.HashMap)151 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)149 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)146 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)141 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)139 ArrayList (java.util.ArrayList)120 BJSON (org.ballerinalang.model.values.BJSON)94 Request (org.wso2.msf4j.Request)92 HttpResponse (org.wso2.carbon.automation.test.utils.http.client.HttpResponse)72 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)67 Path (javax.ws.rs.Path)66