Skip to content

Commit

Permalink
Merge pull request #3654 from jfdenise/master
Browse files Browse the repository at this point in the history
CLI, fix for WFCORE-1478 and WFCORE-1698
  • Loading branch information
jmesnil authored Feb 6, 2019
2 parents 2da5180 + 0852c69 commit 249e175
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,17 @@ public abstract class BaseOperationCommand extends CommandHandlerWithHelp implem
protected AccessRequirement accessRequirement;

public BaseOperationCommand(CommandContext ctx, String command, boolean connectionRequired) {
this(ctx, command, connectionRequired, true);
}

public BaseOperationCommand(CommandContext ctx, String command, boolean connectionRequired, boolean needHeaders) {
super(command, connectionRequired);
ctx.addEventListener(this);
headers = new ArgumentWithValue(this, HeadersCompleter.INSTANCE, HeadersArgumentValueConverter.INSTANCE, "--headers");
if (needHeaders) {
headers = new ArgumentWithValue(this, HeadersCompleter.INSTANCE, HeadersArgumentValueConverter.INSTANCE, "--headers");
} else {
headers = null;
}
accessRequirement = setupAccessRequirement(ctx);
}

Expand Down Expand Up @@ -272,7 +280,7 @@ protected ModelNode buildRequestWOValidation(CommandContext ctx) throws CommandF
protected abstract ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws CommandFormatException;

protected void addHeaders(CommandContext ctx, ModelNode request) throws CommandFormatException {
if(!headers.isPresent(ctx.getParsedCommandLine())) {
if(headers == null || !headers.isPresent(ctx.getParsedCommandLine())) {
return;
}
final ModelNode headersNode = headers.toModelNode(ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class ShutdownHandler extends BaseOperationCommand {
private PerNodeOperationAccess hostShutdownPermission;

public ShutdownHandler(CommandContext ctx, final AtomicReference<EmbeddedProcessLaunch> embeddedServerRef) {
super(ctx, "shutdown", true);
super(ctx, "shutdown", true, false);

this.embeddedServerRef = embeddedServerRef;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void appendPath(OperationRequestAddress path) {
nodes = new ArrayList<NodeImpl>(path.length());
}
for(Node n : path) {
nodes.add(new NodeImpl(n.getType(), n.getType()));
nodes.add(new NodeImpl(n.getType(), n.getName()));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.cli.handlers;

import java.util.concurrent.atomic.AtomicReference;
import org.jboss.as.cli.CliInitializationException;
import org.jboss.as.cli.CommandContext;
import org.jboss.as.cli.CommandContextFactory;
import org.jboss.as.cli.embedded.EmbeddedProcessLaunch;
import static org.junit.Assert.assertEquals;
import org.junit.Test;

/**
*
* @author [email protected]
*/
public class ShutdownHandlerTestCase {
@Test
public void test() throws CliInitializationException {
CommandContext ctx = CommandContextFactory.getInstance().newCommandContext();
ShutdownHandler handler = new ShutdownHandler(ctx, new AtomicReference<EmbeddedProcessLaunch>());
assertEquals(null, handler.getArgument(ctx, "--headers"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.cli.operation.impl;

import org.junit.Assert;
import org.junit.Test;

/**
*
* @author [email protected]
*/
public class DefaultOperationRequestAddressTestCase {
@Test
public void test() {
DefaultOperationRequestAddress expected = new DefaultOperationRequestAddress();
expected.toNode("org", "foo");
expected.toNode("my", "node");
DefaultOperationRequestAddress addr = new DefaultOperationRequestAddress();
addr.toNode("org", "foo");
DefaultOperationRequestAddress addr2 = new DefaultOperationRequestAddress();
addr2.toNode("my", "node");
addr.appendPath(addr2);
Assert.assertEquals(expected, addr);
}
}

0 comments on commit 249e175

Please sign in to comment.