1 package com.atlassian.plugins.codegen.modules.common.servlet;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.util.regex.Matcher;
6
7 import com.atlassian.plugins.codegen.AbstractCodegenTestCase;
8 import com.atlassian.plugins.codegen.modules.PluginModuleLocation;
9
10 import org.apache.commons.io.FileUtils;
11 import org.junit.Before;
12 import org.junit.Test;
13
14 import static org.junit.Assert.assertTrue;
15
16
17
18
19
20 public class ServletContextListenerTest extends AbstractCodegenTestCase<ServletContextListenerProperties>
21 {
22 public static final String PACKAGE_NAME = "com.atlassian.plugins.servlet.listener";
23
24 @Before
25 public void runGenerator() throws Exception
26 {
27 setCreator(new ServletContextListenerModuleCreator());
28 setModuleLocation(new PluginModuleLocation.Builder(srcDir)
29 .resourcesDirectory(resourcesDir)
30 .testDirectory(testDir)
31 .templateDirectory(templateDir)
32 .build());
33
34 setProps(new ServletContextListenerProperties(PACKAGE_NAME + ".MyServletContextListener"));
35
36 props.setIncludeExamples(false);
37
38 creator.createModule(moduleLocation, props);
39 }
40
41 @Test
42 public void allFilesAreGenerated() throws Exception
43 {
44 String packagePath = PACKAGE_NAME.replaceAll("\\.", Matcher.quoteReplacement(File.separator));
45 assertTrue("main class not generated", new File(srcDir, packagePath + File.separator + "MyServletContextListener.java").exists());
46 assertTrue("test class not generated", new File(testDir, packagePath + File.separator + "MyServletContextListenerTest.java").exists());
47 assertTrue("main class not generated", new File(resourcesDir, "atlassian-plugin.xml").exists());
48
49 }
50
51 @Test
52 public void pluginXmlContainsModule() throws IOException
53 {
54 String pluginXmlContent = FileUtils.readFileToString(pluginXml);
55
56 assertTrue("module not found in plugin xml", pluginXmlContent.contains("<servlet-context-listener"));
57 assertTrue("module class not found in plugin xml", pluginXmlContent.contains("class=\"" + PACKAGE_NAME + ".MyServletContextListener\""));
58 }
59
60 }