Search in sources :

Example 31 with TestCaseCountryProperties

use of org.cerberus.crud.entity.TestCaseCountryProperties in project cerberus-source by cerberustesting.

the class TestCaseCountryPropertiesDAO method findTestCaseCountryPropertiesByKey.

@Override
public TestCaseCountryProperties findTestCaseCountryPropertiesByKey(String test, String testcase, String country, String property) throws CerberusException {
    TestCaseCountryProperties result = null;
    boolean throwException = false;
    final String query = "SELECT * FROM testcasecountryproperties WHERE test = ? AND testcase = ? AND country = ? AND hex(`property`) = hex(?)";
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setString(1, test);
            preStat.setString(2, testcase);
            preStat.setString(3, country);
            preStat.setBytes(4, property.getBytes("UTF-8"));
            ResultSet resultSet = preStat.executeQuery();
            try {
                if (resultSet.first()) {
                    String description = resultSet.getString("description");
                    String type = resultSet.getString("type");
                    String database = resultSet.getString("database");
                    String value1 = resultSet.getString("value1");
                    String value2 = resultSet.getString("value2");
                    String length = resultSet.getString("length");
                    int rowLimit = resultSet.getInt("rowLimit");
                    String nature = resultSet.getString("nature");
                    int retryNb = resultSet.getInt("RetryNb");
                    int retryPeriod = resultSet.getInt("RetryPeriod");
                    int cacheExpire = resultSet.getInt("CacheExpire");
                    result = factoryTestCaseCountryProperties.create(test, testcase, country, property, description, type, database, value1, value2, length, rowLimit, nature, retryNb, retryPeriod, cacheExpire);
                } else {
                    throwException = true;
                }
            } catch (SQLException exception) {
                LOG.error("Unable to execute query : " + exception.toString());
            } finally {
                resultSet.close();
            }
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
        } catch (UnsupportedEncodingException ex) {
            LOG.error(ex.toString());
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    if (throwException) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));
    }
    return result;
}
Also used : CerberusException(org.cerberus.exception.CerberusException) TestCaseCountryProperties(org.cerberus.crud.entity.TestCaseCountryProperties) IFactoryTestCaseCountryProperties(org.cerberus.crud.factory.IFactoryTestCaseCountryProperties) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PreparedStatement(java.sql.PreparedStatement)

Example 32 with TestCaseCountryProperties

use of org.cerberus.crud.entity.TestCaseCountryProperties in project cerberus-source by cerberustesting.

the class TestCaseCountryPropertiesService method compareListAndUpdateInsertDeleteElements.

@Override
public Answer compareListAndUpdateInsertDeleteElements(String test, String testCase, List<TestCaseCountryProperties> newList) {
    Answer ans = new Answer(null);
    MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);
    Answer finalAnswer = new Answer(msg1);
    List<TestCaseCountryProperties> oldList = new ArrayList();
    // try {
    oldList = this.findListOfPropertyPerTestTestCase(test, testCase);
    // } catch (CerberusException ex) {
    // LOG.error(ex);
    // }
    /**
     * Iterate on (Object From Page - Object From Database) If Object in
     * Database has same key : Update and remove from the list. If Object in
     * database does ot exist : Insert it.
     */
    List<TestCaseCountryProperties> listToUpdateOrInsert = new ArrayList(newList);
    listToUpdateOrInsert.removeAll(oldList);
    List<TestCaseCountryProperties> listToUpdateOrInsertToIterate = new ArrayList(listToUpdateOrInsert);
    for (TestCaseCountryProperties objectDifference : listToUpdateOrInsertToIterate) {
        for (TestCaseCountryProperties objectInDatabase : oldList) {
            if (objectDifference.hasSameKey(objectInDatabase)) {
                ans = this.update(objectDifference);
                finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
                listToUpdateOrInsert.remove(objectDifference);
            }
        }
    }
    /**
     * Iterate on (Object From Database - Object From Page). If Object in
     * Page has same key : remove from the list. Then delete the list of
     * Object
     */
    List<TestCaseCountryProperties> listToDelete = new ArrayList(oldList);
    listToDelete.removeAll(newList);
    List<TestCaseCountryProperties> listToDeleteToIterate = new ArrayList(listToDelete);
    for (TestCaseCountryProperties objectDifference : listToDeleteToIterate) {
        for (TestCaseCountryProperties objectInPage : newList) {
            if (objectDifference.hasSameKey(objectInPage)) {
                listToDelete.remove(objectDifference);
            }
        }
    }
    if (!listToDelete.isEmpty()) {
        ans = this.deleteList(listToDelete);
        finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
    }
    // We insert only at the end (after deletion of all potencial enreg - linked with #1281)
    if (!listToUpdateOrInsert.isEmpty()) {
        ans = this.createList(listToUpdateOrInsert);
        finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
    }
    return finalAnswer;
}
Also used : Answer(org.cerberus.util.answer.Answer) TestCaseCountryProperties(org.cerberus.crud.entity.TestCaseCountryProperties) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList)

Example 33 with TestCaseCountryProperties

use of org.cerberus.crud.entity.TestCaseCountryProperties in project cerberus-source by cerberustesting.

the class LoadTestCaseService method loadTestCase.

@Override
public void loadTestCase(TestCaseExecution tCExecution) {
    TestCase testCase = tCExecution.getTestCaseObj();
    String test = testCase.getTest();
    String testcase = testCase.getTestCase();
    List<TestCaseCountry> testCaseCountry = new ArrayList<TestCaseCountry>();
    List<TestCaseCountryProperties> testCaseCountryProperty = new ArrayList<TestCaseCountryProperties>();
    List<TestCaseStep> testCaseStep = new ArrayList<TestCaseStep>();
    List<TestCaseStep> PretestCaseStep = new ArrayList<TestCaseStep>();
    /**
     * Get List of PreTest for selected TestCase
     */
    LOG.debug("Loading pretests for " + tCExecution.getCountry() + tCExecution.getTestCaseObj().getApplication());
    List<String> login = this.testCaseStepService.getLoginStepFromTestCase(tCExecution.getCountry(), tCExecution.getTestCaseObj().getApplication());
    /**
     * Load Steps of PreTest
     */
    if (login != null) {
        for (String tsCase : login) {
            TestCaseCountry preTestCaseCountry = factoryTestCaseCountry.create("Pre Tests", tsCase, tCExecution.getCountry());
            preTestCaseCountry.setTestCaseCountryProperty(this.loadProperties(preTestCaseCountry));
            testCaseCountry.add(preTestCaseCountry);
            TestCase preTestCase = factoryTCase.create("Pre Tests", tsCase);
            LOG.debug("add all pretest");
            PretestCaseStep.addAll(loadTestCaseStep(preTestCase));
        }
    }
    /**
     * Load Information of TestCase
     */
    TestCase testCaseToAdd = factoryTCase.create(test, testcase);
    LOG.debug("add all step");
    testCaseStep.addAll(loadTestCaseStep(testCaseToAdd));
    LOG.debug("search all countryprop");
    List<TestCaseCountryProperties> testCaseCountryPropertyToAdd = this.testCaseCountryPropertiesService.findListOfPropertyPerTestTestCaseCountry(test, testcase, tCExecution.getCountry());
    LOG.debug("add all countryprop");
    if (testCaseCountryPropertyToAdd != null) {
        testCaseCountryProperty.addAll(testCaseCountryPropertyToAdd);
    }
    /**
     * Set Execution Object
     */
    testCase.setTestCaseCountry(testCaseCountry);
    LOG.debug("set testcasestep");
    testCase.setTestCaseStep(testCaseStep);
    LOG.debug("setTestCaseCountryProperties");
    testCase.setTestCaseCountryProperties(testCaseCountryProperty);
    LOG.debug("settCase");
    tCExecution.setTestCaseObj(testCase);
}
Also used : TestCaseCountryProperties(org.cerberus.crud.entity.TestCaseCountryProperties) TestCase(org.cerberus.crud.entity.TestCase) IFactoryTestCase(org.cerberus.crud.factory.IFactoryTestCase) ArrayList(java.util.ArrayList) IFactoryTestCaseCountry(org.cerberus.crud.factory.IFactoryTestCaseCountry) TestCaseCountry(org.cerberus.crud.entity.TestCaseCountry) IFactoryTestCaseStep(org.cerberus.crud.factory.IFactoryTestCaseStep) TestCaseStep(org.cerberus.crud.entity.TestCaseStep)

Aggregations

TestCaseCountryProperties (org.cerberus.crud.entity.TestCaseCountryProperties)33 ArrayList (java.util.ArrayList)19 IFactoryTestCaseCountryProperties (org.cerberus.crud.factory.IFactoryTestCaseCountryProperties)13 MessageEvent (org.cerberus.engine.entity.MessageEvent)12 TestCase (org.cerberus.crud.entity.TestCase)11 TestCaseStep (org.cerberus.crud.entity.TestCaseStep)11 JSONObject (org.json.JSONObject)11 ITestCaseCountryPropertiesService (org.cerberus.crud.service.ITestCaseCountryPropertiesService)10 TestCaseStepAction (org.cerberus.crud.entity.TestCaseStepAction)9 AnswerItem (org.cerberus.util.answer.AnswerItem)9 ApplicationContext (org.springframework.context.ApplicationContext)9 TestCaseCountry (org.cerberus.crud.entity.TestCaseCountry)8 TestCaseStepActionControl (org.cerberus.crud.entity.TestCaseStepActionControl)8 ITestCaseCountryService (org.cerberus.crud.service.ITestCaseCountryService)8 Answer (org.cerberus.util.answer.Answer)8 ITestCaseService (org.cerberus.crud.service.ITestCaseService)7 CerberusException (org.cerberus.exception.CerberusException)7 JSONArray (org.json.JSONArray)7 Connection (java.sql.Connection)6 PreparedStatement (java.sql.PreparedStatement)6