Search in sources :

Example 1 with TestScenarioGroupResource

use of jp.ossc.nimbus.service.test.TestScenarioGroup.TestScenarioGroupResource in project nimbus by nimbus-org.

the class TestControllerService method endScenarioGroup.

public synchronized void endScenarioGroup() throws Exception {
    if (currentTestScenarioGroup == null) {
        return;
    }
    getLogger().write("TC___00007", currentTestScenarioGroup.getScenarioGroupId());
    try {
        setUserId(null);
        TestScenarioGroupContext context = (TestScenarioGroupContext) contextMap.get(currentTestScenarioGroup.getScenarioGroupId());
        if (context == null) {
            throw new TestException("ScenarioGroup is not started. scenarioGroupId=" + currentTestScenarioGroup.getScenarioGroupId());
        }
        if (context != null) {
            TestScenarioContext[] testScenarioContexts = context.getTestScenarioContexts();
            if (testScenarioContexts != null) {
                for (int i = 0; i < testScenarioContexts.length; i++) {
                    TestScenario.Status scenarioStatus = testScenarioContexts[i].getStatus();
                    if (scenarioStatus != null && scenarioStatus.getState() == TestScenario.Status.STARTED) {
                        endScenario(testScenarioContexts[i].getTestScenario().getScenarioId());
                    }
                }
            }
        }
        if (testEventListeners != null) {
            for (int i = 0; i < testEventListeners.length; i++) {
                testEventListeners[i].endScenarioGroup();
            }
        }
        TestContextImpl scenarioGroupTestContext = (TestContextImpl) context.getTestContext();
        TestScenarioGroup testScenarioGroup = context.getTestScenarioGroup();
        TestScenarioGroupResource testScenarioGroupResource = testScenarioGroup.getTestScenarioGroupResource();
        if (testPhase == null || testScenarioGroupResource.isExecutable(testPhase)) {
            TestScenarioGroupImpl.StatusImpl status = (TestScenarioGroupImpl.StatusImpl) context.getStatus();
            String[] finallyActionIds = testScenarioGroupResource.getFinallyActionIds();
            try {
                executeAction(context, scenarioGroupTestContext, status, finallyActionIds, true, false, false);
            } catch (NotSupportActionException e) {
                throw new TestException("This action is not support at FinallyAction of ScenarioGroup. action=" + e.getAction().getClass().getName());
            }
            status.setState(TestScenarioGroup.Status.END);
            status.setEndTime(new Date());
        }
        currentTestScenarioGroup = null;
        currentTestScenario = null;
        currentTestCase = null;
    } catch (Exception e) {
        getLogger().write("TC___00008", currentTestScenarioGroup.getScenarioGroupId(), e);
        throw e;
    }
}
Also used : TestScenarioGroupResource(jp.ossc.nimbus.service.test.TestScenarioGroup.TestScenarioGroupResource) Date(java.util.Date) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException)

Example 2 with TestScenarioGroupResource

use of jp.ossc.nimbus.service.test.TestScenarioGroup.TestScenarioGroupResource in project nimbus by nimbus-org.

the class TestControllerService method startScenarioGroup.

public synchronized void startScenarioGroup(String userId, String scenarioGroupId) throws Exception {
    getLogger().write("TC___00005", new Object[] { scenarioGroupId, userId });
    try {
        setUserId(userId);
        if (currentTestScenarioGroup != null) {
            throw new TestException("ScenarioGroup is already started. ScenarioGroupId=" + currentTestScenarioGroup.getScenarioGroupId() + " UserId=" + currentTestScenarioGroup.getStatus().getUserId());
        }
        String[] scenarioGroupIds = testResourceManager.getScenarioGroupIds();
        if (!Arrays.asList(scenarioGroupIds).contains(scenarioGroupId)) {
            throw new TestException("This ScenarioGroupId does not exist. ScenarioGroupId=" + scenarioGroupId);
        }
        File resourceDir = new File(testResourceFileBaseDirectory, scenarioGroupId);
        downloadTestScenarioGroupResource(resourceDir, scenarioGroupId);
        if (testEventListeners != null) {
            for (int i = 0; i < testEventListeners.length; i++) {
                testEventListeners[i].startScenarioGroup(userId, scenarioGroupId);
            }
        }
        TestScenarioGroupImpl testScenarioGroup = new TestScenarioGroupImpl(scenarioGroupId);
        testScenarioGroup.setController(this);
        TestScenarioGroupContext context = new TestScenarioGroupContext();
        contextMap.put(scenarioGroupId, context);
        context.setTestScenarioGroup(testScenarioGroup);
        TestScenarioGroupImpl.StatusImpl status = new TestScenarioGroupImpl.StatusImpl(userId);
        context.setStatus(status);
        TestContextImpl testContext = new TestContextImpl();
        testContext.setCurrentDirectory(resourceDir);
        context.setTestContext(testContext);
        testContext.setTestScenarioGroup(testScenarioGroup);
        TestScenarioGroupResource testScenarioGroupResource = testScenarioGroup.getTestScenarioGroupResource();
        if (testPhase == null || testScenarioGroupResource.isExecutable(testPhase)) {
            String[] beforeActionIds = testScenarioGroupResource.getBeforeActionIds();
            try {
                executeAction(context, testContext, status, beforeActionIds, true, true, true);
            } catch (NotSupportActionException e) {
                throw new TestException("This action is not support at BeforeAction of ScenarioGroup. action=" + e.getAction().getClass().getName());
            }
            boolean result = context.isAllActionSuccess();
            status.setResult(result);
            status.setStartTime(new Date());
            if (result) {
                status.setState(TestScenarioGroup.Status.STARTED);
            } else {
                status.setState(TestScenarioGroup.Status.ERROR);
            }
        }
        currentTestScenarioGroup = testScenarioGroup;
    } catch (Exception e) {
        getLogger().write("TC___00006", scenarioGroupId, e);
        throw e;
    }
}
Also used : TestScenarioGroupResource(jp.ossc.nimbus.service.test.TestScenarioGroup.TestScenarioGroupResource) Date(java.util.Date) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException) RecurciveSearchFile(jp.ossc.nimbus.io.RecurciveSearchFile) File(java.io.File)

Example 3 with TestScenarioGroupResource

use of jp.ossc.nimbus.service.test.TestScenarioGroup.TestScenarioGroupResource in project nimbus by nimbus-org.

the class HtmlTestCaseProgressReporterService method reportScenarioGroup.

private void reportScenarioGroup(PrintWriter pw, TestController controller, TestScenarioGroup group) throws Exception {
    TestScenario[] scenarios = controller.getScenarios(group.getScenarioGroupId());
    Map scenarioTestcaseMap = new TreeMap();
    int testCaseCount = 0;
    for (int index = 0; index < scenarios.length; index++) {
        TestCase[] cases = controller.getTestCases(group.getScenarioGroupId(), scenarios[index].getScenarioId());
        if (cases.length == 0) {
            testCaseCount++;
        } else {
            testCaseCount += cases.length;
        }
        scenarioTestcaseMap.put(scenarios[index].getScenarioId(), cases);
    }
    TestScenarioGroupResource groupResource = group.getTestScenarioGroupResource();
    pw.println("<tr>");
    printResource(pw, groupResource, group.getScenarioGroupId(), "rowgroup", testCaseCount);
    Iterator ite = scenarioTestcaseMap.keySet().iterator();
    boolean isFirst = true;
    while (ite.hasNext()) {
        String scenarioId = (String) ite.next();
        TestScenario testScenario = controller.getScenario(group.getScenarioGroupId(), scenarioId);
        TestScenario.TestScenarioResource testScenarioResource = testScenario.getTestScenarioResource();
        if (testScenarioResource == null) {
            continue;
        }
        TestCase[] cases = (TestCase[]) scenarioTestcaseMap.get(scenarioId);
        int count = cases.length;
        if (count == 0) {
            count = 1;
        }
        if (!isFirst) {
            pw.println("<tr>");
        }
        isFirst = false;
        printResource(pw, testScenarioResource, scenarioId, "rowgroup", count);
        if (cases.length == 0) {
            pw.println("</tr>");
        } else {
            printResource(pw, cases[0].getTestCaseResource(), cases[0].getTestCaseId(), "row", 0);
            pw.println("</tr>");
            for (int index = 1; index < cases.length; index++) {
                pw.println("<tr>");
                printResource(pw, cases[index].getTestCaseResource(), cases[index].getTestCaseId(), "row", 0);
                pw.println("</tr>");
            }
        }
    }
}
Also used : TestScenarioGroupResource(jp.ossc.nimbus.service.test.TestScenarioGroup.TestScenarioGroupResource) TestCase(jp.ossc.nimbus.service.test.TestCase) TestScenario(jp.ossc.nimbus.service.test.TestScenario) Iterator(java.util.Iterator) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Aggregations

TestScenarioGroupResource (jp.ossc.nimbus.service.test.TestScenarioGroup.TestScenarioGroupResource)3 IOException (java.io.IOException)2 Date (java.util.Date)2 SAXException (org.xml.sax.SAXException)2 SAXParseException (org.xml.sax.SAXParseException)2 File (java.io.File)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 RecurciveSearchFile (jp.ossc.nimbus.io.RecurciveSearchFile)1 TestCase (jp.ossc.nimbus.service.test.TestCase)1 TestScenario (jp.ossc.nimbus.service.test.TestScenario)1