use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.
the class EndpointsApiServiceImplTestCase method testEndpointsEndpointIdGetNotExist.
@Test
public void testEndpointsEndpointIdGetNotExist() 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(null).doThrow(new IllegalArgumentException()).when(apiPublisher).getEndpoint(endpointId);
Response response = endpointsApiService.endpointsEndpointIdGet(endpointId, null, null, getRequest());
assertEquals(response.getStatus(), 404);
assertTrue(response.getEntity().toString().contains("Endpoint Not Found"));
}
use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.
the class EndpointsApiServiceImplTestCase method testEndpointsEndpointIdGetException.
@Test
public void testEndpointsEndpointIdGetException() 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.doThrow(new APIManagementException("Error occurred", ExceptionCodes.APPLICATION_INACTIVE)).when(apiPublisher).getEndpoint(endpointId);
Response response = endpointsApiService.endpointsEndpointIdGet(endpointId, null, null, getRequest());
assertEquals(response.getStatus(), 400);
assertTrue(response.getEntity().toString().contains("Application is not active"));
}
use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.
the class EndpointsApiServiceImplTestCase method testEndpointsEndpointIdPutException.
@Test
public void testEndpointsEndpointIdPutException() 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();
EndPointDTO endPointDTO = MappingUtil.toEndPointDTO(endpoint);
Mockito.doThrow(new APIManagementException("Error occurred", ExceptionCodes.ENDPOINT_ALREADY_EXISTS)).when(apiPublisher).getEndpoint(endpointId);
Response response = endpointsApiService.endpointsEndpointIdPut(endpointId, endPointDTO, null, null, getRequest());
assertEquals(response.getStatus(), 409);
assertTrue(response.getEntity().toString().contains("Endpoint already exists"));
}
use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.
the class EndpointsApiServiceImplTestCase method testEndpointsEndpointIdPutNotExist.
@Test
public void testEndpointsEndpointIdPutNotExist() 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();
EndPointDTO endPointDTO = MappingUtil.toEndPointDTO(endpoint);
String endpointId = endpoint.getId();
Mockito.doReturn(null).doThrow(new IllegalArgumentException()).when(apiPublisher).getEndpoint(endpointId);
Response response = endpointsApiService.endpointsEndpointIdPut(endpointId, endPointDTO, null, null, getRequest());
assertEquals(response.getStatus(), 404);
assertTrue(response.getEntity().toString().contains("Endpoint Not Found"));
}
use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.
the class PoliciesApiServiceImplTestCase method testPoliciesTierLevelTierNameGet.
@Test
public void testPoliciesTierLevelTierNameGet() throws Exception {
printTestMethodName();
PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
Policy gold = SampleTestObjectCreator.goldSubscriptionPolicy;
Mockito.doReturn(gold).doThrow(new IllegalArgumentException()).when(apiPublisher).getPolicyByName(RestApiUtil.mapRestApiPolicyLevelToPolicyLevelEnum("subscription"), "Gold");
Response response = policiesApiService.policiesTierLevelTierNameGet("Gold", "subscription", null, null, getRequest());
assertEquals(response.getStatus(), 200);
assertTrue(response.getEntity().toString().contains("Gold"));
}
Aggregations