コード例 #1
0
  /**
   * Tests the XSLT used to downgrade from current schema to 2003-FC. An XML file with an image is
   * created and the stylesheet is applied.
   *
   * @throws Exception Thrown if an error occurred.
   */
  @Test(enabled = false)
  public void testDowngradeTo2003FCImageNoMetadata() throws Exception {
    File inFile = File.createTempFile("testDowngradeTo2003FCImageNoMetadata", "." + OME_XML_FORMAT);
    files.add(inFile);
    File middleFileA =
        File.createTempFile("testDowngradeTo2003FCImageNoMetadataMiddleA", "." + OME_XML_FORMAT);
    files.add(middleFileA);
    File middleFileB =
        File.createTempFile("testDowngradeTo2003FCImageNoMetadataMiddleB", "." + OME_XML_FORMAT);
    files.add(middleFileB);
    File outputFile =
        File.createTempFile("testDowngradeTo2003FCImageNoMetadataOutput", "." + OME_XML_FORMAT);
    files.add(outputFile);
    XMLMockObjects xml = new XMLMockObjects();
    XMLWriter writer = new XMLWriter();
    writer.writeFile(inFile, xml.createImage(), true);

    transformFileWithStream(inFile, middleFileA, STYLESHEET_A);
    transformFileWithStream(middleFileA, middleFileB, STYLESHEET_B);
    transformFileWithStream(middleFileB, outputFile, STYLESHEET_C);

    Document doc = anOmeValidator.parseFileWithStreamArray(outputFile, schemaArray);
    Assert.assertNotNull(doc);

    // Should only have one root node i.e. OME node
    NodeList list = doc.getChildNodes();
    Assert.assertEquals(list.getLength(), 1);
    Node root = list.item(0);
    Assert.assertEquals(root.getNodeName(), XMLWriter.OME_TAG);
    // now analyse the root node
    list = root.getChildNodes();
    String name;
    Node n;
    Document docSrc = anOmeValidator.parseFile(inFile, null);
    Node rootSrc = docSrc.getChildNodes().item(0);
    Node imageNode = null;
    NodeList listSrc = rootSrc.getChildNodes();
    for (int i = 0; i < listSrc.getLength(); i++) {
      n = listSrc.item(i);
      name = n.getNodeName();
      if (name != null) {
        if (name.contains(XMLWriter.IMAGE_TAG)) imageNode = n;
      }
    }

    for (int i = 0; i < list.getLength(); i++) {
      n = list.item(i);
      name = n.getNodeName();
      if (name != null) {
        // TODO: add other node
        if (name.contains(XMLWriter.IMAGE_TAG) && imageNode != null) checkImageNode(n, imageNode);
      }
    }
  }