Search in sources :

Example 31 with Application

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

Example 32 with 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;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) BlockConditions(org.wso2.carbon.apimgt.core.models.BlockConditions) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) Application(org.wso2.carbon.apimgt.core.models.Application)

Example 33 with Application

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) 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) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) Test(org.testng.annotations.Test)

Example 34 with Application

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);
}
Also used : ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Application(org.wso2.carbon.apimgt.core.models.Application) Test(org.testng.annotations.Test)

Example 35 with Application

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);
}
Also used : ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Application(org.wso2.carbon.apimgt.core.models.Application) Test(org.testng.annotations.Test)

Aggregations

Application (org.wso2.carbon.apimgt.core.models.Application)121 Test (org.testng.annotations.Test)91 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)61 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)59 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)58 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)57 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)40 ArrayList (java.util.ArrayList)35 SQLException (java.sql.SQLException)33 API (org.wso2.carbon.apimgt.core.models.API)33 Test (org.junit.Test)29 BeforeTest (org.testng.annotations.BeforeTest)29 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)29 APISubscriptionDAO (org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO)27 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)27 Connection (java.sql.Connection)26 PreparedStatement (java.sql.PreparedStatement)26 HashMap (java.util.HashMap)26 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)25 Subscription (org.wso2.carbon.apimgt.core.models.Subscription)25