Search in sources :

Example 81 with Application

use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.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);
}
Also used : APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO)

Example 82 with Application

use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.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;
}
Also used : Application(org.wso2.carbon.apimgt.core.models.Application)

Example 83 with Application

use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.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");
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) BlockConditions(org.wso2.carbon.apimgt.core.models.BlockConditions) UUID(java.util.UUID) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Example 84 with Application

use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.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());
    }
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) CustomPolicy(org.wso2.carbon.apimgt.core.models.policy.CustomPolicy) APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Example 85 with Application

use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.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");
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) Iterator(java.util.Iterator) Workflow(org.wso2.carbon.apimgt.core.workflow.Workflow) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)156 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)143 Application (org.wso2.carbon.apimgt.api.model.Application)130 Application (org.wso2.carbon.apimgt.core.models.Application)121 Test (org.junit.Test)102 ArrayList (java.util.ArrayList)98 SQLException (java.sql.SQLException)94 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)94 PreparedStatement (java.sql.PreparedStatement)88 Connection (java.sql.Connection)83 ResultSet (java.sql.ResultSet)73 Subscriber (org.wso2.carbon.apimgt.api.model.Subscriber)71 HashMap (java.util.HashMap)70 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)63 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)63 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)61 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)60 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)59 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)58 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)57