Author: tilman Date: Sat Jan 31 18:57:43 2015 New Revision: 1656236 URL: http://svn.apache.org/r1656236 Log: PDFBOX-1979: use pseudorandom and fuzztest for tests, by Guillaume Bailleul
Added: pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/AbstractTypeTester.java - copied, changed from r1656216, pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TypeTestingHelper.java Removed: pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TypeTestingHelper.java Modified: pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/schema/AbstractSchemaTester.java pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/schema/DublinCoreTest.java pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/schema/PhotoshopSchemaTest.java pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/AbstractStructuredTypeTester.java pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestJobType.java pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestLayerType.java pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestResourceEventType.java pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestResourceRefType.java pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestThumbnailType.java pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestVersionType.java 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=1656236&r1=1656235&r2=1656236&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 Sat Jan 31 18:57:43 2015 @@ -1,216 +1,274 @@ -/***************************************************************************** - * 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 - * regarding copyright ownership. The ASF licenses this file - * to you under 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.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -package org.apache.xmpbox.schema; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.List; -import org.apache.xmpbox.XMPMetadata; -import org.apache.xmpbox.type.AbstractSimpleProperty; -import org.apache.xmpbox.type.ArrayProperty; -import org.apache.xmpbox.type.Cardinality; -import org.apache.xmpbox.type.TypeMapping; -import org.apache.xmpbox.type.TypeTestingHelper; -import org.apache.xmpbox.type.Types; -import org.apache.xmpbox.xml.DomXmpParser; -import org.junit.Assert; -import org.junit.Test; - -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)); - } - } - } - - @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(); - } - -} +/***************************************************************************** + * 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 + * regarding copyright ownership. The ASF licenses this file + * to you under 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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +package org.apache.xmpbox.schema; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.List; +import java.util.Random; + +import org.apache.xmpbox.XMPMetadata; +import org.apache.xmpbox.type.AbstractSimpleProperty; +import org.apache.xmpbox.type.ArrayProperty; +import org.apache.xmpbox.type.Cardinality; +import org.apache.xmpbox.type.TypeMapping; +import org.apache.xmpbox.type.AbstractTypeTester; +import org.apache.xmpbox.type.Types; +import org.apache.xmpbox.xml.DomXmpParser; +import org.junit.Assert; +import org.junit.Test; + +public abstract class AbstractSchemaTester extends AbstractTypeTester +{ + + 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 + { + XMPSchema schema = getSchema(); + // default method + Assert.assertNull(schema.getProperty(fieldName)); + // accessor + if (cardinality == Cardinality.Simple) + { + String getter = calculateSimpleGetter(fieldName); + Method get = getSchemaClass().getMethod(getter, new Class[0]); + Object result = get.invoke(schema, new Object[0]); + Assert.assertNull(result); + } + else + { + // arrays + String getter = calculateArrayGetter(fieldName); + Method get = getSchemaClass().getMethod(getter, new Class[0]); + Object result = get.invoke(schema, new Object[0]); + Assert.assertNull(result); + } + + } + + @Test + public void testSettingValue() throws Exception + { + internalTestSettingValue(); + } + + @Test + public void testRandomSettingValue() throws Exception + { + initializeSeed(new Random()); + for (int i=0; i < RAND_LOOP_COUNT;i++) { + internalTestSettingValue(); + } + } + + private void internalTestSettingValue() throws Exception { + if (cardinality != Cardinality.Simple) + return; + XMPSchema schema = getSchema(); + // only test simple properties + Object value = getJavaValue(type); + AbstractSimpleProperty property = schema.instanciateSimple(fieldName, value); + schema.addProperty(property); + String qn = getPropertyQualifiedName(fieldName); + Assert.assertNotNull(schema.getProperty(fieldName)); + // check other properties not modified + List<Field> fields = 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(schema.getProperty(fqn)); + } + } + } + + @Test + public void testSettingValueInArray() throws Exception + { + internalTestSettingValueInArray(); + } + + @Test + public void testRandomSettingValueInArray() throws Exception + { + initializeSeed(new Random()); + for (int i=0; i < RAND_LOOP_COUNT;i++) { + internalTestSettingValueInArray(); + } + } + + private void internalTestSettingValueInArray() throws Exception { + if (cardinality == Cardinality.Simple) + return; + XMPSchema schema = getSchema(); + // only test array properties + Object value = getJavaValue(type); + AbstractSimpleProperty property = schema.instanciateSimple(fieldName, value); + switch (cardinality) + { + case Seq: + schema.addUnqualifiedSequenceValue(property.getPropertyName(), property); + break; + case Bag: + schema.addBagValue(property.getPropertyName(), property); + break; + default: + throw new Exception("Unexpected case in test : " + cardinality.name()); + } + String qn = getPropertyQualifiedName(fieldName); + Assert.assertNotNull(schema.getProperty(fieldName)); + // check other properties not modified + List<Field> fields = 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(schema.getProperty(fqn)); + } + } + } + + @Test + public void testPropertySetterSimple() throws Exception + { + internalTestPropertySetterSimple(); + } + + @Test + public void testRandomPropertySetterSimple() throws Exception + { + initializeSeed(new Random()); + for (int i=0; i < RAND_LOOP_COUNT;i++) { + internalTestPropertySetterSimple(); + } + } + + private void internalTestPropertySetterSimple() throws Exception { + if (cardinality != Cardinality.Simple) + return; + XMPSchema schema = getSchema(); + String setter = calculateSimpleSetter(fieldName) + "Property"; + Object value = getJavaValue(type); + AbstractSimpleProperty asp = typeMapping.instanciateSimpleProperty(schema.getNamespace(), schema + .getPrefix(), fieldName, value, type); + Method set = getSchemaClass().getMethod(setter, new Class<?>[] { type.getImplementingClass() }); + set.invoke(schema, new Object[] { asp }); + // check property set + AbstractSimpleProperty stored = (AbstractSimpleProperty) schema.getProperty(fieldName); + Assert.assertEquals(value, stored.getValue()); + // check getter + String getter = calculateSimpleGetter(fieldName) + "Property"; + Method get = getSchemaClass().getMethod(getter, new Class[0]); + Object result = get.invoke(schema, new Object[0]); + Assert.assertTrue(type.getImplementingClass().isAssignableFrom(result.getClass())); + Assert.assertEquals(asp, result); + } + + @Test + public void testPropertySetterInArray() throws Exception { + internalTestPropertySetterInArray(); + } + + @Test + public void testRandomPropertySetterInArray() throws Exception + { + initializeSeed(new Random()); + for (int i=0; i < RAND_LOOP_COUNT;i++) { + internalTestPropertySetterInArray(); + } + } + + private void internalTestPropertySetterInArray() throws Exception { + if (cardinality == Cardinality.Simple) + return; + XMPSchema schema = getSchema(); + // add value + String setter = "add" + calculateFieldNameForMethod(fieldName); + // TypeDescription<AbstractSimpleProperty> td = + // typeMapping.getSimpleDescription(type); + Object value1 = getJavaValue(type); + Method set = getSchemaClass().getMethod(setter, new Class<?>[] { getJavaType(type) }); + set.invoke(schema, new Object[] { value1 }); + // retrieve complex property + String getter = calculateArrayGetter(fieldName) + "Property"; + Method getcp = getSchemaClass().getMethod(getter, new Class[0]); + Object ocp = getcp.invoke(schema, 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 = getJavaValue(type); + set.invoke(schema, new Object[] { value2 }); + Assert.assertEquals(2, cp.getContainer().getAllProperties().size()); + // remove the first + String remover = "remove" + calculateFieldNameForMethod(fieldName); + Method remove = getSchemaClass().getMethod(remover, new Class<?>[] { getJavaType(type) }); + remove.invoke(schema, 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(); + } + +} Modified: pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/schema/DublinCoreTest.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/schema/DublinCoreTest.java?rev=1656236&r1=1656235&r2=1656236&view=diff ============================================================================== --- pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/schema/DublinCoreTest.java (original) +++ pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/schema/DublinCoreTest.java Sat Jan 31 18:57:43 2015 @@ -34,18 +34,15 @@ import org.junit.runners.Parameterized.P public class DublinCoreTest extends AbstractSchemaTester { - protected DublinCoreSchema schema = null; - public DublinCoreSchema getSchema() { - return schema; + return xmp.createAndAddDublinCoreSchema(); } @Before public void before() throws Exception { super.before(); - schema = xmp.createAndAddDublinCoreSchema(); } public DublinCoreTest(String fieldName, Types type, Cardinality card) Modified: pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/schema/PhotoshopSchemaTest.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/schema/PhotoshopSchemaTest.java?rev=1656236&r1=1656235&r2=1656236&view=diff ============================================================================== --- pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/schema/PhotoshopSchemaTest.java (original) +++ pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/schema/PhotoshopSchemaTest.java Sat Jan 31 18:57:43 2015 @@ -34,12 +34,10 @@ import org.junit.runners.Parameterized.P public class PhotoshopSchemaTest extends AbstractSchemaTester { - protected PhotoshopSchema schema = null; - @Override public PhotoshopSchema getSchema() { - return schema; + return xmp.createAndAddPhotoshopSchema(); } @Before @@ -47,7 +45,6 @@ public class PhotoshopSchemaTest extends public void before() throws Exception { super.before(); - schema = xmp.createAndAddPhotoshopSchema(); } public PhotoshopSchemaTest(String fieldName, Types type, Cardinality card) Modified: pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/AbstractStructuredTypeTester.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/AbstractStructuredTypeTester.java?rev=1656236&r1=1656235&r2=1656236&view=diff ============================================================================== --- pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/AbstractStructuredTypeTester.java (original) +++ pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/AbstractStructuredTypeTester.java Sat Jan 31 18:57:43 2015 @@ -1,123 +1,171 @@ -/***************************************************************************** - * - * 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 - * regarding copyright ownership. The ASF licenses this file - * to you under 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.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -package org.apache.xmpbox.type; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.List; -import org.apache.xmpbox.XMPMetadata; -import org.apache.xmpbox.xml.DomXmpParser; -import org.junit.Assert; -import org.junit.Test; - -public abstract class AbstractStructuredTypeTester -{ - - protected XMPMetadata xmp; - - protected String fieldName; - - protected Types type; - - protected Class<? extends AbstractStructuredType> clz; - - protected TypeMapping typeMapping = null; - - protected DomXmpParser builder; - - public void before() throws Exception - { - builder = new DomXmpParser(); - xmp = XMPMetadata.createXMPMetadata(); - typeMapping = xmp.getTypeMapping(); - } - - public AbstractStructuredTypeTester(Class<? extends AbstractStructuredType> clz, String fieldName, Types type) - { - this.clz = clz; - this.fieldName = fieldName; - this.type = type; - } - - protected abstract AbstractStructuredType getStructured(); - - @Test - public void testInitializedToNull() throws Exception - { - // default method - Assert.assertNull(getStructured().getProperty(fieldName)); - // accessor - Method get = clz.getMethod(TypeTestingHelper.calculateSimpleGetter(fieldName), new Class[0]); - Object result = get.invoke(getStructured(), new Object[0]); - Assert.assertNull(result); - - } - - @Test - public void testSettingValue() throws Exception - { - Object value = TypeTestingHelper.getJavaValue(type); - getStructured().addSimpleProperty(fieldName, value); - Assert.assertNotNull(getStructured().getProperty(fieldName)); - // check other properties not modified - List<Field> fields = TypeTestingHelper.getXmpFields(clz); - for (Field field : fields) - { - // do not check the current name - String name = field.get(null).toString(); - if (!name.equals(fieldName)) - { - Assert.assertNull(getStructured().getProperty(name)); - } - } - } - - @Test - public void testPropertyType() throws Exception - { - Object value = TypeTestingHelper.getJavaValue(type); - getStructured().addSimpleProperty(fieldName, value); - Assert.assertNotNull(getStructured().getProperty(fieldName)); - // check property type - AbstractSimpleProperty asp = (AbstractSimpleProperty) getStructured().getProperty(fieldName); - Assert.assertEquals(type.getImplementingClass(), asp.getClass()); - } - - @Test - public void testSetter() throws Exception - { - String setter = TypeTestingHelper.calculateSimpleSetter(fieldName); - Object value = TypeTestingHelper.getJavaValue(type); - Method set = clz.getMethod(setter, new Class<?>[] { TypeTestingHelper.getJavaType(type) }); - set.invoke(getStructured(), new Object[] { value }); - // check property set - Assert.assertEquals(value, ((AbstractSimpleProperty) getStructured().getProperty(fieldName)).getValue()); - // check getter - Method get = clz.getMethod(TypeTestingHelper.calculateSimpleGetter(fieldName), new Class[0]); - Object result = get.invoke(getStructured(), new Object[0]); - // Assert.assertEquals(getJavaType(td),result.getClass()); - Assert.assertTrue(TypeTestingHelper.getJavaType(type).isAssignableFrom(result.getClass())); - Assert.assertEquals(value, result); - - } - -} +/***************************************************************************** + * + * 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 + * regarding copyright ownership. The ASF licenses this file + * to you under 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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +package org.apache.xmpbox.type; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.List; +import java.util.Random; + +import org.apache.xmpbox.XMPMetadata; +import org.apache.xmpbox.xml.DomXmpParser; +import org.junit.Assert; +import org.junit.Test; + +public abstract class AbstractStructuredTypeTester extends AbstractTypeTester +{ + + protected XMPMetadata xmp; + + protected String fieldName; + + protected Types type; + + protected Class<? extends AbstractStructuredType> clz; + + protected TypeMapping typeMapping = null; + + protected DomXmpParser builder; + + public void before() throws Exception + { + builder = new DomXmpParser(); + xmp = XMPMetadata.createXMPMetadata(); + typeMapping = xmp.getTypeMapping(); + } + + public AbstractStructuredTypeTester(Class<? extends AbstractStructuredType> clz, String fieldName, Types type) + { + this.clz = clz; + this.fieldName = fieldName; + this.type = type; + } + + protected abstract AbstractStructuredType getStructured(); + + @Test + public void testInitializedToNull() throws Exception + { + AbstractStructuredType structured = getStructured(); + // default method + Assert.assertNull(structured.getProperty(fieldName)); + // accessor + Method get = clz.getMethod(calculateSimpleGetter(fieldName), new Class[0]); + Object result = get.invoke(structured, new Object[0]); + Assert.assertNull(result); + + } + + @Test + public void testSettingValue() throws Exception + { + internalTestSettingValue(); + } + + @Test + public void testRandomSettingValue() throws Exception + { + initializeSeed(new Random()); + for (int i=0; i < RAND_LOOP_COUNT;i++) { + internalTestSettingValue(); + } + } + + private void internalTestSettingValue () throws Exception + { + AbstractStructuredType structured = getStructured(); + Object value = getJavaValue(type); + structured.addSimpleProperty(fieldName, value); + Assert.assertNotNull(structured.getProperty(fieldName)); + // check other properties not modified + List<Field> fields = getXmpFields(clz); + for (Field field : fields) + { + // do not check the current name + String name = field.get(null).toString(); + if (!name.equals(fieldName)) + { + Assert.assertNull(structured.getProperty(name)); + } + } + } + + + @Test + public void testPropertyType() throws Exception + { + internalTestPropertyType(); + } + + @Test + public void testRandomPropertyType() throws Exception + { + initializeSeed(new Random()); + for (int i=0; i < RAND_LOOP_COUNT;i++) { + internalTestPropertyType(); + } + } + + + private void internalTestPropertyType () throws Exception + { + AbstractStructuredType structured = getStructured(); + Object value = getJavaValue(type); + structured.addSimpleProperty(fieldName, value); + Assert.assertNotNull(structured.getProperty(fieldName)); + // check property type + AbstractSimpleProperty asp = (AbstractSimpleProperty) structured.getProperty(fieldName); + Assert.assertEquals(type.getImplementingClass(), asp.getClass()); + } + + + @Test + public void testSetter() throws Exception + { + internalTestSetter(); + } + + @Test + public void testRandomSetter() throws Exception + { + initializeSeed(new Random()); + for (int i=0; i < RAND_LOOP_COUNT;i++) { + internalTestSetter(); + } + } + + private void internalTestSetter () throws Exception + { + AbstractStructuredType structured = getStructured(); + String setter = calculateSimpleSetter(fieldName); + Object value = getJavaValue(type); + Method set = clz.getMethod(setter, new Class<?>[] { getJavaType(type) }); + set.invoke(structured, new Object[] { value }); + // check property set + Assert.assertEquals(value, ((AbstractSimpleProperty) structured.getProperty(fieldName)).getValue()); + // check getter + Method get = clz.getMethod(calculateSimpleGetter(fieldName), new Class[0]); + Object result = get.invoke(structured, new Object[0]); + Assert.assertTrue(getJavaType(type).isAssignableFrom(result.getClass())); + Assert.assertEquals(value, result); + } +} Copied: pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/AbstractTypeTester.java (from r1656216, pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TypeTestingHelper.java) URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/AbstractTypeTester.java?p2=pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/AbstractTypeTester.java&p1=pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TypeTestingHelper.java&r1=1656216&r2=1656236&rev=1656236&view=diff ============================================================================== --- pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TypeTestingHelper.java (original) +++ pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/AbstractTypeTester.java Sat Jan 31 18:57:43 2015 @@ -1,134 +1,139 @@ -/***************************************************************************** - * 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 - * regarding copyright ownership. The ASF licenses this file - * to you under 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.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -package org.apache.xmpbox.type; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.List; -import java.util.Random; -import java.util.UUID; - -public final class TypeTestingHelper -{ - - public static String calculateSimpleGetter(String name) - { - StringBuilder sb = new StringBuilder(3 + name.length()); - sb.append("get").append(calculateFieldNameForMethod(name)); - return sb.toString(); - } - - public static String calculateArrayGetter(String name) - { - StringBuilder sb = new StringBuilder(4 + name.length()); - String fn = calculateFieldNameForMethod(name); - sb.append("get").append(fn); - if (!fn.endsWith("s")) - { - sb.append("s"); - } - return sb.toString(); - } - - public static String calculateSimpleSetter(String name) - { - StringBuilder sb = new StringBuilder(3 + name.length()); - sb.append("set").append(calculateFieldNameForMethod(name)); - return sb.toString(); - } - - public static String calculateFieldNameForMethod(String name) - { - StringBuilder sb = new StringBuilder(name.length()); - sb.append(name.substring(0, 1).toUpperCase()).append(name.substring(1)); - return sb.toString(); - } - - public static Class<?> getJavaType(Types type) - { - if (type.getImplementingClass() == TextType.class) - { - return String.class; - } - else if (type.getImplementingClass() == DateType.class) - { - return Calendar.class; - } - else if (type.getImplementingClass() == IntegerType.class) - { - return Integer.class; - } - else if (TextType.class.isAssignableFrom(type.getImplementingClass())) - { - return String.class; - } - else - { - throw new IllegalArgumentException("Type not expected in test : " + type.getImplementingClass()); - } - } - - public static Object getJavaValue(Types type) - { - if (type.getImplementingClass() == TextType.class) - { - return UUID.randomUUID().toString(); - } - else if (type.getImplementingClass() == DateType.class) - { - // use random because test are too fast (generate same calendar - // twice) - Calendar calendar = Calendar.getInstance(); - Random rand = new Random(); - calendar.setTimeInMillis(rand.nextLong()); - return calendar; - } - else if (type.getImplementingClass() == IntegerType.class) - { - return new Integer(14); - } - else if (TextType.class.isAssignableFrom(type.getImplementingClass())) - { - // all derived from TextType - return UUID.randomUUID().toString(); - } - else - { - throw new IllegalArgumentException("Type not expected in test : " + type.getImplementingClass()); - } - } - - public static List<Field> getXmpFields(Class<?> clz) - { - Field[] fields = clz.getFields(); - List<Field> result = new ArrayList<Field>(fields.length); - for (Field field : fields) - { - if (field.getAnnotation(PropertyType.class) != null) - { - result.add(field); - } - } - return result; - } - -} +/***************************************************************************** +/***************************************************************************** + * 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 + * regarding copyright ownership. The ASF licenses this file + * to you under 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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +package org.apache.xmpbox.type; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; +import java.util.Random; + +public abstract class AbstractTypeTester +{ + + private static final long COUNTER_SEED = 0; + + private static final long MAX_COUNTER = Long.MAX_VALUE; + + public static final int RAND_LOOP_COUNT = 50; + + + private Random counterRandom = new Random(COUNTER_SEED); + + protected void initializeSeed (Random rand) { + this.counterRandom = rand; + } + + public String calculateSimpleGetter(String name) + { + StringBuilder sb = new StringBuilder(3 + name.length()); + sb.append("get").append(calculateFieldNameForMethod(name)); + return sb.toString(); + } + + public String calculateArrayGetter(String name) + { + StringBuilder sb = new StringBuilder(4 + name.length()); + String fn = calculateFieldNameForMethod(name); + sb.append("get").append(fn); + if (!fn.endsWith("s")) + { + sb.append("s"); + } + return sb.toString(); + } + + public String calculateSimpleSetter(String name) + { + StringBuilder sb = new StringBuilder(3 + name.length()); + sb.append("set").append(calculateFieldNameForMethod(name)); + return sb.toString(); + } + + public String calculateFieldNameForMethod(String name) + { + StringBuilder sb = new StringBuilder(name.length()); + sb.append(name.substring(0, 1).toUpperCase()).append(name.substring(1)); + return sb.toString(); + } + + public Class<?> getJavaType(Types type) + { + if (type.getImplementingClass() == TextType.class) + { + return String.class; + } + else if (type.getImplementingClass() == DateType.class) + { + return Calendar.class; + } + else if (type.getImplementingClass() == IntegerType.class) + { + return Integer.class; + } + else if (TextType.class.isAssignableFrom(type.getImplementingClass())) + { + return String.class; + } + else + { + throw new IllegalArgumentException("Type not expected in test : " + type.getImplementingClass()); + } + } + + public Object getJavaValue(Types type) + { + if (TextType.class.isAssignableFrom(type.getImplementingClass())) + { + return "Text_String_"+ counterRandom.nextLong()%MAX_COUNTER; + } + else if (type.getImplementingClass() == DateType.class) + { + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(counterRandom.nextLong()%MAX_COUNTER); + return calendar; + } + else if (type.getImplementingClass() == IntegerType.class) + { + return new Integer(counterRandom.nextInt()); + } + else + { + throw new IllegalArgumentException("Type not expected in test : " + type.getImplementingClass()); + } + } + + public List<Field> getXmpFields(Class<?> clz) + { + Field[] fields = clz.getFields(); + List<Field> result = new ArrayList<Field>(fields.length); + for (Field field : fields) + { + if (field.getAnnotation(PropertyType.class) != null) + { + result.add(field); + } + } + return result; + } + +} Modified: pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestJobType.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestJobType.java?rev=1656236&r1=1656235&r2=1656236&view=diff ============================================================================== --- pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestJobType.java (original) +++ pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestJobType.java Sat Jan 31 18:57:43 2015 @@ -1,69 +1,66 @@ -/***************************************************************************** - * - * 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 - * regarding copyright ownership. The ASF licenses this file - * to you under 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.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -package org.apache.xmpbox.type; - -import java.util.ArrayList; -import java.util.Collection; - -import org.junit.Before; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -@RunWith(Parameterized.class) -public class TestJobType extends AbstractStructuredTypeTester -{ - - protected JobType structured = null; - - @Before - public void before() throws Exception - { - super.before(); - structured = new JobType(xmp, "job"); - } - - public TestJobType(Class<? extends AbstractStructuredType> clz, String field, Types type) - { - super(clz, field, type); - } - - @Override - protected AbstractStructuredType getStructured() - { - return structured; - } - - @Parameters - public static Collection<Object[]> initializeParameters() throws Exception - { - Collection<Object[]> result = new ArrayList<Object[]>(); - - result.add(new Object[] { JobType.class, "id", Types.Text }); - result.add(new Object[] { JobType.class, "name", Types.Text }); - result.add(new Object[] { JobType.class, "url", Types.URL }); - - return result; - - } - -} +/***************************************************************************** + * + * 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 + * regarding copyright ownership. The ASF licenses this file + * to you under 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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +package org.apache.xmpbox.type; + +import java.util.ArrayList; +import java.util.Collection; + +import org.junit.Before; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +@RunWith(Parameterized.class) +public class TestJobType extends AbstractStructuredTypeTester +{ + + @Before + public void before() throws Exception + { + super.before(); + } + + public TestJobType(Class<? extends AbstractStructuredType> clz, String field, Types type) + { + super(clz, field, type); + } + + @Override + protected AbstractStructuredType getStructured() + { + return new JobType(xmp, "job"); + } + + @Parameters + public static Collection<Object[]> initializeParameters() throws Exception + { + Collection<Object[]> result = new ArrayList<Object[]>(); + + result.add(new Object[] { JobType.class, "id", Types.Text }); + result.add(new Object[] { JobType.class, "name", Types.Text }); + result.add(new Object[] { JobType.class, "url", Types.URL }); + + return result; + + } + +} Modified: pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestLayerType.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestLayerType.java?rev=1656236&r1=1656235&r2=1656236&view=diff ============================================================================== --- pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestLayerType.java (original) +++ pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestLayerType.java Sat Jan 31 18:57:43 2015 @@ -1,68 +1,65 @@ -/***************************************************************************** - * - * 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 - * regarding copyright ownership. The ASF licenses this file - * to you under 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.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -package org.apache.xmpbox.type; - -import java.util.ArrayList; -import java.util.Collection; - -import org.junit.Before; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -@RunWith(Parameterized.class) -public class TestLayerType extends AbstractStructuredTypeTester -{ - - protected LayerType structured = null; - - @Before - public void before() throws Exception - { - super.before(); - structured = new LayerType(xmp); - } - - public TestLayerType(Class<? extends AbstractStructuredType> clz, String field, Types type) - { - super(clz, field, type); - } - - @Override - protected AbstractStructuredType getStructured() - { - return structured; - } - - @Parameters - public static Collection<Object[]> initializeParameters() throws Exception - { - Collection<Object[]> result = new ArrayList<Object[]>(); - - result.add(new Object[] { LayerType.class, "LayerName", Types.Text }); - result.add(new Object[] { LayerType.class, "LayerText", Types.Text }); - - return result; - - } - -} +/***************************************************************************** + * + * 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 + * regarding copyright ownership. The ASF licenses this file + * to you under 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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +package org.apache.xmpbox.type; + +import java.util.ArrayList; +import java.util.Collection; + +import org.junit.Before; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +@RunWith(Parameterized.class) +public class TestLayerType extends AbstractStructuredTypeTester +{ + + @Before + public void before() throws Exception + { + super.before(); + } + + public TestLayerType(Class<? extends AbstractStructuredType> clz, String field, Types type) + { + super(clz, field, type); + } + + @Override + protected AbstractStructuredType getStructured() + { + return new LayerType(xmp); + } + + @Parameters + public static Collection<Object[]> initializeParameters() throws Exception + { + Collection<Object[]> result = new ArrayList<Object[]>(); + + result.add(new Object[] { LayerType.class, "LayerName", Types.Text }); + result.add(new Object[] { LayerType.class, "LayerText", Types.Text }); + + return result; + + } + +} Modified: pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestResourceEventType.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestResourceEventType.java?rev=1656236&r1=1656235&r2=1656236&view=diff ============================================================================== --- pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestResourceEventType.java (original) +++ pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestResourceEventType.java Sat Jan 31 18:57:43 2015 @@ -1,72 +1,69 @@ -/***************************************************************************** - * - * 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 - * regarding copyright ownership. The ASF licenses this file - * to you under 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.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -package org.apache.xmpbox.type; - -import java.util.ArrayList; -import java.util.Collection; - -import org.junit.Before; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -@RunWith(Parameterized.class) -public class TestResourceEventType extends AbstractStructuredTypeTester -{ - - protected ResourceEventType structured = null; - - @Before - public void before() throws Exception - { - super.before(); - structured = new ResourceEventType(xmp); - } - - public TestResourceEventType(Class<? extends AbstractStructuredType> clz, String field, Types type) - { - super(clz, field, type); - } - - @Override - protected AbstractStructuredType getStructured() - { - return structured; - } - - @Parameters - public static Collection<Object[]> initializeParameters() throws Exception - { - Collection<Object[]> result = new ArrayList<Object[]>(); - - result.add(new Object[] { ResourceEventType.class, "action", Types.Choice }); - result.add(new Object[] { ResourceEventType.class, "changed", Types.Text }); - result.add(new Object[] { ResourceEventType.class, "instanceID", Types.GUID }); - result.add(new Object[] { ResourceEventType.class, "parameters", Types.Text }); - result.add(new Object[] { ResourceEventType.class, "softwareAgent", Types.AgentName }); - result.add(new Object[] { ResourceEventType.class, "when", Types.Date }); - - return result; - - } - -} +/***************************************************************************** + * + * 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 + * regarding copyright ownership. The ASF licenses this file + * to you under 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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +package org.apache.xmpbox.type; + +import java.util.ArrayList; +import java.util.Collection; + +import org.junit.Before; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +@RunWith(Parameterized.class) +public class TestResourceEventType extends AbstractStructuredTypeTester +{ + + @Before + public void before() throws Exception + { + super.before(); + } + + public TestResourceEventType(Class<? extends AbstractStructuredType> clz, String field, Types type) + { + super(clz, field, type); + } + + @Override + protected AbstractStructuredType getStructured() + { + return new ResourceEventType(xmp); + } + + @Parameters + public static Collection<Object[]> initializeParameters() throws Exception + { + Collection<Object[]> result = new ArrayList<Object[]>(); + + result.add(new Object[] { ResourceEventType.class, "action", Types.Choice }); + result.add(new Object[] { ResourceEventType.class, "changed", Types.Text }); + result.add(new Object[] { ResourceEventType.class, "instanceID", Types.GUID }); + result.add(new Object[] { ResourceEventType.class, "parameters", Types.Text }); + result.add(new Object[] { ResourceEventType.class, "softwareAgent", Types.AgentName }); + result.add(new Object[] { ResourceEventType.class, "when", Types.Date }); + + return result; + + } + +} Modified: pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestResourceRefType.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestResourceRefType.java?rev=1656236&r1=1656235&r2=1656236&view=diff ============================================================================== --- pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestResourceRefType.java (original) +++ pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestResourceRefType.java Sat Jan 31 18:57:43 2015 @@ -1,83 +1,80 @@ -/***************************************************************************** - * - * 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 - * regarding copyright ownership. The ASF licenses this file - * to you under 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.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -package org.apache.xmpbox.type; - -import java.util.ArrayList; -import java.util.Collection; - -import org.junit.Before; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -@RunWith(Parameterized.class) -public class TestResourceRefType extends AbstractStructuredTypeTester -{ - - protected ResourceRefType structured = null; - - @Before - public void before() throws Exception - { - super.before(); - structured = new ResourceRefType(xmp); - } - - public TestResourceRefType(Class<? extends AbstractStructuredType> clz, String field, Types type) - { - super(clz, field, type); - } - - @Override - protected AbstractStructuredType getStructured() - { - return structured; - } - - @Parameters - public static Collection<Object[]> initializeParameters() throws Exception - { - Collection<Object[]> result = new ArrayList<Object[]>(); - - // result.add(new Object [] - // {ResourceRefType.class,"alternatePaths","seq URI"}); - result.add(new Object[] { ResourceRefType.class, "documentID", Types.URI }); - result.add(new Object[] { ResourceRefType.class, "filePath", Types.URI }); - result.add(new Object[] { ResourceRefType.class, "fromPart", Types.Part }); - result.add(new Object[] { ResourceRefType.class, "instanceID", Types.URI }); - result.add(new Object[] { ResourceRefType.class, "lastModifyDate", Types.Date }); - result.add(new Object[] { ResourceRefType.class, "manager", Types.AgentName }); - result.add(new Object[] { ResourceRefType.class, "managerVariant", Types.Text }); - result.add(new Object[] { ResourceRefType.class, "manageTo", Types.URI }); - result.add(new Object[] { ResourceRefType.class, "manageUI", Types.URI }); - result.add(new Object[] { ResourceRefType.class, "maskMarkers", Types.Choice }); - result.add(new Object[] { ResourceRefType.class, "partMapping", Types.Text }); - result.add(new Object[] { ResourceRefType.class, "renditionClass", Types.RenditionClass }); - result.add(new Object[] { ResourceRefType.class, "renditionParams", Types.Text }); - result.add(new Object[] { ResourceRefType.class, "toPart", Types.Part }); - result.add(new Object[] { ResourceRefType.class, "versionID", Types.Text }); - - return result; - - } - -} +/***************************************************************************** + * + * 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 + * regarding copyright ownership. The ASF licenses this file + * to you under 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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +package org.apache.xmpbox.type; + +import java.util.ArrayList; +import java.util.Collection; + +import org.junit.Before; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +@RunWith(Parameterized.class) +public class TestResourceRefType extends AbstractStructuredTypeTester +{ + + @Before + public void before() throws Exception + { + super.before(); + } + + public TestResourceRefType(Class<? extends AbstractStructuredType> clz, String field, Types type) + { + super(clz, field, type); + } + + @Override + protected AbstractStructuredType getStructured() + { + return new ResourceRefType(xmp); + } + + @Parameters + public static Collection<Object[]> initializeParameters() throws Exception + { + Collection<Object[]> result = new ArrayList<Object[]>(); + + // result.add(new Object [] + // {ResourceRefType.class,"alternatePaths","seq URI"}); + result.add(new Object[] { ResourceRefType.class, "documentID", Types.URI }); + result.add(new Object[] { ResourceRefType.class, "filePath", Types.URI }); + result.add(new Object[] { ResourceRefType.class, "fromPart", Types.Part }); + result.add(new Object[] { ResourceRefType.class, "instanceID", Types.URI }); + result.add(new Object[] { ResourceRefType.class, "lastModifyDate", Types.Date }); + result.add(new Object[] { ResourceRefType.class, "manager", Types.AgentName }); + result.add(new Object[] { ResourceRefType.class, "managerVariant", Types.Text }); + result.add(new Object[] { ResourceRefType.class, "manageTo", Types.URI }); + result.add(new Object[] { ResourceRefType.class, "manageUI", Types.URI }); + result.add(new Object[] { ResourceRefType.class, "maskMarkers", Types.Choice }); + result.add(new Object[] { ResourceRefType.class, "partMapping", Types.Text }); + result.add(new Object[] { ResourceRefType.class, "renditionClass", Types.RenditionClass }); + result.add(new Object[] { ResourceRefType.class, "renditionParams", Types.Text }); + result.add(new Object[] { ResourceRefType.class, "toPart", Types.Part }); + result.add(new Object[] { ResourceRefType.class, "versionID", Types.Text }); + + return result; + + } + +} Modified: pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestThumbnailType.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestThumbnailType.java?rev=1656236&r1=1656235&r2=1656236&view=diff ============================================================================== --- pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestThumbnailType.java (original) +++ pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestThumbnailType.java Sat Jan 31 18:57:43 2015 @@ -1,70 +1,67 @@ -/***************************************************************************** - * - * 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 - * regarding copyright ownership. The ASF licenses this file - * to you under 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.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -package org.apache.xmpbox.type; - -import java.util.ArrayList; -import java.util.Collection; - -import org.junit.Before; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -@RunWith(Parameterized.class) -public class TestThumbnailType extends AbstractStructuredTypeTester -{ - - protected ThumbnailType structured = null; - - @Before - public void before() throws Exception - { - super.before(); - structured = new ThumbnailType(xmp); - } - - public TestThumbnailType(Class<? extends AbstractStructuredType> clz, String field, Types type) - { - super(clz, field, type); - } - - @Override - protected AbstractStructuredType getStructured() - { - return structured; - } - - @Parameters - public static Collection<Object[]> initializeParameters() throws Exception - { - Collection<Object[]> result = new ArrayList<Object[]>(); - - result.add(new Object[] { ThumbnailType.class, "format", Types.Choice }); - result.add(new Object[] { ThumbnailType.class, "height", Types.Integer }); - result.add(new Object[] { ThumbnailType.class, "width", Types.Integer }); - result.add(new Object[] { ThumbnailType.class, "image", Types.Text }); - - return result; - - } - -} +/***************************************************************************** + * + * 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 + * regarding copyright ownership. The ASF licenses this file + * to you under 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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +package org.apache.xmpbox.type; + +import java.util.ArrayList; +import java.util.Collection; + +import org.junit.Before; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +@RunWith(Parameterized.class) +public class TestThumbnailType extends AbstractStructuredTypeTester +{ + + @Before + public void before() throws Exception + { + super.before(); + } + + public TestThumbnailType(Class<? extends AbstractStructuredType> clz, String field, Types type) + { + super(clz, field, type); + } + + @Override + protected AbstractStructuredType getStructured() + { + return new ThumbnailType(xmp); + } + + @Parameters + public static Collection<Object[]> initializeParameters() throws Exception + { + Collection<Object[]> result = new ArrayList<Object[]>(); + + result.add(new Object[] { ThumbnailType.class, "format", Types.Choice }); + result.add(new Object[] { ThumbnailType.class, "height", Types.Integer }); + result.add(new Object[] { ThumbnailType.class, "width", Types.Integer }); + result.add(new Object[] { ThumbnailType.class, "image", Types.Text }); + + return result; + + } + +} Modified: pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestVersionType.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestVersionType.java?rev=1656236&r1=1656235&r2=1656236&view=diff ============================================================================== --- pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestVersionType.java (original) +++ pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/type/TestVersionType.java Sat Jan 31 18:57:43 2015 @@ -1,71 +1,64 @@ -/***************************************************************************** - * - * 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 - * regarding copyright ownership. The ASF licenses this file - * to you under 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.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -package org.apache.xmpbox.type; - -import java.util.ArrayList; -import java.util.Collection; - -import org.junit.Before; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -@RunWith(Parameterized.class) -public class TestVersionType extends AbstractStructuredTypeTester -{ - - protected VersionType structured = null; - - @Before - public void before() throws Exception - { - super.before(); - structured = new VersionType(xmp); - } - - public TestVersionType(Class<? extends AbstractStructuredType> clz, String field, Types type) - { - super(clz, field, type); - } - - @Override - protected AbstractStructuredType getStructured() - { - return structured; - } - - @Parameters - public static Collection<Object[]> initializeParameters() throws Exception - { - Collection<Object[]> result = new ArrayList<Object[]>(); - - // result.add(new Object [] {VersionType.class,"version",Types.Text}); - // result.add(new Object [] {VersionType.class,"comments",Types.Text}); - // result.add(new Object [] - // {VersionType.class,"modifyDate",Types.Date}); - result.add(new Object[] { VersionType.class, "modifier", Types.ProperName }); - - return result; - - } - -} +/***************************************************************************** + * + * 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 + * regarding copyright ownership. The ASF licenses this file + * to you under 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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +package org.apache.xmpbox.type; + +import java.util.ArrayList; +import java.util.Collection; + +import org.junit.Before; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +@RunWith(Parameterized.class) +public class TestVersionType extends AbstractStructuredTypeTester +{ + + @Before + public void before() throws Exception + { + super.before(); + } + + public TestVersionType(Class<? extends AbstractStructuredType> clz, String field, Types type) + { + super(clz, field, type); + } + + @Override + protected AbstractStructuredType getStructured() + { + return new VersionType(xmp); + } + + @Parameters + public static Collection<Object[]> initializeParameters() throws Exception + { + Collection<Object[]> result = new ArrayList<Object[]>(); + + result.add(new Object[] { VersionType.class, "modifier", Types.ProperName }); + + return result; + + } + +}