use of org.wso2.carbon.apimgt.api.model.APIStore in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testUpdateRating.
@Test(description = "Update rating")
public void testUpdateRating() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APIStore apiStore = getApiStoreImpl(apiDAO);
API api = SampleTestObjectCreator.createDefaultAPI().build();
Mockito.when(apiDAO.isAPIExists(api.getId())).thenReturn(true);
Rating ratingFromDB = SampleTestObjectCreator.createDefaultRating(api.getId());
Rating ratingFromPayload = SampleTestObjectCreator.createDefaultRating(api.getId());
ratingFromPayload.setRating(3);
Mockito.when(apiDAO.getRatingByUUID(api.getId(), ratingFromDB.getUuid())).thenReturn(ratingFromDB);
apiStore.updateRating(api.getId(), ratingFromDB.getUuid(), ratingFromPayload);
Mockito.verify(apiDAO, Mockito.times(1)).isAPIExists(api.getId());
Mockito.verify(apiDAO, Mockito.times(1)).updateRating(api.getId(), ratingFromDB.getUuid(), ratingFromPayload);
}
use of org.wso2.carbon.apimgt.api.model.APIStore in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testDeleteSubscriptionWithOnholdState.
@Test(description = "Delete subscription with on_hold state")
public void testDeleteSubscriptionWithOnholdState() throws APIManagementException {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIStore apiStore = getApiStoreImpl(applicationDAO, apiSubscriptionDAO, workflowDAO, apiGateway);
Application application = SampleTestObjectCreator.createDefaultApplication();
APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
API api = builder.build();
Subscription subscription = new Subscription(UUID, application, api, new SubscriptionPolicy("Gold"));
subscription.setStatus(SubscriptionStatus.ON_HOLD);
String externalRef = java.util.UUID.randomUUID().toString();
Mockito.when(workflowDAO.getExternalWorkflowReferenceForPendingTask(subscription.getId(), WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION)).thenReturn(Optional.of(externalRef));
Mockito.when(apiSubscriptionDAO.getAPISubscription(UUID)).thenReturn(subscription);
apiStore.deleteAPISubscription(UUID);
Mockito.verify(apiSubscriptionDAO, Mockito.times(1)).deleteAPISubscription(UUID);
Mockito.verify(workflowDAO, Mockito.times(1)).getExternalWorkflowReferenceForPendingTask(subscription.getId(), WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION);
}
use of org.wso2.carbon.apimgt.api.model.APIStore in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testDeleteSubscription.
@Test(description = "Delete subscription")
public void testDeleteSubscription() throws APIManagementException {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIStore apiStore = getApiStoreImpl(applicationDAO, apiSubscriptionDAO, workflowDAO, apiGateway);
Application application = SampleTestObjectCreator.createDefaultApplication();
APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
API api = builder.build();
Subscription subscription = new Subscription(UUID, application, api, new SubscriptionPolicy("Gold"));
Mockito.when(apiSubscriptionDAO.getAPISubscription(UUID)).thenReturn(subscription);
apiStore.deleteAPISubscription(UUID);
Mockito.verify(apiSubscriptionDAO, Mockito.times(1)).deleteAPISubscription(UUID);
}
use of org.wso2.carbon.apimgt.api.model.APIStore in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddCommentException.
@Test(description = "Exception in dao when adding a comment", expectedExceptions = APIManagementException.class)
public void testAddCommentException() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APIStore apiStore = getApiStoreImpl(apiDAO);
API api = SampleTestObjectCreator.createDefaultAPI().build();
Mockito.when(apiDAO.getAPI(api.getId())).thenReturn(api);
Comment comment = SampleTestObjectCreator.createDefaultComment(api.getId());
Mockito.doThrow(new APIMgtDAOException("Error occurred while adding comment for api id " + api.getId(), new SQLException())).when(apiDAO).addComment(comment, api.getId());
apiStore.addComment(comment, api.getId());
}
use of org.wso2.carbon.apimgt.api.model.APIStore in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testSelfSignUp.
@Test(description = "User Self Signup")
public void testSelfSignUp() throws Exception {
IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
APIStoreImpl apiStore = getApiStoreImpl(identityProvider);
User user = new User();
Mockito.doNothing().when(identityProvider).registerUser(user);
apiStore.selfSignUp(user);
}
Aggregations