Source Code Cross Referenced for RMInInterceptorTest.java in  » Web-Services-apache-cxf-2.0.1 » ws-rm » org » apache » cxf » ws » rm » 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 » Web Services apache cxf 2.0.1 » ws rm » org.apache.cxf.ws.rm 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements. See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership. The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License. You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied. See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */package org.apache.cxf.ws.rm;
019:
020:        import java.lang.reflect.Method;
021:        import java.util.ArrayList;
022:        import java.util.Collection;
023:        import java.util.Iterator;
024:        import java.util.SortedSet;
025:        import java.util.TreeSet;
026:
027:        import org.apache.cxf.message.Exchange;
028:        import org.apache.cxf.message.Message;
029:        import org.apache.cxf.phase.Phase;
030:        import org.apache.cxf.phase.PhaseInterceptorChain;
031:        import org.apache.cxf.ws.addressing.AddressingPropertiesImpl;
032:        import org.apache.cxf.ws.addressing.AttributedURIType;
033:        import org.apache.cxf.ws.addressing.JAXWSAConstants;
034:        import org.apache.cxf.ws.addressing.MAPAggregator;
035:        import org.apache.cxf.ws.policy.AssertionInfoMap;
036:        import org.easymock.classextension.EasyMock;
037:        import org.easymock.classextension.IMocksControl;
038:        import org.junit.After;
039:        import org.junit.Assert;
040:        import org.junit.Before;
041:        import org.junit.Test;
042:
043:        public class RMInInterceptorTest extends Assert {
044:
045:            private IMocksControl control;
046:            private RMInInterceptor interceptor;
047:            private RMManager manager;
048:            private RMEndpoint rme;
049:            private RMProperties rmps;
050:
051:            @Before
052:            public void setUp() {
053:                control = EasyMock.createNiceControl();
054:                rmps = control.createMock(RMProperties.class);
055:            }
056:
057:            @After
058:            public void tearDown() {
059:                control.verify();
060:            }
061:
062:            @Test
063:            public void testOrdering() {
064:                control.replay();
065:                Phase p = new Phase(Phase.PRE_LOGICAL, 1);
066:                SortedSet<Phase> phases = new TreeSet<Phase>();
067:                phases.add(p);
068:                PhaseInterceptorChain chain = new PhaseInterceptorChain(phases);
069:                MAPAggregator map = new MAPAggregator();
070:                RMInInterceptor rmi = new RMInInterceptor();
071:                chain.add(rmi);
072:                chain.add(map);
073:                Iterator it = chain.iterator();
074:                assertSame("Unexpected order.", rmi, it.next());
075:                assertSame("Unexpected order.", map, it.next());
076:
077:            }
078:
079:            @Test
080:            public void testHandleCreateSequenceOnServer()
081:                    throws SequenceFault, RMException {
082:                interceptor = new RMInInterceptor();
083:                Message message = setupInboundMessage(RMConstants
084:                        .getCreateSequenceAction(), true);
085:                rme.receivedControlMessage();
086:                EasyMock.expectLastCall();
087:                EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(
088:                        null);
089:
090:                control.replay();
091:                interceptor.handle(message);
092:            }
093:
094:            @Test
095:            public void testHandleCreateSequenceOnClient()
096:                    throws SequenceFault, RMException {
097:                interceptor = new RMInInterceptor();
098:                Message message = setupInboundMessage(RMConstants
099:                        .getCreateSequenceAction(), false);
100:                rme.receivedControlMessage();
101:                EasyMock.expectLastCall();
102:                Servant servant = control.createMock(Servant.class);
103:                EasyMock.expect(rme.getServant()).andReturn(servant);
104:                CreateSequenceResponseType csr = control
105:                        .createMock(CreateSequenceResponseType.class);
106:                EasyMock.expect(servant.createSequence(message)).andReturn(csr);
107:                Proxy proxy = control.createMock(Proxy.class);
108:                EasyMock.expect(rme.getProxy()).andReturn(proxy);
109:                proxy.createSequenceResponse(csr);
110:                EasyMock.expectLastCall();
111:
112:                control.replay();
113:                interceptor.handle(message);
114:            }
115:
116:            @Test
117:            public void testHandleSequenceAckOnClient() throws SequenceFault,
118:                    RMException, NoSuchMethodException {
119:                testHandleSequenceAck(false);
120:            }
121:
122:            @Test
123:            public void testHandleSequenceAckOnServer() throws SequenceFault,
124:                    RMException, NoSuchMethodException {
125:                testHandleSequenceAck(true);
126:            }
127:
128:            private void testHandleSequenceAck(boolean onServer)
129:                    throws SequenceFault, RMException, NoSuchMethodException {
130:                Method m = RMInInterceptor.class.getDeclaredMethod(
131:                        "processAcknowledgments", new Class[] { Source.class,
132:                                RMProperties.class });
133:                interceptor = control.createMock(RMInInterceptor.class,
134:                        new Method[] { m });
135:                Message message = setupInboundMessage(RMConstants
136:                        .getSequenceAckAction(), onServer);
137:                rme.receivedControlMessage();
138:                EasyMock.expectLastCall();
139:                Source s = control.createMock(Source.class);
140:                EasyMock.expect(rme.getSource()).andReturn(s);
141:                interceptor.processAcknowledgments(s, rmps);
142:                EasyMock.expectLastCall();
143:                EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(
144:                        null);
145:
146:                control.replay();
147:                interceptor.handle(message);
148:            }
149:
150:            @Test
151:            public void testHandleTerminateSequenceOnServer()
152:                    throws SequenceFault, RMException {
153:                testHandleTerminateSequence(true);
154:            }
155:
156:            @Test
157:            public void testHandleTerminateSequenceOnClient()
158:                    throws SequenceFault, RMException {
159:                testHandleTerminateSequence(false);
160:            }
161:
162:            private void testHandleTerminateSequence(boolean onServer)
163:                    throws SequenceFault, RMException {
164:                interceptor = new RMInInterceptor();
165:                Message message = setupInboundMessage(RMConstants
166:                        .getTerminateSequenceAction(), onServer);
167:                rme.receivedControlMessage();
168:                EasyMock.expectLastCall();
169:                EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(
170:                        null);
171:
172:                control.replay();
173:                interceptor.handle(message);
174:            }
175:
176:            @Test
177:            public void testAppRequest() throws SequenceFault, RMException,
178:                    NoSuchMethodException {
179:                testAppMessage(true);
180:            }
181:
182:            @Test
183:            public void testAppResponse() throws SequenceFault, RMException,
184:                    NoSuchMethodException {
185:                testAppMessage(false);
186:            }
187:
188:            private void testAppMessage(boolean onServer) throws SequenceFault,
189:                    RMException, NoSuchMethodException {
190:                Method m1 = RMInInterceptor.class.getDeclaredMethod(
191:                        "processAcknowledgments", new Class[] { Source.class,
192:                                RMProperties.class });
193:                Method m2 = RMInInterceptor.class.getDeclaredMethod(
194:                        "processAcknowledgmentRequests", new Class[] {
195:                                Destination.class, Message.class });
196:                Method m3 = RMInInterceptor.class.getDeclaredMethod(
197:                        "processSequence", new Class[] { Destination.class,
198:                                Message.class });
199:                Method m4 = RMInInterceptor.class.getDeclaredMethod(
200:                        "processDeliveryAssurance",
201:                        new Class[] { RMProperties.class });
202:                interceptor = control.createMock(RMInInterceptor.class,
203:                        new Method[] { m1, m2, m3, m4 });
204:                Message message = setupInboundMessage("greetMe", true);
205:                Destination d = control.createMock(Destination.class);
206:                EasyMock.expect(manager.getDestination(message)).andReturn(d);
207:                Source s = control.createMock(Source.class);
208:                EasyMock.expect(rme.getSource()).andReturn(s);
209:                interceptor.processAcknowledgments(s, rmps);
210:                EasyMock.expectLastCall();
211:                interceptor.processAcknowledgmentRequests(d, message);
212:                EasyMock.expectLastCall();
213:                interceptor.processSequence(d, message);
214:                EasyMock.expectLastCall();
215:                interceptor.processDeliveryAssurance(rmps);
216:                EasyMock.expectLastCall();
217:                EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(
218:                        null);
219:                rme.receivedApplicationMessage();
220:                EasyMock.expectLastCall();
221:
222:                control.replay();
223:                interceptor.handle(message);
224:            }
225:
226:            @Test
227:            public void testProcessAcknowledgments() throws RMException {
228:                interceptor = new RMInInterceptor();
229:                manager = control.createMock(RMManager.class);
230:                Source source = control.createMock(Source.class);
231:                interceptor.setManager(manager);
232:                SequenceAcknowledgement ack1 = control
233:                        .createMock(SequenceAcknowledgement.class);
234:                SequenceAcknowledgement ack2 = control
235:                        .createMock(SequenceAcknowledgement.class);
236:                Collection<SequenceAcknowledgement> acks = new ArrayList<SequenceAcknowledgement>();
237:                acks.add(ack1);
238:                acks.add(ack2);
239:                EasyMock.expect(rmps.getAcks()).andReturn(acks);
240:                Identifier id1 = control.createMock(Identifier.class);
241:                EasyMock.expect(ack1.getIdentifier()).andReturn(id1);
242:                SourceSequence ss1 = control.createMock(SourceSequence.class);
243:                EasyMock.expect(source.getSequence(id1)).andReturn(ss1);
244:                ss1.setAcknowledged(ack1);
245:                EasyMock.expectLastCall();
246:                Identifier id2 = control.createMock(Identifier.class);
247:                EasyMock.expect(ack2.getIdentifier()).andReturn(id2);
248:                EasyMock.expect(source.getSequence(id2)).andReturn(null);
249:
250:                control.replay();
251:                try {
252:                    interceptor.processAcknowledgments(source, rmps);
253:                    fail("Expected SequenceFault not thrown");
254:                } catch (SequenceFault sf) {
255:                    assertEquals(RMConstants.getUnknownSequenceFaultCode(), sf
256:                            .getSequenceFault().getFaultCode());
257:                }
258:            }
259:
260:            @Test
261:            public void testProcessAcknowledgmentRequests() {
262:                control.replay();
263:                // TODI
264:            }
265:
266:            @Test
267:            public void testProcessSequence() throws SequenceFault, RMException {
268:                Destination destination = control.createMock(Destination.class);
269:                Message message = control.createMock(Message.class);
270:                destination.acknowledge(message);
271:                EasyMock.expectLastCall();
272:                control.replay();
273:                interceptor = new RMInInterceptor();
274:                interceptor.processSequence(destination, message);
275:            }
276:
277:            @Test
278:            public void testProcessDeliveryAssurance() {
279:                control.replay();
280:                // TODO
281:            }
282:
283:            private Message setupInboundMessage(String action,
284:                    boolean serverSide) {
285:                Message message = control.createMock(Message.class);
286:                Exchange exchange = control.createMock(Exchange.class);
287:                EasyMock.expect(message.getExchange()).andReturn(exchange)
288:                        .times(2);
289:                EasyMock.expect(exchange.getOutMessage()).andReturn(null);
290:                EasyMock.expect(exchange.getOutFaultMessage()).andReturn(null);
291:                EasyMock.expect(
292:                        message.get(RMMessageConstants.RM_PROPERTIES_INBOUND))
293:                        .andReturn(rmps);
294:
295:                EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(
296:                        !serverSide);
297:                AddressingPropertiesImpl maps = control
298:                        .createMock(AddressingPropertiesImpl.class);
299:                EasyMock
300:                        .expect(
301:                                message
302:                                        .get(JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_INBOUND))
303:                        .andReturn(maps);
304:
305:                AttributedURIType actionURI = control
306:                        .createMock(AttributedURIType.class);
307:                EasyMock.expect(maps.getAction()).andReturn(actionURI).times(2);
308:                EasyMock.expect(actionURI.getValue()).andReturn(action);
309:
310:                EasyMock
311:                        .expect(
312:                                message
313:                                        .get(RMMessageConstants.ORIGINAL_REQUESTOR_ROLE))
314:                        .andReturn(Boolean.FALSE);
315:                EasyMock.expect(
316:                        message.put(Message.REQUESTOR_ROLE, Boolean.FALSE))
317:                        .andReturn(null);
318:
319:                org.apache.cxf.transport.Destination td = serverSide ? control
320:                        .createMock(org.apache.cxf.transport.Destination.class)
321:                        : null;
322:                EasyMock.expect(exchange.getDestination()).andReturn(td);
323:
324:                manager = control.createMock(RMManager.class);
325:                interceptor.setManager(manager);
326:                rme = control.createMock(RMEndpoint.class);
327:                EasyMock.expect(manager.getReliableEndpoint(message))
328:                        .andReturn(rme);
329:                return message;
330:            }
331:
332:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.