Exemplo n.º 1
0
  @Test
  public void testParseCommandCopy() {
    String cmd = "copy file1 file2";
    ITool resultTool = shell.parse(cmd);

    assertNotNull(resultTool);
    assertEquals("CopyTool", resultTool.getClass().getSimpleName());
  }
Exemplo n.º 2
0
  @Test
  public void testParseCommandDelete() {
    String cmd = "delete file1";
    ITool resultTool = shell.parse(cmd);

    assertNotNull(resultTool);
    assertEquals("DeleteTool", resultTool.getClass().getSimpleName());
  }
Exemplo n.º 3
0
  @Test
  public void testParseCommandCat() {
    String cmd = "cat path/to/file1";
    ITool resultTool = shell.parse(cmd);

    assertNotNull(resultTool);
    assertEquals("CatTool", resultTool.getClass().getSimpleName());
  }
Exemplo n.º 4
0
  @Test
  public void testParseCommandCd() {
    String cmd = "cd path/new";
    ITool result = shell.parse(cmd);

    assertNotNull(result);
    assertEquals("CdTool", result.getClass().getSimpleName());
  }
Exemplo n.º 5
0
  @Test
  public void testParseCommandWc() {
    String cmd = "wc testfile.txt";
    ITool resultTool = shell.parse(cmd);

    assertNotNull(resultTool);
    assertEquals("WcTool", resultTool.getClass().getSimpleName());
  }
Exemplo n.º 6
0
  @Test
  public void testParseCommandWithInconsistentSpace() {
    String cmd = "  eChO      sOme   wOrd   ";
    ITool resultTool = shell.parse(cmd);

    assertNotNull(resultTool);
    assertEquals("EchoTool", resultTool.getClass().getSimpleName());
  }
Exemplo n.º 7
0
  @Test
  public void testParseCommandPiping() {
    String cmd = "cmd-1 | cmd-2";
    ITool resultTool = shell.parse(cmd);

    assertNotNull(resultTool);
    assertEquals("PipingTool", resultTool.getClass().getSimpleName());
  }
Exemplo n.º 8
0
  @Test
  public void testParseCommandMove() {
    String cmd = "move path1 path2";
    ITool resultTool = shell.parse(cmd);

    assertNotNull(resultTool);
    assertEquals("MoveTool", resultTool.getClass().getSimpleName());
  }
Exemplo n.º 9
0
  @Test
  public void testParseCommandLs() {
    String cmd = "ls";
    ITool resultTool = shell.parse(cmd);

    assertNotNull(resultTool);
    assertEquals("LsTool", resultTool.getClass().getSimpleName());
  }
Exemplo n.º 10
0
  @Test
  public void testParseCommandEcho() {
    String cmd = "echo some word";
    ITool resultTool = shell.parse(cmd);

    assertNotNull(resultTool);
    assertEquals("EchoTool", resultTool.getClass().getSimpleName());
  }
Exemplo n.º 11
0
  @Test
  public void testParseCommandWithEscapedPipe2()
      throws IllegalArgumentException, IllegalAccessException {
    String cmd = "cat testCase_3.txt | grep [a|b]";
    ITool resultTool = shell.parse(cmd);

    String[] expected = {"cat testCase_3.txt", "grep [a", "b]"};
    Field fields[] = resultTool.getClass().getSuperclass().getDeclaredFields();
    for (Field field : fields) {
      if (field.getName().equals("args")) {
        field.setAccessible(true);
        List<String> args = Arrays.asList((String[]) field.get(resultTool));
        for (int i = 0; i < expected.length; i++) {
          assertEquals(expected[i], args.get(i));
        }
      }
    }
  }
Exemplo n.º 12
0
  @Test
  public void testParseCommandWithQuotes() throws IllegalArgumentException, IllegalAccessException {
    String cmd = "ls \"normal\" 'test's";
    String[] expected = {"normal", "tests"};
    ITool resultTool = shell.parse(cmd);

    assertNotNull(resultTool);

    Field fields[] = resultTool.getClass().getSuperclass().getDeclaredFields();
    for (Field field : fields) {
      if (field.getName().equals("args")) {
        field.setAccessible(true);
        List<String> args = Arrays.asList((String[]) field.get(resultTool));
        for (int i = 0; i < expected.length; i++) {
          assertEquals(expected[i], args.get(i));
        }
      }
    }
  }
Exemplo n.º 13
0
  @Test
  public void testParseCommandWithMixedQuotesandEscapedSpaceandDuplicateMatch()
      throws IllegalArgumentException, IllegalAccessException {
    String cmd = "echo \"normal\" as\"as'\\ r\\$'w\\ e\"d's d's dd\\ sa\\$";
    String[] expected = {"normal", "asas'\\ r$'w\\ eds ds", "dd sa$"};
    ITool resultTool = shell.parse(cmd);

    assertNotNull(resultTool);

    Field fields[] = resultTool.getClass().getSuperclass().getDeclaredFields();
    for (Field field : fields) {
      if (field.getName().equals("args")) {
        field.setAccessible(true);
        List<String> args = Arrays.asList((String[]) field.get(resultTool));
        for (int i = 0; i < expected.length; i++) {
          assertEquals(expected[i], args.get(i));
        }
      }
    }
  }