Search in sources :

Example 1 with NimbusEntityResolver

use of jp.ossc.nimbus.core.NimbusEntityResolver in project nimbus by nimbus-org.

the class BeanFlowRestServerService method reload.

public synchronized void reload() throws Exception {
    if (serverDefinitionPath == null || serverDefinitionPath.length() == 0) {
        throw new IllegalArgumentException("ServerDefinitionPath is null");
    }
    File serviceDefDir = null;
    if (getServiceNameObject() != null) {
        ServiceMetaData metaData = ServiceManagerFactory.getServiceMetaData(getServiceNameObject());
        if (metaData != null) {
            jp.ossc.nimbus.core.ServiceLoader loader = metaData.getServiceLoader();
            if (loader != null) {
                String filePath = loader.getServiceURL().getFile();
                if (filePath != null) {
                    serviceDefDir = new File(filePath).getParentFile();
                }
            }
        }
    }
    URL url = null;
    File localFile = new File(serverDefinitionPath);
    if (!localFile.exists() && serviceDefDir != null) {
        localFile = new File(serviceDefDir, serverDefinitionPath);
    }
    if (localFile.exists()) {
        if (!localFile.isFile()) {
            throw new IllegalArgumentException("ServerDefinitionPath must be file : " + localFile);
        }
        try {
            url = localFile.toURI().toURL();
        } catch (MalformedURLException e) {
        // この例外は発生しないはず
        }
    } else {
        final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        final URL resource = classLoader.getResource(serverDefinitionPath);
        if (resource != null) {
            url = resource;
        }
    }
    if (url == null) {
        throw new IllegalArgumentException("ServerDefinitionPath not found : " + serverDefinitionPath);
    }
    final InputSource inputSource = new InputSource(url.openStream());
    DocumentBuilderFactory domFactory = null;
    if (documentBuilderFactoryClassName == null) {
        domFactory = DocumentBuilderFactory.newInstance();
    } else {
        domFactory = (DocumentBuilderFactory) Class.forName(documentBuilderFactoryClassName, true, NimbusClassLoader.getInstance()).newInstance();
    }
    domFactory.setValidating(isValidate());
    final DocumentBuilder builder = domFactory.newDocumentBuilder();
    final NimbusEntityResolver resolver = new NimbusEntityResolver();
    builder.setEntityResolver(resolver);
    final MyErrorHandler handler = new MyErrorHandler();
    builder.setErrorHandler(handler);
    final Document doc = builder.parse(inputSource);
    if (handler.isError()) {
        throw new DeploymentException("Failed to parse ServerDefinition");
    }
    final RestServerMetaData serverData = new RestServerMetaData();
    serverData.importXML(doc.getDocumentElement());
    restServerMetaData = serverData;
}
Also used : MalformedURLException(java.net.MalformedURLException) InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NimbusEntityResolver(jp.ossc.nimbus.core.NimbusEntityResolver) ServiceMetaData(jp.ossc.nimbus.core.ServiceMetaData) URL(java.net.URL) DocumentBuilder(javax.xml.parsers.DocumentBuilder) NimbusClassLoader(jp.ossc.nimbus.core.NimbusClassLoader) DeploymentException(jp.ossc.nimbus.core.DeploymentException) File(java.io.File)

Example 2 with NimbusEntityResolver

use of jp.ossc.nimbus.core.NimbusEntityResolver in project nimbus by nimbus-org.

the class TestControllerService method getRootElement.

private Element getRootElement(File file, InputStream is) throws Exception {
    InputSource inputSource = new InputSource(is);
    DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    domFactory.setValidating(true);
    DocumentBuilder builder = domFactory.newDocumentBuilder();
    NimbusEntityResolver resolver = new NimbusEntityResolver();
    builder.setEntityResolver(resolver);
    ParseErrorHandler handler = new ParseErrorHandler(file);
    builder.setErrorHandler(handler);
    Document doc = builder.parse(inputSource);
    if (handler.isError()) {
        getLogger().write("TC___00004", handler.getException());
        throw handler.getException();
    }
    return doc.getDocumentElement();
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NimbusEntityResolver(jp.ossc.nimbus.core.NimbusEntityResolver) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Document(org.w3c.dom.Document)

Example 3 with NimbusEntityResolver

use of jp.ossc.nimbus.core.NimbusEntityResolver in project nimbus by nimbus-org.

the class TestRunner method main.

public static void main(String[] args) {
    if (args.length != 0 && args[0].equals("-help")) {
        usage();
        return;
    }
    String runnerDefPath = null;
    final List servicePaths = new ArrayList();
    boolean validate = false;
    boolean verbose = false;
    String userId = null;
    for (int i = 0; i < args.length; i++) {
        if (args[i].equals("-verbose")) {
            verbose = true;
        } else if (args[i].equals("-validate")) {
            validate = true;
        } else if (args[i].equals("-userId")) {
            userId = args[++i];
        } else if (runnerDefPath == null) {
            runnerDefPath = args[i];
        } else {
            servicePaths.add(args[i]);
        }
    }
    if (runnerDefPath == null || servicePaths.size() == 0) {
        usage();
        return;
    }
    if (userId == null) {
        userId = System.getProperty("user.name");
    }
    try {
        for (int i = 0, max = servicePaths.size(); i < max; i++) {
            if (!ServiceManagerFactory.loadManager((String) servicePaths.get(i), false, validate)) {
                System.exit(-1);
            }
        }
        if (!ServiceManagerFactory.checkLoadManagerCompleted()) {
            System.exit(-1);
        }
        TestController testController = null;
        List testReporterList = null;
        String phase = null;
        Map scenarioGroupMap = new HashMap();
        boolean isTest = true;
        try {
            final InputSource inputSource = new InputSource(new FileInputStream(runnerDefPath));
            final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
            domFactory.setValidating(validate);
            final DocumentBuilder builder = domFactory.newDocumentBuilder();
            final NimbusEntityResolver resolver = new NimbusEntityResolver();
            builder.setEntityResolver(resolver);
            final MyErrorHandler handler = new MyErrorHandler();
            builder.setErrorHandler(handler);
            final Document doc = builder.parse(inputSource);
            if (handler.isError()) {
                ServiceManagerFactory.getLogger().write("TR___00004", runnerDefPath);
                System.exit(-1);
            }
            final Element root = doc.getDocumentElement();
            isTest = MetaData.getOptionalBooleanAttribute(root, "test", true);
            final Element controllerElement = MetaData.getOptionalChild(root, "controller");
            final String controllerServiceNameStr = controllerElement == null ? "Nimbus#TestController" : MetaData.getElementContent(controllerElement, "Nimbus#TestController");
            final ServiceNameEditor editor = new ServiceNameEditor();
            editor.setAsText(controllerServiceNameStr);
            final ServiceName controllerServiceName = (ServiceName) editor.getValue();
            testController = (TestController) ServiceManagerFactory.getServiceObject(controllerServiceName);
            final Iterator reporterElements = MetaData.getChildrenByTagName(root, "reporter");
            testReporterList = new ArrayList();
            if (reporterElements.hasNext()) {
                while (reporterElements.hasNext()) {
                    final Element reporterElement = (Element) reporterElements.next();
                    final String reporterServiceNameStr = MetaData.getElementContent(reporterElement);
                    editor.setAsText(reporterServiceNameStr);
                    final ServiceName reporterServiceName = (ServiceName) editor.getValue();
                    TestReporter testReporter = (TestReporter) ServiceManagerFactory.getServiceObject(reporterServiceName);
                    testReporterList.add(testReporter);
                }
            } else {
                editor.setAsText("Nimbus#TestReporter");
                final ServiceName reporterServiceName = (ServiceName) editor.getValue();
                TestReporter testReporter = (TestReporter) ServiceManagerFactory.getServiceObject(reporterServiceName);
                testReporterList.add(testReporter);
            }
            final Element phaseElement = MetaData.getOptionalChild(root, "phase");
            if (phaseElement != null) {
                phase = MetaData.getElementContent(phaseElement, null);
            }
            testController.setTestPhase(phase);
            if (verbose) {
                ServiceManagerFactory.getLogger().write("TR___00005", phase);
            }
            final Iterator includeElements = MetaData.getChildrenByTagName(root, "include");
            if (includeElements.hasNext()) {
                while (includeElements.hasNext()) {
                    final Element includeElement = (Element) includeElements.next();
                    final Iterator scenarioGroupElements = MetaData.getChildrenByTagName(includeElement, "scenarioGroup");
                    while (scenarioGroupElements.hasNext()) {
                        final Element scenarioGroupElement = (Element) scenarioGroupElements.next();
                        final String scenarioGroupId = MetaData.getUniqueAttribute(scenarioGroupElement, "id");
                        Map scenarioMap = (Map) scenarioGroupMap.get(scenarioGroupId);
                        if (scenarioMap == null) {
                            scenarioMap = new HashMap();
                            scenarioGroupMap.put(scenarioGroupId, scenarioMap);
                        }
                        final Iterator scenarioElements = MetaData.getChildrenByTagName(scenarioGroupElement, "scenario");
                        if (scenarioElements.hasNext()) {
                            while (scenarioElements.hasNext()) {
                                final Element scenarioElement = (Element) scenarioElements.next();
                                final String scenarioId = MetaData.getUniqueAttribute(scenarioElement, "id");
                                Set testCaseSet = (Set) scenarioMap.get(scenarioId);
                                if (testCaseSet == null) {
                                    testCaseSet = new HashSet();
                                    scenarioMap.put(scenarioId, testCaseSet);
                                }
                                TestCase[] testCases = testController.getTestCases(scenarioGroupId, scenarioId);
                                for (int k = 0; k < testCases.length; k++) {
                                    testCaseSet.add(testCases[k].getTestCaseId());
                                }
                            }
                        } else {
                            TestScenario[] scenarios = testController.getScenarios(scenarioGroupId);
                            for (int j = 0; j < scenarios.length; j++) {
                                Set testCaseSet = (Set) scenarioMap.get(scenarios[j].getScenarioId());
                                if (testCaseSet == null) {
                                    testCaseSet = new HashSet();
                                    scenarioMap.put(scenarios[j].getScenarioId(), testCaseSet);
                                }
                                TestCase[] testCases = testController.getTestCases(scenarioGroupId, scenarios[j].getScenarioId());
                                for (int k = 0; k < testCases.length; k++) {
                                    testCaseSet.add(testCases[k].getTestCaseId());
                                }
                            }
                        }
                    }
                }
            } else {
                TestScenarioGroup[] groups = testController.getScenarioGroups();
                for (int i = 0; i < groups.length; i++) {
                    Map scenarioMap = (Map) scenarioGroupMap.get(groups[i].getScenarioGroupId());
                    if (scenarioMap == null) {
                        scenarioMap = new HashMap();
                        scenarioGroupMap.put(groups[i].getScenarioGroupId(), scenarioMap);
                    }
                    TestScenario[] scenarios = testController.getScenarios(groups[i].getScenarioGroupId());
                    for (int j = 0; j < scenarios.length; j++) {
                        Set testCaseSet = (Set) scenarioMap.get(scenarios[j].getScenarioId());
                        if (testCaseSet == null) {
                            testCaseSet = new HashSet();
                            scenarioMap.put(scenarios[j].getScenarioId(), testCaseSet);
                        }
                        TestCase[] testCases = testController.getTestCases(groups[i].getScenarioGroupId(), scenarios[j].getScenarioId());
                        for (int k = 0; k < testCases.length; k++) {
                            testCaseSet.add(testCases[k].getTestCaseId());
                        }
                    }
                }
            }
            final Iterator excludeElements = MetaData.getChildrenByTagName(root, "exclude");
            while (excludeElements.hasNext()) {
                final Element excludeElement = (Element) excludeElements.next();
                final Iterator scenarioGroupElements = MetaData.getChildrenByTagName(excludeElement, "scenarioGroup");
                while (scenarioGroupElements.hasNext()) {
                    final Element scenarioGroupElement = (Element) scenarioGroupElements.next();
                    final String scenarioGroupId = MetaData.getUniqueAttribute(scenarioGroupElement, "id");
                    Map scenarioMap = (Map) scenarioGroupMap.get(scenarioGroupId);
                    if (scenarioMap == null) {
                        continue;
                    }
                    final Iterator scenarioElements = MetaData.getChildrenByTagName(scenarioGroupElement, "scenario");
                    if (scenarioElements.hasNext()) {
                        while (scenarioElements.hasNext()) {
                            final Element scenarioElement = (Element) scenarioElements.next();
                            final String scenarioId = MetaData.getUniqueAttribute(scenarioElement, "id");
                            scenarioMap.remove(scenarioId);
                        }
                    } else {
                        scenarioGroupMap.remove(scenarioGroupId);
                    }
                }
            }
        } catch (Exception e) {
            ServiceManagerFactory.getLogger().write("TR___00004", runnerDefPath, e);
            System.exit(-1);
        }
        TestScenarioGroup[] groups = null;
        try {
            groups = testController.getScenarioGroups();
        } catch (Exception e) {
            // TODO
            ServiceManagerFactory.getLogger().write("TR___00006", e);
            System.exit(-1);
        }
        for (int i = 0; i < groups.length; i++) {
            Map scenarioMap = (Map) scenarioGroupMap.get(groups[i].getScenarioGroupId());
            if (scenarioMap == null) {
                continue;
            }
            try {
                if (verbose) {
                    ServiceManagerFactory.getLogger().write("TR___00007", groups[i].getScenarioGroupId());
                }
                if (isTest) {
                    testController.startScenarioGroup(userId, groups[i].getScenarioGroupId());
                    if (!groups[i].getStatus().getResult()) {
                        continue;
                    }
                } else {
                    testController.downloadTestScenarioGroupResource(groups[i].getScenarioGroupId());
                }
                TestScenario[] scenarios = testController.getScenarios(groups[i].getScenarioGroupId());
                for (int j = 0; j < scenarios.length; j++) {
                    Set testCaseSet = (Set) scenarioMap.get(scenarios[j].getScenarioId());
                    if (testCaseSet == null) {
                        continue;
                    }
                    try {
                        if (verbose) {
                            ServiceManagerFactory.getLogger().write("TR___00008", scenarios[j].getScenarioId());
                        }
                        if (isTest) {
                            testController.startScenario(userId, scenarios[j].getScenarioId());
                            if (!scenarios[j].getStatus().getResult()) {
                                testController.cancelScenario(scenarios[j].getScenarioId());
                                continue;
                            }
                            int defaultTestCaseErrorContinue = scenarios[j].getTestScenarioResource().getErrorContinue();
                            TestCase[] testCases = testController.getTestCases(groups[i].getScenarioGroupId(), scenarios[j].getScenarioId());
                            for (int k = 0; k < testCases.length; k++) {
                                if (!testCaseSet.contains(testCases[k].getTestCaseId())) {
                                    continue;
                                }
                                try {
                                    if (verbose) {
                                        ServiceManagerFactory.getLogger().write("TR___00009", testCases[k].getTestCaseId());
                                    }
                                    testController.startTestCase(userId, scenarios[j].getScenarioId(), testCases[k].getTestCaseId());
                                    if (testCases[k].getStatus().getResult()) {
                                        testController.endTestCase(scenarios[j].getScenarioId(), testCases[k].getTestCaseId());
                                    } else {
                                        testController.cancelTestCase(scenarios[j].getScenarioId(), testCases[k].getTestCaseId());
                                    }
                                    if (testCases[k].getStatus().getResult()) {
                                        if (verbose) {
                                            ServiceManagerFactory.getLogger().write("TR___00010", new Object[] { testCases[k].getTestCaseId(), testCases[k].getStatus() });
                                        }
                                    } else {
                                        int ErrorContinue = testCases[k].getTestCaseResource().getErrorContinue();
                                        if (!(ErrorContinue == TestResourceBase.CONTINUE_TYPE_TRUE || (ErrorContinue == TestResourceBase.CONTINUE_TYPE_DEFAULT && defaultTestCaseErrorContinue == TestResourceBase.CONTINUE_TYPE_TRUE))) {
                                            break;
                                        }
                                        if (verbose) {
                                            ServiceManagerFactory.getLogger().write("TR___00011", new Object[] { testCases[k].getTestCaseId(), testCases[k].getStatus() });
                                        }
                                    }
                                } catch (Exception e) {
                                    if (verbose) {
                                        ServiceManagerFactory.getLogger().write("TR___00012", new Object[] { testCases[k].getTestCaseId(), testCases[k].getStatus() }, e);
                                    }
                                    continue;
                                }
                            }
                            testController.endScenario(scenarios[j].getScenarioId());
                            if (verbose) {
                                if (scenarios[j].getStatus().getResult()) {
                                    ServiceManagerFactory.getLogger().write("TR___00013", new Object[] { scenarios[j].getScenarioId(), scenarios[j].getStatus() });
                                } else {
                                    ServiceManagerFactory.getLogger().write("TR___00014", new Object[] { scenarios[j].getScenarioId(), scenarios[j].getStatus() });
                                }
                            }
                        } else {
                            testController.downloadTestScenarioResource(groups[i].getScenarioGroupId(), scenarios[j].getScenarioId());
                        }
                    } catch (Exception e) {
                        if (verbose) {
                            ServiceManagerFactory.getLogger().write("TR___00015", new Object[] { scenarios[j].getScenarioId(), scenarios[j].getStatus() }, e);
                        }
                        continue;
                    }
                }
                if (isTest) {
                    testController.endScenarioGroup();
                }
                if (verbose) {
                    ServiceManagerFactory.getLogger().write("TR___00016", groups[i].getScenarioGroupId());
                }
            } catch (Exception e) {
                if (verbose) {
                    ServiceManagerFactory.getLogger().write("TR___00017", groups[i].getScenarioGroupId(), e);
                }
                continue;
            }
        }
        // レポート
        if (testReporterList != null) {
            for (int i = 0; i < testReporterList.size(); i++) {
                ((TestReporter) testReporterList.get(i)).report(testController);
            }
        }
    } finally {
        for (int i = servicePaths.size(); --i >= 0; ) {
            ServiceManagerFactory.unloadManager((String) servicePaths.get(i));
        }
    }
}
Also used : ServiceNameEditor(jp.ossc.nimbus.beans.ServiceNameEditor) NimbusEntityResolver(jp.ossc.nimbus.core.NimbusEntityResolver) ServiceName(jp.ossc.nimbus.core.ServiceName)

Example 4 with NimbusEntityResolver

use of jp.ossc.nimbus.core.NimbusEntityResolver in project nimbus by nimbus-org.

the class DataSetCodeGenerator method generate.

public File[] generate(String definitionPath, InputStream definitionIn, File outDir) {
    Set files = new LinkedHashSet();
    try {
        final InputSource inputSource = new InputSource(definitionIn);
        final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
        domFactory.setValidating(isValidate);
        final DocumentBuilder builder = domFactory.newDocumentBuilder();
        final NimbusEntityResolver resolver = new NimbusEntityResolver();
        builder.setEntityResolver(resolver);
        final MyErrorHandler handler = new MyErrorHandler(definitionPath);
        builder.setErrorHandler(handler);
        final Document doc = builder.parse(inputSource);
        if (handler.isError()) {
            ServiceManagerFactory.getLogger().write("DSCG_00004", definitionPath);
            return new File[0];
        }
        dataSetsData = new DataSetsMetaData();
        dataSetsData.importXML(doc.getDocumentElement());
        dataSetsData.generate(outDir, files);
        return (File[]) files.toArray(new File[files.size()]);
    } catch (Exception e) {
        ServiceManagerFactory.getLogger().write("DSCG_00004", definitionPath, e);
        return (File[]) files.toArray(new File[files.size()]);
    }
}
Also used : NimbusEntityResolver(jp.ossc.nimbus.core.NimbusEntityResolver) DeploymentException(jp.ossc.nimbus.core.DeploymentException)

Example 5 with NimbusEntityResolver

use of jp.ossc.nimbus.core.NimbusEntityResolver in project nimbus by nimbus-org.

the class DataSetCodeGenerator method loadDefinition.

public void loadDefinition(String definitionPath, InputStream definitionIn) throws DeploymentException {
    try {
        final InputSource inputSource = new InputSource(definitionIn);
        final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
        domFactory.setValidating(isValidate);
        final DocumentBuilder builder = domFactory.newDocumentBuilder();
        final NimbusEntityResolver resolver = new NimbusEntityResolver();
        builder.setEntityResolver(resolver);
        final MyErrorHandler handler = new MyErrorHandler(definitionPath);
        builder.setErrorHandler(handler);
        final Document doc = builder.parse(inputSource);
        if (handler.isError()) {
            throw new DeploymentException(ServiceManagerFactory.getMessageRecordFactory().findEmbedMessage("DSCG_00004", new Object[] { definitionPath }));
        }
        dataSetsData = new DataSetsMetaData();
        dataSetsData.importXML(doc.getDocumentElement());
    } catch (DeploymentException e) {
        throw e;
    } catch (Exception e) {
        throw new DeploymentException(ServiceManagerFactory.getMessageRecordFactory().findEmbedMessage("DSCG_00004", new Object[] { definitionPath }), e);
    }
}
Also used : NimbusEntityResolver(jp.ossc.nimbus.core.NimbusEntityResolver) DeploymentException(jp.ossc.nimbus.core.DeploymentException) DeploymentException(jp.ossc.nimbus.core.DeploymentException)

Aggregations

NimbusEntityResolver (jp.ossc.nimbus.core.NimbusEntityResolver)5 DeploymentException (jp.ossc.nimbus.core.DeploymentException)3 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 InputSource (org.xml.sax.InputSource)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ServiceNameEditor (jp.ossc.nimbus.beans.ServiceNameEditor)1 NimbusClassLoader (jp.ossc.nimbus.core.NimbusClassLoader)1 ServiceMetaData (jp.ossc.nimbus.core.ServiceMetaData)1 ServiceName (jp.ossc.nimbus.core.ServiceName)1 Document (org.w3c.dom.Document)1