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