diff --git a/src/main/java/com/bioraft/rundeck/conditional/IfElse.java b/src/main/java/com/bioraft/rundeck/conditional/IfElse.java index 6ee45f2..d1f186e 100644 --- a/src/main/java/com/bioraft/rundeck/conditional/IfElse.java +++ b/src/main/java/com/bioraft/rundeck/conditional/IfElse.java @@ -61,6 +61,12 @@ public IfElse(PluginStepContext ctx) { this.ctx = ctx; } + /** + * Setter to control elevation to global context. + * + * @param elevate Flag indicating if variable should be make global. + * @return self + */ public IfElse setElevate(boolean elevate) { this.elevate = elevate; return this; @@ -110,7 +116,7 @@ public void ifElse(String group, String name, String testValue, String operator, } if (matched.equals("")) { - if (ifFalse == null || ifFalse.length() == 0) { + if (ifFalse.length() == 0) { ctx.getLogger().log(Constants.DEBUG_LEVEL, "No match, default is empty."); return; } diff --git a/src/main/java/com/bioraft/rundeck/conditional/Switch.java b/src/main/java/com/bioraft/rundeck/conditional/Switch.java index ef1b41f..f4c0fa3 100644 --- a/src/main/java/com/bioraft/rundeck/conditional/Switch.java +++ b/src/main/java/com/bioraft/rundeck/conditional/Switch.java @@ -39,13 +39,30 @@ public class Switch { private PluginStepContext ctx; + private Map cfg; + + private String defaultValue; + /** - * Constructor sets PluginStepContext. + * Constructor sets PluginStepContext, configuration map, and default value. * * @param ctx Plugin step context + * @param cfg Configuration map. + * @param defaultValue The default value, if defined. */ - public Switch(PluginStepContext ctx) { + public Switch(PluginStepContext ctx, Map cfg, String defaultValue) { this.ctx = ctx; + this.cfg = cfg; + + boolean cfgHasDefault = cfg.containsKey(CFG_DEFAULT_VALUE); + if (cfgHasDefault) { + if (cfg.get(CFG_DEFAULT_VALUE) == null) { + this.defaultValue = null; + } else { + this.defaultValue = cfg.get(CFG_DEFAULT_VALUE).toString(); + } + } + } /** @@ -56,14 +73,21 @@ public Switch(PluginStepContext ctx) { * @param name The name of the variable. * @param cases The switch cases as test1:value1;test2:value2 * @param test The string to test the cases against. - * @param defaultValue The value to return if no cases match * @param elevate If specified, also create a variable in global export * context. */ - public void switchCase(String group, String name, String cases, String test, String defaultValue, boolean elevate) throws JsonProcessingException { + public void switchCase(String group, String name, String cases, String test, boolean elevate) throws JsonProcessingException { + group = cfg.getOrDefault("group", group).toString(); + name = cfg.getOrDefault("name", name).toString(); + cases = cfg.getOrDefault("cases", cases).toString(); + test = cfg.getOrDefault("testValue", test).toString(); + + String message = "Setting " + group + "." + name + " based on " + test + " " + cases; + ctx.getLogger().log(Constants.DEBUG_LEVEL, message); + // If no case was matched, assign defaultValue if it is not null. try { - if (!switchCase(group, name, cases, test, elevate)) { + if (!switchCase2(group, name, cases, test, elevate)) { if (defaultValue != null && defaultValue.length() > 0) { addOutput(elevate, group, name, defaultValue); ctx.getLogger().log(Constants.DEBUG_LEVEL, "No match, using default."); @@ -89,7 +113,7 @@ public void switchCase(String group, String name, String cases, String test, Str * * @return True if matched, false otherwise. */ - public boolean switchCase(String group, String name, String cases, String test, boolean elevate) throws JsonProcessingException { + public boolean switchCase2(String group, String name, String cases, String test, boolean elevate) throws JsonProcessingException { ObjectMapper objectMapper = new ObjectMapper(); JsonNode map = objectMapper.readTree(ensureStringIsJsonObject(cases)); Iterator> iterator = map.fields(); diff --git a/src/main/java/com/bioraft/rundeck/conditional/SwitchCaseNodeStepPlugin.java b/src/main/java/com/bioraft/rundeck/conditional/SwitchCaseNodeStepPlugin.java index ec2355a..6080b31 100644 --- a/src/main/java/com/bioraft/rundeck/conditional/SwitchCaseNodeStepPlugin.java +++ b/src/main/java/com/bioraft/rundeck/conditional/SwitchCaseNodeStepPlugin.java @@ -17,7 +17,6 @@ import java.util.Map; -import com.dtolabs.rundeck.core.Constants; import com.dtolabs.rundeck.core.common.INodeEntry; import com.dtolabs.rundeck.core.execution.workflow.steps.node.NodeStepException; import com.dtolabs.rundeck.core.plugins.Plugin; @@ -32,7 +31,6 @@ import static com.dtolabs.rundeck.core.plugins.configuration.StringRenderingConstants.CODE_SYNTAX_MODE; import static com.dtolabs.rundeck.core.plugins.configuration.StringRenderingConstants.DISPLAY_TYPE_KEY; -import static com.bioraft.rundeck.conditional.Switch.CFG_DEFAULT_VALUE; /** * Workflow Node Step Plug-in to choose one of several values to uplift into a @@ -73,27 +71,10 @@ public class SwitchCaseNodeStepPlugin implements NodeStepPlugin { public void executeNodeStep(PluginStepContext ctx, Map cfg, INodeEntry node) throws NodeStepException { - group = cfg.getOrDefault("group", this.group).toString(); - name = cfg.getOrDefault("name", this.name).toString(); - cases = cfg.getOrDefault("cases", this.cases).toString(); - testValue = cfg.getOrDefault("testValue", this.testValue).toString(); elevateToGlobal = cfg.getOrDefault("elevateToGlobal", String.valueOf(elevateToGlobal)).equals("true"); - boolean globalHasDefault = defaultValue != null && defaultValue.length() > 0; - boolean cfgHasDefault = cfg.containsKey(CFG_DEFAULT_VALUE) && cfg.get(CFG_DEFAULT_VALUE) != null; - if (cfgHasDefault) { - this.defaultValue = cfg.get(CFG_DEFAULT_VALUE).toString(); - } - - String message = "Setting " + group + "." + name + " based on " + testValue + " " + cases; - ctx.getLogger().log(Constants.DEBUG_LEVEL, message); - try { - if (cfgHasDefault || globalHasDefault) { - (new Switch(ctx)).switchCase(group, name, cases, testValue, defaultValue, elevateToGlobal); - } else { - (new Switch(ctx)).switchCase(group, name, cases, testValue, elevateToGlobal); - } + (new Switch(ctx, cfg, defaultValue)).switchCase(group, name, cases, testValue, elevateToGlobal); } catch (JsonProcessingException e) { throw new NodeStepException(e.getMessage(), Switch.Causes.INVALID_JSON, node.getNodename()); } diff --git a/src/main/java/com/bioraft/rundeck/conditional/SwitchCaseStepPlugin.java b/src/main/java/com/bioraft/rundeck/conditional/SwitchCaseStepPlugin.java index 49ecacc..1087d57 100644 --- a/src/main/java/com/bioraft/rundeck/conditional/SwitchCaseStepPlugin.java +++ b/src/main/java/com/bioraft/rundeck/conditional/SwitchCaseStepPlugin.java @@ -17,7 +17,6 @@ import java.util.Map; -import com.dtolabs.rundeck.core.Constants; import com.dtolabs.rundeck.core.execution.workflow.steps.StepException; import com.dtolabs.rundeck.core.plugins.Plugin; import com.dtolabs.rundeck.plugins.ServiceNameConstants; @@ -31,7 +30,6 @@ import static com.dtolabs.rundeck.core.plugins.configuration.StringRenderingConstants.CODE_SYNTAX_MODE; import static com.dtolabs.rundeck.core.plugins.configuration.StringRenderingConstants.DISPLAY_TYPE_KEY; -import static com.bioraft.rundeck.conditional.Switch.CFG_DEFAULT_VALUE; /** * Workflow Node Step Plug-in to choose one of several values to uplift into a @@ -70,27 +68,10 @@ public class SwitchCaseStepPlugin implements StepPlugin { @Override public void executeStep(final PluginStepContext ctx, final Map cfg) throws StepException { - group = cfg.getOrDefault("group", this.group).toString(); - name = cfg.getOrDefault("name", this.name).toString(); - cases = cfg.getOrDefault("cases", this.cases).toString(); - testValue = cfg.getOrDefault("testValue", this.testValue).toString(); elevateToGlobal = cfg.getOrDefault("elevateToGlobal", String.valueOf(elevateToGlobal)).equals("true"); - boolean globalHasDefault = defaultValue != null && defaultValue.length() > 0; - boolean cfgHasDefault = cfg.containsKey(CFG_DEFAULT_VALUE) && cfg.get(CFG_DEFAULT_VALUE) != null; - if (cfgHasDefault) { - this.defaultValue = cfg.get(CFG_DEFAULT_VALUE).toString(); - } - - ctx.getLogger().log(Constants.DEBUG_LEVEL, - "Setting " + group + "." + name + " based on " + testValue + " " + cases); - try { - if (cfgHasDefault || globalHasDefault) { - (new Switch(ctx)).switchCase(group, name, cases, testValue, defaultValue, elevateToGlobal); - } else { - (new Switch(ctx)).switchCase(group, name, cases, testValue, elevateToGlobal); - } + (new Switch(ctx, cfg, defaultValue)).switchCase(group, name, cases, testValue, elevateToGlobal); } catch (JsonProcessingException e) { throw new StepException(e.getMessage(), Switch.Causes.INVALID_JSON); } diff --git a/src/test/java/com/bioraft/rundeck/conditional/IfElseTest.java b/src/test/java/com/bioraft/rundeck/conditional/IfElseTest.java index 21491c4..4baf457 100644 --- a/src/test/java/com/bioraft/rundeck/conditional/IfElseTest.java +++ b/src/test/java/com/bioraft/rundeck/conditional/IfElseTest.java @@ -15,8 +15,8 @@ */ package com.bioraft.rundeck.conditional; +import com.dtolabs.rundeck.core.dispatcher.ContextView; import com.dtolabs.rundeck.core.execution.workflow.SharedOutputContext; -import com.dtolabs.rundeck.core.execution.workflow.steps.StepException; import com.dtolabs.rundeck.plugins.PluginLogger; import com.dtolabs.rundeck.plugins.step.PluginStepContext; import org.junit.Before; @@ -60,7 +60,7 @@ public void setUp() { } @Test - public void runTrueTests() throws StepException { + public void runTrueTests() { int i = 0; this.runTestTrue("apple", "eq", "apple", ++i); this.runTestTrue("apple", "ne", "pear", ++i); @@ -79,7 +79,7 @@ public void runTrueTests() throws StepException { } @Test - public void runFalseTests() throws StepException { + public void runFalseTests() { int i = 0; this.runTestFalse("apple", "eq", "apples", ++i); this.runTestFalse("apple", "ne", "apple", ++i); @@ -97,7 +97,33 @@ public void runFalseTests() throws StepException { this.runTestFalse("2.0", "!=", "2.00", ++i); } - private void runTestTrue(String testValue, String operator, String comparison, int calls) throws StepException { + @Test + public void runNoDefaultTests() { + when(context.getOutputContext()).thenReturn(sharedOutputContext); + when(context.getLogger()).thenReturn(logger); + + this.plugin.setElevate(false).setCfg(configuration). + ifElse("raft", "test", "apple", "EQ", "apples", "1", ""); + verify(context, never()).getOutputContext(); + verify(sharedOutputContext, never()).addOutput(anyString(), anyString(), anyString()); + } + + @Test + public void testElevation() { + String group = "raft"; + String name = "test"; + String ifTrue = "1"; + + when(context.getOutputContext()).thenReturn(sharedOutputContext); + when(context.getLogger()).thenReturn(logger); + + this.plugin.setElevate(true).setCfg(configuration).ifElse(group, name, name, "EQ", name, ifTrue, ifTrue); + verify(context, times(2)).getOutputContext(); + verify(sharedOutputContext, times(1)).addOutput(eq(group), eq(name), eq(ifTrue)); + verify(sharedOutputContext, times(1)).addOutput(any(ContextView.class), eq("export"), anyString(), eq(ifTrue)); + } + + private void runTestTrue(String testValue, String operator, String comparison, int calls) { String group = "raft"; String name = "test"; String ifTrue = "1"; @@ -111,8 +137,7 @@ private void runTestTrue(String testValue, String operator, String comparison, i verify(sharedOutputContext, atLeast(calls)).addOutput(eq(group), eq(name), eq(ifTrue)); } - private void runTestFalse(String testValue, String operator, String comparison, int calls) - throws StepException { + private void runTestFalse(String testValue, String operator, String comparison, int calls) { String group = "boat"; String name = "real"; String ifTrue = "yes"; diff --git a/src/test/java/com/bioraft/rundeck/conditional/SwitchCaseNodeStepPluginTest.java b/src/test/java/com/bioraft/rundeck/conditional/SwitchCaseNodeStepPluginTest.java index b3da176..2fc6211 100644 --- a/src/test/java/com/bioraft/rundeck/conditional/SwitchCaseNodeStepPluginTest.java +++ b/src/test/java/com/bioraft/rundeck/conditional/SwitchCaseNodeStepPluginTest.java @@ -15,7 +15,6 @@ */ package com.bioraft.rundeck.conditional; -import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.never; @@ -23,7 +22,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import java.util.HashMap; import java.util.Map; import org.junit.Before; @@ -46,7 +44,7 @@ * @since 2019-12-11 */ @RunWith(MockitoJUnitRunner.class) -public class SwitchCaseNodeStepPluginTest { +public class SwitchCaseNodeStepPluginTest extends SwitchTestBase { SwitchCaseNodeStepPlugin plugin; @@ -61,30 +59,12 @@ public class SwitchCaseNodeStepPluginTest { @Mock INodeEntry node; - private final String group = "raft"; - private final String name = "test"; - private final String testValue = "any"; - private final String defaultValue = "any"; @Before public void setUp() { this.plugin = new SwitchCaseNodeStepPlugin(); } - @Test - public void testEnsureStringIsJsonObject() { - assertEquals("", Switch.ensureStringIsJsonObject(null)); - String given = "\"a\": \"1\""; - String expected = "{" + given + "}"; - assertEquals(expected, Switch.ensureStringIsJsonObject(given)); - assertEquals(expected, Switch.ensureStringIsJsonObject(given + ",")); - assertEquals(expected, Switch.ensureStringIsJsonObject(given + "}")); - assertEquals(expected, Switch.ensureStringIsJsonObject("{" + given)); - assertEquals(expected, Switch.ensureStringIsJsonObject("{" + given + "}")); - assertEquals(expected, Switch.ensureStringIsJsonObject("{" + given + ",}")); - assertEquals(expected, Switch.ensureStringIsJsonObject("{" + given + ", } ")); - } - @Test public void runTestOne() throws NodeStepException { Map cases = ImmutableMap.builder().put("k1", "v1").put("k2", "v2").build(); @@ -103,62 +83,18 @@ public void returnsDefaultOnNoMatch() throws NodeStepException { this.runTest(testValue, "k3", cases, defaultValue); } - @Test - public void runTestDefaultIsNull() throws NodeStepException { - Map configuration = new HashMap<>(); - configuration.put("defaultValue", null); - this.runTestNoDefault(configuration); - } - - @Test - public void runTestNoDefaultValue() throws NodeStepException { - Map configuration = new HashMap<>(); - this.runTestNoDefault(configuration); - } - - @Test - public void testStrippingTrailingComma() throws NodeStepException { - StringBuffer caseString = new StringBuffer(); - Map cases = ImmutableMap.builder().put("k1", "v1").put("k2", "v2").build(); - cases.forEach((k, v) -> caseString.append('"').append(k).append('"').append(":").append('"').append(v).append('"').append(",")); - validInput(caseString.toString()); - } - @Test(expected = NodeStepException.class) public void testInvalidCases() throws NodeStepException { StringBuffer caseString = new StringBuffer(); Map cases = ImmutableMap.builder().put("k1", "v1").put("k2", "v2").build(); cases.forEach((k, v) -> caseString.append('"').append(k).append('"').append(":").append('"').append(v).append('"').append(".")); - invalidInput(caseString.toString()); - } - - private void validInput(String caseString) - throws NodeStepException { - - Map configuration = new HashMap<>(); - configuration.put("group", group); - configuration.put("name", name); - configuration.put("cases", caseString); - configuration.put("testValue", testValue); - configuration.put("defaultValue", defaultValue); - - when(context.getOutputContext()).thenReturn(sharedOutputContext); - when(context.getLogger()).thenReturn(logger); - - this.plugin.executeNodeStep(context, configuration, node); - verify(context, times(1)).getOutputContext(); - verify(sharedOutputContext, times(1)).addOutput(eq(group), eq(name), eq(defaultValue)); + invalidInput(caseString); } - private void invalidInput(String caseString) + private void invalidInput(StringBuffer caseString) throws NodeStepException { - Map configuration = new HashMap<>(); - configuration.put("group", group); - configuration.put("name", name); - configuration.put("cases", caseString); - configuration.put("testValue", testValue); - configuration.put("defaultValue", defaultValue); + Map configuration = getConfiguration(testValue, caseString, defaultValue); when(context.getOutputContext()).thenReturn(sharedOutputContext); when(context.getLogger()).thenReturn(logger); @@ -172,12 +108,7 @@ private void runTest(String expected, String testValue, Map case cases.forEach((k, v) -> caseString.append('"').append(k).append('"').append(":").append('"').append(v).append('"').append(",")); caseString.setLength(caseString.length() - 1); - Map configuration = new HashMap<>(); - configuration.put("group", group); - configuration.put("name", name); - configuration.put("cases", caseString); - configuration.put("testValue", testValue); - configuration.put("defaultValue", defaultValue); + Map configuration = getConfiguration(testValue, caseString, defaultValue); when(context.getOutputContext()).thenReturn(sharedOutputContext); when(context.getLogger()).thenReturn(logger); diff --git a/src/test/java/com/bioraft/rundeck/conditional/SwitchCaseStepPluginTest.java b/src/test/java/com/bioraft/rundeck/conditional/SwitchCaseStepPluginTest.java index b003ebf..6ff64dd 100644 --- a/src/test/java/com/bioraft/rundeck/conditional/SwitchCaseStepPluginTest.java +++ b/src/test/java/com/bioraft/rundeck/conditional/SwitchCaseStepPluginTest.java @@ -15,6 +15,7 @@ */ package com.bioraft.rundeck.conditional; +import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.never; @@ -25,7 +26,6 @@ import java.util.HashMap; import java.util.Map; -import com.dtolabs.rundeck.core.execution.workflow.steps.node.NodeStepException; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -45,7 +45,7 @@ * @since 2019-12-11 */ @RunWith(MockitoJUnitRunner.class) -public class SwitchCaseStepPluginTest { +public class SwitchCaseStepPluginTest extends SwitchTestBase { SwitchCaseStepPlugin plugin; @@ -54,7 +54,7 @@ public class SwitchCaseStepPluginTest { @Mock PluginLogger logger; - + @Mock SharedOutputContext sharedOutputContext; @@ -68,12 +68,44 @@ public void setUp() { this.plugin = new SwitchCaseStepPlugin(); } + @Test + public void testEnsureStringIsJsonObject() { + assertEquals("", Switch.ensureStringIsJsonObject(null)); + String given = "\"a\": \"1\""; + String expected = "{" + given + "}"; + assertEquals(expected, Switch.ensureStringIsJsonObject(given)); + assertEquals(expected, Switch.ensureStringIsJsonObject(given + ",")); + assertEquals(expected, Switch.ensureStringIsJsonObject(given + "}")); + assertEquals(expected, Switch.ensureStringIsJsonObject("{" + given)); + assertEquals(expected, Switch.ensureStringIsJsonObject("{" + given + "}")); + assertEquals(expected, Switch.ensureStringIsJsonObject("{" + given + ",}")); + assertEquals(expected, Switch.ensureStringIsJsonObject("{" + given + ", } ")); + } + @Test public void runTestOne() throws StepException { Map cases = ImmutableMap.builder().put("k1", "v1").put("k2", "v2").build(); this.runTest("v1", "k1", cases, "any"); } + @Test + public void runTestOneGlobal() throws StepException { + Map cases = ImmutableMap.builder().put("k1", "v1").put("k2", "v2").build(); + this.runTestGlobal("v1", "k1", cases, "any", 1); + } + + @Test + public void runTestTwoGlobal() throws StepException { + Map cases = ImmutableMap.builder().put("k1", "v1").put("k2", "v2").build(); + this.runTestGlobal("", "k3", cases, "", 0); + } + + @Test + public void runTestThreeGlobal() throws StepException { + Map cases = ImmutableMap.builder().put("k1", "v1").put("k2", "v2").build(); + this.runTestGlobal("", "k3", cases, null, 0); + } + @Test public void runTestTwo() throws StepException { Map cases = ImmutableMap.builder().put("k1", "v1").put("k2", "v2").build(); @@ -125,7 +157,7 @@ public void testInvalidCases() throws StepException { StringBuffer caseString = new StringBuffer(); Map cases = ImmutableMap.builder().put("k1", "v1").put("k2", "v2").build(); cases.forEach((k, v) -> caseString.append('"').append(k).append('"').append(":").append('"').append(v).append('"').append(".")); - invalidInput(caseString.toString()); + invalidInput(caseString); } private void validInput(String caseString) @@ -146,15 +178,10 @@ private void validInput(String caseString) verify(sharedOutputContext, times(1)).addOutput(eq(group), eq(name), eq(defaultValue)); } - private void invalidInput(String caseString) + private void invalidInput(StringBuffer caseString) throws StepException { - Map configuration = new HashMap<>(); - configuration.put("group", group); - configuration.put("name", name); - configuration.put("cases", caseString); - configuration.put("testValue", testValue); - configuration.put("defaultValue", defaultValue); + Map configuration = getConfiguration(testValue, caseString, defaultValue); when(context.getOutputContext()).thenReturn(sharedOutputContext); when(context.getLogger()).thenReturn(logger); @@ -164,18 +191,11 @@ private void invalidInput(String caseString) private void runTest(String expected, String testValue, Map cases, String defaultValue) throws StepException { - String group = "raft"; - String name = "test"; StringBuffer caseString = new StringBuffer(); cases.forEach((k, v) -> caseString.append('"').append(k).append('"').append(":").append('"').append(v).append('"').append(",")); caseString.setLength(caseString.length() - 1); - Map configuration = new HashMap<>(); - configuration.put("group", group); - configuration.put("name", name); - configuration.put("cases", caseString); - configuration.put("testValue", testValue); - configuration.put("defaultValue", defaultValue); + Map configuration = getConfiguration(testValue, caseString, defaultValue); when(context.getOutputContext()).thenReturn(sharedOutputContext); when(context.getLogger()).thenReturn(logger); @@ -186,9 +206,6 @@ private void runTest(String expected, String testValue, Map case } public void runTestNoDefault(Map configuration) throws StepException { - String group = "raft"; - String name = "test"; - Map cases = ImmutableMap.builder().put("k1", "v1").put("k2", "v2").build(); StringBuilder caseString = new StringBuilder(); cases.forEach((k, v) -> caseString.append('"').append(k).append('"').append(":").append('"').append(v).append('"').append(",")); @@ -196,7 +213,7 @@ public void runTestNoDefault(Map configuration) throws StepExcep configuration.put("cases", caseString.toString()); configuration.put("group", group); - configuration.put("name", name); + configuration.put("name", name); configuration.put("testValue", "v3"); when(context.getOutputContext()).thenReturn(sharedOutputContext); @@ -206,4 +223,23 @@ public void runTestNoDefault(Map configuration) throws StepExcep verify(context, never()).getOutputContext(); verify(sharedOutputContext, never()).addOutput(any(String.class), any(String.class), any(String.class)); } + + private void runTestGlobal(String expected, String testValue, Map cases, String defaultValue, int mult) + throws StepException { + String group = "raft"; + String name = "test"; + StringBuffer caseString = new StringBuffer(); + cases.forEach((k, v) -> caseString.append('"').append(k).append('"').append(":").append('"').append(v).append('"').append(",")); + caseString.setLength(caseString.length() - 1); + + Map configuration = getConfiguration(testValue, caseString, defaultValue); + configuration.put("elevateToGlobal", "true"); + + when(context.getOutputContext()).thenReturn(sharedOutputContext); + when(context.getLogger()).thenReturn(logger); + + this.plugin.executeStep(context, configuration); + verify(context, times(mult * 2)).getOutputContext(); + verify(sharedOutputContext, times(mult)).addOutput(eq(group), eq(name), eq(expected)); + } } diff --git a/src/test/java/com/bioraft/rundeck/conditional/SwitchTestBase.java b/src/test/java/com/bioraft/rundeck/conditional/SwitchTestBase.java new file mode 100644 index 0000000..ebbe7df --- /dev/null +++ b/src/test/java/com/bioraft/rundeck/conditional/SwitchTestBase.java @@ -0,0 +1,23 @@ +package com.bioraft.rundeck.conditional; + +import java.util.HashMap; +import java.util.Map; + +public class SwitchTestBase { + + protected final String group = "raft"; + protected final String name = "test"; + protected final String testValue = "any"; + protected final String defaultValue = "any"; + + protected Map getConfiguration(String testValue, StringBuffer caseString, String defaultValue) { + Map configuration = new HashMap<>(); + configuration.put("group", group); + configuration.put("name", name); + configuration.put("cases", caseString); + configuration.put("testValue", testValue); + configuration.put("defaultValue", defaultValue); + return configuration; + } + +}