use of org.wso2.carbon.apimgt.api.model.APIStore 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.api.model.APIStore in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testGetLabelInfoException.
@Test(description = "Exception when retrieving labels", expectedExceptions = LabelException.class)
public void testGetLabelInfoException() throws APIManagementException {
LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
APIStore apiStore = getApiStoreImpl(labelDAO);
List<String> labels = new ArrayList<>();
labels.add("label");
Mockito.when(labelDAO.getLabelsByName(labels)).thenThrow(new APIMgtDAOException("Error occurred while retrieving label information", new SQLException()));
apiStore.getLabelInfo(labels, USER_NAME);
}
use of org.wso2.carbon.apimgt.api.model.APIStore in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testGetAPIWithNotAllowedLifecycleStates.
@Test(description = "Test get API with not allowed lifecycle states (Created, Maintenance, Retired)")
public void testGetAPIWithNotAllowedLifecycleStates() throws APIManagementException {
String exceptionShouldThrowError = "Exception should be thrown when accessing an API in %s state";
String matchedErrorMessage = "Attempt to access an API which is in a restricted state";
ApiDAO apiDAO = Mockito.mock(ApiDAO.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, Mockito.mock(ApplicationDAO.class), Mockito.mock(APISubscriptionDAO.class), Mockito.mock(WorkflowDAO.class), Mockito.mock(APIGateway.class), policyDAO);
API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI();
String apiId = apiBuilder.getId();
List<String> notAllowedStates = new ArrayList<String>() {
{
add(APIStatus.CREATED.getStatus());
add(APIStatus.MAINTENANCE.getStatus());
add(APIStatus.RETIRED.getStatus());
}
};
for (String notAllowedState : notAllowedStates) {
apiBuilder.lifeCycleStatus(notAllowedState);
API api = apiBuilder.build();
Mockito.when(apiDAO.getAPI(apiId)).thenReturn(api);
try {
apiStore.getAPIbyUUID(apiId);
Assert.fail(exceptionShouldThrowError);
} catch (APIManagementException e) {
Assert.assertTrue(e.getMessage().contains(matchedErrorMessage));
}
}
}
use of org.wso2.carbon.apimgt.api.model.APIStore in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method getLabelsByTypeException.
@Test(description = "get labels by type Exception", expectedExceptions = Exception.class)
public void getLabelsByTypeException() throws Exception {
LabelDAO labelDao = Mockito.mock(LabelDAO.class);
APIStore apiStore = getApiStoreImpl();
List<Label> labels = new ArrayList<>();
Label label = new Label.Builder().id("123").name("Default").type("STORE").accessUrls(new ArrayList<>()).build();
labels.add(label);
Mockito.when(labelDao.getLabelsByType("STORE")).thenReturn(labels);
Mockito.doThrow(new LabelException("Error occurred while retrieving labels ")).when(labelDao).getLabelsByType("STORE");
apiStore.getLabelsByType("STORE");
}
use of org.wso2.carbon.apimgt.api.model.APIStore in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testDeleteCommentDaoException.
@Test(description = "Exception in dao when deleting a specific comment", expectedExceptions = APIMgtResourceNotFoundException.class)
public void testDeleteCommentDaoException() 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.when(apiDAO.getCommentByUUID(comment.getUuid(), api.getId())).thenReturn(comment);
Mockito.doThrow(new APIMgtDAOException("Error occurred while deleting comment " + comment.getUuid(), new SQLException())).when(apiDAO).deleteComment(comment.getUuid(), api.getId());
apiStore.deleteComment(comment.getUuid(), api.getId(), "admin");
}
Aggregations