use of org.wso2.charon3.core.objects.User in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImplTestCase method testSubscriptionsBlockSubscriptionPostException.
@Test
public void testSubscriptionsBlockSubscriptionPostException() throws Exception {
printTestMethodName();
SubscriptionsApiServiceImpl subscriptionsApiService = new SubscriptionsApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
String subscriptionId = UUID.randomUUID().toString();
Subscription subscription = SampleTestObjectCreator.createSubscription(subscriptionId);
subscription.setStatus(APIMgtConstants.SubscriptionStatus.REJECTED);
Mockito.doThrow(new APIManagementException("Error occurred", ExceptionCodes.SUBSCRIPTION_STATE_INVALID)).when(apiPublisher).getSubscriptionByUUID(subscriptionId);
Response response = subscriptionsApiService.subscriptionsBlockSubscriptionPost(subscriptionId, APIMgtConstants.SubscriptionStatus.BLOCKED.name(), null, null, getRequest());
assertEquals(response.getStatus(), 400);
assertTrue(response.getEntity().toString().contains("Invalid state change for subscription"));
}
use of org.wso2.charon3.core.objects.User in project carbon-apimgt by wso2.
the class EnvironmentsApiServiceImplTestCase 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.charon3.core.objects.User in project carbon-apimgt by wso2.
the class ExportApiServiceImplTestCase method testExportApisGetNotFound.
@Test
public void testExportApisGetNotFound() throws Exception {
printTestMethodName();
ExportApiServiceImpl exportApiService = new ExportApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
Response response = exportApiService.exportApisGet("", null, null, getRequest());
assertEquals(response.getStatus(), 404);
}
use of org.wso2.charon3.core.objects.User in project carbon-apimgt by wso2.
the class ExternalResourcesApiServiceImplTestCase 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.charon3.core.objects.User in project carbon-apimgt by wso2.
the class ExternalResourcesApiServiceImplTestCase method testExternalResourcesServicesGet.
@Test
public void testExternalResourcesServicesGet() throws Exception {
printTestMethodName();
ExternalResourcesApiServiceImpl externalResourcesApiService = new ExternalResourcesApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
Endpoint endpoint1 = SampleTestObjectCreator.createMockEndpoint();
Endpoint endpoint2 = SampleTestObjectCreator.createMockEndpoint();
List<Endpoint> endpointList = new ArrayList<>();
endpointList.add(endpoint1);
endpointList.add(endpoint2);
Mockito.doReturn(endpointList).doThrow(new IllegalArgumentException()).when(apiPublisher).discoverServiceEndpoints();
Response response = externalResourcesApiService.externalResourcesServicesGet(null, null, getRequest());
Assert.assertEquals(response.getStatus(), 200);
Assert.assertTrue(response.getEntity().toString().contains(endpoint1.getId()));
Assert.assertTrue(response.getEntity().toString().contains(endpoint2.getId()));
}
Aggregations