Package org.hudsonci.utils.marshal

Examples of org.hudsonci.utils.marshal.XStreamMarshaller


    @Test
    public void testChewDocument() throws Exception {
        XStream xs = new XStream();
        xs.autodetectAnnotations(true);
        XStreamMarshaller marshaller = new XStreamMarshaller(xs);

        XReferenceStore store = new FileXReferenceStore(marshaller, util.resolveFile("target/test-xref"));
        XReferenceStoreConverter converter = new XReferenceStoreConverter(store, xs.getMapper(), xs.getReflectionProvider());
        xs.registerConverter(converter);

        Document<Record> doc1 = new Document<Record>();
        Record rec1 = new Record("1");
        Entity ent1 = new Entity("1");
        rec1.set(ent1);
        assertNotNull(rec1.entity.holder);
        assertTrue(rec1.entity.holder instanceof XReference.InstanceHolder);
        XReference.InstanceHolder holder1 = (XReference.InstanceHolder)rec1.entity.holder;
        assertNotNull(holder1.instance);

        doc1.records.add(rec1);

        StringWriter buff = new StringWriter();
        marshaller.marshal(doc1, buff);
        System.out.println("XML:\n" + buff);

        Document<Record> doc2 = (Document<Record>) marshaller.unmarshal(new StringReader(buff.toString()));
        assertNotNull(doc2);
        assertNotNull(doc2.records);
        assertEquals(1, doc2.records.size());

        Record rec2 = doc2.records.get(0);
        assertNotNull(rec2.entity);
        System.out.println("ENT REF: " + rec2.entity);
        assertNotNull(rec2.entity.holder);
        assertTrue(rec2.entity.holder instanceof XReferenceStoreConverter.UnmarshalHolder);

        XReferenceStoreConverter.UnmarshalHolder holder2 = (XReferenceStoreConverter.UnmarshalHolder)rec2.entity.holder;
        assertNull(holder2.instance);

        Entity ent2 = rec2.get();
        System.out.println("ENT: " + ent2);
        assertNotNull(ent2);
        assertNotNull(holder2.instance);

        buff = new StringWriter();
        marshaller.marshal(doc2, buff);
        System.out.println("XML\n" + buff);
    }
View Full Code Here

TOP

Related Classes of org.hudsonci.utils.marshal.XStreamMarshaller

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.