org.hd.d.pg2k.test.dev
Class SerializationTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.hd.d.pg2k.test.dev.SerializationTest
All Implemented Interfaces:
junit.framework.Test

public final class SerializationTest
extends junit.framework.TestCase

Test that critical classes can be correctly serialised and deserialised. This is useful for items that will be:


Field Summary
private static int evv_TOTAL_EVENT_COUNT
          Total event count in map.
private static java.lang.String evvTestString1
          First test string value for EVV; has a count of 1.
private static java.lang.String evvTestString2
          Second test string value for EVV; has a count of 2.
private static java.lang.String hillsAreAlive
          Raw value of String variable value for "hills are alive" value.
private static int MAX_BYTES_PER_LINE
          Maximum bytes to print on each line of serialised form.
private static boolean PRINT_SER_BYTES
          If true, print out serialised value in form that can be cut-n-paste back into test code.
private static java.util.Random rnd
          Private source of OK pseudo-random numbers.
private static java.lang.String ROBA_compS1
          Value to check compression is working and can be correctly undone even on non-ASCII/non-8-bit text.
private static byte[] serData_AllExhibitPropertiesDelta_empty
          Empty AEP delta instance.
private static byte[] serData_C7BS_20060803
          Forced serialised form to check deserialisation is not broken.
private static byte[] serData_C7BS_20060804
          Forced serialised form after allowing for partial token (prefix) matching.
private static byte[] serData_CS8Bit
          Serialised CS8 form.
private static byte[] serData_efn1_20090711
          Serialisation of ExhibitFullName("a/a-A.a").
private static byte[] serData_efnpair_20090711
          Frozen pair of long values with common prefix and suffix.
private static byte[] serData_esa1a_20090711
          Original String field format serialisation of ExhibitStaticAttr("a/a-A.a", 1, CoreConsts.GALLERY_EPOC_START).
private static byte[] serData_esa1b_20090711
          CharSequence field format serialisation of ExhibitStaticAttr("a/a-A.a", 1, CoreConsts.GALLERY_EPOC_START) with run-time String field type.
private static byte[] serData_esa1c_20090711
          CharSequence field format serialisation of ExhibitStaticAttr("a/a-A.a", 1, CoreConsts.GALLERY_EPOC_START) with run-time Name.ExhibitFull field type.
private static byte[] serData_evv1_20050130_1748
          Old serialised format of a single EVV with embedded Map<Object, ValueInfo>.
private static byte[] serData_evv1_20050131_1512
          New (more compact) serialised format of a single EVV with counts[]/values[].
private static byte[] serData_evv1_20090806
          Newer serialised format (with Name in place of String on the wire) of a single EVV with counts[]/values[].
private static byte[] serData_hillsAreAlive_20050130
          Serialised String variable value for "hills are alive" value.
private static byte[] serData_pdS16_20090714
          Old-style String keys and values PropertiesDiff value.
private static byte[] serData_pdvar_20090714
          New-style String keys and values PropertiesDiff value.
private static byte[] serData_ROBA_compS1_20050522
          On-the-wire format on ROBA_compS1.
private static byte[] serData_ROByteArray_EMPTY_20050522
          Empty ROByteArray (ie wrapping a byte[0]).
private static byte[] serData_Thumbnail_20060704
          On-the-wire format of Thumbnail.
private static java.lang.String[] TEST_C7BS_DATA
          Sample input String values for Compact7BitString tests.
private static java.lang.String THE_HILLS_ARE_ALIVE
          Test text for CS8 (de)serialisation.
 
Constructor Summary
SerializationTest(java.lang.String name)
           
 
Method Summary
static void checkEmptyInstancesAreZeroAndEqualAndSerializable(java.lang.Class<? extends java.io.Serializable> c)
          Basic tests for those objects whose empty instances should have zero hash and compare equal.
static java.lang.Object checkObjectCanBeSerialisedAndDeserialised(java.lang.Object obj)
          Check that the object passed can be serialised and deserialised.
static java.lang.Object checkSerialisationPreservesEquality(java.lang.Object obj)
          Check that the passed (non-null) object compares equals after being serialised/deserialised.
(package private) static java.lang.Object deserialiseFromByteArray(byte[] data)
          Deserialise an Object from the supplied serialised form.
private static void dumpAsciiComment(java.lang.StringBuilder sbTmp, int count, byte[] values)
          Dump to System.out "count" characters from values, substituting non-printable-ASCII.
private static void dumpSerData(java.lang.Object obj, byte[] data)
          Dump serialised data in a form suitable to copy-and-paste into code.
static byte[] serialiseToByteArray(java.lang.Object obj)
          Serialise given object to byte array; never null.
static void testAccessionDataSer()
          Tests of accessions of serialisation of AccessionData.
static void testAEPSerialisationSize()
          Check that the current AEP serialisation is not less compact (when compressed) than the last one persisted.
static void testAllExhibitImmutableData()
          Test AllExhibitImmutableData for (de)serialisability.
static void testAllExhibitProperties()
          Test AllExhibitProperties for (de)serialisability.
static void testCompact7BitString()
          Test of serialisation and other behaviour of Compact7BitString.
static void testCompressors()
          Test correctness of some of our (de)compressors often used with serialisation.
static void testCS8Bit()
          Test behaviour of PropertiesBundleDiff object.
static void testDecompDeserRobustness()
          Test the robustness of our decompression routines in conjunction with deserialization.
static void testEPGIBasic()
          Basic serialisation tests of EPGI and its diff.
static void testESABasic()
          Basic serialisation tests of ExhibitStaticAttrs.
static void testEventVariableValues()
          Test that we can succesfully create and (de)serialise event container objects...
static void testExhibitFullNameBasic()
          Basic serialisation tests of ExhibitFullName.
static void testExhibitPropsLoadable()
          Basic tests on ExhibitPropsLoadable.
static void testExhibitThumbnails()
          Test ExhibitThumbnails.
static void testGenProps()
          Test GenProps for (de)serialisability.
static void testLocation()
          Test Location data (esp Estd) can be (de)serialised.
static void testLocationMap()
          Test (de)serialisation of LocationMap.
static void testPropertiesBundleDiff()
          Test behaviour of PropertiesBundleDiff object.
static void testPropertiesDiff()
          Test behaviour of PropertiesDiff object.
static void testROByteArray()
          Test handling of ROByteArray.
static void testSerAllExhibitPropertiesDelta()
          Simple AllExhibitPropertiesDelta (de)serialisation tests.
static void testSimpleVariables()
          Test that variables can be correctly serialised/deserialised.
static void testThumbnailSer()
          Test that we can (de)serialise Thumbnail data OK.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, tearDown, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PRINT_SER_BYTES

private static final boolean PRINT_SER_BYTES
If true, print out serialised value in form that can be cut-n-paste back into test code.

See Also:
Constant Field Values

MAX_BYTES_PER_LINE

private static final int MAX_BYTES_PER_LINE
Maximum bytes to print on each line of serialised form.

See Also:
Constant Field Values

hillsAreAlive

private static final java.lang.String hillsAreAlive
Raw value of String variable value for "hills are alive" value.

See Also:
Constant Field Values

serData_hillsAreAlive_20050130

private static final byte[] serData_hillsAreAlive_20050130
Serialised String variable value for "hills are alive" value.


evvTestString1

private static final java.lang.String evvTestString1
First test string value for EVV; has a count of 1.

See Also:
Constant Field Values

evvTestString2

private static final java.lang.String evvTestString2
Second test string value for EVV; has a count of 2.

See Also:
Constant Field Values

evv_TOTAL_EVENT_COUNT

private static final int evv_TOTAL_EVENT_COUNT
Total event count in map.

See Also:
Constant Field Values

serData_evv1_20050130_1748

private static final byte[] serData_evv1_20050130_1748
Old serialised format of a single EVV with embedded Map<Object, ValueInfo>.


serData_evv1_20050131_1512

private static final byte[] serData_evv1_20050131_1512
New (more compact) serialised format of a single EVV with counts[]/values[].


serData_evv1_20090806

private static final byte[] serData_evv1_20090806
Newer serialised format (with Name in place of String on the wire) of a single EVV with counts[]/values[].


serData_ROByteArray_EMPTY_20050522

private static final byte[] serData_ROByteArray_EMPTY_20050522
Empty ROByteArray (ie wrapping a byte[0]).


ROBA_compS1

private static final java.lang.String ROBA_compS1
Value to check compression is working and can be correctly undone even on non-ASCII/non-8-bit text.

See Also:
Constant Field Values

serData_ROBA_compS1_20050522

private static final byte[] serData_ROBA_compS1_20050522
On-the-wire format on ROBA_compS1.


serData_Thumbnail_20060704

private static final byte[] serData_Thumbnail_20060704
On-the-wire format of Thumbnail.


serData_AllExhibitPropertiesDelta_empty

private static final byte[] serData_AllExhibitPropertiesDelta_empty
Empty AEP delta instance.


TEST_C7BS_DATA

private static final java.lang.String[] TEST_C7BS_DATA
Sample input String values for Compact7BitString tests. These values include hard/edge cases and realistic sample data.

These are tested individually and all together in one stream.


serData_C7BS_20060803

private static final byte[] serData_C7BS_20060803
Forced serialised form to check deserialisation is not broken. Encoded value: "prefix1 prefix1suffix prefix2 prefix2suffix prefix2suffix".


serData_C7BS_20060804

private static final byte[] serData_C7BS_20060804
Forced serialised form after allowing for partial token (prefix) matching. Encoded value: "prefix1 prefix1suffix prefix2 prefix2suffix prefix2suffix".


serData_pdS16_20090714

private static final byte[] serData_pdS16_20090714
Old-style String keys and values PropertiesDiff value.


serData_pdvar_20090714

private static final byte[] serData_pdvar_20090714
New-style String keys and values PropertiesDiff value.


serData_esa1a_20090711

private static final byte[] serData_esa1a_20090711
Original String field format serialisation of ExhibitStaticAttr("a/a-A.a", 1, CoreConsts.GALLERY_EPOC_START).


serData_esa1b_20090711

private static final byte[] serData_esa1b_20090711
CharSequence field format serialisation of ExhibitStaticAttr("a/a-A.a", 1, CoreConsts.GALLERY_EPOC_START) with run-time String field type.


serData_esa1c_20090711

private static final byte[] serData_esa1c_20090711
CharSequence field format serialisation of ExhibitStaticAttr("a/a-A.a", 1, CoreConsts.GALLERY_EPOC_START) with run-time Name.ExhibitFull field type.


serData_efn1_20090711

private static final byte[] serData_efn1_20090711
Serialisation of ExhibitFullName("a/a-A.a").


serData_efnpair_20090711

private static final byte[] serData_efnpair_20090711
Frozen pair of long values with common prefix and suffix.


THE_HILLS_ARE_ALIVE

private static final java.lang.String THE_HILLS_ARE_ALIVE
Test text for CS8 (de)serialisation.

See Also:
Constant Field Values

serData_CS8Bit

private static final byte[] serData_CS8Bit
Serialised CS8 form.


rnd

private static final java.util.Random rnd
Private source of OK pseudo-random numbers.

Constructor Detail

SerializationTest

public SerializationTest(java.lang.String name)
Method Detail

checkObjectCanBeSerialisedAndDeserialised

public static java.lang.Object checkObjectCanBeSerialisedAndDeserialised(java.lang.Object obj)
                                                                  throws java.io.IOException,
                                                                         java.lang.ClassNotFoundException
Check that the object passed can be serialised and deserialised.

Parameters:
obj - must implement java.io.Serializable; never null
Returns:
the deserialised version of the object
Throws:
java.io.IOException
java.lang.ClassNotFoundException

serialiseToByteArray

public static byte[] serialiseToByteArray(java.lang.Object obj)
                                   throws java.io.IOException
Serialise given object to byte array; never null.

Throws:
java.io.IOException

dumpSerData

private static void dumpSerData(java.lang.Object obj,
                                byte[] data)
Dump serialised data in a form suitable to copy-and-paste into code.


dumpAsciiComment

private static void dumpAsciiComment(java.lang.StringBuilder sbTmp,
                                     int count,
                                     byte[] values)
Dump to System.out "count" characters from values, substituting non-printable-ASCII.


deserialiseFromByteArray

static java.lang.Object deserialiseFromByteArray(byte[] data)
                                          throws java.io.IOException,
                                                 java.lang.ClassNotFoundException
Deserialise an Object from the supplied serialised form.

Throws:
java.io.IOException
java.lang.ClassNotFoundException

checkSerialisationPreservesEquality

public static java.lang.Object checkSerialisationPreservesEquality(java.lang.Object obj)
                                                            throws java.lang.Exception
Check that the passed (non-null) object compares equals after being serialised/deserialised. This looks at equals() and hashCode().

Tests in passing that the object can be (de)serialised.

Returns:
deserialised object in case we want to perform extra tests on it
Throws:
java.lang.Exception - in case of difficulty.

checkEmptyInstancesAreZeroAndEqualAndSerializable

public static void checkEmptyInstancesAreZeroAndEqualAndSerializable(java.lang.Class<? extends java.io.Serializable> c)
                                                              throws java.lang.Exception
Basic tests for those objects whose empty instances should have zero hash and compare equal. (Empty instances are those made with the default constructor.)

Most of our persistable and transmittable-across-the-wire objects should show this property so that we can easily tell empty objects from ones containing useful data for example.

These objects should also be Serializable ((de)serializable) and still compare equal.

Throws:
java.lang.Exception - in case of difficulty.

testAllExhibitImmutableData

public static void testAllExhibitImmutableData()
                                        throws java.lang.Exception
Test AllExhibitImmutableData for (de)serialisability. We check that:

Throws:
java.lang.Exception

testAllExhibitProperties

public static void testAllExhibitProperties()
                                     throws java.lang.Exception
Test AllExhibitProperties for (de)serialisability. We check that:

Throws:
java.lang.Exception

testExhibitPropsLoadable

public static void testExhibitPropsLoadable()
                                     throws java.lang.Exception
Basic tests on ExhibitPropsLoadable.

Throws:
java.lang.Exception

testGenProps

public static void testGenProps()
                         throws java.lang.Exception
Test GenProps for (de)serialisability. We check that:

Throws:
java.lang.Exception

testExhibitThumbnails

public static void testExhibitThumbnails()
                                  throws java.lang.Exception
Test ExhibitThumbnails. We want to check that object resolving works and we discard duplicate values that equals NO_THUMBNAILS on deserialisation.

Throws:
java.lang.Exception

testLocation

public static void testLocation()
                         throws java.lang.Exception
Test Location data (esp Estd) can be (de)serialised. We also test the LocationMap.

Throws:
java.lang.Exception

testSimpleVariables

public static void testSimpleVariables()
                                throws java.lang.Exception
Test that variables can be correctly serialised/deserialised. We check all the built-in definitions and instances/values of several types.

Throws:
java.lang.Exception

testEventVariableValues

public static void testEventVariableValues()
                                    throws java.lang.Exception
Test that we can succesfully create and (de)serialise event container objects... In particular we ensure that we can recover data in older formats where necessary so that we don't lose hard-to-replace historic data.

Throws:
java.lang.Exception

testROByteArray

public static void testROByteArray()
                            throws java.lang.Exception
Test handling of ROByteArray.

Throws:
java.lang.Exception

testAccessionDataSer

public static void testAccessionDataSer()
                                 throws java.lang.Exception
Tests of accessions of serialisation of AccessionData. This is both for Java serialisation and XML format.

Throws:
java.lang.Exception

testThumbnailSer

public static void testThumbnailSer()
                             throws java.lang.Exception
Test that we can (de)serialise Thumbnail data OK.

Throws:
java.lang.Exception

testDecompDeserRobustness

public static void testDecompDeserRobustness()
Test the robustness of our decompression routines in conjunction with deserialization. We expect clean failures rather than hangs or messy crashes, whatever junk is thrown at the decompressors.


testSerAllExhibitPropertiesDelta

public static void testSerAllExhibitPropertiesDelta()
                                             throws java.lang.Exception
Simple AllExhibitPropertiesDelta (de)serialisation tests. While it is not promised that the serialised format for AllExhibitPropertiesDelta will be stable indefinitely, we want to make sure that we don't change it inadvertently, which would prevent clients and servers exchanging it for example.

Throws:
java.lang.Exception

testCompact7BitString

public static void testCompact7BitString()
                                  throws java.lang.Exception
Test of serialisation and other behaviour of Compact7BitString. The aim is that Compact7BitString should usually be significant smaller than String in memory and serialised for 7-bit ASCII text, especially when multiple similar values are serialised to a single stream.

We take the (maximally) compressed serialised stream to be our target usage.

Throws:
java.lang.Exception

testLocationMap

public static void testLocationMap()
                            throws java.lang.Exception
Test (de)serialisation of LocationMap.

Throws:
java.lang.Exception

testCompressors

public static void testCompressors()
                            throws java.lang.Exception
Test correctness of some of our (de)compressors often used with serialisation. This ensures that they correctly handle some sample data streams and that they work correctly in the face of a mid-stream flush().

Throws:
java.lang.Exception

testPropertiesDiff

public static void testPropertiesDiff()
                               throws java.lang.Exception
Test behaviour of PropertiesDiff object. This is primarily used to allow efficient transmission of properties values/updates over the wire.

Throws:
java.lang.Exception

testPropertiesBundleDiff

public static void testPropertiesBundleDiff()
                                     throws java.lang.Exception
Test behaviour of PropertiesBundleDiff object. This is primarily used to allow efficient transmission of properties values/updates over the wire.

Throws:
java.lang.Exception

testEPGIBasic

public static void testEPGIBasic()
                          throws java.lang.Exception
Basic serialisation tests of EPGI and its diff.

Throws:
java.lang.Exception

testESABasic

public static void testESABasic()
                         throws java.lang.Exception
Basic serialisation tests of ExhibitStaticAttrs.

Throws:
java.lang.Exception

testExhibitFullNameBasic

public static void testExhibitFullNameBasic()
                                     throws java.lang.Exception
Basic serialisation tests of ExhibitFullName.

Throws:
java.lang.Exception

testAEPSerialisationSize

public static void testAEPSerialisationSize()
                                     throws java.lang.Exception
Check that the current AEP serialisation is not less compact (when compressed) than the last one persisted. This is a useful test for tuning the serialised format against a realistic/large AEP instance.

This is quiet-ish unless the AEP changes in size significantly when re-serialised and GZIPped. A big enough bloat is an error.

Often serialisation formats will compress slightly better when less compact at the micro level (ie if we avoid internally (over-)compressing each component first).

We only test with the last captured AEP, assumed to be the nearest to current.

This also measures code performance in the (de)serialisation path.

Throws:
java.lang.Exception

testCS8Bit

public static void testCS8Bit()
                       throws java.lang.Exception
Test behaviour of PropertiesBundleDiff object. This is primarily used to allow efficient transmission of properties values/updates over the wire.

Throws:
java.lang.Exception

DHD Multimedia Gallery V1.57.21

Copyright (c) 1996-2011, Damon Hart-Davis. All rights reserved.