use of org.wso2.carbon.apimgt.core.models.User in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisGet.
@Test
public void testApisGet() throws Exception {
printTestMethodName();
List<API> apis = new ArrayList<>();
apis.add(SampleTestObjectCreator.createDefaultAPI().name("newAPI1").build());
apis.add(SampleTestObjectCreator.createDefaultAPI().name("newAPI2").build());
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
Mockito.doReturn(apis).doThrow(new IllegalArgumentException()).when(apiPublisher).searchAPIs(10, 0, "");
Response response = apisApiService.apisGet(10, 0, "", null, getRequest());
assertEquals(response.getStatus(), 200);
assertTrue(response.getEntity().toString().contains("newAPI1"));
assertTrue(response.getEntity().toString().contains("newAPI2"));
}
use of org.wso2.carbon.apimgt.core.models.User in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testDeleteApiErrorCase.
@Test
public void testDeleteApiErrorCase() 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 api1Id = UUID.randomUUID().toString();
Mockito.doThrow(new APIManagementException("Error Occurred", ExceptionCodes.API_NOT_FOUND)).when(apiPublisher).deleteAPI(api1Id);
Response response = apisApiService.apisApiIdDelete(api1Id, null, null, getRequest());
assertEquals(response.getStatus(), 404);
assertTrue(response.getEntity().toString().contains("API not found"));
}
use of org.wso2.carbon.apimgt.core.models.User in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdDedicatedGatewayGetForInvalidAPI.
@Test
public void testApisApiIdDedicatedGatewayGetForInvalidAPI() 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.doReturn(false).when(apiPublisher).isAPIExists(apiId);
Response response = apisApiService.apisApiIdDedicatedGatewayGet(apiId, null, null, getRequest());
assertEquals(ExceptionCodes.API_NOT_FOUND.getHttpStatusCode(), response.getStatus());
assertTrue(response.getEntity().toString().contains(ExceptionCodes.API_NOT_FOUND.getErrorMessage()));
}
use of org.wso2.carbon.apimgt.core.models.User in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdScopesNameDeleteException.
@Test
public void testApisApiIdScopesNameDeleteException() 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("Scope couldn't found by name: apim:api_view", ExceptionCodes.SCOPE_NOT_FOUND)).when(apiPublisher).deleteScopeFromApi(apiId, "apim:api_view");
Response response = apisApiService.apisApiIdScopesNameDelete(apiId, "apim:api_view", null, null, getRequest());
assertEquals(response.getStatus(), 404);
assertTrue(response.getEntity().toString().contains("Scope not found"));
}
use of org.wso2.carbon.apimgt.core.models.User in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase 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;
}
Aggregations