use of org.jbpm.bpmn2.xml.BPMNSemanticModule 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());
}
}
use of org.jbpm.bpmn2.xml.BPMNSemanticModule 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");
}
use of org.jbpm.bpmn2.xml.BPMNSemanticModule 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());
}
use of org.jbpm.bpmn2.xml.BPMNSemanticModule 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());
}
}
use of org.jbpm.bpmn2.xml.BPMNSemanticModule 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;
}
Aggregations