1
2
3
4
5
6
7
8
9
10
11 package org.mod4j.dslcommon.openarchitectureware;
12
13 import static org.junit.Assert.*;
14
15 import java.io.File;
16 import java.io.IOException;
17 import java.util.HashMap;
18 import java.util.Map;
19
20 import org.junit.Before;
21 import org.junit.Test;
22
23
24
25
26
27 public class Mod4WorklowRunnerTest {
28
29 private String wfFile;
30
31 private Map<String, String> properties = new HashMap<String, String>();
32
33 private static final String TESTDIR = "target/mod4j-tests";
34
35 @Before
36 public void createTestDir() {
37 new File(TESTDIR).mkdirs();
38 }
39
40
41
42
43
44
45 @Test
46 public final void testRunWorkflowCleanerSuccessful() {
47
48 Mod4jWorkflowRunner workflowRunner = new Mod4jWorkflowRunner();
49 File testFile = new File(TESTDIR + "/dummyFile.txt");
50 properties.put("directories", TESTDIR);
51 wfFile = "org/mod4j/dslcommon/workflow/DirectoryClean.oaw";
52
53 try {
54 if (testFile.exists() || testFile.createNewFile()) {
55 workflowRunner.runWorkflow(wfFile, properties);
56 }
57 assertFalse("dummyFile expected to be cleaned [" + testFile.getAbsolutePath() + "]", testFile.exists());
58
59 } catch (Mod4jWorkflowException e) {
60 e.printStackTrace();
61 fail("A Mod4jWorkflowException was thrown. Expected to run successful.");
62 } catch (IOException e) {
63 e.printStackTrace();
64 fail("Cannot ceate test file in the system temporal directory");
65 }
66 }
67
68
69
70
71
72
73 @Test
74 public final void testRunWorkflowCleanerFail() {
75
76 Mod4jWorkflowRunner workflowRunner = new Mod4jWorkflowRunner();
77 wfFile = "src/test/resources/TestWorkflowCleaner.oaw";
78
79 try {
80 workflowRunner.runWorkflow(wfFile, properties);
81 fail("A Mod4jWorkflowException was expected to be thrown.");
82 } catch (Mod4jWorkflowException e) {
83
84 assertTrue("Caught a Mod4jWorkflowException", e.getMessage().startsWith(
85 "ERROR(S) detected while running workflow"));
86 }
87 }
88 }