Source Code Cross Referenced for ReferenceAndReplicationTest.java in  » Net » Terracotta » com » tctest » spring » integrationtests » tests » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » Terracotta » com.tctest.spring.integrationtests.tests 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice.  All rights reserved.
003:         */
004:        package com.tctest.spring.integrationtests.tests;
005:
006:        import com.tc.test.server.appserver.deployment.AbstractTwoServerDeploymentTest;
007:        import com.tc.test.server.appserver.deployment.DeploymentBuilder;
008:        import com.tctest.spring.bean.ISimpleBean;
009:        import com.tctest.spring.integrationtests.SpringTwoServerTestSetup;
010:
011:        import java.util.HashSet;
012:        import java.util.Set;
013:
014:        import junit.extensions.TestSetup;
015:        import junit.framework.Test;
016:
017:        /**
018:         * Testing the following features
019:         * 1. Replication behavior
020:         * 2. Bean reference another bean and how the sharing
021:         *
022:         * Test depends on the order of the instantiation of the parent beans
023:         *
024:         * @author Liyu Yi
025:         */
026:        public class ReferenceAndReplicationTest extends
027:                AbstractTwoServerDeploymentTest {
028:
029:            private static final String SHAREDPARENT_SERVICE_NAME = "ShareParent";
030:            private static final String LOCALCHILD1_SERVICE_NAME = "LocalChild1";
031:            private static final String LOCALCHILD2_SERVICE_NAME = "LocalChild2";
032:            private static final String LOCALCHILD3_SERVICE_NAME = "LocalChild3";
033:            private static final String BEAN_DEFINITION_FILE_FOR_TEST = "classpath:/com/tctest/spring/beanfactory-referenceandreplication.xml";
034:            private static final String CONFIG_FILE_FOR_TEST = "/tc-config-files/referenceandreplication-tc-config.xml";
035:
036:            // for N1
037:            private ISimpleBean sharedParentN1;
038:            private ISimpleBean localChild1N1;
039:            private ISimpleBean localChild2N1;
040:            private ISimpleBean localChild3N1;
041:
042:            // for N2
043:            private ISimpleBean sharedParentN2;
044:            private ISimpleBean localChild1N2;
045:            private ISimpleBean localChild2N2;
046:            private ISimpleBean localChild3N2;
047:
048:            protected void setUp() throws Exception {
049:                super .setUp();
050:                // for N1
051:                localChild1N1 = (ISimpleBean) server0.getProxy(
052:                        ISimpleBean.class, LOCALCHILD1_SERVICE_NAME);
053:                localChild2N1 = (ISimpleBean) server0.getProxy(
054:                        ISimpleBean.class, LOCALCHILD2_SERVICE_NAME);
055:                localChild3N1 = (ISimpleBean) server0.getProxy(
056:                        ISimpleBean.class, LOCALCHILD3_SERVICE_NAME);
057:                sharedParentN1 = (ISimpleBean) server0.getProxy(
058:                        ISimpleBean.class, SHAREDPARENT_SERVICE_NAME);
059:                // for N2
060:                localChild1N2 = (ISimpleBean) server1.getProxy(
061:                        ISimpleBean.class, LOCALCHILD1_SERVICE_NAME);
062:                localChild2N2 = (ISimpleBean) server1.getProxy(
063:                        ISimpleBean.class, LOCALCHILD2_SERVICE_NAME);
064:                localChild3N2 = (ISimpleBean) server1.getProxy(
065:                        ISimpleBean.class, LOCALCHILD3_SERVICE_NAME);
066:                sharedParentN2 = (ISimpleBean) server1.getProxy(
067:                        ISimpleBean.class, SHAREDPARENT_SERVICE_NAME);
068:            }
069:
070:            public void testReplication() throws Exception {
071:                logger.debug("testing replication of shared spring bean");
072:                // check pre-conditions
073:                long id2 = sharedParentN2.getId();
074:                long id1 = sharedParentN1.getId();
075:
076:                assertFalse("Pre-condition check failed", id1 == id2);
077:
078:                long timeStamp1 = sharedParentN1.getTimeStamp();
079:                long timeStamp2 = sharedParentN2.getTimeStamp();
080:                long timeStampMin = timeStamp1 < timeStamp2 ? timeStamp1
081:                        : timeStamp2;
082:
083:                // check shared field replication and also the behavior of
084:                // the GetBeanProtocol for the 2nd Node (which is N1) to grab the shared
085:                // bean from singletonCache in the mixin
086:                assertEquals("Shared field replication failed: "
087:                        + sharedParentN1.getSharedId(), timeStampMin,
088:                        sharedParentN1.getSharedId());
089:                assertEquals("Shared field replication failed: "
090:                        + sharedParentN2.getSharedId(), timeStampMin,
091:                        sharedParentN2.getSharedId());
092:
093:                // check shared field replication again
094:                assertNull("", sharedParentN2.getField());
095:                sharedParentN1.setField("" + id1);
096:                assertEquals("Shared field replication failed: "
097:                        + sharedParentN2.getField(), "" + id1, sharedParentN2
098:                        .getField());
099:
100:                // check transient field stopping replication
101:                assertNull("Pre-condition check failed", sharedParentN1
102:                        .getTransientField());
103:                assertNull("Pre-condition check failed", sharedParentN2
104:                        .getTransientField());
105:                sharedParentN1.setTransientField("" + id1);
106:                sharedParentN2.setTransientField("" + id2);
107:                assertEquals("Unexpected field replication: "
108:                        + sharedParentN1.getTransientField(), "" + id1,
109:                        sharedParentN1.getTransientField());
110:                assertEquals("Unexpected field replication: "
111:                        + sharedParentN2.getTransientField(), "" + id2,
112:                        sharedParentN2.getTransientField());
113:
114:                // check "dso transient" field stopping replication
115:                assertNull("Pre-condition check failed", sharedParentN1
116:                        .getDsoTransientField());
117:                assertNull("Pre-condition check failed", sharedParentN2
118:                        .getDsoTransientField());
119:                sharedParentN1.setDsoTransientField("" + id1);
120:                sharedParentN2.setDsoTransientField("" + id2);
121:                assertEquals("Unexpected field replication: "
122:                        + sharedParentN1.getDsoTransientField(), "" + id1,
123:                        sharedParentN1.getDsoTransientField());
124:                assertEquals("Unexpected field replication: "
125:                        + sharedParentN2.getDsoTransientField(), "" + id2,
126:                        sharedParentN2.getDsoTransientField());
127:
128:                // check static field stopping replication
129:                assertNull("Pre-condition check failed", sharedParentN1
130:                        .getStaticField());
131:                assertNull("Pre-condition check failed", sharedParentN2
132:                        .getStaticField());
133:                sharedParentN1.setStaticField("" + id1);
134:                sharedParentN2.setStaticField("" + id2);
135:                assertEquals("Unexpected field replication: "
136:                        + sharedParentN1.getStaticField(), "" + id1,
137:                        sharedParentN1.getStaticField());
138:                assertEquals("Unexpected field replication: "
139:                        + sharedParentN2.getStaticField(), "" + id2,
140:                        sharedParentN2.getStaticField());
141:
142:                logger.debug("!!!! Asserts passed !!!");
143:            }
144:
145:            public void testBeanReference() throws Exception {
146:                logger.debug("testing shared bean reference other beans");
147:
148:                // check pre-conditions
149:                long id2 = sharedParentN2.getId();
150:                long id1 = sharedParentN1.getId();
151:
152:                assertFalse("Pre-condition check failed", id1 == id2);
153:
154:                Set idSet = new HashSet();
155:
156:                long id11 = localChild1N1.getId();
157:                idSet.add(new Long(id11));
158:                long id21 = localChild2N1.getId();
159:                idSet.add(new Long(id21));
160:                long id31 = localChild3N1.getId();
161:                idSet.add(new Long(id31));
162:                long id12 = localChild1N2.getId();
163:                idSet.add(new Long(id12));
164:                long id22 = localChild2N2.getId();
165:                idSet.add(new Long(id22));
166:                long id32 = localChild3N2.getId();
167:                idSet.add(new Long(id32));
168:
169:                assertEquals("Pre-condition check failed: " + idSet, 6, idSet
170:                        .size());
171:
172:                // check localChild1 -- bean through shared reference is NOT shared if the reference bean is not declared as shared explicitly
173:                //    localChild1N1.setField("localChild1N1");
174:                //    localChild1N2.setField("localChild1N2");
175:                //    assertEquals("Unexcpected field replication: " + localChild1N1.getField(), "localChild1N1", localChild1N1.getField());
176:                //    assertEquals("Unexcpected field replication: " + localChild1N2.getField(), "localChild1N2", localChild1N2.getField());
177:                //
178:                //    assertEquals("Singleton semantics broken: " + id11 + " - " + sharedParentN1.getSharedRefId(), id11, sharedParentN1.getSharedRefId());
179:                //    assertEquals("Singleton semantics broken: " + id12 + " - " + sharedParentN2.getSharedRefId(), id12, sharedParentN2.getSharedRefId());
180:
181:                // check localChild2 -- bean through transient reference is not shared
182:                localChild2N1.setField("localChild2N1");
183:                localChild2N2.setField("localChild2N2");
184:                assertEquals("Unexcpected field replication: "
185:                        + localChild2N1.getField(), "localChild2N1",
186:                        localChild2N1.getField());
187:                assertEquals("Unexcpected field replication: "
188:                        + localChild2N2.getField(), "localChild2N2",
189:                        localChild2N2.getField());
190:
191:                // check localChild3 -- bean through dso transient reference is not shared
192:                localChild3N1.setField("localChild3N1");
193:                localChild3N2.setField("localChild3N2");
194:                assertEquals("Unexcpected field replication: "
195:                        + localChild3N1.getField(), "localChild3N1",
196:                        localChild3N1.getField());
197:                assertEquals("Unexcpected field replication: "
198:                        + localChild3N2.getField(), "localChild3N2",
199:                        localChild3N2.getField());
200:
201:                logger.debug("!!!! Asserts passed !!!");
202:            }
203:
204:            private static class InnerTestSetup extends
205:                    SpringTwoServerTestSetup {
206:                private InnerTestSetup() {
207:                    super (ReferenceAndReplicationTest.class,
208:                            CONFIG_FILE_FOR_TEST,
209:                            "test-referenceandreplication");
210:                }
211:
212:                protected void configureWar(DeploymentBuilder builder) {
213:                    builder
214:                            .addBeanDefinitionFile(BEAN_DEFINITION_FILE_FOR_TEST);
215:                    builder.addRemoteService(SHAREDPARENT_SERVICE_NAME,
216:                            "sharedParent", ISimpleBean.class);
217:                    builder.addRemoteService(LOCALCHILD1_SERVICE_NAME,
218:                            "localChild1", ISimpleBean.class);
219:                    builder.addRemoteService(LOCALCHILD2_SERVICE_NAME,
220:                            "localChild2", ISimpleBean.class);
221:                    builder.addRemoteService(LOCALCHILD3_SERVICE_NAME,
222:                            "localChild3", ISimpleBean.class);
223:                }
224:            }
225:
226:            /**
227:             *  JUnit test loader entry point
228:             */
229:            public static Test suite() {
230:                TestSetup setup = new InnerTestSetup();
231:                return setup;
232:            }
233:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.