From 56860f0aca32b2c69b6213ff7df2b28a62dce7d3 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Tue, 8 Jun 2010 02:33:09 +0000 Subject: Fix serialization of adapted primary key properties. --- .../carbonado/gen/TestStorableSerializer.java | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'src/test/java/com') diff --git a/src/test/java/com/amazon/carbonado/gen/TestStorableSerializer.java b/src/test/java/com/amazon/carbonado/gen/TestStorableSerializer.java index 1574045..3a73faa 100644 --- a/src/test/java/com/amazon/carbonado/gen/TestStorableSerializer.java +++ b/src/test/java/com/amazon/carbonado/gen/TestStorableSerializer.java @@ -23,6 +23,8 @@ import java.io.*; import junit.framework.TestCase; import junit.framework.TestSuite; +import org.joda.time.DateTime; + import com.amazon.carbonado.*; import com.amazon.carbonado.lob.*; @@ -225,6 +227,38 @@ public class TestStorableSerializer extends TestCase { } */ + public void testAdaptedPkProperty() throws Exception { + // Make sure that adapted property in pk can be read back, even if + // current property is clean. This is a test for a bug fix. + Storage storage = mRepository.storageFor(TheDate.class); + DateTime date = new DateTime(); + TheDate d = storage.prepare(); + d.setId(1); + d.setDate(date); + d.setValue("hello"); + d.insert(); + + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + DataOutputStream dout = new DataOutputStream(bout); + + d.writeTo(dout); + dout.flush(); + + byte[] bytes = bout.toByteArray(); + + d = storage.prepare(); + d.setId(1); + d.setDate(date); + // Properties are clean. + d.load(); + + ByteArrayInputStream bin = new ByteArrayInputStream(bytes); + DataInputStream din = new DataInputStream(bin); + + // No exception thrown. + d.readFrom(din); + } + @PrimaryKey("id") public static abstract class ManyProperties implements Storable { public abstract int getId(); @@ -380,4 +414,16 @@ public class TestStorableSerializer extends TestCase { public abstract int getProp47(); public abstract void setProp47(int v); } + + @PrimaryKey({"id", "date"}) + public static interface TheDate extends Storable { + long getId(); + void setId(long id); + + DateTime getDate(); + void setDate(DateTime date); + + String getValue(); + void setValue(String value); + } } -- cgit v1.2.3