use of org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO in project carbon-apimgt by wso2.
the class SubscriptionDAOImplIT method testAddAndGetSubscription.
@Test
public void testAddAndGetSubscription() throws Exception {
// add new app
Application app = TestUtil.addTestApplication();
// add new api
API api = TestUtil.addTestAPI();
// add subscription
String subscriptionTier = GOLD_TIER;
APISubscriptionDAO apiSubscriptionDAO = DAOFactory.getAPISubscriptionDAO();
String uuid = UUID.randomUUID().toString();
apiSubscriptionDAO.addAPISubscription(uuid, api.getId(), app.getId(), goldSubscriptionPolicy.getUuid(), APIMgtConstants.SubscriptionStatus.ACTIVE);
// get subscription
Subscription subscription = apiSubscriptionDAO.getAPISubscription(uuid);
// validate
Assert.assertNotNull(subscription);
Assert.assertEquals(subscription.getId(), uuid);
Assert.assertEquals(subscription.getStatus(), APIMgtConstants.SubscriptionStatus.ACTIVE);
Assert.assertEquals(subscription.getPolicy().getPolicyName(), subscriptionTier);
Assert.assertEquals(subscription.getApi(), TestUtil.createSummaryAPI(api), TestUtil.printDiff(subscription.getApi(), TestUtil.createSummaryAPI(api)));
Assert.assertEquals(subscription.getApplication(), TestUtil.createSummaryApplication(app), TestUtil.printDiff(subscription.getApplication(), TestUtil.createSummaryApplication(app)));
}
use of org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO in project carbon-apimgt by wso2.
the class SubscriptionDAOImplIT method testUpdateSubscription.
@Test
public void testUpdateSubscription() throws Exception {
// add new app
Application app = TestUtil.addTestApplication();
// add new api
API api = TestUtil.addTestAPI();
// add subscription
String subscriptionPolicy = GOLD_TIER;
APISubscriptionDAO apiSubscriptionDAO = DAOFactory.getAPISubscriptionDAO();
String uuid = UUID.randomUUID().toString();
apiSubscriptionDAO.addAPISubscription(uuid, api.getId(), app.getId(), goldSubscriptionPolicy.getUuid(), APIMgtConstants.SubscriptionStatus.ACTIVE);
// get subscription
Subscription subscription = apiSubscriptionDAO.getAPISubscription(uuid);
// validate fingerprint
String fingerprintBeforeUpdate = ETagUtils.generateETag(apiSubscriptionDAO.getLastUpdatedTimeOfSubscription(uuid));
Assert.assertNotNull(fingerprintBeforeUpdate);
// validate tier and status
Assert.assertNotNull(subscription);
Assert.assertEquals(subscription.getId(), uuid);
Assert.assertEquals(subscription.getStatus(), APIMgtConstants.SubscriptionStatus.ACTIVE);
Assert.assertEquals(subscription.getPolicy().getPolicyName(), subscriptionPolicy);
// update subscription policy
String newSubscriptionPolicy = SILVER_TIER;
apiSubscriptionDAO.updateSubscriptionPolicy(uuid, newSubscriptionPolicy);
// get subscription
subscription = apiSubscriptionDAO.getAPISubscription(uuid);
// validate
Assert.assertNotNull(subscription);
Assert.assertEquals(subscription.getId(), uuid);
Assert.assertEquals(subscription.getStatus(), APIMgtConstants.SubscriptionStatus.ACTIVE);
Assert.assertEquals(subscription.getPolicy().getPolicyName(), newSubscriptionPolicy);
Assert.assertEquals(subscription.getApi(), TestUtil.createSummaryAPI(api), TestUtil.printDiff(subscription.getApi(), TestUtil.createSummaryAPI(api)));
Assert.assertEquals(subscription.getApplication(), TestUtil.createSummaryApplication(app), TestUtil.printDiff(subscription.getApplication(), TestUtil.createSummaryApplication(app)));
// update subscription status
APIMgtConstants.SubscriptionStatus newSubscriptionStatus = APIMgtConstants.SubscriptionStatus.PROD_ONLY_BLOCKED;
apiSubscriptionDAO.updateSubscriptionStatus(uuid, newSubscriptionStatus);
// get subscription
subscription = apiSubscriptionDAO.getAPISubscription(uuid);
String fingerprintAfterUpdate = ETagUtils.generateETag(apiSubscriptionDAO.getLastUpdatedTimeOfSubscription(uuid));
// validate
Assert.assertNotNull(subscription);
Assert.assertNotNull(fingerprintAfterUpdate);
Assert.assertEquals(subscription.getId(), uuid);
Assert.assertEquals(subscription.getStatus(), newSubscriptionStatus);
Assert.assertEquals(subscription.getPolicy().getPolicyName(), newSubscriptionPolicy);
Assert.assertEquals(subscription.getApi(), TestUtil.createSummaryAPI(api), TestUtil.printDiff(subscription.getApi(), TestUtil.createSummaryAPI(api)));
Assert.assertEquals(subscription.getApplication(), TestUtil.createSummaryApplication(app), TestUtil.printDiff(subscription.getApplication(), TestUtil.createSummaryApplication(app)));
Assert.assertNotEquals(fingerprintBeforeUpdate, fingerprintAfterUpdate);
}
use of org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO in project carbon-apimgt by wso2.
the class SubscriptionDAOImplIT method createApisAppsAndSubscriptions.
private ApisAndApps createApisAppsAndSubscriptions() throws Exception {
List<Application> apps = new ArrayList<>();
// add 4 apps
String username = ADMIN;
Application app1 = TestUtil.addCustomApplication(APP_1, username);
apps.add(app1);
Application app2 = TestUtil.addCustomApplication(APP_2, username);
apps.add(app2);
Application app3 = TestUtil.addCustomApplication(APP_3, username);
apps.add(app3);
Application app4 = TestUtil.addCustomApplication(APP_4, username);
apps.add(app4);
// add 4 apis
List<API> apis = new ArrayList<>();
API api1 = TestUtil.addCustomAPI(API_1, API_VERSION, API1_CONTEXT);
apis.add(api1);
API api2 = TestUtil.addCustomAPI(API_2, API_VERSION, API2_CONTEXT);
apis.add(api2);
API api3 = TestUtil.addCustomAPI(API_3, API_VERSION, API3_CONTEXT);
apis.add(api3);
API api4 = TestUtil.addCustomAPI(API_4, API_VERSION, API4_CONTEXT);
apis.add(api4);
// Add subscriptions
APISubscriptionDAO subscriptionDAO = DAOFactory.getAPISubscriptionDAO();
// app1: api2
subscriptionDAO.addAPISubscription(UUID.randomUUID().toString(), api2.getId(), app1.getId(), goldSubscriptionPolicy.getUuid(), APIMgtConstants.SubscriptionStatus.ACTIVE);
// app2: api1, api2, api3
subscriptionDAO.addAPISubscription(UUID.randomUUID().toString(), api1.getId(), app2.getId(), goldSubscriptionPolicy.getUuid(), APIMgtConstants.SubscriptionStatus.ACTIVE);
subscriptionDAO.addAPISubscription(UUID.randomUUID().toString(), api2.getId(), app2.getId(), goldSubscriptionPolicy.getUuid(), APIMgtConstants.SubscriptionStatus.ACTIVE);
subscriptionDAO.addAPISubscription(UUID.randomUUID().toString(), api3.getId(), app2.getId(), goldSubscriptionPolicy.getUuid(), APIMgtConstants.SubscriptionStatus.ACTIVE);
// app3: api3
subscriptionDAO.addAPISubscription(UUID.randomUUID().toString(), api3.getId(), app3.getId(), goldSubscriptionPolicy.getUuid(), APIMgtConstants.SubscriptionStatus.ACTIVE);
// app4: api1, api2, api3, api4
subscriptionDAO.addAPISubscription(UUID.randomUUID().toString(), api1.getId(), app4.getId(), goldSubscriptionPolicy.getUuid(), APIMgtConstants.SubscriptionStatus.ACTIVE);
subscriptionDAO.addAPISubscription(UUID.randomUUID().toString(), api2.getId(), app4.getId(), goldSubscriptionPolicy.getUuid(), APIMgtConstants.SubscriptionStatus.ACTIVE);
subscriptionDAO.addAPISubscription(UUID.randomUUID().toString(), api3.getId(), app4.getId(), goldSubscriptionPolicy.getUuid(), APIMgtConstants.SubscriptionStatus.ACTIVE);
subscriptionDAO.addAPISubscription(UUID.randomUUID().toString(), api4.getId(), app4.getId(), goldSubscriptionPolicy.getUuid(), APIMgtConstants.SubscriptionStatus.ACTIVE);
return new ApisAndApps(apis, apps);
}
use of org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testUpdateCompositeApi.
@Test(description = "Update Composite API")
public void testUpdateCompositeApi() throws APIManagementException {
// Add a new Composite API
CompositeAPI.Builder apiBuilder = SampleTestObjectCreator.createUniqueCompositeAPI();
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
IdentityProvider idp = Mockito.mock(IdentityProvider.class);
APIStore apiStore = getApiStoreImpl(idp, null, apiDAO, apiSubscriptionDAO, gatewaySourceGenerator, apiGateway);
String ballerinaImpl = "Ballerina";
apiStore.addCompositeApi(apiBuilder);
CompositeAPI createdAPI = apiBuilder.build();
// Update existing Composite API
apiBuilder = SampleTestObjectCreator.createUniqueCompositeAPI();
apiBuilder.id(createdAPI.getId());
apiBuilder.name(createdAPI.getName());
apiBuilder.provider(createdAPI.getProvider());
apiBuilder.version(createdAPI.getVersion());
apiBuilder.context(createdAPI.getContext());
Mockito.when(apiDAO.getCompositeAPI(apiBuilder.getId())).thenReturn(createdAPI);
Mockito.when(apiDAO.getCompositeAPIGatewayConfig(apiBuilder.getId())).thenReturn(new ByteArrayInputStream(ballerinaImpl.getBytes(StandardCharsets.UTF_8)));
Mockito.when(gatewaySourceGenerator.getGatewayConfigFromSwagger(Matchers.anyString(), Matchers.anyString())).thenReturn(ballerinaImpl);
apiStore.updateCompositeApi(apiBuilder);
CompositeAPI updatedAPI = apiBuilder.build();
Assert.assertEquals(updatedAPI.getId(), createdAPI.getId());
Assert.assertEquals(updatedAPI.getName(), createdAPI.getName());
Assert.assertEquals(updatedAPI.getProvider(), createdAPI.getProvider());
Assert.assertEquals(updatedAPI.getVersion(), createdAPI.getVersion());
Assert.assertEquals(updatedAPI.getContext(), createdAPI.getContext());
}
use of org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddSubscriptionWorkflowReject.
@Test(description = "Test Subscription workflow rejection")
public void testAddSubscriptionWorkflowReject() 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);
APIStore apiStore = getApiStoreImpl(apiDAO, applicationDAO, apiSubscriptionDAO, workflowDAO, apiGateway, policyDAO);
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, TIER)).thenReturn(policy);
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 response = apiStore.addApiSubscription(apiId, UUID, TIER);
DefaultWorkflowExecutor executor = Mockito.mock(DefaultWorkflowExecutor.class);
Workflow workflow = new SubscriptionCreationWorkflow(apiSubscriptionDAO, workflowDAO, apiGateway);
workflow.setWorkflowType(APIMgtConstants.WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION);
workflow.setWorkflowReference(response.getSubscriptionUUID());
WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
workflowResponse.setWorkflowStatus(WorkflowStatus.REJECTED);
Mockito.when(executor.complete(workflow)).thenReturn(workflowResponse);
apiStore.completeWorkflow(executor, workflow);
Mockito.verify(apiSubscriptionDAO, Mockito.times(1)).updateSubscriptionStatus(response.getSubscriptionUUID(), SubscriptionStatus.REJECTED);
}
Aggregations