Search in sources :

Example 11 with GeneralWorkflowResponse

use of org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse in project carbon-apimgt by wso2.

the class APIStoreImplTestCase method testAddApplicationWorkflowReject.

@Test(description = "Test Application workflow rejection")
public void testAddApplicationWorkflowReject() throws APIManagementException {
    ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
    Policy policy = Mockito.mock(Policy.class);
    APIGateway apiGateway = Mockito.mock(APIGateway.class);
    APIStore apiStore = getApiStoreImpl(applicationDAO, policyDAO, workflowDAO, apiGateway);
    Application application = new Application(APP_NAME, USER_NAME);
    application.setPolicy(new ApplicationPolicy(TIER));
    application.setPermissionString("[{\"groupId\": \"testGroup\",\"permission\":[\"READ\",\"UPDATE\",\"DELETE\",\"SUBSCRIPTION\"]}]");
    Mockito.when(applicationDAO.isApplicationNameExists(APP_NAME)).thenReturn(false);
    Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, TIER)).thenReturn(policy);
    apiStore.addApplication(application);
    DefaultWorkflowExecutor executor = Mockito.mock(DefaultWorkflowExecutor.class);
    Workflow workflow = new ApplicationCreationWorkflow(applicationDAO, workflowDAO, apiGateway);
    workflow.setWorkflowReference(application.getId());
    WorkflowResponse response = new GeneralWorkflowResponse();
    response.setWorkflowStatus(WorkflowStatus.REJECTED);
    Mockito.when(executor.complete(workflow)).thenReturn(response);
    apiStore.completeWorkflow(executor, workflow);
    Mockito.verify(applicationDAO, Mockito.times(1)).updateApplicationState(application.getId(), "REJECTED");
}
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) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Workflow(org.wso2.carbon.apimgt.core.workflow.Workflow) ApplicationCreationWorkflow(org.wso2.carbon.apimgt.core.workflow.ApplicationCreationWorkflow) ApplicationUpdateWorkflow(org.wso2.carbon.apimgt.core.workflow.ApplicationUpdateWorkflow) SubscriptionCreationWorkflow(org.wso2.carbon.apimgt.core.workflow.SubscriptionCreationWorkflow) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) DefaultWorkflowExecutor(org.wso2.carbon.apimgt.core.workflow.DefaultWorkflowExecutor) WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) ApplicationCreationWorkflow(org.wso2.carbon.apimgt.core.workflow.ApplicationCreationWorkflow) WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) Application(org.wso2.carbon.apimgt.core.models.Application) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 12 with GeneralWorkflowResponse

use of org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse in project carbon-apimgt by wso2.

the class SubscriptionsApiServiceImplTestCase method testSubscriptionsSubscriptionIdDelete.

@Test
public void testSubscriptionsSubscriptionIdDelete() throws APIManagementException, NotFoundException {
    TestUtil.printTestMethodName();
    String subsID1 = UUID.randomUUID().toString();
    SubscriptionsApiServiceImpl subscriptionsApiService = new SubscriptionsApiServiceImpl();
    APIStore apiStore = Mockito.mock(APIStoreImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
    Request request = TestUtil.getRequest();
    PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
    WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
    workflowResponse.setWorkflowStatus(WorkflowStatus.APPROVED);
    Mockito.when(apiStore.deleteAPISubscription(subsID1)).thenReturn(workflowResponse);
    Response response = subscriptionsApiService.subscriptionsSubscriptionIdDelete(subsID1, null, null, request);
    Assert.assertEquals(200, response.getStatus());
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Response(javax.ws.rs.core.Response) Request(org.wso2.msf4j.Request) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with GeneralWorkflowResponse

use of org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse in project carbon-apimgt by wso2.

the class DefaultWorkflowExecutor method complete.

/**
 * Complete the external process status
 * Based on the workflow status we will update the status column of the
 * Application table
 *
 * @param workFlow - Workflow
 */
public WorkflowResponse complete(Workflow workFlow) throws WorkflowException {
    if (log.isDebugEnabled()) {
        log.debug("Executing complete() in Workflow for " + workFlow.getWorkflowType());
    }
    WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
    workflowResponse.setWorkflowStatus(workFlow.getStatus());
    return workflowResponse;
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse)

Example 14 with GeneralWorkflowResponse

use of org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse in project carbon-apimgt by wso2.

the class DefaultWorkflowExecutor method execute.

/**
 * {@inheritDoc}
 */
@Override
public WorkflowResponse execute(Workflow workFlow) throws WorkflowException {
    if (log.isDebugEnabled()) {
        log.debug("Executing execute() in Workflow for " + workFlow.getWorkflowType());
    }
    WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
    // set the state to approved
    workflowResponse.setWorkflowStatus(WorkflowStatus.APPROVED);
    return workflowResponse;
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse)

Example 15 with GeneralWorkflowResponse

use of org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse in project carbon-apimgt by wso2.

the class ApplicationsApiServiceImplTestCase method testApplicationsPostErrorCase.

@Test
public void testApplicationsPostErrorCase() throws APIManagementException, NotFoundException {
    TestUtil.printTestMethodName();
    String applicationId = UUID.randomUUID().toString();
    String accessToken = UUID.randomUUID().toString();
    String clientID = UUID.randomUUID().toString();
    String clientSecret = UUID.randomUUID().toString();
    ApplicationsApiServiceImpl applicationsApiService = new ApplicationsApiServiceImpl();
    APIStore apiStore = Mockito.mock(APIStoreImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
    Request request = getRequest();
    PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
    Application application = getSampleApplication(applicationId);
    WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
    workflowResponse.setWorkflowStatus(WorkflowStatus.APPROVED);
    ApplicationCreationResponse creationResponse = new ApplicationCreationResponse(UUID.randomUUID().toString(), workflowResponse);
    Mockito.when(apiStore.addApplication(application)).thenReturn(creationResponse);
    Mockito.when(apiStore.getApplication(creationResponse.getApplicationUUID(), USER)).thenReturn(application);
    ApplicationTokenDTO applicationTokenDTO = new ApplicationTokenDTO();
    applicationTokenDTO.setAccessToken(accessToken);
    applicationTokenDTO.setTokenScopes("SCOPE1");
    applicationTokenDTO.setValidityTime((long) 100000);
    List<String> grantTypes = new ArrayList<>();
    grantTypes.add("password");
    grantTypes.add("jwt");
    ApplicationKeysDTO applicationKeysDTO = new ApplicationKeysDTO();
    applicationKeysDTO.setConsumerKey(clientID);
    applicationKeysDTO.setConsumerSecret(clientSecret);
    applicationKeysDTO.setKeyType(ApplicationKeysDTO.KeyTypeEnum.PRODUCTION);
    applicationKeysDTO.setCallbackUrl(null);
    applicationKeysDTO.setSupportedGrantTypes(grantTypes);
    List<ApplicationKeysDTO> applicationKeysDTOList = new ArrayList<>();
    applicationKeysDTOList.add(applicationKeysDTO);
    ApplicationDTO applicationDTO = new ApplicationDTO();
    applicationDTO.setApplicationId(applicationId);
    applicationDTO.setDescription("sample application");
    applicationDTO.setName("app1");
    applicationDTO.setSubscriber("subscriber");
    applicationDTO.setPermission("permission");
    applicationDTO.setLifeCycleStatus("APPROVED");
    applicationDTO.setThrottlingTier("UNLIMITED");
    applicationDTO.setToken(applicationTokenDTO);
    applicationDTO.setKeys(applicationKeysDTOList);
    Response response = applicationsApiService.applicationsPost(applicationDTO, request);
    Assert.assertEquals(201, response.getStatus());
}
Also used : ApplicationDTO(org.wso2.carbon.apimgt.rest.api.store.dto.ApplicationDTO) ApplicationTokenDTO(org.wso2.carbon.apimgt.rest.api.store.dto.ApplicationTokenDTO) ApplicationCreationResponse(org.wso2.carbon.apimgt.core.workflow.ApplicationCreationResponse) Request(org.wso2.msf4j.Request) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) ArrayList(java.util.ArrayList) WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) ApplicationCreationResponse(org.wso2.carbon.apimgt.core.workflow.ApplicationCreationResponse) Response(javax.ws.rs.core.Response) ApplicationKeysDTO(org.wso2.carbon.apimgt.rest.api.store.dto.ApplicationKeysDTO) WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Application(org.wso2.carbon.apimgt.core.models.Application) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)19 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)15 Response (javax.ws.rs.core.Response)8 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)8 Test (org.testng.annotations.Test)6 Request (org.wso2.msf4j.Request)5 HashMap (java.util.HashMap)4 Application (org.wso2.carbon.apimgt.core.models.Application)4 ApplicationCreationResponse (org.wso2.carbon.apimgt.core.workflow.ApplicationCreationResponse)4 ArrayList (java.util.ArrayList)3 BeforeTest (org.testng.annotations.BeforeTest)3 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)3 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)3 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)3 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)3 WorkflowDAO (org.wso2.carbon.apimgt.core.dao.WorkflowDAO)3 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)3 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)3