Search in sources :

Example 66 with API

use of org.wso2.carbon.apimgt.core.models.API in project carbon-apimgt by wso2.

the class ApiDAOImplIT method testFingerprintAfterUpdatingDocument.

@Test
public void testFingerprintAfterUpdatingDocument() throws Exception {
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
    API api = builder.build();
    testAddGetEndpoint();
    apiDAO.addAPI(api);
    DocumentInfo documentInfo = SampleTestObjectCreator.createDefaultDocumentationInfo();
    apiDAO.addDocumentInfo(api.getId(), documentInfo);
    String fingerprintBeforeUpdate = ETagUtils.generateETag(apiDAO.getLastUpdatedTimeOfDocument(documentInfo.getId()));
    Assert.assertNotNull(fingerprintBeforeUpdate);
    Thread.sleep(1);
    DocumentInfo updateDocument = SampleTestObjectCreator.createAlternativeDocumentationInfo(documentInfo.getId());
    apiDAO.updateDocumentInfo(api.getId(), updateDocument, ADMIN);
    String fingerprintAfterUpdate = ETagUtils.generateETag(apiDAO.getLastUpdatedTimeOfDocument(documentInfo.getId()));
    Assert.assertNotNull(fingerprintBeforeUpdate);
    Assert.assertNotEquals(fingerprintBeforeUpdate, fingerprintAfterUpdate);
}
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) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) Test(org.testng.annotations.Test)

Example 67 with API

use of org.wso2.carbon.apimgt.core.models.API in project carbon-apimgt by wso2.

the class ApiDAOImplIT method testFingerprintAfterUpdatingGatewayConfig.

@Test
public void testFingerprintAfterUpdatingGatewayConfig() throws Exception {
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
    builder.gatewayConfig(SampleTestObjectCreator.createSampleGatewayConfig());
    API api = builder.build();
    testAddGetEndpoint();
    apiDAO.addAPI(api);
    String fingerprintBeforeUpdate = ETagUtils.generateETag(apiDAO.getLastUpdatedTimeOfGatewayConfig(api.getId()));
    Assert.assertNotNull(fingerprintBeforeUpdate);
    Thread.sleep(1);
    String gwConfig = SampleTestObjectCreator.createAlternativeGatewayConfig();
    apiDAO.updateGatewayConfig(api.getId(), gwConfig, ADMIN);
    String fingerprintAfterUpdate = ETagUtils.generateETag(apiDAO.getLastUpdatedTimeOfGatewayConfig(api.getId()));
    Assert.assertNotNull(fingerprintAfterUpdate);
    Assert.assertNotEquals(fingerprintBeforeUpdate, fingerprintAfterUpdate);
}
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 68 with API

use of org.wso2.carbon.apimgt.core.models.API 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 69 with API

use of org.wso2.carbon.apimgt.core.models.API 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 70 with API

use of org.wso2.carbon.apimgt.core.models.API 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)

Aggregations

API (org.wso2.carbon.apimgt.core.models.API)359 Test (org.testng.annotations.Test)320 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)253 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)179 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)154 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)132 HashMap (java.util.HashMap)129 ArrayList (java.util.ArrayList)112 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)106 Test (org.junit.Test)83 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)83 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)82 SQLException (java.sql.SQLException)75 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)75 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)70 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)65 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)61 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)60 Connection (java.sql.Connection)58 Response (javax.ws.rs.core.Response)58