1 package com.atlassian.plugins.codegen.modules.common.licensing;
2
3 import com.atlassian.plugins.codegen.AbstractCodegenTestCase;
4 import com.atlassian.plugins.codegen.BundleInstruction;
5 import com.atlassian.plugins.codegen.MavenPlugin;
6 import com.atlassian.plugins.codegen.PluginArtifact;
7 import com.atlassian.plugins.codegen.PluginParameter;
8
9 import org.junit.Before;
10 import org.junit.Test;
11
12 import static com.atlassian.plugins.codegen.AmpsSystemPropertyVariable.ampsSystemPropertyVariable;
13 import static com.atlassian.plugins.codegen.ClassId.packageAndClass;
14 import static com.atlassian.plugins.codegen.I18nString.i18nString;
15 import static com.atlassian.plugins.codegen.PluginParameter.pluginParameter;
16 import static org.junit.Assert.assertEquals;
17 import static org.junit.Assert.assertFalse;
18 import static org.junit.Assert.assertNotNull;
19 import static org.junit.Assert.assertNull;
20
21
22
23
24 public class LicensingUpm1CompatibleTest extends AbstractCodegenTestCase<LicensingProperties>
25 {
26 private static final String LICENSE_SERVLET_PATH = "my/license";
27 private static final String HELLO_SERVLET_PATH = "good/morning/sunshine";
28
29 @Before
30 public void setupProps()
31 {
32 setCreator(new LicensingUpm1CompatibleModuleCreator());
33 setProps(new LicensingProperties(PACKAGE_NAME + ".MyServlet"));
34 props.setLicenseServletPath(LICENSE_SERVLET_PATH);
35 props.setHelloWorldServletPath(HELLO_SERVLET_PATH);
36 }
37
38 @Test
39 public void licensingPluginParamIsAdded() throws Exception
40 {
41 assertEquals(pluginParameter("atlassian-licensing-enabled", "true"), getChangesetForModule(PluginParameter.class).get(0));
42 }
43
44 @Test
45 public void pluginInstallerComponentIsAdded() throws Exception
46 {
47 getComponentOfClass(LicensingUpm1CompatibleModuleCreator.PLUGIN_INSTALLER_CLASS);
48 }
49
50 @Test
51 public void licenseStorageManagerComponentIsAdded() throws Exception
52 {
53 getComponentOfClass(LicensingUpm1CompatibleModuleCreator.LICENSE_STORAGE_MANAGER_CLASS);
54 }
55
56 @Test
57 public void bundleInstructionsAreAdded() throws Exception
58 {
59
60 assertFalse(getChangesetForModule(BundleInstruction.class).isEmpty());
61 }
62
63 @Test
64 public void bundledArtifactsAreAdded() throws Exception
65 {
66
67 assertFalse(getChangesetForModule(PluginArtifact.class).isEmpty());
68 }
69
70 @Test
71 public void mavenDependencyPluginIsAdded() throws Exception
72 {
73 MavenPlugin mp = getChangesetForModule(MavenPlugin.class).get(0);
74 assertEquals("maven-dependency-plugin", mp.getGroupAndArtifactId().getCombinedId());
75 }
76
77 @Test
78 public void pluginLicenseStorageLibDependencyIsAdded() throws Exception
79 {
80 getDependency("com.atlassian.upm", "plugin-license-storage-lib");
81 }
82
83 @Test
84 public void licenseServletModuleIsAdded() throws Exception
85 {
86 assertNotNull(getAllGeneratedModulesOfType("servlet").selectSingleNode("//servlet[@key='my-servlet']"));
87 }
88
89 @Test
90 public void licenseServletModuleHasClass() throws Exception
91 {
92 assertEquals(packageAndClass(PACKAGE_NAME, "MyServlet").getFullName(),
93 getAllGeneratedModulesOfType("servlet").selectSingleNode("//servlet[@key='my-servlet']/@class").getText());
94 }
95
96 @Test
97 public void licenseServletModuleHasUrlPattern() throws Exception
98 {
99 assertEquals("/" + LICENSE_SERVLET_PATH,
100 getAllGeneratedModulesOfType("servlet").selectSingleNode("//servlet[@key='my-servlet']/url-pattern").getText());
101 }
102
103 @Test
104 public void helloWorldServletModuleIsNotAddedByDefault() throws Exception
105 {
106 assertNull(getAllGeneratedModulesOfType("servlet").selectSingleNode("//servlet[@key='license-hello-world-servlet']"));
107 }
108
109 @Test
110 public void helloWorldServletModuleIsAddedIfExamplesAreSelected() throws Exception
111 {
112 props.setIncludeExamples(true);
113 assertNotNull(getAllGeneratedModulesOfType("servlet").selectSingleNode("//servlet[@key='license-hello-world-servlet']"));
114 }
115
116 @Test
117 public void helloWorldServletModuleHasClass() throws Exception
118 {
119 props.setIncludeExamples(true);
120 assertEquals(packageAndClass(PACKAGE_NAME, LicensingUpm1CompatibleModuleCreator.HELLO_WORLD_SERVLET_CLASS_NAME).getFullName(),
121 getAllGeneratedModulesOfType("servlet").selectSingleNode("//servlet[@key='license-hello-world-servlet']/@class").getText());
122 }
123
124 @Test
125 public void helloWorldServletModuleHasUrlPattern() throws Exception
126 {
127 props.setIncludeExamples(true);
128 assertEquals("/" + HELLO_SERVLET_PATH,
129 getAllGeneratedModulesOfType("servlet").selectSingleNode("//servlet[@key='license-hello-world-servlet']/url-pattern").getText());
130 }
131
132 @Test
133 public void i18nStringsAreAdded() throws Exception
134 {
135
136 assertChangesetContains(i18nString("plugin.license.storage.admin.license.details", "License Details"),
137 i18nString("plugin.license.storage.admin.license.type.DEVELOPER", "developer"));
138 }
139 }