private void hasElement(String result, String elementPattern) { hasElement(result, elementPattern, 1); }
@Override public Graph unmarshall(Metadata metadata, InputStream inputStream) { Graph result = super.unmarshall(metadata, inputStream); this.updateTitle(metadata, result); return result; }
@Override @SuppressWarnings("unchecked") public String marshall(Diagram<Graph, Metadata> diagram) throws IOException { preMarshallProcess(diagram); return super.marshall(diagram); }
@Test public void testMarshall() throws Exception { String result = tested.marshall(createCase()); hasElement(result, "<bpmn2:adHocSubProcess id=\"_BCD8C7E1-9833-407D-9833-E12763A9A63D\" name=\"Stage\" ordering=\"Sequential\">"); hasElement(result, "<bpmn2:adHocSubProcess id=\"_F0A19BD0-3F42-493A-9A2D-2F4C24ED75D9\" name=\"Stage\" ordering=\"Sequential\">"); hasElement(result, "<bpmn2:userTask id=\"_E95AD08A-4595-4FA4-8948-3318D8BE7941\" name=\"Task\">"); hasElement(result, "<bpmn2:callActivity id=\"_C468418F-A1EE-470A-BC30-D85888DF3DF7\" drools:independent=\"false\" drools:waitForCompletion=\"true\" name=\"Subcase\" calledElement=\"\">"); hasElement(result, "<bpmn2:callActivity id=\"_4DF08597-2D2D-4CEE-B0EF-1AF0ED4ADAC2\" drools:independent=\"false\" drools:waitForCompletion=\"true\" name=\"Subcase\" calledElement=\"\">"); hasElement(result, "<bpmn2:callActivity id=\"_438D1DB6-4161-43C5-86F5-FC6B0F97BA7B\" drools:independent=\"false\" drools:waitForCompletion=\"true\" name=\"Subprocess\" calledElement=\"\">"); hasElement(result, "<drools:metaData name=\"case\">(\\s*)" + Pattern.quote("<drools:metaValue><![CDATA[true]]></drools:metaValue>") + "(\\s*)</drools:metaData>", 2); hasElement(result, "<bpmn2:startEvent id=\"" + UUID_REGEX + "\">(\\s*)<bpmn2:outgoing>" + UUID_REGEX + "</bpmn2:outgoing>(\\s*)</bpmn2:startEvent>"); hasElement(result, "<bpmn2:endEvent id=\"" + UUID_REGEX + "\">(\\s*)<bpmn2:incoming>" + UUID_REGEX + "</bpmn2:incoming>(\\s*)</bpmn2:endEvent>"); hasElement(result, "<bpmn2:sequenceFlow id=\"(" + UUID_REGEX + ")\" sourceRef=\"(" + UUID_REGEX + ")\" targetRef=\"_F0A19BD0-3F42-493A-9A2D-2F4C24ED75D9\"/>"); hasElement(result, "<bpmn2:sequenceFlow id=\"(" + UUID_REGEX + ")\" sourceRef=\"_F0A19BD0-3F42-493A-9A2D-2F4C24ED75D9\" targetRef=\"_BCD8C7E1-9833-407D-9833-E12763A9A63D\"/>");
@Test public void testMarshall_diagram() throws Exception { String result = tested.marshall(createDiagram()); hasElement(result, "<bpmn2:itemDefinition id=\"_DiagramTestItem\" structureRef=\"Boolean\"/>"); hasElement(result, "<bpmn2:itemDefinition id=\"_caseFile_DiagramTestItem\" structureRef=\"Boolean\"/>"); hasElement(result, "<bpmn2:process id=\"DiagramTest\" drools:packageName=\"DiagramTest\" drools:version=\"2.0\" drools:adHoc=\"true\" " + "name=\"DiagramTest\" isExecutable=\"true\">"); hasElement(result, "<bpmn2:documentation id=\"" + ID_REGEX + "\">" + Pattern.quote("<![CDATA[DiagramTest]]>") + "</bpmn2:documentation>"); hasElement(result, "<drools:metaData name=\"customDescription\">(\\s*)" + Pattern.quote("<drools:metaValue><![CDATA[DiagramTest]]></drools:metaValue>") + "(\\s*)</drools:metaData>"); hasElement(result, "<drools:metaData name=\"customCaseIdPrefix\">(\\s*)" + Pattern.quote("<drools:metaValue><![CDATA[DiagramTest]]></drools:metaValue>") + "(\\s*)</drools:metaData>"); hasElement(result, "<drools:metaData name=\"customCaseRoles\">(\\s*)" + Pattern.quote("<drools:metaValue><![CDATA[DiagramTest:5]]></drools:metaValue>") + "(\\s*)</drools:metaData>"); hasElement(result, "<bpmn2:property id=\"DiagramTest\" itemSubjectRef=\"_DiagramTestItem\" name=\"DiagramTest\"/>"); hasElement(result, "<bpmn2:property id=\"caseFile_DiagramTest\" itemSubjectRef=\"_caseFile_DiagramTestItem\" name=\"caseFile_DiagramTest\"/>"); }
@Test public void testMarshall_stage() throws Exception { String result = tested.marshall(createStage()); hasElement(result, "<bpmn2:itemDefinition id=\"_StageTestItem\" structureRef=\"Boolean\"/>"); hasElement(result, "<bpmn2:process id=\"StageTest\" drools:version=\"1.0\" drools:adHoc=\"false\" name=\"StageTest\" isExecutable=\"true\">"); hasElement(result, "<bpmn2:adHocSubProcess id=\"" + UUID_REGEX + "\" name=\"StageTest\" ordering=\"Sequential\">"); hasElement(result, "<bpmn2:documentation id=\"" + ID_REGEX + "\">" + Pattern.quote("<![CDATA[StageTest]]>") + "</bpmn2:documentation>"); hasElement(result, "<drools:metaData name=\"elementname\">(\\s*)" + Pattern.quote("<drools:metaValue><![CDATA[StageTest]]></drools:metaValue>") + "(\\s*)</drools:metaData>"); hasElement(result, "<drools:onEntry-script scriptFormat=\"http://www.java.com/java\">(\\s*)" + Pattern.quote("<drools:script><![CDATA[StageTest]]></drools:script>") + "(\\s*)</drools:onEntry-script>"); hasElement(result, "<drools:onExit-script scriptFormat=\"http://www.java.com/java\">(\\s*)" + Pattern.quote("<drools:script><![CDATA[StageTest]]></drools:script>") + "(\\s*)</drools:onExit-script>"); hasElement(result, "<bpmn2:completionCondition xsi:type=\"bpmn2:tFormalExpression\" id=\"" + ID_REGEX + "\" language=\"http://www.jboss.org/drools/rule\">" + Pattern.quote("<![CDATA[autocomplete]]>") + "</bpmn2:completionCondition>"); hasElement(result, "<bpmn2:property id=\"StageTest\" itemSubjectRef=\"_StageTestItem\" name=\"StageTest\"/>"); }
@Test public void testMarshall_subprocess() throws Exception { String result = tested.marshall(createSubprocess()); hasElement(result, "<bpmn2:itemDefinition id=\"_" + UUID_REGEX + "_SubprocessTestInputXItem\" structureRef=\"Boolean\"/>"); hasElement(result, "<bpmn2:itemDefinition id=\"_+" + UUID_REGEX + "_SubprocessTestOutputXItem\" structureRef=\"Boolean\"/>"); hasElement(result, "<bpmn2:process id=\"SubprocessTest\" drools:version=\"1.0\" drools:adHoc=\"false\" name=\"SubprocessTest\" isExecutable=\"true\">"); hasElement(result, "<bpmn2:adHocSubProcess id=\"" + UUID_REGEX + "\" name=\"StageSubprocessTest\" ordering=\"Sequential\">"); hasElement(result, "<bpmn2:callActivity id=\"" + UUID_REGEX + "\" drools:independent=\"true\" drools:waitForCompletion=\"true\" name=\"SubprocessTest\" calledElement=\"\">"); hasElement(result, "<bpmn2:documentation id=\"" + ID_REGEX + "\">" + Pattern.quote("<![CDATA[SubprocessTest]]>") + "</bpmn2:documentation>"); hasElement(result, "<drools:metaData name=\"elementname\">(\\s*)" + Pattern.quote("<drools:metaValue><![CDATA[SubprocessTest]]></drools:metaValue>") + "(\\s*)</drools:metaData>"); hasElement(result, "<drools:onEntry-script scriptFormat=\"http://www.java.com/java\">(\\s*)" + Pattern.quote("<drools:script><![CDATA[SubprocessTest]]></drools:script>") + "(\\s*)</drools:onEntry-script>");
@Test public void testUpdateTitle() throws Exception { final String name = "mockName"; final Diagram mockDiagram = mockDiagram(name, null); final Metadata metadata = new MetadataImpl(); marshaller.updateTitle(metadata, mockDiagram.getGraph()); assertEquals(metadata.getTitle(), name); }
@Test public void testMarshall_validateId() throws Exception { final Diagram mockDiagram = mockDiagram("mockName", null); exceptionRule.expect(RuntimeException.class); marshaller.marshall(mockDiagram); }
@Override public Graph<DefinitionSet, Node> unmarshall(Metadata metadata, InputStream inputStream) throws IOException { Graph<DefinitionSet, Node> graph = super.unmarshall(metadata, inputStream); postUnmarshallProcess(graph); return graph; }
@Override public String marshall(Diagram diagram) { if (validateDiagram(diagram)) { return super.marshall(diagram); } else { throw new RuntimeException("Invalid definition for Case Modeler diagram."); } }
@Inject public CaseManagementBackendService(final @CaseManagementEditor CaseManagementDiagramMarshaller cmDiagramMarshaller, final @CaseManagementEditor CaseManagementDirectDiagramMarshaller cmDirectDiagramMarshaller, final CaseManagementDefinitionSetResourceType cmResourceType) { super(chooseMarshaller(cmDiagramMarshaller, cmDirectDiagramMarshaller)); this.cmResourceType = cmResourceType; }
@Before public void setup() { this.marshaller = new CaseManagementDiagramMarshaller(diagramMetadataMarshaller, graphBuilderFactory, definitionManager, indexBuilder, oryxManager, factoryManager, null, // TODO! rulesManager, graphCommandManager, commandFactory); }
@Test public void testCreateBpmn2Marshaller() throws Exception { final Bpmn2Marshaller bpmn2Marshaller = this.marshaller.createBpmn2Marshaller(mock(DefinitionManager.class), mock(OryxManager.class)); assertTrue(bpmn2Marshaller instanceof CaseManagementMarshaller); }
@Test public void testCreateBpmn2UnMarshaller() throws Exception { final Bpmn2UnMarshaller bpmn2UnMarshaller = this.marshaller.createBpmn2UnMarshaller(mock(GraphObjectBuilderFactory.class), mock(DefinitionManager.class), mock(FactoryManager.class), mock(DefinitionsCacheRegistry.class), mock(RuleManager.class), mock(OryxManager.class), mock(GraphCommandManager.class), mock(GraphCommandFactory.class), mock(GraphIndexBuilder.class), Object.class, CaseManagementDiagram.class); assertTrue(bpmn2UnMarshaller instanceof CaseManagementUnMarshaller); } }
@Test public void testGetDefinitionSetClass() throws Exception { assertEquals(tested.getDefinitionSetClass(), CaseManagementDefinitionSet.class); } }
@Test public void getDiagramDefinitionSetClass() { // It is important that CaseManagementDiagramMarshaller declares it relates to the CaseManagementDefinitionSet // otherwise all sorts of things break. This test attempts to drawer the importance of this to future changes // should someone decide to change the apparent innocuous method in CaseManagementDiagramMarshaller. assertEquals(CaseManagementDefinitionSet.class, marshaller.getDiagramDefinitionSetClass()); }
@Test public void testCreatePropertyWriterFactory() throws Exception { assertTrue(tested.createPropertyWriterFactory() instanceof CaseManagementPropertyWriterFactory); }
@Override public <M extends Metadata, D extends Diagram> D newDiagram(String uuid, String defSetId, M metadata) { final Graph graph = (Graph) this.newElement(uuid, defSetId); final DiagramImpl result = new DiagramImpl(uuid, new MetadataImpl.MetadataImplBuilder(defSetId).build()); result.setGraph(graph); return (D) result; }
@Test public void testMarshall_validateName() throws Exception { final Diagram mockDiagram = mockDiagram(null, "mockId"); exceptionRule.expect(RuntimeException.class); marshaller.marshall(mockDiagram); }