use of org.wso2.eventing.Subscription in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testGetAPISubscriptionCountByAPI.
@Test(description = "Exception when getting api subscription count by API", expectedExceptions = APIManagementException.class)
public void testGetAPISubscriptionCountByAPI() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
API api = SampleTestObjectCreator.createDefaultAPI().build();
String uuid = api.getId();
Mockito.when(apiSubscriptionDAO.getSubscriptionCountByAPI(uuid)).thenThrow(new APIMgtDAOException("Couldn't retrieve Subscriptions for API " + uuid));
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiSubscriptionDAO);
apiPublisher.getAPISubscriptionCountByAPI(uuid);
}
use of org.wso2.eventing.Subscription in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUpdateSubscriptionStatus.
@Test(description = "Update subscription status")
public void testUpdateSubscriptionStatus() throws APIManagementException {
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
APIGateway apiGatewayPublisher = Mockito.mock(APIGateway.class);
Application application = SampleTestObjectCreator.createDefaultApplication();
API api = SampleTestObjectCreator.createDefaultAPI().build();
Policy policy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
Subscription subscription = new Subscription(SUB_ID, application, api, policy);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiSubscriptionDAO, apiGatewayPublisher);
Mockito.when(apiSubscriptionDAO.getAPISubscription(SUB_ID)).thenReturn(subscription);
apiPublisher.updateSubscriptionStatus(SUB_ID, APIMgtConstants.SubscriptionStatus.ACTIVE);
Mockito.verify(apiSubscriptionDAO, Mockito.times(1)).updateSubscriptionStatus(SUB_ID, APIMgtConstants.SubscriptionStatus.ACTIVE);
}
use of org.wso2.eventing.Subscription in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testUpdateSubscriptionPolicy.
@Test(description = "Test update subscription policy")
public void testUpdateSubscriptionPolicy() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
SubscriptionPolicy subscriptionPolicy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
adminService.updateSubscriptionPolicy(subscriptionPolicy);
Mockito.verify(policyDAO, Mockito.times(1)).updateSubscriptionPolicy(subscriptionPolicy);
// Error path
Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).updateSubscriptionPolicy(subscriptionPolicy);
try {
adminService.updateSubscriptionPolicy(subscriptionPolicy);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't update Subscription policy for uuid: " + subscriptionPolicy.getUuid());
}
}
use of org.wso2.eventing.Subscription in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testAddSubscriptionPolicy.
@Test(description = "Test add subscription policy")
public void testAddSubscriptionPolicy() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
SubscriptionPolicy policy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
adminService.addSubscriptionPolicy(policy);
Mockito.verify(policyDAO, Mockito.times(1)).addSubscriptionPolicy(policy);
// Error path
Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).addSubscriptionPolicy(policy);
try {
adminService.addSubscriptionPolicy(policy);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't add Subscription policy for uuid: " + policy.getUuid());
}
}
use of org.wso2.eventing.Subscription in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetSubscriptionPolicies.
@Test(description = "Test getting all Subscription Policies")
public void testGetSubscriptionPolicies() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
adminService.getSubscriptionPolicies();
Mockito.verify(policyDAO, Mockito.times(1)).getSubscriptionPolicies();
// Error path
Mockito.when(policyDAO.getSubscriptionPolicies()).thenThrow(APIMgtDAOException.class);
try {
adminService.getSubscriptionPolicies();
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't retrieve Subscription policies");
}
}
Aggregations