Search in sources :

Example 51 with APIMgtAdminServiceImpl

use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method apisApiIdGatewayConfigGetTestCase.

@Test
public void apisApiIdGatewayConfigGetTestCase() throws Exception {
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    String apiID = UUID.randomUUID().toString();
    String gatewayConfig = "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(adminService.getAPIGatewayServiceConfig(apiID)).thenReturn(gatewayConfig);
    APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
    PowerMockito.mockStatic(APIManagerFactory.class);
    PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
    Mockito.when(instance.getAPIMgtAdminService()).thenReturn(adminService);
    Response response = apisApiService.apisApiIdGatewayConfigGet(apiID, 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 52 with APIMgtAdminServiceImpl

use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.

the class ApplicationsApiServiceImplTestCase method applicationsGetTestCase.

@Test
public void applicationsGetTestCase() throws Exception {
    ApplicationsApiServiceImpl applicationsApiService = new ApplicationsApiServiceImpl();
    APIMgtAdminServiceImpl adminService = 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(adminService);
    List<Application> applicationList = new ArrayList<>();
    Application applicationOne = SampleTestObjectCreator.createRandomApplication();
    Application applicationTwo = SampleTestObjectCreator.createRandomApplication();
    Application applicationThree = SampleTestObjectCreator.createRandomApplication();
    applicationList.add(applicationOne);
    applicationList.add(applicationTwo);
    applicationList.add(applicationThree);
    Mockito.when(adminService.getAllApplications()).thenReturn(applicationList);
    Response response = applicationsApiService.applicationsGet(null, getRequest());
    Assert.assertEquals(response.getStatus(), 200);
    Assert.assertEquals(((ApplicationListDTO) 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) Application(org.wso2.carbon.apimgt.core.models.Application) ApplicationListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.ApplicationListDTO) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 53 with APIMgtAdminServiceImpl

use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.

the class BlacklistApiServiceImplTestCase method blacklistGetTestCase.

@Test
public void blacklistGetTestCase() throws Exception {
    APIMgtAdminServiceImpl adminService = 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(adminService);
    BlacklistApiServiceImpl blacklistApiService = new BlacklistApiServiceImpl();
    BlockConditions blockConditionOne = SampleTestObjectCreator.createUniqueBlockConditions("IP_RANGE");
    BlockConditions blockConditionTwo = SampleTestObjectCreator.createUniqueBlockConditions("IP");
    BlockConditions blockConditionThree = SampleTestObjectCreator.createUniqueBlockConditions("IP_RANGE");
    List<BlockConditions> blockConditions = new ArrayList<>();
    blockConditions.add(blockConditionOne);
    blockConditions.add(blockConditionTwo);
    blockConditions.add(blockConditionThree);
    Mockito.when(adminService.getBlockConditions()).thenReturn(blockConditions);
    Response response = blacklistApiService.blacklistGet(null, getRequest());
    Assert.assertEquals(response.getStatus(), 200);
    Assert.assertEquals(((BlockingConditionListDTO) response.getEntity()).getList().size(), 3);
}
Also used : Response(javax.ws.rs.core.Response) BlockingConditionListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionListDTO) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) BlockConditions(org.wso2.carbon.apimgt.core.models.BlockConditions) ArrayList(java.util.ArrayList) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 54 with APIMgtAdminServiceImpl

use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.

the class APIMgtAdminServiceImplTestCase method testGetAllApplications.

@Test(description = "Test getting all applications")
public void testGetAllApplications() throws APIManagementException {
    ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
    APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(applicationDAO);
    List<Application> applicationListExpected = new ArrayList<>();
    Application application = SampleTestObjectCreator.createDefaultApplication();
    applicationListExpected.add(application);
    Mockito.when(applicationDAO.getAllApplications()).thenReturn(applicationListExpected);
    List<Application> applicationListReturned = adminService.getAllApplications();
    Assert.assertEquals(applicationListReturned, applicationListExpected);
    // Error path
    Mockito.when(applicationDAO.getAllApplications()).thenThrow(APIMgtDAOException.class);
    try {
        adminService.getAllApplications();
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Error occurred while getting the Application list");
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ArrayList(java.util.ArrayList) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Application(org.wso2.carbon.apimgt.core.models.Application) Test(org.testng.annotations.Test)

Example 55 with APIMgtAdminServiceImpl

use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.

the class APIMgtAdminServiceImplTestCase method testDeleteCustomRule.

@Test(description = "Test deleting a custom rule")
public void testDeleteCustomRule() throws APIManagementException {
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
    CustomPolicy customPolicy = SampleTestObjectCreator.createDefaultCustomPolicy();
    adminService.deleteCustomRule(customPolicy.getUuid());
    // Error path
    Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).deleteCustomPolicy(customPolicy.getUuid());
    try {
        adminService.deleteCustomRule(customPolicy.getUuid());
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Couldn't delete custom policy with UUID: " + customPolicy.getUuid());
    }
}
Also used : CustomPolicy(org.wso2.carbon.apimgt.core.models.policy.CustomPolicy) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Aggregations

APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)67 Response (javax.ws.rs.core.Response)65 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)65 Test (org.junit.Test)59 Test (org.testng.annotations.Test)58 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)46 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)33 ArrayList (java.util.ArrayList)28 PoliciesApiServiceImpl (org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl)20 APIManagerFactory (org.wso2.carbon.apimgt.core.impl.APIManagerFactory)17 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)14 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)13 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)11 CustomPolicy (org.wso2.carbon.apimgt.core.models.policy.CustomPolicy)11 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)11 BlockConditions (org.wso2.carbon.apimgt.core.models.BlockConditions)10 Label (org.wso2.carbon.apimgt.core.models.Label)10 ThreatProtectionPolicy (org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy)9 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)6 LabelDAO (org.wso2.carbon.apimgt.core.dao.LabelDAO)6