/**
  * Tests file handling.
  *
  * @throws Exception if there were unexpected failures.
  */
 @Test
 public void fileHandling() throws Exception {
   // Create a temp file with text.
   File tmp = File.createTempFile("strat", ".tmp");
   tmp.deleteOnExit();
   String strategyContents = "Test strategy script";
   CopyCharsUtils.copy(strategyContents.toCharArray(), tmp.getAbsolutePath());
   CreateStrategyParameters csp =
       new CreateStrategyParameters(null, "mname", "JAVA", tmp, null, false);
   // verify that the input stream yields the correct contents.
   InputStream is = csp.getStrategySource();
   assertEquals(strategyContents, IOUtils.toString(is));
   is.close();
   // verify failure when a non existent file is supplied
   final CreateStrategyParameters csp2 =
       new CreateStrategyParameters(null, "mname", "JAVA", tmp, null, true);
   assertTrue(tmp.delete());
   assertFalse(tmp.exists());
   new ExpectedFailure<FileNotFoundException>() {
     @Override
     protected void run() throws Exception {
       csp2.getStrategySource();
     }
   };
 }
Пример #2
0
  @Test
  public void createStrategy() throws Exception {
    File f = File.createTempFile("strat", ".tst");
    f.deleteOnExit();
    CopyCharsUtils.copy("Test Strategy Contents".toCharArray(), f.getAbsolutePath());
    final CreateStrategyParameters input =
        new CreateStrategyParameters("instance", "strategy", "java", f, "key=value", false);
    final ModuleURN output = new ModuleURN("test:prov:me:A");
    testAPI(
        new WSTester<ModuleURN>() {
          @Override
          protected ModuleURN invokeApi(boolean isNullParams) throws Exception {
            return getClient().createStrategy(isNullParams ? null : input);
          }

          @Override
          protected ModuleURN setReturnValue(boolean isNullParams) {
            ModuleURN value = isNullParams ? null : output;
            getMockSAService().setURN(value);
            return value;
          }

          @Override
          protected void verifyInputParams(boolean isNullParams) throws Exception {
            verifyEquals(
                isNullParams ? null : input, getMockSAService().getCreateStrategyParameters());
          }
        });
    // Test non-existent file behavior
    resetServiceParameters();
    // Create the parameter and then delete the file.
    CreateStrategyParameters parms =
        new CreateStrategyParameters("instance", "strategy", "java", f, "key=value", false);
    assertTrue(f.delete());
    assertFalse(f.exists());
    getClient().createStrategy(parms);
    InputStream file = getMockSAService().getCreateStrategyParameters().getStrategySource();
    assertNotNull(file);
    // If the file doesn't exist at the time it's being sent, it comes out
    // as empty at the other end.
    assertEquals(0, IOUtils.toByteArray(file).length);
  }