use of org.wso2.carbon.apimgt.core.dao.ApiDAO in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testAddUpdateGetEndpoint.
@Test
public void testAddUpdateGetEndpoint() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
apiDAO.addEndpoint(SampleTestObjectCreator.createMockEndpoint());
Endpoint updatedEndpoint = SampleTestObjectCreator.createUpdatedEndpoint();
apiDAO.updateEndpoint(updatedEndpoint);
Endpoint retrieved = apiDAO.getEndpoint(updatedEndpoint.getId());
Assert.assertEquals(updatedEndpoint, retrieved);
}
use of org.wso2.carbon.apimgt.core.dao.ApiDAO in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testUpdateAPIWithLabels.
@Test
public void testUpdateAPIWithLabels() throws Exception {
LabelDAO labelDAO = DAOFactory.getLabelDAO();
Label label1 = SampleTestObjectCreator.createLabel("public", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
Label label2 = SampleTestObjectCreator.createLabel("private", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
LabelDAOImpl.addLabel(label1);
LabelDAOImpl.addLabel(label2);
ApiDAO apiDAO = DAOFactory.getApiDAO();
List<String> labelIds = new ArrayList<>();
labelIds.add(label1.getId());
API.APIBuilder builder1 = SampleTestObjectCreator.createDefaultAPI();
API api = builder1.labels(labelIds).build();
testAddGetEndpoint();
apiDAO.addAPI(api);
API apiFromDBWithOneLabel = apiDAO.getAPI(api.getId());
Assert.assertEquals(apiFromDBWithOneLabel.getLabels().size(), builder1.getLabels().size());
labelIds.add(label2.getId());
API substituteAPI = new API.APIBuilder(api).labels(labelIds).build();
apiDAO.updateAPI(api.getId(), substituteAPI);
API apiFromDB = apiDAO.getAPI(api.getId());
API expectedAPI = SampleTestObjectCreator.copyAPIIgnoringNonEditableFields(api, substituteAPI);
Assert.assertNotNull(apiFromDB);
Assert.assertEquals(apiFromDB.getLabels().size(), expectedAPI.getLabels().size());
}
use of org.wso2.carbon.apimgt.core.dao.ApiDAO in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testGetAPIsWhenUserIsProvider.
@Test(description = "Tests getting the APIs when the user is the provider of the API")
public void testGetAPIsWhenUserIsProvider() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
Set<String> rolesOfUser = new HashSet<>();
// The ID here is the group ID of the provider of the API. This ID is not assigned permissions for the API
rolesOfUser.add(ALTERNATIVE_USER_ROLE_ID);
// But this user is the provider of the API
List<API> apiList = apiDAO.getAPIs(rolesOfUser, ADMIN);
Assert.assertTrue(apiList.isEmpty());
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
API api1 = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api1);
apiList = apiDAO.getAPIs(rolesOfUser, ADMIN);
List<API> expectedAPIs = new ArrayList<>();
expectedAPIs.add(SampleTestObjectCreator.copyAPISummary(api1));
// The provider will have all permissions for the API by default
Assert.assertTrue(apiList.size() == 1);
Assert.assertTrue(APIUtils.isListsEqualIgnoreOrder(apiList, expectedAPIs, new APIComparator()), TestUtil.printDiff(apiList, expectedAPIs));
}
use of org.wso2.carbon.apimgt.core.dao.ApiDAO in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testIsAPINameExists.
@Test
public void testIsAPINameExists() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
testAddGetEndpoint();
API api = SampleTestObjectCreator.createUniqueAPI().build();
apiDAO.addAPI(api);
Assert.assertTrue(apiDAO.isAPINameExists(api.getName(), api.getProvider()));
Assert.assertFalse(apiDAO.isAPINameExists("Not-Exists", api.getProvider()));
final String upperCaseName = "CAPITAL";
// Add API with upper case name
api = SampleTestObjectCreator.createUniqueAPI().name(upperCaseName).build();
apiDAO.addAPI(api);
// Check with upper case format
Assert.assertTrue(apiDAO.isAPINameExists(upperCaseName, api.getProvider()));
// Check with lower case format
Assert.assertTrue(apiDAO.isAPINameExists(upperCaseName.toLowerCase(Locale.ENGLISH), api.getProvider()));
// Check with mixed case format
Assert.assertTrue(apiDAO.isAPINameExists(upperCaseName.substring(0, 3) + upperCaseName.substring(3).toLowerCase(Locale.ENGLISH), api.getProvider()));
final String lowerCaseName = "simple";
// Add API with upper case name
api = SampleTestObjectCreator.createUniqueAPI().name(lowerCaseName).build();
apiDAO.addAPI(api);
// Check with lower case format
Assert.assertTrue(apiDAO.isAPINameExists(lowerCaseName, api.getProvider()));
// Check with upper case format
Assert.assertTrue(apiDAO.isAPINameExists(lowerCaseName.toUpperCase(Locale.ENGLISH), api.getProvider()));
// Check with mixed case format
Assert.assertTrue(apiDAO.isAPINameExists(lowerCaseName.substring(0, 3) + lowerCaseName.substring(3).toUpperCase(Locale.ENGLISH), api.getProvider()));
// Create same API for different providers and check for existence
final String sameName = "same";
API api1 = SampleTestObjectCreator.createUniqueAPI().name(sameName).build();
apiDAO.addAPI(api1);
API api2 = SampleTestObjectCreator.createUniqueAPI().name(sameName).build();
apiDAO.addAPI(api2);
Assert.assertTrue(apiDAO.isAPINameExists(sameName, api1.getProvider()));
Assert.assertTrue(apiDAO.isAPINameExists(sameName, api2.getProvider()));
Assert.assertFalse(apiDAO.isAPINameExists(sameName, "no_such_provider"));
}
use of org.wso2.carbon.apimgt.core.dao.ApiDAO in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testAttributeSearchAPIs.
@Test(description = "Retrieve summary of paginated data of all available APIs that match the given search criteria")
public void testAttributeSearchAPIs() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
testAddGetEndpoint();
API api = SampleTestObjectCreator.createDefaultAPI().build();
apiDAO.addAPI(api);
Set<String> roles = new HashSet<>();
Map<String, String> attributeMap = new HashMap<>();
attributeMap.put("name", api.getName());
List<API> apiList = apiDAO.attributeSearchAPIs(roles, api.getProvider(), attributeMap, 0, 2);
Assert.assertTrue(apiList.size() > 0);
}
Aggregations