Search in sources :

Example 16 with TestCase

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

the class TestCaseExecutionService method createAllTestCaseExecution.

@Override
public List<TestCaseExecution> createAllTestCaseExecution(List<TestCase> testCaseList, List<String> envList, List<String> countryList) {
    List<TestCaseExecution> result = new ArrayList<TestCaseExecution>();
    for (TestCase tc : testCaseList) {
        for (String environment : envList) {
            for (String country : countryList) {
                TestCaseExecution execution = new TestCaseExecution();
                execution.setTest(tc.getTest());
                execution.setTestCase(tc.getTestCase());
                execution.setEnvironment(environment);
                execution.setCountry(country);
                result.add(execution);
            }
        }
    }
    return result;
}
Also used : TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) TestCase(org.cerberus.crud.entity.TestCase) ArrayList(java.util.ArrayList)

Example 17 with TestCase

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

the class TestCaseExecutionService method readByKeyWithDependency.

@Override
public AnswerItem readByKeyWithDependency(long executionId) {
    AnswerItem tce = this.readByKey(executionId);
    TestCaseExecution testCaseExecution = (TestCaseExecution) tce.getItem();
    AnswerItem<TestCase> ai = testCaseService.readByKeyWithDependency(testCaseExecution.getTest(), testCaseExecution.getTestCase());
    testCaseExecution.setTestCaseObj(ai.getItem());
    AnswerList a = testCaseExecutionDataService.readByIdWithDependency(executionId);
    for (Object object : a.getDataList()) {
        TestCaseExecutionData tced = (TestCaseExecutionData) object;
        if (tced.getIndex() == 1) {
            testCaseExecution.getTestCaseExecutionDataMap().put(tced.getProperty(), tced);
        }
    }
    // We frist add the 'Pres Testing' testcase execution steps.
    AnswerList preTestCaseSteps = testCaseStepExecutionService.readByVarious1WithDependency(executionId, "Pre Testing", null);
    testCaseExecution.setTestCaseStepExecutionList(preTestCaseSteps.getDataList());
    // Then we add the steps from the main testcase.
    AnswerList steps = testCaseStepExecutionService.readByVarious1WithDependency(executionId, testCaseExecution.getTest(), testCaseExecution.getTestCase());
    testCaseExecution.addTestCaseStepExecutionList(steps.getDataList());
    AnswerList files = testCaseExecutionFileService.readByVarious(executionId, "");
    testCaseExecution.setFileList((List<TestCaseExecutionFile>) files.getDataList());
    AnswerItem response = new AnswerItem(testCaseExecution, tce.getResultMessage());
    return response;
}
Also used : TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) AnswerList(org.cerberus.util.answer.AnswerList) TestCase(org.cerberus.crud.entity.TestCase) TestCaseExecutionData(org.cerberus.crud.entity.TestCaseExecutionData) TestCaseExecutionFile(org.cerberus.crud.entity.TestCaseExecutionFile) AnswerItem(org.cerberus.util.answer.AnswerItem)

Example 18 with TestCase

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

the class TestCaseService method findTestCaseActiveAutomatedBySystem.

@Override
public List<TestCase> findTestCaseActiveAutomatedBySystem(String test, String system) {
    TestCase tCase = factoryTCase.create(test, null, null, null, null, null, null, null, null, null, null, null, null, null, -1, null, null, null, null, null, "Y", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
    List<TestCase> result = new ArrayList();
    List<TestCase> testCases = findTestCaseByAllCriteria(tCase, null, system);
    for (TestCase testCase : testCases) {
        if (!testCase.getGroup().equals("PRIVATE")) {
            result.add(testCase);
        }
    }
    return result;
}
Also used : TestCase(org.cerberus.crud.entity.TestCase) IFactoryTestCase(org.cerberus.crud.factory.IFactoryTestCase) ArrayList(java.util.ArrayList)

Example 19 with TestCase

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

the class TestCaseService method findTestCaseByKeyWithDependency.

@Override
public TestCase findTestCaseByKeyWithDependency(String test, String testCase) throws CerberusException {
    TestCase newTcase;
    newTcase = findTestCaseByKey(test, testCase);
    if (newTcase == null) {
        // TODO:FN temporary debug messages
        LOG.warn("test case is null - test: " + test + " testcase: " + testCase);
    } else {
        List<TestCaseCountry> testCaseCountry = testCaseCountryService.findTestCaseCountryByTestTestCase(test, testCase);
        List<TestCaseCountry> testCaseCountryToAdd = new ArrayList();
        for (TestCaseCountry tcc : testCaseCountry) {
            List<TestCaseCountryProperties> properties = testCaseCountryPropertiesService.findListOfPropertyPerTestTestCaseCountry(test, testCase, tcc.getCountry());
            tcc.setTestCaseCountryProperty(properties);
            testCaseCountryToAdd.add(tcc);
        }
        newTcase.setTestCaseCountry(testCaseCountryToAdd);
        String initialTest = test;
        String initialTc = testCase;
        List<TestCaseStep> tcs = testCaseStepService.getListOfSteps(test, testCase);
        List<TestCaseStep> tcsToAdd = new ArrayList();
        for (TestCaseStep step : tcs) {
            int stepNumber = step.getStep();
            int initialStep = step.getStep();
            if (step.getUseStep().equals("Y")) {
                test = step.getUseStepTest();
                testCase = step.getUseStepTestCase();
                stepNumber = step.getUseStepStep();
            }
            List<TestCaseStepAction> tcsa = testCaseStepActionService.getListOfAction(test, testCase, stepNumber);
            List<TestCaseStepAction> tcsaToAdd = new ArrayList();
            for (TestCaseStepAction action : tcsa) {
                List<TestCaseStepActionControl> tcsac = testCaseStepActionControlService.findControlByTestTestCaseStepSequence(test, testCase, stepNumber, action.getSequence());
                List<TestCaseStepActionControl> tcsacToAdd = new ArrayList();
                for (TestCaseStepActionControl control : tcsac) {
                    control.setTest(initialTest);
                    control.setTestCase(initialTc);
                    control.setStep(initialStep);
                    tcsacToAdd.add(control);
                }
                action.setTestCaseStepActionControl(tcsacToAdd);
                action.setTest(initialTest);
                action.setTestCase(initialTc);
                action.setStep(initialStep);
                tcsaToAdd.add(action);
            }
            step.setTestCaseStepAction(tcsaToAdd);
            tcsToAdd.add(step);
        }
        newTcase.setTestCaseStep(tcsToAdd);
    }
    return newTcase;
}
Also used : TestCaseStepAction(org.cerberus.crud.entity.TestCaseStepAction) TestCaseCountryProperties(org.cerberus.crud.entity.TestCaseCountryProperties) ArrayList(java.util.ArrayList) TestCaseStep(org.cerberus.crud.entity.TestCaseStep) TestCase(org.cerberus.crud.entity.TestCase) IFactoryTestCase(org.cerberus.crud.factory.IFactoryTestCase) TestCaseCountry(org.cerberus.crud.entity.TestCaseCountry) TestCaseStepActionControl(org.cerberus.crud.entity.TestCaseStepActionControl)

Example 20 with TestCase

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

the class ReadTestCase method findTestCaseWithStep.

private AnswerItem findTestCaseWithStep(ApplicationContext appContext, HttpServletRequest request, String test, String testCase) throws JSONException {
    AnswerItem item = new AnswerItem();
    JSONObject object = new JSONObject();
    HashMap<String, JSONObject> hashProp = new HashMap<String, JSONObject>();
    JSONObject jsonResponse = new JSONObject();
    testCaseService = appContext.getBean(ITestCaseService.class);
    testCaseCountryService = appContext.getBean(ITestCaseCountryService.class);
    testCaseStepService = appContext.getBean(ITestCaseStepService.class);
    testCaseStepActionService = appContext.getBean(ITestCaseStepActionService.class);
    testCaseStepActionControlService = appContext.getBean(ITestCaseStepActionControlService.class);
    ITestCaseCountryPropertiesService testCaseCountryPropertiesService = appContext.getBean(ITestCaseCountryPropertiesService.class);
    // finds the testcase
    AnswerItem answer = testCaseService.readByKey(test, testCase);
    AnswerList testCaseCountryList = testCaseCountryService.readByTestTestCase(null, test, testCase);
    AnswerList testCaseStepList = testCaseStepService.readByTestTestCase(test, testCase);
    AnswerList testCaseStepActionList = testCaseStepActionService.readByTestTestCase(test, testCase);
    AnswerList testCaseStepActionControlList = testCaseStepActionControlService.readByTestTestCase(test, testCase);
    if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
        // if the service returns an OK message then we can get the item and convert it to JSONformat
        TestCase tc = (TestCase) answer.getItem();
        object = convertToJSONObject(tc);
        object.put("countryList", new JSONObject());
        jsonResponse.put("hasPermissionsDelete", testCaseService.hasPermissionsDelete(tc, request));
        jsonResponse.put("hasPermissionsUpdate", testCaseService.hasPermissionsUpdate(tc, request));
        jsonResponse.put("hasPermissionsStepLibrary", (request.isUserInRole("TestStepLibrary")));
    }
    for (TestCaseCountry country : (List<TestCaseCountry>) testCaseCountryList.getDataList()) {
        object.getJSONObject("countryList").put(country.getCountry(), country.getCountry());
    }
    JSONArray stepList = new JSONArray();
    Gson gson = new Gson();
    for (TestCaseStep step : (List<TestCaseStep>) testCaseStepList.getDataList()) {
        step = testCaseStepService.modifyTestCaseStepDataFromUsedStep(step);
        JSONObject jsonStep = new JSONObject(gson.toJson(step));
        // Fill JSON with step info
        jsonStep.put("objType", "step");
        // Add a JSON array for Action List from this step
        jsonStep.put("actionList", new JSONArray());
        if (step.getUseStep().equals("Y")) {
            // If this step is imported from library, we call the service to retrieve actions
            TestCaseStep usedStep = testCaseStepService.findTestCaseStep(step.getUseStepTest(), step.getUseStepTestCase(), step.getUseStepStep());
            List<TestCaseStepAction> actionList = testCaseStepActionService.getListOfAction(step.getUseStepTest(), step.getUseStepTestCase(), step.getUseStepStep());
            List<TestCaseStepActionControl> controlList = testCaseStepActionControlService.findControlByTestTestCaseStep(step.getUseStepTest(), step.getUseStepTestCase(), step.getUseStepStep());
            List<TestCaseCountryProperties> properties = testCaseCountryPropertiesService.findDistinctPropertiesOfTestCase(step.getUseStepTest(), step.getUseStepTestCase());
            // Get the used step sort
            jsonStep.put("useStepStepSort", usedStep.getSort());
            // retrieve the inherited properties
            for (TestCaseCountryProperties prop : properties) {
                JSONObject propertyFound = new JSONObject();
                propertyFound.put("fromTest", prop.getTest());
                propertyFound.put("fromTestCase", prop.getTestCase());
                propertyFound.put("property", prop.getProperty());
                propertyFound.put("description", prop.getDescription());
                propertyFound.put("type", prop.getType());
                propertyFound.put("database", prop.getDatabase());
                propertyFound.put("value1", prop.getValue1());
                propertyFound.put("value2", prop.getValue2());
                propertyFound.put("length", prop.getLength());
                propertyFound.put("rowLimit", prop.getRowLimit());
                propertyFound.put("nature", prop.getNature());
                List<String> countriesSelected = testCaseCountryPropertiesService.findCountryByProperty(prop);
                JSONArray countries = new JSONArray();
                for (String country : countriesSelected) {
                    countries.put(country);
                }
                propertyFound.put("country", countries);
                hashProp.put(prop.getTest() + "_" + prop.getTestCase() + "_" + prop.getProperty(), propertyFound);
            }
            for (TestCaseStepAction action : actionList) {
                if (action.getStep() == step.getUseStepStep()) {
                    JSONObject jsonAction = new JSONObject(gson.toJson(action));
                    jsonAction.put("objType", "action");
                    jsonAction.put("controlList", new JSONArray());
                    // We fill the action with the corresponding controls
                    for (TestCaseStepActionControl control : controlList) {
                        if (control.getStep() == step.getUseStepStep() && control.getSequence() == action.getSequence()) {
                            JSONObject jsonControl = new JSONObject(gson.toJson(control));
                            jsonControl.put("objType", "control");
                            jsonAction.getJSONArray("controlList").put(jsonControl);
                        }
                    }
                    // we put the action in the actionList for the corresponding step
                    jsonStep.getJSONArray("actionList").put(jsonAction);
                }
            }
        } else {
            // else, we fill the actionList with the action from this step
            for (TestCaseStepAction action : (List<TestCaseStepAction>) testCaseStepActionList.getDataList()) {
                if (action.getStep() == step.getStep()) {
                    JSONObject jsonAction = new JSONObject(gson.toJson(action));
                    jsonAction.put("objType", "action");
                    jsonAction.put("controlList", new JSONArray());
                    // We fill the action with the corresponding controls
                    for (TestCaseStepActionControl control : (List<TestCaseStepActionControl>) testCaseStepActionControlList.getDataList()) {
                        if (control.getStep() == step.getStep() && control.getSequence() == action.getSequence()) {
                            JSONObject jsonControl = new JSONObject(gson.toJson(control));
                            jsonControl.put("objType", "control");
                            jsonAction.getJSONArray("controlList").put(jsonControl);
                        }
                    }
                    // we put the action in the actionList for the corresponding step
                    jsonStep.getJSONArray("actionList").put(jsonAction);
                }
            }
        }
        stepList.put(jsonStep);
    }
    jsonResponse.put("info", object);
    jsonResponse.put("stepList", stepList);
    jsonResponse.put("inheritedProp", hashProp.values());
    item.setItem(jsonResponse);
    item.setResultMessage(answer.getResultMessage());
    return item;
}
Also used : ITestCaseStepActionService(org.cerberus.crud.service.ITestCaseStepActionService) TestCaseStepAction(org.cerberus.crud.entity.TestCaseStepAction) TestCaseCountryProperties(org.cerberus.crud.entity.TestCaseCountryProperties) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Gson(com.google.gson.Gson) TestCaseStep(org.cerberus.crud.entity.TestCaseStep) ITestCaseCountryService(org.cerberus.crud.service.ITestCaseCountryService) ITestCaseCountryPropertiesService(org.cerberus.crud.service.ITestCaseCountryPropertiesService) ITestCaseService(org.cerberus.crud.service.ITestCaseService) TestCaseCountry(org.cerberus.crud.entity.TestCaseCountry) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List) TestCaseStepActionControl(org.cerberus.crud.entity.TestCaseStepActionControl) AnswerList(org.cerberus.util.answer.AnswerList) ITestCaseStepService(org.cerberus.crud.service.ITestCaseStepService) JSONArray(org.json.JSONArray) ITestCaseStepActionControlService(org.cerberus.crud.service.ITestCaseStepActionControlService) AnswerItem(org.cerberus.util.answer.AnswerItem) JSONObject(org.json.JSONObject) TestCase(org.cerberus.crud.entity.TestCase)

Aggregations

TestCase (org.cerberus.crud.entity.TestCase)68 ITestCaseService (org.cerberus.crud.service.ITestCaseService)30 ArrayList (java.util.ArrayList)29 IFactoryTestCase (org.cerberus.crud.factory.IFactoryTestCase)29 JSONObject (org.json.JSONObject)26 AnswerItem (org.cerberus.util.answer.AnswerItem)24 ApplicationContext (org.springframework.context.ApplicationContext)24 MessageEvent (org.cerberus.engine.entity.MessageEvent)23 SQLException (java.sql.SQLException)17 TestCaseCountry (org.cerberus.crud.entity.TestCaseCountry)17 JSONArray (org.json.JSONArray)17 PolicyFactory (org.owasp.html.PolicyFactory)17 Connection (java.sql.Connection)16 PreparedStatement (java.sql.PreparedStatement)16 ResultSet (java.sql.ResultSet)16 CerberusException (org.cerberus.exception.CerberusException)16 TestCaseStep (org.cerberus.crud.entity.TestCaseStep)15 ILogEventService (org.cerberus.crud.service.ILogEventService)15 AnswerList (org.cerberus.util.answer.AnswerList)15 List (java.util.List)13