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);
}
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"));
}
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);
}
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);
}
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);
}
Aggregations