1   package com.atlassian.plugins.codegen.modules.common.component;
2   
3   import com.atlassian.plugins.codegen.AbstractCodegenTestCase;
4   import com.atlassian.plugins.codegen.ClassId;
5   
6   import com.google.common.collect.ImmutableMap;
7   
8   import org.junit.Before;
9   import org.junit.Test;
10  
11  import static com.atlassian.fugue.Option.some;
12  import static org.junit.Assert.assertEquals;
13  
14  /**
15   * @since 3.6
16   */
17  public class ComponentTest extends AbstractCodegenTestCase<ComponentProperties>
18  {
19      @Before
20      public void setup() throws Exception
21      {
22          setCreator(new ComponentModuleCreator());
23          
24          setProps(new ComponentProperties(PACKAGE_NAME + ".CustomComponent"));
25  
26          props.setFullyQualifiedInterface(PACKAGE_NAME + ".CustomInterface");
27          props.setGenerateClass(true);
28          props.setGenerateInterface(true);
29          props.setIncludeExamples(false);
30      }
31  
32      @Test
33      public void classFileIsGenerated() throws Exception
34      {
35          getSourceFile(PACKAGE_NAME, "CustomComponent");
36      }
37  
38      @Test
39      public void interfaceFileIsGenerated() throws Exception
40      {
41          getSourceFile(PACKAGE_NAME, "CustomInterface");
42      }
43  
44      @Test
45      public void unitTestFileIsGenerated() throws Exception
46      {
47          getTestSourceFile(PACKAGE_NAME, "CustomComponentTest");
48      }
49  
50      @Test
51      public void functionalTestFileIsGenerated() throws Exception
52      {
53          getTestSourceFile(FUNC_TEST_PACKAGE_NAME, "CustomComponentFuncTest");
54      }
55  
56      @Test
57      public void componentDeclarationIsGenerated() throws Exception
58      {
59          assertEquals("expected a component declaration", 1, getChangesetForModule().getComponentDeclarations().size());
60      }
61      
62      @Test
63      public void componentDeclarationHasDefaultKey() throws Exception
64      {
65          assertEquals("custom-component", getChangesetForModule().getComponentDeclarations().get(0).getKey());
66      }
67      
68      @Test
69      public void componentDeclarationHasSpecifiedKey() throws Exception
70      {
71          props.setModuleKey("newkey");
72          assertEquals("newkey", getChangesetForModule().getComponentDeclarations().get(0).getKey());
73      }
74      
75      @Test
76      public void componentDeclarationHasName() throws Exception
77      {
78          assertEquals(some("Custom Component"), getChangesetForModule().getComponentDeclarations().get(0).getName());
79      }
80  
81      @Test
82      public void componentDeclarationHasNameI18nKey() throws Exception
83      {
84          props.setNameI18nKey("name-key");
85          assertEquals(some("name-key"), getChangesetForModule().getComponentDeclarations().get(0).getNameI18nKey());
86      }
87  
88      @Test
89      public void componentDeclarationHasClass() throws Exception
90      {
91          assertEquals(ClassId.packageAndClass(PACKAGE_NAME, "CustomComponent"), getChangesetForModule().getComponentDeclarations().get(0).getClassId());
92      }
93  
94      @Test
95      public void componentDeclarationHasInterface() throws Exception
96      {
97          assertEquals(some(ClassId.packageAndClass(PACKAGE_NAME, "CustomInterface")), getChangesetForModule().getComponentDeclarations().get(0).getInterfaceId());
98      }
99  
100     @Test
101     public void componentDeclarationHasDescription() throws Exception
102     {
103         props.setDescription("desc");
104         assertEquals(some("desc"), getChangesetForModule().getComponentDeclarations().get(0).getDescription());
105     }
106 
107     @Test
108     public void componentDeclarationHasDescriptionI18nKey() throws Exception
109     {
110         props.setDescriptionI18nKey("desc-key");
111         assertEquals(some("desc-key"), getChangesetForModule().getComponentDeclarations().get(0).getDescriptionI18nKey());
112     }
113     
114     @Test
115     public void componentDeclarationHasServiceProperties() throws Exception
116     {
117         props.setServiceProps(ImmutableMap.of("prop1", "value1"));
118         assertEquals("value1", getChangesetForModule().getComponentDeclarations().get(0).getServiceProperties().get("prop1"));
119     }
120 }