use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testGetPolicies.
@Test(description = "Get all policies of a specific policy level")
public void testGetPolicies() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIStore apiStore = getApiStoreImpl(policyDAO);
apiStore.getPolicies(APIMgtAdminService.PolicyLevel.application);
Mockito.verify(policyDAO, Mockito.times(1)).getPoliciesByLevel(APIMgtAdminService.PolicyLevel.application);
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetCustomRules.
@Test(description = "Test getting custom rules")
public void testGetCustomRules() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
List<CustomPolicy> customPolicyListExpected = new ArrayList<>();
CustomPolicy customPolicy = SampleTestObjectCreator.createDefaultCustomPolicy();
customPolicyListExpected.add(customPolicy);
Mockito.when(policyDAO.getCustomPolicies()).thenReturn(customPolicyListExpected);
List<CustomPolicy> customPolicyListReturned = adminService.getCustomRules();
Assert.assertEquals(customPolicyListReturned, customPolicyListExpected);
// Error path
Mockito.when(policyDAO.getCustomPolicies()).thenThrow(APIMgtDAOException.class);
try {
adminService.getCustomRules();
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't get list of custom policy.");
}
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testDeletePolicyByUuid.
@Test(description = "Test delete policy by UUID")
public void testDeletePolicyByUuid() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
APIPolicy apiPolicy = SampleTestObjectCreator.createDefaultAPIPolicy();
adminService.deletePolicyByUuid(apiPolicy.getUuid(), APIMgtAdminService.PolicyLevel.api);
// Error path
Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).deletePolicyByUuid(APIMgtAdminService.PolicyLevel.api, apiPolicy.getUuid());
try {
adminService.deletePolicyByUuid(apiPolicy.getUuid(), APIMgtAdminService.PolicyLevel.api);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't delete policy with id: " + apiPolicy.getUuid() + ", level: " + APIMgtAdminService.PolicyLevel.api);
}
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUpdateAPIWithRestrictedVisibilityButDifferentContext.
@Test(description = "Test UpdateAPI with restricted visibility but different context")
public void testUpdateAPIWithRestrictedVisibilityButDifferentContext() throws APIManagementException {
Set<String> visibleRoles = new HashSet<>();
visibleRoles.add(ADMIN_ROLE);
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
API.APIBuilder api = SampleTestObjectCreator.createDefaultAPI().visibility(API.Visibility.RESTRICTED).visibleRoles(visibleRoles);
String uuid = api.getId();
APIGateway gateway = Mockito.mock(APIGateway.class);
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, APIMgtConstants.DEFAULT_API_POLICY)).thenReturn(new APIPolicy(APIMgtConstants.DEFAULT_API_POLICY));
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, GOLD_TIER)).thenReturn(new SubscriptionPolicy(GOLD_TIER));
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, SILVER_TIER)).thenReturn(new SubscriptionPolicy(SILVER_TIER));
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, BRONZE_TIER)).thenReturn(new SubscriptionPolicy(BRONZE_TIER));
APIPublisherImpl apiPublisher = getApiPublisherImpl(identityProvider, apiDAO, apiLifecycleManager, gatewaySourceGenerator, gateway, policyDAO);
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api.build());
Mockito.when(apiDAO.getApiSwaggerDefinition(api.getId())).thenReturn(SampleTestObjectCreator.apiDefinition);
Mockito.when(identityProvider.getRoleId(ADMIN_ROLE)).thenReturn(ADMIN_ROLE_ID);
Mockito.when(identityProvider.getRoleId(DEVELOPER_ROLE)).thenReturn(DEVELOPER_ROLE_ID);
apiPublisher.updateAPI(api.context("testContext"));
Mockito.verify(apiDAO, Mockito.times(1)).getAPI(uuid);
Mockito.verify(apiDAO, Mockito.times(1)).isAPIContextExists(api.getContext());
Mockito.verify(apiDAO, Mockito.times(1)).updateAPI(uuid, api.build());
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testUpdateApplicationPolicy.
@Test(description = "Test update application policy")
public void testUpdateApplicationPolicy() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
ApplicationPolicy applicationPolicy = SampleTestObjectCreator.createDefaultApplicationPolicy();
adminService.updateApplicationPolicy(applicationPolicy);
Mockito.verify(policyDAO, Mockito.times(1)).updateApplicationPolicy(applicationPolicy);
// Error path
Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).updateApplicationPolicy(applicationPolicy);
try {
adminService.updateApplicationPolicy(applicationPolicy);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't update Application policy for uuid: " + applicationPolicy.getUuid());
}
}
Aggregations