use of org.wso2.carbon.apimgt.keymgt.model.entity.API in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testCheckContextExist.
@Test
public void testCheckContextExist() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
apiDAO.changeLifeCycleStatus(api.getId(), APIStatus.PUBLISHED.getStatus());
Assert.assertTrue(apiDAO.isAPIContextExists(api.getContext()));
Assert.assertFalse(apiDAO.isAPIContextExists("/abc"));
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.API in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testAddGetAPI.
@Test
public void testAddGetAPI() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
API apiFromDB = apiDAO.getAPI(api.getId());
Assert.assertNotNull(apiFromDB);
Assert.assertTrue(api.equals(apiFromDB), TestUtil.printDiff(api, apiFromDB));
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.API in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testGetAPIsByStatusStore.
@Test
public void testGetAPIsByStatusStore() throws Exception {
// Add few APIs with different attributes.
List<String> apiIDList = createAPIsAndGetIDsOfAddedAPIs();
Set<String> userRoles = new HashSet<>();
List<String> statuses = new ArrayList<>();
statuses.add(APIStatus.PUBLISHED.getStatus());
statuses.add(APIStatus.PROTOTYPED.getStatus());
ApiDAO apiDAO = DAOFactory.getApiDAO();
String[] expectedAPINames;
List<API> apiResults;
// Asserting results for different search queries
// Role based API retrieval for a user with "admin" role
userRoles.add(ADMIN);
apiResults = apiDAO.getAPIsByStatus(userRoles, statuses, new ArrayList<>());
List<String> resultAPINameList = new ArrayList<>();
for (API api : apiResults) {
resultAPINameList.add(api.getName());
}
expectedAPINames = new String[] { "PublicAPI", "AdminManagerAPI" };
Assert.assertTrue(resultAPINameList.containsAll(Arrays.asList(expectedAPINames)) && Arrays.asList(expectedAPINames).containsAll(resultAPINameList));
userRoles.clear();
apiResults.clear();
resultAPINameList.clear();
// Role based API retrieval for a user with "manager" role
userRoles.add(MANAGER_ROLE);
apiResults = apiDAO.getAPIsByStatus(userRoles, statuses, new ArrayList<>());
for (API api : apiResults) {
resultAPINameList.add(api.getName());
}
expectedAPINames = new String[] { "PublicAPI", "ManagerOnlyAPI", "AdminManagerAPI", "NonAdminAPI" };
Assert.assertTrue(resultAPINameList.containsAll(Arrays.asList(expectedAPINames)) && Arrays.asList(expectedAPINames).containsAll(resultAPINameList));
userRoles.clear();
apiResults.clear();
resultAPINameList.clear();
// Role based API retrieval for a user with "manager", "employee" and "customer" roles
userRoles.add(MANAGER_ROLE);
userRoles.add(EMPLOYEE_ROLE);
userRoles.add(CUSTOMER_ROLE);
apiResults = apiDAO.getAPIsByStatus(userRoles, statuses, new ArrayList<>());
for (API api : apiResults) {
resultAPINameList.add(api.getName());
}
expectedAPINames = new String[] { "PublicAPI", "ManagerOnlyAPI", "AdminManagerAPI", "EmployeeAPI", "NonAdminAPI" };
Assert.assertTrue(resultAPINameList.containsAll(Arrays.asList(expectedAPINames)) && Arrays.asList(expectedAPINames).containsAll(resultAPINameList));
userRoles.clear();
apiResults.clear();
resultAPINameList.clear();
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.API in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testUpdateRating.
@Test
public void testUpdateRating() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
Rating rating1 = SampleTestObjectCreator.createDefaultRating(api.getId());
apiDAO.addRating(api.getId(), rating1);
Rating rating2 = SampleTestObjectCreator.createDefaultRating(api.getId());
rating2.setRating(4);
apiDAO.updateRating(api.getId(), rating1.getUuid(), rating2);
Rating ratingFromDB = apiDAO.getRatingByUUID(api.getId(), rating1.getUuid());
Assert.assertNotNull(ratingFromDB);
Assert.assertEquals(4, ratingFromDB.getRating());
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.API in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testAddGetComment.
@Test
public void testAddGetComment() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
Comment comment = SampleTestObjectCreator.createDefaultComment(api.getId());
apiDAO.addComment(comment, api.getId());
Comment commentFromDB = apiDAO.getCommentByUUID(comment.getUuid(), api.getId());
Assert.assertNotNull(commentFromDB);
}
Aggregations