use of org.wso2.carbon.apimgt.core.dao.ApplicationDAO in project carbon-apimgt by wso2.
the class TestUtil method addCustomApplication.
public static Application addCustomApplication(String applicationName, String owner) throws APIMgtDAOException {
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
Application application = SampleTestObjectCreator.createCustomApplication(applicationName, owner);
applicationDAO.addApplication(application);
return application;
}
use of org.wso2.carbon.apimgt.core.dao.ApplicationDAO in project carbon-apimgt by wso2.
the class SubscriptionDAOImplIT method testGetSubscriptionForApplicationAndKeyType.
@Test
public void testGetSubscriptionForApplicationAndKeyType() throws Exception {
// add test apis, apps and subscriptions
// app1: api2
// app2: api1, api2, api3
// app3: api3
// app4: api1, api2, api3, api4
ApisAndApps apisAndApps = createApisAppsAndSubscriptions();
APISubscriptionDAO subscriptionDAO = DAOFactory.getAPISubscriptionDAO();
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
API api2 = apisAndApps.getApis().get(1);
Application app1 = apisAndApps.getApps().get(0);
registerOAuthAppForApplication(applicationDAO, "client-key-for-app-1", app1.getId());
// get subscriptions of app1-PRODUCTION
List<SubscriptionValidationData> subscriptionValidationDataProd = subscriptionDAO.getAPISubscriptionsOfAppForValidation(app1.getId(), "PRODUCTION");
// validate subscriptions
Assert.assertEquals(subscriptionValidationDataProd.size(), 1, "There should be 1 subscriptions (only).");
SubscriptionValidationData validationData = subscriptionValidationDataProd.get(0);
Assert.assertNotNull(validationData);
Assert.assertEquals(validationData.getApiName(), api2.getName());
Assert.assertEquals(validationData.getApiVersion(), api2.getVersion());
Assert.assertEquals(validationData.getApplicationId(), app1.getId());
Assert.assertEquals(validationData.getKeyEnvType(), "PRODUCTION");
// list subscriptions for app1-SANDBOX
List<SubscriptionValidationData> subscriptionValidationDataSandbox = subscriptionDAO.getAPISubscriptionsOfAppForValidation(app1.getId(), "SANDBOX");
Assert.assertEquals(subscriptionValidationDataSandbox.size(), 0, "There shouldn't be any subscriptions.");
}
use of org.wso2.carbon.apimgt.core.dao.ApplicationDAO 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.apimgt.core.dao.ApplicationDAO 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.apimgt.core.dao.ApplicationDAO 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);
}
Aggregations