use of org.wso2.carbon.identity.oauth.dcr.bean.Application in project carbon-apimgt by wso2.
the class TestUtil method subscribeToAPI.
/**
* Subscribe an application to given API
*
* @param api API to be subscribed to
* @param application Application to subscribe to the API
* @return {@link Subscription} object
* @throws APIManagementException If failed to add subscription.
*/
public static Subscription subscribeToAPI(API api, Application application) throws APIManagementException {
APISubscriptionDAO subscriptionDAO = DAOFactory.getAPISubscriptionDAO();
String subscriptionId = UUID.randomUUID().toString();
subscriptionDAO.addAPISubscription(subscriptionId, api.getId(), application.getId(), api.getPolicies().iterator().next().getUuid(), APIMgtConstants.SubscriptionStatus.ACTIVE);
return subscriptionDAO.getAPISubscription(subscriptionId);
}
use of org.wso2.carbon.identity.oauth.dcr.bean.Application in project carbon-apimgt by wso2.
the class TestUtil method createSummaryApplication.
/**
* Create a summary Applocation only with Application ID, Name, Callback URL, Application Owner and Status
*
* @param app Complete Application object
* @return Summary Application object
*/
public static Application createSummaryApplication(Application app) {
Application summaryApp = new Application(app.getName(), app.getCreatedUser());
summaryApp.setId(app.getId());
summaryApp.setStatus(app.getStatus());
return summaryApp;
}
use of org.wso2.carbon.identity.oauth.dcr.bean.Application in project carbon-apimgt by wso2.
the class PolicyDAOImplIT method testValidityOfBlockCondition.
@Test
public void testValidityOfBlockCondition() throws Exception {
PolicyDAO policyDAO = DAOFactory.getPolicyDAO();
BlockConditions blockConditionIPRange = SampleTestObjectCreator.createDefaultBlockCondition(APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITION_IP_RANGE);
BlockConditions blockConditionAPI = SampleTestObjectCreator.createDefaultBlockCondition(APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITIONS_API);
BlockConditions blockConditionsApp = SampleTestObjectCreator.createDefaultBlockCondition(APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITIONS_APPLICATION);
// Making starting IP > ending IP
blockConditionIPRange.setStartingIP("12.34.13.12");
blockConditionIPRange.setEndingIP("10.32.44.32");
// Giving invalid API context
blockConditionAPI.setConditionValue("invalid");
// giving invalid app name and invalid UUID
String[] appArray = blockConditionsApp.getConditionValue().split(":");
UUID appUuid = UUID.randomUUID();
String appName = appArray[1];
blockConditionsApp.setConditionValue(appUuid + ":" + appName);
try {
policyDAO.addBlockConditions(blockConditionIPRange);
} catch (APIMgtDAOException ex) {
Assert.assertEquals(ex.getMessage(), "Couldn't Save Block Condition Due to Invalid IP Range -> Starting IP : " + blockConditionIPRange.getStartingIP() + " EndingIP : " + blockConditionIPRange.getEndingIP());
}
try {
policyDAO.addBlockConditions(blockConditionAPI);
} catch (APIMgtDAOException ex) {
Assert.assertEquals(ex.getMessage(), "Couldn't Save Block Condition Due to Invalid API Context : " + blockConditionAPI.getConditionValue());
}
try {
policyDAO.addBlockConditions(blockConditionsApp);
} catch (APIMgtDAOException ex) {
Assert.assertEquals(ex.getMessage(), "Couldn't Save Block Condition Due to Invalid Application : " + appName + ", UUID :" + appUuid);
}
// Making IP block condition valid and add twice to check if it shows already existing
blockConditionIPRange.setEndingIP("29.23.12.12");
policyDAO.addBlockConditions(blockConditionIPRange);
try {
policyDAO.addBlockConditions(blockConditionIPRange);
} catch (APIMgtDAOException ex) {
Assert.assertEquals(ex.getMessage(), "Condition with type: " + blockConditionIPRange.getConditionType() + ", value: " + blockConditionIPRange.getConditionValue() + " already exists");
}
}
use of org.wso2.carbon.identity.oauth.dcr.bean.Application in project carbon-apimgt by wso2.
the class PolicyDAOImplIT method testAddGetAndDeleteApplicationPolicy.
@Test(description = "Add, Get and Delete an Application policy")
public void testAddGetAndDeleteApplicationPolicy() throws Exception {
ApplicationPolicy policy = SampleTestObjectCreator.createDefaultApplicationPolicy();
PolicyDAO policyDAO = DAOFactory.getPolicyDAO();
// add policy
policyDAO.addApplicationPolicy(policy);
// get added policy
Policy addedPolicy = policyDAO.getApplicationPolicy(policy.getPolicyName());
Assert.assertNotNull(addedPolicy);
Assert.assertEquals(addedPolicy.getPolicyName(), policy.getPolicyName());
// delete policy
policyDAO.deletePolicy(APIMgtAdminService.PolicyLevel.application, policy.getPolicyName());
// get policy after deletion
try {
policyDAO.getApplicationPolicy(policy.getPolicyName());
Assert.fail("Exception expected, but not thrown.");
} catch (APIMgtDAOException ex) {
Assert.assertEquals(ex.getMessage(), "Application Policy not found for name: " + addedPolicy.getPolicyName());
}
try {
policyDAO.getApplicationPolicyByUuid(policy.getUuid());
Assert.fail("Exception expected, but not thrown.");
} catch (APIMgtDAOException ex) {
Assert.assertEquals(ex.getMessage(), "Application Policy not found for id: " + addedPolicy.getUuid());
}
}
use of org.wso2.carbon.identity.oauth.dcr.bean.Application in project carbon-apimgt by wso2.
the class WorkflowDAOIT method testGetWorkflowsList.
@Test
public void testGetWorkflowsList() throws Exception {
WorkflowDAO workflowDAO = DAOFactory.getWorkflowDAO();
// pending application 1
String workflowExtRefId1 = UUID.randomUUID().toString();
String applicationId1 = UUID.randomUUID().toString();
Workflow workflow1 = SampleTestObjectCreator.createWorkflow(workflowExtRefId1);
workflow1.setWorkflowType(WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION);
workflow1.setWorkflowReference(applicationId1);
workflow1.setStatus(WorkflowStatus.CREATED);
workflowDAO.addWorkflowEntry(workflow1);
// pending application 2
String workflowExtRefId2 = UUID.randomUUID().toString();
String applicationId2 = UUID.randomUUID().toString();
Workflow workflow2 = SampleTestObjectCreator.createWorkflow(workflowExtRefId2);
workflow2.setWorkflowType(WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION);
workflow2.setWorkflowReference(applicationId2);
workflow2.setStatus(WorkflowStatus.CREATED);
workflowDAO.addWorkflowEntry(workflow2);
// completed application 1
String workflowExtRefId3 = UUID.randomUUID().toString();
String applicationId3 = UUID.randomUUID().toString();
Workflow workflow3 = SampleTestObjectCreator.createWorkflow(workflowExtRefId3);
workflow3.setWorkflowType(WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION);
workflow3.setWorkflowReference(applicationId3);
workflow3.setStatus(WorkflowStatus.APPROVED);
workflowDAO.addWorkflowEntry(workflow3);
// pending subscription 1
String workflowExtRefId4 = UUID.randomUUID().toString();
String applicationId4 = UUID.randomUUID().toString();
Workflow workflow4 = SampleTestObjectCreator.createWorkflow(workflowExtRefId4);
workflow4.setWorkflowType(WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION);
workflow4.setWorkflowReference(applicationId4);
workflow4.setStatus(WorkflowStatus.CREATED);
workflowDAO.addWorkflowEntry(workflow4);
// completed subscription 1
String workflowExtRefId5 = UUID.randomUUID().toString();
String applicationId5 = UUID.randomUUID().toString();
Workflow workflow5 = SampleTestObjectCreator.createWorkflow(workflowExtRefId5);
workflow5.setWorkflowType(WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION);
workflow5.setWorkflowReference(applicationId5);
workflow5.setStatus(WorkflowStatus.APPROVED);
workflowDAO.addWorkflowEntry(workflow5);
List<Workflow> list = workflowDAO.retrieveUncompleteWorkflows(WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION);
for (Iterator iterator = list.iterator(); iterator.hasNext(); ) {
Workflow workflow = (Workflow) iterator.next();
// check whether there are any completed workflows
Assert.assertFalse(WorkflowStatus.APPROVED == workflow.getStatus(), "Retrieved list contains approved workflows");
// check whether it has subscription workflow entry
Assert.assertFalse(WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION.equals(workflow.getWorkflowType()), "Application workflow list contains subscription workflow entry");
}
// get all the pending workflows
List<Workflow> fullList = workflowDAO.retrieveUncompleteWorkflows();
Assert.assertEquals(fullList.size(), 3, "Retrived workflow list does not contain valid entires");
}
Aggregations