use of org.wso2.msf4j.Response 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));
}
use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisPost.
@Test
public void testApisPost() 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.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI();
API api = apiBuilder.id(apiId).build();
APIDTO apidto = MappingUtil.toAPIDto(api);
Mockito.doReturn(apiId).doThrow(new IllegalArgumentException()).when(apiPublisher).addAPI(apiBuilder);
Mockito.doReturn(api).doThrow(new IllegalArgumentException()).when(apiPublisher).getAPIbyUUID(apiId);
Response response = apisApiService.apisPost(apidto, getRequest());
assertEquals(response.getStatus(), 201);
assertTrue(response.getEntity().toString().contains(api.getId()));
assertTrue(response.getEntity().toString().contains(api.getName()));
}
use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.
the class EndpointsApiServiceImplTestCase method testEndpointsEndpointIdGet.
@Test
public void testEndpointsEndpointIdGet() throws Exception {
printTestMethodName();
EndpointsApiServiceImpl endpointsApiService = new EndpointsApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
Endpoint endpoint = SampleTestObjectCreator.createMockEndpoint();
String endpointId = endpoint.getId();
Mockito.doReturn(endpoint).doThrow(new IllegalArgumentException()).when(apiPublisher).getEndpoint(endpointId);
Response response = endpointsApiService.endpointsEndpointIdGet(endpointId, null, null, getRequest());
assertEquals(response.getStatus(), 200);
assertTrue(response.getEntity().toString().contains(endpointId));
}
use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.
the class EndpointsApiServiceImplTestCase method testEndpointsEndpointIdPut.
@Test
public void testEndpointsEndpointIdPut() throws Exception {
printTestMethodName();
EndpointsApiServiceImpl endpointsApiService = new EndpointsApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
Endpoint endpointOld = SampleTestObjectCreator.createMockEndpoint();
String endpointOldId = endpointOld.getId();
Endpoint.Builder endpointUpdateBuilder = SampleTestObjectCreator.createMockEndpointBuilder();
endpointUpdateBuilder.name("newNameEndpoint").id(endpointOldId);
Endpoint newEndpoint = endpointUpdateBuilder.build();
EndPointDTO endPointDTO = MappingUtil.toEndPointDTO(newEndpoint);
Mockito.doReturn(endpointOld).doReturn(newEndpoint).doThrow(new IllegalArgumentException()).when(apiPublisher).getEndpoint(endpointOldId);
Mockito.doNothing().doThrow(new IllegalArgumentException()).when(apiPublisher).updateEndpoint(newEndpoint);
Response response = endpointsApiService.endpointsEndpointIdPut(endpointOldId, endPointDTO, null, null, getRequest());
assertEquals(response.getStatus(), 200);
assertTrue(response.getEntity().toString().contains("newNameEndpoint"));
}
use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.
the class EndpointsApiServiceImplTestCase method testEndpointsGetException.
@Test
public void testEndpointsGetException() throws Exception {
printTestMethodName();
EndpointsApiServiceImpl endpointsApiService = new EndpointsApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
Mockito.doThrow(new APIManagementException("Error occurred", ExceptionCodes.ENDPOINT_ADD_FAILED)).when(apiPublisher).getAllEndpoints();
Response response = endpointsApiService.endpointsGet(null, null, getRequest());
assertEquals(response.getStatus(), 400);
assertTrue(response.getEntity().toString().contains("Endpoint adding failed"));
}
Aggregations