Search in sources :

Example 51 with Response

use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.

the class SubscriptionsApiServiceImplTestCase method testSubscriptionsUnblockSubscriptionPostException.

@Test
public void testSubscriptionsUnblockSubscriptionPostException() throws Exception {
    printTestMethodName();
    SubscriptionsApiServiceImpl subscriptionsApiService = new SubscriptionsApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    List<Subscription> subscriptions = new ArrayList<>();
    String sub1 = UUID.randomUUID().toString();
    String sub2 = UUID.randomUUID().toString();
    subscriptions.add(SampleTestObjectCreator.createSubscription(sub1));
    subscriptions.add(SampleTestObjectCreator.createSubscription(sub2));
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    String apiId = UUID.randomUUID().toString();
    Mockito.doThrow(new APIManagementException("Error occurred", ExceptionCodes.SUBSCRIPTION_STATE_INVALID)).when(apiPublisher).getSubscriptionsByAPI(apiId);
    Response response = subscriptionsApiService.subscriptionsGet(apiId, 10, 0, null, getRequest());
    assertEquals(response.getStatus(), 400);
    assertTrue(response.getEntity().toString().contains("Invalid state change for subscription"));
}
Also used : Response(javax.ws.rs.core.Response) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ArrayList(java.util.ArrayList) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 52 with Response

use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.

the class SubscriptionsApiServiceImplTestCase method testSubscriptionsBlockSubscriptionPostNotExist.

@Test
public void testSubscriptionsBlockSubscriptionPostNotExist() 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();
    Mockito.doReturn(null).doThrow(new IllegalArgumentException()).when(apiPublisher).getSubscriptionByUUID(subscriptionId);
    Response response = subscriptionsApiService.subscriptionsBlockSubscriptionPost(subscriptionId, null, null, null, getRequest());
    assertEquals(response.getStatus(), 404);
    assertTrue(response.getEntity().toString().contains("Subscription not found"));
}
Also used : Response(javax.ws.rs.core.Response) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 53 with Response

use of org.wso2.msf4j.Response 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"));
}
Also used : Response(javax.ws.rs.core.Response) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 54 with Response

use of org.wso2.msf4j.Response 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);
}
Also used : Response(javax.ws.rs.core.Response) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 55 with Response

use of org.wso2.msf4j.Response 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()));
}
Also used : Response(javax.ws.rs.core.Response) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) ArrayList(java.util.ArrayList) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Response (javax.ws.rs.core.Response)344 Test (org.testng.annotations.Test)329 Test (org.junit.Test)317 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)317 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)248 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)217 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)201 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)189 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)153 HashMap (java.util.HashMap)151 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)149 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)146 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)141 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)139 ArrayList (java.util.ArrayList)120 BJSON (org.ballerinalang.model.values.BJSON)94 Request (org.wso2.msf4j.Request)92 HttpResponse (org.wso2.carbon.automation.test.utils.http.client.HttpResponse)72 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)67 Path (javax.ws.rs.Path)66