pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gbaill...@apache.org
Subject svn commit: r1453395 [8/11] - in /pdfbox/trunk/xmpbox: ./ src/main/java/org/apache/xmpbox/ src/main/java/org/apache/xmpbox/schema/ src/main/java/org/apache/xmpbox/type/ src/main/java/org/apache/xmpbox/xml/ src/test/java/org/apache/xmpbox/ src/test/java...
Date Wed, 06 Mar 2013 15:57:52 GMT
Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/xml/XmpParsingException.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/xml/XmpParsingException.java?rev=1453395&r1=1453394&r2=1453395&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/xml/XmpParsingException.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/xml/XmpParsingException.java Wed Mar  6 15:57:44 2013
@@ -27,59 +27,55 @@ package org.apache.xmpbox.xml;
  * @author a183132
  * 
  */
-public class XmpParsingException extends Exception {
+public class XmpParsingException extends Exception
+{
 
-	public enum ErrorType {
-		Undefined,
-		Configuration,
-		XpacketBadStart,
-		XpacketBadEnd,
-		NoRootElement,
-		NoSchema, // undefined schema
-		InvalidPdfaSchema,
-		NoType, // undefined type
-		InvalidType,
-		Format, // weird things in serialized document
-		NoValueType,
-		RequiredProperty,
-		InvalidPrefix, // unexpected namespace prefix used
-	}
-	
-	private ErrorType errorType;
-	
-	/**
-	 * serial version uid
-	 */
-	private static final long serialVersionUID = -8843096358184702908L;
-
-	/**
-	 * Create an instance of XmpParsingException
-	 * 
-	 * @param message
-	 *            a description of the encountered problem
-	 * @param cause
-	 *            the cause of the exception
-	 */
-	public XmpParsingException(ErrorType error, String message, Throwable cause) {
-		super(message, cause);
-		this.errorType = error;
-	}
-
-	/**
-	 * Create an instance of XmpParsingException
-	 * 
-	 * @param message
-	 *            a description of the encountered problem
-	 */
-	public XmpParsingException(ErrorType error, String message) {
-		super(message);
-		this.errorType = error;
-	}
-
-	public ErrorType getErrorType() {
-		return errorType;
-	}
+    public enum ErrorType
+    {
+        Undefined, Configuration, XpacketBadStart, XpacketBadEnd, NoRootElement, NoSchema, // undefined
+                                                                                           // schema
+        InvalidPdfaSchema, NoType, // undefined type
+        InvalidType, Format, // weird things in serialized document
+        NoValueType, RequiredProperty, InvalidPrefix, // unexpected namespace
+                                                      // prefix used
+    }
+
+    private ErrorType errorType;
+
+    /**
+     * serial version uid
+     */
+    private static final long serialVersionUID = -8843096358184702908L;
+
+    /**
+     * Create an instance of XmpParsingException
+     * 
+     * @param message
+     *            a description of the encountered problem
+     * @param cause
+     *            the cause of the exception
+     */
+    public XmpParsingException(ErrorType error, String message, Throwable cause)
+    {
+        super(message, cause);
+        this.errorType = error;
+    }
+
+    /**
+     * Create an instance of XmpParsingException
+     * 
+     * @param message
+     *            a description of the encountered problem
+     */
+    public XmpParsingException(ErrorType error, String message)
+    {
+        super(message);
+        this.errorType = error;
+    }
+
+    public ErrorType getErrorType()
+    {
+        return errorType;
+    }
 
-	
-	
 }

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/xml/XmpSerializationException.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/xml/XmpSerializationException.java?rev=1453395&r1=1453394&r2=1453395&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/xml/XmpSerializationException.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/xml/XmpSerializationException.java Wed Mar  6 15:57:44 2013
@@ -27,31 +27,34 @@ package org.apache.xmpbox.xml;
  * @author a183132
  * 
  */
-public class XmpSerializationException extends Exception {
+public class XmpSerializationException extends Exception
+{
 
-	private static final long serialVersionUID = -3495894314480173555L;
+    private static final long serialVersionUID = -3495894314480173555L;
 
-	/**
-	 * Create an instance of TransformException
-	 * 
-	 * @param message
-	 *            a description of the encountered problem
-	 */
-	public XmpSerializationException(String message) {
-		super(message);
-	}
+    /**
+     * Create an instance of TransformException
+     * 
+     * @param message
+     *            a description of the encountered problem
+     */
+    public XmpSerializationException(String message)
+    {
+        super(message);
+    }
 
-	/**
-	 * Create an instance of TransformException
-	 * 
-	 * @param message
-	 *            a description of the encountered problem
-	 * @param cause
-	 *            the cause of the exception
-	 */
-	public XmpSerializationException(String message, Throwable cause) {
-		super(message, cause);
+    /**
+     * Create an instance of TransformException
+     * 
+     * @param message
+     *            a description of the encountered problem
+     * @param cause
+     *            the cause of the exception
+     */
+    public XmpSerializationException(String message, Throwable cause)
+    {
+        super(message, cause);
 
-	}
+    }
 
 }

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/xml/XmpSerializer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/xml/XmpSerializer.java?rev=1453395&r1=1453394&r2=1453395&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/xml/XmpSerializer.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/xml/XmpSerializer.java Wed Mar  6 15:57:44 2013
@@ -50,176 +50,203 @@ import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.ProcessingInstruction;
 
-public class XmpSerializer {
+public class XmpSerializer
+{
 
-	private DocumentBuilder documentBuilder = null;
+    private DocumentBuilder documentBuilder = null;
 
-	private boolean parseTypeResourceForLi = true;
+    private boolean parseTypeResourceForLi = true;
 
-	public XmpSerializer () throws XmpSerializationException {
-		// xml init
-		DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
-		try {
-			documentBuilder = builderFactory.newDocumentBuilder();
-		} catch (ParserConfigurationException e) {
-			throw new XmpSerializationException("Failed to init XmpSerializer", e);
-		}
-
-	}
-
-
-	public void serialize(XMPMetadata metadata, OutputStream os, boolean withXpacket) throws TransformerException {
-		Document doc = documentBuilder.newDocument();
-		// fill document
-		Element rdf = createRdfElement(doc,metadata, withXpacket);
-		for (XMPSchema schema : metadata.getAllSchemas()) {
-			rdf.appendChild(serializeSchema(doc, schema));
-		}
-		// save
-		save(doc, os, "UTF-8");
-	}
-
-	protected Element serializeSchema (Document doc, XMPSchema schema) {
-		// prepare schema
-		Element selem = doc.createElementNS(XmpConstants.RDF_NAMESPACE,"rdf:Description");
-		selem.setAttributeNS(XmpConstants.RDF_NAMESPACE, "rdf:about",schema.getAboutValue());
-		selem.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:"+schema.getPrefix(), schema.getNamespace());
-		// the other attributes
-		fillElementWithAttributes(selem, schema);
-		// the content
-		List<AbstractField> fields = schema.getAllProperties();
-		serializeFields(doc, selem, fields, true);
-		// return created schema
-		return selem;
-	}
-
-	public void serializeFields (Document doc, Element parent, List<AbstractField> fields, boolean wrapWithProperty) {
-		for (AbstractField field : fields) {
-
-			if (field instanceof AbstractSimpleProperty) {
-				AbstractSimpleProperty simple = (AbstractSimpleProperty)field;
-				Element esimple = doc.createElement(simple.getPrefix()+":"+simple.getPropertyName());
-				esimple.setTextContent(simple.getStringValue());
-				parent.appendChild(esimple);
-			} else if (field instanceof ArrayProperty) {
-				ArrayProperty array = (ArrayProperty)field;
-				// property
-				Element asimple = doc.createElement(array.getPrefix()+":"+array.getPropertyName());
-				parent.appendChild(asimple);
-				// attributes
-				fillElementWithAttributes(asimple, array);
-				// the array definition
-				Element econtainer = doc.createElement(XmpConstants.DEFAULT_RDF_PREFIX+":"+array.getArrayType()); 
-				asimple.appendChild(econtainer);
-				// for each element of the array
-				List<AbstractField> innerFields = array.getAllProperties();
-				serializeFields(doc, econtainer, innerFields, false);
-			} else if (field instanceof AbstractStructuredType) {
-				AbstractStructuredType structured = (AbstractStructuredType)field;
-				List<AbstractField> innerFields = structured.getAllProperties();
-				// property name attribute
-				Element listParent = parent;
-				if (wrapWithProperty) {
-					Element nstructured = doc.createElement(structured.getPrefix()+":"+structured.getPropertyName());
-					parent.appendChild(nstructured);
-					listParent = nstructured;
-				}
-
-				// element li
-				Element estructured = doc.createElement(XmpConstants.DEFAULT_RDF_PREFIX+":"+XmpConstants.LIST_NAME);
-				listParent.appendChild(estructured);
-				if (parseTypeResourceForLi) {
-					estructured.setAttribute("rdf:parseType", "Resource");
-					// all properties
-					serializeFields(doc, estructured, innerFields, true);
-				} else {
-					// element description
-					Element econtainer = doc.createElement(XmpConstants.DEFAULT_RDF_PREFIX+":"+"Description");
-					estructured.appendChild(econtainer);
-					// all properties
-					serializeFields(doc, econtainer, innerFields, true);
-				}
-			} else {
-				// XXX finish serialization classes
-				System.err.println(">> TODO >> "+field.getClass());
-			}
-		}
-
-	}
-
-	private void fillElementWithAttributes (Element target, AbstractComplexProperty property ) {
-		List<Attribute> attributes = property.getAllAttributes();
-		for (Attribute attribute : attributes) {
-			if (XmpConstants.RDF_NAMESPACE.equals(attribute.getNamespace())) {
-				target.setAttribute(XmpConstants.DEFAULT_RDF_PREFIX+":"+attribute.getName(), attribute.getValue());
-			} else if (target.getNamespaceURI().equals(attribute.getNamespace())) {
-					target.setAttribute(attribute.getName(), attribute.getValue());
-			} else {
-				target.setAttribute(attribute.getName(), attribute.getValue());
-			}
-		}
-		for (Map.Entry<String, String> ns : property.getAllNamespacesWithPrefix().entrySet()) {
-			target.setAttribute(XMLConstants.XMLNS_ATTRIBUTE+":"+ns.getValue(), ns.getKey());
-		}
-	}
-
-	protected Element createRdfElement (Document doc, XMPMetadata metadata, boolean withXpacket) {
-		// starting xpacket
-		if (withXpacket) {
-			ProcessingInstruction beginXPacket = doc
-					.createProcessingInstruction("xpacket", "begin=\""
-							+ metadata.getXpacketBegin() + "\" id=\""
-							+ metadata.getXpacketId() + "\"");
-			doc.appendChild(beginXPacket);
-		}
-		// meta element
-		Element xmpmeta = doc.createElementNS("adobe:ns:meta/", "x:xmpmeta");
-		xmpmeta.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:x","adobe:ns:meta/");
-		doc.appendChild(xmpmeta);
-		// ending xpacket
-		if (withXpacket) {
-			ProcessingInstruction endXPacket = doc
-					.createProcessingInstruction("xpacket", "end=\""+metadata
-							.getEndXPacket()+"\"");
-			doc.appendChild(endXPacket);
-		}
-		// rdf element
-		Element rdf = doc.createElementNS(XmpConstants.RDF_NAMESPACE, "rdf:RDF");
-		//		rdf.setAttributeNS(XMPSchema.NS_NAMESPACE, qualifiedName, value)
-		xmpmeta.appendChild(rdf);
-		// return the rdf element where all will be put
-		return rdf;
-	}
-
-	/**
-	 * Save the XML document to an output stream.
-	 * 
-	 * @param doc
-	 *            The XML document to save.
-	 * @param outStream
-	 *            The stream to save the document to.
-	 * @param encoding
-	 *            The encoding to save the file as.
-	 * 
-	 * @throws TransformerException
-	 *             If there is an error while saving the XML.
-	 */
-	private void save(Node doc, OutputStream outStream, String encoding)
-			throws TransformerException {
-		Transformer transformer = TransformerFactory.newInstance()
-				.newTransformer();
-		// human readable
-		transformer.setOutputProperty(OutputKeys.INDENT, "yes");
-		// indent elements
-		transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
-		// encoding
-		transformer.setOutputProperty(OutputKeys.ENCODING, encoding);
-		transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,
-				"yes");
-		// initialize StreamResult with File object to save to file
-		Result result = new StreamResult(outStream);
-		DOMSource source = new DOMSource(doc);
-		// save
-		transformer.transform(source, result);
-	}	
+    public XmpSerializer() throws XmpSerializationException
+    {
+        // xml init
+        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
+        try
+        {
+            documentBuilder = builderFactory.newDocumentBuilder();
+        }
+        catch (ParserConfigurationException e)
+        {
+            throw new XmpSerializationException("Failed to init XmpSerializer", e);
+        }
+
+    }
+
+    public void serialize(XMPMetadata metadata, OutputStream os, boolean withXpacket) throws TransformerException
+    {
+        Document doc = documentBuilder.newDocument();
+        // fill document
+        Element rdf = createRdfElement(doc, metadata, withXpacket);
+        for (XMPSchema schema : metadata.getAllSchemas())
+        {
+            rdf.appendChild(serializeSchema(doc, schema));
+        }
+        // save
+        save(doc, os, "UTF-8");
+    }
+
+    protected Element serializeSchema(Document doc, XMPSchema schema)
+    {
+        // prepare schema
+        Element selem = doc.createElementNS(XmpConstants.RDF_NAMESPACE, "rdf:Description");
+        selem.setAttributeNS(XmpConstants.RDF_NAMESPACE, "rdf:about", schema.getAboutValue());
+        selem.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:" + schema.getPrefix(), schema.getNamespace());
+        // the other attributes
+        fillElementWithAttributes(selem, schema);
+        // the content
+        List<AbstractField> fields = schema.getAllProperties();
+        serializeFields(doc, selem, fields, true);
+        // return created schema
+        return selem;
+    }
+
+    public void serializeFields(Document doc, Element parent, List<AbstractField> fields, boolean wrapWithProperty)
+    {
+        for (AbstractField field : fields)
+        {
+
+            if (field instanceof AbstractSimpleProperty)
+            {
+                AbstractSimpleProperty simple = (AbstractSimpleProperty) field;
+                Element esimple = doc.createElement(simple.getPrefix() + ":" + simple.getPropertyName());
+                esimple.setTextContent(simple.getStringValue());
+                parent.appendChild(esimple);
+            }
+            else if (field instanceof ArrayProperty)
+            {
+                ArrayProperty array = (ArrayProperty) field;
+                // property
+                Element asimple = doc.createElement(array.getPrefix() + ":" + array.getPropertyName());
+                parent.appendChild(asimple);
+                // attributes
+                fillElementWithAttributes(asimple, array);
+                // the array definition
+                Element econtainer = doc.createElement(XmpConstants.DEFAULT_RDF_PREFIX + ":" + array.getArrayType());
+                asimple.appendChild(econtainer);
+                // for each element of the array
+                List<AbstractField> innerFields = array.getAllProperties();
+                serializeFields(doc, econtainer, innerFields, false);
+            }
+            else if (field instanceof AbstractStructuredType)
+            {
+                AbstractStructuredType structured = (AbstractStructuredType) field;
+                List<AbstractField> innerFields = structured.getAllProperties();
+                // property name attribute
+                Element listParent = parent;
+                if (wrapWithProperty)
+                {
+                    Element nstructured = doc
+                            .createElement(structured.getPrefix() + ":" + structured.getPropertyName());
+                    parent.appendChild(nstructured);
+                    listParent = nstructured;
+                }
+
+                // element li
+                Element estructured = doc.createElement(XmpConstants.DEFAULT_RDF_PREFIX + ":" + XmpConstants.LIST_NAME);
+                listParent.appendChild(estructured);
+                if (parseTypeResourceForLi)
+                {
+                    estructured.setAttribute("rdf:parseType", "Resource");
+                    // all properties
+                    serializeFields(doc, estructured, innerFields, true);
+                }
+                else
+                {
+                    // element description
+                    Element econtainer = doc.createElement(XmpConstants.DEFAULT_RDF_PREFIX + ":" + "Description");
+                    estructured.appendChild(econtainer);
+                    // all properties
+                    serializeFields(doc, econtainer, innerFields, true);
+                }
+            }
+            else
+            {
+                // XXX finish serialization classes
+                System.err.println(">> TODO >> " + field.getClass());
+            }
+        }
+
+    }
+
+    private void fillElementWithAttributes(Element target, AbstractComplexProperty property)
+    {
+        List<Attribute> attributes = property.getAllAttributes();
+        for (Attribute attribute : attributes)
+        {
+            if (XmpConstants.RDF_NAMESPACE.equals(attribute.getNamespace()))
+            {
+                target.setAttribute(XmpConstants.DEFAULT_RDF_PREFIX + ":" + attribute.getName(), attribute.getValue());
+            }
+            else if (target.getNamespaceURI().equals(attribute.getNamespace()))
+            {
+                target.setAttribute(attribute.getName(), attribute.getValue());
+            }
+            else
+            {
+                target.setAttribute(attribute.getName(), attribute.getValue());
+            }
+        }
+        for (Map.Entry<String, String> ns : property.getAllNamespacesWithPrefix().entrySet())
+        {
+            target.setAttribute(XMLConstants.XMLNS_ATTRIBUTE + ":" + ns.getValue(), ns.getKey());
+        }
+    }
+
+    protected Element createRdfElement(Document doc, XMPMetadata metadata, boolean withXpacket)
+    {
+        // starting xpacket
+        if (withXpacket)
+        {
+            ProcessingInstruction beginXPacket = doc.createProcessingInstruction("xpacket",
+                    "begin=\"" + metadata.getXpacketBegin() + "\" id=\"" + metadata.getXpacketId() + "\"");
+            doc.appendChild(beginXPacket);
+        }
+        // meta element
+        Element xmpmeta = doc.createElementNS("adobe:ns:meta/", "x:xmpmeta");
+        xmpmeta.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:x", "adobe:ns:meta/");
+        doc.appendChild(xmpmeta);
+        // ending xpacket
+        if (withXpacket)
+        {
+            ProcessingInstruction endXPacket = doc.createProcessingInstruction("xpacket",
+                    "end=\"" + metadata.getEndXPacket() + "\"");
+            doc.appendChild(endXPacket);
+        }
+        // rdf element
+        Element rdf = doc.createElementNS(XmpConstants.RDF_NAMESPACE, "rdf:RDF");
+        // rdf.setAttributeNS(XMPSchema.NS_NAMESPACE, qualifiedName, value)
+        xmpmeta.appendChild(rdf);
+        // return the rdf element where all will be put
+        return rdf;
+    }
+
+    /**
+     * Save the XML document to an output stream.
+     * 
+     * @param doc
+     *            The XML document to save.
+     * @param outStream
+     *            The stream to save the document to.
+     * @param encoding
+     *            The encoding to save the file as.
+     * 
+     * @throws TransformerException
+     *             If there is an error while saving the XML.
+     */
+    private void save(Node doc, OutputStream outStream, String encoding) throws TransformerException
+    {
+        Transformer transformer = TransformerFactory.newInstance().newTransformer();
+        // human readable
+        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+        // indent elements
+        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
+        // encoding
+        transformer.setOutputProperty(OutputKeys.ENCODING, encoding);
+        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+        // initialize StreamResult with File object to save to file
+        Result result = new StreamResult(outStream);
+        DOMSource source = new DOMSource(doc);
+        // save
+        transformer.transform(source, result);
+    }
 }

Modified: pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/DoubleSameTypeSchemaTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/DoubleSameTypeSchemaTest.java?rev=1453395&r1=1453394&r2=1453395&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/DoubleSameTypeSchemaTest.java (original)
+++ pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/DoubleSameTypeSchemaTest.java Wed Mar  6 15:57:44 2013
@@ -26,7 +26,6 @@ import java.util.List;
 
 import junit.framework.Assert;
 
-import org.apache.xmpbox.XMPMetadata;
 import org.apache.xmpbox.schema.DublinCoreSchema;
 import org.apache.xmpbox.schema.XMPSchema;
 import org.apache.xmpbox.type.StructuredType;
@@ -34,59 +33,60 @@ import org.junit.Before;
 import org.junit.Test;
 
 /**
- * Test with 2 dublinCore with different prefix (Test comportment of
- * XMPMetadata)
+ * Test with 2 dublinCore with different prefix (Test comportment of XMPMetadata)
  * 
  * @author a183132
  * 
  */
-public class DoubleSameTypeSchemaTest {
+public class DoubleSameTypeSchemaTest
+{
 
-	protected XMPMetadata metadata;
+    protected XMPMetadata metadata;
 
-	@Before
-	public void testInit() throws Exception {
-		metadata = XMPMetadata.createXMPMetadata();
-	}
-
-	@Test
-	public void testDoubleDublinCore() throws Exception {
-		DublinCoreSchema dc1 = metadata.createAndAddDublinCoreSchema();
-		String ownPrefix = "test";
-		DublinCoreSchema dc2 = new DublinCoreSchema(metadata, ownPrefix);
-		metadata.addSchema(dc2);
-
-		List<String> creators = new ArrayList<String>();
-		creators.add("creator1");
-		creators.add("creator2");
-
-		String format = "application/pdf";
-		dc1.setFormat(format);
-		dc1.addCreator(creators.get(0));
-		dc1.addCreator(creators.get(1));
-
-		String coverage = "Coverage";
-		dc2.setCoverage(coverage);
-		dc2.addCreator(creators.get(0));
-		dc2.addCreator(creators.get(1));
-
-		StructuredType stDub = DublinCoreSchema.class.getAnnotation(StructuredType.class);
-		
-		// We can't use metadata.getDublinCoreSchema() due to specification of
-		// XMPBox (see Javadoc of XMPMetadata)
-		Assert.assertEquals(format, ((DublinCoreSchema) metadata.getSchema(
-				stDub.preferedPrefix(), stDub.namespace()))
-				.getFormat());
-		Assert.assertEquals(coverage, ((DublinCoreSchema) metadata.getSchema(
-				ownPrefix, stDub.namespace())).getCoverage());
-
-		List<XMPSchema> schems = metadata.getAllSchemas();
-		DublinCoreSchema dc;
-		for (XMPSchema xmpSchema : schems) {
-			dc = (DublinCoreSchema) xmpSchema;
-			Assert.assertTrue(dc.getCreators().containsAll(creators));
-		}
+    @Before
+    public void testInit() throws Exception
+    {
+        metadata = XMPMetadata.createXMPMetadata();
+    }
+
+    @Test
+    public void testDoubleDublinCore() throws Exception
+    {
+        DublinCoreSchema dc1 = metadata.createAndAddDublinCoreSchema();
+        String ownPrefix = "test";
+        DublinCoreSchema dc2 = new DublinCoreSchema(metadata, ownPrefix);
+        metadata.addSchema(dc2);
+
+        List<String> creators = new ArrayList<String>();
+        creators.add("creator1");
+        creators.add("creator2");
+
+        String format = "application/pdf";
+        dc1.setFormat(format);
+        dc1.addCreator(creators.get(0));
+        dc1.addCreator(creators.get(1));
+
+        String coverage = "Coverage";
+        dc2.setCoverage(coverage);
+        dc2.addCreator(creators.get(0));
+        dc2.addCreator(creators.get(1));
+
+        StructuredType stDub = DublinCoreSchema.class.getAnnotation(StructuredType.class);
+
+        // We can't use metadata.getDublinCoreSchema() due to specification of
+        // XMPBox (see Javadoc of XMPMetadata)
+        Assert.assertEquals(format,
+                ((DublinCoreSchema) metadata.getSchema(stDub.preferedPrefix(), stDub.namespace())).getFormat());
+        Assert.assertEquals(coverage,
+                ((DublinCoreSchema) metadata.getSchema(ownPrefix, stDub.namespace())).getCoverage());
+
+        List<XMPSchema> schems = metadata.getAllSchemas();
+        DublinCoreSchema dc;
+        for (XMPSchema xmpSchema : schems)
+        {
+            dc = (DublinCoreSchema) xmpSchema;
+            Assert.assertTrue(dc.getCreators().containsAll(creators));
+        }
 
-
-	}
+    }
 }

Modified: pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/SaveMetadataHelperTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/SaveMetadataHelperTest.java?rev=1453395&r1=1453394&r2=1453395&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/SaveMetadataHelperTest.java (original)
+++ pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/SaveMetadataHelperTest.java Wed Mar  6 15:57:44 2013
@@ -21,37 +21,38 @@
 
 package org.apache.xmpbox;
 
-import org.apache.xmpbox.XMPMetadata;
 import org.apache.xmpbox.schema.AdobePDFSchema;
 import org.apache.xmpbox.schema.DublinCoreSchema;
 import org.junit.Test;
 
-public class SaveMetadataHelperTest {
+public class SaveMetadataHelperTest
+{
 
-	@Test
-	public void testSchemaParsing() throws Exception {
-		DublinCoreSchema dc = new DublinCoreSchema(XMPMetadata.createXMPMetadata());
-		dc.setCoverage("coverage");
-		dc.addContributor("contributor1");
-		dc.addContributor("contributor2");
-		dc.addDescription("x-default", "Description");
-	}
-
-	@Test
-	public void testMetadataParsing() throws Exception {
-		XMPMetadata meta = XMPMetadata.createXMPMetadata();
-
-		DublinCoreSchema dc = meta.createAndAddDublinCoreSchema();
-		dc.setCoverage("coverage");
-		dc.addContributor("contributor1");
-		dc.addContributor("contributor2");
-		dc.addDescription("x-default", "Description");
-
-		AdobePDFSchema pdf = meta.createAndAddAdobePDFSchema();
-		pdf.setProducer("Producer");
-		pdf.setPDFVersion("1.4");
+    @Test
+    public void testSchemaParsing() throws Exception
+    {
+        DublinCoreSchema dc = new DublinCoreSchema(XMPMetadata.createXMPMetadata());
+        dc.setCoverage("coverage");
+        dc.addContributor("contributor1");
+        dc.addContributor("contributor2");
+        dc.addDescription("x-default", "Description");
+    }
+
+    @Test
+    public void testMetadataParsing() throws Exception
+    {
+        XMPMetadata meta = XMPMetadata.createXMPMetadata();
+
+        DublinCoreSchema dc = meta.createAndAddDublinCoreSchema();
+        dc.setCoverage("coverage");
+        dc.addContributor("contributor1");
+        dc.addContributor("contributor2");
+        dc.addDescription("x-default", "Description");
+
+        AdobePDFSchema pdf = meta.createAndAddAdobePDFSchema();
+        pdf.setProducer("Producer");
+        pdf.setPDFVersion("1.4");
 
-
-	}
+    }
 
 }

Modified: pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/TestXMPWithDefinedSchemas.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/TestXMPWithDefinedSchemas.java?rev=1453395&r1=1453394&r2=1453395&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/TestXMPWithDefinedSchemas.java (original)
+++ pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/TestXMPWithDefinedSchemas.java Wed Mar  6 15:57:44 2013
@@ -26,7 +26,6 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
-import org.apache.xmpbox.XMPMetadata;
 import org.apache.xmpbox.xml.DomXmpParser;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -34,38 +33,37 @@ import org.junit.runners.Parameterized;
 import org.junit.runners.Parameterized.Parameters;
 
 @RunWith(Parameterized.class)
-public class TestXMPWithDefinedSchemas {
+public class TestXMPWithDefinedSchemas
+{
 
-	
+    @Parameters
+    public static Collection<Object[]> initializeParameters() throws Exception
+    {
+        List<Object[]> data = new ArrayList<Object[]>();
+        data.add(new Object[] { "/validxmp/override_ns.rdf" });
+        data.add(new Object[] { "/validxmp/ghost2.xmp" });
+        data.add(new Object[] { "/validxmp/history2.rdf" });
+        data.add(new Object[] { "/validxmp/Notepad++_A1b.xmp" });
+        data.add(new Object[] { "/validxmp/metadata.rdf" });
+        return data;
+    }
+
+    private String path;
+
+    public TestXMPWithDefinedSchemas(String path)
+    {
+        this.path = path;
+    }
+
+    @Test
+    public void main() throws Exception
+    {
 
-	@Parameters
-	public static Collection<Object[]> initializeParameters() throws Exception 
-	{
-		List<Object[]> data = new ArrayList<Object[]>();
-		data.add(new Object [] {"/validxmp/override_ns.rdf"});
-		data.add(new Object [] {"/validxmp/ghost2.xmp"});
-		data.add(new Object [] {"/validxmp/history2.rdf"});
-		data.add(new Object [] {"/validxmp/Notepad++_A1b.xmp"});
-		data.add(new Object [] {"/validxmp/metadata.rdf"});
-		return data;
-	}
-
-	private String path;
-	
-	public TestXMPWithDefinedSchemas(String path) {
-		this.path = path;
-	}
-
-	
-	@Test
-	public void main() throws Exception {
-		
-		InputStream is = this.getClass().getResourceAsStream(path);
-		
-		DomXmpParser builder = new DomXmpParser();
-		XMPMetadata rxmp = builder.parse(is);
-		
-	}
+        InputStream is = this.getClass().getResourceAsStream(path);
+
+        DomXmpParser builder = new DomXmpParser();
+        XMPMetadata rxmp = builder.parse(is);
+
+    }
 
-	
 }

Modified: pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/XMPMetaDataTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/XMPMetaDataTest.java?rev=1453395&r1=1453394&r2=1453395&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/XMPMetaDataTest.java (original)
+++ pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/XMPMetaDataTest.java Wed Mar  6 15:57:44 2013
@@ -25,7 +25,6 @@ import java.util.List;
 
 import junit.framework.Assert;
 
-import org.apache.xmpbox.XMPMetadata;
 import org.apache.xmpbox.schema.XMPSchema;
 import org.apache.xmpbox.xml.XmpSerializationException;
 import org.junit.Before;
@@ -38,79 +37,80 @@ import org.w3c.dom.Document;
  * @author a183132
  * 
  */
-public class XMPMetaDataTest {
+public class XMPMetaDataTest
+{
 
-	protected XMPMetadata metadata;
-	protected Document parent;
-	protected XMPSchema tmp, tmp2;
-
-	@Before
-	public void init() throws Exception {
-		metadata = XMPMetadata.createXMPMetadata();
-		String tmpNsURI = "http://www.test.org/schem/";
-		tmp = new XMPSchema(metadata, tmpNsURI, "test");
-		tmp.addQualifiedBagValue("BagContainer", "Value1");
-		tmp.addQualifiedBagValue("BagContainer", "Value2");
-		tmp.addQualifiedBagValue("BagContainer", "Value3");
-
-		tmp.addUnqualifiedSequenceValue("SeqContainer", "Value1");
-		tmp.addUnqualifiedSequenceValue("SeqContainer", "Value2");
-		tmp.addUnqualifiedSequenceValue("SeqContainer", "Value3");
-
-		tmp
-				.addProperty(metadata.getTypeMapping().createText(null,"test", "simpleProperty",
-						"YEP"));
-
-		tmp2 = new XMPSchema(metadata, "http://www.space.org/schem/", "space","space");
-		tmp2.addUnqualifiedSequenceValue("SeqSpContainer", "ValueSpace1");
-		tmp2.addUnqualifiedSequenceValue("SeqSpContainer", "ValueSpace2");
-		tmp2.addUnqualifiedSequenceValue("SeqSpContainer", "ValueSpace3");
-
-		metadata.addSchema(tmp);
-
-		metadata.addSchema(tmp2);
-
-		// Check schema getting
-		Assert.assertEquals(tmp, metadata.getSchema(tmpNsURI));
-		Assert.assertNull(metadata.getSchema("THIS URI NOT EXISTS !"));
-	}
-
-	@Test
-	public void testAddingSchem() {
-
-		List<XMPSchema> vals = metadata.getAllSchemas();
-		Assert.assertTrue(vals.contains(tmp));
-		Assert.assertTrue(vals.contains(tmp2));
-	}
-
-	/*
-	 * @Test public void displayResult() throws TransformException {
-	 * System.out.println
-	 * ("info used:\n XPacketBegin:"+metadata.getXpacketBegin()+
-	 * "\n XPacketID:"+metadata.getXpacketId());
-	 * SaveMetadataHelper.serialize(metadata, true, System.out);
-	 * 
-	 * }
-	 */
-
-	@Test(expected = org.apache.xmpbox.xml.XmpSerializationException.class)
-	public void testTransformerExceptionMessage() throws XmpSerializationException {
-		throw new XmpSerializationException("TEST");
-	}
-
-	@Test(expected = org.apache.xmpbox.xml.XmpSerializationException.class)
-	public void testTransformerExceptionWithCause() throws XmpSerializationException {
-		throw new XmpSerializationException("TEST", new Throwable());
-	}
-
-	@Test
-	public void testInitMetaDataWithInfo() throws Exception {
-		String xpacketBegin = "TESTBEG", xpacketId = "TESTID", xpacketBytes = "TESTBYTES", xpacketEncoding = "TESTENCOD";
-		metadata = XMPMetadata.createXMPMetadata(xpacketBegin, xpacketId, xpacketBytes,
-				xpacketEncoding);
-		Assert.assertEquals(xpacketBegin, metadata.getXpacketBegin());
-		Assert.assertEquals(xpacketId, metadata.getXpacketId());
-		Assert.assertEquals(xpacketBytes, metadata.getXpacketBytes());
-		Assert.assertEquals(xpacketEncoding, metadata.getXpacketEncoding());
-	}
+    protected XMPMetadata metadata;
+    protected Document parent;
+    protected XMPSchema tmp, tmp2;
+
+    @Before
+    public void init() throws Exception
+    {
+        metadata = XMPMetadata.createXMPMetadata();
+        String tmpNsURI = "http://www.test.org/schem/";
+        tmp = new XMPSchema(metadata, tmpNsURI, "test");
+        tmp.addQualifiedBagValue("BagContainer", "Value1");
+        tmp.addQualifiedBagValue("BagContainer", "Value2");
+        tmp.addQualifiedBagValue("BagContainer", "Value3");
+
+        tmp.addUnqualifiedSequenceValue("SeqContainer", "Value1");
+        tmp.addUnqualifiedSequenceValue("SeqContainer", "Value2");
+        tmp.addUnqualifiedSequenceValue("SeqContainer", "Value3");
+
+        tmp.addProperty(metadata.getTypeMapping().createText(null, "test", "simpleProperty", "YEP"));
+
+        tmp2 = new XMPSchema(metadata, "http://www.space.org/schem/", "space", "space");
+        tmp2.addUnqualifiedSequenceValue("SeqSpContainer", "ValueSpace1");
+        tmp2.addUnqualifiedSequenceValue("SeqSpContainer", "ValueSpace2");
+        tmp2.addUnqualifiedSequenceValue("SeqSpContainer", "ValueSpace3");
+
+        metadata.addSchema(tmp);
+
+        metadata.addSchema(tmp2);
+
+        // Check schema getting
+        Assert.assertEquals(tmp, metadata.getSchema(tmpNsURI));
+        Assert.assertNull(metadata.getSchema("THIS URI NOT EXISTS !"));
+    }
+
+    @Test
+    public void testAddingSchem()
+    {
+
+        List<XMPSchema> vals = metadata.getAllSchemas();
+        Assert.assertTrue(vals.contains(tmp));
+        Assert.assertTrue(vals.contains(tmp2));
+    }
+
+    /*
+     * @Test public void displayResult() throws TransformException { System.out.println
+     * ("info used:\n XPacketBegin:"+metadata.getXpacketBegin()+ "\n XPacketID:"+metadata.getXpacketId());
+     * SaveMetadataHelper.serialize(metadata, true, System.out);
+     * 
+     * }
+     */
+
+    @Test(expected = org.apache.xmpbox.xml.XmpSerializationException.class)
+    public void testTransformerExceptionMessage() throws XmpSerializationException
+    {
+        throw new XmpSerializationException("TEST");
+    }
+
+    @Test(expected = org.apache.xmpbox.xml.XmpSerializationException.class)
+    public void testTransformerExceptionWithCause() throws XmpSerializationException
+    {
+        throw new XmpSerializationException("TEST", new Throwable());
+    }
+
+    @Test
+    public void testInitMetaDataWithInfo() throws Exception
+    {
+        String xpacketBegin = "TESTBEG", xpacketId = "TESTID", xpacketBytes = "TESTBYTES", xpacketEncoding = "TESTENCOD";
+        metadata = XMPMetadata.createXMPMetadata(xpacketBegin, xpacketId, xpacketBytes, xpacketEncoding);
+        Assert.assertEquals(xpacketBegin, metadata.getXpacketBegin());
+        Assert.assertEquals(xpacketId, metadata.getXpacketId());
+        Assert.assertEquals(xpacketBytes, metadata.getXpacketBytes());
+        Assert.assertEquals(xpacketEncoding, metadata.getXpacketEncoding());
+    }
 }

Modified: pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/parser/DeserializationTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/parser/DeserializationTest.java?rev=1453395&r1=1453394&r2=1453395&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/parser/DeserializationTest.java (original)
+++ pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/parser/DeserializationTest.java Wed Mar  6 15:57:44 2013
@@ -34,291 +34,310 @@ import org.apache.xmpbox.schema.XMPSchem
 import org.apache.xmpbox.type.ThumbnailType;
 import org.apache.xmpbox.xml.DomXmpParser;
 import org.apache.xmpbox.xml.XmpParsingException;
-import org.apache.xmpbox.xml.XmpSerializer;
 import org.apache.xmpbox.xml.XmpParsingException.ErrorType;
+import org.apache.xmpbox.xml.XmpSerializer;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
-public class DeserializationTest {
+public class DeserializationTest
+{
+
+    protected ByteArrayOutputStream bos;
+
+    protected XmpSerializer serializer;
+
+    @Before
+    public void init() throws Exception
+    {
+        bos = new ByteArrayOutputStream();
+        serializer = new XmpSerializer();
+    }
+
+    @Test
+    public void testStructuredRecursive() throws Exception
+    {
+        InputStream fis = DomXmpParser.class.getResourceAsStream("/org/apache/xmpbox/parser/structured_recursive.xml");
+
+        DomXmpParser xdb = new DomXmpParser();
+
+        xdb.parse(fis);
+
+    }
+
+    @Test
+    public void testEmptyLi() throws Exception
+    {
+        InputStream fis = DomXmpParser.class.getResourceAsStream("/org/apache/xmpbox/parser/empty_list.xml");
+
+        DomXmpParser xdb = new DomXmpParser();
+
+        xdb.parse(fis);
+
+    }
+
+    @Test
+    public void testEmptyLi2() throws Exception
+    {
+        InputStream fis = DomXmpParser.class.getResourceAsStream("/validxmp/emptyli.xml");
+
+        DomXmpParser xdb = new DomXmpParser();
+
+        XMPMetadata meta = xdb.parse(fis);
+        DublinCoreSchema dc = meta.getDublinCoreSchema();
+        dc.getCreatorsProperty();
+    }
+
+    @Test
+    public void testGetTitle() throws Exception
+    {
+        InputStream fis = DomXmpParser.class.getResourceAsStream("/validxmp/emptyli.xml");
+
+        DomXmpParser xdb = new DomXmpParser();
+
+        XMPMetadata meta = xdb.parse(fis);
+        DublinCoreSchema dc = meta.getDublinCoreSchema();
+        String s = dc.getTitle(null);
+        Assert.assertEquals("title value", s);
+    }
+
+    @Test
+    public void testAltBagSeq() throws Exception
+    {
+        InputStream fis = DomXmpParser.class.getResourceAsStream("/org/apache/xmpbox/parser/AltBagSeqTest.xml");
+
+        DomXmpParser xdb = new DomXmpParser();
+
+        xdb.parse(fis);
+        // XMPMetadata metadata=xdb.parse(fis);
+        // SaveMetadataHelper.serialize(metadata, true, System.out);
+    }
+
+    @Test
+    public void testIsartorStyleWithThumbs() throws Exception
+    {
+
+        InputStream fis = DomXmpParser.class.getResourceAsStream("/org/apache/xmpbox/parser/ThumbisartorStyle.xml");
+
+        DomXmpParser xdb = new DomXmpParser();
+
+        XMPMetadata metadata = xdb.parse(fis);
+
+        // <xmpMM:DocumentID>
+        Assert.assertEquals("uuid:09C78666-2F91-3A9C-92AF-3691A6D594F7", metadata.getXMPMediaManagementSchema()
+                .getDocumentID());
+
+        // <xmp:CreateDate>
+        // <xmp:ModifyDate>
+        // <xmp:MetadataDate>
+        Assert.assertEquals(DateConverter.toCalendar("2008-01-18T16:59:54+01:00"), metadata.getXMPBasicSchema()
+                .getCreateDate());
+        Assert.assertEquals(DateConverter.toCalendar("2008-01-18T16:59:54+01:00"), metadata.getXMPBasicSchema()
+                .getModifyDate());
+        Assert.assertEquals(DateConverter.toCalendar("2008-01-18T16:59:54+01:00"), metadata.getXMPBasicSchema()
+                .getMetadataDate());
+
+        // THUMBNAILS TEST
+        List<ThumbnailType> thumbs = metadata.getXMPBasicSchema().getThumbnailsProperty();
+        Assert.assertNotNull(thumbs);
+        Assert.assertEquals(2, thumbs.size());
+
+        ThumbnailType thumb = thumbs.get(0);
+        Assert.assertEquals(new Integer(162), thumb.getHeight());
+        Assert.assertEquals(new Integer(216), thumb.getWidth());
+        Assert.assertEquals("JPEG", thumb.getFormat());
+        Assert.assertEquals("/9j/4AAQSkZJRgABAgEASABIAAD", thumb.getImage());
+
+        thumb = thumbs.get(1);
+        Assert.assertEquals(new Integer(162), thumb.getHeight());
+        Assert.assertEquals(new Integer(216), thumb.getWidth());
+        Assert.assertEquals("JPEG", thumb.getFormat());
+        Assert.assertEquals("/9j/4AAQSkZJRgABAgEASABIAAD", thumb.getImage());
+
+    }
+
+    @Test
+    public void testWithNoXPacketStart() throws Exception
+    {
+        InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/noxpacket.xml");
+
+        DomXmpParser xdb = new DomXmpParser();
+        try
+        {
+            xdb.parse(fis);
+            Assert.fail("Should fail during parse");
+        }
+        catch (XmpParsingException e)
+        {
+            Assert.assertEquals(ErrorType.XpacketBadStart, e.getErrorType());
+        }
+    }
+
+    @Test
+    public void testWithNoXPacketEnd() throws Exception
+    {
+        InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/noxpacketend.xml");
+
+        DomXmpParser xdb = new DomXmpParser();
+        try
+        {
+            xdb.parse(fis);
+            Assert.fail("Should fail during parse");
+        }
+        catch (XmpParsingException e)
+        {
+            Assert.assertEquals(ErrorType.XpacketBadEnd, e.getErrorType());
+        }
+    }
+
+    @Test
+    public void testWithNoRDFElement() throws Exception
+    {
+        InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/noroot.xml");
+
+        DomXmpParser xdb = new DomXmpParser();
+        try
+        {
+            xdb.parse(fis);
+            Assert.fail("Should fail during parse");
+        }
+        catch (XmpParsingException e)
+        {
+            Assert.assertEquals(ErrorType.Format, e.getErrorType());
+        }
+    }
+
+    @Test
+    public void testWithTwoRDFElement() throws Exception
+    {
+        InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/tworoot.xml");
+
+        DomXmpParser xdb = new DomXmpParser();
+        try
+        {
+            xdb.parse(fis);
+            Assert.fail("Should fail during parse");
+        }
+        catch (XmpParsingException e)
+        {
+            Assert.assertEquals(ErrorType.Format, e.getErrorType());
+        }
+    }
+
+    @Test
+    public void testWithInvalidRDFElementPrefix() throws Exception
+    {
+        InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/invalidroot2.xml");
+
+        DomXmpParser xdb = new DomXmpParser();
+        try
+        {
+            xdb.parse(fis);
+            Assert.fail("Should fail during parse");
+        }
+        catch (XmpParsingException e)
+        {
+            Assert.assertEquals(ErrorType.Format, e.getErrorType());
+        }
+    }
+
+    @Test
+    public void testWithRDFRootAsText() throws Exception
+    {
+        InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/invalidroot.xml");
+
+        DomXmpParser xdb = new DomXmpParser();
+        try
+        {
+            xdb.parse(fis);
+            Assert.fail("Should fail during parse");
+        }
+        catch (XmpParsingException e)
+        {
+            Assert.assertEquals(ErrorType.Format, e.getErrorType());
+        }
+    }
+
+    @Test
+    public void testUndefinedSchema() throws Exception
+    {
+        InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/undefinedschema.xml");
+
+        DomXmpParser xdb = new DomXmpParser();
+        try
+        {
+            xdb.parse(fis);
+            Assert.fail("Should fail during parse");
+        }
+        catch (XmpParsingException e)
+        {
+            Assert.assertEquals(ErrorType.NoSchema, e.getErrorType());
+        }
+    }
+
+    @Test
+    public void testUndefinedPropertyWithDefinedSchema() throws Exception
+    {
+        InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/undefinedpropertyindefinedschema.xml");
+
+        DomXmpParser xdb = new DomXmpParser();
+        try
+        {
+            xdb.parse(fis);
+            Assert.fail("Should fail during parse");
+        }
+        catch (XmpParsingException e)
+        {
+            Assert.assertEquals(ErrorType.NoType, e.getErrorType());
+        }
+    }
+
+    @Test
+    public void testUndefinedStructuredWithDefinedSchema() throws Exception
+    {
+        InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/undefinedstructuredindefinedschema.xml");
+
+        DomXmpParser xdb = new DomXmpParser();
+        try
+        {
+            xdb.parse(fis);
+            Assert.fail("Should fail during parse");
+        }
+        catch (XmpParsingException e)
+        {
+            Assert.assertEquals(ErrorType.NoValueType, e.getErrorType());
+        }
+    }
+
+    @Test
+    public void testRdfAboutFound() throws Exception
+    {
+        InputStream fis = DomXmpParser.class.getResourceAsStream("/validxmp/emptyli.xml");
+        DomXmpParser xdb = new DomXmpParser();
+        XMPMetadata meta = xdb.parse(fis);
+        List<XMPSchema> schemas = meta.getAllSchemas();
+        for (XMPSchema xmpSchema : schemas)
+        {
+            Assert.assertNotNull(xmpSchema.getAboutAttribute());
+        }
+    }
+
+    @Test
+    public void testWihtAttributesAsProperties() throws Exception
+    {
+        InputStream fis = DomXmpParser.class.getResourceAsStream("/validxmp/attr_as_props.xml");
+        DomXmpParser xdb = new DomXmpParser();
+        XMPMetadata meta = xdb.parse(fis);
+
+        AdobePDFSchema pdf = meta.getAdobePDFSchema();
+        Assert.assertEquals("GPL Ghostscript 8.64", pdf.getProducer());
+
+        DublinCoreSchema dc = meta.getDublinCoreSchema();
+        Assert.assertEquals("application/pdf", dc.getFormat());
+
+        XMPBasicSchema basic = meta.getXMPBasicSchema();
+        Assert.assertNotNull(basic.getCreateDate());
 
-	protected ByteArrayOutputStream bos;
-	
-	protected XmpSerializer serializer;
-
-	@Before
-	public void init() throws Exception {
-		bos = new ByteArrayOutputStream();
-		serializer = new XmpSerializer();
-	}
-
-
-
-	@Test
-	public void testStructuredRecursive () throws Exception {
-		InputStream fis = DomXmpParser.class
-				.getResourceAsStream("/org/apache/xmpbox/parser/structured_recursive.xml");
-
-		DomXmpParser xdb = new DomXmpParser();
-
-		xdb.parse(fis);
-
-	}
-
-	@Test
-	public void testEmptyLi () throws Exception {
-		InputStream fis = DomXmpParser.class
-				.getResourceAsStream("/org/apache/xmpbox/parser/empty_list.xml");
-
-		DomXmpParser xdb = new DomXmpParser();
-
-		xdb.parse(fis);
-
-	}
-
-	@Test
-	public void testEmptyLi2 () throws Exception {
-		InputStream fis = DomXmpParser.class
-				.getResourceAsStream("/validxmp/emptyli.xml");
-
-		DomXmpParser xdb = new DomXmpParser();
-
-		XMPMetadata meta = xdb.parse(fis);
-		DublinCoreSchema dc = meta.getDublinCoreSchema();
-		dc.getCreatorsProperty();
-	}
-
-	@Test
-	public void testGetTitle () throws Exception {
-		InputStream fis = DomXmpParser.class
-				.getResourceAsStream("/validxmp/emptyli.xml");
-
-		DomXmpParser xdb = new DomXmpParser();
-
-		XMPMetadata meta = xdb.parse(fis);
-		DublinCoreSchema dc = meta.getDublinCoreSchema();
-		String s = dc.getTitle(null);
-		Assert.assertEquals("title value", s);
-	}
-
-
-	@Test
-	public void testAltBagSeq() throws Exception {
-		InputStream fis = DomXmpParser.class
-				.getResourceAsStream("/org/apache/xmpbox/parser/AltBagSeqTest.xml");
-
-		DomXmpParser xdb = new DomXmpParser();
-
-		xdb.parse(fis);
-		// XMPMetadata metadata=xdb.parse(fis);
-		// SaveMetadataHelper.serialize(metadata, true, System.out);
-	}
-
-	@Test
-	public void testIsartorStyleWithThumbs() throws Exception {
-
-		InputStream fis = DomXmpParser.class
-				.getResourceAsStream("/org/apache/xmpbox/parser/ThumbisartorStyle.xml");
-
-
-		DomXmpParser xdb = new DomXmpParser();
-
-		XMPMetadata metadata = xdb.parse(fis);
-
-		// <xmpMM:DocumentID>
-		Assert.assertEquals("uuid:09C78666-2F91-3A9C-92AF-3691A6D594F7",
-				metadata.getXMPMediaManagementSchema().getDocumentID());
-
-		// <xmp:CreateDate>
-		// <xmp:ModifyDate>
-		// <xmp:MetadataDate>
-		Assert.assertEquals(DateConverter
-				.toCalendar("2008-01-18T16:59:54+01:00"), metadata
-				.getXMPBasicSchema().getCreateDate());
-		Assert.assertEquals(DateConverter
-				.toCalendar("2008-01-18T16:59:54+01:00"), metadata
-				.getXMPBasicSchema().getModifyDate());
-		Assert.assertEquals(DateConverter
-				.toCalendar("2008-01-18T16:59:54+01:00"), metadata
-				.getXMPBasicSchema().getMetadataDate());
-
-		// THUMBNAILS TEST
-		List<ThumbnailType> thumbs = metadata.getXMPBasicSchema()
-				.getThumbnailsProperty();
-		Assert.assertNotNull(thumbs);
-		Assert.assertEquals(2, thumbs.size());
-
-		ThumbnailType thumb = thumbs.get(0);
-		Assert.assertEquals(new Integer(162), thumb.getHeight());
-		Assert.assertEquals(new Integer(216), thumb.getWidth());
-		Assert.assertEquals("JPEG", thumb.getFormat());
-		Assert.assertEquals("/9j/4AAQSkZJRgABAgEASABIAAD", thumb.getImage());
-
-		thumb = thumbs.get(1);
-		Assert.assertEquals(new Integer(162), thumb.getHeight());
-		Assert.assertEquals(new Integer(216), thumb.getWidth());
-		Assert.assertEquals("JPEG", thumb.getFormat());
-		Assert.assertEquals("/9j/4AAQSkZJRgABAgEASABIAAD", thumb.getImage());
-
-
-	}
-
-
-	@Test
-	public void testWithNoXPacketStart () throws Exception {
-		InputStream fis = DomXmpParser.class
-				.getResourceAsStream("/invalidxmp/noxpacket.xml");
-
-		DomXmpParser xdb = new DomXmpParser();
-		try {
-			xdb.parse(fis);
-			Assert.fail("Should fail during parse");
-		} catch (XmpParsingException e) {
-			Assert.assertEquals(ErrorType.XpacketBadStart, e.getErrorType());
-		}
-	}
-
-	@Test
-	public void testWithNoXPacketEnd () throws Exception {
-		InputStream fis = DomXmpParser.class
-				.getResourceAsStream("/invalidxmp/noxpacketend.xml");
-
-		DomXmpParser xdb = new DomXmpParser();
-		try {
-			xdb.parse(fis);
-			Assert.fail("Should fail during parse");
-		} catch (XmpParsingException e) {
-			Assert.assertEquals(ErrorType.XpacketBadEnd, e.getErrorType());
-		}
-	}
-
-	@Test
-	public void testWithNoRDFElement () throws Exception {
-		InputStream fis = DomXmpParser.class
-				.getResourceAsStream("/invalidxmp/noroot.xml");
-
-		DomXmpParser xdb = new DomXmpParser();
-		try {
-			xdb.parse(fis);
-			Assert.fail("Should fail during parse");
-		} catch (XmpParsingException e) {
-			Assert.assertEquals(ErrorType.Format, e.getErrorType());
-		}
-	}
-
-	@Test
-	public void testWithTwoRDFElement () throws Exception {
-		InputStream fis = DomXmpParser.class
-				.getResourceAsStream("/invalidxmp/tworoot.xml");
-
-		DomXmpParser xdb = new DomXmpParser();
-		try {
-			xdb.parse(fis);
-			Assert.fail("Should fail during parse");
-		} catch (XmpParsingException e) {
-			Assert.assertEquals(ErrorType.Format, e.getErrorType());
-		}
-	}
-
-	@Test
-	public void testWithInvalidRDFElementPrefix () throws Exception {
-		InputStream fis = DomXmpParser.class
-				.getResourceAsStream("/invalidxmp/invalidroot2.xml");
-
-		DomXmpParser xdb = new DomXmpParser();
-		try {
-			xdb.parse(fis);
-			Assert.fail("Should fail during parse");
-		} catch (XmpParsingException e) {
-			Assert.assertEquals(ErrorType.Format, e.getErrorType());
-		}
-	}
-
-	@Test
-	public void testWithRDFRootAsText() throws Exception {
-		InputStream fis = DomXmpParser.class
-				.getResourceAsStream("/invalidxmp/invalidroot.xml");
-
-		DomXmpParser xdb = new DomXmpParser();
-		try {
-			xdb.parse(fis);
-			Assert.fail("Should fail during parse");
-		} catch (XmpParsingException e) {
-			Assert.assertEquals(ErrorType.Format, e.getErrorType());
-		}
-	}
-
-	@Test
-	public void testUndefinedSchema() throws Exception {
-		InputStream fis = DomXmpParser.class
-				.getResourceAsStream("/invalidxmp/undefinedschema.xml");
-
-		DomXmpParser xdb = new DomXmpParser();
-		try {
-			xdb.parse(fis);
-			Assert.fail("Should fail during parse");
-		} catch (XmpParsingException e) {
-			Assert.assertEquals(ErrorType.NoSchema, e.getErrorType());
-		}
-	}
-
-	@Test
-	public void testUndefinedPropertyWithDefinedSchema() throws Exception {
-		InputStream fis = DomXmpParser.class
-				.getResourceAsStream("/invalidxmp/undefinedpropertyindefinedschema.xml");
-
-		DomXmpParser xdb = new DomXmpParser();
-		try {
-			xdb.parse(fis);
-			Assert.fail("Should fail during parse");
-		} catch (XmpParsingException e) {
-			Assert.assertEquals(ErrorType.NoType, e.getErrorType());
-		}
-	}
-
-	@Test
-	public void testUndefinedStructuredWithDefinedSchema() throws Exception {
-		InputStream fis = DomXmpParser.class
-				.getResourceAsStream("/invalidxmp/undefinedstructuredindefinedschema.xml");
-
-		DomXmpParser xdb = new DomXmpParser();
-		try {
-			xdb.parse(fis);
-			Assert.fail("Should fail during parse");
-		} catch (XmpParsingException e) {
-			Assert.assertEquals(ErrorType.NoValueType, e.getErrorType());
-		}
-	}
-
-	@Test
-	public void testRdfAboutFound() throws Exception {
-		InputStream fis = DomXmpParser.class
-				.getResourceAsStream("/validxmp/emptyli.xml");
-		DomXmpParser xdb = new DomXmpParser();
-		XMPMetadata meta = xdb.parse(fis);
-		List<XMPSchema> schemas = meta.getAllSchemas();
-		for (XMPSchema xmpSchema : schemas) {
-			Assert.assertNotNull(xmpSchema.getAboutAttribute());
-		}
-	}
-
-	@Test
-	public void testWihtAttributesAsProperties() throws Exception {
-		InputStream fis = DomXmpParser.class
-				.getResourceAsStream("/validxmp/attr_as_props.xml");
-		DomXmpParser xdb = new DomXmpParser();
-		XMPMetadata meta = xdb.parse(fis);
-
-		AdobePDFSchema pdf = meta.getAdobePDFSchema();
-		Assert.assertEquals("GPL Ghostscript 8.64", pdf.getProducer());
-		
-		DublinCoreSchema dc = meta.getDublinCoreSchema();
-		Assert.assertEquals("application/pdf", dc.getFormat());
-
-		XMPBasicSchema basic = meta.getXMPBasicSchema();
-		Assert.assertNotNull(basic.getCreateDate());
-		
-	}
+    }
 
-	
 }

Modified: pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/parser/PropMappingTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/parser/PropMappingTest.java?rev=1453395&r1=1453394&r2=1453395&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/parser/PropMappingTest.java (original)
+++ pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/parser/PropMappingTest.java Wed Mar  6 15:57:44 2013
@@ -21,21 +21,19 @@
 
 package org.apache.xmpbox.parser;
 
-import junit.framework.Assert;
-
 import org.apache.xmpbox.type.PropertiesDescription;
 import org.junit.Before;
-import org.junit.Test;
-
-public class PropMappingTest {
 
-	protected PropertiesDescription propMap;
-	protected String nsURI = "http://www.test.org/PropMap#";
+public class PropMappingTest
+{
 
-	@Before
-	public void init() {
-		propMap = new PropertiesDescription();
-	}
+    protected PropertiesDescription propMap;
+    protected String nsURI = "http://www.test.org/PropMap#";
 
+    @Before
+    public void init()
+    {
+        propMap = new PropertiesDescription();
+    }
 
 }

Modified: pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/schema/AbstractSchemaTester.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/schema/AbstractSchemaTester.java?rev=1453395&r1=1453394&r2=1453395&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/schema/AbstractSchemaTester.java (original)
+++ pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/schema/AbstractSchemaTester.java Wed Mar  6 15:57:44 2013
@@ -1,4 +1,4 @@
- /*****************************************************************************
+/*****************************************************************************
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -27,7 +27,6 @@ import java.util.List;
 import junit.framework.Assert;
 
 import org.apache.xmpbox.XMPMetadata;
-import org.apache.xmpbox.schema.XMPSchema;
 import org.apache.xmpbox.type.AbstractSimpleProperty;
 import org.apache.xmpbox.type.ArrayProperty;
 import org.apache.xmpbox.type.Cardinality;
@@ -37,164 +36,183 @@ import org.apache.xmpbox.type.Types;
 import org.apache.xmpbox.xml.DomXmpParser;
 import org.junit.Test;
 
-public abstract class AbstractSchemaTester {
+public abstract class AbstractSchemaTester
+{
 
-	
-	protected XMPMetadata xmp;
-	
-	protected String fieldName;
-	
-	protected Types type;
-	
-	protected Cardinality cardinality;
-
-	protected TypeMapping typeMapping = null;
-	
-	protected DomXmpParser builder;
-	
-	public void before () throws Exception {
-		builder = new DomXmpParser();
-		xmp = XMPMetadata.createXMPMetadata();
-		typeMapping = xmp.getTypeMapping();
-	}
-
-	protected abstract XMPSchema getSchema ();
-	
-	protected Class<? extends XMPSchema> getSchemaClass () {
-		return getSchema().getClass();
-	}
-	
-	public AbstractSchemaTester (String fieldName, Types type, Cardinality card) {
-		this.fieldName = fieldName;
-		this.type = type;
-		this.cardinality = card;
-	}
-
-	@Test
-	public void testInitializedToNull() throws Exception {
-		// default method
-		Assert.assertNull(getSchema().getProperty(fieldName));
-		// accessor
-		if (cardinality==Cardinality.Simple) {
-			String getter = TypeTestingHelper.calculateSimpleGetter(fieldName);
-	    	Method get = getSchemaClass().getMethod(getter, new Class[0]);
-	    	Object result = get.invoke(getSchema(), new Object [0]);
-	    	Assert.assertNull(result);
-		} else {
-			// arrays
-			String getter = TypeTestingHelper.calculateArrayGetter(fieldName);
-	    	Method get = getSchemaClass().getMethod(getter, new Class[0]);
-	    	Object result = get.invoke(getSchema(), new Object [0]);
-	    	Assert.assertNull(result);
-		}
-		
-	}
-
-	@Test
-	public void testSettingValue() throws Exception {
-		if (cardinality!=Cardinality.Simple) return;
-		// only test simple properties
-		Object value = TypeTestingHelper.getJavaValue(type);
-		AbstractSimpleProperty property = getSchema().instanciateSimple(fieldName, value);
-		getSchema().addProperty(property);
-		String qn = getPropertyQualifiedName(fieldName);
-		Assert.assertNotNull(getSchema().getProperty(fieldName));
-		// check other properties not modified
-		List<Field> fields = TypeTestingHelper.getXmpFields(getSchemaClass());
-		for (Field field : fields) {
-			// do not check the current name
-			String fqn = getPropertyQualifiedName(field.get(null).toString());
-			if (!fqn.equals(qn)) {
-				Assert.assertNull(getSchema().getProperty(fqn));
-			}
-		}
-	}
-
-	@Test
-	public void testSettingValueInArray() throws Exception {
-		if (cardinality==Cardinality.Simple) return;
-		// only test array properties
-		Object value = TypeTestingHelper.getJavaValue(type);
-		AbstractSimpleProperty property = getSchema().instanciateSimple(fieldName, value);
-		switch (cardinality) {
-		case Seq:
-			getSchema().addUnqualifiedSequenceValue(property.getPropertyName(), property);
-			break;
-		case Bag:
-			getSchema().addBagValue(property.getPropertyName(), property);
-			break;
-		default :
-			throw new Exception ("Unexpected case in test : "+cardinality.name());
-		}
-		String qn = getPropertyQualifiedName(fieldName);
-		Assert.assertNotNull(getSchema().getProperty(fieldName));
-		// check other properties not modified
-		List<Field> fields = TypeTestingHelper.getXmpFields(getSchemaClass());
-		for (Field field : fields) {
-			// do not check the current name
-			String fqn = getPropertyQualifiedName(field.get(null).toString());
-			if (!fqn.equals(qn)) {
-				Assert.assertNull(getSchema().getProperty(fqn));
-			}
-		}
-	}
+    protected XMPMetadata xmp;
+
+    protected String fieldName;
+
+    protected Types type;
+
+    protected Cardinality cardinality;
+
+    protected TypeMapping typeMapping = null;
+
+    protected DomXmpParser builder;
+
+    public void before() throws Exception
+    {
+        builder = new DomXmpParser();
+        xmp = XMPMetadata.createXMPMetadata();
+        typeMapping = xmp.getTypeMapping();
+    }
+
+    protected abstract XMPSchema getSchema();
+
+    protected Class<? extends XMPSchema> getSchemaClass()
+    {
+        return getSchema().getClass();
+    }
+
+    public AbstractSchemaTester(String fieldName, Types type, Cardinality card)
+    {
+        this.fieldName = fieldName;
+        this.type = type;
+        this.cardinality = card;
+    }
 
-	
     @Test
-    public void testPropertySetterSimple () throws Exception {
-		if (cardinality!=Cardinality.Simple) return;
-    	String setter = TypeTestingHelper.calculateSimpleSetter(fieldName)+"Property";
-    	Object value = TypeTestingHelper.getJavaValue(type);
-    	AbstractSimpleProperty asp = typeMapping.instanciateSimpleProperty(
-    			getSchema().getNamespace(), 
-    			getSchema().getPrefix(), fieldName, value, type);
-    	Method set = getSchemaClass().getMethod(setter, new Class<?>[] {type.getImplementingClass()} );
-    	set.invoke(getSchema(), new Object [] {asp});
-    	// check property set
-    	AbstractSimpleProperty stored = (AbstractSimpleProperty)getSchema().getProperty(fieldName);
-    	Assert.assertEquals(value, stored.getValue());
-    	// check getter
-    	String getter = TypeTestingHelper.calculateSimpleGetter(fieldName)+"Property";
-    	Method get = getSchemaClass().getMethod(getter, new Class[0]);
-    	Object result = get.invoke(getSchema(), new Object [0]);
-    	Assert.assertTrue(type.getImplementingClass().isAssignableFrom(result.getClass()));
-    	Assert.assertEquals(asp, result);
+    public void testInitializedToNull() throws Exception
+    {
+        // default method
+        Assert.assertNull(getSchema().getProperty(fieldName));
+        // accessor
+        if (cardinality == Cardinality.Simple)
+        {
+            String getter = TypeTestingHelper.calculateSimpleGetter(fieldName);
+            Method get = getSchemaClass().getMethod(getter, new Class[0]);
+            Object result = get.invoke(getSchema(), new Object[0]);
+            Assert.assertNull(result);
+        }
+        else
+        {
+            // arrays
+            String getter = TypeTestingHelper.calculateArrayGetter(fieldName);
+            Method get = getSchemaClass().getMethod(getter, new Class[0]);
+            Object result = get.invoke(getSchema(), new Object[0]);
+            Assert.assertNull(result);
+        }
+
     }
 
     @Test
-    public void testPropertySetterInArray () throws Exception {
-		if (cardinality==Cardinality.Simple) return;
-		// add value
-    	String setter = "add"+TypeTestingHelper.calculateFieldNameForMethod(fieldName);
-//    	TypeDescription<AbstractSimpleProperty> td = typeMapping.getSimpleDescription(type);
-    	Object value1 = TypeTestingHelper.getJavaValue(type);
-    	Method set = getSchemaClass().getMethod(setter, new Class<?>[] {TypeTestingHelper.getJavaType(type)} );
-    	set.invoke(getSchema(), new Object [] {value1});
-    	// retrieve complex property
-    	String getter = TypeTestingHelper.calculateArrayGetter(fieldName)+"Property";
-    	Method getcp = getSchemaClass().getMethod(getter, new Class[0]);
-    	Object ocp = getcp.invoke(getSchema(), new Object[0]);
-    	Assert.assertTrue(ocp instanceof ArrayProperty);
-    	ArrayProperty cp = (ArrayProperty)ocp;
-    	// check size is ok (1)
-    	Assert.assertEquals(1,cp.getContainer().getAllProperties().size());
-    	// add a new one
-    	Object value2 = TypeTestingHelper.getJavaValue(type);
-    	set.invoke(getSchema(), new Object [] {value2});
-    	Assert.assertEquals(2,cp.getContainer().getAllProperties().size());
-    	// remove the first
-    	String remover = "remove"+TypeTestingHelper.calculateFieldNameForMethod(fieldName);
-    	Method remove = getSchemaClass().getMethod(remover, new Class<?>[] {TypeTestingHelper.getJavaType(type)});
-    	remove.invoke(getSchema(), value1);
-    	Assert.assertEquals(1,cp.getContainer().getAllProperties().size());
-    	
-    }
-	
-	
-	protected String getPropertyQualifiedName (String name) {
-		StringBuilder sb = new StringBuilder();
-		sb.append(getSchema().getPrefix()).append(":").append(name);
-		return sb.toString();
-	}
-	
+    public void testSettingValue() throws Exception
+    {
+        if (cardinality != Cardinality.Simple)
+            return;
+        // only test simple properties
+        Object value = TypeTestingHelper.getJavaValue(type);
+        AbstractSimpleProperty property = getSchema().instanciateSimple(fieldName, value);
+        getSchema().addProperty(property);
+        String qn = getPropertyQualifiedName(fieldName);
+        Assert.assertNotNull(getSchema().getProperty(fieldName));
+        // check other properties not modified
+        List<Field> fields = TypeTestingHelper.getXmpFields(getSchemaClass());
+        for (Field field : fields)
+        {
+            // do not check the current name
+            String fqn = getPropertyQualifiedName(field.get(null).toString());
+            if (!fqn.equals(qn))
+            {
+                Assert.assertNull(getSchema().getProperty(fqn));
+            }
+        }
+    }
+
+    @Test
+    public void testSettingValueInArray() throws Exception
+    {
+        if (cardinality == Cardinality.Simple)
+            return;
+        // only test array properties
+        Object value = TypeTestingHelper.getJavaValue(type);
+        AbstractSimpleProperty property = getSchema().instanciateSimple(fieldName, value);
+        switch (cardinality)
+        {
+        case Seq:
+            getSchema().addUnqualifiedSequenceValue(property.getPropertyName(), property);
+            break;
+        case Bag:
+            getSchema().addBagValue(property.getPropertyName(), property);
+            break;
+        default:
+            throw new Exception("Unexpected case in test : " + cardinality.name());
+        }
+        String qn = getPropertyQualifiedName(fieldName);
+        Assert.assertNotNull(getSchema().getProperty(fieldName));
+        // check other properties not modified
+        List<Field> fields = TypeTestingHelper.getXmpFields(getSchemaClass());
+        for (Field field : fields)
+        {
+            // do not check the current name
+            String fqn = getPropertyQualifiedName(field.get(null).toString());
+            if (!fqn.equals(qn))
+            {
+                Assert.assertNull(getSchema().getProperty(fqn));
+            }
+        }
+    }
+
+    @Test
+    public void testPropertySetterSimple() throws Exception
+    {
+        if (cardinality != Cardinality.Simple)
+            return;
+        String setter = TypeTestingHelper.calculateSimpleSetter(fieldName) + "Property";
+        Object value = TypeTestingHelper.getJavaValue(type);
+        AbstractSimpleProperty asp = typeMapping.instanciateSimpleProperty(getSchema().getNamespace(), getSchema()
+                .getPrefix(), fieldName, value, type);
+        Method set = getSchemaClass().getMethod(setter, new Class<?>[] { type.getImplementingClass() });
+        set.invoke(getSchema(), new Object[] { asp });
+        // check property set
+        AbstractSimpleProperty stored = (AbstractSimpleProperty) getSchema().getProperty(fieldName);
+        Assert.assertEquals(value, stored.getValue());
+        // check getter
+        String getter = TypeTestingHelper.calculateSimpleGetter(fieldName) + "Property";
+        Method get = getSchemaClass().getMethod(getter, new Class[0]);
+        Object result = get.invoke(getSchema(), new Object[0]);
+        Assert.assertTrue(type.getImplementingClass().isAssignableFrom(result.getClass()));
+        Assert.assertEquals(asp, result);
+    }
+
+    @Test
+    public void testPropertySetterInArray() throws Exception
+    {
+        if (cardinality == Cardinality.Simple)
+            return;
+        // add value
+        String setter = "add" + TypeTestingHelper.calculateFieldNameForMethod(fieldName);
+        // TypeDescription<AbstractSimpleProperty> td =
+        // typeMapping.getSimpleDescription(type);
+        Object value1 = TypeTestingHelper.getJavaValue(type);
+        Method set = getSchemaClass().getMethod(setter, new Class<?>[] { TypeTestingHelper.getJavaType(type) });
+        set.invoke(getSchema(), new Object[] { value1 });
+        // retrieve complex property
+        String getter = TypeTestingHelper.calculateArrayGetter(fieldName) + "Property";
+        Method getcp = getSchemaClass().getMethod(getter, new Class[0]);
+        Object ocp = getcp.invoke(getSchema(), new Object[0]);
+        Assert.assertTrue(ocp instanceof ArrayProperty);
+        ArrayProperty cp = (ArrayProperty) ocp;
+        // check size is ok (1)
+        Assert.assertEquals(1, cp.getContainer().getAllProperties().size());
+        // add a new one
+        Object value2 = TypeTestingHelper.getJavaValue(type);
+        set.invoke(getSchema(), new Object[] { value2 });
+        Assert.assertEquals(2, cp.getContainer().getAllProperties().size());
+        // remove the first
+        String remover = "remove" + TypeTestingHelper.calculateFieldNameForMethod(fieldName);
+        Method remove = getSchemaClass().getMethod(remover, new Class<?>[] { TypeTestingHelper.getJavaType(type) });
+        remove.invoke(getSchema(), value1);
+        Assert.assertEquals(1, cp.getContainer().getAllProperties().size());
+
+    }
+
+    protected String getPropertyQualifiedName(String name)
+    {
+        StringBuilder sb = new StringBuilder();
+        sb.append(getSchema().getPrefix()).append(":").append(name);
+        return sb.toString();
+    }
+
 }



Mime
View raw message