use of org.wso2.carbon.apimgt.core.api.APIPublisher in project carbon-apimgt by wso2.
the class ImportApiServiceImplTestCase method testImportApisPostError.
@Test
public void testImportApisPostError() throws Exception {
printTestMethodName();
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("swagger.json").getFile());
FileInputStream fis = null;
fis = new FileInputStream(file);
ImportApiServiceImpl importApiService = new ImportApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
Response response = importApiService.importApisPost(fis, null, null, getRequest());
assertEquals(response.getStatus(), 500);
assertTrue(response.getEntity().toString().contains("Error while importing the given APIs"));
}
use of org.wso2.carbon.apimgt.core.api.APIPublisher in project carbon-apimgt by wso2.
the class ImportApiServiceImplTestCase method testImportApisPutError.
@Test
public void testImportApisPutError() throws Exception {
printTestMethodName();
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("swagger.json").getFile());
FileInputStream fis = null;
fis = new FileInputStream(file);
ImportApiServiceImpl importApiService = new ImportApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
Response response = importApiService.importApisPut(fis, null, null, getRequest());
assertEquals(response.getStatus(), 500);
assertTrue(response.getEntity().toString().contains("Error while importing the given APIs"));
}
use of org.wso2.carbon.apimgt.core.api.APIPublisher in project carbon-apimgt by wso2.
the class LabelsApiServiceImplTestCase method testLabelsGetException.
@Test
public void testLabelsGetException() throws Exception {
printTestMethodName();
LabelsApiServiceImpl labelsApiService = new LabelsApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
Mockito.doThrow(new LabelException("Error occurred", ExceptionCodes.LABEL_EXCEPTION)).when(apiPublisher).getAllLabels();
Response response = labelsApiService.labelsGet(null, null, null, null, getRequest());
assertEquals(response.getStatus(), 500);
assertTrue(response.getEntity().toString().contains("Label Error"));
}
use of org.wso2.carbon.apimgt.core.api.APIPublisher in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdThumbnailGetException.
@Test
public void testApisApiIdThumbnailGetException() 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.doThrow(new APIManagementException("Error occurred", ExceptionCodes.API_TYPE_INVALID)).when(apiPublisher).getThumbnailImage(apiId);
Response response = apisApiService.apisApiIdThumbnailGet(apiId, null, null, getRequest());
assertEquals(response.getStatus(), 400);
assertTrue(response.getEntity().toString().contains("API Type specified is invalid"));
}
use of org.wso2.carbon.apimgt.core.api.APIPublisher 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"));
}
Aggregations