Search in sources :

Example 91 with API

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"));
}
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 92 with API

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));
}
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 93 with API

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();
}
Also used : ArrayList(java.util.ArrayList) 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 94 with API

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());
}
Also used : Rating(org.wso2.carbon.apimgt.core.models.Rating) 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 95 with API

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);
}
Also used : Comment(org.wso2.carbon.apimgt.core.models.Comment) 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)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)582 ArrayList (java.util.ArrayList)374 API (org.wso2.carbon.apimgt.core.models.API)359 Test (org.testng.annotations.Test)350 HashMap (java.util.HashMap)318 Test (org.junit.Test)316 API (org.wso2.carbon.apimgt.api.model.API)307 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)255 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)253 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)234 SQLException (java.sql.SQLException)190 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)186 IOException (java.io.IOException)181 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)179 PreparedStatement (java.sql.PreparedStatement)169 Connection (java.sql.Connection)158 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)154 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)149 JSONObject (org.json.simple.JSONObject)142 Resource (org.wso2.carbon.registry.core.Resource)139