This is an automated email from the ASF dual-hosted git repository.
garydgregory pushed a commit to branch 1.X
in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git
The following commit(s) were added to refs/heads/1.X by this push:
new b184f405 Add DynaPropertySerializationReadVersion1Test.
b184f405 is described below
commit b184f405c5d86d67e4c896ac14964484207694f6
Author: Gary Gregory <[email protected]>
AuthorDate: Tue Jul 28 17:33:46 2026 -0400
Add DynaPropertySerializationReadVersion1Test.
---
.../DynaPropertySerializationReadVersion1Test.java | 212 +++++++++++++++++++++
.../org/apache/commons/beanutils/arrayListProp.ser | Bin 0 -> 189 bytes
.../org/apache/commons/beanutils/boolProp.ser | Bin 0 -> 109 bytes
.../org/apache/commons/beanutils/byteProp.ser | Bin 0 -> 109 bytes
.../org/apache/commons/beanutils/charProp.ser | Bin 0 -> 109 bytes
.../org/apache/commons/beanutils/doubleProp.ser | Bin 0 -> 111 bytes
.../org/apache/commons/beanutils/floatProp.ser | Bin 0 -> 110 bytes
.../org/apache/commons/beanutils/hashMapProp.ser | Bin 0 -> 174 bytes
.../org/apache/commons/beanutils/intArrayProp.ser | Bin 0 -> 135 bytes
.../org/apache/commons/beanutils/intListProp.ser | Bin 0 -> 146 bytes
.../org/apache/commons/beanutils/intMapProp.ser | Bin 0 -> 144 bytes
.../org/apache/commons/beanutils/intProp.ser | Bin 0 -> 108 bytes
.../org/apache/commons/beanutils/integerProp.ser | Bin 0 -> 181 bytes
.../org/apache/commons/beanutils/listProp.ser | Bin 0 -> 140 bytes
.../org/apache/commons/beanutils/longProp.ser | Bin 0 -> 109 bytes
.../org/apache/commons/beanutils/mapProp.ser | Bin 0 -> 138 bytes
.../org/apache/commons/beanutils/nameOnly.ser | Bin 0 -> 138 bytes
.../org/apache/commons/beanutils/objProp.ser | Bin 0 -> 137 bytes
.../org/apache/commons/beanutils/shortProp.ser | Bin 0 -> 110 bytes
.../org/apache/commons/beanutils/strArrayProp.ser | Bin 0 -> 181 bytes
.../org/apache/commons/beanutils/strProp.ser | Bin 0 -> 137 bytes
.../org/apache/commons/beanutils/typedListProp.ser | Bin 0 -> 177 bytes
.../org/apache/commons/beanutils/typedMapProp.ser | Bin 0 -> 175 bytes
23 files changed, 212 insertions(+)
diff --git
a/src/test/java/org/apache/commons/beanutils/DynaPropertySerializationReadVersion1Test.java
b/src/test/java/org/apache/commons/beanutils/DynaPropertySerializationReadVersion1Test.java
new file mode 100644
index 00000000..afb8dbca
--- /dev/null
+++
b/src/test/java/org/apache/commons/beanutils/DynaPropertySerializationReadVersion1Test.java
@@ -0,0 +1,212 @@
+/*
+ * 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
+ *
+ * https://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.commons.beanutils;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests that {@link DynaProperty} instances serialized by a prior version can
still be deserialized correctly.
+ * <h2>Workflow</h2>
+ * <ol>
+ * <li>Run {@link #main(String[])} once to produce serialized files under
{@code ./target/DynaPropertySerialization}. Each file is named after the
property it
+ * represents (for example {@code nameOnly.ser}).</li>
+ * <li>Copy those files to {@code
src/test/resources/org/apache/commons/beanutils/}.</li>
+ * <li>Run the test suite normally. {@link #testDeserializeFromResources()}
reads every {@code *.ser} file from the resource directory and asserts that
+ * deserialization succeeds and produces a non-null {@link DynaProperty} with
the expected name.</li>
+ * </ol>
+ * <p>
+ * {@link #testDeserializeFromTargetDirectory()} provides immediate feedback:
it reads the files written by {@link #main(String[])} from
+ * {@code ./target/DynaPropertySerialization} and performs the same
assertions, so a developer can verify the round-trip without copying files
first.
+ * </p>
+ */
+class DynaPropertySerializationReadVersion1Test {
+
+ /** Resource path (relative to the classpath root) where committed
serialized files live. */
+ private static final String RESOURCE_DIR = "org/apache/commons/beanutils";
+
+ /** Directory where {@link #main(String[])} writes serialized files. */
+ private static final String TARGET_DIR =
"target/DynaPropertySerialization";
+
+ /**
+ * Deserializes a {@link DynaProperty} from the given stream and asserts
that the result is structurally equal to {@code expected}.
+ *
+ * @param ois source stream (caller is responsible for closing).
+ * @param expected the property the deserialized instance must equal.
+ * @throws IOException if an I/O error occurs.
+ * @throws ClassNotFoundException if the class of the serialized object
cannot be found.
+ */
+ private static void assertDeserializedProperty(final ObjectInputStream
ois, final DynaProperty expected) throws IOException, ClassNotFoundException {
+ final Object obj = ois.readObject();
+ assertNotNull(obj, "Deserialized object must not be null");
+ assertTrue(obj instanceof DynaProperty, "Deserialized object must be a
DynaProperty, was: " + obj.getClass());
+ final DynaProperty actual = (DynaProperty) obj;
+ assertEquals(expected.getName(), actual.getName(), () -> "name must be
preserved for property " + expected.getName());
+ assertEquals(expected.getType(), actual.getType(), () -> "type must be
preserved for property " + expected.getName());
+ assertEquals(expected.getContentType(), actual.getContentType(), () ->
"contentType must be preserved for property " + expected.getName());
+ assertEquals(expected, actual, () -> "equals() must hold for property
" + expected.getName());
+ }
+
+ /**
+ * Deserializes all {@code *.ser} files found in {@code dir} and asserts
that each one matches the canonical property of the same name.
+ *
+ * @param dir directory containing {@code *.ser} files.
+ * @param description human-readable label used in assertion messages.
+ * @throws Exception if deserialization fails or an assertion is violated.
+ */
+ private static void assertDeserializeFromDirectory(final File dir, final
String description) throws Exception {
+ assertTrue(dir.isDirectory(), () -> description + ": directory must
exist: " + dir.getAbsolutePath());
+ final File[] files = dir.listFiles((d, name) -> name.endsWith(".ser"));
+ assertNotNull(files, () -> description + ": listFiles() must not
return null");
+ assertTrue(files.length > 0, () -> description + ": directory must
contain at least one *.ser file: " + dir.getAbsolutePath());
+ final Map<String, DynaProperty> expected = buildCanonicalMap();
+ for (final File file : files) {
+ final String propName = file.getName().replace(".ser", "");
+ final DynaProperty expectedProp = expected.get(propName);
+ assertNotNull(expectedProp,
+ () -> description + ": no canonical property found for
file: " + file.getName() + ". Known names: " + expected.keySet());
+ try (FileInputStream fis = new FileInputStream(file);
ObjectInputStream ois = new ObjectInputStream(fis)) {
+ assertDeserializedProperty(ois, expectedProp);
+ }
+ }
+ }
+
+ /**
+ * Builds a lookup map from property name to canonical {@link
DynaProperty} so that test methods can locate the expected value for any file
they encounter.
+ */
+ private static Map<String, DynaProperty> buildCanonicalMap() {
+ final Map<String, DynaProperty> map = new HashMap<>();
+ for (final DynaProperty prop : buildCanonicalProperties()) {
+ map.put(prop.getName(), prop);
+ }
+ return map;
+ }
+
+ /**
+ * Returns the canonical list of {@link DynaProperty} instances whose
serialized form is committed to source control as "version 1" compatibility
fixtures.
+ *
+ * @return ordered list of property instances.
+ */
+ private static List<DynaProperty> buildCanonicalProperties() {
+ final List<DynaProperty> props = new ArrayList<>();
+ // Simple types
+ props.add(new DynaProperty("nameOnly")); // Object.class
+ props.add(new DynaProperty("strProp", String.class));
+ props.add(new DynaProperty("integerProp", Integer.class));
+ props.add(new DynaProperty("objProp", Object.class));
+ // Primitive types
+ props.add(new DynaProperty("boolProp", Boolean.TYPE));
+ props.add(new DynaProperty("byteProp", Byte.TYPE));
+ props.add(new DynaProperty("charProp", Character.TYPE));
+ props.add(new DynaProperty("doubleProp", Double.TYPE));
+ props.add(new DynaProperty("floatProp", Float.TYPE));
+ props.add(new DynaProperty("intProp", Integer.TYPE));
+ props.add(new DynaProperty("longProp", Long.TYPE));
+ props.add(new DynaProperty("shortProp", Short.TYPE));
+ // Array types
+ props.add(new DynaProperty("strArrayProp", String[].class));
+ props.add(new DynaProperty("intArrayProp", int[].class));
+ // Indexed (List) types
+ props.add(new DynaProperty("listProp", List.class));
+ props.add(new DynaProperty("typedListProp", List.class, String.class));
+ props.add(new DynaProperty("intListProp", List.class, Integer.TYPE));
+ props.add(new DynaProperty("arrayListProp", ArrayList.class,
String.class));
+ // Mapped (Map) types
+ props.add(new DynaProperty("mapProp", Map.class));
+ props.add(new DynaProperty("typedMapProp", Map.class, String.class));
+ props.add(new DynaProperty("intMapProp", Map.class, Integer.TYPE));
+ props.add(new DynaProperty("hashMapProp", HashMap.class, Double.TYPE));
+ return props;
+ }
+
+ private static File checkDir(final File dir) throws IOException {
+ if (!dir.mkdirs() && !dir.isDirectory()) {
+ throw new IOException("Cannot create directory: " +
dir.getAbsolutePath());
+ }
+ return dir;
+ }
+
+ /**
+ * Serializes each canonical {@link DynaProperty} to a file under {@value
#TARGET_DIR}.
+ * <p>
+ * Run this once to produce the fixture files, then copy them to {@code
src/test/resources/org/apache/commons/beanutils/} before committing.
+ * </p>
+ *
+ * @param args ignored.
+ * @throws IOException if any I/O error occurs.
+ */
+ public static void main(final String[] args) throws IOException {
+ final File dir = checkDir(new File(TARGET_DIR));
+ for (final DynaProperty prop : buildCanonicalProperties()) {
+ final File file = new File(dir, prop.getName() + ".ser");
+ try (FileOutputStream fos = new FileOutputStream(file);
ObjectOutputStream oos = new ObjectOutputStream(fos)) {
+ oos.writeObject(prop);
+ }
+ System.out.println("Wrote: " + file.getAbsolutePath());
+ }
+ System.out.println("Done. Copy " + TARGET_DIR + "/*.ser to
src/test/resources/" + RESOURCE_DIR + "/");
+ }
+
+ /**
+ * Reads every {@code *.ser} file from the classpath resource directory
{@code src/test/resources/org/apache/commons/beanutils/} and asserts that
+ * deserialization produces a {@link DynaProperty} equal to the canonical
instance with the same name.
+ * <p>
+ * This test verifies backwards compatibility: files serialized by an
older version of the code can still be read by the current version.
+ * </p>
+ * <p>
+ * <strong>Prerequisites:</strong> run {@link #main(String[])} once and
copy the resulting {@code *.ser} files from {@value #TARGET_DIR} to
+ * {@code src/test/resources/org/apache/commons/beanutils/} before running
this test.
+ * </p>
+ */
+ @Test
+ void testDeserializeFromResources() throws Exception {
+ // Resolve the resource directory relative to the project root so the
test
+ // works whether launched from Maven or from an IDE.
+ final File resourceDir = new File("src/test/resources/" +
RESOURCE_DIR);
+ assertDeserializeFromDirectory(resourceDir, "Resources directory");
+ }
+
+ /**
+ * Reads every {@code *.ser} file written by {@link #main(String[])} from
{@value #TARGET_DIR} and asserts that deserialization produces a
+ * {@link DynaProperty} equal to the canonical instance with the same name.
+ * <p>
+ * This test allows a developer to verify the round-trip immediately after
running {@link #main(String[])}, without having to copy the files first.
+ * </p>
+ */
+ @Test
+ @Disabled("Requires manual execution of main() to produce files first")
+ void testDeserializeFromTargetDirectory() throws Exception {
+ final File targetDir = new File(TARGET_DIR);
+ assertDeserializeFromDirectory(targetDir, "Target directory");
+ }
+}
diff --git a/src/test/resources/org/apache/commons/beanutils/arrayListProp.ser
b/src/test/resources/org/apache/commons/beanutils/arrayListProp.ser
new file mode 100644
index 00000000..c827c43f
Binary files /dev/null and
b/src/test/resources/org/apache/commons/beanutils/arrayListProp.ser differ
diff --git a/src/test/resources/org/apache/commons/beanutils/boolProp.ser
b/src/test/resources/org/apache/commons/beanutils/boolProp.ser
new file mode 100644
index 00000000..d99f3355
Binary files /dev/null and
b/src/test/resources/org/apache/commons/beanutils/boolProp.ser differ
diff --git a/src/test/resources/org/apache/commons/beanutils/byteProp.ser
b/src/test/resources/org/apache/commons/beanutils/byteProp.ser
new file mode 100644
index 00000000..2b727098
Binary files /dev/null and
b/src/test/resources/org/apache/commons/beanutils/byteProp.ser differ
diff --git a/src/test/resources/org/apache/commons/beanutils/charProp.ser
b/src/test/resources/org/apache/commons/beanutils/charProp.ser
new file mode 100644
index 00000000..d8558583
Binary files /dev/null and
b/src/test/resources/org/apache/commons/beanutils/charProp.ser differ
diff --git a/src/test/resources/org/apache/commons/beanutils/doubleProp.ser
b/src/test/resources/org/apache/commons/beanutils/doubleProp.ser
new file mode 100644
index 00000000..0f443f1a
Binary files /dev/null and
b/src/test/resources/org/apache/commons/beanutils/doubleProp.ser differ
diff --git a/src/test/resources/org/apache/commons/beanutils/floatProp.ser
b/src/test/resources/org/apache/commons/beanutils/floatProp.ser
new file mode 100644
index 00000000..c17dbf93
Binary files /dev/null and
b/src/test/resources/org/apache/commons/beanutils/floatProp.ser differ
diff --git a/src/test/resources/org/apache/commons/beanutils/hashMapProp.ser
b/src/test/resources/org/apache/commons/beanutils/hashMapProp.ser
new file mode 100644
index 00000000..5695a1fe
Binary files /dev/null and
b/src/test/resources/org/apache/commons/beanutils/hashMapProp.ser differ
diff --git a/src/test/resources/org/apache/commons/beanutils/intArrayProp.ser
b/src/test/resources/org/apache/commons/beanutils/intArrayProp.ser
new file mode 100644
index 00000000..1263e95c
Binary files /dev/null and
b/src/test/resources/org/apache/commons/beanutils/intArrayProp.ser differ
diff --git a/src/test/resources/org/apache/commons/beanutils/intListProp.ser
b/src/test/resources/org/apache/commons/beanutils/intListProp.ser
new file mode 100644
index 00000000..4e223a5a
Binary files /dev/null and
b/src/test/resources/org/apache/commons/beanutils/intListProp.ser differ
diff --git a/src/test/resources/org/apache/commons/beanutils/intMapProp.ser
b/src/test/resources/org/apache/commons/beanutils/intMapProp.ser
new file mode 100644
index 00000000..c982751b
Binary files /dev/null and
b/src/test/resources/org/apache/commons/beanutils/intMapProp.ser differ
diff --git a/src/test/resources/org/apache/commons/beanutils/intProp.ser
b/src/test/resources/org/apache/commons/beanutils/intProp.ser
new file mode 100644
index 00000000..ff6b67f9
Binary files /dev/null and
b/src/test/resources/org/apache/commons/beanutils/intProp.ser differ
diff --git a/src/test/resources/org/apache/commons/beanutils/integerProp.ser
b/src/test/resources/org/apache/commons/beanutils/integerProp.ser
new file mode 100644
index 00000000..78cd089f
Binary files /dev/null and
b/src/test/resources/org/apache/commons/beanutils/integerProp.ser differ
diff --git a/src/test/resources/org/apache/commons/beanutils/listProp.ser
b/src/test/resources/org/apache/commons/beanutils/listProp.ser
new file mode 100644
index 00000000..1a5c859d
Binary files /dev/null and
b/src/test/resources/org/apache/commons/beanutils/listProp.ser differ
diff --git a/src/test/resources/org/apache/commons/beanutils/longProp.ser
b/src/test/resources/org/apache/commons/beanutils/longProp.ser
new file mode 100644
index 00000000..dfdff74b
Binary files /dev/null and
b/src/test/resources/org/apache/commons/beanutils/longProp.ser differ
diff --git a/src/test/resources/org/apache/commons/beanutils/mapProp.ser
b/src/test/resources/org/apache/commons/beanutils/mapProp.ser
new file mode 100644
index 00000000..f60d5063
Binary files /dev/null and
b/src/test/resources/org/apache/commons/beanutils/mapProp.ser differ
diff --git a/src/test/resources/org/apache/commons/beanutils/nameOnly.ser
b/src/test/resources/org/apache/commons/beanutils/nameOnly.ser
new file mode 100644
index 00000000..e0198143
Binary files /dev/null and
b/src/test/resources/org/apache/commons/beanutils/nameOnly.ser differ
diff --git a/src/test/resources/org/apache/commons/beanutils/objProp.ser
b/src/test/resources/org/apache/commons/beanutils/objProp.ser
new file mode 100644
index 00000000..21a53aa7
Binary files /dev/null and
b/src/test/resources/org/apache/commons/beanutils/objProp.ser differ
diff --git a/src/test/resources/org/apache/commons/beanutils/shortProp.ser
b/src/test/resources/org/apache/commons/beanutils/shortProp.ser
new file mode 100644
index 00000000..81ce3ac8
Binary files /dev/null and
b/src/test/resources/org/apache/commons/beanutils/shortProp.ser differ
diff --git a/src/test/resources/org/apache/commons/beanutils/strArrayProp.ser
b/src/test/resources/org/apache/commons/beanutils/strArrayProp.ser
new file mode 100644
index 00000000..4aebc2fd
Binary files /dev/null and
b/src/test/resources/org/apache/commons/beanutils/strArrayProp.ser differ
diff --git a/src/test/resources/org/apache/commons/beanutils/strProp.ser
b/src/test/resources/org/apache/commons/beanutils/strProp.ser
new file mode 100644
index 00000000..66a26bdf
Binary files /dev/null and
b/src/test/resources/org/apache/commons/beanutils/strProp.ser differ
diff --git a/src/test/resources/org/apache/commons/beanutils/typedListProp.ser
b/src/test/resources/org/apache/commons/beanutils/typedListProp.ser
new file mode 100644
index 00000000..282d1c3c
Binary files /dev/null and
b/src/test/resources/org/apache/commons/beanutils/typedListProp.ser differ
diff --git a/src/test/resources/org/apache/commons/beanutils/typedMapProp.ser
b/src/test/resources/org/apache/commons/beanutils/typedMapProp.ser
new file mode 100644
index 00000000..f4e62127
Binary files /dev/null and
b/src/test/resources/org/apache/commons/beanutils/typedMapProp.ser differ