Search in sources :

Example 56 with User

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

the class ApisApiServiceImplTestCase method testApisApiIdDocumentsDocumentIdGetException.

@Test
public void testApisApiIdDocumentsDocumentIdGetException() 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.doThrow(new APIManagementException("Error Occurred", ExceptionCodes.INVALID_DOCUMENT_CONTENT_DATA)).when(apiPublisher).getDocumentationSummary(documentId);
    Response response = apisApiService.apisApiIdDocumentsDocumentIdGet(apiId, documentId, null, null, getRequest());
    assertEquals(response.getStatus(), 400);
    assertTrue(response.getEntity().toString().contains("Invalid document content data provided"));
}
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 57 with User

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

the class ApisApiServiceImplTestCase method testApisApiIdDocumentsDocumentIdContentPostFileWrongSource.

@Test
public void testApisApiIdDocumentsDocumentIdContentPostFileWrongSource() throws Exception {
    String fileName = "swagger.json";
    String contentType = "text/json";
    ClassLoader classLoader = getClass().getClassLoader();
    File file = new File(classLoader.getResource(fileName).getFile());
    FileInfo fileDetail = new FileInfo();
    fileDetail.setFileName(fileName);
    fileDetail.setContentType(contentType);
    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);
    String api1Id = UUID.randomUUID().toString();
    String documentId = UUID.randomUUID().toString();
    DocumentInfo documentInfo = SampleTestObjectCreator.createDefaultDocumentationInfo().fileName(fileName).sourceType(DocumentInfo.SourceType.INLINE).build();
    Mockito.doReturn(documentInfo).doThrow(new IllegalArgumentException()).when(apiPublisher).getDocumentationSummary(documentId);
    Mockito.doNothing().doThrow(new IllegalArgumentException()).when(apiPublisher).uploadDocumentationFile(documentId, fis, contentType);
    Response response = apisApiService.apisApiIdDocumentsDocumentIdContentPost(api1Id, documentId, fis, fileDetail, null, null, null, getRequest());
    fis.close();
    assertEquals(response.getStatus(), 400);
    assertTrue(response.getEntity().toString().contains("is not FILE"));
}
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) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) File(java.io.File) FileInputStream(java.io.FileInputStream) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 58 with User

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

the class ApisApiServiceImplTestCase method testApisApiIdLifecycleHistoryGet.

@Test
public void testApisApiIdLifecycleHistoryGet() 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();
    API api = SampleTestObjectCreator.createDefaultAPI().id(apiId).build();
    Mockito.doReturn(true).doThrow(new IllegalArgumentException()).when(apiPublisher).isAPIExists(apiId);
    Mockito.doReturn(api).doThrow(new IllegalArgumentException()).when(apiPublisher).getAPIbyUUID(apiId);
    Response response = apisApiService.apisApiIdLifecycleHistoryGet(apiId, null, null, getRequest());
    assertEquals(response.getStatus(), 200);
}
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 59 with User

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

the class ApisApiServiceImplTestCase method testApisCopyApiPost.

@Test
public void testApisCopyApiPost() throws Exception {
    printTestMethodName();
    String newVersion = "1.0.0";
    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();
    String newAPIId = UUID.randomUUID().toString();
    API newAPI = SampleTestObjectCreator.createDefaultAPI().id(newAPIId).build();
    Mockito.doReturn(newAPIId).doThrow(new IllegalArgumentException()).when(apiPublisher).createNewAPIVersion(apiId, newVersion);
    Mockito.doReturn(newAPI).doThrow(new IllegalArgumentException()).when(apiPublisher).getAPIbyUUID(newAPIId);
    Response response = apisApiService.apisCopyApiPost(newVersion, apiId, getRequest());
    assertEquals(response.getStatus(), 201);
    assertTrue(response.getEntity().toString().contains(newAPIId));
}
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 60 with User

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

the class ApisApiServiceImplTestCase method testApisPost.

@Test
public void testApisPost() 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();
    API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI();
    API api = apiBuilder.id(apiId).build();
    APIDTO apidto = MappingUtil.toAPIDto(api);
    Mockito.doReturn(apiId).doThrow(new IllegalArgumentException()).when(apiPublisher).addAPI(apiBuilder);
    Mockito.doReturn(api).doThrow(new IllegalArgumentException()).when(apiPublisher).getAPIbyUUID(apiId);
    Response response = apisApiService.apisPost(apidto, getRequest());
    assertEquals(response.getStatus(), 201);
    assertTrue(response.getEntity().toString().contains(api.getId()));
    assertTrue(response.getEntity().toString().contains(api.getName()));
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Response(javax.ws.rs.core.Response) APIDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.APIDTO) 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

Test (org.junit.Test)225 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)223 Response (javax.ws.rs.core.Response)215 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 Test (org.testng.annotations.Test)74 API (org.wso2.carbon.apimgt.core.models.API)73 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)65 ArrayList (java.util.ArrayList)55 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)44 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)41 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)37 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)35 HashMap (java.util.HashMap)34 LifecycleState (org.wso2.carbon.lcm.core.impl.LifecycleState)28 DocumentInfo (org.wso2.carbon.apimgt.core.models.DocumentInfo)26