use of org.wso2.carbon.apimgt.core.models.Application in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createDefaultApplication.
public static Application createDefaultApplication() {
// created by admin
Application application = new Application(TEST_APP_1, ADMIN);
application.setId(UUID.randomUUID().toString());
application.setDescription("This is a test application");
application.setStatus(APIMgtConstants.ApplicationStatus.APPLICATION_CREATED);
application.setPolicy(fiftyPerMinApplicationPolicy);
application.setCreatedTime(LocalDateTime.now());
application.setUpdatedUser(ADMIN);
application.setUpdatedTime(LocalDateTime.now());
return application;
}
use of org.wso2.carbon.apimgt.core.models.Application in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createDefaultBlockCondition.
public static BlockConditions createDefaultBlockCondition(String conditionType) {
BlockConditions blockConditions = new BlockConditions();
blockConditions.setConditionType(conditionType);
blockConditions.setEnabled(true);
if (conditionType.equals(APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITIONS_IP)) {
blockConditions.setConditionValue(SAMPLE_IP_1);
} else if (conditionType.equals(APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITION_IP_RANGE)) {
blockConditions.setStartingIP(SAMPLE_IP_1);
blockConditions.setEndingIP(SAMPLE_IP_2);
} else if (conditionType.equals(APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITIONS_API)) {
try {
API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI();
API api = apiBuilder.build();
DAOFactory.getApiDAO().addAPI(api);
blockConditions.setConditionValue(api.getContext());
} catch (APIMgtDAOException e) {
log.error("Error while adding default api in default block condition", e);
}
} else if (conditionType.equals(APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITIONS_APPLICATION)) {
try {
Application app = createDefaultApplication();
DAOFactory.getApplicationDAO().addApplication(app);
blockConditions.setConditionValue(app.getId() + ":" + app.getName());
} catch (APIMgtDAOException e) {
log.error("Error while adding default app in default block condition", e);
}
} else if (conditionType.equals(APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITIONS_USER)) {
blockConditions.setConditionValue(ADMIN);
}
return blockConditions;
}
use of org.wso2.carbon.apimgt.core.models.Application in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testGetDocumentContent.
@Test(description = "Getting document content for an API")
public void testGetDocumentContent() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
testAddGetEndpoint();
API api = SampleTestObjectCreator.createDefaultAPI().build();
apiDAO.addAPI(api);
DocumentInfo documentInfo1 = SampleTestObjectCreator.createDefaultDocumentationInfo();
apiDAO.addDocumentInfo(api.getId(), documentInfo1);
List<DocumentInfo> documentInfoList = new ArrayList<>();
documentInfoList.add(documentInfo1);
List<DocumentInfo> documentInfoListFromDB = apiDAO.getDocumentsInfoList(api.getId());
Assert.assertTrue(documentInfoListFromDB.containsAll(documentInfoList));
DocumentInfo documentInfo = SampleTestObjectCreator.createFileDocumentationInfo();
apiDAO.addDocumentInfo(api.getId(), documentInfo);
byte[] contentBytes = SampleTestObjectCreator.createDefaultFileDocumentationContent();
apiDAO.addDocumentFileContent(documentInfo.getId(), new ByteArrayInputStream(contentBytes), "application/pdf", ADMIN);
byte[] retrievedContentFromDB = IOUtils.toByteArray(apiDAO.getDocumentFileContent(documentInfo.getId()));
Assert.assertEquals(contentBytes.length, retrievedContentFromDB.length);
}
use of org.wso2.carbon.apimgt.core.models.Application in project carbon-apimgt by wso2.
the class ApplicationDAOImplIT method testFingerprintAfterUpdatingApplication.
@Test
public void testFingerprintAfterUpdatingApplication() throws Exception {
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
// add new app
Application currentApp = TestUtil.addTestApplication();
String fingerprintBeforeUpdate = ETagUtils.generateETag(applicationDAO.getLastUpdatedTimeOfApplication(currentApp.getId()));
Assert.assertNotNull(fingerprintBeforeUpdate);
Thread.sleep(1);
Application newApp = SampleTestObjectCreator.createAlternativeApplication();
newApp.setId(currentApp.getId());
newApp.setCreatedTime(currentApp.getCreatedTime());
// update app
applicationDAO.updateApplication(currentApp.getId(), newApp);
String fingerprintAfterUpdate = ETagUtils.generateETag(applicationDAO.getLastUpdatedTimeOfApplication(currentApp.getId()));
Assert.assertNotNull(fingerprintAfterUpdate);
// compare
Assert.assertNotEquals(fingerprintBeforeUpdate, fingerprintAfterUpdate);
}
use of org.wso2.carbon.apimgt.core.models.Application in project carbon-apimgt by wso2.
the class ApplicationDAOImplIT method testAddAndGetApplication.
@Test
public void testAddAndGetApplication() throws Exception {
// add new app
Application app = TestUtil.addTestApplication();
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
// get added app
Application appFromDB = applicationDAO.getApplication(app.getId());
Assert.assertNotNull(appFromDB);
// compare
Assert.assertEquals(appFromDB, app, TestUtil.printDiff(appFromDB, app));
validateAppTimestamps(appFromDB, app);
}
Aggregations