Search in sources :

Example 71 with APIPublisher

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

the class ImportApiServiceImplTestCase method testImportApisPostError.

@Test
public void testImportApisPostError() throws Exception {
    printTestMethodName();
    ClassLoader classLoader = getClass().getClassLoader();
    File file = new File(classLoader.getResource("swagger.json").getFile());
    FileInputStream fis = null;
    fis = new FileInputStream(file);
    ImportApiServiceImpl importApiService = new ImportApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    Response response = importApiService.importApisPost(fis, null, null, getRequest());
    assertEquals(response.getStatus(), 500);
    assertTrue(response.getEntity().toString().contains("Error while importing the given APIs"));
}
Also used : Response(javax.ws.rs.core.Response) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 72 with APIPublisher

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

the class ImportApiServiceImplTestCase method testImportApisPutError.

@Test
public void testImportApisPutError() throws Exception {
    printTestMethodName();
    ClassLoader classLoader = getClass().getClassLoader();
    File file = new File(classLoader.getResource("swagger.json").getFile());
    FileInputStream fis = null;
    fis = new FileInputStream(file);
    ImportApiServiceImpl importApiService = new ImportApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    Response response = importApiService.importApisPut(fis, null, null, getRequest());
    assertEquals(response.getStatus(), 500);
    assertTrue(response.getEntity().toString().contains("Error while importing the given APIs"));
}
Also used : Response(javax.ws.rs.core.Response) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 73 with APIPublisher

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

the class LabelsApiServiceImplTestCase method testLabelsGetException.

@Test
public void testLabelsGetException() throws Exception {
    printTestMethodName();
    LabelsApiServiceImpl labelsApiService = new LabelsApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    Mockito.doThrow(new LabelException("Error occurred", ExceptionCodes.LABEL_EXCEPTION)).when(apiPublisher).getAllLabels();
    Response response = labelsApiService.labelsGet(null, null, null, null, getRequest());
    assertEquals(response.getStatus(), 500);
    assertTrue(response.getEntity().toString().contains("Label Error"));
}
Also used : Response(javax.ws.rs.core.Response) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) LabelException(org.wso2.carbon.apimgt.core.exception.LabelException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 74 with APIPublisher

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

the class ApisApiServiceImplTestCase method testApisApiIdThumbnailGetException.

@Test
public void testApisApiIdThumbnailGetException() 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("Error occurred", ExceptionCodes.API_TYPE_INVALID)).when(apiPublisher).getThumbnailImage(apiId);
    Response response = apisApiService.apisApiIdThumbnailGet(apiId, null, null, getRequest());
    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) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 75 with APIPublisher

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

the class ApisApiServiceImplTestCase method testApisApiIdThumbnailPostException.

@Test
public void testApisApiIdThumbnailPostException() 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();
    FileInfo fileDetail = new FileInfo();
    fileDetail.setFileName("test.png");
    Mockito.doThrow(new APIManagementException("Error occurred", ExceptionCodes.API_TYPE_INVALID)).when(apiPublisher).saveThumbnailImage(apiId, null, fileDetail.getFileName());
    Response response = apisApiService.apisApiIdThumbnailPost(apiId, null, fileDetail, null, null, getRequest());
    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) FileInfo(org.wso2.msf4j.formparam.FileInfo) 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)

Aggregations

APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)199 Test (org.testng.annotations.Test)185 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)168 Response (javax.ws.rs.core.Response)144 Test (org.junit.Test)144 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)144 API (org.wso2.carbon.apimgt.core.models.API)124 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)120 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)99 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)99 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)93 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)75 HashMap (java.util.HashMap)61 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)61 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)53 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)52 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)45 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)44 DocumentInfo (org.wso2.carbon.apimgt.core.models.DocumentInfo)41 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)39