1   package com.atlassian.maven.plugins.amps.codegen.prompter.common;
2   
3   import com.atlassian.maven.plugins.amps.codegen.prompter.AbstractPrompterTest;
4   import com.atlassian.maven.plugins.amps.codegen.prompter.PluginModulePrompter;
5   import com.atlassian.plugins.codegen.modules.common.GadgetProperties;
6   
7   import org.codehaus.plexus.components.interactivity.Prompter;
8   import org.codehaus.plexus.components.interactivity.PrompterException;
9   import org.junit.Before;
10  import org.junit.Test;
11  
12  import static com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter.MODULE_DESCRIP_PROMPT;
13  import static com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter.MODULE_KEY_PROMPT;
14  import static com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter.MODULE_NAME_PROMPT;
15  import static org.junit.Assert.assertEquals;
16  import static org.mockito.Mockito.mock;
17  import static org.mockito.Mockito.when;
18  
19  /**
20   * @since 3.6
21   */
22  public class GadgetPrompterTest extends AbstractPrompterTest
23  {
24      public static final String MODULE_NAME = "My Gadget";
25      public static final String MODULE_KEY = "my-gadget";
26      public static final String DESCRIPTION = "The My Gadget Plugin";
27      public static final String I18N_NAME_KEY = "my-gadget.name";
28      public static final String I18N_DESCRIPTION_KEY = "my-gadget.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 = "The Awesomest Plugin Ever";
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      public static final String LOCATION = "gadgets/awesome/gadget.xml";
37  
38      Prompter prompter;
39  
40      @Before
41      public void setup()
42      {
43          prompter = mock(Prompter.class);
44      }
45  
46      @Test
47      public void basicPropertiesAreValid() throws PrompterException
48      {
49          when(prompter.prompt("Enter Gadget Name", "My Gadget")).thenReturn(MODULE_NAME);
50          when(prompter.prompt("Enter Gadget XML location", "gadgets/" + MODULE_KEY + "/gadget.xml")).thenReturn(LOCATION);
51          when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
52          when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
53  
54          GadgetPrompter modulePrompter = new GadgetPrompter(prompter);
55          modulePrompter.setUseAnsiColor(false);
56          GadgetProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
57  
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          assertEquals("wrong location", LOCATION, props.getLocation());
64      }
65  
66      @Test
67      public void advancedPropertiesAreValid() throws PrompterException
68      {
69          when(prompter.prompt("Enter Gadget Name", "My Gadget")).thenReturn(MODULE_NAME);
70          when(prompter.prompt("Enter Gadget XML location", "gadgets/" + MODULE_KEY + "/gadget.xml")).thenReturn(LOCATION);
71          when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y");
72  
73          when(prompter.prompt(MODULE_NAME_PROMPT, MODULE_NAME)).thenReturn(ADV_MODULE_NAME);
74          when(prompter.prompt(MODULE_KEY_PROMPT, MODULE_KEY)).thenReturn(ADV_MODULE_KEY);
75          when(prompter.prompt(MODULE_DESCRIP_PROMPT, DESCRIPTION)).thenReturn(ADV_DESCRIPTION);
76          when(prompter.prompt("i18n Name Key", I18N_NAME_KEY)).thenReturn(ADV_I18N_NAME_KEY);
77          when(prompter.prompt("i18n Description Key", I18N_DESCRIPTION_KEY)).thenReturn(ADV_I18N_DESCRIPTION_KEY);
78  
79          when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
80  
81          GadgetPrompter modulePrompter = new GadgetPrompter(prompter);
82          modulePrompter.setUseAnsiColor(false);
83          GadgetProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
84  
85          assertEquals("wrong adv module name", ADV_MODULE_NAME, props.getModuleName());
86          assertEquals("wrong adv module key", ADV_MODULE_KEY, props.getModuleKey());
87          assertEquals("wrong adv description", ADV_DESCRIPTION, props.getDescription());
88          assertEquals("wrong adv i18n name key", ADV_I18N_NAME_KEY, props.getNameI18nKey());
89          assertEquals("wrong adv i18n desc key", ADV_I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
90          assertEquals("wrong location", LOCATION, props.getLocation());
91      }
92  }