Skip to content

Commit

Permalink
WFCORE-5247 IllegalArgumentException and CLI crash with read-attribut…
Browse files Browse the repository at this point in the history
…e in /system-property
  • Loading branch information
parsharma committed Feb 1, 2021
1 parent 7617b8a commit 1aea910
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 19 deletions.
Expand Up @@ -116,8 +116,12 @@ public boolean canAppearNext(CommandContext ctx) throws CommandFormatException {
op.get(Util.ADDRESS).setEmptyList();
} else {
final ModelNode addrNode = op.get(Util.ADDRESS);
for(OperationRequestAddress.Node node : address) {
addrNode.add(node.getType(), node.getName());
for (OperationRequestAddress.Node node : address) {
if (node.getName() == null) {
addrNode.add(node.getType(), "*");
} else {
addrNode.add(node.getType(), node.getName());
}
}
}

Expand Down Expand Up @@ -219,6 +223,7 @@ public ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws CommandFo
return req;
}

@Override
protected void handleResponse(CommandContext ctx, ModelNode response, boolean composite) throws CommandFormatException {
if (!Util.isSuccess(response)) {
throw new CommandFormatException(Util.getFailureDescription(response));
Expand Down
Expand Up @@ -22,32 +22,20 @@
*/
package org.jboss.as.test.integration.management.cli;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.aesh.complete.AeshCompleteOperation;
import org.aesh.readline.completion.Completion;
import org.aesh.readline.terminal.formatting.TerminalString;
import org.hamcrest.CoreMatchers;
import org.jboss.as.cli.CommandContext;
import org.jboss.as.cli.CommandLineException;
import org.jboss.as.cli.Util;
import org.jboss.as.test.integration.management.util.CLITestUtil;
import org.jboss.as.test.shared.TestSuiteEnvironment;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;


import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
Expand All @@ -56,6 +44,18 @@
import org.junit.runner.RunWith;
import org.wildfly.core.testrunner.WildflyTestRunner;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;


/**
*
* @author jdenise@redhat.com
Expand Down Expand Up @@ -118,7 +118,54 @@ public void complexOperationWithObjectAsAttributeTest() {
assertEquals(candidates.toString(), Arrays.asList(","), candidates);
}
}
/**
* Checks CLI completion for "read-attribute " command
*/
@Test
public void readAttributeWithSpaceTest() {
for (List<String> candidates : getCandidatesLists("read-attribute ", null)) {
assertTrue(candidates.contains("--resolve-expressions"));
assertTrue(candidates.contains("management-major-version"));
assertFalse(candidates.contains("--admin-only"));
}
}
/**
* Checks CLI completion for "read-a" command
*/
@Test
public void readAttributeWithUnfinishedCmdTest() {
for (List<String> candidates : getCandidatesLists("read-a", true)) {
assertTrue(candidates.contains("read-attribute"));
}
}
/**
* Checks CLI completion for "read-attribute --" command
*/
@Test
public void readAttributeWithUnfinishedArgumentTest() {
for (List<String> candidates : getCandidatesLists("read-attribute --", false)) {
assertTrue(candidates.contains("--resolve-expressions"));
assertTrue(candidates.contains("--verbose"));
}
}

@Test
public void readAttributeAfterSystemPropertyTest() throws CommandLineException {
CommandContext ctx = CLITestUtil
.getCommandContext(TestSuiteEnvironment.getServerAddress(), TestSuiteEnvironment.getServerPort(), System.in,
System.out);
ctx.connectController();
ctx.handle("cd /system-property");
try {
String cmd = "read-attribute ";
List candidates = new ArrayList<>();
ctx.getDefaultCommandCompleter().complete(ctx, cmd, cmd.length(), candidates);
candidates = complete(ctx, cmd, null);
assertTrue(candidates.contains("--verbose"));
} finally {
ctx.terminateSession();
}
}
/**
* Checks CLI completion for "help" command
*/
Expand Down

0 comments on commit 1aea910

Please sign in to comment.