1   package com.atlassian.maven.plugins.amps.codegen.prompter.common.moduletype;
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.moduletype.ModuleTypeProperties;
7   
8   import org.codehaus.plexus.components.interactivity.PrompterException;
9   import org.junit.Test;
10  
11  import static com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter.MODULE_DESCRIP_PROMPT;
12  import static com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter.MODULE_KEY_PROMPT;
13  import static com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter.MODULE_NAME_PROMPT;
14  import static org.junit.Assert.assertEquals;
15  import static org.mockito.Mockito.when;
16  
17  /**
18   * @since 3.6
19   */
20  public class ModuleTypePrompterTest extends AbstractPrompterTest
21  {
22      public static final String INTERFACE_CLASS = "Dictionary";
23      public static final String PACKAGE = "com.atlassian.plugins.modules";
24      public static final String CLASSNAME = "DictionaryModuleDescriptor";
25      public static final String MODULE_NAME = "Dictionary Module Descriptor";
26      public static final String MODULE_KEY = "dictionary-module-descriptor";
27      public static final String DESCRIPTION = "The Dictionary Module Descriptor Plugin";
28      public static final String I18N_NAME_KEY = "dictionary-module-descriptor.name";
29      public static final String I18N_DESCRIPTION_KEY = "dictionary-module-descriptor.description";
30  
31      public static final String ADV_MODULE_NAME = "My Awesome Plugin";
32      public static final String ADV_MODULE_KEY = "awesome-module";
33      public static final String ADV_DESCRIPTION = "The Awesomest Plugin Ever";
34      public static final String ADV_I18N_NAME_KEY = "awesome-plugin.name";
35      public static final String ADV_I18N_DESCRIPTION_KEY = "pluginus-awesomeous.description";
36  
37      @Test
38      public void basicPropertiesAreValid() throws PrompterException
39      {
40          when(prompter.prompt("Enter Interface name", "MYModule")).thenReturn(INTERFACE_CLASS);
41          when(prompter.prompt("Enter Interface package", AbstractModulePrompter.DEFAULT_BASE_PACKAGE + ".modules")).thenReturn(PACKAGE);
42          when(prompter.prompt("Enter Class name", CLASSNAME)).thenReturn(CLASSNAME);
43          when(prompter.prompt("Enter Package Name", PACKAGE)).thenReturn(PACKAGE);
44          when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
45          when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
46  
47          ModuleTypePrompter modulePrompter = new ModuleTypePrompter(prompter);
48          modulePrompter.setUseAnsiColor(false);
49          ModuleTypeProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
50  
51          assertEquals("wrong interface", INTERFACE_CLASS, props.getInterfaceId().getName());
52          assertEquals("wrong interface package", PACKAGE, props.getInterfaceId().getPackage());
53          assertEquals("wrong class", CLASSNAME, props.getClassId().getName());
54          assertEquals("wrong class package", PACKAGE, props.getClassId().getPackage());
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      }
61  
62      @Test
63      public void advancedPropertiesAreValid() throws PrompterException
64      {
65          when(prompter.prompt("Enter Interface name", "MYModule")).thenReturn(INTERFACE_CLASS);
66          when(prompter.prompt("Enter Interface package", AbstractModulePrompter.DEFAULT_BASE_PACKAGE + ".modules")).thenReturn(PACKAGE);
67          when(prompter.prompt("Enter Class name", CLASSNAME)).thenReturn(CLASSNAME);
68          when(prompter.prompt("Enter Package Name", PACKAGE)).thenReturn(PACKAGE);
69          when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y");
70  
71          when(prompter.prompt(MODULE_NAME_PROMPT, MODULE_NAME)).thenReturn(ADV_MODULE_NAME);
72          when(prompter.prompt(MODULE_KEY_PROMPT, MODULE_KEY)).thenReturn(ADV_MODULE_KEY);
73          when(prompter.prompt(MODULE_DESCRIP_PROMPT, DESCRIPTION)).thenReturn(ADV_DESCRIPTION);
74          when(prompter.prompt("i18n Name Key", I18N_NAME_KEY)).thenReturn(ADV_I18N_NAME_KEY);
75          when(prompter.prompt("i18n Description Key", I18N_DESCRIPTION_KEY)).thenReturn(ADV_I18N_DESCRIPTION_KEY);
76  
77          when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
78  
79          ModuleTypePrompter modulePrompter = new ModuleTypePrompter(prompter);
80          modulePrompter.setUseAnsiColor(false);
81          ModuleTypeProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
82  
83          assertEquals("wrong adv interface", INTERFACE_CLASS, props.getInterfaceId().getName());
84          assertEquals("wrong adv interface package", PACKAGE, props.getInterfaceId().getPackage());
85          assertEquals("wrong adv class", CLASSNAME, props.getClassId().getName());
86          assertEquals("wrong adv package", PACKAGE, props.getClassId().getPackage());
87          assertEquals("wrong adv module name", ADV_MODULE_NAME, props.getModuleName());
88          assertEquals("wrong adv module key", ADV_MODULE_KEY, props.getModuleKey());
89          assertEquals("wrong adv description", ADV_DESCRIPTION, props.getDescription());
90          assertEquals("wrong adv i18n name key", ADV_I18N_NAME_KEY, props.getNameI18nKey());
91          assertEquals("wrong adv i18n desc key", ADV_I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
92      }
93  }