use of org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddApplicationPermissionStringInvalid.
@Test(description = "Add an application with invalid permission String")
public void testAddApplicationPermissionStringInvalid() throws APIManagementException {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
Policy policy = Mockito.mock(Policy.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.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\":[\"TESTREAD\",\"TESTUPDATE\"]}]");
Mockito.when(applicationDAO.isApplicationNameExists(APP_NAME)).thenReturn(false);
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, TIER)).thenReturn(policy);
ApplicationCreationResponse applicationResponse = apiStore.addApplication(application);
String applicationUuid = applicationResponse.getApplicationUUID();
Assert.assertNotNull(applicationUuid);
Mockito.verify(applicationDAO, Mockito.times(1)).addApplication(application);
}
use of org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddApplicationNullTier.
@Test(description = "Add an application with null tier", expectedExceptions = APIManagementException.class)
public void testAddApplicationNullTier() 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(null));
Mockito.when(applicationDAO.isApplicationNameExists(APP_NAME)).thenReturn(false);
apiStore.addApplication(application);
}
use of org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddApplicationParsingException.
@Test(description = "Parse exception when adding an application", expectedExceptions = APIManagementException.class)
public void testAddApplicationParsingException() throws Exception {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
Policy policy = Mockito.mock(Policy.class);
APIStore apiStore = getApiStoreImpl(applicationDAO, policyDAO);
Application application = new Application(APP_NAME, USER_NAME);
application.setPolicy(new ApplicationPolicy(TIER));
application.setPermissionString("data");
Mockito.when(applicationDAO.isApplicationNameExists(APP_NAME)).thenReturn(false);
Mockito.when(policyDAO.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, TIER)).thenReturn(policy);
apiStore.addApplication(application);
}
use of org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testGetApplicationsException.
@Test(description = "Exception when retrieving applications", expectedExceptions = APIManagementException.class)
public void testGetApplicationsException() throws APIManagementException {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
APIStore apiStore = getApiStoreImpl(applicationDAO);
Mockito.when(applicationDAO.getApplications(USER_ID)).thenThrow(new APIMgtDAOException("Error occurred while fetching applications for the given subscriber - " + USER_ID, new SQLException()));
apiStore.getApplications(USER_ID);
}
use of org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddSubscription.
@Test(description = "Add subscription to an application")
public void testAddSubscription() throws APIManagementException {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.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, applicationDAO, apiSubscriptionDAO, workflowDAO, apiGateway, policyDAO);
API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI();
apiBuilder.lifeCycleStatus(APIStatus.PUBLISHED.getStatus());
API api = apiBuilder.build();
String apiId = api.getId();
Application application = new Application("TestApp", USER_ID);
application.setId(UUID);
Mockito.when(apiDAO.getAPI(apiId)).thenReturn(api);
Mockito.when(applicationDAO.getApplication(UUID)).thenReturn(application);
SubscriptionResponse subscriptionResponse = apiStore.addApiSubscription(apiId, UUID, TIER);
String subscriptionId = subscriptionResponse.getSubscriptionUUID();
Assert.assertNotNull(subscriptionId);
// before workflow add subscription with blocked state
Mockito.verify(apiSubscriptionDAO, Mockito.times(1)).addAPISubscription(subscriptionId, apiId, UUID, policy.getUuid(), APIMgtConstants.SubscriptionStatus.ON_HOLD);
// after workflow change the state
Mockito.verify(apiSubscriptionDAO, Mockito.times(1)).updateSubscriptionStatus(subscriptionId, APIMgtConstants.SubscriptionStatus.ACTIVE);
}
Aggregations