1   package com.atlassian.plugins.codegen.modules.common;
2   
3   import com.atlassian.plugins.codegen.AbstractModuleCreatorTestCase;
4   
5   import org.junit.Before;
6   import org.junit.Test;
7   
8   import static org.junit.Assert.assertEquals;
9   
10  /**
11   * @since 3.6
12   */
13  public class RESTTest extends AbstractModuleCreatorTestCase<RESTProperties>
14  {
15      public static final String PACKAGE1 = "com.atlassian.plugins.rest.hello";
16      public static final String PACKAGE2 = "com.atlassian.plugins.rest.message";
17      public static final String DISPATCHER1 = "REQUEST";
18      public static final String DISPATCHER2 = "FORWARD";
19      
20      public RESTTest()
21      {
22          super("rest", new RESTModuleCreator());
23      }
24      
25      @Before
26      public void setupProps() throws Exception
27      {
28          setProps(new RESTProperties(PACKAGE_NAME + ".MyRestResource"));
29          props.setIncludeExamples(false);
30          props.addPackageToScan(PACKAGE1);
31          props.addPackageToScan(PACKAGE2);
32          props.addDispatcher(DISPATCHER1);
33          props.addDispatcher(DISPATCHER2);
34      }
35  
36      @Test
37      public void classFileIsGenerated() throws Exception
38      {
39          getSourceFile(PACKAGE_NAME, "MyRestResource");
40      }
41  
42      @Test
43      public void modelClassFileIsGenerated() throws Exception
44      {
45          getSourceFile(PACKAGE_NAME, "MyRestResourceModel");
46      }
47      
48      @Test
49      public void unitTestFileIsGenerated() throws Exception
50      {
51          getTestSourceFile(PACKAGE_NAME, "MyRestResourceTest");
52      }
53  
54      @Test
55      public void functionalTestTestFileIsGenerated() throws Exception
56      {
57          getTestSourceFile(FUNC_TEST_PACKAGE_NAME, "MyRestResourceFuncTest");
58      }
59      
60      @Test
61      public void moduleHasDefaultPath() throws Exception
62      {
63          assertEquals("/myrestresource", getGeneratedModule().attributeValue("path"));
64      }
65  
66      @Test
67      public void moduleHasSpecifiedPath() throws Exception
68      {
69          props.setPath("/helloworld");
70          
71          assertEquals("/helloworld", getGeneratedModule().attributeValue("path"));
72      }
73  
74      @Test
75      public void moduleHasDefaultVersion() throws Exception
76      {
77          assertEquals("1.0", getGeneratedModule().attributeValue("version"));
78      }
79  
80      @Test
81      public void moduleHasSpecifiedVersion() throws Exception
82      {
83          props.setVersion("1.1");
84          
85          assertEquals("1.1", getGeneratedModule().attributeValue("version"));
86      }
87      
88      @Test
89      public void package1IsAdded() throws Exception
90      {
91          assertEquals(PACKAGE1, getGeneratedModule().selectSingleNode("package[1]").getText());
92      }
93  
94      @Test
95      public void package2IsAdded() throws Exception
96      {
97          assertEquals(PACKAGE2, getGeneratedModule().selectSingleNode("package[2]").getText());
98      }
99  
100     @Test
101     public void dispatcher1IsAdded() throws Exception
102     {
103         assertEquals(DISPATCHER1, getGeneratedModule().selectSingleNode("dispatcher[1]").getText());
104     }
105 
106     @Test
107     public void dispatcher2IsAdded() throws Exception
108     {
109         assertEquals(DISPATCHER2, getGeneratedModule().selectSingleNode("dispatcher[2]").getText());
110     }
111 }