Search in sources :

Example 41 with ApiDAO

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);
}
Also used : Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 42 with ApiDAO

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());
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) ArrayList(java.util.ArrayList) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 43 with ApiDAO

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));
}
Also used : ArrayList(java.util.ArrayList) APIComparator(org.wso2.carbon.apimgt.core.util.APIComparator) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 44 with ApiDAO

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"));
}
Also used : CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 45 with ApiDAO

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);
}
Also used : HashMap(java.util.HashMap) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)315 Test (org.testng.annotations.Test)305 API (org.wso2.carbon.apimgt.core.models.API)210 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)108 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)102 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)75 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)65 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)62 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)59 BeforeTest (org.testng.annotations.BeforeTest)50 ArrayList (java.util.ArrayList)48 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)47 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)46 LabelDAO (org.wso2.carbon.apimgt.core.dao.LabelDAO)45 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)43 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)36 HashMap (java.util.HashMap)31 SQLException (java.sql.SQLException)30 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)30 LifecycleState (org.wso2.carbon.lcm.core.impl.LifecycleState)27