/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc. and/or its affiliates, and * individual contributors as indicated by the @author tags. See the * copyright.txt file in the distribution for a full listing of * individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.infinispan.marshall; import org.infinispan.commands.RemoteCommandsFactory; import org.infinispan.test.AbstractInfinispanTest; import org.jboss.marshalling.ContextClassResolver; import org.jboss.marshalling.MarshallerFactory; import org.jboss.marshalling.Marshalling; import org.jboss.marshalling.MarshallingConfiguration; import org.jboss.marshalling.Unmarshaller; import org.jboss.marshalling.reflect.SunReflectiveCreator; import org.jboss.marshalling.river.RiverMarshallerFactory; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.Serializable; /** * // TODO: Document this * * @author Galder ZamarreƱo */ @Test(groups = "functional", testName = "marshall.LowerLevelMarshall534545Test") public class LowerLevelMarshall534545Test extends AbstractInfinispanTest { // private final VersionAwareMarshaller marshaller = new VersionAwareMarshaller(); private MarshallerFactory factory; private org.jboss.marshalling.Marshaller marshaller; private Unmarshaller unmarshaller; @BeforeTest public void setUp() throws Exception { // marshaller.inject(Thread.currentThread().getContextClassLoader(), new RemoteCommandsFactory()); // marshaller.start(); MarshallingConfiguration configuration = new MarshallingConfiguration(); configuration.setCreator(new SunReflectiveCreator()); configuration.setObjectTable(null); configuration.setClassResolver(new ContextClassResolver()); configuration.setVersion(2); factory = new RiverMarshallerFactory(); marshaller = factory.createMarshaller(configuration); unmarshaller = factory.createUnmarshaller(configuration); } // @AfterClass // public void tearDown() { // marshaller.stop(); // } // public void test000() throws Exception { // Child1 child1Obj = new Child1(1234, "1234"); // byte[] bytes = marshaller.objectToByteBuffer(child1Obj); // marshaller.objectFromByteBuffer(bytes); // } // public void test001() throws Exception { // Child1 child1Obj = new Child1(1234, "1234"); // Child2 child2Obj = new Child2(2345, "2345", child1Obj); // byte[] bytes = marshaller.objectToByteBuffer(child2Obj); // marshaller.objectFromByteBuffer(bytes); // } public void test000() throws Exception { Child1 child1Obj = new Child1(1234, "1234"); ByteArrayOutputStream baos = new ByteArrayOutputStream(128); marshaller.start(Marshalling.createByteOutput(baos)); try { marshaller.writeObject(child1Obj); } finally { marshaller.finish(); } byte[] bytes = baos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes, 0, bytes.length); unmarshaller.start(Marshalling.createByteInput(bais)); try { unmarshaller.readObject(); } finally { unmarshaller.finish(); } } public void test001() throws Exception { Child1 child1Obj = new Child1(1234, "1234"); Child2 child2Obj = new Child2(2345, "2345", child1Obj); ByteArrayOutputStream baos = new ByteArrayOutputStream(128); marshaller.start(Marshalling.createByteOutput(baos)); try { marshaller.writeObject(child2Obj); } finally { marshaller.finish(); } byte[] bytes = baos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes, 0, bytes.length); unmarshaller.start(Marshalling.createByteInput(bais)); try { unmarshaller.readObject(); } finally { unmarshaller.finish(); } } static class Parent implements Serializable { private String id; private Child1 child1Obj; public Parent(String id, Child1 child1Obj) { this.id = id; this.child1Obj = child1Obj; } public String getId() { return id; } public Child1 getChild1Obj() { return child1Obj; } } static class Child1 extends Parent { private int someInt; public Child1(int someInt, String parentStr) { super(parentStr, null); this.someInt = someInt; } } static class Child2 extends Parent { private int someInt; public Child2(int someInt, String parentStr, Child1 child1Obj) { super(parentStr, child1Obj); this.someInt = someInt; } } }