Search in sources :

Example 61 with APIMgtAdminService

use of org.wso2.carbon.apimgt.core.api.APIMgtAdminService in project carbon-apimgt by wso2.

the class ResourcesApiServiceImplTestCase method getResponse.

private Response getResponse(String apiContext, String apiVersion) throws Exception {
    APIMgtAdminServiceImpl apiMgtAdminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
    PowerMockito.mockStatic(APIManagerFactory.class);
    PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
    Mockito.when(instance.getAPIMgtAdminService()).thenReturn(apiMgtAdminService);
    ResourcesApiServiceImpl resourcesApiService = new ResourcesApiServiceImpl();
    return resourcesApiService.resourcesGet(apiContext, apiVersion, null, getRequest());
}
Also used : APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)

Example 62 with APIMgtAdminService

use of org.wso2.carbon.apimgt.core.api.APIMgtAdminService in project carbon-apimgt by wso2.

the class ResourcesApiServiceImplTestCase method resourcesGetTest.

@Test
public void resourcesGetTest() throws Exception {
    APIMgtAdminServiceImpl apiMgtAdminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
    PowerMockito.mockStatic(APIManagerFactory.class);
    PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
    Mockito.when(instance.getAPIMgtAdminService()).thenReturn(apiMgtAdminService);
    ResourcesApiServiceImpl resourcesApiService = new ResourcesApiServiceImpl();
    UriTemplate uriTemplateOne = SampleTestObjectCreator.createUniqueUriTemplate();
    UriTemplate uriTemplateTwo = SampleTestObjectCreator.createUniqueUriTemplate();
    UriTemplate uriTemplateThree = SampleTestObjectCreator.createUniqueUriTemplate();
    List<UriTemplate> uriTemplateList = new ArrayList<>();
    uriTemplateList.add(uriTemplateOne);
    uriTemplateList.add(uriTemplateTwo);
    uriTemplateList.add(uriTemplateThree);
    Mockito.when(apiMgtAdminService.getAllResourcesForApi(API_CONTEXT, API_VERSION)).thenReturn(uriTemplateList);
    Response response = resourcesApiService.resourcesGet(API_CONTEXT, API_VERSION, null, getRequest());
    Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
    Assert.assertEquals(((ResourcesListDTO) response.getEntity()).getList().size(), 3);
}
Also used : Response(javax.ws.rs.core.Response) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) ArrayList(java.util.ArrayList) UriTemplate(org.wso2.carbon.apimgt.core.models.UriTemplate) ResourcesListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.ResourcesListDTO) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 63 with APIMgtAdminService

use of org.wso2.carbon.apimgt.core.api.APIMgtAdminService in project carbon-apimgt by wso2.

the class SubscriptionsApiServiceImplTestCase method subscriptionsGetTest.

@Test
public void subscriptionsGetTest() throws Exception {
    APIMgtAdminServiceImpl apiMgtAdminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
    PowerMockito.mockStatic(APIManagerFactory.class);
    PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
    Mockito.when(instance.getAPIMgtAdminService()).thenReturn(apiMgtAdminService);
    SubscriptionsApiServiceImpl subscriptionsApiService = new SubscriptionsApiServiceImpl();
    Mockito.when(apiMgtAdminService.getAPISubscriptionsOfApi(API_CONTEXT, API_VERSION)).thenReturn(createSubscriptionValidationDataList());
    Response response = subscriptionsApiService.subscriptionsGet(API_CONTEXT, API_VERSION, LIMIT, null, getRequest());
    Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
    Assert.assertEquals(((SubscriptionListDTO) response.getEntity()).getList().size(), 2);
}
Also used : Response(javax.ws.rs.core.Response) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) SubscriptionListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.SubscriptionListDTO) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)47 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)46 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)36 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)17 Response (javax.ws.rs.core.Response)16 Test (org.junit.Test)15 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)15 HashMap (java.util.HashMap)10 APIManagerFactory (org.wso2.carbon.apimgt.core.impl.APIManagerFactory)9 ArrayList (java.util.ArrayList)8 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)6 CustomPolicy (org.wso2.carbon.apimgt.core.models.policy.CustomPolicy)6 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)6 Map (java.util.Map)5 BlockConditions (org.wso2.carbon.apimgt.core.models.BlockConditions)5 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)5 Label (org.wso2.carbon.apimgt.core.models.Label)3 ThreatProtectionPolicy (org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy)3 Workflow (org.wso2.carbon.apimgt.core.workflow.Workflow)3 File (java.io.File)2