Пример #1
0
 public void testParseArgs() throws Exception {
   {
     // test invalid action
     final JobsTool tool = new JobsTool(getFrameworkInstance());
     try {
       final String[] args = {"invalid"};
       final CommandLine line = tool.parseArgs(args);
       tool.validateOptions(line, args);
       fail("invalid action should have failed");
     } catch (CLIToolOptionsException e) {
       assertNotNull(e);
     }
   }
   {
     // test valid actions missing require options
     final JobsTool tool = new JobsTool(getFrameworkInstance());
     try {
       final String[] args = {"load"};
       final CommandLine line = tool.parseArgs(args);
       tool.validateOptions(line, args);
       fail("should have thrown missing argument exception.");
     } catch (CLIToolOptionsException e) {
       assertNotNull(e);
     }
   }
   {
     // test valid actions, with invalid option
     final JobsTool tool = new JobsTool(getFrameworkInstance());
     try {
       final String[] args = {"load", "-d", "zamboni"};
       final CommandLine line = tool.parseArgs(args);
       tool.validateOptions(line, args);
       fail("should have thrown missing argument exception.");
     } catch (CLIToolOptionsException e) {
       assertNotNull(e);
       assertTrue(
           "Wrong message: " + e.getMessage(),
           e.getMessage().startsWith("Illegal value for --duplicate"));
     }
   }
   {
     // test valid actions, missing required -f
     final JobsTool tool = new JobsTool(getFrameworkInstance());
     try {
       final String[] args = {"load", "-d", "update"};
       final CommandLine line = tool.parseArgs(args);
       tool.validateOptions(line, args);
       fail("should have thrown missing argument exception.");
     } catch (CLIToolOptionsException e) {
       assertNotNull(e);
       assertTrue(
           "wrong message:" + e.getMessage(),
           e.getMessage().startsWith("load action: -f/--file option is required"));
     }
   }
   {
     // test valid actions,  -f points to DNE file
     final JobsTool tool = new JobsTool(getFrameworkInstance());
     try {
       final String[] args = {"load", "-f", "doesnotexist"};
       final CommandLine line = tool.parseArgs(args);
       tool.validateOptions(line, args);
       fail("should have thrown missing argument exception.");
     } catch (CLIToolOptionsException e) {
       assertNotNull(e);
       assertTrue(
           "wrong message:" + e.getMessage(),
           e.getMessage().startsWith("load action: -f/--file option: File does not exist"));
     }
   }
   {
     // test valid actions
     final JobsTool tool = new JobsTool(getFrameworkInstance());
     boolean success = false;
     try {
       final String[] args = {"list", "-n", "test1"};
       final CommandLine line = tool.parseArgs(args);
       tool.validateOptions(line, args);
       success = true;
     } catch (CLIToolOptionsException e) {
       fail("unexpected exception: " + e.getMessage());
     }
     assertTrue("parseArgs did not succeed", success);
   }
   {
     // test valid actions
     final JobsTool tool = new JobsTool(getFrameworkInstance());
     try {
       final String[] args = {"list"};
       final CommandLine line = tool.parseArgs(args);
       tool.validateOptions(line, args);
     } catch (CLIToolOptionsException e) {
       fail("unexpected exception: " + e.getMessage());
     }
   }
 }
Пример #2
0
  public void testRun() throws Exception {
    final Framework framework = getFrameworkInstance();
    {
      // test list action
      // test null  result

      final JobsTool tool = new JobsTool(framework);
      final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
      framework.setCentralDispatcherMgr(centralDispatcher1);

      try {
        tool.run(new String[] {"list"});
        fail("run should fail");
      } catch (JobsToolException e) {
        assertTrue(e.getMessage().startsWith("List request returned null"));
      }
    }
    {
      // test list action
      // test 0 items result

      final JobsTool tool = new JobsTool(framework);
      final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
      framework.setCentralDispatcherMgr(centralDispatcher1);

      final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
      centralDispatcher1.listJobsResult = jobs;

      tool.run(new String[] {"list"});
      assertTrue("list action was not called", centralDispatcher1.listStoredJobsCalled);
      assertFalse("load action should not be called", centralDispatcher1.loadJobsCalled);
      assertNotNull(centralDispatcher1.listStoredJobsQuery);
      assertNull(centralDispatcher1.listStoredJobsOutput);
    }
    {
      // test list action with output file
      // test 0 items result

      final JobsTool tool = new JobsTool(framework);
      final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
      framework.setCentralDispatcherMgr(centralDispatcher1);
      File t = File.createTempFile("TestJobsTool", "xml");
      t.deleteOnExit();

      final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
      centralDispatcher1.listJobsResult = jobs;

      tool.run(new String[] {"list", "-f", t.getAbsolutePath()});
      assertTrue("list action was not called", centralDispatcher1.listStoredJobsCalled);
      assertFalse("load action should not be called", centralDispatcher1.loadJobsCalled);
      assertNotNull(centralDispatcher1.listStoredJobsQuery);
      assertNotNull(centralDispatcher1.listStoredJobsOutput);
    }
    {
      // test list action with query params, -n

      final JobsTool tool = new JobsTool(framework);
      final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
      framework.setCentralDispatcherMgr(centralDispatcher1);

      final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
      centralDispatcher1.listJobsResult = jobs;

      tool.run(new String[] {"list", "-" + JobsTool.NAME_OPTION, "name1"});
      assertTrue("list action was not called", centralDispatcher1.listStoredJobsCalled);
      assertFalse("load action should not be called", centralDispatcher1.loadJobsCalled);
      assertNull(centralDispatcher1.listStoredJobsOutput);
      assertNotNull(centralDispatcher1.listStoredJobsQuery);
      assertEquals("name1", centralDispatcher1.listStoredJobsQuery.getNameMatch());
    }
    {
      // test list action with query params, --name

      final JobsTool tool = new JobsTool(framework);
      final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
      framework.setCentralDispatcherMgr(centralDispatcher1);

      final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
      centralDispatcher1.listJobsResult = jobs;

      tool.run(new String[] {"list", "--" + JobsTool.NAME_OPTION_LONG, "name1"});
      assertTrue("list action was not called", centralDispatcher1.listStoredJobsCalled);
      assertFalse("load action should not be called", centralDispatcher1.loadJobsCalled);
      assertNull(centralDispatcher1.listStoredJobsOutput);
      assertNotNull(centralDispatcher1.listStoredJobsQuery);
      assertEquals("name1", centralDispatcher1.listStoredJobsQuery.getNameMatch());
    }
    {
      // test list action with query params, -g

      final JobsTool tool = new JobsTool(framework);
      final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
      framework.setCentralDispatcherMgr(centralDispatcher1);

      final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
      centralDispatcher1.listJobsResult = jobs;

      tool.run(new String[] {"list", "-" + JobsTool.GROUP_OPTION, "group1"});
      assertTrue("list action was not called", centralDispatcher1.listStoredJobsCalled);
      assertFalse("load action should not be called", centralDispatcher1.loadJobsCalled);
      assertNull(centralDispatcher1.listStoredJobsOutput);
      assertNotNull(centralDispatcher1.listStoredJobsQuery);
      assertEquals("group1", centralDispatcher1.listStoredJobsQuery.getGroupMatch());
    }
    {
      // test list action with query params, --group

      final JobsTool tool = new JobsTool(framework);
      final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
      framework.setCentralDispatcherMgr(centralDispatcher1);

      final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
      centralDispatcher1.listJobsResult = jobs;

      tool.run(new String[] {"list", "--" + JobsTool.GROUP_OPTION_LONG, "group2"});
      assertTrue("list action was not called", centralDispatcher1.listStoredJobsCalled);
      assertFalse("load action should not be called", centralDispatcher1.loadJobsCalled);
      assertNull(centralDispatcher1.listStoredJobsOutput);
      assertNotNull(centralDispatcher1.listStoredJobsQuery);
      assertEquals("group2", centralDispatcher1.listStoredJobsQuery.getGroupMatch());
    }
    {
      // test list action with query params, -i

      final JobsTool tool = new JobsTool(framework);
      final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
      framework.setCentralDispatcherMgr(centralDispatcher1);

      final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
      centralDispatcher1.listJobsResult = jobs;

      tool.run(new String[] {"list", "-" + JobsTool.IDLIST_OPTION, "1,2"});
      assertTrue("list action was not called", centralDispatcher1.listStoredJobsCalled);
      assertFalse("load action should not be called", centralDispatcher1.loadJobsCalled);
      assertNull(centralDispatcher1.listStoredJobsOutput);
      assertNotNull(centralDispatcher1.listStoredJobsQuery);
      assertNull(centralDispatcher1.listStoredJobsQuery.getCommand());
      assertNull(centralDispatcher1.listStoredJobsQuery.getType());
      assertNull(centralDispatcher1.listStoredJobsQuery.getResource());
      assertEquals("1,2", centralDispatcher1.listStoredJobsQuery.getIdlist());
    }
    {
      // test list action with query params, --idlist

      final JobsTool tool = new JobsTool(framework);
      final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
      framework.setCentralDispatcherMgr(centralDispatcher1);

      final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
      centralDispatcher1.listJobsResult = jobs;

      tool.run(new String[] {"list", "--" + JobsTool.IDLIST_OPTION_LONG, "3,4"});
      assertTrue("list action was not called", centralDispatcher1.listStoredJobsCalled);
      assertFalse("load action should not be called", centralDispatcher1.loadJobsCalled);
      assertNull(centralDispatcher1.listStoredJobsOutput);
      assertNotNull(centralDispatcher1.listStoredJobsQuery);
      assertNull(centralDispatcher1.listStoredJobsQuery.getCommand());
      assertNull(centralDispatcher1.listStoredJobsQuery.getType());
      assertNull(centralDispatcher1.listStoredJobsQuery.getResource());
      assertEquals("3,4", centralDispatcher1.listStoredJobsQuery.getIdlist());
    }
  }