Search in sources :

Example 26 with FileInfo

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

the class ApisApiServiceImplTestCase method testApisImportDefinitionPostWSDLWithNoAdditionalProperties.

@Test
public void testApisImportDefinitionPostWSDLWithNoAdditionalProperties() 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();
    powerMockDefaultAPIPublisher();
    Response response = apisApiService.apisImportDefinitionPost(WSDL, fis, fileInfo, null, null, null, null, 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 27 with FileInfo

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

the class ApisApiServiceImplTestCase method testApisApiIdThumbnailPost.

@Test
public void testApisApiIdThumbnailPost() throws Exception {
    printTestMethodName();
    ClassLoader classLoader = getClass().getClassLoader();
    File file = new File(classLoader.getResource("api1_thumbnail.png").getFile());
    FileInputStream fis = null;
    fis = new FileInputStream(file);
    FileInfo fileDetail = new FileInfo();
    fileDetail.setFileName("test.png");
    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.doNothing().doThrow(new IllegalArgumentException()).when(apiPublisher).saveThumbnailImage(apiId, fis, fileDetail.getFileName());
    Response response = apisApiService.apisApiIdThumbnailPost(apiId, fis, fileDetail, null, null, getRequest());
    fis.close();
    assertEquals(response.getStatus(), 201);
    assertTrue(response.getEntity().toString().contains("application/octet-strea"));
}
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) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 28 with FileInfo

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

the class ApisApiServiceImplTestCase method testApisValidateDefinitionPostWSDLFile.

@Test
public void testApisValidateDefinitionPostWSDLFile() 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();
    powerMockDefaultAPIPublisher();
    Response response = apisApiService.apisValidateDefinitionPost(WSDL, fis, fileInfo, null, getRequest());
    fis.close();
    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) 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 29 with FileInfo

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

the class ApisApiServiceImplTestCase method testApisApiIdWsdlPutException.

@Test
public void testApisApiIdWsdlPutException() throws Exception {
    printTestMethodName();
    File file = new File(getClass().getClassLoader().getResource(WSDL_FILE_LOCATION).getFile());
    FileInfo fileInfo = new FileInfo();
    fileInfo.setFileName(WSDL_FILE);
    InputStream inputStream = new FileInputStream(file);
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIPublisher apiPublisher = powerMockDefaultAPIPublisher();
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    Mockito.doThrow(new APIMgtWSDLException("Error while updating WSDL", ExceptionCodes.INTERNAL_WSDL_EXCEPTION)).when(apiPublisher).updateAPIWSDL(api.getId(), inputStream);
    Response response = apisApiService.apisApiIdWsdlPut(api.getId(), inputStream, fileInfo, null, null, getRequest());
    assertEquals(response.getStatus(), 500);
}
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) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) API(org.wso2.carbon.apimgt.core.models.API) File(java.io.File) FileInputStream(java.io.FileInputStream) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 30 with FileInfo

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

the class ApisApiServiceImplTestCase method testApisImportDefinitionPostWSDLWithInvalidFileExtension.

@Test
public void testApisImportDefinitionPostWSDLWithInvalidFileExtension() throws Exception {
    printTestMethodName();
    File file = new File(getClass().getClassLoader().getResource("swagger.json").getFile());
    FileInputStream fis = new FileInputStream(file);
    FileInfo fileInfo = new FileInfo();
    fileInfo.setFileName("swagger.json");
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    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);
    powerMockDefaultAPIPublisher();
    Response response = apisApiService.apisImportDefinitionPost(WSDL, fis, fileInfo, null, additionalProperties, null, null, 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) APIDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.APIDTO) FileInfo(org.wso2.msf4j.formparam.FileInfo) 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)

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