/** * Verifies that gfsh executed with status ERROR */ public CommandResultAssert statusIsError() { CommandResult result = actual.getCommandResult(); Assertions.assertThat(result.getStatus()).describedAs(actual.getOutput()) .isEqualTo(Result.Status.ERROR); return this; }
@Test public void testCannotDestroyIndexWithNoOptions() throws Exception { // Destroy index with no option CommandStringBuilder csb = new CommandStringBuilder(CliStrings.DESTROY_INDEX); CommandResult result = gfsh.executeCommand(csb.toString()); assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR); assertThat(gfsh.getGfshOutput()).contains("requires that one or more parameters be provided."); }
@Test public void testCannotCreateIndexWithInvalidIndexExpression() throws Exception { // Create index with wrong expression CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_INDEX); csb.addOption(CliStrings.CREATE_INDEX__NAME, indexName); csb.addOption(CliStrings.CREATE_INDEX__EXPRESSION, "InvalidExpressionOption"); csb.addOption(CliStrings.CREATE_INDEX__REGION, "/" + regionName); csb.addOption(CliStrings.CREATE_INDEX__TYPE, "hash"); CommandResult result = gfsh.executeCommand(csb.toString()); assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR); }
@Test public void noMemberFound() throws Exception { doReturn(Collections.EMPTY_SET).when(command).findMembers(any(), any()); result = gfshParser.executeCommandWithInstance(command, "create index --name=abc --expression=abc --region=abc"); assertThat(result.getStatus()).isEqualTo(ERROR); assertThat(result.getMessageFromContent()).contains("No Members Found"); }
@Test public void validIndexType2() throws Exception { doReturn(Collections.EMPTY_SET).when(command).findMembers(any(), any()); result = gfshParser.executeCommandWithInstance(command, "create index --name=abc --expression=abc --region=abc --type=hash"); assertThat(result.getStatus()).isEqualTo(ERROR); assertThat(result.getMessageFromContent()).contains("No Members Found"); }
@Test public void errorCodeCorrectlyUpdated() { String json = "{\"contentType\":\"table\",\"data\":{\"content\":{\"Member\":[\"server\"],\"Status\":[\"ERROR: Bad.\"]},\"footer\":\"\",\"header\":\"\",\"type-class\":\"org.apache.geode.management.internal.cli.CommandResponse.Data\"},\"debugInfo\":\"\",\"failedToPersist\":false,\"fileToDownload\":null,\"page\":\"1/1\",\"sender\":\"server\",\"status\":-1,\"tokenAccessor\":\"__NULL__\",\"type-class\":\"org.apache.geode.management.internal.cli.CommandResponse\",\"version\":\"1.3.0-SNAPSHOT\",\"when\":\"10/17/17 8:17 AM\"}"; CommandResult result = ResultBuilder.fromJson(json); assertThat(result.getStatus().getCode()).isEqualTo(-1); } }
@Test public void connectToManagerWithNoPatchVersion() { when(gfsh.getVersion()).thenReturn("1.5.1"); when(operationInvoker.getRemoteVersion()).thenReturn("1.5"); when(operationInvoker.isConnected()).thenReturn(true); when(result.getStatus()).thenReturn(Result.Status.OK); gfshParserRule.executeAndAssertThat(connectCommand, "connect --locator=localhost:4040") .statusIsSuccess(); }
@Test public void missingBothTypeAndUseAttributeFrom() throws Exception { CommandResult result = parser.executeCommandWithInstance(command, "create region --name=region"); assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR); assertThat(result.getMessageFromContent()) .contains("One of \"type\" or \"template-region\" is required."); }
@Test public void invalidEvictionAttributes() throws Exception { CommandResult result = parser.executeCommandWithInstance(command, "create region --name=region --type=REPLICATE --eviction-max-memory=1000 --eviction-entry-count=200"); assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR); assertThat(result.getMessageFromContent()) .contains("eviction-max-memory and eviction-entry-count cannot both be specified."); }
@Test public void invalidEvictionSizerAndCount() throws Exception { CommandResult result = parser.executeCommandWithInstance(command, "create region --name=region --type=REPLICATE --eviction-entry-count=1 --eviction-object-sizer=abc --eviction-action=local-destroy"); assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR); assertThat(result.getMessageFromContent()) .contains("eviction-object-sizer cannot be specified with eviction-entry-count"); }
@Test public void noDefinitions() throws Exception { result = gfshParser.executeCommandWithInstance(command, "create defined indexes"); assertThat(result.getStatus()).isEqualTo(OK); assertThat(result.getMessageFromContent()).contains("No indexes defined"); }
@Test public void invalidPortNumber() throws Exception { ShowMetricsCommand command = spy(ShowMetricsCommand.class); CommandResult result = parser.executeCommandWithInstance(command, "show metrics --port=abc"); assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR); // When relying on Spring's converters, any command that does not parse is "Invalid" assertThat(result.getMessageFromContent()).contains("Invalid command"); } }
@Test public void connectToAValidManager() { when(gfsh.getVersion()).thenReturn("1.5"); when(operationInvoker.getRemoteVersion()).thenReturn("1.5"); when(operationInvoker.isConnected()).thenReturn(true); when(result.getStatus()).thenReturn(Result.Status.OK); gfshParserRule.executeAndAssertThat(connectCommand, "connect --locator=localhost:4040") .statusIsSuccess(); } }
@Test public void noMembers() throws Exception { IndexDefinition.addIndex("indexName", "indexedExpression", "TestRegion", IndexType.FUNCTIONAL); doReturn(Collections.EMPTY_SET).when(command).findMembers(any(), any()); result = gfshParser.executeCommandWithInstance(command, "create defined indexes"); assertThat(result.getStatus()).isEqualTo(ERROR); assertThat(result.getMessageFromContent()).contains("No Members Found"); }
@Test public void invalidKeyType() throws Exception { CommandResult result = parser.executeCommandWithInstance(command, "create region --name=region --type=REPLICATE --key-type=abc-def"); assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR); assertThat(result.getMessageFromContent()).contains("Invalid command"); }
@Test public void invalidValueType() throws Exception { CommandResult result = parser.executeCommandWithInstance(command, "create region --name=region --type=REPLICATE --value-type=abc-def"); assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR); assertThat(result.getMessageFromContent()).contains("Invalid command"); }
@Test public void invalidEvictionAction() throws Exception { CommandResult result = parser.executeCommandWithInstance(command, "create region --name=region --type=REPLICATE --eviction-action=invalidAction"); assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR); assertThat(result.getMessageFromContent()) .contains("eviction-action must be 'local-destroy' or 'overflow-to-disk'"); }
@Test public void invalidCompressor() throws Exception { CommandResult result = parser.executeCommandWithInstance(command, "create region --name=region --type=REPLICATE --compressor=abc-def"); assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR); assertThat(result.getMessageFromContent()).contains("abc-def is an invalid Compressor."); }
@Test public void missingRegion() throws Exception { result = gfshParser.executeCommandWithInstance(command, "create index --name=abc --expression=abc"); assertThat(result.getStatus()).isEqualTo(ERROR); assertThat(result.getMessageFromContent()).contains("Invalid command"); }
@Test public void invalidIndexType() throws Exception { result = gfshParser.executeCommandWithInstance(command, "create index --name=abc --expression=abc --region=abc --type=abc"); assertThat(result.getStatus()).isEqualTo(ERROR); assertThat(result.getMessageFromContent()).contains("Invalid command"); }