Search in sources :

Example 96 with Answer

use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.

the class TestCaseLabelService method duplicateList.

@Override
public Answer duplicateList(List<TestCaseLabel> dataList, String targetTest, String targetTestCase) {
    Answer ans = new Answer(null);
    List<TestCaseLabel> listToCreate = new ArrayList();
    for (TestCaseLabel objectToDuplicate : dataList) {
        objectToDuplicate.setTest(targetTest);
        objectToDuplicate.setTestcase(targetTestCase);
        listToCreate.add(objectToDuplicate);
    }
    return createList(listToCreate);
}
Also used : Answer(org.cerberus.util.answer.Answer) TestCaseLabel(org.cerberus.crud.entity.TestCaseLabel) ArrayList(java.util.ArrayList)

Example 97 with Answer

use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.

the class TestCaseLabelService method compareListAndUpdateInsertDeleteElements.

@Override
public Answer compareListAndUpdateInsertDeleteElements(String test, String testCase, List<TestCaseLabel> newList) {
    Answer ans = new Answer(null);
    MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);
    Answer finalAnswer = new Answer(msg1);
    List<TestCaseLabel> oldList = new ArrayList();
    try {
        oldList = this.convert(this.readByTestTestCase(test, testCase));
    } catch (CerberusException ex) {
        LOG.error(ex);
    }
    /**
     * Update and Create all objects database Objects from newList
     */
    List<TestCaseLabel> listToUpdateOrInsert = new ArrayList(newList);
    listToUpdateOrInsert.removeAll(oldList);
    List<TestCaseLabel> listToUpdateOrInsertToIterate = new ArrayList(listToUpdateOrInsert);
    for (TestCaseLabel objectDifference : listToUpdateOrInsertToIterate) {
        for (TestCaseLabel objectInDatabase : oldList) {
            if (objectDifference.hasSameKey(objectInDatabase)) {
                ans = this.update(objectDifference);
                finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
                listToUpdateOrInsert.remove(objectDifference);
            }
        }
    }
    /**
     * Delete all objects database Objects that do not exist from newList
     */
    List<TestCaseLabel> listToDelete = new ArrayList(oldList);
    listToDelete.removeAll(newList);
    List<TestCaseLabel> listToDeleteToIterate = new ArrayList(listToDelete);
    for (TestCaseLabel tcsDifference : listToDeleteToIterate) {
        for (TestCaseLabel tcsInPage : newList) {
            if (tcsDifference.hasSameKey(tcsInPage)) {
                listToDelete.remove(tcsDifference);
            }
        }
    }
    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) CerberusException(org.cerberus.exception.CerberusException) MessageEvent(org.cerberus.engine.entity.MessageEvent) TestCaseLabel(org.cerberus.crud.entity.TestCaseLabel) ArrayList(java.util.ArrayList)

Example 98 with Answer

use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.

the class TestCaseStepActionService method duplicateList.

@Override
public Answer duplicateList(List<TestCaseStepAction> objectList, String targetTest, String targetTestCase) {
    Answer ans = new Answer(null);
    List<TestCaseStepAction> listToCreate = new ArrayList();
    for (TestCaseStepAction objectToDuplicate : objectList) {
        objectToDuplicate.setTest(targetTest);
        objectToDuplicate.setTestCase(targetTestCase);
        listToCreate.add(objectToDuplicate);
    }
    ans = createList(listToCreate);
    return ans;
}
Also used : Answer(org.cerberus.util.answer.Answer) TestCaseStepAction(org.cerberus.crud.entity.TestCaseStepAction) ArrayList(java.util.ArrayList)

Example 99 with Answer

use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.

the class TestCaseStepService method duplicateList.

@Override
public Answer duplicateList(List<TestCaseStep> listOfSteps, String targetTest, String targetTestCase) {
    Answer ans = new Answer(null);
    List<TestCaseStep> listToCreate = new ArrayList();
    for (TestCaseStep objectToDuplicate : listOfSteps) {
        objectToDuplicate.setTest(targetTest);
        objectToDuplicate.setTestCase(targetTestCase);
        listToCreate.add(objectToDuplicate);
    }
    return createList(listToCreate);
}
Also used : Answer(org.cerberus.util.answer.Answer) ArrayList(java.util.ArrayList) TestCaseStep(org.cerberus.crud.entity.TestCaseStep)

Example 100 with Answer

use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.

the class TestDataLibDataService method compareListAndUpdateInsertDeleteElements.

@Override
public Answer compareListAndUpdateInsertDeleteElements(Integer testDataLibId, List<TestDataLibData> newList) {
    Answer ans = new Answer(null);
    MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);
    Answer finalAnswer = new Answer(msg1);
    List<TestDataLibData> oldList = new ArrayList();
    try {
        oldList = this.convert(this.readByVarious(testDataLibId, null, null, null));
    } catch (CerberusException ex) {
        LOG.error(ex);
    }
    /**
     * Update and Create all objects database Objects from newList
     */
    List<TestDataLibData> listToUpdateOrInsert = new ArrayList(newList);
    listToUpdateOrInsert.removeAll(oldList);
    List<TestDataLibData> listToUpdateOrInsertToIterate = new ArrayList(listToUpdateOrInsert);
    for (TestDataLibData objectDifference : listToUpdateOrInsertToIterate) {
        for (TestDataLibData objectInDatabase : oldList) {
            if (objectDifference.hasSameKey(objectInDatabase)) {
                ans = this.update(objectDifference);
                finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
                listToUpdateOrInsert.remove(objectDifference);
            }
        }
    }
    /**
     * Delete all objects database Objects that do not exist from newList
     */
    List<TestDataLibData> listToDelete = new ArrayList(oldList);
    listToDelete.removeAll(newList);
    List<TestDataLibData> listToDeleteToIterate = new ArrayList(listToDelete);
    for (TestDataLibData tcsDifference : listToDeleteToIterate) {
        for (TestDataLibData tcsInPage : newList) {
            if (tcsDifference.hasSameKey(tcsInPage)) {
                listToDelete.remove(tcsDifference);
            }
        }
    }
    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) CerberusException(org.cerberus.exception.CerberusException) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList) TestDataLibData(org.cerberus.crud.entity.TestDataLibData)

Aggregations

Answer (org.cerberus.util.answer.Answer)241 MessageEvent (org.cerberus.engine.entity.MessageEvent)227 Connection (java.sql.Connection)127 PreparedStatement (java.sql.PreparedStatement)127 SQLException (java.sql.SQLException)127 ApplicationContext (org.springframework.context.ApplicationContext)77 JSONObject (org.json.JSONObject)75 ILogEventService (org.cerberus.crud.service.ILogEventService)74 PolicyFactory (org.owasp.html.PolicyFactory)60 AnswerItem (org.cerberus.util.answer.AnswerItem)53 CerberusException (org.cerberus.exception.CerberusException)45 ArrayList (java.util.ArrayList)35 JSONException (org.json.JSONException)26 IOException (java.io.IOException)23 ServletException (javax.servlet.ServletException)19 JSONArray (org.json.JSONArray)15 LogEventService (org.cerberus.crud.service.impl.LogEventService)13 TestCase (org.cerberus.crud.entity.TestCase)10 ITestCaseService (org.cerberus.crud.service.ITestCaseService)10 CountryEnvParam (org.cerberus.crud.entity.CountryEnvParam)8