1   package com.atlassian.maven.plugins.amps.codegen.prompter.common.web;
2   
3   import com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter;
4   import com.atlassian.maven.plugins.amps.codegen.prompter.AbstractPrompterTest;
5   import com.atlassian.maven.plugins.amps.codegen.prompter.PluginModulePrompter;
6   import com.atlassian.plugins.codegen.modules.common.web.WebPanelRendererProperties;
7   
8   import org.codehaus.plexus.components.interactivity.Prompter;
9   import org.codehaus.plexus.components.interactivity.PrompterException;
10  import org.junit.Before;
11  import org.junit.Test;
12  
13  import static com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter.MODULE_DESCRIP_PROMPT;
14  import static com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter.MODULE_KEY_PROMPT;
15  import static com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter.MODULE_NAME_PROMPT;
16  import static org.junit.Assert.assertEquals;
17  import static org.mockito.Mockito.mock;
18  import static org.mockito.Mockito.when;
19  
20  /**
21   * @since 3.6
22   */
23  public class WebPanelRendererPrompterTest extends AbstractPrompterTest
24  {
25      public static final String PACKAGE = "com.atlassian.plugins.web";
26      public static final String CLASSNAME = "AwesomeWebPanelRenderer";
27      public static final String MODULE_NAME = "Awesome Web Panel Renderer";
28      public static final String MODULE_KEY = "awesome-web-panel-renderer";
29      public static final String DESCRIPTION = "The Awesome Web Panel Renderer Plugin";
30      public static final String I18N_NAME_KEY = "awesome-web-panel-renderer.name";
31      public static final String I18N_DESCRIPTION_KEY = "awesome-web-panel-renderer.description";
32  
33      public static final String ADV_MODULE_NAME = "My Awesome Plugin";
34      public static final String ADV_MODULE_KEY = "awesome-module";
35      public static final String ADV_DESCRIPTION = "Renders Panels Just Like Bacon!";
36      public static final String ADV_I18N_NAME_KEY = "awesome-plugin.name";
37      public static final String ADV_I18N_DESCRIPTION_KEY = "pluginus-awesomeous.description";
38  
39      Prompter prompter;
40  
41      @Before
42      public void setup()
43      {
44          prompter = mock(Prompter.class);
45      }
46  
47      @Test
48      public void basicPropertiesAreValid() throws PrompterException
49      {
50          when(prompter.prompt("Enter New Classname", "MyWebPanelRenderer")).thenReturn(CLASSNAME);
51          when(prompter.prompt("Enter Package Name", AbstractModulePrompter.DEFAULT_BASE_PACKAGE + ".web")).thenReturn(PACKAGE);
52          when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
53          when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
54  
55          WebPanelRendererPrompter modulePrompter = new WebPanelRendererPrompter(prompter);
56          modulePrompter.setUseAnsiColor(false);
57          WebPanelRendererProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
58  
59          assertEquals("wrong class", CLASSNAME, props.getClassId().getName());
60          assertEquals("wrong class package", PACKAGE, props.getClassId().getPackage());
61          assertEquals("wrong module name", MODULE_NAME, props.getModuleName());
62          assertEquals("wrong module key", MODULE_KEY, props.getModuleKey());
63          assertEquals("wrong description", DESCRIPTION, props.getDescription());
64          assertEquals("wrong i18n name key", I18N_NAME_KEY, props.getNameI18nKey());
65          assertEquals("wrong i18n desc key", I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
66      }
67  
68      @Test
69      public void advancedPropertiesAreValid() throws PrompterException
70      {
71          when(prompter.prompt("Enter New Classname", "MyWebPanelRenderer")).thenReturn(CLASSNAME);
72          when(prompter.prompt("Enter Package Name", AbstractModulePrompter.DEFAULT_BASE_PACKAGE + ".web")).thenReturn(PACKAGE);
73          when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y");
74  
75          when(prompter.prompt(MODULE_NAME_PROMPT, MODULE_NAME)).thenReturn(ADV_MODULE_NAME);
76          when(prompter.prompt(MODULE_KEY_PROMPT, MODULE_KEY)).thenReturn(ADV_MODULE_KEY);
77          when(prompter.prompt(MODULE_DESCRIP_PROMPT, DESCRIPTION)).thenReturn(ADV_DESCRIPTION);
78          when(prompter.prompt("i18n Name Key", I18N_NAME_KEY)).thenReturn(ADV_I18N_NAME_KEY);
79          when(prompter.prompt("i18n Description Key", I18N_DESCRIPTION_KEY)).thenReturn(ADV_I18N_DESCRIPTION_KEY);
80  
81          when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
82  
83          WebPanelRendererPrompter modulePrompter = new WebPanelRendererPrompter(prompter);
84          modulePrompter.setUseAnsiColor(false);
85          WebPanelRendererProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
86  
87          assertEquals("wrong adv class", CLASSNAME, props.getClassId().getName());
88          assertEquals("wrong adv package", PACKAGE, props.getClassId().getPackage());
89          assertEquals("wrong adv module name", ADV_MODULE_NAME, props.getModuleName());
90          assertEquals("wrong adv module key", ADV_MODULE_KEY, props.getModuleKey());
91          assertEquals("wrong adv description", ADV_DESCRIPTION, props.getDescription());
92          assertEquals("wrong adv i18n name key", ADV_I18N_NAME_KEY, props.getNameI18nKey());
93          assertEquals("wrong adv i18n desc key", ADV_I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
94      }
95  }