Beispiel #1
0
  public void testZUpdate()
      throws RemoteException, UnexpectedErrorFault, InvalidTypeFault, MalformedQueryFault,
          InvalidQueryLocatorFault {
    try {
      ZApi zapi = new ZApi();
      assertTrue("Logged in", zapi.isLoggedIn);

      QueryResult qres =
          zapi.zQuery("Select Id,Description From Product Where Name='JTest Product'");
      ZObject[] zprods = qres.getRecords();
      Product p1 = (Product) zprods[0];
      assertTrue("Found JTest Product", p1.getDescription().equals("JTest Description"));

      p1.setDescription("JTest Description 2");
      SaveResult[] sr = zapi.zUpdate(new ZObject[] {p1});
      if (!sr[0].getSuccess()) {
        System.out.println(sr[0].getErrors()[0].getMessage());
      }
      assertTrue("Updated Product", sr[0].getSuccess());

      QueryResult qres2 =
          zapi.zQuery("Select Id,Description From Product Where Name='JTest Product'");
      ZObject[] zprods2 = qres2.getRecords();
      Product p2 = (Product) zprods2[0];
      assertTrue("Found Updated JTest Product", p2.getDescription().equals("JTest Description 2"));

    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
  }
Beispiel #2
0
  public void testLoadFile() {
    try {
      String datadir =
          System.getProperty("planworks.test.data.dir")
              .concat(System.getProperty("file.separator"))
              .concat("loadTest")
              .concat(System.getProperty("file.separator"));
      checkConstraintLoad(datadir);
      checkConstraintVarMapLoad(datadir);
      checkObjectLoad(datadir);
      checkPartialPlanLoad(datadir);
      checkProjectLoad(datadir);
      checkSequenceLoad(datadir);
      checkTokenLoad(datadir);
      checkVariableLoad(datadir);
      // checkTransactionLoad(datadir);
      checkPartialPlanStatsLoad(datadir);
      checkResourceInstantsLoad(datadir);
      checkRulesLoad(datadir);
      checkRuleInstanceLoad(datadir);
      checkDecisionLoad(datadir);

      // catch assert errors and Exceptions here, since JUnit seems to not do it
    } catch (AssertionFailedError err) {
      err.printStackTrace();
      System.exit(-1);
    } catch (Exception excp) {
      excp.printStackTrace();
      System.exit(-1);
    }
  }
 @Test
 public void testBug37723() {
   Region region = CacheUtils.createRegion("portfolios", Portfolio.class);
   region.put("0", new Portfolio(0));
   region.put("1", new Portfolio(1));
   region.put("2", new Portfolio(2));
   region.put("3", new Portfolio(3));
   QueryService qs = CacheUtils.getQueryService();
   String qry =
       "select distinct getID, status from /portfolios pf where getID < 10 order by getID desc";
   Query q = qs.newQuery(qry);
   try {
     SelectResults result = (SelectResults) q.execute();
     Iterator itr = result.iterator();
     int j = 3;
     while (itr.hasNext()) {
       Struct struct = (Struct) itr.next();
       assertEquals(j--, ((Integer) struct.get("getID")).intValue());
     }
     qry = "select distinct getID, status from /portfolios pf where getID < 10 order by getID asc";
     q = qs.newQuery(qry);
     result = (SelectResults) q.execute();
     itr = result.iterator();
     j = 0;
     while (itr.hasNext()) {
       Struct struct = (Struct) itr.next();
       assertEquals(j++, ((Integer) struct.get("getID")).intValue());
     }
   } catch (Exception e) {
     e.printStackTrace();
     fail("Test failed because of exception=" + e);
   }
 }
  public void testPathList() {
    System.out.println("PATH LIST TEST");
    String testString =
        "<?xml version='1.0' encoding='ISO-8859-1'?>"
            + "<root xmlns:olli=\"http://www.zeigermann.de\" xmlns:daniel=\"http://www.floreysoft.de\"><sub>"
            + "<olli:element>\n"
            + "<daniel:element>Huhu</daniel:element>\n"
            + "</olli:element>"
            + "</sub></root>";
    System.out.println("TEST STRING:");
    System.out.println(testString);
    System.out.println("");

    try {
      InputStream in = new ByteArrayInputStream(testString.getBytes("ISO-8859-1"));
      SimpleImporter testImporter = new SimpleImporter();
      PathListTester tester = new PathListTester();
      testImporter.addSimpleImportHandler(tester);
      testImporter.setBuildComplexPath(true);
      testImporter.setUseQName(false);
      testImporter.setIncludeLeadingCDataIntoStartElementCallback(false);
      testImporter.parse(new InputSource(in));
    } catch (Exception e) {
      e.printStackTrace();
      fail("Error: " + e);
    }
  }
  public void testJavaBean() {
    try {
      MyBean lTest1 = new MyBean();
      lTest1.setId(100);
      lTest1.setName("SISE Rules!");
      lTest1.setInt1(new Integer(0));
      lTest1.setInt2(new Integer(0));

      System.out.println(marshall.marshall(lTest1).render(true));
      MarshallValue lResult = marshall.unmarshall(marshall.marshall(lTest1));
      Assert.assertTrue(MarshallValue.REFERENCE == lResult.getType());
      MyBean lTest2 = (MyBean) lResult.getReference();

      // Test if the contents are intact.
      Assert.assertNotNull(lTest2);
      Assert.assertEquals(lTest2.getName(), "SISE Rules!");
      Assert.assertEquals(lTest2.getId(), 100);

      // Different physical objects should remain different, even if they
      // are equal.
      Assert.assertTrue(!(lTest2.getInt1() == lTest2.getInt2()));
    } catch (Exception e) {
      e.printStackTrace(System.out);
      Assert.fail();
    }
  }
Beispiel #6
0
  public void testPreferenceChange() {
    try {
      Preferences userRoot = Preferences.userRoot();
      Preferences node = userRoot.node("testAdd");

      node.addPreferenceChangeListener(
          new PreferenceChangeListener() {
            public void preferenceChange(PreferenceChangeEvent evt) {
              System.out.println(
                  " node "
                      + evt.getNode().name()
                      + " key = <"
                      + evt.getKey()
                      + "> val= <"
                      + evt.getNewValue()
                      + ">");
              if (evt.getKey().equals("love"))
                assert evt.getNewValue().equals("ok") : evt.getNewValue();
              else if (evt.getKey().equals("love2"))
                assert evt.getNewValue().equals("not ok") : evt.getNewValue();
            }
          });

      node.put("love", "ok");
      node.put("love2", "not ok");

    } catch (Exception e) {
      System.out.println(e);
      e.printStackTrace();
    }
  }
  /* Test TimeStampTZ with no zone set */
  public void testNoZone() {
    int year = 2000, month = 1, date = 10, hour = 11, minute = 21, second = 31;
    Integer tsId = null;
    java.util.Calendar originalCal = null, dbCal = null;

    EntityManager em = createEntityManager("timestamptz");
    beginTransaction(em);
    try {
      TStamp ts = new TStamp();
      originalCal = java.util.Calendar.getInstance();
      originalCal.set(year, month, date, hour, minute, second);
      ts.setNoZone(originalCal);
      em.persist(ts);
      em.flush();
      tsId = ts.getId();
      commitTransaction(em);
    } catch (Exception e) {
      e.printStackTrace();
      rollbackTransaction(em);
    } finally {
      clearCache();
      dbCal = em.find(TStamp.class, tsId).getNoZone();
      closeEntityManager(em);
    }

    assertEquals("The date retrived from db is not the one set to the child ", dbCal, originalCal);
    assertTrue("The year is not macth", year == dbCal.get(java.util.Calendar.YEAR));
    assertTrue("The month is not match", month == dbCal.get(java.util.Calendar.MONTH));
    assertTrue("The date is not match", date == dbCal.get(java.util.Calendar.DATE));
    assertTrue("The hour is not match", hour == dbCal.get(java.util.Calendar.HOUR));
    assertTrue("The minute is not match", minute == dbCal.get(java.util.Calendar.MINUTE));
    assertTrue("The second is not match", second == dbCal.get(java.util.Calendar.SECOND));
  }
  public void testJavaBeanArray() {
    try {
      MyBean lTest1 = new MyBean();
      lTest1.setId(100);
      lTest1.setName("SISE Rules!");

      MyBean lTest2 = new MyBean();
      lTest2.setId(200);
      lTest2.setName("S.D.I.-Consulting");

      MarshallValue lResult = marshall.unmarshall(marshall.marshall(new MyBean[] {lTest1, lTest2}));
      Assert.assertTrue(MarshallValue.REFERENCE == lResult.getType());
      MyBean[] lArr = (MyBean[]) lResult.getReference();

      Assert.assertNotNull(lArr);
      Assert.assertTrue(lArr.length == 2);

      Assert.assertEquals(lArr[0].getName(), "SISE Rules!");
      Assert.assertEquals(lArr[0].getId(), 100);

      Assert.assertEquals(lArr[1].getName(), "S.D.I.-Consulting");
      Assert.assertEquals(lArr[1].getId(), 200);
    } catch (Exception e) {
      e.printStackTrace(System.out);
      Assert.fail();
    }
  }
Beispiel #9
0
  public void testNodeChange() {
    System.out.println("***TestEvent");
    try {
      Preferences userRoot = Preferences.userRoot();

      userRoot.addNodeChangeListener(
          new NodeChangeListener() {
            public void childAdded(NodeChangeEvent evt) {
              System.out.println(
                  "childAdded = " + evt.getParent().name() + " " + evt.getChild().name());
            }

            public void childRemoved(NodeChangeEvent evt) {
              System.out.println(
                  "childRemoved = " + evt.getParent().name() + " " + evt.getChild().name());
            }
          });

      Preferences node = userRoot.node("testAdd");
      node.removeNode();

    } catch (Exception e) {
      System.out.println(e);
      e.printStackTrace();
    }
  }
Beispiel #10
0
 public void testPurgeLocallyStoredHistory() {
   try {
     this.historyService.purgeLocallyStoredHistory(this.history.getID());
   } catch (Exception ex) {
     fail("Cannot delete local history with id " + this.history.getID() + " : " + ex.getMessage());
   }
 }
Beispiel #11
0
 public static void main(String args[]) {
   try {
     junit.textui.TestRunner.run(suite());
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Beispiel #12
0
 public void testZLogin() {
   try {
     ZApi zapi = new ZApi();
     assertTrue("Logged in", zapi.isLoggedIn);
   } catch (Exception e) {
     e.printStackTrace();
     fail(e.getMessage());
   }
 }
 public void run() {
   Configuration conf = new Configuration();
   try {
     conf.setEventManager(new EventManager());
     Thread.sleep(100);
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
 public void run() {
   Configuration conf = new Configuration();
   try {
     conf.setBulkFitnessFunction(new TestBulkFitnessFunction());
     Thread.sleep(100);
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
  protected void tearDown() {

    try {
      connection.close();
    } catch (Exception e) {
      e.printStackTrace();
      System.out.println("TestSql.tearDown() error: " + e.getMessage());
    }
  }
  public void testColumnUpdatableAndInsertableThroughQuery() {
    if ((JUnitTestCase.getServerSession()).getPlatform().isSymfoware()) {
      getServerSession()
          .logMessage(
              "Test testColumnUpdatableAndInsertableThroughQuery skipped for this platform, "
                  + "Symfoware doesn't support UpdateAll/DeleteAll on multi-table objects (see rfe 298193).");
      return;
    }

    EntityManager em = createEntityManager();

    try {
      // Create an official
      beginTransaction(em);
      Official initialOfficial = new Official();
      initialOfficial.setName("Gui Pelletier");
      em.persist(initialOfficial);
      commitTransaction(em);

      // Close the EM, clear cache and get new EM.
      closeEntityManager(em);
      clearCache();
      em = createEntityManager();

      // Update the official using a named query.
      beginTransaction(em);
      Query query = em.createNamedQuery("UpdateXMLOfficalName");
      query.setParameter("name", "Guy");
      query.setParameter("id", initialOfficial.getId());
      query.executeUpdate();
      Official modifiedOfficial = em.find(Official.class, initialOfficial.getId());
      assertTrue(
          "The name was not updated after executing the named query",
          modifiedOfficial.getName().equals("Guy"));
      commitTransaction(em);

      // Close the EM, clear cache and get new EM.
      closeEntityManager(em);
      clearCache();
      em = createEntityManager();

      Official refreshedOfficial = em.find(Official.class, modifiedOfficial.getId());
      assertTrue(
          "The refreshedOfficial did not match the modified",
          getServerSession().compareObjects(modifiedOfficial, refreshedOfficial));

    } catch (Exception e) {
      if (isTransactionActive(em)) {
        rollbackTransaction(em);
      }

      fail("Update query failed: " + e.getMessage());
    } finally {
      closeEntityManager(em);
    }
  }
 public void testrunCommandNoDomains() throws Exception {
   try {
     Vector operands = new Vector();
     operands.add("UndefinedDomain");
     testCommand.setOperands(operands);
     testCommand.runCommand();
   } catch (Exception e) {
     assertEquals(e.getMessage(), "CLI157 Could not stop the domain UndefinedDomain.");
   }
 }
 /*
  * main method for debugging
  */
 public static void main(String[] args) {
   try {
     // System.setProperty("uselocal", "true");
     SimpleHelloTester tester = new SimpleHelloTester("SimpleHelloTester");
     tester.testHello();
     tester.testHelloOneWay();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Beispiel #19
0
 private void addErrorMessage(TestResult testResult, String message) {
   String processedTestsMessage =
       myRunTests <= 0 ? "None of tests was run" : myRunTests + " tests processed";
   try {
     testResult.startTest(this);
     testResult.addError(this, new Throwable(processedTestsMessage + " before: " + message));
     testResult.endTest(this);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
 public static FreeColServer startServer(
     File file, boolean publicServer, boolean singlePlayer, int port, String name) {
   stopServer();
   try {
     server = new FreeColServer(new FreeColSavegameFile(file), null, port, name);
   } catch (Exception e) {
     fail(e.getMessage());
   }
   assertNotNull(server);
   assertEquals(FreeColServer.GameState.IN_GAME, server.getGameState());
   return server;
 }
 /**
  * This function instantiates an invariant class by using the <type>(PptSlice) constructor.
  *
  * @param theClass the invariant class to be instantiated
  * @param sl the PptSlice representing the variables about which an invariant is determined
  * @return an instance of the class in theClass if one can be constructed, else throw a
  *     RuntimeException
  */
 private static Invariant instantiateClass(Class<? extends Invariant> theClass, PptSlice sl) {
   try {
     Method get_proto = theClass.getMethod("get_proto", new Class<?>[] {});
     Invariant proto = (/*@Prototype*/ Invariant) get_proto.invoke(null, new Object[] {});
     Invariant inv = proto.instantiate(sl);
     return (inv);
   } catch (Exception e) {
     e.printStackTrace(System.out);
     throw new RuntimeException(
         "Error while instantiating invariant " + theClass.getName() + ": " + e.toString());
   }
 }
Beispiel #22
0
 protected void setUp() {
   try {
     new MySQLDB();
     SQLDB.startDatabase();
     SQLDB.registerDatabase();
     SQLDB.cleanDatabase();
   } catch (Exception e) {
     e.printStackTrace();
     System.exit(-1);
   }
   PlanWorksTest.TEST_RUNNING = 2;
 }
  /**
   * Creates a group in the server stored contact list, makes sure that the corresponding event has
   * been generated and verifies that the group is in the list.
   *
   * @throws java.lang.Exception
   */
  public void postTestCreateGroup() throws Exception {
    // first clear the list
    fixture.clearProvidersLists();

    Object o = new Object();
    synchronized (o) {
      o.wait(3000);
    }

    logger.trace("testing creation of server stored groups");
    // first add a listener
    GroupChangeCollector groupChangeCollector = new GroupChangeCollector();
    opSetPersPresence1.addServerStoredGroupChangeListener(groupChangeCollector);

    // create the group
    opSetPersPresence1.createServerStoredContactGroup(
        opSetPersPresence1.getServerStoredContactListRoot(), testGroupName);

    groupChangeCollector.waitForEvent(10000);

    opSetPersPresence1.removeServerStoredGroupChangeListener(groupChangeCollector);

    // check whether we got group created event
    assertEquals("Collected Group Change events: ", 1, groupChangeCollector.collectedEvents.size());

    assertEquals(
        "Group name.",
        testGroupName,
        ((ServerStoredGroupEvent) groupChangeCollector.collectedEvents.get(0))
            .getSourceGroup()
            .getGroupName());

    // check whether the group is retrievable
    ContactGroup group =
        opSetPersPresence1.getServerStoredContactListRoot().getGroup(testGroupName);

    assertNotNull("A newly created group was not in the contact list.", group);

    assertEquals("New group name", testGroupName, group.getGroupName());

    // when opearting with groups . the group must have entries
    // so changes to take effect. Otherwise group will be lost after loggingout
    try {
      opSetPersPresence1.subscribe(group, fixture.userID2);

      synchronized (o) {
        o.wait(1500);
      }
    } catch (Exception ex) {
      fail("error adding entry to group : " + group.getGroupName() + " " + ex.getMessage());
    }
  }
  /** A unit test for JUnit */
  public void testExecute() {
    try {
      builder.execute(msg);
    } catch (Exception e) {
      e.printStackTrace();
    }
    String query0 = "Insert into OtherTestTable ( NoField, sequence_field ) values ( 256.3652, 6 )";
    assertEquals("Query was not built and inserted into the MsgObject", query0, msg.getQuery()[0]);

    String query1 =
        "Insert into TestTable ( FirstField, SecondField ) values ( 1, 'testing string' )";
    assertEquals("Query was not built and inserted into the MsgObject", query1, msg.getQuery()[1]);
  }
Beispiel #25
0
  /**
   * Writes the entire model to a file.
   *
   * @throws Exception
   */
  public void testWriteRDFFile() throws Exception {

    File tmpFile1 = null;
    File tmpFile2 = null;

    try {

      File rdfFile = new File(RDF_FILE);
      Content rdfContent = new FileContent(rdfFile);

      // check to be sure test data is ok
      assertTrue(
          "Bad test data. Not parsable by RDF/XML Content Handler.",
          contentHandler.canParse(rdfContent));
      ResolverSession session1 = new TestResolverSession();
      Statements statements1 = contentHandler.parse(rdfContent, session1);
      // write them
      tmpFile1 = writeStatements(statements1, session1);

      // re-parse to ensure it is valid
      rdfContent = new FileContent(tmpFile1);
      ResolverSession session2 = new TestResolverSession();
      // output should be parsable
      assertTrue(
          "Output is not parsable by RDF/XML Content Handler.",
          contentHandler.canParse(rdfContent));
      Statements statements2 = contentHandler.parse(rdfContent, session2);
      tmpFile2 = writeStatements(statements2, session2);

      // Compare the two files
      assertTrue(
          "RDF/XML files are not being written consistantly.", compareFiles(tmpFile1, tmpFile2));
    } catch (Exception exception) {

      exception.printStackTrace();
      throw new Exception(exception);
    } finally {

      // delete the tmp files
      if (tmpFile1 != null) {
        tmpFile1.delete();
      }
      if (tmpFile2 != null) {
        tmpFile2.delete();
      }
    }
  }
Beispiel #26
0
  public void testValid() {
    Enumeration e = validRsls.keys();
    String key;
    String rsl;
    while (e.hasMoreElements()) {
      key = (String) e.nextElement();
      rsl = validRsls.getProperty(key);

      System.out.println("Parsing valid rsl " + key + ": " + rsl);
      try {
        RSLParser.parse(rsl);
      } catch (Exception ex) {
        ex.printStackTrace();
        fail("Failed to parse!!!");
      }
    }
  }
  @Test
  public void testMultipleOrderByClauses() {
    Region region = CacheUtils.createRegion("portfolios", Portfolio.class);
    region.put("2", new Portfolio(2));
    region.put("3", new Portfolio(3));
    region.put("4", new Portfolio(4));
    region.put("5", new Portfolio(5));
    region.put("6", new Portfolio(6));
    region.put("7", new Portfolio(7));
    QueryService qs = CacheUtils.getQueryService();
    String qry =
        "select distinct status, getID from /portfolios pf where getID < 10 order by status asc, getID desc";
    Query q = qs.newQuery(qry);
    try {
      SelectResults result = (SelectResults) q.execute();
      Iterator itr = result.iterator();
      int j = 6;
      while (itr.hasNext() && j > 0) {
        Struct struct = (Struct) itr.next();
        assertEquals("active", struct.get("status"));
        assertEquals(j, ((Integer) struct.get("getID")).intValue());

        j -= 2;
      }
      j = 7;
      while (itr.hasNext()) {
        Struct struct = (Struct) itr.next();
        assertEquals(j, ((Integer) struct.get("getID")).intValue());
        assertEquals("inactive", struct.get("status"));
        j -= 2;
      }
      /*
      qry = "select distinct getID, status from /portfolios pf where getID < 10 order by getID asc";
      q = qs.newQuery(qry);
      result = (SelectResults) q.execute();
      itr = result.iterator();
      j = 0;
      while ( itr.hasNext()) {
       Struct struct = (Struct)itr.next();
       assertEquals(j++, ((Integer)struct.get("getID")).intValue());
      }*/
    } catch (Exception e) {
      e.printStackTrace();
      fail("Test failed because of exception=" + e);
    }
  }
Beispiel #28
0
  public void testWriteRecordsWithMaxNumber() {
    HistoryWriter writer = this.history.getWriter();
    HistoryReader reader = this.history.getReader();

    try {

      for (int i = 0; i < 20; i++) {
        writer.addRecord(new String[] {"" + i, "name" + i, i % 2 == 0 ? "m" : "f"}, 20);
        synchronized (this) {
          try {
            wait(100);
          } catch (Throwable t) {
          }
        }
      }

      QueryResultSet<HistoryRecord> recs = reader.findLast(20);
      int count = 0;
      while (recs.hasNext()) {
        count++;
        recs.next();
      }

      assertEquals("Wrong count of messages", 20, count);

      writer.addRecord(new String[] {"" + 21, "name" + 21, "f"}, 20);

      recs = reader.findLast(20);
      count = 0;
      boolean foundFirstMessage = false;
      while (recs.hasNext()) {
        count++;
        HistoryRecord hr = recs.next();

        if (hr.getPropertyValues()[0].equals("0")) foundFirstMessage = true;
      }

      assertEquals("Wrong count of messages", 20, count);

      assertFalse("Wrong message removed, must be the first one", foundFirstMessage);

    } catch (Exception e) {
      e.printStackTrace();
      fail("Could not write records. Reason: " + e);
    }
  }
Beispiel #29
0
  public void testZQuery()
      throws RemoteException, UnexpectedErrorFault, InvalidTypeFault, MalformedQueryFault,
          InvalidQueryLocatorFault {
    try {
      ZApi zapi = new ZApi();
      assertTrue("Logged in", zapi.isLoggedIn);

      QueryResult qres =
          zapi.zQuery("Select Id,Name,Description From Product Where Name='JTest Product'");
      ZObject[] zprods = qres.getRecords();
      Product p1 = (Product) zprods[0];

      assertTrue("Found JTest Product", p1.getDescription().equals("JTest Description"));
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
  }
  /**
   * Test of getProductsByCategory2 method, of class
   * thirdstage.exercise.spring.hibernate5.ProductDaoHibernateImpl3.
   */
  public void testGetProductsByCategory2() throws Exception {
    System.out.println("getProductsByCategory2");

    ProductDao dao = (ProductDao) (this.factory.getBean("productDao3"));
    String category = "cpu";
    try {
      java.util.List<Product> result = dao.getProductsByCategory2(category);

      for (int i = 0, n = result.size(); i < n; i++) {
        System.out.println("" + result.get(i).getId() + ", " + result.get(i).getName());
      }

      assertTrue(result.size() > 0);
    } catch (Exception ex) {
      System.out.println("fail");
      ex.printStackTrace(System.out);
    }
  }