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());
}
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);
}
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);
}
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");
}
}
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());
}
}
Aggregations