use of org.wso2.carbon.apimgt.api.model.APIPublisher 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"));
}
use of org.wso2.carbon.apimgt.api.model.APIPublisher 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"));
}
use of org.wso2.carbon.apimgt.api.model.APIPublisher 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);
}
use of org.wso2.carbon.apimgt.api.model.APIPublisher 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));
}
use of org.wso2.carbon.apimgt.api.model.APIPublisher 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));
}
Aggregations