1 package com.aurea.maven.plugins.sonic;
2
3 import java.io.File;
4
5 import org.apache.maven.plugin.Mojo;
6 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
7 import org.apache.maven.plugin.testing.ArtifactStubFactory;
8 import org.codehaus.plexus.util.FileUtils;
9
10 import com.aurea.maven.plugins.sonic.esb.MavenProjectMock;
11
12
13
14
15 public abstract class AbstractESBPluginTest extends AbstractMojoTestCase {
16
17
18
19
20
21 protected File testDir = null;
22
23
24
25 protected Mojo mojoUnderTest = null;
26
27
28
29 protected ArtifactStubFactory stubFactory = null;
30
31
32
33
34 public AbstractESBPluginTest() {
35
36 super();
37 }
38
39
40
41
42 protected abstract String getTestName();
43
44
45
46
47 protected abstract String getMojoGoal();
48
49
50
51
52 protected String getSourceDirectory() {
53
54 return "src/main/java";
55 }
56
57
58
59
60
61 @Override
62 protected void setUp() throws Exception {
63
64
65
66
67
68
69 testDir = new File(getBasedir(), "target" + File.separatorChar + "unit-tests" + File.separatorChar + getTestName()
70 + File.separatorChar);
71
72 FileUtils.deleteDirectory(testDir.getAbsolutePath());
73 assertFalse(testDir.exists());
74
75 testDir.mkdirs();
76 assertTrue("'" + testDir + "' does not exist", testDir.exists());
77
78 stubFactory = new ArtifactStubFactory(testDir, true);
79
80 String testResourcesDir = getTestResourcesDir();
81 File testResources = new File(testResourcesDir);
82 assertTrue("Directory : " + testResourcesDir + " : does not exist.", testResources.exists());
83 assertTrue("Directory : " + testResourcesDir + " is not a directory", testResources.isDirectory());
84
85 File projectDirectory = new File(testResources, "projectArchive");
86 assertTrue(projectDirectory.exists());
87 assertTrue(projectDirectory.isDirectory());
88
89
90
91
92
93 File pluginCfg = getPluginConfigFile();
94 assertTrue(pluginCfg.exists());
95 assertTrue(pluginCfg.isFile());
96
97
98
99
100
101
102
103 FileUtils.copyDirectoryStructure(projectDirectory, testDir);
104
105
106
107 MavenProjectMock.setBaseDir(testDir.getAbsolutePath());
108 MavenProjectMock.setSourceDirectory(testDir.getAbsolutePath() + "/" + getSourceDirectory());
109 }
110
111 protected String getTestResourcesDir() {
112
113 return "src/test/resources/" + getTestName();
114 }
115
116 protected File getPluginConfigFile() {
117
118 return new File(getTestResourcesDir(), "plugin-config.xml");
119 }
120
121
122
123
124
125 public void testMojo() throws Exception {
126
127
128 }
129
130
131
132
133
134 protected void tearDown() throws Exception {
135
136
137
138
139
140
141
142
143
144
145
146
147 super.tearDown();
148 }
149 }