use of org.wso2.carbon.apimgt.api.model.policy.Policy in project carbon-apimgt by wso2.
the class ThreatProtectionDAOImplIT method testPolicyExists.
@Test
public void testPolicyExists() throws Exception {
ThreatProtectionPolicy policy = SampleTestObjectCreator.createUniqueThreatProtectionPolicy();
ThreatProtectionDAO dao = DAOFactory.getThreatProtectionDAO();
dao.addPolicy(policy);
Assert.assertEquals(dao.isPolicyExists(policy.getUuid()), true);
ThreatProtectionPolicy policy2 = SampleTestObjectCreator.createUniqueThreatProtectionPolicy();
Assert.assertEquals(dao.isPolicyExists(policy2.getUuid()), false);
}
use of org.wso2.carbon.apimgt.api.model.policy.Policy in project carbon-apimgt by wso2.
the class ThreatProtectionDAOImplIT method testAddPolicy.
@Test
public void testAddPolicy() throws Exception {
ThreatProtectionPolicy policy = SampleTestObjectCreator.createUniqueThreatProtectionPolicy();
ThreatProtectionDAO dao = DAOFactory.getThreatProtectionDAO();
dao.addPolicy(policy);
ThreatProtectionPolicy fromDb = dao.getPolicy(policy.getUuid());
Assert.assertEquals(fromDb.getUuid(), policy.getUuid());
Assert.assertEquals(fromDb.getName(), policy.getName());
Assert.assertEquals(fromDb.getType(), policy.getType());
Assert.assertEquals(fromDb.getPolicy(), policy.getPolicy());
}
use of org.wso2.carbon.apimgt.api.model.policy.Policy in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddApplicationNullPolicy.
@Test(description = "Add an application with null policy", expectedExceptions = APIManagementException.class)
public void testAddApplicationNullPolicy() throws Exception {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
APIStore apiStore = getApiStoreImpl(applicationDAO, policyDAO, workflowDAO);
Application application = new Application(APP_NAME, USER_NAME);
application.setPolicy(new ApplicationPolicy(TIER));
Mockito.when(applicationDAO.isApplicationNameExists(APP_NAME)).thenReturn(false);
Mockito.when(policyDAO.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, TIER)).thenReturn(null);
apiStore.addApplication(application);
}
use of org.wso2.carbon.apimgt.api.model.policy.Policy in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testGetAPIWithNotAllowedLifecycleStates.
@Test(description = "Test get API with not allowed lifecycle states (Created, Maintenance, Retired)")
public void testGetAPIWithNotAllowedLifecycleStates() throws APIManagementException {
String exceptionShouldThrowError = "Exception should be thrown when accessing an API in %s state";
String matchedErrorMessage = "Attempt to access an API which is in a restricted state";
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
Policy policy = new SubscriptionPolicy(UUID, TIER);
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, TIER)).thenReturn(policy);
APIStore apiStore = getApiStoreImpl(apiDAO, Mockito.mock(ApplicationDAO.class), Mockito.mock(APISubscriptionDAO.class), Mockito.mock(WorkflowDAO.class), Mockito.mock(APIGateway.class), policyDAO);
API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI();
String apiId = apiBuilder.getId();
List<String> notAllowedStates = new ArrayList<String>() {
{
add(APIStatus.CREATED.getStatus());
add(APIStatus.MAINTENANCE.getStatus());
add(APIStatus.RETIRED.getStatus());
}
};
for (String notAllowedState : notAllowedStates) {
apiBuilder.lifeCycleStatus(notAllowedState);
API api = apiBuilder.build();
Mockito.when(apiDAO.getAPI(apiId)).thenReturn(api);
try {
apiStore.getAPIbyUUID(apiId);
Assert.fail(exceptionShouldThrowError);
} catch (APIManagementException e) {
Assert.assertTrue(e.getMessage().contains(matchedErrorMessage));
}
}
}
use of org.wso2.carbon.apimgt.api.model.policy.Policy in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testGetPolicy.
@Test(description = "Get policy given policy name and policy level")
public void testGetPolicy() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIStore apiStore = getApiStoreImpl(policyDAO);
apiStore.getPolicy(APIMgtAdminService.PolicyLevel.application, POLICY_NAME);
Mockito.verify(policyDAO, Mockito.times(1)).getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, POLICY_NAME);
}
Aggregations