Java Code Examples for org.jboss.forge.addon.ui.controller.CommandController#execute()

The following examples show how to use org.jboss.forge.addon.ui.controller.CommandController#execute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NewComponentInstanceTest.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
@Test
public void testSomething() throws Exception {
    File tempDir = OperatingSystemUtils.createTempDir();
    try {
        Project project = projectFactory.createTempProject();
        Assert.assertNotNull("Should have created a project", project);

        CommandController command = testHarness.createCommandController(CamelSetupCommand.class, project.getRoot());
        command.initialize();
        command.setValueFor("kind", "camel-spring");

        Result result = command.execute();
        Assert.assertFalse("Should setup Camel in the project", result instanceof Failed);

        command = testHarness.createCommandController(CamelGetComponentsCommand.class, project.getRoot());
        command.initialize();

        result = command.execute();
        Assert.assertFalse("Should not fail", result instanceof Failed);

        String message = result.getMessage();
        System.out.println(message);
    } finally {
        tempDir.delete();
    }
}
 
Example 2
Source File: NewNodeXmlTest.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
protected List<ContextDto> getRoutesXml(Project project) throws Exception {
    CommandController command = testHarness.createCommandController(CamelGetRoutesXmlCommand.class, project.getRoot());
    command.initialize();
    command.setValueFor("format", "JSON");

    Result result = command.execute();
    assertFalse("Should not fail", result instanceof Failed);

    String message = result.getMessage();

    System.out.println();
    System.out.println();
    System.out.println("JSON: " + message);
    System.out.println();

    List<ContextDto> answer = NodeDtos.parseContexts(message);
    System.out.println();
    System.out.println();
    List<NodeDto> nodeList = NodeDtos.toNodeList(answer);
    for (NodeDto node : nodeList) {
        System.out.println(node.getLabel());
    }
    System.out.println();
    return answer;
}
 
Example 3
Source File: ProjectGenerator.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
protected void useCommand(RestUIContext context, String commandName, boolean shouldExecute) {
    try {
        UICommand command = commandFactory.getCommandByName(context, commandName);
        if (command == null) {
            LOG.warn("No such command! '" + commandName + "'");
            return;
        }
        CommandController controller = commandControllerFactory.createController(context, runtime, command);
        if (controller == null) {
            LOG.warn("No such controller! '" + commandName + "'");
            return;
        }
        controller.initialize();
        WizardCommandController wizardCommandController = assertWizardController(controller);

        Map<String, InputComponent<?, ?>> inputs = controller.getInputs();
        Set<Map.Entry<String, InputComponent<?, ?>>> entries = inputs.entrySet();
        for (Map.Entry<String, InputComponent<?, ?>> entry : entries) {
            String key = entry.getKey();
            InputComponent component = entry.getValue();
            Object value = InputComponents.getValueFor(component);
            Object completions = null;
            UICompleter<?> completer = InputComponents.getCompleterFor(component);
            if (completer != null) {
                completions = completer.getCompletionProposals(context, component, "");
            }
            LOG.info(key + " = " + component + " value: " + value + " completions: " + completions);
        }
        validate(controller);
        wizardCommandController = wizardCommandController.next();

        if (shouldExecute) {
            Result result = controller.execute();
            printResult(result);
        }
    } catch (Exception e) {
        LOG.error("Failed to create the " + commandName + " controller! " + e, e);
    }
}
 
Example 4
Source File: NewNodeXmlTest.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
protected static void assertValidAndExecutes(CommandController command) throws Exception {
    List<UIMessage> validate = command.validate();
    for (UIMessage uiMessage : validate) {
        System.out.println("Invalid value of input: " + uiMessage.getSource().getName() + " message: " + uiMessage.getDescription());
    }
    Result result = command.execute();
    String message = result.getMessage();
    assertFalse("Should not fail: " + message, result instanceof Failed);

    System.out.println(message);
}