Search in sources :

Example 56 with APIMgtAdminService

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

the class EndpointsApiServiceImplTestCase method endpointsEndpointIdGatewayConfigGetTest.

@Test
public void endpointsEndpointIdGatewayConfigGetTest() 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);
    EndpointsApiServiceImpl endpointsApiService = new EndpointsApiServiceImpl();
    String endpointId = UUID.randomUUID().toString();
    String endpointGatewayConfig = "package deployment.org.wso2.apim;\n" + "import ballerina.net.http;\n" + "\n" + "@http:BasePath(\"/aaa1\")\n" + "service aaa1_1489666767745 {\n" + "\n" + "    @http:GET\n" + "    @http:Path(\"/*\")\n" + "    resource get_star_ (message m) {\n" + "        http:ClientConnector productionEndpoint = create http:ClientConnector(getUrlFromKey" + "(\"aaa1_1.0.0__ep\"));\n   http:ClientConnector sandboxEndpoint = create http:ClientConnector" + "(getUrlFromKey(\"aaa1_1.0.0__ep\"));\n message response;\n string endpointType;\n string " + "productionType;\n \n \n      endpointType = \"production\";\n productionType = \"production\";\n" + "\n      if (endpointType == productionType) {\n" + "            response = http:ClientConnector.execute(productionEndpoint, \"get\", \"\", m);\n" + "        } else {\n" + "            response = http:ClientConnector.execute(sandboxEndpoint, \"get\", \"\", m);\n" + "        }\n" + "\n" + "        reply response;\n" + "    }\n" + "}";
    Mockito.when(apiMgtAdminService.getEndpointGatewayConfig(endpointId)).thenReturn(endpointGatewayConfig);
    Response response = endpointsApiService.endpointsEndpointIdGatewayConfigGet(endpointId, null, getRequest());
    Assert.assertEquals(response.getStatus(), 200);
}
Also used : Response(javax.ws.rs.core.Response) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 57 with APIMgtAdminService

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

the class EndpointsApiServiceImplTestCase method nullEndpointGatewayConfigTest.

@Test
public void nullEndpointGatewayConfigTest() 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);
    EndpointsApiServiceImpl endpointsApiService = new EndpointsApiServiceImpl();
    String endpointId = UUID.randomUUID().toString();
    String endpointGatewayConfig = null;
    Mockito.when(apiMgtAdminService.getEndpointGatewayConfig(endpointId)).thenReturn(endpointGatewayConfig);
    Response response = endpointsApiService.endpointsEndpointIdGatewayConfigGet(endpointId, null, getRequest());
    Assert.assertEquals(response.getStatus(), 404);
}
Also used : Response(javax.ws.rs.core.Response) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 58 with APIMgtAdminService

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

the class EndpointsApiServiceImplTestCase method endpointsGetExceptionTest.

@Test
public void endpointsGetExceptionTest() throws Exception {
    APIMgtAdminServiceImpl apiMgtAdminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    String message = "Error while retrieving endpoint";
    APIManagementException apiManagementException = new APIManagementException(message, ExceptionCodes.ENDPOINT_NOT_FOUND);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenThrow(apiManagementException);
    Mockito.when(apiMgtAdminService.getAllEndpoints()).thenReturn(null);
    EndpointsApiServiceImpl endpointsApiService = new EndpointsApiServiceImpl();
    Response response = endpointsApiService.endpointsGet(null, null, getRequest());
    Assert.assertEquals(response.getStatus(), 404);
}
Also used : Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 59 with APIMgtAdminService

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

the class ExportApiServiceImplTestCase method exportPoliciesThrottleGetTest.

@Test
public void exportPoliciesThrottleGetTest() 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);
    ExportApiServiceImpl exportApiService = new ExportApiServiceImpl();
    LogManager.getRootLogger().setLevel(Level.DEBUG);
    Response response = exportApiService.exportPoliciesThrottleGet(null, getRequest());
    Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
}
Also used : Response(javax.ws.rs.core.Response) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 60 with APIMgtAdminService

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

the class PoliciesApiServiceImplTestCase method policiesGetTest.

@Test
public void policiesGetTest() 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);
    PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
    PolicyValidationData policyValidationDataOne = new PolicyValidationData(UUID.randomUUID().toString(), "APPLICATION_POLICY", true);
    PolicyValidationData policyValidationDataTwo = new PolicyValidationData(UUID.randomUUID().toString(), "APPLICATION_POLICY", true);
    PolicyValidationData policyValidationDataThree = new PolicyValidationData(UUID.randomUUID().toString(), "APPLICATION_POLICY", true);
    Set<PolicyValidationData> policyValidationDataHashSet = new LinkedHashSet<>();
    policyValidationDataHashSet.add(policyValidationDataOne);
    policyValidationDataHashSet.add(policyValidationDataTwo);
    policyValidationDataHashSet.add(policyValidationDataThree);
    Mockito.when(apiMgtAdminService.getAllPolicies()).thenReturn(policyValidationDataHashSet);
    Response response = policiesApiService.policiesGet(null, getRequest());
    Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
    Assert.assertEquals(((PolicyListDTO) response.getEntity()).getList().size(), 3);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Response(javax.ws.rs.core.Response) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) PolicyListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.PolicyListDTO) PolicyValidationData(org.wso2.carbon.apimgt.core.models.PolicyValidationData) 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