use of org.wso2.carbon.identity.oauth.dcr.bean.Application in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testUpdateApplication.
@Test(description = "Update an application")
public void testUpdateApplication() throws APIManagementException {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIStore apiStore = getApiStoreImpl(applicationDAO, policyDAO, workflowDAO, apiGateway);
Application existingApplication = SampleTestObjectCreator.createDefaultApplication();
String appUUID = existingApplication.getUuid();
existingApplication.setStatus(ApplicationStatus.APPLICATION_APPROVED);
Mockito.when(applicationDAO.getApplication(appUUID)).thenReturn(existingApplication);
// Updating the existing application
Application updatedApplication = SampleTestObjectCreator.createDefaultApplication();
updatedApplication.setDescription("updated description");
ApplicationPolicy applicationPolicy = SampleTestObjectCreator.createDefaultApplicationPolicy();
applicationPolicy.setPolicyName(TIER);
updatedApplication.setPolicy(applicationPolicy);
updatedApplication.setStatus(ApplicationStatus.APPLICATION_APPROVED);
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, applicationPolicy.getPolicyName())).thenReturn(applicationPolicy);
apiStore.updateApplication(appUUID, updatedApplication);
Mockito.verify(applicationDAO, Mockito.times(1)).updateApplication(appUUID, updatedApplication);
// Error
// APIMgtDAOException
Mockito.doThrow(APIMgtDAOException.class).when(applicationDAO).updateApplication(appUUID, updatedApplication);
try {
apiStore.updateApplication(appUUID, updatedApplication);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error occurred while updating the application - " + appUUID);
}
// Error path
// When specified tier in the updated application is invalid
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, applicationPolicy.getPolicyName())).thenReturn(null);
try {
apiStore.updateApplication(appUUID, updatedApplication);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Specified tier " + applicationPolicy + " is invalid");
}
}
use of org.wso2.carbon.identity.oauth.dcr.bean.Application 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.identity.oauth.dcr.bean.Application in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testGetApplicationByUUIDException.
@Test(description = "Exception when retrieving an application by uuid", expectedExceptions = APIManagementException.class)
public void testGetApplicationByUUIDException() throws APIManagementException {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
APIStore apiStore = getApiStoreImpl(applicationDAO);
Mockito.when(applicationDAO.getApplication(UUID)).thenThrow(new APIMgtDAOException("Error occurred while retrieving application - " + UUID, new SQLException()));
apiStore.getApplicationByUuid(UUID);
}
use of org.wso2.carbon.identity.oauth.dcr.bean.Application in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testCompleteApplicationWorkflowWithoutReference.
// End of exception testing
@Test(description = "Exception when completing application creation workflow without a reference", expectedExceptions = APIManagementException.class)
public void testCompleteApplicationWorkflowWithoutReference() throws Exception {
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
APIStore apiStore = getApiStoreImpl(applicationDAO, workflowDAO);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
WorkflowExecutor executor = new DefaultWorkflowExecutor();
Workflow workflow = new ApplicationCreationWorkflow(applicationDAO, workflowDAO, apiGateway);
workflow.setWorkflowReference(null);
apiStore.completeWorkflow(executor, workflow);
}
use of org.wso2.carbon.identity.oauth.dcr.bean.Application in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddApplicationUpdateWorkflowReject.
@Test(description = "Test Application update workflow reject")
public void testAddApplicationUpdateWorkflowReject() throws APIManagementException {
/*
* This test is to validate the rollback the application to its previous state for application
* update request rejection
*/
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
Policy policy = Mockito.mock(Policy.class);
APIStore apiStore = getApiStoreImpl(applicationDAO, policyDAO, workflowDAO);
Application application = new Application(APP_NAME, USER_NAME);
application.setStatus(ApplicationStatus.APPLICATION_APPROVED);
application.setPolicy(new ApplicationPolicy(TIER));
application.setId(UUID);
application.setPermissionString("[{\"groupId\": \"testGroup\",\"permission\":[\"READ\",\"UPDATE\",\"DELETE\",\"SUBSCRIPTION\"]}]");
Mockito.when(applicationDAO.isApplicationNameExists(APP_NAME)).thenReturn(false);
Mockito.when(policyDAO.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, TIER)).thenReturn(policy);
// following section mock the workflow callback api
DefaultWorkflowExecutor executor = Mockito.mock(DefaultWorkflowExecutor.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
Workflow workflow = new ApplicationUpdateWorkflow(applicationDAO, workflowDAO, apiGateway);
workflow.setWorkflowReference(application.getId());
workflow.setExternalWorkflowReference(UUID);
// validate the rejection flow
// here we assume the application is an approve state before update
// this attribute is set internally based on the workflow data
workflow.setAttribute(WorkflowConstants.ATTRIBUTE_APPLICATION_EXISTIN_APP_STATUS, ApplicationStatus.APPLICATION_APPROVED);
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(), ApplicationStatus.APPLICATION_APPROVED);
// here we assume the application is an rejected state before update.
workflow.setAttribute(WorkflowConstants.ATTRIBUTE_APPLICATION_EXISTIN_APP_STATUS, ApplicationStatus.APPLICATION_REJECTED);
apiStore.completeWorkflow(executor, workflow);
Mockito.verify(applicationDAO, Mockito.times(1)).updateApplicationState(application.getId(), ApplicationStatus.APPLICATION_REJECTED);
}
Aggregations