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 org.junit.Assert.assertEquals;
13  import static org.mockito.Mockito.mock;
14  import static org.mockito.Mockito.when;
15  
16  /**
17   * @since 3.5
18   */
19  public class GadgetPrompterTest extends AbstractPrompterTest
20  {
21      public static final String MODULE_NAME = "My Gadget";
22      public static final String MODULE_KEY = "my-gadget";
23      public static final String DESCRIPTION = "The My Gadget Plugin";
24      public static final String I18N_NAME_KEY = "my-gadget.name";
25      public static final String I18N_DESCRIPTION_KEY = "my-gadget.description";
26  
27      public static final String ADV_MODULE_NAME = "My Awesome Plugin";
28      public static final String ADV_MODULE_KEY = "awesome-module";
29      public static final String ADV_DESCRIPTION = "The Awesomest Plugin Ever";
30      public static final String ADV_I18N_NAME_KEY = "awesome-plugin.name";
31      public static final String ADV_I18N_DESCRIPTION_KEY = "pluginus-awesomeous.description";
32  
33      public static final String LOCATION = "gadgets/awesome/gadget.xml";
34  
35      Prompter prompter;
36  
37      @Before
38      public void setup()
39      {
40          prompter = mock(Prompter.class);
41      }
42  
43      @Test
44      public void basicPropertiesAreValid() throws PrompterException
45      {
46          when(prompter.prompt("Enter Gadget Name", "My Gadget")).thenReturn(MODULE_NAME);
47          when(prompter.prompt("Enter Gadget XML location", "gadgets/" + MODULE_KEY + "/gadget.xml")).thenReturn(LOCATION);
48          when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
49          when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
50  
51          GadgetPrompter modulePrompter = new GadgetPrompter(prompter);
52          modulePrompter.setUseAnsiColor(false);
53          GadgetProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
54  
55          assertEquals("wrong module name", MODULE_NAME, props.getModuleName());
56          assertEquals("wrong module key", MODULE_KEY, props.getModuleKey());
57          assertEquals("wrong description", DESCRIPTION, props.getDescription());
58          assertEquals("wrong i18n name key", I18N_NAME_KEY, props.getNameI18nKey());
59          assertEquals("wrong i18n desc key", I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
60          assertEquals("wrong location", LOCATION, props.getLocation());
61      }
62  
63      @Test
64      public void advancedPropertiesAreValid() throws PrompterException
65      {
66          when(prompter.prompt("Enter Gadget Name", "My Gadget")).thenReturn(MODULE_NAME);
67          when(prompter.prompt("Enter Gadget XML location", "gadgets/" + MODULE_KEY + "/gadget.xml")).thenReturn(LOCATION);
68          when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y");
69  
70          when(prompter.prompt("Plugin Name", MODULE_NAME)).thenReturn(ADV_MODULE_NAME);
71          when(prompter.prompt("Plugin Key", MODULE_KEY)).thenReturn(ADV_MODULE_KEY);
72          when(prompter.prompt("Plugin Description", DESCRIPTION)).thenReturn(ADV_DESCRIPTION);
73          when(prompter.prompt("i18n Name Key", I18N_NAME_KEY)).thenReturn(ADV_I18N_NAME_KEY);
74          when(prompter.prompt("i18n Description Key", I18N_DESCRIPTION_KEY)).thenReturn(ADV_I18N_DESCRIPTION_KEY);
75  
76          when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
77  
78          GadgetPrompter modulePrompter = new GadgetPrompter(prompter);
79          modulePrompter.setUseAnsiColor(false);
80          GadgetProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
81  
82          assertEquals("wrong adv module name", ADV_MODULE_NAME, props.getModuleName());
83          assertEquals("wrong adv module key", ADV_MODULE_KEY, props.getModuleKey());
84          assertEquals("wrong adv description", ADV_DESCRIPTION, props.getDescription());
85          assertEquals("wrong adv i18n name key", ADV_I18N_NAME_KEY, props.getNameI18nKey());
86          assertEquals("wrong adv i18n desc key", ADV_I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
87          assertEquals("wrong location", LOCATION, props.getLocation());
88      }
89  }