KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > util > DsoFinalMethodTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
3  * notice. All rights reserved.
4  */

5 package com.tc.util;
6
7 import com.tc.exception.ImplementMe;
8 import com.tc.net.protocol.tcm.ChannelIDProvider;
9 import com.tc.net.protocol.tcm.TestChannelIDProvider;
10 import com.tc.object.BaseDSOTestCase;
11 import com.tc.object.ClientObjectManagerImpl;
12 import com.tc.object.MockTCObject;
13 import com.tc.object.ObjectID;
14 import com.tc.object.Portability;
15 import com.tc.object.RemoteObjectManager;
16 import com.tc.object.TCClassFactory;
17 import com.tc.object.TCObject;
18 import com.tc.object.TCObjectFactory;
19 import com.tc.object.TestClassFactory;
20 import com.tc.object.TestObjectFactory;
21 import com.tc.object.TestRemoteObjectManager;
22 import com.tc.object.bytecode.MockClassProvider;
23 import com.tc.object.cache.EvictionPolicy;
24 import com.tc.object.cache.NullCache;
25 import com.tc.object.config.DSOClientConfigHelper;
26 import com.tc.object.idprovider.api.ObjectIDProvider;
27 import com.tc.object.idprovider.impl.ObjectIDProviderImpl;
28 import com.tc.object.loaders.ClassProvider;
29 import com.tc.object.logging.NullRuntimeLogger;
30 import com.tc.object.logging.RuntimeLogger;
31 import com.tc.object.tx.MockTransactionManager;
32 import com.tc.util.sequence.SimpleSequence;
33
34 /**
35  * Test to see if an adapted class has all of the adaptations we expect.
36  */

37 public class DsoFinalMethodTest extends BaseDSOTestCase {
38   private String JavaDoc rootName;
39   private Object JavaDoc rootObject;
40   private MockClientObjectManagerImpl objectManager;
41
42   protected void setUp() throws Exception JavaDoc {
43     super.setUp();
44
45     rootName = "testSyncRoot";
46     rootObject = new Object JavaDoc();
47     ObjectID objectID = new ObjectID(1);
48     TCObject tcObject = new MockTCObject(objectID, rootObject);
49     TestObjectFactory objectFactory = new TestObjectFactory();
50     objectFactory.peerObject = rootObject;
51     objectFactory.tcObject = tcObject;
52     objectManager = new MockClientObjectManagerImpl(new MockRemoteObjectManagerImpl(), configHelper(),
53                                                     new ObjectIDProviderImpl(new SimpleSequence()), new NullCache(),
54                                                     new NullRuntimeLogger(), new TestChannelIDProvider(),
55                                                     new MockClassProvider(), new TestClassFactory(), objectFactory);
56
57     objectManager.setTransactionManager(new MockTransactionManagerImpl());
58   }
59
60   protected void tearDown() throws Exception JavaDoc {
61     super.tearDown();
62     this.objectManager = null;
63     this.rootName = null;
64     this.rootObject = null;
65   }
66
67   /**
68    * This test makes sure that method retrieveRootID() of RemoteObjectManager will not be called when dsoFinal is set to
69    * false when a root is being created.
70    */

71   public void testRootCreateOrReplaceWithNonDsoFinal() throws Exception JavaDoc {
72     // If retrieveRootID() of RemoteObjectManager is being called, this call will throw an
73
// AssertionError.
74
objectManager.lookupOrCreateRoot(rootName, rootObject, false);
75   }
76
77   public void testRootCreateOrReplaceWithDsoFinal() throws Exception JavaDoc {
78     try {
79       objectManager.lookupOrCreateRoot(rootName, rootObject, true);
80       throw new AssertionError JavaDoc("should have thrown an AssertionError");
81     } catch (AssertionError JavaDoc e) {
82       // expected.
83
}
84   }
85
86   private static class MockClientObjectManagerImpl extends ClientObjectManagerImpl {
87     public MockClientObjectManagerImpl(RemoteObjectManager remoteObjectManager,
88                                        DSOClientConfigHelper clientConfiguration, ObjectIDProvider idProvider,
89                                        EvictionPolicy cache, RuntimeLogger runtimeLogger, ChannelIDProvider provider,
90                                        ClassProvider classProvider, TCClassFactory classFactory,
91                                        TCObjectFactory objectFactory) {
92       super(remoteObjectManager, clientConfiguration, idProvider, cache, runtimeLogger, provider, classProvider,
93             classFactory, objectFactory, new TestPortability(), null);
94       }
95
96     public boolean isPortable(Object JavaDoc obj) {
97       return true;
98     }
99
100     public Object JavaDoc lookupObject(ObjectID objectID) {
101       return null;
102     }
103   }
104
105   private static class MockRemoteObjectManagerImpl extends TestRemoteObjectManager {
106
107     public ObjectID retrieveRootID(String JavaDoc name) {
108       throw new AssertionError JavaDoc("retrieveRootID should not be called.");
109     }
110   }
111
112   private static class MockTransactionManagerImpl extends MockTransactionManager {
113     public void createRoot(String JavaDoc name, ObjectID id) {
114       return;
115     }
116
117     public void createObject(TCObject source) {
118       return;
119     }
120   }
121
122   private static class TestPortability implements Portability {
123
124     public boolean allowSubclassOf(Class JavaDoc clazz) {
125       return true;
126     }
127
128     public NonPortableReason getNonPortableReason(Class JavaDoc topLevelClass) {
129       throw new ImplementMe();
130     }
131
132     public boolean isInstrumentationNotNeeded(String JavaDoc name) {
133       return false;
134     }
135
136     public boolean isPortableClass(Class JavaDoc clazz) {
137       return true;
138     }
139
140     public boolean isClassPhysicallyInstrumented(Class JavaDoc clazz) {
141       throw new ImplementMe();
142     }
143
144     public boolean isPortableInstance(Object JavaDoc obj) {
145       return true;
146     }
147
148   }
149
150 }
151
Popular Tags