use of org.wso2.carbon.apimgt.api.model.API in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testAddEndPointsForApi.
@Test(description = "Test adding API with endpointMap")
public void testAddEndPointsForApi() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
Map<String, Endpoint> endpointMap = new HashMap<>();
endpointMap.put(APIMgtConstants.PRODUCTION_ENDPOINT, new Endpoint.Builder().id(SampleTestObjectCreator.endpointId).applicableLevel(APIMgtConstants.GLOBAL_ENDPOINT).build());
API api = SampleTestObjectCreator.createDefaultAPI().endpoint(endpointMap).build();
testAddGetEndpoint();
apiDAO.addAPI(api);
API apiFromDB = apiDAO.getAPI(api.getId());
Assert.assertNotNull(apiFromDB);
Assert.assertTrue(api.equals(apiFromDB), TestUtil.printDiff(api, apiFromDB));
}
use of org.wso2.carbon.apimgt.api.model.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);
}
use of org.wso2.carbon.apimgt.api.model.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);
}
use of org.wso2.carbon.apimgt.api.model.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());
}
use of org.wso2.carbon.apimgt.api.model.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());
}
Aggregations