use of org.wso2.carbon.user.core.common.User 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.user.core.common.User 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.user.core.common.User in project carbon-apimgt by wso2.
the class LabelsApiServiceImplTestCase method getRequest.
// Sample request to be used by tests
private Request getRequest() throws Exception {
HTTPCarbonMessage carbonMessage = Mockito.mock(HTTPCarbonMessage.class);
Mockito.when(carbonMessage.getProperty("LOGGED_IN_USER")).thenReturn(USER);
Request request = new Request(carbonMessage);
return request;
}
use of org.wso2.carbon.user.core.common.User 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.user.core.common.User 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"));
}
Aggregations