use of org.wso2.carbon.apimgt.core.api.APIGateway in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testUpdateSubscriptionPolicy.
@Test(description = "Test update subscription policy")
public void testUpdateSubscriptionPolicy() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
SubscriptionPolicy subscriptionPolicy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
adminService.updateSubscriptionPolicy(subscriptionPolicy);
Mockito.verify(policyDAO, Mockito.times(1)).updateSubscriptionPolicy(subscriptionPolicy);
// Error path
Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).updateSubscriptionPolicy(subscriptionPolicy);
try {
adminService.updateSubscriptionPolicy(subscriptionPolicy);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't update Subscription policy for uuid: " + subscriptionPolicy.getUuid());
}
}
use of org.wso2.carbon.apimgt.core.api.APIGateway in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUpdateScopeToApi.
@Test(description = "update existing Scope to API")
public void testUpdateScopeToApi() throws APIManagementException, IOException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
API api = SampleTestObjectCreator.createDefaultAPI().build();
String uuid = api.getId();
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
KeyManager keyManager = Mockito.mock(KeyManager.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(identityProvider, apiDAO, gatewaySourceGenerator, gateway, keyManager);
String oldSwagger = IOUtils.toString(new FileInputStream("src" + File.separator + "test" + File.separator + "resources" + File.separator + "swagger" + File.separator + "swaggerWithAuthorization" + ".yaml"));
Scope scope = new Scope("apim:api_create", "apim:api_create");
Mockito.when(apiDAO.getApiSwaggerDefinition(uuid)).thenReturn(oldSwagger);
Mockito.when(keyManager.updateScope(scope)).thenReturn(true);
Mockito.when(keyManager.retrieveScope("apim:api_create")).thenReturn(new Scope("apim:api_create", "Create " + "API"));
apiPublisher.updateScopeOfTheApi(api.getId(), scope);
}
use of org.wso2.carbon.apimgt.core.api.APIGateway in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testAddBlockCondition.
@Test(description = "Test adding block condition")
public void testAddBlockCondition() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
BlockConditions blockConditions = SampleTestObjectCreator.createDefaultBlockCondition(BLOCK_CONDITION_TYPE);
String uuid = adminService.addBlockCondition(blockConditions);
Assert.assertNotNull(uuid);
// Error path
Mockito.when(policyDAO.addBlockConditions(blockConditions)).thenThrow(APIMgtDAOException.class);
try {
adminService.addBlockCondition(blockConditions);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't add block condition with condition type: " + blockConditions.getConditionType() + ", condition value: " + blockConditions.getConditionValue());
}
}
use of org.wso2.carbon.apimgt.core.api.APIGateway in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testDeletePolicy.
@Test(description = "Test delete policy")
public void testDeletePolicy() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
APIPolicy apiPolicy = SampleTestObjectCreator.createDefaultAPIPolicy();
Mockito.when(policyDAO.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, apiPolicy.getPolicyName())).thenReturn(apiPolicy);
adminService.deletePolicy(apiPolicy.getPolicyName(), APIMgtAdminService.PolicyLevel.api);
Mockito.verify(policyDAO, Mockito.times(1)).getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, apiPolicy.getPolicyName());
Mockito.verify(policyDAO, Mockito.times(1)).deletePolicy(APIMgtAdminService.PolicyLevel.api, apiPolicy.getPolicyName());
// Error path
Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).deletePolicy(APIMgtAdminService.PolicyLevel.api, apiPolicy.getPolicyName());
try {
adminService.deletePolicy(apiPolicy.getPolicyName(), APIMgtAdminService.PolicyLevel.api);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't delete policy with name: " + apiPolicy.getPolicyName() + ", level: " + APIMgtAdminService.PolicyLevel.api);
}
}
use of org.wso2.carbon.apimgt.core.api.APIGateway in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testAddSubscriptionPolicy.
@Test(description = "Test add subscription policy")
public void testAddSubscriptionPolicy() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
SubscriptionPolicy policy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
adminService.addSubscriptionPolicy(policy);
Mockito.verify(policyDAO, Mockito.times(1)).addSubscriptionPolicy(policy);
// Error path
Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).addSubscriptionPolicy(policy);
try {
adminService.addSubscriptionPolicy(policy);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't add Subscription policy for uuid: " + policy.getUuid());
}
}
Aggregations