/** * Register the command classes used by the fs subcommand * @param factory where to register the class */ public static void registerCommands(CommandFactory factory) { factory.registerCommands(AclCommands.class); factory.registerCommands(CopyCommands.class); factory.registerCommands(Count.class); factory.registerCommands(Delete.class); factory.registerCommands(Display.class); factory.registerCommands(Find.class); factory.registerCommands(FsShellPermissions.class); factory.registerCommands(FsUsage.class); factory.registerCommands(Ls.class); factory.registerCommands(Mkdir.class); factory.registerCommands(MoveCommands.class); factory.registerCommands(SetReplication.class); factory.registerCommands(Stat.class); factory.registerCommands(Tail.class); factory.registerCommands(Test.class); factory.registerCommands(Touch.class); factory.registerCommands(Truncate.class); factory.registerCommands(SnapshotCommands.class); factory.registerCommands(XAttrCommands.class); }
@Test public void processOptionsFollowLink() throws IOException { Find find = new Find(); String args = "-L path"; find.processOptions(getArgs(args)); assertTrue(find.getOptions().isFollowLink()); assertFalse(find.getOptions().isFollowArgLink()); }
@Test public void processOptionsFollowArgLink() throws IOException { Find find = new Find(); String args = "-H path"; find.processOptions(getArgs(args)); assertFalse(find.getOptions().isFollowLink()); assertTrue(find.getOptions().isFollowArgLink()); }
@Test public void processOptionsFollowLinkFollowArgLink() throws IOException { Find find = new Find(); String args = "-L -H path"; find.processOptions(getArgs(args)); assertTrue(find.getOptions().isFollowLink()); // follow link option takes precedence over follow arg link assertFalse(find.getOptions().isFollowArgLink()); }
@Test public void processOptionsExpression() throws IOException { Find find = new Find(); find.setConf(conf); String paths = "path1 path2 path3"; String args = "-L -H " + paths + " -print -name test"; LinkedList<String> argsList = getArgs(args); find.processOptions(argsList); LinkedList<String> pathList = getArgs(paths); assertEquals(pathList, argsList); }
@Test public void processOptionsNoExpression() throws IOException { Find find = new Find(); find.setConf(conf); String args = "path"; String expected = "Print(;)"; find.processOptions(getArgs(args)); Expression expression = find.getRootExpression(); assertEquals(expected, expression.toString()); }
@Test public void processOptionsUnknown() throws IOException { Find find = new Find(); find.setConf(conf); String args = "path -unknown"; try { find.processOptions(getArgs(args)); fail("Unknown expression not caught"); } catch (IOException e) { } }
@Test public void processOptionsKnownUnknown() throws IOException { Find find = new Find(); find.setConf(conf); String args = "path -print -unknown -print"; try { find.processOptions(getArgs(args)); fail("Unknown expression not caught"); } catch (IOException e) { } }
@Test public void processOptionsNoPath() throws IOException { Find find = new Find(); find.setConf(conf); String args = "-print"; LinkedList<String> argsList = getArgs(args); find.processOptions(argsList); assertEquals(Collections.singletonList(Path.CUR_DIR), argsList); }
@Test public void processOptionsName() throws IOException { Find find = new Find(); find.setConf(conf); String args = "path -name namemask"; String expected = "And(;Name(namemask;),Print(;))"; find.processOptions(getArgs(args)); Expression expression = find.getRootExpression(); assertEquals(expected, expression.toString()); }
@Test public void processOptionsIname() throws IOException { Find find = new Find(); find.setConf(conf); String args = "path -iname namemask"; String expected = "And(;Iname-Name(namemask;),Print(;))"; find.processOptions(getArgs(args)); Expression expression = find.getRootExpression(); assertEquals(expected, expression.toString()); }
@Test public void processOptionsPrint() throws IOException { Find find = new Find(); find.setConf(conf); String args = "path -print"; String expected = "Print(;)"; find.processOptions(getArgs(args)); Expression expression = find.getRootExpression(); assertEquals(expected, expression.toString()); }
@Test public void processOptionsPrint0() throws IOException { Find find = new Find(); find.setConf(conf); String args = "path -print0"; String expected = "Print0-Print(;)"; find.processOptions(getArgs(args)); Expression expression = find.getRootExpression(); assertEquals(expected, expression.toString()); }
@Test public void processOptionsNoop() throws IOException { Find find = new Find(); find.setConf(conf); String args = "path -name one -name two -print"; String expected = "And(;And(;Name(one;),Name(two;)),Print(;))"; find.processOptions(getArgs(args)); Expression expression = find.getRootExpression(); assertEquals(expected, expression.toString()); }
@Test public void processOptionsA() throws IOException { Find find = new Find(); find.setConf(conf); String args = "path -name one -a -name two -a -print"; String expected = "And(;And(;Name(one;),Name(two;)),Print(;))"; find.processOptions(getArgs(args)); Expression expression = find.getRootExpression(); assertEquals(expected, expression.toString()); }
@Test public void processOptionsAnd() throws IOException { Find find = new Find(); find.setConf(conf); String args = "path -name one -and -name two -and -print"; String expected = "And(;And(;Name(one;),Name(two;)),Print(;))"; find.processOptions(getArgs(args)); Expression expression = find.getRootExpression(); assertEquals(expected, expression.toString()); }
@Test(timeout = 1000) public void processOptionsFollowLink() throws IOException { Find find = new Find(); String args = "-L path"; find.processOptions(getArgs(args)); assertTrue(find.getOptions().isFollowLink()); assertFalse(find.getOptions().isFollowArgLink()); }
@Test(timeout = 1000) public void processOptionsFollowArgLink() throws IOException { Find find = new Find(); String args = "-H path"; find.processOptions(getArgs(args)); assertFalse(find.getOptions().isFollowLink()); assertTrue(find.getOptions().isFollowArgLink()); }
@Test(timeout = 1000) public void processOptionsFollowLinkFollowArgLink() throws IOException { Find find = new Find(); String args = "-L -H path"; find.processOptions(getArgs(args)); assertTrue(find.getOptions().isFollowLink()); // follow link option takes precedence over follow arg link assertFalse(find.getOptions().isFollowArgLink()); }
@Test(timeout = 1000) public void processOptionsExpression() throws IOException { Find find = new Find(); find.setConf(conf); String paths = "path1 path2 path3"; String args = "-L -H " + paths + " -print -name test"; LinkedList<String> argsList = getArgs(args); find.processOptions(argsList); LinkedList<String> pathList = getArgs(paths); assertEquals(pathList, argsList); }
@Test(timeout = 1000) public void processOptionsNoExpression() throws IOException { Find find = new Find(); find.setConf(conf); String args = "path"; String expected = "Print(;)"; find.processOptions(getArgs(args)); Expression expression = find.getRootExpression(); assertEquals(expected, expression.toString()); }
@Test(timeout = 1000) public void processOptionsUnknown() throws IOException { Find find = new Find(); find.setConf(conf); String args = "path -unknown"; try { find.processOptions(getArgs(args)); fail("Unknown expression not caught"); } catch (IOException e) { } }
@Test(timeout = 1000) public void processOptionsKnownUnknown() throws IOException { Find find = new Find(); find.setConf(conf); String args = "path -print -unknown -print"; try { find.processOptions(getArgs(args)); fail("Unknown expression not caught"); } catch (IOException e) { } }
@Test(timeout = 1000) public void processOptionsNoPath() throws IOException { Find find = new Find(); find.setConf(conf); String args = "-print"; LinkedList<String> argsList = getArgs(args); find.processOptions(argsList); assertEquals(Collections.singletonList(Path.CUR_DIR), argsList); }
@Test(timeout = 1000) public void processOptionsName() throws IOException { Find find = new Find(); find.setConf(conf); String args = "path -name namemask"; String expected = "And(;Name(namemask;),Print(;))"; find.processOptions(getArgs(args)); Expression expression = find.getRootExpression(); assertEquals(expected, expression.toString()); }
@Test(timeout = 1000) public void processOptionsIname() throws IOException { Find find = new Find(); find.setConf(conf); String args = "path -iname namemask"; String expected = "And(;Iname-Name(namemask;),Print(;))"; find.processOptions(getArgs(args)); Expression expression = find.getRootExpression(); assertEquals(expected, expression.toString()); }
@Test(timeout = 1000) public void processOptionsPrint() throws IOException { Find find = new Find(); find.setConf(conf); String args = "path -print"; String expected = "Print(;)"; find.processOptions(getArgs(args)); Expression expression = find.getRootExpression(); assertEquals(expected, expression.toString()); }
@Test(timeout = 1000) public void processOptionsPrint0() throws IOException { Find find = new Find(); find.setConf(conf); String args = "path -print0"; String expected = "Print0-Print(;)"; find.processOptions(getArgs(args)); Expression expression = find.getRootExpression(); assertEquals(expected, expression.toString()); }
@Test(timeout = 1000) public void processOptionsNoop() throws IOException { Find find = new Find(); find.setConf(conf); String args = "path -name one -name two -print"; String expected = "And(;And(;Name(one;),Name(two;)),Print(;))"; find.processOptions(getArgs(args)); Expression expression = find.getRootExpression(); assertEquals(expected, expression.toString()); }
@Test(timeout = 1000) public void processOptionsA() throws IOException { Find find = new Find(); find.setConf(conf); String args = "path -name one -a -name two -a -print"; String expected = "And(;And(;Name(one;),Name(two;)),Print(;))"; find.processOptions(getArgs(args)); Expression expression = find.getRootExpression(); assertEquals(expected, expression.toString()); }
@Test(timeout = 1000) public void processOptionsAnd() throws IOException { Find find = new Find(); find.setConf(conf); String args = "path -name one -and -name two -and -print"; String expected = "And(;And(;Name(one;),Name(two;)),Print(;))"; find.processOptions(getArgs(args)); Expression expression = find.getRootExpression(); assertEquals(expected, expression.toString()); }