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