Package org.springframework.shell.core

Examples of org.springframework.shell.core.CommandResult


      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 {
      // restore the system input stream
      System.setIn(System.in);
    }
View Full Code Here


      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

      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

  @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

  @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

        "http post --target http://" + host + ":%d --data \"%s\"",
        port, payload.replace("\"", "\\\""));
    if (contentType != null) {
      command += String.format(" --contentType \"%s\"", contentType);
    }
    CommandResult result = shell.executeCommand(command);
    Assert.isTrue(result.isSuccess(), "http post failed. Command result: " + result.getException());
    return this;
  }
View Full Code Here

        "http post --target http://localhost:%d --file \"%s\"",
        port, file.getAbsolutePath());
    if (contentType != null) {
      command += String.format(" --contentType \"%s\"", contentType);
    }
    CommandResult result = shell.executeCommand(command);
    Assert.isTrue(result.isSuccess());
    return this;
  }
View Full Code Here

  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

 
  @Test
  public void dateTest() throws ParseException {
   
    //Execute command
    CommandResult cr = getShell().executeCommand("date");
   
    //Get result  
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, Locale.getDefault());
    Date result = df.parse(cr.getResult().toString());
   
    //Make assertions
    Date now = new Date();
    MatcherAssert.assertThat(now, DateMatchers.within(5, TimeUnit.SECONDS, result));   
  }
View Full Code Here

TOP

Related Classes of org.springframework.shell.core.CommandResult

Copyright © 2018 www.massapicom. 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.