Search in sources :

Example 96 with APIPublisher

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

the class ApisApiServiceImplTestCase method testApisValidateDefinitionPostWSDLArchive.

@Test
public void testApisValidateDefinitionPostWSDLArchive() throws Exception {
    printTestMethodName();
    File file = new File(getClass().getClassLoader().getResource(WSDL_ZIP_LOCATION).getFile());
    FileInputStream fis = new FileInputStream(file);
    FileInfo fileInfo = new FileInfo();
    fileInfo.setFileName(WSDL_ZIP);
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIPublisher apiPublisher = powerMockDefaultAPIPublisher();
    WSDLArchiveInfo archiveInfo = new WSDLArchiveInfo("/tmp", "sample.zip");
    WSDLInfo wsdlInfo = new WSDLInfo();
    wsdlInfo.setVersion("1.1");
    archiveInfo.setWsdlInfo(wsdlInfo);
    Mockito.doReturn(archiveInfo).doThrow(new IllegalArgumentException()).when(apiPublisher).extractAndValidateWSDLArchive(fis);
    Response response = apisApiService.apisValidateDefinitionPost(WSDL, fis, fileInfo, null, getRequest());
    fis.close();
    assertEquals(response.getStatus(), 200);
    assertTrue(response.getEntity() instanceof APIDefinitionValidationResponseDTO);
    assertTrue(((APIDefinitionValidationResponseDTO) response.getEntity()).getIsValid());
}
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) WSDLInfo(org.wso2.carbon.apimgt.core.models.WSDLInfo) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) WSDLArchiveInfo(org.wso2.carbon.apimgt.core.models.WSDLArchiveInfo) File(java.io.File) FileInputStream(java.io.FileInputStream) APIDefinitionValidationResponseDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.APIDefinitionValidationResponseDTO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 97 with APIPublisher

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

the class ApisApiServiceImplTestCase method testApisApiIdDocumentsDocumentIdPut.

@Test
public void testApisApiIdDocumentsDocumentIdPut() throws Exception {
    printTestMethodName();
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    DocumentInfo documentInfo1 = SampleTestObjectCreator.createDefaultDocumentationInfo().build();
    DocumentInfo documentInfo2 = SampleTestObjectCreator.createDefaultDocumentationInfo().id(documentInfo1.getId()).summary("My new summary").build();
    DocumentDTO documentDTO = MappingUtil.toDocumentDTO(documentInfo2);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    String documentId = UUID.randomUUID().toString();
    String apiId = UUID.randomUUID().toString();
    Mockito.doReturn(documentInfo1).doReturn(documentInfo2).doThrow(new IllegalArgumentException()).when(apiPublisher).getDocumentationSummary(documentId);
    Mockito.doReturn("updated").doThrow(new IllegalArgumentException()).when(apiPublisher).updateDocumentation(apiId, documentInfo1);
    Response response = apisApiService.apisApiIdDocumentsDocumentIdPut(apiId, documentId, documentDTO, null, null, getRequest());
    assertEquals(response.getStatus(), 200);
    assertTrue(response.getEntity().toString().contains("My new summary"));
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Response(javax.ws.rs.core.Response) DocumentDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.DocumentDTO) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 98 with APIPublisher

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

the class ApisApiServiceImplTestCase method testApisApiIdDocumentsDocumentIdContentPostAPIManagementException.

@Test
public void testApisApiIdDocumentsDocumentIdContentPostAPIManagementException() throws Exception {
    String inlineContent = "INLINE CONTENT";
    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();
    Mockito.doThrow(new APIManagementException("Error Occurred", ExceptionCodes.DOCUMENT_CONTENT_NOT_FOUND)).when(apiPublisher).getDocumentationSummary(documentId);
    Response response = apisApiService.apisApiIdDocumentsDocumentIdContentPost(api1Id, documentId, null, null, null, null, null, getRequest());
    assertEquals(response.getStatus(), 404);
    assertTrue(response.getEntity().toString().contains("Document content 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 99 with APIPublisher

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

the class ApisApiServiceImplTestCase method testApisApiIdDedicatedGatewayPutForInvalidAPI.

@Test
public void testApisApiIdDedicatedGatewayPutForInvalidAPI() 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.doReturn(false).when(apiPublisher).isAPIExists(apiId);
    Response response = apisApiService.apisApiIdDedicatedGatewayPut(apiId, new DedicatedGatewayDTO(), null, null, getRequest());
    assertEquals(ExceptionCodes.API_NOT_FOUND.getHttpStatusCode(), response.getStatus());
    assertTrue(response.getEntity().toString().contains(ExceptionCodes.API_NOT_FOUND.getErrorMessage()));
}
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) DedicatedGatewayDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.DedicatedGatewayDTO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 100 with APIPublisher

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

the class ApisApiServiceImplTestCase method testApisHeadNoWord.

@Test
public void testApisHeadNoWord() throws Exception {
    printTestMethodName();
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    Mockito.doReturn(true).doThrow(new IllegalArgumentException()).when(apiPublisher).checkIfAPIContextExists("testContext");
    Response response = apisApiService.apisHead("", null, getRequest());
    assertEquals(response.getStatus(), 400);
}
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)

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