/******************************************************************************* * Copyright 2017 Graz University of Technology * EAAF-Core Components has been developed in a cooperation between EGIZ, * A-SIT+, A-SIT, and Graz University of Technology. * * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * https://joinup.ec.europa.eu/news/understanding-eupl-v12 * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. *******************************************************************************/ /******************************************************************************* *******************************************************************************/ /******************************************************************************* *******************************************************************************/ package at.gv.egiz.eaaf.core.impl.idp.process.test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.IOException; import java.io.InputStream; import org.junit.Test; import at.gv.egiz.eaaf.core.impl.idp.process.ProcessDefinitionParser; import at.gv.egiz.eaaf.core.impl.idp.process.ProcessDefinitionParserException; import at.gv.egiz.eaaf.core.impl.idp.process.model.EndEvent; import at.gv.egiz.eaaf.core.impl.idp.process.model.ProcessDefinition; import at.gv.egiz.eaaf.core.impl.idp.process.model.ProcessNode; import at.gv.egiz.eaaf.core.impl.idp.process.model.StartEvent; import at.gv.egiz.eaaf.core.impl.idp.process.model.TaskInfo; import at.gv.egiz.eaaf.core.impl.idp.process.model.Transition; public class ProcessDefinitionParserTest { @Test(expected = ProcessDefinitionParserException.class) public void testParseInvalidProcessDefinition_MultipleStartEvents() throws IOException, ProcessDefinitionParserException { try (InputStream in = getClass().getResourceAsStream("InvalidProcessDefinition_MultipleStartEvents.xml")) { new ProcessDefinitionParser().parse(in); } } @Test(expected = ProcessDefinitionParserException.class) public void testParseInvalidProcessDefinition_TransitionLoop() throws IOException, ProcessDefinitionParserException { try (InputStream in = getClass().getResourceAsStream("InvalidProcessDefinition_TransitionLoop.xml")) { new ProcessDefinitionParser().parse(in); } } @Test(expected = ProcessDefinitionParserException.class) public void testParseInvalidProcessDefinition_TransitionStartsFromEndEvent() throws IOException, ProcessDefinitionParserException { try (InputStream in = getClass().getResourceAsStream("InvalidProcessDefinition_TransitionStartsFromEndEvent.xml")) { new ProcessDefinitionParser().parse(in); } } @Test(expected = ProcessDefinitionParserException.class) public void testParseInvalidProcessDefinition_TransitionRefsTransition() throws IOException, ProcessDefinitionParserException { try (InputStream in = getClass().getResourceAsStream("InvalidProcessDefinition_TransitionRefsTransition.xml")) { new ProcessDefinitionParser().parse(in); } } @Test(expected = ProcessDefinitionParserException.class) public void testParseInvalidProcessDefinition_NoStartEvents() throws IOException, ProcessDefinitionParserException { try (InputStream in = getClass().getResourceAsStream("InvalidProcessDefinition_NoStartEvents.xml")) { new ProcessDefinitionParser().parse(in); } } @Test public void testParseSampleProcessDefinition() throws IOException, ProcessDefinitionParserException { try (InputStream in = getClass().getResourceAsStream("/process/test/SampleProcessDefinition1.xml")) { ProcessDefinitionParser parser = new ProcessDefinitionParser(); ProcessDefinition pd = parser.parse(in); assertNotNull(pd); assertEquals("SampleProcess1", pd.getId()); // first assert tasks then transitions // start event StartEvent startEvent = pd.getStartEvent(); assertNotNull(startEvent); assertEquals("start", startEvent.getId()); assertEquals(startEvent, pd.getProcessNode("start")); // task1 ProcessNode processNode = pd.getProcessNode("task1"); assertNotNull(processNode); assertTrue(processNode instanceof TaskInfo); TaskInfo task1 = (TaskInfo) processNode; assertEquals("task1", task1.getId()); assertFalse(task1.isAsync()); // task2 processNode = pd.getProcessNode("task2"); assertNotNull(processNode); assertTrue(processNode instanceof TaskInfo); TaskInfo task2 = (TaskInfo) processNode; assertEquals("task2", task2.getId()); assertTrue(task2.isAsync()); // end event processNode = pd.getProcessNode("end"); assertNotNull(processNode); assertTrue(processNode instanceof EndEvent); EndEvent endEvent = (EndEvent) processNode; assertEquals("end", endEvent.getId()); // assert transitions // start event assertNotNull(startEvent.getIncomingTransitions()); assertTrue(startEvent.getIncomingTransitions().isEmpty()); assertNotNull(startEvent.getOutgoingTransitions()); assertEquals(1, startEvent.getOutgoingTransitions().size()); // transition from start to task1 Transition startToTask1 = startEvent.getOutgoingTransitions().get(0); assertEquals("fromStart", startToTask1.getId()); assertEquals(startEvent, startToTask1.getFrom()); assertEquals(task1, startToTask1.getTo()); assertEquals("true", startToTask1.getConditionExpression()); // task1 assertNotNull(task1.getIncomingTransitions()); assertEquals(1, task1.getIncomingTransitions().size()); assertEquals(startToTask1, task1.getIncomingTransitions().get(0)); assertNotNull(task1.getOutgoingTransitions()); assertEquals(1, task1.getOutgoingTransitions().size()); // transition from task1 to task2 Transition task1ToTask2 = task1.getOutgoingTransitions().get(0); assertNull(task1ToTask2.getId()); assertEquals(task1, task1ToTask2.getFrom()); assertEquals(task2, task1ToTask2.getTo()); assertNull(task1ToTask2.getConditionExpression()); // task2 assertNotNull(task2.getIncomingTransitions()); assertEquals(1, task2.getIncomingTransitions().size()); assertEquals(task1ToTask2, task2.getIncomingTransitions().get(0)); assertNotNull(task2.getOutgoingTransitions()); assertEquals(1, task2.getOutgoingTransitions().size()); // transition from task2 to end Transition task2ToEnd = task2.getOutgoingTransitions().get(0); assertNull(task2ToEnd.getId()); assertEquals(task2, task2ToEnd.getFrom()); assertEquals(endEvent, task2ToEnd.getTo()); assertNull(task2ToEnd.getConditionExpression()); } } }