use of org.wso2.carbon.apimgt.api.model.policy.APIPolicy in project carbon-apimgt by wso2.
the class PolicyDAOImplIT method testAddGetAndDeleteApiPolicy.
@Test(description = "Add, Get and Delete an API policy")
public void testAddGetAndDeleteApiPolicy() throws Exception {
APIPolicy policy = SampleTestObjectCreator.createDefaultAPIPolicy();
PolicyDAO policyDAO = DAOFactory.getPolicyDAO();
// add policy
policyDAO.addApiPolicy(policy);
// get added policy
Policy addedPolicy = policyDAO.getApiPolicy(policy.getPolicyName());
Assert.assertNotNull(addedPolicy);
Assert.assertEquals(addedPolicy.getPolicyName(), policy.getPolicyName());
// delete policy
policyDAO.deletePolicy(APIMgtAdminService.PolicyLevel.api, policy.getPolicyName());
// get policy after deletion
try {
policyDAO.getApiPolicy(policy.getPolicyName());
Assert.fail("Exception expected, but not thrown.");
} catch (APIMgtDAOException ex) {
Assert.assertEquals(ex.getMessage(), "API Policy not found for name: " + addedPolicy.getPolicyName());
}
try {
policyDAO.getApiPolicyByUuid(policy.getUuid());
Assert.fail("Exception expected, but not thrown.");
} catch (APIMgtDAOException ex) {
Assert.assertEquals(ex.getMessage(), "API Policy not found for id: " + addedPolicy.getUuid());
}
}
use of org.wso2.carbon.apimgt.api.model.policy.APIPolicy in project carbon-apimgt by wso2.
the class PolicyDAOImplIT method testGetAllPolicies.
@Test
public void testGetAllPolicies() throws Exception {
PolicyDAO policyDAO = DAOFactory.getPolicyDAO();
int size = policyDAO.getAllPolicies().size();
APIPolicy apiPolicy = SampleTestObjectCreator.createDefaultAPIPolicy();
ApplicationPolicy applicationPolicy = SampleTestObjectCreator.createDefaultApplicationPolicy();
SubscriptionPolicy subscriptionPolicy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
policyDAO.addApiPolicy(apiPolicy);
policyDAO.addApplicationPolicy(applicationPolicy);
policyDAO.addSubscriptionPolicy(subscriptionPolicy);
Set<PolicyValidationData> policyValidationData = policyDAO.getAllPolicies();
Assert.assertTrue(policyValidationData.size() == size + 3);
}
use of org.wso2.carbon.apimgt.api.model.policy.APIPolicy in project carbon-apimgt by wso2.
the class PolicyDAOImplIT method testGetAPIPolicyWithBandwidthLimit.
@Test(description = "Get API Policies with bandwidth limit")
public void testGetAPIPolicyWithBandwidthLimit() throws Exception {
APIPolicy policy = SampleTestObjectCreator.createDefaultAPIPolicyWithBandwidthLimit();
PolicyDAO policyDAO = DAOFactory.getPolicyDAO();
// add policy
policyDAO.addApiPolicy(policy);
Policy policyAdded = policyDAO.getApiPolicy(policy.getPolicyName());
Assert.assertNotNull(policyAdded);
Assert.assertEquals(policyAdded.getPolicyName(), policy.getPolicyName());
}
use of org.wso2.carbon.apimgt.api.model.policy.APIPolicy in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUpdateAPIWithRestrictedVisibility.
@Test(description = "Test UpdateAPI with restricted visibility")
public void testUpdateAPIWithRestrictedVisibility() throws APIManagementException, LifecycleException {
Set<String> visibleRoles = new HashSet<>();
visibleRoles.add(ADMIN_ROLE);
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
API.APIBuilder api = SampleTestObjectCreator.createDefaultAPI().visibility(API.Visibility.RESTRICTED).visibleRoles(visibleRoles);
String uuid = api.getId();
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
IdentityProvider identityProvider = Mockito.mock(IdentityProvider.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.lifeCycleStatus(APIStatus.CREATED.getStatus()).build());
Mockito.when(apiDAO.isAPIContextExists(api.getContext())).thenReturn(true);
String configString = SampleTestObjectCreator.createSampleGatewayConfig();
Mockito.when(apiDAO.getGatewayConfigOfAPI(uuid)).thenReturn(configString);
Mockito.when(identityProvider.getRoleId(ADMIN_ROLE)).thenReturn(ADMIN_ROLE_ID);
Mockito.when(apiDAO.getApiSwaggerDefinition(api.getId())).thenReturn(SampleTestObjectCreator.apiDefinition);
Mockito.when(identityProvider.getRoleId(DEVELOPER_ROLE)).thenReturn(DEVELOPER_ROLE_ID);
apiPublisher.updateAPI(api.lifeCycleStatus(APIStatus.CREATED.getStatus()).id(uuid));
Mockito.verify(apiDAO, Mockito.times(1)).getAPI(uuid);
Mockito.verify(apiDAO, Mockito.times(0)).isAPIContextExists(api.getContext());
Mockito.verify(apiDAO, Mockito.times(1)).updateAPI(uuid, api.lifeCycleStatus(APIStatus.CREATED.getStatus()).build());
}
use of org.wso2.carbon.apimgt.api.model.policy.APIPolicy in project carbon-apimgt by wso2.
the class PoliciesApiServiceImplTest method policiesThrottlingAdvancedPolicyIdGetTest.
@Test
public void policiesThrottlingAdvancedPolicyIdGetTest() throws APIManagementException, NotFoundException {
printTestMethodName();
PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
String uuid = UUID.randomUUID().toString();
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
APIPolicy policy1 = new APIPolicy(uuid, "samplePolicy1");
policy1.setDescription("Sample Policy");
policy1.setDeployed(true);
policy1.setDisplayName("Simple Policy");
Mockito.doReturn(policy1).doThrow(new IllegalArgumentException()).when(adminService).getApiPolicyByUuid(uuid);
Response response = policiesApiService.policiesThrottlingAdvancedIdGet(uuid, null, null, getRequest());
Assert.assertEquals(response.getStatus(), 200);
}
Aggregations