Search in sources :

Example 1 with BPMNDISemanticModule

use of org.jbpm.bpmn2.xml.BPMNDISemanticModule in project jbpm by kiegroup.

the class BPMN2XMLTest method testXML.

public void testXML() throws IOException, SAXException {
    SemanticModules modules = new SemanticModules();
    modules.addSemanticModule(new BPMNSemanticModule());
    modules.addSemanticModule(new BPMNDISemanticModule());
    XmlProcessReader processReader = new XmlProcessReader(modules, getClass().getClassLoader());
    for (String processName : processes) {
        String original = slurp(BPMN2XMLTest.class.getResourceAsStream("/" + processName));
        List<Process> processes = processReader.read(BPMN2XMLTest.class.getResourceAsStream("/" + processName));
        assertNotNull(processes);
        assertEquals(1, processes.size());
        RuleFlowProcess p = (RuleFlowProcess) processes.get(0);
        String result = XmlBPMNProcessDumper.INSTANCE.dump(p, XmlBPMNProcessDumper.META_DATA_USING_DI);
        // Compare original with result using XMLUnit
        Diff diff = new Diff(original, result);
        // Ignore the sequence of nodes (or children nodes) when looking at these nodes
        final HashSet<String> sequenceDoesNotMatter = new HashSet<String>();
        sequenceDoesNotMatter.add("startEvent");
        sequenceDoesNotMatter.add("scriptTask");
        sequenceDoesNotMatter.add("endEvent");
        sequenceDoesNotMatter.add("bpmndi:BPMNShape");
        diff.overrideDifferenceListener(new DifferenceListener() {

            public int differenceFound(Difference diff) {
                String nodeName = diff.getTestNodeDetail().getNode().getNodeName();
                if (sequenceDoesNotMatter.contains(nodeName) && diff.getId() == DifferenceConstants.CHILD_NODELIST_SEQUENCE_ID) {
                    return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
                }
                logger.info("! {}", diff.getTestNodeDetail().getNode().getNodeName());
                return RETURN_ACCEPT_DIFFERENCE;
            }

            public void skippedComparison(Node one, Node two) {
                logger.info("{} : {}", one.getLocalName(), two.getLocalName());
            }
        });
        // nodes should only be compared if their attributes are the same
        diff.overrideElementQualifier(new ElementNameAndAttributeQualifier());
        assertTrue("Original and generated output is not the same.", diff.identical());
    }
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) Diff(org.custommonkey.xmlunit.Diff) XmlProcessReader(org.jbpm.compiler.xml.XmlProcessReader) Node(org.w3c.dom.Node) Process(org.kie.api.definition.process.Process) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) Difference(org.custommonkey.xmlunit.Difference) SemanticModules(org.drools.core.xml.SemanticModules) BPMNDISemanticModule(org.jbpm.bpmn2.xml.BPMNDISemanticModule) ElementNameAndAttributeQualifier(org.custommonkey.xmlunit.ElementNameAndAttributeQualifier) BPMNSemanticModule(org.jbpm.bpmn2.xml.BPMNSemanticModule) DifferenceListener(org.custommonkey.xmlunit.DifferenceListener) HashSet(java.util.HashSet)

Example 2 with BPMNDISemanticModule

use of org.jbpm.bpmn2.xml.BPMNDISemanticModule in project jbpm by kiegroup.

the class BPMN2XMLTest method testInvalidXMLInCompositeNode.

public void testInvalidXMLInCompositeNode() throws Exception, SAXException {
    SemanticModules modules = new SemanticModules();
    modules.addSemanticModule(new BPMNSemanticModule());
    modules.addSemanticModule(new BPMNDISemanticModule());
    XmlProcessReader processReader = new XmlProcessReader(modules, getClass().getClassLoader()) {

        @Override
        protected String processParserMessage(LinkedList<Object> parents, org.xml.sax.Attributes attr, String errorMessage) {
            setErrorMessage(super.processParserMessage(parents, attr, errorMessage));
            return errorMessage;
        }
    };
    processReader.read(BPMN2XMLTest.class.getResourceAsStream("/BPMN2-XMLProcessWithErrorInCompositeNode.bpmn2"));
    assertNotNull(getErrorMessage());
    assertThat(getErrorMessage()).contains("Process Info: id:abc.abc, pkg:org.drools.bpmn2, name:abc, version:1.0 \n" + "Node Info: id:_47489F3D-FEBD-4452-B62E-B04EF191C6C3 name: \n" + "Parser message: (null: 24, 185): cvc-complex-type.2.4.a: Invalid content was found");
}
Also used : SemanticModules(org.drools.core.xml.SemanticModules) BPMNDISemanticModule(org.jbpm.bpmn2.xml.BPMNDISemanticModule) XmlProcessReader(org.jbpm.compiler.xml.XmlProcessReader) BPMNSemanticModule(org.jbpm.bpmn2.xml.BPMNSemanticModule) LinkedList(java.util.LinkedList)

Example 3 with BPMNDISemanticModule

use of org.jbpm.bpmn2.xml.BPMNDISemanticModule in project kie-wb-common by kiegroup.

the class BPMNValidatorImpl method init.

@PostConstruct
protected void init() {
    modules = new SemanticModules();
    modules.addSemanticModule(new BPMNSemanticModule());
    modules.addSemanticModule(new BPMNDISemanticModule());
}
Also used : SemanticModules(org.drools.core.xml.SemanticModules) BPMNDISemanticModule(org.jbpm.bpmn2.xml.BPMNDISemanticModule) BPMNSemanticModule(org.jbpm.bpmn2.xml.BPMNSemanticModule) PostConstruct(javax.annotation.PostConstruct)

Example 4 with BPMNDISemanticModule

use of org.jbpm.bpmn2.xml.BPMNDISemanticModule in project jbpm by kiegroup.

the class BPMN2ProcessProviderImpl method configurePackageBuilder.

public void configurePackageBuilder(KnowledgeBuilder knowledgeBuilder) {
    KnowledgeBuilderConfigurationImpl conf = ((KnowledgeBuilderImpl) knowledgeBuilder).getBuilderConfiguration();
    if (conf.getSemanticModules().getSemanticModule(BPMNSemanticModule.BPMN2_URI) == null) {
        conf.addSemanticModule(new BPMNSemanticModule());
        conf.addSemanticModule(new BPMNDISemanticModule());
        conf.addSemanticModule(new BPMNExtensionsSemanticModule());
    }
}
Also used : BPMNExtensionsSemanticModule(org.jbpm.bpmn2.xml.BPMNExtensionsSemanticModule) BPMNDISemanticModule(org.jbpm.bpmn2.xml.BPMNDISemanticModule) KnowledgeBuilderConfigurationImpl(org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) BPMNSemanticModule(org.jbpm.bpmn2.xml.BPMNSemanticModule)

Example 5 with BPMNDISemanticModule

use of org.jbpm.bpmn2.xml.BPMNDISemanticModule in project jbpm by kiegroup.

the class JbpmBpmn2TestCase method buildAndDumpBPMN2Process.

// Important to test this since persistence relies on this
protected List<Resource> buildAndDumpBPMN2Process(String process) throws SAXException, IOException {
    KnowledgeBuilderConfiguration conf = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
    ((KnowledgeBuilderConfigurationImpl) conf).initSemanticModules();
    ((KnowledgeBuilderConfigurationImpl) conf).addSemanticModule(new BPMNSemanticModule());
    ((KnowledgeBuilderConfigurationImpl) conf).addSemanticModule(new BPMNDISemanticModule());
    ((KnowledgeBuilderConfigurationImpl) conf).addSemanticModule(new BPMNExtensionsSemanticModule());
    Resource classpathResource = ResourceFactory.newClassPathResource(process);
    // Dump and reread
    XmlProcessReader processReader = new XmlProcessReader(((KnowledgeBuilderConfigurationImpl) conf).getSemanticModules(), getClass().getClassLoader());
    List<Process> processes = processReader.read(this.getClass().getResourceAsStream("/" + process));
    List<Resource> resources = new ArrayList<Resource>();
    for (Process p : processes) {
        RuleFlowProcess ruleFlowProcess = (RuleFlowProcess) p;
        String dumpedString = XmlBPMNProcessDumper.INSTANCE.dump(ruleFlowProcess);
        Resource resource = ResourceFactory.newReaderResource(new StringReader(dumpedString));
        resource.setSourcePath(classpathResource.getSourcePath());
        resource.setTargetPath(classpathResource.getTargetPath());
        resources.add(resource);
    }
    return resources;
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) KnowledgeBuilderConfigurationImpl(org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl) XmlProcessReader(org.jbpm.compiler.xml.XmlProcessReader) Resource(org.kie.api.io.Resource) ArrayList(java.util.ArrayList) Process(org.kie.api.definition.process.Process) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) BPMNExtensionsSemanticModule(org.jbpm.bpmn2.xml.BPMNExtensionsSemanticModule) BPMNDISemanticModule(org.jbpm.bpmn2.xml.BPMNDISemanticModule) BPMNSemanticModule(org.jbpm.bpmn2.xml.BPMNSemanticModule) StringReader(java.io.StringReader) KnowledgeBuilderConfiguration(org.kie.internal.builder.KnowledgeBuilderConfiguration)

Aggregations

BPMNDISemanticModule (org.jbpm.bpmn2.xml.BPMNDISemanticModule)6 BPMNSemanticModule (org.jbpm.bpmn2.xml.BPMNSemanticModule)6 SemanticModules (org.drools.core.xml.SemanticModules)4 XmlProcessReader (org.jbpm.compiler.xml.XmlProcessReader)4 LinkedList (java.util.LinkedList)2 KnowledgeBuilderConfigurationImpl (org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl)2 BPMNExtensionsSemanticModule (org.jbpm.bpmn2.xml.BPMNExtensionsSemanticModule)2 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)2 Process (org.kie.api.definition.process.Process)2 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 PostConstruct (javax.annotation.PostConstruct)1 Diff (org.custommonkey.xmlunit.Diff)1 Difference (org.custommonkey.xmlunit.Difference)1 DifferenceListener (org.custommonkey.xmlunit.DifferenceListener)1 ElementNameAndAttributeQualifier (org.custommonkey.xmlunit.ElementNameAndAttributeQualifier)1 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)1 Resource (org.kie.api.io.Resource)1 KnowledgeBuilderConfiguration (org.kie.internal.builder.KnowledgeBuilderConfiguration)1