@Test public void testRegressionXFormSerializations() { FormDef def = XFormUtils.getFormFromResource("/resources/forms/placeholder.xml"); try { ExtUtil.deserialize(ExtUtil.serialize(def), FormDef.class, TestUtils.factory); } catch (IOException | DeserializationException e) { e.printStackTrace(); throw new RuntimeException(e.getMessage()); } }
public static void testExternalizable( Object orig, Object template, PrototypeFactory pf, TestCase tc, String failMessage) { if (failMessage == null) failMessage = "Serialization Failure"; byte[] bytes; Object deser; print(""); print("Original: " + printObj(orig)); try { bytes = ExtUtil.serialize(orig); print("Serialized as:"); print(ExtUtil.printBytes(bytes)); if (template instanceof Class) { deser = ExtUtil.deserialize(bytes, (Class) template, pf); } else if (template instanceof ExternalizableWrapper) { deser = ExtUtil.read( new DataInputStream(new ByteArrayInputStream(bytes)), (ExternalizableWrapper) template, pf); } else { throw new ClassCastException(); } print("Reconstituted: " + printObj(deser)); if (ExtUtil.equals(orig, deser)) { print("SUCCESS"); } else { print("FAILURE"); tc.fail(failMessage + ": Objects do not match"); } print("---------------------------------------------"); } catch (Exception e) { tc.fail(failMessage + ": Exception! " + e.getClass().getName() + " " + e.getMessage()); } }