Search in sources :

Example 1 with FileInfo

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

Example 2 with FileInfo

use of org.wso2.msf4j.formparam.FileInfo 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 3 with FileInfo

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

the class ApisApiServiceImplTestCase method testApisImportDefinitionPostWSDLFile.

@Test
public void testApisImportDefinitionPostWSDLFile() throws Exception {
    printTestMethodName();
    File file = new File(getClass().getClassLoader().getResource(WSDL_FILE_LOCATION).getFile());
    FileInputStream fis = new FileInputStream(file);
    FileInfo fileInfo = new FileInfo();
    fileInfo.setFileName(WSDL_FILE);
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIPublisher apiPublisher = powerMockDefaultAPIPublisher();
    String apiId = UUID.randomUUID().toString();
    API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI().id(apiId);
    API api = apiBuilder.build();
    APIDTO apiDto = MappingUtil.toAPIDto(api);
    ObjectMapper objectMapper = new ObjectMapper();
    String additionalProperties = objectMapper.writeValueAsString(apiDto);
    Mockito.doReturn(api).doThrow(new IllegalArgumentException()).when(apiPublisher).getAPIbyUUID(apiId);
    Mockito.doReturn(apiId).when(apiPublisher).addAPIFromWSDLFile(Mockito.argThat(getAPIBuilderMatcher(apiBuilder)), Mockito.eq(fis), Mockito.eq(false));
    Response response = apisApiService.apisImportDefinitionPost(WSDL, fis, fileInfo, null, additionalProperties, null, null, null, getRequest());
    fis.close();
    assertEquals(response.getStatus(), 201);
    assertTrue(response.getEntity().toString().contains(apiId));
}
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) FileInfo(org.wso2.msf4j.formparam.FileInfo) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) API(org.wso2.carbon.apimgt.core.models.API) File(java.io.File) FileInputStream(java.io.FileInputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with FileInfo

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

the class ApisApiServiceImplTestCase method testApisValidateDefinitionPostWSDLFileInvalid.

@Test
public void testApisValidateDefinitionPostWSDLFileInvalid() throws Exception {
    printTestMethodName();
    File file = new File(getClass().getClassLoader().getResource(WSDL_FILE_INVALID_LOCATION).getFile());
    FileInputStream fis = new FileInputStream(file);
    FileInfo fileInfo = new FileInfo();
    fileInfo.setFileName(WSDL_FILE_INVALID);
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    powerMockDefaultAPIPublisher();
    Response response = apisApiService.apisValidateDefinitionPost(WSDL, fis, fileInfo, null, getRequest());
    fis.close();
    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) FileInfo(org.wso2.msf4j.formparam.FileInfo) File(java.io.File) FileInputStream(java.io.FileInputStream) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with FileInfo

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

Aggregations

Response (javax.ws.rs.core.Response)24 Test (org.junit.Test)22 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)22 FileInfo (org.wso2.msf4j.formparam.FileInfo)22 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)21 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)21 File (java.io.File)19 FileInputStream (java.io.FileInputStream)19 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)17 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)10 API (org.wso2.carbon.apimgt.core.models.API)10 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)6 APIDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.APIDTO)6 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4 DocumentInfo (org.wso2.carbon.apimgt.core.models.DocumentInfo)3 Request (org.wso2.msf4j.Request)3 IOException (java.io.IOException)2