geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bschucha...@apache.org
Subject [14/37] incubator-geode git commit: GEODE-213: New unit test that confirms bug
Date Tue, 01 Sep 2015 16:48:52 GMT
GEODE-213: New unit test that confirms bug


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/581702ac
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/581702ac
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/581702ac

Branch: refs/heads/feature/GEODE-77
Commit: 581702ac1d2a9debe8619680d09fa868b9ca8b05
Parents: f246c7f
Author: Kirk Lund <klund@pivotal.io>
Authored: Wed Aug 19 16:01:26 2015 -0700
Committer: Kirk Lund <klund@pivotal.io>
Committed: Wed Aug 19 16:08:07 2015 -0700

----------------------------------------------------------------------
 build.gradle                                    |   2 +
 .../WanCommandsControllerJUnitTest.java         | 162 +++++++++++++++++++
 2 files changed, 164 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/581702ac/build.gradle
----------------------------------------------------------------------
diff --git a/build.gradle b/build.gradle
index 42b4a14..d7b4965 100755
--- a/build.gradle
+++ b/build.gradle
@@ -278,11 +278,13 @@ subprojects {
     testCompile 'com.github.stefanbirkner:system-rules:1.9.0'
     testCompile 'edu.umd.cs.mtc:multithreadedtc:1.01'
     testCompile 'junit:junit:4.12'
+    testCompile 'org.assertj:assertj-core:2.1.0'
     testCompile 'org.mockito:mockito-core:1.10.19'
     testCompile 'org.hamcrest:hamcrest-all:1.3'
     testCompile 'org.jmock:jmock:2.8.1'
     testCompile 'org.jmock:jmock-junit4:2.8.1'
     testCompile 'org.jmock:jmock-legacy:2.8.1'
+    testCompile 'pl.pragmatists:JUnitParams:1.0.4'
     
     testRuntime 'cglib:cglib:3.1'
     testRuntime 'org.objenesis:objenesis:2.1'

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/581702ac/gemfire-core/src/test/java/com/gemstone/gemfire/management/internal/web/controllers/WanCommandsControllerJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/management/internal/web/controllers/WanCommandsControllerJUnitTest.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/management/internal/web/controllers/WanCommandsControllerJUnitTest.java
new file mode 100755
index 0000000..fb39d8c
--- /dev/null
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/management/internal/web/controllers/WanCommandsControllerJUnitTest.java
@@ -0,0 +1,162 @@
+package com.gemstone.gemfire.management.internal.web.controllers;
+
+import static com.gemstone.gemfire.management.internal.cli.i18n.CliStrings.*;
+import static junitparams.JUnitParamsRunner.$;
+import static org.assertj.core.api.Assertions.*;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
+
+import junitparams.JUnitParamsRunner;
+import junitparams.Parameters;
+
+/**
+ * Unit tests for WanCommandsController. 
+ * 
+ * Introduced for GEODE-213 "JMX -http manager treats "start gateway-sender" as "start gateway-receiver"
+ *  
+ * @author Kirk Lund
+ */
+@SuppressWarnings("unused")
+@Category(UnitTest.class)
+@RunWith(JUnitParamsRunner.class)
+public class WanCommandsControllerJUnitTest {
+
+  private TestableWanCommandsController wanCommandsController;
+  
+  @Before
+  public void setUp() {
+    this.wanCommandsController = new TestableWanCommandsController();
+  }
+  
+  private static final Object[] getParametersWithGroups() {
+    return $(
+        new Object[] { "sender1", new String[] { "group1" }, new String[] { }, true, false
},
+        new Object[] { "sender2", new String[] { "group1, group2" }, new String[] { }, true,
false }
+    );
+  }
+
+  private static final Object[] getParametersWithMembers() {
+    return $(
+        new Object[] { "sender3", new String[] { }, new String[] { "member1" }, false, true
},
+        new Object[] { "sender4", new String[] { }, new String[] { "member1, member2" },
false, true }
+    );
+  }
+  
+  private static final Object[] getParametersWithGroupsAndMembers() {
+    return $(
+        new Object[] { "sender5", new String[] { "group1" }, new String[] { "member1" },
true, true },
+        new Object[] { "sender6", new String[] { "group1,group2" }, new String[] { "member1,member2"
}, true, true },
+        new Object[] { "sender7", new String[] { "group1, group2" }, new String[] { "member1,
member2" }, true, true }
+    );
+  }
+  
+  @Test
+  public void shouldDefineStartGatewayReceiverCommandWithNulls() {
+    this.wanCommandsController.startGatewaySender(null, null, null);
+    
+    assertThat(this.wanCommandsController.testableCommand).contains("--"+START_GATEWAYSENDER__ID+"="+null);
+    assertThat(this.wanCommandsController.testableCommand).contains(START_GATEWAYSENDER);
+    assertThat(this.wanCommandsController.testableCommand).doesNotContain(START_GATEWAYRECEIVER__GROUP);
+    assertThat(this.wanCommandsController.testableCommand).doesNotContain(START_GATEWAYRECEIVER__MEMBER);
+  }
+  
+  @Test
+  @Parameters(method = "getParametersWithGroups")
+  public void shouldDefineStartGatewayReceiverCommandWithGroups(final String gatewaySenderId,
final String[] groups, final String[] members, final boolean containsGroups, final boolean
containsMembers) {
+    this.wanCommandsController.startGatewaySender(gatewaySenderId, groups, members);
+    
+    assertThat(this.wanCommandsController.testableCommand).contains(START_GATEWAYSENDER);
+    assertThat(this.wanCommandsController.testableCommand).contains("--"+START_GATEWAYSENDER__ID+"="+gatewaySenderId);
+    assertThat(this.wanCommandsController.testableCommand).contains(START_GATEWAYRECEIVER__GROUP);
+    assertThat(this.wanCommandsController.testableCommand).doesNotContain(START_GATEWAYRECEIVER__MEMBER);
+  }
+  
+  @Test
+  @Parameters(method = "getParametersWithMembers")
+  public void shouldDefineStartGatewayReceiverCommandWithMembers(final String gatewaySenderId,
final String[] groups, final String[] members, final boolean containsGroups, final boolean
containsMembers) {
+    this.wanCommandsController.startGatewaySender(gatewaySenderId, groups, members);
+    
+    assertThat(this.wanCommandsController.testableCommand).contains(START_GATEWAYSENDER);
+    assertThat(this.wanCommandsController.testableCommand).contains("--"+START_GATEWAYSENDER__ID+"="+gatewaySenderId);
+    assertThat(this.wanCommandsController.testableCommand).doesNotContain(START_GATEWAYRECEIVER__GROUP);
+    assertThat(this.wanCommandsController.testableCommand).contains(START_GATEWAYRECEIVER__MEMBER);
+  }
+  
+  @Test
+  @Parameters(method = "getParametersWithGroupsAndMembers")
+  public void shouldDefineStartGatewayReceiverCommandWithGroupsAndMembers(final String gatewaySenderId,
final String[] groups, final String[] members, final boolean containsGroups, final boolean
containsMembers) {
+    this.wanCommandsController.startGatewaySender(gatewaySenderId, groups, members);
+    
+    assertThat(this.wanCommandsController.testableCommand).contains(START_GATEWAYSENDER);
+    assertThat(this.wanCommandsController.testableCommand).contains("--"+START_GATEWAYSENDER__ID+"="+gatewaySenderId);
+    assertThat(this.wanCommandsController.testableCommand).contains(START_GATEWAYRECEIVER__GROUP);
+    assertThat(this.wanCommandsController.testableCommand).contains(START_GATEWAYRECEIVER__MEMBER);
+  }
+  
+  @Test
+  public void shouldDefineStartGatewayReceiverCommandWithOutGroupsOrMembers() {
+    final String gatewaySenderId = "senderA";
+        
+    this.wanCommandsController.startGatewaySender("senderA", new String[] {}, new String[]
{});
+    
+    assertThat(this.wanCommandsController.testableCommand).contains(START_GATEWAYSENDER);
+    assertThat(this.wanCommandsController.testableCommand).contains("--"+START_GATEWAYSENDER__ID+"="+gatewaySenderId);
+    assertThat(this.wanCommandsController.testableCommand).doesNotContain(START_GATEWAYRECEIVER__GROUP);
+    assertThat(this.wanCommandsController.testableCommand).doesNotContain(START_GATEWAYRECEIVER__MEMBER);
+  }
+  
+  /**
+   * Tests null gatewaySenderId.
+   * 
+   * This test verifies that the class under test allows null value which 
+   * would only be rejected at runtime by the overall framework and is tested 
+   * within an integration test.
+   *
+   * @see WanCommandGatewaySenderStartDUnitTest
+   */
+  @Test
+  public void shouldDefineStartGatewayReceiverCommandWithNullGatewaySenderId() {
+    this.wanCommandsController.startGatewaySender(null, null, null);
+    
+    assertThat(this.wanCommandsController.testableCommand).contains(START_GATEWAYSENDER);
+    assertThat(this.wanCommandsController.testableCommand).contains("--"+START_GATEWAYSENDER__ID+"="+null);
+  }
+  
+  /**
+   * Tests empty gatewaySenderId.
+   * 
+   * This test verifies that the class under test allows empty value which 
+   * would only be rejected at runtime by the overall framework and is tested 
+   * within an integration test.
+   *
+   * @see WanCommandGatewaySenderStartDUnitTest
+   */
+  @Test
+  public void shouldDefineStartGatewayReceiverCommandWithEmptyGatewaySenderId() {
+    this.wanCommandsController.startGatewaySender("", null, null);
+    
+    assertThat(this.wanCommandsController.testableCommand).contains(START_GATEWAYSENDER);
+    assertThat(this.wanCommandsController.testableCommand).contains("--"+START_GATEWAYSENDER__ID+"="+"");
+  }
+  
+  /**
+   * It would be ideal to refactor AbstractCommandsController such that 
+   * defining of command strings and submitting them for execution are
+   * performed by two different classes. Then we could mock the executor
+   * class while testing just the command string definition class.
+   */
+  public static class TestableWanCommandsController extends WanCommandsController {
+    protected String testableCommand;
+    
+    @Override
+    protected String processCommand(final String command) {
+      this.testableCommand = command;
+      return null; // do nothing
+    }
+  }
+}


Mime
View raw message