Example #1
0
  private void assertHandlesLogTruncation(XaCommand cmd) throws IOException {
    inMemoryBuffer.reset();
    cmd.writeToFile(inMemoryBuffer);

    int bytesSuccessfullyWritten = inMemoryBuffer.bytesWritten();
    assertEquals(cmd, Command.readCommand(null, null, inMemoryBuffer, ByteBuffer.allocate(100)));

    bytesSuccessfullyWritten--;

    while (bytesSuccessfullyWritten-- > 0) {
      inMemoryBuffer.reset();
      cmd.writeToFile(inMemoryBuffer);
      inMemoryBuffer.truncateTo(bytesSuccessfullyWritten);

      Command deserialized =
          Command.readCommand(null, null, inMemoryBuffer, ByteBuffer.allocate(100));

      assertNull(
          "Deserialization did not detect log truncation! Record: "
              + cmd
              + ", deserialized: "
              + deserialized,
          deserialized);
    }
  }
Example #2
0
  @Test
  public void testCommand() throws CommandException {
    CommandManager cm = new CommandManager();
    CommandSource testSource = new TestCommandSource(cm);
    Command cmd =
        cm.getCommand("test1")
            .addAlias("t1")
            .setPermission("test.1")
            .setExecutor(
                new Executor() {
                  @Override
                  public void execute(CommandSource source, Command command, CommandArguments args)
                      throws CommandException {
                    args.popString("testArg1");
                    args.popString("testArg2", "Not specified");
                    args.assertCompletelyParsed();
                  }
                });

    // execute with success
    cmd.process(testSource, "foo");
    cmd.process(testSource, "foo", "bar");

    // execute with failure
    thrown.expect(CommandException.class);
    cmd.process(testSource, "foo", "bar", "baz");
    cmd.process(testSource);
  }
Example #3
0
 @Test
 public void initialization() {
   assertThat(command.getCommandName(), is("command"));
   assertThat(command.getArgumentCount(), is(2));
   assertThat(command.getFormattedArguments().trim(), is("[arg1] [arg2]"));
   assertThat(command.getHelpText(), is("help text"));
 }
  @Test
  public void testForNonExistingRoute() throws Exception {
    String[] route = {"A", "X", "J"};
    Command cmd = new DistCommand(route);

    String expected = DistCommand.NO_SUCH_ROUTE_ERROR;
    String actual = cmd.execute(g);
    assertEquals(expected, actual);
  }
Example #5
0
 /** Tests http:send-request((),()). */
 @Test
 public void sendReqNoParams() {
   final Command cmd = new XQuery(_HTTP_SEND_REQUEST.args("()"));
   try {
     cmd.execute(ctx);
   } catch (final BaseXException ex) {
     assertTrue(ex.getMessage().contains(ErrType.HC.toString()));
   }
 }
  @Test
  public void testForExistingRoute2Nodes() throws Exception {
    String[] route = {"D", "A"};
    Command cmd = new DistCommand(route);

    String expected = "1";
    String actual = cmd.execute(g);
    assertEquals(expected, actual);
  }
Example #7
0
 @Test
 public void testParseInputToCommand13() {
   List<Double> list = new ArrayList<Double>();
   list.add(1.0);
   list.add(2.0);
   String vaildInput = "add 1 !0 2 3";
   History.addToHistory(new AddCmd(list).calculate());
   Command output = Parser.parseInputToCommand(vaildInput);
   assertEquals(AddCmd.class, output.getClass());
 }
Example #8
0
  @Test
  public void testCantProcessQweString() {
    // given
    Command command = new Exit(view);

    // when
    boolean canProcess = command.canProcess("qwe");

    // then
    assertFalse(canProcess);
  }
Example #9
0
  @Test
  public void testCanProcessExitString() {
    // given
    Command command = new Exit(view);

    // when
    boolean canProcess = command.canProcess("exit");

    // then
    assertTrue(canProcess);
  }
  @Test
  public void addCommandTest() {
    Command cmd = createMock(MoveCommand.class);
    Drone drone = Drone.getInstance();
    ThreadCmd tc = new ThreadCmd(drone);

    expect(cmd.isUnique()).andReturn(true);
    replayAll();
    tc.addCommand(cmd);
    verifyAll();
  }
Example #11
0
    @Override
    public void processCommand(String command, String... args) {
      Command cmd = cm.getCommand(command, false);
      if (cmd == null) {
        sendMessage("Unknown command: '" + command + "'.");
        return;
      }

      try {
        cmd.process(this, args);
      } catch (CommandException e) {
        throw new RuntimeException(e);
      }
    }
Example #12
0
  @Test
  public void testProcessExitCommand_thowsExitException() {
    // given
    Command command = new Exit(view);

    // when
    try {
      command.process("exit");
      fail("Expected ExitException");
    } catch (ExitException e) {
      // do nothing
    }

    // then
    Mockito.verify(view).write("До скорой встречи!");
  }
Example #13
0
 @Test
 public void testparseInputToAddSquaresCommand() {
   String validInput = "addsquares 1 2 3";
   Command cmd = Parser.parseInputToCommand(validInput);
   assertEquals(AddSquaresCmd.class, cmd.getClass());
 }
Example #14
0
 @Test
 public void testConnectionIsNeeded() {
   Command command = new Exit(view);
   assertFalse(command.needsConnection());
 }
Example #15
0
 @Test
 public void testparseInputToSubCommand() {
   String validInput = "sub 1 2 3";
   Command cmd = Parser.parseInputToCommand(validInput);
   assertEquals(SubCmd.class, cmd.getClass());
 }
Example #16
0
 @Test
 public void testparseInputToHistCommand() {
   String validInput = "hist";
   Command cmd = Parser.parseInputToCommand(validInput);
   assertEquals(HistCmd.class, cmd.getClass());
 }
Example #17
0
 @Test
 public void testparseInputToCommand10() {
   String validInput = "div 1 2 3";
   Command output = Parser.parseInputToCommand(validInput);
   assertEquals(DivCmd.class, output.getClass());
 }
Example #18
0
 @Test
 public void testparseInputToCommand9() {
   String validInput = "mul 1 2 3 4";
   Command output = Parser.parseInputToCommand(validInput);
   assertEquals(MulCmd.class, output.getClass());
 }