1   package com.atlassian.plugins.codegen.modules.common.licensing;
2   
3   import com.atlassian.plugins.codegen.AbstractCodegenTestCase;
4   import com.atlassian.plugins.codegen.MavenPlugin;
5   
6   import org.junit.Before;
7   import org.junit.Test;
8   
9   import static org.junit.Assert.assertEquals;
10  import static org.junit.Assert.assertFalse;
11  import static org.junit.Assert.assertNotNull;
12  import static org.junit.Assert.assertTrue;
13  
14  /**
15   * @since 3.8
16   */
17  public class LicensingUpm1CompatibleTest extends AbstractCodegenTestCase<LicensingProperties>
18  {
19      @Before
20      public void setupProps()
21      {
22          setCreator(new LicensingUpm1CompatibleModuleCreator());
23          setProps(new LicensingProperties());
24      }
25  
26      @Test
27      public void licensingPluginParamIsAdded() throws Exception
28      {
29          assertEquals("true", getChangesetForModule().getPluginParameters().get("atlassian-licensing-enabled"));
30      }
31      
32      @Test
33      public void pluginInstallerComponentIsAdded() throws Exception
34      {
35          getComponentOfClass(LicensingUpm1CompatibleModuleCreator.PLUGIN_INSTALLER_CLASS);
36      }
37      
38      @Test
39      public void licenseStorageManagerComponentIsAdded() throws Exception
40      {
41          getComponentOfClass(LicensingUpm1CompatibleModuleCreator.LICENSE_STORAGE_MANAGER_CLASS);
42      }
43      
44      @Test
45      public void bundleInstructionsAreAdded() throws Exception
46      {
47          // won't verify all the individual bundle instructions, just make sure we have some
48          assertFalse(getChangesetForModule().getBundleInstructions().isEmpty());
49      }
50  
51      @Test
52      public void bundledArtifactsAreAdded() throws Exception
53      {
54          // won't verify all the individual bundled artifacts, just make sure we have some
55          assertFalse(getChangesetForModule().getBundledArtifacts().isEmpty());
56      }
57      
58      @Test
59      public void mavenDependencyPluginIsAdded() throws Exception
60      {
61          MavenPlugin mp = getChangesetForModule().getMavenPlugins().get(0);
62          assertEquals("maven-dependency-plugin", mp.getGroupAndArtifactId().getCombinedId());
63      }
64      
65      @Test
66      public void pluginLicenseStorageLibDependencyIsAdded() throws Exception
67      {
68          getDependency("com.atlassian.upm", "plugin-license-storage-lib");
69      }
70      
71      @Test
72      public void servletModulesAreNotGeneratedByDefault() throws Exception
73      {
74          assertFalse(hasGeneratedModulesOfType("servlet"));
75      }
76      
77      @Test
78      public void classFilesAreNotGeneratedByDefault() throws Exception
79      {
80          assertTrue(getChangesetForModule().getSourceFiles().isEmpty());
81      }
82      
83      @Test
84      public void licenseServletModuleIsAddedIfExamplesAreDesired() throws Exception
85      {
86          props.setIncludeExamples(true);
87          
88          assertNotNull(getAllGeneratedModulesOfType("servlet").selectSingleNode("//servlet[@key='license-servlet']"));
89      }
90  
91      @Test
92      public void licenseServletModuleHasClass() throws Exception
93      {
94          props.setIncludeExamples(true);
95          
96          assertEquals(LicensingUpm1CompatibleModuleCreator.LICENSE_SERVLET_CLASS.getFullName(),
97                       getAllGeneratedModulesOfType("servlet").selectSingleNode("//servlet[@key='license-servlet']/@class").getText());
98      }
99  
100     @Test
101     public void licenseServletModuleHasUrlPattern() throws Exception
102     {
103         props.setIncludeExamples(true);
104         
105         assertEquals(LicensingUpm1CompatibleModuleCreator.LICENSE_SERVLET_URL_PATTERN,
106                      getAllGeneratedModulesOfType("servlet").selectSingleNode("//servlet[@key='license-servlet']/url-pattern").getText());
107     }
108 
109     @Test
110     public void helloWorldServletModuleIsAddedIfExamplesAreDesired() throws Exception
111     {
112         props.setIncludeExamples(true);
113         
114         assertNotNull(getAllGeneratedModulesOfType("servlet").selectSingleNode("//servlet[@key='hello-world-servlet']"));
115     }
116     
117     @Test
118     public void helloWorldServletModuleHasClass() throws Exception
119     {
120         props.setIncludeExamples(true);
121         
122         assertEquals(LicensingUpm1CompatibleModuleCreator.HELLO_WORLD_SERVLET_CLASS.getFullName(),
123                      getAllGeneratedModulesOfType("servlet").selectSingleNode("//servlet[@key='hello-world-servlet']/@class").getText());
124     }
125 
126     @Test
127     public void helloWorldServletModuleHasUrlPattern() throws Exception
128     {
129         props.setIncludeExamples(true);
130         
131         assertEquals(LicensingUpm1CompatibleModuleCreator.HELLO_WORLD_SERVLET_URL_PATTERN,
132                      getAllGeneratedModulesOfType("servlet").selectSingleNode("//servlet[@key='hello-world-servlet']/url-pattern").getText());
133     }
134 }