/**
  * 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
 /**
  * Verifies the equality of the two objects. Performs special handling of certain types.
  *
  * @param inExpected expected object.
  * @param inActual actual object.
  * @throws IOException if there were errors.
  */
 private static void verifyEquals(Object inExpected, Object inActual) throws IOException {
   if (inExpected == null) {
     assertNull(inActual);
   } else {
     assertNotNull("Expected:" + inExpected, inActual);
     // special handling for certain types
     if (inExpected instanceof ModuleInfo) {
       ModuleInfo e = (ModuleInfo) inExpected;
       ModuleInfo a = (ModuleInfo) inActual;
       ModuleTestBase.assertModuleInfo(
           a,
           e.getURN(),
           e.getState(),
           e.getInitiatedDataFlows(),
           e.getParticipatingDataFlows(),
           e.isAutocreated(),
           e.isAutostart(),
           e.isReceiver(),
           e.isEmitter(),
           e.isFlowRequester());
       assertEquals(e.getLastStartFailure(), a.getLastStartFailure());
       assertEquals(e.getLastStopFailure(), a.getLastStopFailure());
       assertEquals(e.getLockQueueLength(), a.getLockQueueLength());
       assertEquals(e.getReadLockCount(), a.getReadLockCount());
       assertEquals(e.isWriteLocked(), a.isWriteLocked());
     } else if (inExpected instanceof Map) {
       // Convert both maps to the same type
       Map e = new HashMap<Object, Object>((Map<?, ?>) inExpected);
       Map a = new HashMap<Object, Object>((Map<?, ?>) inActual);
       assertEquals(e, a);
     } else if (inExpected instanceof CreateStrategyParameters) {
       CreateStrategyParameters e = (CreateStrategyParameters) inExpected;
       CreateStrategyParameters a = (CreateStrategyParameters) inActual;
       assertEquals(e.getInstanceName(), a.getInstanceName());
       assertEquals(e.getStrategyName(), a.getStrategyName());
       assertEquals(e.getLanguage(), a.getLanguage());
       InputStream ein = e.getStrategySource();
       InputStream ain = a.getStrategySource();
       assertArrayEquals(IOUtils.toByteArray(ein), IOUtils.toByteArray(ain));
       ein.close();
       ain.close();
     } else {
       assertEquals(inExpected, inActual);
     }
   }
 }