@Test
  public void testRunFile() throws Exception {
    String script = TestTools.readResource("testwot.js");
    WotJavaScriptRuntime jsrt = WotJavaScriptRuntime.create();

    String testTD = TestTools.readResource("simplething.jsonld");
    jsrt.getEngine().put("testTD", testTD);

    // jsrt.runScript(script);
  }
  public void testSerialization() throws Exception {
    IdentityHashBag bag2 = (IdentityHashBag) TestTools.serialize(this.bag);

    assertTrue("same object?", this.bag != bag2);
    assertEquals(11, bag2.size());
    assertEquals(CollectionTools.bag(this.bag.iterator()), CollectionTools.bag(bag2.iterator()));
    // look for similar elements
    assertTrue(CollectionTools.bag(bag2.iterator()).contains(null));
    assertTrue(CollectionTools.bag(bag2.iterator()).contains("one"));
    assertTrue(CollectionTools.bag(bag2.iterator()).contains("two"));
    assertTrue(CollectionTools.bag(bag2.iterator()).contains("three"));
    assertTrue(CollectionTools.bag(bag2.iterator()).contains("four"));

    int nullCount = 0, oneCount = 0, twoCount = 0, threeCount = 0, fourCount = 0;
    for (Iterator stream = bag2.iterator(); stream.hasNext(); ) {
      String next = (String) stream.next();
      if (next == null) nullCount++;
      else if (next.equals("one")) oneCount++;
      else if (next.equals("two")) twoCount++;
      else if (next.equals("three")) threeCount++;
      else if (next.equals("four")) fourCount++;
    }
    assertEquals(1, nullCount);
    assertEquals(1, oneCount);
    assertEquals(2, twoCount);
    assertEquals(3, threeCount);
    assertEquals(4, fourCount);
  }
  // NOTE: All test classes will use the ticket-generator-server.properties
  // from test/resoures
  // and the log4j.properties
  @Before
  public void setUp() {
    ticketService = mock(TicketService.class);

    ticketGenerator.setSleepInterval(2);
    ticketGenerator.setTicketService(ticketService);

    ticketList = TestTools.createTestTicketOrders();
  }
  public void testSerialization() throws Exception {
    Association assoc2 = (Association) TestTools.serialize(this.assoc);

    assertEquals(this.assoc, assoc2);
    assertNotSame(this.assoc, assoc2);
    assertEquals(this.assoc.getKey(), assoc2.getKey());
    assertNotSame(this.assoc.getKey(), assoc2.getKey());
    assertEquals(this.assoc.getValue(), assoc2.getValue());
    assertNotSame(this.assoc.getValue(), assoc2.getValue());
  }
Example #5
0
  public static void main(String[] args) throws Exception {

    GraphTestCase graphTestCase = new GraphTestCase(args[0]);

    String[] addresses = graphTestCase.getCassandraClusterIps().split(",");

    for (int i = 0; i < addresses.length; i++) {
      TestTools.genCassandraYaml(
          new CassandraStartMsg(
              graphTestCase.getWorkDirectory(),
              graphTestCase.getStorageDirectory(),
              addresses.length,
              i,
              addresses[0].trim(),
              addresses[i].trim(),
              false));
    }
  }
  @Test
  public void doTest() throws Exception {
    // let's send process one batch
    when(ticketService.getOpenTickets()).thenReturn(ticketList);

    ticketGenerator.startAndWait();

    // give the system some time to do something
    Thread.sleep(2 * 1000);

    ticketGenerator.stopAndWait();

    // -- CHECK YOUR RESULTS
    // now check to see if it did anything
    assertEquals(1, ticketGenerator.getTicketBatchSendCount());

    // ask to fake tickQueue if the order got there
    // for redis this would be serialized
    TicketBatch ticketBatch = ticketGenerator.getTicketQueue().poll();

    TestTools.verifyTestTicketBatch(ticketBatch);
  }
Example #7
0
  public int compileJava() {
    try {
      //    create new bin directory
      boolean createBin = new File(classPath).mkdir();

      //    create new javac ProcessBuilder
      //      ProcessBuilder pb =
      //      new ProcessBuilder("javac", "-d", classPath, "./" + studentPath + "/*.java");

      ProcessBuilder pbDir = new ProcessBuilder("dir");
      //    Determine current working directory
      File srcAbsPath = new File(sourcePath);
      srcAbsPathName = srcAbsPath.getAbsolutePath();
      System.out.println("Compiler.java line 69 source path: " + sourcePath);
      System.out.println("Compiler.java line 69 source absolute path: " + srcAbsPathName);

      File cwd = pbDir.directory();
      //    debug code - to confirm correct directory
      //    TestTools.dir(cwd);
      //    NB - ProcessBuilder default is to return a null
      //    pointer for the abstract path to indicate that it
      //    is using System.Properties "user.dir", i.e., the
      //    current system working directory; hence the
      //    critical need to handle a NullPointerException.
      //    Also returns a null pointer if the directory
      //    doesn't exist.

      // all this is doing is changing the dir, can we approach this in a different way using a
      // value in our Data Object? -mh
      File nwd = TestTools.cd(cwd, studentPath);

      System.out.println("(Compiler.java line 88)new working directory: " + nwd.toString());
      String studentPathName = nwd.getAbsolutePath();
      File nwdPath = new File(studentPath);
      System.out.println("(Compiler.java line 91)new working directory path: " + studentPathName);
      //    debug code to test new working directory
      //    TestTools.dir(nwd);

      FileFilter filter = new FileFilter() {};

      String[] javaFileList = nwdPath.list(filter);
      //    set up output file
      File outputFile = new File(outputFileName);
      //    System.out.println(outputFileName);
      outputFile.delete();

      for (int k = 0; k < javaFileList.length; k++) {
        try {
          if (filter.accept(nwdPath, javaFileList[k]) == true) {
            System.out.println("COMPILER.JAVA (line 111)  Compiling: " + javaFileList[k]);

            String compilePath =
                "javac" + "-d" + classPath + ".\\" + studentPath + "\\" + javaFileList[k];
            System.out.println("Compiler.java 117 compile path: " + compilePath);
            ProcessBuilder pb =
                // new ProcessBuilder("javac ", "-d", classPath, ".\\" + studentPath + "\\" +
                // javaFileList[k]);
                new ProcessBuilder(compilePath);

            // System.out.println(pb.environment().toString());  <-- THIS IS VERY INTERESTING

            //          Create environment map and set environmental variables
            Map<String, String> env = pb.environment();
            env.clear();
            env.put("PATH", path);
            env.put("CLASSPATH", classPath);
            //          env.put("SOURCEPATH", sourcePath);
            //          env.remove("OTHERVAR");

            pb.redirectErrorStream(true);
            pb.redirectOutput(Redirect.appendTo(outputFile));

            //          start javac process
            Process p = pb.start();

            //          need other processes to wait for compilation to finish
            //          basically joins the thread to the javac process to force sequential
            //          execution - need to be careful - if any process hangs, whole run hangs
            success =
                p
                    .waitFor(); // Returns the exit value of the process. By convention, 0 indicates
                                // normal termination.
                                // http://docs.oracle.com/javase/6/docs/api/java/lang/Process.html#waitFor%28%29

            assert pb.redirectInput() == Redirect.PIPE;
            assert pb.redirectOutput().file() == outputFile;
            assert p.getInputStream().read() == -1;
            System.out.println("COMPILER.JAVA (line 138)  end of loop, success = " + success);
          }
        } catch (Exception e) {
          System.out.println(" Compiler.java FOR LOOP Compile Exception: " + javaFileList[k]);
        }
      }
    } catch (Exception e) {
      System.out.println("Compile Exception, PROBABLY DUE TO FILE PATH");
      System.out.println("source absolute path: " + srcAbsPathName);
    }

    return success;
  }
 protected void tearDown() throws Exception {
   TestTools.clear(this);
   super.tearDown();
 }