1 4 package com.tc.object.msg; 5 6 import com.tc.exception.ImplementMe; 7 import com.tc.io.TCByteBufferOutputStream; 8 import com.tc.net.protocol.tcm.ChannelID; 9 import com.tc.net.protocol.tcm.NullMessageMonitor; 10 import com.tc.net.protocol.tcm.TCMessageHeader; 11 import com.tc.net.protocol.tcm.TCMessageType; 12 import com.tc.net.protocol.tcm.TestMessageChannel; 13 import com.tc.object.ObjectID; 14 import com.tc.object.ObjectRequestContext; 15 import com.tc.object.ObjectRequestID; 16 import com.tc.object.session.SessionID; 17 import com.tc.test.TCTestCase; 18 19 import java.util.HashSet ; 20 import java.util.Set ; 21 22 public class RequestManagedObjectMessageImplTest extends TCTestCase { 23 24 public void testBasics() throws Exception { 25 TestMessageChannel channel = new TestMessageChannel(); 26 TCMessageType type = TCMessageType.REQUEST_MANAGED_OBJECT_MESSAGE; 27 28 TestObjectRequestContext ctxt = new TestObjectRequestContext(); 29 ObjectID id = new ObjectID(1); 30 Set removedIDs = new HashSet (); 31 for (int i = 3; i < 100; i++) { 32 removedIDs.add(new ObjectID(i)); 33 } 34 35 RequestManagedObjectMessageImpl msg = new RequestManagedObjectMessageImpl(new NullMessageMonitor(), 36 new TCByteBufferOutputStream(4, 4096, 37 false), 38 channel, type); 39 Set oids = new HashSet (); 40 oids.add(id); 41 msg.initialize(ctxt, oids, removedIDs); 42 43 msg.dehydrate(); 44 45 RequestManagedObjectMessageImpl msg2 = new RequestManagedObjectMessageImpl(SessionID.NULL_ID, 46 new NullMessageMonitor(), channel, 47 (TCMessageHeader) msg.getHeader(), msg 48 .getPayload()); 49 msg2.hydrate(); 50 51 Set ids = new HashSet (); 52 ids.add(id); 53 54 checkMessageValues(ctxt, removedIDs, ids, msg2); 55 } 56 57 private void checkMessageValues(TestObjectRequestContext ctxt, Set removedIDs, Set ids, 58 RequestManagedObjectMessageImpl msg) { 59 assertEquals(ids, new HashSet (msg.getObjectIDs())); 60 assertEquals(ctxt.getRequestID(), msg.getRequestID()); 61 assertEquals(removedIDs, msg.getRemoved()); 62 } 63 64 private static class TestObjectRequestContext implements ObjectRequestContext { 65 66 public ObjectRequestID getRequestID() { 67 return new ObjectRequestID(1); 68 } 69 70 public ChannelID getChannelID() { 71 throw new ImplementMe(); 72 } 73 74 public Set getObjectIDs() { 75 throw new ImplementMe(); 76 } 77 78 public int getRequestDepth() { 79 return 10; 80 } 81 } 82 } 83 | Popular Tags |