
java.fedora.server.test.METSToFOXMLTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fcrepo-client Show documentation
Show all versions of fcrepo-client Show documentation
The Fedora Client is a Java Library that allows API access to a Fedora Repository. The client is typically one part of a full Fedora installation.
The newest version!
/*
* -----------------------------------------------------------------------------
*
* License and Copyright: The contents of this file are subject to the
* Apache License, Version 2.0 (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of
* the License at
* http://www.fedora-commons.org/licenses.
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The entire file consists of original code.
* Copyright © 2008 Fedora Commons, Inc.
*
Copyright © 2002-2007 The Rector and Visitors of the University of
* Virginia and Cornell University
* All rights reserved.
*
* -----------------------------------------------------------------------------
*/
package fedora.server.test;
import junit.framework.TestCase;
import fedora.server.storage.types.BasicDigitalObject;
import fedora.server.storage.types.DigitalObject;
import fedora.server.storage.translation.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
/**
* Tests the METS deserializer and FOXML serializer
* by opening a METS file, deserializing it, re-serializing it as FOXML,
* and sending it to STDOUT.
*
* @author [email protected]
* @version $Id: METSToFOXMLTest.java 5220 2006-11-20 13:52:20Z cwilper $
*/
public class METSToFOXMLTest
extends TestCase {
protected File inFile = null;
protected File outFile = null;
protected DigitalObject obj = null;
protected void setUp() {
// Set the METS input file and FOXML output file
inFile=new File("TestIngestFiles/bmech-simple-image-4res.xml");
outFile=new File("TestExportFiles/OUT-foxml.xml");
System.setProperty("fedoraServerHost", "localhost");
System.setProperty("fedoraServerPort", "80");
FileInputStream in=null;
try {
in=new FileInputStream(inFile);
} catch (IOException ioe) {
System.out.println("Error on FOXML file inputstream: " + ioe.getMessage());
ioe.printStackTrace();
}
try {
// deserialize
METSLikeDODeserializer deser=new METSLikeDODeserializer();
FOXMLDOSerializer ser=new FOXMLDOSerializer();
HashMap desermap=new HashMap();
HashMap sermap=new HashMap();
desermap.put("metslikefedora1", deser);
DOTranslatorImpl trans=new DOTranslatorImpl(sermap, desermap);
obj=new BasicDigitalObject();
System.out.println("Deserializing METS input...");
trans.deserialize(in, obj, "metslikefedora1", "UTF-8", DOTranslationUtility.DESERIALIZE_INSTANCE);
System.out.println("Digital Object PID= " + obj.getPid());
// serialize
sermap.put("foxml1.0", ser);
System.out.println("Re-serializing as FOXML...");
System.out.println("Writing file to... " + outFile.getPath());
FileOutputStream out = new FileOutputStream(outFile);
//ByteArrayOutputStream out=new ByteArrayOutputStream();
trans.serialize(obj, out, "foxml1.0", "UTF-8", DOTranslationUtility.SERIALIZE_STORAGE_INTERNAL);
System.out.println("Done.");
//System.out.println("Here it is:");
//System.out.println(out.toString("UTF-8"));
} catch (Exception e) {
System.out.println("Error: (" + e.getClass().getName() + "):" + e.getMessage());
e.printStackTrace();
}
}
public void testDigitalObject() {
assertNotNull("Failure: digital object PID is null.", obj.getPid());
assertNotNull("Failure: digital object audit record set is null.", obj.getAuditRecords());
assertNotNull("Failure: digital object cmodel is null.", obj.getContentModelId());
//assertNotNull("Failure: digital object createDate is null.", obj.getCreateDate());
assertNotNull("Failure: digital object label is null.", obj.getLabel());
//assertNotNull("Failure: digital object modDate is null.", obj.getLastModDate());
assertNotNull("Failure: digital object namespaceMap is null.", obj.getNamespaceMapping());
//assertNotNull("Failure: digital object state is null.", obj.getState());
//assertNotNull("Failure: digital object ftype is null.", obj.getFedoraObjectType());
assertNotNull("Failure: digital object ownerID is null.", obj.getOwnerId());
//assertNotNull("Failure: digital object PID is null.", obj.datastreamIdIterator());
//assertNotNull("Failure: digital object PID is null.", obj.disseminatorIdIterator());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy