IT. Expert System.

Android Reference

SerializationTest


org.apache.harmony.testframework.serialization

Class SerializationTest

  • java.lang.Object
    • TestCase
      • org.apache.harmony.testframework.serialization.SerializationTest
  • Direct Known Subclasses:
    BadPaddingExceptionTest, ExemptionMechanismExceptionTest, IllegalBlockSizeExceptionTest, NoSuchPaddingExceptionTest, ShortBufferExceptionTest


    public abstract class SerializationTest
    extends TestCase
    Framework for serialization testing. Subclasses only need to override getData() method and, optionally, assertDeserialized() method. The first one returns array of objects to be de/serialized in tests, and the second compares reference and deserialized objects (needed only if tested objects do not provide specific method equals()).
    There are two modes of test run: reference generation mode and testing mode . The actual mode is selected via "test.mode" system property. The testing mode is the default mode.
    To turn on the reference generation mode , the test.mode property should be set to value "serial.reference". In this mode, no testing is performed but golden files are produced, which contain reference serialized objects. This mode should be run on a pure Implementation classes, which are targeted for compartibility.
    The location of golden files (in both modes) is controlled via "RESOURCE_DIR" system property.
    • Constructor Detail

      • SerializationTest

        public SerializationTest()
    • Method Detail

      • getData

        protected abstract Object[] getData()
        This is the main working method of this framework. Subclasses must override it to provide actual objects for testing.
        Returns:
        array of objects to be de/serialized in tests.
      • testSelf

        public void testSelf()
                      throws Throwable
        Tests that data objects can be serialized and deserialized without exceptions, and that deserialization really produces deeply cloned objects.
        Throws:
        Throwable
      • testGolden

        public void testGolden()
                        throws Throwable
        Tests that data objects can be deserialized from golden files, to verify compatibility with Reference Implementation.
        Throws:
        Throwable
      • getDataFile

        protected File getDataFile(int index)
        Returns golden file for an object being tested.
        Parameters:
        index - array index of tested data (as returned by getData())
        Returns:
        corresponding golden file
      • produceGoldenFiles

        protected void produceGoldenFiles()
                                   throws IOException
        Working method for files generation mode. Serializes test objects returned by getData()to golden files, each object to a separate file.
        Throws:
        IOException
      • defineComparator

        public static SerializationTest.SerializableAssert defineComparator(TestCase test,
                                                            Object object)
                                                                     throws Exception
        Returns comparator for provided serializable object. The comparator is searched in the following order:
        - if test implements SerializableAssert interface then it is selected as comparator.
        - if passed object has class in its classes hierarchy that overrides equals(Object) method then DEFAULT_COMPARATOR is selected.
        - the method tries to select one of known comparators basing on object's class,for example, if passed object is instance of Throwable then THROWABLE_COMPARATOR is used.
        - otherwise RuntimeException is thrown
        Parameters:
        test - - test case
        object - - object to be compared
        Returns:
        object's comparator
        Throws:
        Exception
      • verifyGolden

        public static void verifyGolden(TestCase test,
                        Object object)
                                 throws Exception
        Verifies that object deserialized from golden file correctly. The method invokes
        verifyGolden(test, object, defineComparator(test, object));
        Parameters:
        test - - test case
        object - - to be compared
        Throws:
        Exception
      • verifyGolden

        public static void verifyGolden(TestCase test,
                        Object object,
                        SerializationTest.SerializableAssert comparator)
                                 throws Exception
        Verifies that object deserialized from golden file correctly. The method loads "testName.golden.ser" resource file from "/src/test/resources/serialization/testPackage" folder, reads an object from the loaded file and compares it with object using specified comparator.
        Parameters:
        test - - test case
        object - - to be compared
        comparator - - for comparing (de)serialized objects
        Throws:
        Exception
      • verifyGolden

        public static void verifyGolden(TestCase test,
                        Object[] objects)
                                 throws Exception
        Verifies that objects from array deserialized from golden files correctly. The method invokes
        verifyGolden(test, objects, defineComparator(test, object[0]));
        Parameters:
        test - - test case
        objects - - array of objects to be compared
        Throws:
        Exception
      • verifyGolden

        public static void verifyGolden(TestCase test,
                        Object[] objects,
                        SerializationTest.SerializableAssert comparator)
                                 throws Exception
        Verifies that objects from array deserialized from golden files correctly. The method loads "testName.golden.N.ser" resource files from "/src/test/resources/serialization/testPackage" folder, from each loaded file it reads an object from and compares it with corresponding object in provided array (i.e. objects[N]) using specified comparator. (N is index in object's array.)
        Parameters:
        test - - test case
        objects - - array of objects to be compared
        comparator - - for comparing (de)serialized objects
        Throws:
        Exception
      • verifySelf

        public static void verifySelf(Object object)
                               throws Exception
        Verifies that object can be smoothly serialized/deserialized. The method invokes
        verifySelf(object, defineComparator(null, object));
        Parameters:
        object - - to be serialized/deserialized
        Throws:
        Exception
      • verifySelf

        public static void verifySelf(Object object,
                      SerializationTest.SerializableAssert comparator)
                               throws Exception
        Verifies that object can be smoothly serialized/deserialized. The method serialize/deserialize object and compare it with initial object.
        Parameters:
        object - - object to be serialized/deserialized
        comparator - - for comparing serialized/deserialized object with initial object
        Throws:
        Exception
      • verifySelf

        public static void verifySelf(Object[] objects)
                               throws Exception
        Verifies that that objects from array can be smoothly serialized/deserialized. The method invokes
        verifySelf(objects, defineComparator(null, object[0]));
        Parameters:
        objects - - array of objects to be serialized/deserialized
        Throws:
        Exception
      • verifySelf

        public static void verifySelf(Object[] objects,
                      SerializationTest.SerializableAssert comparator)
                               throws Exception
        Verifies that that objects from array can be smoothly serialized/deserialized. The method serialize/deserialize each object in objects array and compare it with initial object.
        Parameters:
        objects - - array of objects to be serialized/deserialized
        comparator - - for comparing serialized/deserialized object with initial object
        Throws:
        Exception
      • createGoldenFile

        public static void createGoldenFile(String root,
                            TestCase test,
                            Object object)
                                     throws IOException
        Creates golden file. The folder for created file is: root + test's package name. The file name is: test's name + "golden.ser"
        Parameters:
        root - - root directory for serialization resource files
        test - - test case
        object - - to be serialized
        Throws:
        IOException - - if I/O error


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 116 / 158677778. Delta: 0.05158 с