Exemple #1
0
  /** test to generate a clon of a day */
  public void test_cloneDay() {
    Day firstDay = new Day();
    Day clonedDay = new Day();
    DSetOfResources setOfSequences = new StandardCollection();

    for (int i = 1; i < 4; i++) {
      setOfSequences.addResource(new DResource(Integer.toString(i), new Sequence()), 0);
    }
    firstDay.setSetOfSequences(setOfSequences);
    clonedDay = firstDay.cloneDay();

    assertEquals(
        "test_cloneDay : assertEquals 1 (Size of setOfSequences): ",
        firstDay.getSetOfSequences().size(),
        clonedDay.getSetOfSequences().size());
    assertEquals(
        "test_cloneDay : assertEquals 2 (ID of sequence 1): ",
        firstDay.getSetOfSequences().getResourceAt(0).getID(),
        firstDay.getSetOfSequences().getResourceAt(0).getID());
    assertEquals(
        "test_cloneDay : assertEquals 3 (ID of sequence 2): ",
        firstDay.getSetOfSequences().getResourceAt(1).getID(),
        firstDay.getSetOfSequences().getResourceAt(1).getID());
    assertEquals(
        "test_cloneDay : assertEquals 4 (ID of sequence 3): ",
        firstDay.getSetOfSequences().getResourceAt(2).getID(),
        firstDay.getSetOfSequences().getResourceAt(2).getID());
  } // end of method
Exemple #2
0
  public void test_writeXMLtag() {
    XMLInputFile xmlFile;
    Element eSetOfSequences;
    Day firstDay = new Day();
    Day savedDay = new Day();
    DSetOfResources setOfSequences = new StandardCollection();

    try {
      xmlFile = new XMLInputFile();
      Document doc;
      Sequence seq;
      for (int i = 1; i < 4; i++) {
        seq = new Sequence();
        seq.getSetOfPeriods().addResource(new DResource("AM", new Period()), 0);
        setOfSequences.addResource(new DResource(Integer.toString(i), seq), 1);
      }
      firstDay.setSetOfSequences(setOfSequences);
      XMLWriter wr = new XMLWriter();
      doc = wr.getNewDocument();
      eSetOfSequences = firstDay.writeXMLtag(doc);
      doc = wr.buildDocument(doc, eSetOfSequences);
      XMLOutputFile xmlOF = new XMLOutputFile();
      xmlOF.write(doc, _pathForOutputFiles + "SavedDay.xml");

      // read xml file
      InputStream is = new FileInputStream(_pathForOutputFiles + "SavedDay.xml");
      doc = xmlFile.createDocumentFromInputStream(is);

      XMLReader list = new XMLReader();
      eSetOfSequences = list.getRootElement(doc);
      savedDay = new Day();
      savedDay.readXMLtag(eSetOfSequences);

      assertEquals(
          "test_writeXMLtag : assertEquals 1 (setOfSequences size): ",
          firstDay.getSetOfSequences().size(),
          savedDay.getSetOfSequences().size());
      assertEquals(
          "test_writeXMLtag : assertEquals 2 (ID of sequence 1): ",
          firstDay.getSetOfSequences().getResourceAt(0).getID(),
          savedDay.getSetOfSequences().getResourceAt(0).getID());
      assertEquals(
          "test_writeXMLtag : assertEquals 3 (ID of sequence 2): ",
          firstDay.getSetOfSequences().getResourceAt(1).getID(),
          savedDay.getSetOfSequences().getResourceAt(1).getID());
      assertEquals(
          "test_writeXMLtag : assertEquals 4 (ID of sequence 3): ",
          firstDay.getSetOfSequences().getResourceAt(2).getID(),
          savedDay.getSetOfSequences().getResourceAt(2).getID());
    } catch (Exception e) {
      // Should not fail in tests, but if file not there gives a failure
      assertEquals("test_writeXMLtag: exception", "nullPointer", e.toString());
      System.out.println("Exception in: test_writeXMLtag");
      e.printStackTrace();
    }
  } // end of method