Examples of JLineShellComponent


Examples of org.springframework.shell.core.JLineShellComponent

    return new DefaultHistoryFileNameProvider();
  }

  @Bean(name = "shell")
  JLineShellComponent shell() {
    return new JLineShellComponent();
  }
View Full Code Here

Examples of org.springframework.shell.core.JLineShellComponent

  }

  @Test
  public void testShellWithCredentials() throws Exception {
    Bootstrap bootstrap = new Bootstrap();
    JLineShellComponent shell = bootstrap.getJLineShellComponent();
    CommandResult commandResult = shell.executeCommand("admin config server --uri http://localhost:" + adminPort + " --username admin --password whosThere");
    assertThat(commandResult.isSuccess(), is(true));
    commandResult = shell.executeCommand("module list");
    assertThat(commandResult.isSuccess(), is(true));
    assertThat(commandResult.getResult(), instanceOf(Table.class));
    assertThat(((Table) commandResult.getResult()).getHeaders().size(), greaterThan(0));
  }
View Full Code Here

Examples of org.springframework.shell.core.JLineShellComponent

    try {
      // Simulate user input by replacing the system input stream
      SimulatedInputStream simulatedInputStream = new SimulatedInputStream("whosThere\n");
      System.setIn(simulatedInputStream);
      Bootstrap bootstrap = new Bootstrap();
      JLineShellComponent shell = bootstrap.getJLineShellComponent();
      assertThat(simulatedInputStream.isReadPerformed(), is(false));
      assertThat(simulatedInputStream.hasUnreadData(), is(true));
      CommandResult commandResult = shell.executeCommand("admin config server --uri http://localhost:" + adminPort + " --username admin --password");
      assertThat(simulatedInputStream.isReadPerformed(), is(true));
      assertThat(simulatedInputStream.hasUnreadData(), is(false));
      assertThat(commandResult.isSuccess(), is(true));
      commandResult = shell.executeCommand("module list");
      assertThat(commandResult.isSuccess(), is(true));
      assertThat(commandResult.getResult(), instanceOf(Table.class));
      assertThat(((Table) commandResult.getResult()).getHeaders().size(), greaterThan(0));
    }
    finally {
View Full Code Here

Examples of org.springframework.shell.core.JLineShellComponent

    try {
      // Simulate user input by replacing the system input stream
      SimulatedInputStream simulatedInputStream = new SimulatedInputStream("aWrongPassword\n");
      System.setIn(simulatedInputStream);
      Bootstrap bootstrap = new Bootstrap();
      JLineShellComponent shell = bootstrap.getJLineShellComponent();
      assertThat(simulatedInputStream.isReadPerformed(), is(false));
      assertThat(simulatedInputStream.hasUnreadData(), is(true));
      CommandResult commandResult = shell.executeCommand("admin config server --uri http://localhost:" + adminPort + " --username admin --password");
      assertThat(simulatedInputStream.isReadPerformed(), is(true));
      assertThat(simulatedInputStream.hasUnreadData(), is(false));
      assertThat(commandResult.isSuccess(), is(true));
      Configuration configuration = bootstrap.getApplicationContext().getBean(Configuration.class);
      assertThat(configuration.getTarget().getTargetException(), instanceOf(HttpClientErrorException.class));
      assertThat(((HttpClientErrorException) configuration.getTarget().getTargetException()).getStatusCode(), equalTo(HttpStatus.UNAUTHORIZED));
      commandResult = shell.executeCommand("module list");
      assertThat(commandResult.isSuccess(), is(false));
    }
    finally {
      // restore the system input stream
      System.setIn(System.in);
View Full Code Here

Examples of org.springframework.shell.core.JLineShellComponent

    try {
      // Simulate user input by replacing the system input stream
      SimulatedInputStream simulatedInputStream = new SimulatedInputStream("whosThere\n");
      System.setIn(simulatedInputStream);
      Bootstrap bootstrap = new Bootstrap();
      JLineShellComponent shell = bootstrap.getJLineShellComponent();
      assertThat(simulatedInputStream.isReadPerformed(), is(false));
      assertThat(simulatedInputStream.hasUnreadData(), is(true));
      CommandResult commandResult = shell.executeCommand("admin config server --uri http://localhost:" + adminPort + " --username admin");
      assertThat(simulatedInputStream.isReadPerformed(), is(false)); // without the --password flag, the shell doesn't prompt and doesn't read from input
      assertThat(simulatedInputStream.hasUnreadData(), is(true));
      assertThat(commandResult.isSuccess(), is(true));
      Configuration configuration = bootstrap.getApplicationContext().getBean(Configuration.class);
      assertThat(configuration.getTarget().getTargetException(), instanceOf(HttpClientErrorException.class));
      assertThat(((HttpClientErrorException) configuration.getTarget().getTargetException()).getStatusCode(), equalTo(HttpStatus.UNAUTHORIZED));
      commandResult = shell.executeCommand("module list");
      assertThat(commandResult.isSuccess(), is(false));
    }
    finally {
      // restore the system input stream
      System.setIn(System.in);
View Full Code Here

Examples of org.springframework.shell.core.JLineShellComponent

  }

  @Test
  public void testShellWithWrongCredentials() throws Exception {
    Bootstrap bootstrap = new Bootstrap();
    JLineShellComponent shell = bootstrap.getJLineShellComponent();
    CommandResult commandResult = shell.executeCommand("admin config server --uri http://localhost:" + adminPort + " --username admin --password whosThere2");
    assertThat(commandResult.isSuccess(), is(true));
    Configuration configuration = bootstrap.getApplicationContext().getBean(Configuration.class);
    assertThat(configuration.getTarget().getTargetException(), instanceOf(HttpClientErrorException.class));
    assertThat(((HttpClientErrorException) configuration.getTarget().getTargetException()).getStatusCode(), equalTo(HttpStatus.UNAUTHORIZED));
    commandResult = shell.executeCommand("module list");
    assertThat(commandResult.isSuccess(), is(false));
  }
View Full Code Here

Examples of org.springframework.shell.core.JLineShellComponent

  }

  @Test
  public void testShellWithMissingUsername() throws Exception {
    Bootstrap bootstrap = new Bootstrap();
    JLineShellComponent shell = bootstrap.getJLineShellComponent();
    CommandResult commandResult = shell.executeCommand("admin config server --uri http://localhost:" + adminPort + " --password whosThere");
    assertThat(commandResult.isSuccess(), is(true));
    Configuration configuration = bootstrap.getApplicationContext().getBean(Configuration.class);
    assertThat(configuration.getTarget().getTargetException(), instanceOf(IllegalArgumentException.class));
    assertThat(configuration.getTarget().getTargetException().getMessage(), equalTo("A password may be specified only together with a user name"));
    commandResult = shell.executeCommand("module list");
    assertThat(commandResult.isSuccess(), is(false));
  }
View Full Code Here

Examples of org.springframework.shell.core.JLineShellComponent

  @Test
  public void testSimple() {
    Bootstrap bootstrap = new Bootstrap();
   
    JLineShellComponent shell = bootstrap.getJLineShellComponent();
   
    CommandResult cr = shell.executeCommand("hw simple --message hello");
    assertEquals(true, cr.isSuccess());
    assertEquals("Message = [hello] Location = [null]", cr.getResult());
  }
View Full Code Here

Examples of org.springframework.shell.core.JLineShellComponent

  @Test
  public void test() throws IOException {
    try {
      Bootstrap bootstrap = new Bootstrap(null);
      JLineShellComponent shell = bootstrap.getJLineShellComponent();
     
      //This is a brittle assertion - as additiona 'test' commands are added to the suite, this number will increase.
      Assert.assertEquals("Number of CommandMarkers is incorrect", 10, shell.getSimpleParser().getCommandMarkers().size());
      Assert.assertEquals("Number of Converters is incorrect", 16, shell.getSimpleParser().getConverters().size());     
    } catch (RuntimeException t) {
      throw t;
    } finally {
      HandlerUtils.flushAllHandlers(Logger.getLogger(""));
    }
View Full Code Here

Examples of org.springframework.shell.core.JLineShellComponent

  @CliCommand(value = "help", help = "List all commands usage")
  public void obtainHelp(
      @CliOption(key = { "", "command" }, optionContext = "disable-string-converter availableCommands", help = "Command name to provide help for")
      String buffer) {
    JLineShellComponent shell = ctx.getBean("shell", JLineShellComponent.class);
    SimpleParser parser = shell.getSimpleParser();
    parser.obtainHelp(buffer);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.