Search in sources :

Example 6 with MockCommandContext

use of org.jboss.as.cli.completion.mock.MockCommandContext in project wildfly-core by wildfly.

the class ParameterValueResolutionTestCase method testPropertyList_SimpleCommaSeparated.

@Test
public void testPropertyList_SimpleCommaSeparated() throws Exception {
    final CommandContext ctx = new MockCommandContext();
    ctx.setResolveParameterValues(true);
    final ModelNode value = parseProperties(ctx, "${cli.test.prop1}=${cli.test.prop2},${cli.test.prop3}=${cli.test.prop4}");
    assertNotNull(value);
    assertEquals(ModelType.LIST, value.getType());
    final List<Property> list = value.asPropertyList();
    assertEquals(2, list.size());
    Property prop = list.get(0);
    assertNotNull(prop);
    assertEquals("one", prop.getName());
    assertEquals("two", prop.getValue().asString());
    prop = list.get(1);
    assertNotNull(prop);
    assertEquals("three", prop.getName());
    assertEquals("four", prop.getValue().asString());
}
Also used : MockCommandContext(org.jboss.as.cli.completion.mock.MockCommandContext) CommandContext(org.jboss.as.cli.CommandContext) MockCommandContext(org.jboss.as.cli.completion.mock.MockCommandContext) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property) Test(org.junit.Test)

Example 7 with MockCommandContext

use of org.jboss.as.cli.completion.mock.MockCommandContext in project wildfly-core by wildfly.

the class IfExpressionParsingTestCase method setup.

@BeforeClass
public static void setup() throws Exception {
    CTX = new MockCommandContext();
    ADDRESS = new DefaultOperationRequestAddress();
    LINE = new DefaultCallbackHandler();
    final IfHandler ifHandler = new IfHandler();
    CONDITION = ifHandler.getConditionArgument();
}
Also used : IfHandler(org.jboss.as.cli.handlers.ifelse.IfHandler) DefaultOperationRequestAddress(org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress) MockCommandContext(org.jboss.as.cli.completion.mock.MockCommandContext) DefaultCallbackHandler(org.jboss.as.cli.operation.impl.DefaultCallbackHandler) BeforeClass(org.junit.BeforeClass)

Example 8 with MockCommandContext

use of org.jboss.as.cli.completion.mock.MockCommandContext in project wildfly-core by wildfly.

the class DefaultOperationCandidatesProviderTestCase method testGetPropertiesFromPropList.

@Test
public void testGetPropertiesFromPropList() throws Exception {
    List<Property> propList = new ArrayList<>();
    propList.add(new Property("blocking", ModelNode.fromString(list_content)));
    propList.add(new Property("blocking-param", ModelNode.fromString(list_content)));
    propList.add(new Property("start-mode", ModelNode.fromString(list_content)));
    MockCommandContext ctx = new MockCommandContext();
    String operationName = "operationName";
    ctx.parseCommandLine(":" + operationName + "(!blocking", false);
    DefaultOperationRequestAddress address = new DefaultOperationRequestAddress();
    DefaultOperationCandidatesProvider candidatesProvider = new DefaultOperationCandidatesProvider();
    List<CommandArgument> candidates = candidatesProvider.getPropertiesFromPropList(propList, ctx, operationName, address);
    assertEquals(propList.size(), candidates.size());
    for (CommandArgument candidate : candidates) {
        if (candidate.getFullName().equals("blocking"))
            assertFalse("Property blocking can't appear next, since it's completely specified" + " on the commandline as !blocking", candidate.canAppearNext(ctx));
        else
            assertTrue(candidate.canAppearNext(ctx));
    }
}
Also used : CommandArgument(org.jboss.as.cli.CommandArgument) ArrayList(java.util.ArrayList) MockCommandContext(org.jboss.as.cli.completion.mock.MockCommandContext) Property(org.jboss.dmr.Property) Test(org.junit.Test)

Example 9 with MockCommandContext

use of org.jboss.as.cli.completion.mock.MockCommandContext in project wildfly-core by wildfly.

the class AbstractAddressCompleterTest method init.

protected void init() {
    ctx = new MockCommandContext();
    ctx.setOperationCandidatesProvider(new MockOperationCandidatesProvider(root));
    completer = new OperationRequestCompleter();
}
Also used : MockOperationCandidatesProvider(org.jboss.as.cli.completion.mock.MockOperationCandidatesProvider) MockCommandContext(org.jboss.as.cli.completion.mock.MockCommandContext) OperationRequestCompleter(org.jboss.as.cli.operation.OperationRequestCompleter)

Example 10 with MockCommandContext

use of org.jboss.as.cli.completion.mock.MockCommandContext in project wildfly-core by wildfly.

the class OperationParsingTestCase method testDMREqualsAsParamEquals.

@Test
public void testDMREqualsAsParamEquals() throws Exception {
    DefaultCallbackHandler handler = new DefaultCallbackHandler();
    parse(":add(keystore=>{password=1234test,url=/Users/xxx/clientcert.jks})", handler);
    assertFalse(handler.hasAddress());
    assertTrue(handler.hasOperationName());
    assertTrue(handler.hasProperties());
    assertFalse(handler.endsOnAddressOperationNameSeparator());
    assertFalse(handler.endsOnPropertyListStart());
    assertFalse(handler.endsOnPropertySeparator());
    assertFalse(handler.endsOnPropertyValueSeparator());
    assertFalse(handler.endsOnNodeSeparator());
    assertFalse(handler.endsOnNodeTypeNameSeparator());
    assertFalse(handler.isRequestComplete());
    assertEquals("add", handler.getOperationName());
    Set<String> args = handler.getPropertyNames();
    assertEquals(1, args.size());
    assertTrue(args.contains("keystore"));
    assertEquals(">{password=1234test,url=/Users/xxx/clientcert.jks}", handler.getPropertyValue("keystore"));
    final ModelNode request = handler.toOperationRequest(new MockCommandContext());
    final ModelNode keystoreDmr = request.get("keystore");
    assertTrue(keystoreDmr.isDefined());
    assertEquals(ModelType.OBJECT, keystoreDmr.getType());
    final Set<String> props = keystoreDmr.keys();
    assertEquals(2, props.size());
    // this name is not alphanumeric but it's still a value of the CLI operation parameter
    // and the CLI at the moment does not attempt to validate values
    assertTrue(props.contains(">{password"));
    assertTrue(props.contains("url"));
    assertEquals("1234test", keystoreDmr.get(">{password").asString());
    assertEquals("/Users/xxx/clientcert.jks}", keystoreDmr.get("url").asString());
}
Also used : MockCommandContext(org.jboss.as.cli.completion.mock.MockCommandContext) DefaultCallbackHandler(org.jboss.as.cli.operation.impl.DefaultCallbackHandler) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Aggregations

MockCommandContext (org.jboss.as.cli.completion.mock.MockCommandContext)13 Test (org.junit.Test)11 ModelNode (org.jboss.dmr.ModelNode)10 CommandContext (org.jboss.as.cli.CommandContext)9 Property (org.jboss.dmr.Property)3 DefaultCallbackHandler (org.jboss.as.cli.operation.impl.DefaultCallbackHandler)2 ArrayList (java.util.ArrayList)1 CommandArgument (org.jboss.as.cli.CommandArgument)1 MockOperationCandidatesProvider (org.jboss.as.cli.completion.mock.MockOperationCandidatesProvider)1 IfHandler (org.jboss.as.cli.handlers.ifelse.IfHandler)1 OperationRequestCompleter (org.jboss.as.cli.operation.OperationRequestCompleter)1 DefaultOperationRequestAddress (org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress)1 BeforeClass (org.junit.BeforeClass)1