This is an automated email from the ASF dual-hosted git repository.
jinmeiliao pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new 36408b7 GEODE-3872: simplify the Command result Assert (#1043)
36408b7 is described below
commit 36408b72b8a629896842fcc1dcae04c939cccda7
Author: jinmeiliao <[email protected]>
AuthorDate: Fri Nov 10 15:21:28 2017 -0800
GEODE-3872: simplify the Command result Assert (#1043)
* GEODE-3872: simplify the Command result Assert
---
.../cli/commands/DestroyRegionCommandTest.java | 6 ++-
...ionRuleAssert.java => CommandResultAssert.java} | 48 +++++++++++-----------
...eExecution.java => CommandResultExecution.java} | 19 +++------
.../geode/test/junit/rules/GfshParserRule.java | 6 +++
.../test/junit/rules/GfshShellConnectionRule.java | 6 +--
.../internal/cli/LuceneIndexCommandsDUnitTest.java | 5 +--
6 files changed, 46 insertions(+), 44 deletions(-)
diff --git
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DestroyRegionCommandTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DestroyRegionCommandTest.java
index b519c8d..7cfe126 100644
---
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DestroyRegionCommandTest.java
+++
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DestroyRegionCommandTest.java
@@ -31,6 +31,7 @@ import org.junit.experimental.categories.Category;
import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.management.cli.Result;
import org.apache.geode.management.internal.cli.result.CommandResult;
+import org.apache.geode.test.junit.assertions.CommandResultAssert;
import org.apache.geode.test.junit.categories.UnitTest;
import org.apache.geode.test.junit.rules.GfshParserRule;
@@ -68,9 +69,10 @@ public class DestroyRegionCommandTest {
public void whenNoRegionIsFoundOnAnyMembers() throws Exception {
doReturn(Collections.emptySet()).when(command).findMembersForRegion(any(),
any());
result = parser.executeCommandWithInstance(command, "destroy region
--name=test");
- assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR);
+ new CommandResultAssert(result).statusIsError()
+ .containsOutput("Could not find a Region with Region path");
result = parser.executeCommandWithInstance(command, "destroy region
--name=test --if-exists");
- assertThat(result.getStatus()).isEqualTo(Result.Status.OK);
+ new CommandResultAssert(result).statusIsSuccess();
}
}
diff --git
a/geode-core/src/test/java/org/apache/geode/test/junit/assertions/GfshShellConnectionRuleAssert.java
b/geode-core/src/test/java/org/apache/geode/test/junit/assertions/CommandResultAssert.java
similarity index 80%
rename from
geode-core/src/test/java/org/apache/geode/test/junit/assertions/GfshShellConnectionRuleAssert.java
rename to
geode-core/src/test/java/org/apache/geode/test/junit/assertions/CommandResultAssert.java
index 79d54d9..f23326b 100644
---
a/geode-core/src/test/java/org/apache/geode/test/junit/assertions/GfshShellConnectionRuleAssert.java
+++
b/geode-core/src/test/java/org/apache/geode/test/junit/assertions/CommandResultAssert.java
@@ -17,8 +17,6 @@ package org.apache.geode.test.junit.assertions;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;
-import java.util.List;
-import java.util.Optional;
import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.Assertions;
@@ -27,14 +25,18 @@ import org.json.JSONArray;
import org.apache.geode.management.cli.Result;
import org.apache.geode.management.internal.cli.json.GfJsonObject;
import org.apache.geode.management.internal.cli.result.CommandResult;
-import org.apache.geode.test.junit.rules.GfshShellConnectionRule;
-public class GfshShellConnectionRuleAssert
- extends AbstractAssert<GfshShellConnectionRuleAssert,
GfshShellConnectionRuleExecution> {
- public GfshShellConnectionRuleAssert(GfshShellConnectionRule gfsh,
CommandResult commandResult) {
- super(new GfshShellConnectionRuleExecution(gfsh, commandResult),
- GfshShellConnectionRuleAssert.class);
+public class CommandResultAssert
+ extends AbstractAssert<CommandResultAssert, CommandResultExecution> {
+
+ public CommandResultAssert(CommandResult commandResult) {
+ super(new CommandResultExecution(commandResult.toJson(), commandResult),
+ CommandResultAssert.class);
+ }
+
+ public CommandResultAssert(String output, CommandResult commandResult) {
+ super(new CommandResultExecution(output, commandResult),
CommandResultAssert.class);
}
/**
@@ -57,8 +59,8 @@ public class GfshShellConnectionRuleAssert
* <code> containsKeyValuePair("Key Class", "java.lang.String"); </code>
* </pre>
*/
- public GfshShellConnectionRuleAssert containsKeyValuePair(String key, String
value) {
- assertThat(actual.getGfshOutput()).containsPattern(key + "\\s+: " + value);
+ public CommandResultAssert containsKeyValuePair(String key, String value) {
+ assertThat(actual.getOutput()).containsPattern(key + "\\s+: " + value);
return this;
}
@@ -66,9 +68,9 @@ public class GfshShellConnectionRuleAssert
/**
* Verifies the gfsh output contains the given output
*/
- public GfshShellConnectionRuleAssert containsOutput(String...
expectedOutputs) {
+ public CommandResultAssert containsOutput(String... expectedOutputs) {
for (String expectedOutput : expectedOutputs) {
- assertThat(actual.getGfshOutput()).contains(expectedOutput);
+ assertThat(actual.getOutput()).contains(expectedOutput);
}
return this;
@@ -77,9 +79,9 @@ public class GfshShellConnectionRuleAssert
/**
* Verifies the gfsh output does not contain the given output
*/
- public GfshShellConnectionRuleAssert doesNotContainOutput(String...
expectedOutputs) {
+ public CommandResultAssert doesNotContainOutput(String... expectedOutputs) {
for (String expectedOutput : expectedOutputs) {
- assertThat(actual.getGfshOutput()).doesNotContain(expectedOutput);
+ assertThat(actual.getOutput()).doesNotContain(expectedOutput);
}
return this;
@@ -88,9 +90,9 @@ public class GfshShellConnectionRuleAssert
/**
* Verifies that gfsh executed with status OK
*/
- public GfshShellConnectionRuleAssert statusIsSuccess() {
+ public CommandResultAssert statusIsSuccess() {
CommandResult result = actual.getCommandResult();
-
Assertions.assertThat(result.getStatus()).describedAs(actual.getGfsh().getGfshOutput())
+ Assertions.assertThat(result.getStatus()).describedAs(actual.getOutput())
.isEqualTo(Result.Status.OK);
return this;
@@ -99,9 +101,9 @@ public class GfshShellConnectionRuleAssert
/**
* Verifies that gfsh executed with status ERROR
*/
- public GfshShellConnectionRuleAssert statusIsError() {
+ public CommandResultAssert statusIsError() {
CommandResult result = actual.getCommandResult();
-
Assertions.assertThat(result.getStatus()).describedAs(actual.getGfsh().getGfshOutput())
+ Assertions.assertThat(result.getStatus()).describedAs(actual.getOutput())
.isEqualTo(Result.Status.ERROR);
return this;
@@ -127,7 +129,7 @@ public class GfshShellConnectionRuleAssert
* </code>
* </pre>
*/
- public GfshShellConnectionRuleAssert
tableHasColumnWithExactValuesInExactOrder(String header,
+ public CommandResultAssert tableHasColumnWithExactValuesInExactOrder(String
header,
Object... expectedValues) {
GfJsonObject resultContentJSON = actual.getCommandResult().getContent();
Object content = resultContentJSON.get(header);
@@ -163,7 +165,7 @@ public class GfshShellConnectionRuleAssert
* <code> tableHasColumnWithExactValuesInAnyOrder("Region Path", "/region2",
"/region1"); </code>
* </pre>
*/
- public GfshShellConnectionRuleAssert
tableHasColumnWithExactValuesInAnyOrder(String header,
+ public CommandResultAssert tableHasColumnWithExactValuesInAnyOrder(String
header,
Object... expectedValues) {
GfJsonObject resultContentJSON = actual.getCommandResult().getContent();
Object content = resultContentJSON.get(header);
@@ -183,7 +185,7 @@ public class GfshShellConnectionRuleAssert
* Verifies that each of the actual values in the column with the given
header contains at least
* one of the expectedValues.
*/
- public GfshShellConnectionRuleAssert
tableHasColumnWithValuesContaining(String header,
+ public CommandResultAssert tableHasColumnWithValuesContaining(String header,
String... expectedValues) {
GfJsonObject resultContentJSON = actual.getCommandResult().getContent();
Object content = resultContentJSON.get(header);
@@ -208,13 +210,13 @@ public class GfshShellConnectionRuleAssert
return this;
}
- public GfshShellConnectionRuleAssert hasResult() {
+ public CommandResultAssert hasResult() {
containsKeyValuePair("Result", "true");
return this;
}
- public GfshShellConnectionRuleAssert hasNoResult() {
+ public CommandResultAssert hasNoResult() {
containsKeyValuePair("Result", "false");
return this;
diff --git
a/geode-core/src/test/java/org/apache/geode/test/junit/assertions/GfshShellConnectionRuleExecution.java
b/geode-core/src/test/java/org/apache/geode/test/junit/assertions/CommandResultExecution.java
similarity index 71%
rename from
geode-core/src/test/java/org/apache/geode/test/junit/assertions/GfshShellConnectionRuleExecution.java
rename to
geode-core/src/test/java/org/apache/geode/test/junit/assertions/CommandResultExecution.java
index b4c3003..ec79c18 100644
---
a/geode-core/src/test/java/org/apache/geode/test/junit/assertions/GfshShellConnectionRuleExecution.java
+++
b/geode-core/src/test/java/org/apache/geode/test/junit/assertions/CommandResultExecution.java
@@ -15,28 +15,21 @@
package org.apache.geode.test.junit.assertions;
import org.apache.geode.management.internal.cli.result.CommandResult;
-import org.apache.geode.test.junit.rules.GfshShellConnectionRule;
-public class GfshShellConnectionRuleExecution {
- private GfshShellConnectionRule gfsh;
+public class CommandResultExecution {
private CommandResult commandResult;
+ private String output;
- public GfshShellConnectionRuleExecution(GfshShellConnectionRule gfsh,
- CommandResult commandResult) {
-
- this.gfsh = gfsh;
+ public CommandResultExecution(String output, CommandResult commandResult) {
+ this.output = output;
this.commandResult = commandResult;
}
- public GfshShellConnectionRule getGfsh() {
- return gfsh;
- }
-
public CommandResult getCommandResult() {
return commandResult;
}
- public String getGfshOutput() {
- return gfsh.getGfshOutput();
+ public String getOutput() {
+ return output;
}
}
diff --git
a/geode-core/src/test/java/org/apache/geode/test/junit/rules/GfshParserRule.java
b/geode-core/src/test/java/org/apache/geode/test/junit/rules/GfshParserRule.java
index 9e1b220..20592be 100644
---
a/geode-core/src/test/java/org/apache/geode/test/junit/rules/GfshParserRule.java
+++
b/geode-core/src/test/java/org/apache/geode/test/junit/rules/GfshParserRule.java
@@ -34,6 +34,7 @@ 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;
import org.apache.geode.management.internal.cli.result.ResultBuilder;
+import org.apache.geode.test.junit.assertions.CommandResultAssert;
public class GfshParserRule extends ExternalResource {
@@ -81,6 +82,11 @@ public class GfshParserRule extends ExternalResource {
parseResult.getArguments());
}
+ public <T> CommandResultAssert executeAndAssertThat(T instance, String
command) {
+ CommandResult result = executeCommandWithInstance(instance, command);
+ return new CommandResultAssert(result);
+ }
+
public CommandCandidate complete(String command) {
List<Completion> candidates = new ArrayList<>();
int cursor = parser.completeAdvanced(command, command.length(),
candidates);
diff --git
a/geode-core/src/test/java/org/apache/geode/test/junit/rules/GfshShellConnectionRule.java
b/geode-core/src/test/java/org/apache/geode/test/junit/rules/GfshShellConnectionRule.java
index 6f8de9b..1b09cb9 100644
---
a/geode-core/src/test/java/org/apache/geode/test/junit/rules/GfshShellConnectionRule.java
+++
b/geode-core/src/test/java/org/apache/geode/test/junit/rules/GfshShellConnectionRule.java
@@ -34,7 +34,7 @@ import
org.apache.geode.management.internal.cli.result.CommandResult;
import org.apache.geode.management.internal.cli.shell.Gfsh;
import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
import org.apache.geode.test.dunit.IgnoredException;
-import org.apache.geode.test.junit.assertions.GfshShellConnectionRuleAssert;
+import org.apache.geode.test.junit.assertions.CommandResultAssert;
/**
* Class which eases the connection to the locator/jmxManager in Gfsh shell
and execute gfsh
@@ -238,9 +238,9 @@ public class GfshShellConnectionRule extends
DescribedExternalResource {
return result;
}
- public GfshShellConnectionRuleAssert executeAndAssertThat(String command) {
+ public CommandResultAssert executeAndAssertThat(String command) {
CommandResult commandResult = executeCommand(command);
- return new GfshShellConnectionRuleAssert(this, commandResult);
+ return new CommandResultAssert(gfsh.outputString, commandResult);
}
diff --git
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java
index 2aa3804..e87ed02 100755
---
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java
+++
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java
@@ -59,7 +59,7 @@ import
org.apache.geode.management.internal.cli.result.CommandResult;
import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
import org.apache.geode.test.dunit.rules.MemberVM;
-import org.apache.geode.test.junit.assertions.GfshShellConnectionRuleAssert;
+import org.apache.geode.test.junit.assertions.CommandResultAssert;
import org.apache.geode.test.junit.categories.DistributedTest;
import org.apache.geode.test.junit.rules.GfshShellConnectionRule;
import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
@@ -461,8 +461,7 @@ public class LuceneIndexCommandsDUnitTest implements
Serializable {
csb.addOption(LuceneCliStrings.LUCENE_SEARCH_INDEX__QUERY_STRING,
"field1:jon~");
csb.addOption(LuceneCliStrings.LUCENE_SEARCH_INDEX__DEFAULT_FIELD,
"field1");
- GfshShellConnectionRuleAssert assertion =
- gfsh.executeAndAssertThat(csb.toString()).statusIsSuccess();
+ CommandResultAssert assertion =
gfsh.executeAndAssertThat(csb.toString()).statusIsSuccess();
try {
assertion.tableHasColumnWithExactValuesInExactOrder("key", "A", "B",
"C", "D");
--
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].