コード例 #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 = true)
  public void testDowngradeTo2003FCImageNoMetadata() throws Exception {
    File inFile = File.createTempFile("testDowngradeTo2003FCImageNoMetadata", "." + OME_XML_FORMAT);
    files.add(inFile);
    File middleFile =
        File.createTempFile("testDowngradeTo2003FCImageNoMetadataMiddle", "." + OME_XML_FORMAT);
    files.add(middleFile);
    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, middleFile, STYLESHEET_A);
    transformFileWithStream(middleFile, outputFile, STYLESHEET_B);

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

    // Should only have one root node i.e. OME node
    NodeList list = doc.getChildNodes();
    assertEquals(list.getLength(), 1);
    Node root = list.item(0);
    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);
      }
    }
  }
コード例 #2
0
  /**
   * Tests the XSLT used to downgrade from schema 2011-06 to 2010-06. An XML file with an image is
   * created and the stylesheet is applied.
   *
   * @throws Exception Thrown if an error occurred.
   */
  @Test(enabled = true)
  public void testDowngradeTo201006ImageNoMetadata() throws Exception {
    File f = File.createTempFile("testDowngradeTo201006ImageNoMetadata", "." + OME_XML_FORMAT);
    files.add(f);
    File output =
        File.createTempFile("testDowngradeTo201006ImageNoMetadataOutput", "." + OME_XML_FORMAT);
    files.add(output);
    XMLMockObjects xml = new XMLMockObjects();
    XMLWriter writer = new XMLWriter();
    writer.writeFile(f, xml.createImage(), true);

    // Dump out file for debuging
    //		File fCheckIn  = new File("/Users/andrew/Desktop/wibble1.xml");
    //		writer.writeFile(fCheckIn , xml.getRoot(), true);

    transformFileWithStream(f, output, STYLESHEET);
    Document doc = anOmeValidator.parseFileWithStreamArray(output, schemaArray);
    assertNotNull(doc);

    // Should only have one root node i.e. OME node
    NodeList list = doc.getChildNodes();
    assertEquals(list.getLength(), 1);
    Node root = list.item(0);
    assertEquals(root.getNodeName(), XMLWriter.OME_TAG);
    // now analyse the root node
    list = root.getChildNodes();
    String name;
    Node n;
    Document docSrc = anOmeValidator.parseFile(f, 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);
      }
    }
  }