[jboss-cvs] jboss-serialization/tests/org/serial/testshared ...

Clebert Suconic csuconic at jboss.com
Fri Jul 28 01:00:44 EDT 2006


  User: csuconic
  Date: 06/07/28 01:00:43

  Added:       tests/org/serial/testshared  SharedObjectsTestCase.java
  Log:
  refactoring wrong package name
  
  Revision  Changes    Path
  1.1      date: 2006/07/28 05:00:43;  author: csuconic;  state: Exp;jboss-serialization/tests/org/serial/testshared/SharedObjectsTestCase.java
  
  Index: SharedObjectsTestCase.java
  ===================================================================
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt 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.serial.testshared;
  
  import java.io.ByteArrayInputStream;
  import java.io.ByteArrayOutputStream;
  import java.io.ObjectInputStream;
  import java.io.ObjectOutputStream;
  import java.util.Collection;
  import java.util.Collections;
  
  import junit.framework.TestCase;
  
  import org.jboss.serial.data.TestCircularReferences;
  import org.jboss.serial.io.JBossObjectInputStreamSharedTree;
  import org.jboss.serial.io.JBossObjectOutputStreamSharedTree;
  
  /** Verifies if two objects written to the same Streaming will share the same object tree */
  public class SharedObjectsTestCase extends TestCase
  {
  	public void testJava() throws Exception
  	{
  		ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
  		ObjectOutputStream objOut = new ObjectOutputStream(byteOut);
  
  		TestCircularReferences circular = TestCircularReferences.createTestInstance();
  		objOut.writeObject(circular.getReferences());
  		objOut.writeObject(circular);
  		objOut.reset();
  		objOut.writeObject(circular.getReferences());
  		
  		ObjectInputStream objInput = new ObjectInputStream(new ByteArrayInputStream(byteOut.toByteArray()));
  		
  		Object first = objInput.readObject();
  		TestCircularReferences second = (TestCircularReferences)objInput.readObject();
  		Object third = objInput.readObject();
  		assertSame((Object)second.getReferences(),first);
  		assertEquals(circular.getReferences().size(),((Collection)third).size());
  		assertNotSame(third,second);
  	}
  	
  	public void testJBoss() throws Exception
  	{
  		ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
  		ObjectOutputStream objOut = new JBossObjectOutputStreamSharedTree(byteOut);
  
  		TestCircularReferences circular = TestCircularReferences.createTestInstance();
  		objOut.writeObject(circular.getReferences());
  		objOut.writeObject(circular);
  		objOut.reset();
  		objOut.writeObject(circular.getReferences());
  		
  		ObjectInputStream objInput = new JBossObjectInputStreamSharedTree(new ByteArrayInputStream(byteOut.toByteArray()));
  		
  		Object first = objInput.readObject();
  		TestCircularReferences second = (TestCircularReferences)objInput.readObject();
  		Object third = objInput.readObject();
  		assertSame((Object)second.getReferences(),first);
  		assertEquals(circular.getReferences().size(),((Collection)third).size());
  		assertNotSame(third,second);
  	}
  }
  
  
  



More information about the jboss-cvs-commits mailing list