geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [18/27] geode git commit: GEODE-3328: simplify GfshParserRule
Date Fri, 04 Aug 2017 23:25:46 GMT
GEODE-3328: simplify GfshParserRule


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

Branch: refs/heads/feature/GEODE-3299
Commit: f52ebcaf4ff1fecedcc7daced0c0adac13764ed1
Parents: f7198be
Author: Jinmei Liao <jiliao@pivotal.io>
Authored: Thu Aug 3 10:06:51 2017 -0700
Committer: Jinmei Liao <jiliao@pivotal.io>
Committed: Thu Aug 3 12:43:39 2017 -0700

----------------------------------------------------------------------
 .../StartLocatorCommandIntegrationTest.java     | 23 ++++++++------
 .../StartServerCommandIntegrationTest.java      | 25 ++++++++-------
 .../CreateAlterDestroyRegionCommandsTest.java   |  9 ++++--
 .../geode/test/dunit/rules/GfshParserRule.java  | 32 ++++++++------------
 4 files changed, 45 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/f52ebcaf/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommandIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommandIntegrationTest.java
b/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommandIntegrationTest.java
index 0700742..9dfb718 100644
--- a/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommandIntegrationTest.java
+++ b/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommandIntegrationTest.java
@@ -25,11 +25,13 @@ import static org.mockito.Mockito.verify;
 
 import java.util.Properties;
 
+import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.junit.rules.TemporaryFolder;
 import org.mockito.ArgumentCaptor;
+import org.mockito.Mockito;
 
 import org.apache.geode.management.internal.cli.shell.Gfsh;
 import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
@@ -46,10 +48,17 @@ public class StartLocatorCommandIntegrationTest {
   @Rule
   public TemporaryFolder temporaryFolder = new TemporaryFolder();
 
+  private StartLocatorCommand spy;
+
+  @Before
+  public void before() throws Exception {
+    spy = Mockito.spy(StartLocatorCommand.class);
+    doReturn(mock(Gfsh.class)).when(spy).getGfsh();
+  }
+
   @Test
   public void startLocatorWorksWithNoOptions() throws Exception {
-    StartLocatorCommand spy = spyOnStartLocatorCommand("start locator");
-    commandRule.executeLastCommandWithInstance(spy);
+    commandRule.executeCommandWithInstance(spy, "start locator");
 
     ArgumentCaptor<Properties> gemfirePropertiesCaptor = ArgumentCaptor.forClass(Properties.class);
     verify(spy).createStartLocatorCommandLine(any(), any(), any(),
@@ -65,11 +74,10 @@ public class StartLocatorCommandIntegrationTest {
     String startLocatorCommand = new CommandStringBuilder("start locator")
         .addOption(JMX_MANAGER_HOSTNAME_FOR_CLIENTS, FAKE_HOSTNAME).toString();
 
-    StartLocatorCommand spyCommand = spyOnStartLocatorCommand(startLocatorCommand);
-    commandRule.executeLastCommandWithInstance(spyCommand);
+    commandRule.executeCommandWithInstance(spy, startLocatorCommand);
 
     ArgumentCaptor<Properties> gemfirePropertiesCaptor = ArgumentCaptor.forClass(Properties.class);
-    verify(spyCommand).createStartLocatorCommandLine(any(), any(), any(),
+    verify(spy).createStartLocatorCommandLine(any(), any(), any(),
         gemfirePropertiesCaptor.capture(), any(), any(), any(), any(), any());
 
     Properties gemfireProperties = gemfirePropertiesCaptor.getValue();
@@ -77,9 +85,4 @@ public class StartLocatorCommandIntegrationTest {
     assertThat(gemfireProperties.get(JMX_MANAGER_HOSTNAME_FOR_CLIENTS)).isEqualTo(FAKE_HOSTNAME);
   }
 
-  private StartLocatorCommand spyOnStartLocatorCommand(String command) {
-    StartLocatorCommand spy = commandRule.spyCommand(command);
-    doReturn(mock(Gfsh.class)).when(spy).getGfsh();
-    return spy;
-  }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/f52ebcaf/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StartServerCommandIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StartServerCommandIntegrationTest.java
b/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StartServerCommandIntegrationTest.java
index 059611d..8bfd801 100644
--- a/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StartServerCommandIntegrationTest.java
+++ b/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StartServerCommandIntegrationTest.java
@@ -25,11 +25,13 @@ import static org.mockito.Mockito.verify;
 
 import java.util.Properties;
 
+import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.junit.rules.TemporaryFolder;
 import org.mockito.ArgumentCaptor;
+import org.mockito.Mockito;
 
 import org.apache.geode.management.internal.cli.shell.Gfsh;
 import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
@@ -46,10 +48,17 @@ public class StartServerCommandIntegrationTest {
   @Rule
   public TemporaryFolder temporaryFolder = new TemporaryFolder();
 
+  private StartServerCommand spy;
+
+  @Before
+  public void before() throws Exception {
+    spy = Mockito.spy(StartServerCommand.class);
+    doReturn(mock(Gfsh.class)).when(spy).getGfsh();
+  }
+
   @Test
   public void startServerWorksWithNoOptions() throws Exception {
-    StartServerCommand spy = spyOnStartServerCommand("start server");
-    commandRule.executeLastCommandWithInstance(spy);
+    commandRule.executeCommandWithInstance(spy, "start server");
 
     ArgumentCaptor<Properties> gemfirePropertiesCaptor = ArgumentCaptor.forClass(Properties.class);
     verify(spy).createStartServerCommandLine(any(), any(), any(), gemfirePropertiesCaptor.capture(),
@@ -65,21 +74,15 @@ public class StartServerCommandIntegrationTest {
     String startServerCommand = new CommandStringBuilder("start server")
         .addOption(JMX_MANAGER_HOSTNAME_FOR_CLIENTS, FAKE_HOSTNAME).toString();
 
-    StartServerCommand commandSpy = spyOnStartServerCommand(startServerCommand);
-    commandRule.executeLastCommandWithInstance(commandSpy);
+    commandRule.executeCommandWithInstance(spy, startServerCommand);
 
     ArgumentCaptor<Properties> gemfirePropertiesCaptor = ArgumentCaptor.forClass(Properties.class);
-    verify(commandSpy).createStartServerCommandLine(any(), any(), any(),
-        gemfirePropertiesCaptor.capture(), any(), any(), any(), any(), any(), any());
+    verify(spy).createStartServerCommandLine(any(), any(), any(), gemfirePropertiesCaptor.capture(),
+        any(), any(), any(), any(), any(), any());
 
     Properties gemfireProperties = gemfirePropertiesCaptor.getValue();
     assertThat(gemfireProperties).containsKey(JMX_MANAGER_HOSTNAME_FOR_CLIENTS);
     assertThat(gemfireProperties.get(JMX_MANAGER_HOSTNAME_FOR_CLIENTS)).isEqualTo(FAKE_HOSTNAME);
   }
 
-  private StartServerCommand spyOnStartServerCommand(String command) {
-    StartServerCommand spy = commandRule.spyCommand(command);
-    doReturn(mock(Gfsh.class)).when(spy).getGfsh();
-    return spy;
-  }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/f52ebcaf/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsTest.java
index c281080..85b660d 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsTest.java
@@ -23,6 +23,7 @@ import static org.mockito.Mockito.mock;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
+import org.mockito.Mockito;
 
 import org.apache.geode.internal.cache.InternalCache;
 import org.apache.geode.management.DistributedSystemMXBean;
@@ -39,12 +40,14 @@ public class CreateAlterDestroyRegionCommandsTest {
   public void testCreateRegionWithInvalidPartitionResolver() throws Exception {
     InternalCache cache = mock(InternalCache.class);
     DistributedSystemMXBean dsMBean = mock(DistributedSystemMXBean.class);
-    CreateAlterDestroyRegionCommands spy =
-        parser.spyCommand("create region --name=region3 --type=PARTITION --partition-resolver=Foo");
+    CreateAlterDestroyRegionCommands spy = Mockito.spy(CreateAlterDestroyRegionCommands.class);
+
     doReturn(cache).when(spy).getCache();
     doReturn(dsMBean).when(spy).getDSMBean(cache);
 
-    assertThatThrownBy(() -> parser.executeLastCommandWithInstance(spy))
+    String command = "create region --name=region3 --type=PARTITION --partition-resolver=Foo";
+
+    assertThatThrownBy(() -> parser.executeCommandWithInstance(spy, command))
         .hasMessageContaining("Foo is an invalid Partition Resolver");
   }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/f52ebcaf/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshParserRule.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshParserRule.java
b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshParserRule.java
index b1bc7aa..27f4b28 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshParserRule.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshParserRule.java
@@ -16,48 +16,40 @@
 package org.apache.geode.test.dunit.rules;
 
 import static org.mockito.Mockito.spy;
-import static org.assertj.core.api.Assertions.assertThat;
 
-import org.apache.geode.management.cli.Result;
-import org.apache.geode.management.internal.cli.CommandManager;
-import org.apache.geode.management.internal.cli.GfshParseResult;
-import org.apache.geode.management.internal.cli.GfshParser;
-import org.apache.geode.management.internal.cli.remote.RemoteExecutionStrategy;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
 import org.junit.rules.ExternalResource;
-import org.springframework.shell.core.CommandMarker;
 import org.springframework.shell.core.Completion;
 import org.springframework.shell.core.Converter;
+import org.springframework.shell.event.ParseResult;
 import org.springframework.util.ReflectionUtils;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
+import org.apache.geode.management.internal.cli.CommandManager;
+import org.apache.geode.management.internal.cli.GfshParseResult;
+import org.apache.geode.management.internal.cli.GfshParser;
+import org.apache.geode.management.internal.cli.result.CommandResult;
 
 public class GfshParserRule extends ExternalResource {
 
   private GfshParser parser;
   private CommandManager commandManager;
-  private GfshParseResult parseResult;
 
   @Override
   public void before() {
     commandManager = new CommandManager();
     parser = new GfshParser(commandManager);
-    parseResult = null;
   }
 
   public GfshParseResult parse(String command) {
     return parser.parse(command);
   }
 
-  public <T> T spyCommand(String command) {
-    parseResult = parse(command);
-    T spy = (T) spy(parseResult.getInstance());
-    return spy;
-  }
-
-  public <T> Result executeLastCommandWithInstance(T instance) {
-    return (Result) ReflectionUtils.invokeMethod(parseResult.getMethod(), instance,
+  public <T> CommandResult executeCommandWithInstance(T instance, String command) {
+    ParseResult parseResult = parse(command);
+    return (CommandResult) ReflectionUtils.invokeMethod(parseResult.getMethod(), instance,
         parseResult.getArguments());
   }
 


Mime
View raw message