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

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

    assertNotNull(resultTool);
    assertEquals("DeleteTool", resultTool.getClass().getSimpleName());
  }
Esempio 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());
  }
Esempio n. 4
0
  @Test
  public void testParseCommandCd() {
    String cmd = "cd path/new";
    ITool result = shell.parse(cmd);

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

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

    assertNotNull(resultTool);
    assertEquals("EchoTool", resultTool.getClass().getSimpleName());
  }
Esempio 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());
  }
Esempio n. 8
0
  @Test
  public void testParseCommandMove() {
    String cmd = "move path1 path2";
    ITool resultTool = shell.parse(cmd);

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

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

    assertNotNull(resultTool);
    assertEquals("EchoTool", resultTool.getClass().getSimpleName());
  }
Esempio 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));
        }
      }
    }
  }
Esempio 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));
        }
      }
    }
  }
Esempio 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));
        }
      }
    }
  }