PageRenderTime 34ms CodeModel.GetById 6ms app.highlight 23ms RepoModel.GetById 2ms app.codeStats 0ms

/plugin-module-codegen-maven-client/src/test/java/com/atlassian/maven/plugins/amps/codegen/prompter/common/DownloadablePluginResourcePrompterTest.java

https://bitbucket.org/mmeinhold/amps
Java | 84 lines | 68 code | 13 blank | 3 comment | 0 complexity | 5c90421647fc786ab799ec9f6f86ed79 MD5 | raw file
 1package com.atlassian.maven.plugins.amps.codegen.prompter.common;
 2
 3import com.atlassian.maven.plugins.amps.codegen.prompter.AbstractPrompterTest;
 4import com.atlassian.maven.plugins.amps.codegen.prompter.PluginModulePrompter;
 5import com.atlassian.plugins.codegen.modules.common.DownloadablePluginResourceProperties;
 6import com.atlassian.plugins.codegen.modules.common.Resource;
 7
 8import org.apache.commons.lang.StringUtils;
 9import org.codehaus.plexus.components.interactivity.PrompterException;
10import org.junit.Test;
11
12import static org.junit.Assert.assertEquals;
13import static org.junit.Assert.assertTrue;
14import static org.mockito.Mockito.when;
15
16/**
17 * @since 3.6
18 */
19public class DownloadablePluginResourcePrompterTest extends AbstractPrompterTest
20{
21    public static final String RESOURCE_NAME = "resourceCSS";
22    public static final String RESOURCE_NAME_PATTERN = "templates/*.vm";
23    public static final String DOWNLOAD_TYPE = "download";
24    public static final String VELOCITY_TYPE = "velocity";
25    public static final String RESOURCE_CSS_PATH = "templates/resource.css";
26    public static final String RESOURCE_VM_PATH = "templates/resource.vm";
27    public static final String PARAM_KEY = "paramKey";
28    public static final String PARAM_VAL = "paramVal";
29
30
31    @Test
32    public void resourceWithNameIsValid() throws PrompterException
33    {
34        when(prompter.prompt("Enter Resource Name (leave blank to use namePattern)")).thenReturn(RESOURCE_NAME);
35        when(prompter.prompt("Enter Resource Type", "download")).thenReturn(DOWNLOAD_TYPE);
36        when(prompter.prompt("Enter Location (path to resource file)")).thenReturn(RESOURCE_CSS_PATH);
37        when(prompter.prompt("Add Resource Parameter?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y");
38        when(prompter.prompt("params:\nparamKey->paramVal\nAdd Resource Parameter?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
39        when(prompter.prompt("param name")).thenReturn(PARAM_KEY);
40        when(prompter.prompt("param value")).thenReturn(PARAM_VAL);
41        when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
42
43        DownloadablePluginResourcePrompter modulePrompter = new DownloadablePluginResourcePrompter(prompter);
44        modulePrompter.setUseAnsiColor(false);
45        DownloadablePluginResourceProperties props = (DownloadablePluginResourceProperties) modulePrompter.getModulePropertiesFromInput(moduleLocation);
46
47        Resource cssResource = props.getResource();
48
49        assertEquals("wrong css resource name", RESOURCE_NAME, cssResource.getName());
50        assertTrue("css name pattern found when name is set", StringUtils.isBlank(cssResource.getNamePattern()));
51        assertEquals("wrong css resource type", DOWNLOAD_TYPE, cssResource.getType());
52        assertEquals("wrong css resource location", RESOURCE_CSS_PATH, cssResource.getLocation());
53        assertEquals("wrong number of css resource params", 1, cssResource.getParams()
54                .size());
55        assertTrue("css resource param key not found", cssResource.getParams()
56                .containsKey(PARAM_KEY));
57        assertEquals("wrong css resource param value", PARAM_VAL, cssResource.getParams()
58                .get(PARAM_KEY));
59    }
60
61    @Test
62    public void resourceWithNamePatternIsValid() throws PrompterException
63    {
64        when(prompter.prompt("Enter Resource Name (leave blank to use namePattern)")).thenReturn("");
65        when(prompter.prompt("Enter Resource Name Pattern")).thenReturn(RESOURCE_NAME_PATTERN);
66        when(prompter.prompt("Enter Resource Type", "download")).thenReturn(VELOCITY_TYPE);
67        when(prompter.prompt("Enter Location (path to resource file)")).thenReturn(RESOURCE_VM_PATH);
68        when(prompter.prompt("Add Resource Parameter?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
69        when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
70
71        DownloadablePluginResourcePrompter modulePrompter = new DownloadablePluginResourcePrompter(prompter);
72        modulePrompter.setUseAnsiColor(false);
73        DownloadablePluginResourceProperties props = (DownloadablePluginResourceProperties) modulePrompter.getModulePropertiesFromInput(moduleLocation);
74
75        Resource vmResource = props.getResource();
76
77        assertTrue("vm name found when name pattern is set", StringUtils.isBlank(vmResource.getName()));
78        assertEquals("wrong vm resource name pattern", RESOURCE_NAME_PATTERN, vmResource.getNamePattern());
79        assertEquals("wrong vm resource type", VELOCITY_TYPE, vmResource.getType());
80        assertEquals("wrong vm resource location", RESOURCE_VM_PATH, vmResource.getLocation());
81        assertEquals("wrong number of vm resource params", 0, vmResource.getParams()
82                .size());
83    }
84}