Search in sources :

Example 6 with APIDefinition

use of org.wso2.carbon.apimgt.api.APIDefinition in project carbon-apimgt by wso2.

the class ApiDAOImplIT method testUpdateGetDedicatedGateway.

@Test
public void testUpdateGetDedicatedGateway() throws Exception {
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
    API api = builder.build();
    testAddGetEndpoint();
    apiDAO.addAPI(api);
    String autoGeneratedLabelName = ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + api.getId();
    List<Label> labelList = new ArrayList<>();
    LabelDAO labelDAO = DAOFactory.getLabelDAO();
    Label autoGenLabel = new Label.Builder().id(UUID.randomUUID().toString()).name(autoGeneratedLabelName).accessUrls(null).build();
    labelList.add(autoGenLabel);
    labelDAO.addLabels(labelList);
    DedicatedGateway dedicatedGateway = new DedicatedGateway();
    dedicatedGateway.setEnabled(true);
    dedicatedGateway.setUpdatedBy(api.getCreatedBy());
    dedicatedGateway.setApiId(api.getId());
    List<String> labels = new ArrayList<>();
    labels.add(autoGeneratedLabelName);
    apiDAO.updateDedicatedGateway(dedicatedGateway, labels);
    DedicatedGateway result = apiDAO.getDedicatedGateway(api.getId());
    Assert.assertEquals(result.isEnabled(), dedicatedGateway.isEnabled());
}
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) DedicatedGateway(org.wso2.carbon.apimgt.core.models.DedicatedGateway) Test(org.testng.annotations.Test)

Example 7 with APIDefinition

use of org.wso2.carbon.apimgt.api.APIDefinition in project carbon-apimgt by wso2.

the class ApiDAOImplIT method testUpdateComment.

@Test
public void testUpdateComment() throws Exception {
    String newCommentText = "updated comment";
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
    API api = builder.build();
    testAddGetEndpoint();
    apiDAO.addAPI(api);
    Comment comment1 = SampleTestObjectCreator.createDefaultComment(api.getId());
    apiDAO.addComment(comment1, api.getId());
    String lastUpdatedTime1 = apiDAO.getLastUpdatedTimeOfComment(comment1.getUuid());
    // Keep at least millisecond difference between the two timestamps
    Thread.sleep(1);
    Comment comment2 = SampleTestObjectCreator.createDefaultComment(api.getId());
    comment2.setCommentText(newCommentText);
    apiDAO.updateComment(comment2, comment1.getUuid(), api.getId());
    Comment commentFromDB = apiDAO.getCommentByUUID(comment1.getUuid(), api.getId());
    String lastUpdatedTimeAfterUpdating = apiDAO.getLastUpdatedTimeOfComment(comment1.getUuid());
    Assert.assertNotNull(commentFromDB);
    Assert.assertNotNull(lastUpdatedTime1);
    Assert.assertNotNull(lastUpdatedTimeAfterUpdating);
    Assert.assertNotEquals(lastUpdatedTime1, lastUpdatedTimeAfterUpdating);
    Assert.assertEquals(newCommentText, commentFromDB.getCommentText());
}
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)

Example 8 with APIDefinition

use of org.wso2.carbon.apimgt.api.APIDefinition in project carbon-apimgt by wso2.

the class ApiDAOImplIT method testGetAllAverageAndUserRatingsOfAPI.

@Test
public void testGetAllAverageAndUserRatingsOfAPI() 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(2);
    rating2.setUsername("andrew");
    apiDAO.addRating(api.getId(), rating2);
    Rating rating3 = SampleTestObjectCreator.createDefaultRating(api.getId());
    rating3.setRating(3);
    rating3.setUsername("smith");
    apiDAO.addRating(api.getId(), rating3);
    List<Rating> ratingsListFromDB = apiDAO.getRatingsListForApi(api.getId());
    Assert.assertNotNull(ratingsListFromDB);
    Assert.assertEquals(ratingsListFromDB.size(), 3);
    Rating ratingOfJohn = apiDAO.getUserRatingForApiFromUser(api.getId(), "john");
    Rating ratingOfAndrew = apiDAO.getUserRatingForApiFromUser(api.getId(), "andrew");
    Rating ratingOfSmith = apiDAO.getUserRatingForApiFromUser(api.getId(), "smith");
    Assert.assertEquals(ratingOfJohn.getRating(), 4);
    Assert.assertEquals(ratingOfAndrew.getRating(), 2);
    Assert.assertEquals(ratingOfSmith.getRating(), 3);
    double averageRating = apiDAO.getAverageRating(api.getId());
    Assert.assertEquals(averageRating, 3, 0.0001);
}
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 9 with APIDefinition

use of org.wso2.carbon.apimgt.api.APIDefinition in project carbon-apimgt by wso2.

the class ApiDAOImplIT method testDeleteComment.

@Test
public void testDeleteComment() 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());
    apiDAO.deleteComment(comment.getUuid(), api.getId());
    Comment commentFromDB = apiDAO.getCommentByUUID(comment.getUuid(), api.getId());
    Assert.assertNull(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)

Example 10 with APIDefinition

use of org.wso2.carbon.apimgt.api.APIDefinition 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)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)32 HashMap (java.util.HashMap)30 APIDefinition (org.wso2.carbon.apimgt.api.APIDefinition)30 API (org.wso2.carbon.apimgt.core.models.API)30 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)25 ArrayList (java.util.ArrayList)23 API (org.wso2.carbon.apimgt.api.model.API)20 Map (java.util.Map)19 IOException (java.io.IOException)18 Test (org.testng.annotations.Test)18 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)18 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)16 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)15 Scope (org.wso2.carbon.apimgt.api.model.Scope)15 HashSet (java.util.HashSet)13 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)13 APIDefinitionValidationResponse (org.wso2.carbon.apimgt.api.APIDefinitionValidationResponse)12 SwaggerData (org.wso2.carbon.apimgt.api.model.SwaggerData)12 BusinessInformation (org.wso2.carbon.apimgt.core.models.BusinessInformation)12 CorsConfiguration (org.wso2.carbon.apimgt.core.models.CorsConfiguration)12