Skip to content

Commit

Permalink
Update gradle wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Karl DeBisschop committed Feb 29, 2020
1 parent 35e1bc4 commit 54e0aa1
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ dependencies {
)
}

plugins.withType(JacocoPlugin) {
tasks["test"].finalizedBy 'jacocoTestReport'
}

// task to copy plugin libs to output/lib dir
task copyToLib(type: Copy) {
into "$buildDir/output/lib"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ public void executeStep(final PluginStepContext ctx, final Map<String, Object> c
} else {
(new Switch(ctx)).switchCase(group, name, cases, testValue, elevateToGlobal);
}
} catch (
JsonProcessingException e) {
} catch (JsonProcessingException e) {
throw new StepException(e.getMessage(), Switch.Causes.INVALID_JSON);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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;
Expand Down Expand Up @@ -57,6 +58,11 @@ public class SwitchCaseStepPluginTest {
@Mock
SharedOutputContext sharedOutputContext;

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 SwitchCaseStepPlugin();
Expand Down Expand Up @@ -93,6 +99,69 @@ public void runTestFive() throws StepException {
this.runTestNoDefault(configuration);
}

@Test
public void runTestDefaultIsNull() throws StepException {
Map<String, Object> configuration = new HashMap<>();
configuration.put("defaultValue", null);
this.runTestNoDefault(configuration);
}

@Test
public void runTestNoDefaultValue() throws StepException {
Map<String, Object> configuration = new HashMap<>();
this.runTestNoDefault(configuration);
}

@Test
public void testStrippingTrailingComma() throws StepException {
StringBuffer caseString = new StringBuffer();
Map<String, String> cases = ImmutableMap.<String, String>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 = StepException.class)
public void testInvalidCases() throws StepException {
StringBuffer caseString = new StringBuffer();
Map<String, String> cases = ImmutableMap.<String, String>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 StepException {

Map<String, Object> 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.executeStep(context, configuration);
verify(context, times(1)).getOutputContext();
verify(sharedOutputContext, times(1)).addOutput(eq(group), eq(name), eq(defaultValue));
}

private void invalidInput(String caseString)
throws StepException {

Map<String, Object> 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.executeStep(context, configuration);
}

private void runTest(String expected, String testValue, Map<String, String> cases, String defaultValue)
throws StepException {
String group = "raft";
Expand Down

0 comments on commit 54e0aa1

Please sign in to comment.