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