[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/marshall ...

Manik Surtani manik at jboss.org
Wed Mar 7 18:39:36 EST 2007


  User: msurtani
  Date: 07/03/07 18:39:36

  Added:       tests/functional/org/jboss/cache/marshall 
                        MethodIdPreservationTest.java
  Log:
  test preservation of method ids across remote calls
  
  Revision  Changes    Path
  1.1      date: 2007/03/07 23:39:36;  author: msurtani;  state: Exp;JBossCache/tests/functional/org/jboss/cache/marshall/MethodIdPreservationTest.java
  
  Index: MethodIdPreservationTest.java
  ===================================================================
  package org.jboss.cache.marshall;
  
  import junit.framework.TestCase;
  import org.jboss.cache.Fqn;
  
  import java.io.ByteArrayInputStream;
  import java.io.ByteArrayOutputStream;
  import java.io.ObjectInputStream;
  import java.io.ObjectOutputStream;
  import java.util.ArrayList;
  import java.util.List;
  
  /**
   * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
   * @since 2.0.0
   */
  public class MethodIdPreservationTest extends TestCase
  {
     private Marshaller m = new CacheMarshaller200(null, false, false);
     private ObjectOutputStream stream;
     private ByteArrayOutputStream byteStream;
     private MethodCall call1;
     private MethodCall call2;
     private List<MethodCall> list = new ArrayList<MethodCall>(2);
     private MethodCall prepareCall;
  
     protected void setUp() throws Exception
     {
        byteStream = new ByteArrayOutputStream();
        stream = new ObjectOutputStream(byteStream);
        call1 = MethodCallFactory.create(MethodDeclarations.putDataMethodLocal, null, Fqn.ROOT, null, null, true);
        call2 = MethodCallFactory.create(MethodDeclarations.putDataMethodLocal, null, Fqn.ROOT, null, null, true);
        list.clear();
        list.add(call1);
        list.add(call2);
        prepareCall = MethodCallFactory.create(MethodDeclarations.prepareMethod, null, list, null, true);
     }
  
     public void testSingleMethodCall() throws Exception
     {
        m.objectToObjectStream(call1, stream);
        stream.close();
        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(byteStream.toByteArray()));
        Object result = m.objectFromObjectStream(in);
        assertEquals(call1.getClass(), result.getClass());
  
        MethodCall resultMethod = (MethodCall) result;
        assertEquals(call1.getMethodId(), resultMethod.getMethodId());
     }
  
     public void testListOfMethodCalls() throws Exception
     {
        m.objectToObjectStream(list, stream);
        stream.close();
        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(byteStream.toByteArray()));
        Object result = m.objectFromObjectStream(in);
        assertEquals(list.getClass(), result.getClass());
        assertEquals(list.size(), ((List) result).size());
        MethodCall result1 = (MethodCall) ((List) result).get(0);
        MethodCall result2 = (MethodCall) ((List) result).get(1);
  
        assertEquals(call1.getMethodId(), result1.getMethodId());
        assertEquals(call2.getMethodId(), result2.getMethodId());
     }
  
     public void testMethodCallsInPrepare() throws Exception
     {
        m.objectToObjectStream(prepareCall, stream);
        stream.close();
        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(byteStream.toByteArray()));
        Object result = m.objectFromObjectStream(in);
  
        assertEquals(prepareCall.getClass(), result.getClass());
        MethodCall prepareCallRes = (MethodCall) result;
        List listResult = (List) prepareCallRes.getArgs()[1];
  
        assertEquals(list.size(), listResult.size());
        MethodCall result1 = (MethodCall) listResult.get(0);
        MethodCall result2 = (MethodCall) listResult.get(1);
  
        assertEquals(call1.getMethodId(), result1.getMethodId());
        assertEquals(call2.getMethodId(), result2.getMethodId());
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list