Source Code Cross Referenced for PolicyUtilsTest.java in  » Web-Services-apache-cxf-2.0.1 » transports » org » apache » cxf » transport » http » policy » 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 » transports » org.apache.cxf.transport.http.policy 
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.transport.http.policy;
019:
020:        import java.util.ArrayList;
021:        import java.util.Collection;
022:        import java.util.Collections;
023:
024:        import org.apache.cxf.helpers.CastUtils;
025:        import org.apache.cxf.message.Exchange;
026:        import org.apache.cxf.message.Message;
027:        import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
028:        import org.apache.cxf.transports.http.configuration.HTTPServerPolicy;
029:        import org.apache.cxf.ws.policy.AssertionInfo;
030:        import org.apache.cxf.ws.policy.AssertionInfoMap;
031:        import org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion;
032:        import org.apache.neethi.Assertion;
033:        import org.easymock.classextension.EasyMock;
034:        import org.easymock.classextension.IMocksControl;
035:        import org.junit.Assert;
036:        import org.junit.Before;
037:        import org.junit.Test;
038:
039:        /**
040:         * 
041:         */
042:        public class PolicyUtilsTest extends Assert {
043:
044:            private IMocksControl control;
045:
046:            @Before
047:            public void setUp() {
048:                control = EasyMock.createNiceControl();
049:            }
050:
051:            @Test
052:            public void testCompatibleClientPolicies() {
053:                HTTPClientPolicy p1 = new HTTPClientPolicy();
054:                assertTrue("Policy is not compatible with itself.", PolicyUtils
055:                        .compatible(p1, p1));
056:                HTTPClientPolicy p2 = new HTTPClientPolicy();
057:                assertTrue("Policies are not compatible.", PolicyUtils
058:                        .compatible(p1, p2));
059:                p1.setBrowserType("browser");
060:                assertTrue("Policies are not compatible.", PolicyUtils
061:                        .compatible(p1, p2));
062:                p1.setBrowserType(null);
063:                p1.setConnectionTimeout(10000);
064:                assertTrue("Policies are not compatible.", PolicyUtils
065:                        .compatible(p1, p2));
066:                p1.setAllowChunking(false);
067:                assertTrue("Policies are compatible.", !PolicyUtils.compatible(
068:                        p1, p2));
069:                p2.setAllowChunking(false);
070:                assertTrue("Policies are compatible.", PolicyUtils.compatible(
071:                        p1, p2));
072:            }
073:
074:            @Test
075:            public void testIntersectClientPolicies() {
076:                HTTPClientPolicy p1 = new HTTPClientPolicy();
077:                HTTPClientPolicy p2 = new HTTPClientPolicy();
078:                HTTPClientPolicy p = null;
079:
080:                p1.setBrowserType("browser");
081:                p = PolicyUtils.intersect(p1, p2);
082:                assertEquals("browser", p.getBrowserType());
083:                p1.setBrowserType(null);
084:                p1.setConnectionTimeout(10000L);
085:                p = PolicyUtils.intersect(p1, p2);
086:                assertEquals(10000L, p.getConnectionTimeout());
087:                p1.setAllowChunking(false);
088:                p2.setAllowChunking(false);
089:                p = PolicyUtils.intersect(p1, p2);
090:                assertTrue(!p.isAllowChunking());
091:            }
092:
093:            @Test
094:            public void testEqualClientPolicies() {
095:                HTTPClientPolicy p1 = new HTTPClientPolicy();
096:                assertTrue(PolicyUtils.equals(p1, p1));
097:                HTTPClientPolicy p2 = new HTTPClientPolicy();
098:                assertTrue(PolicyUtils.equals(p1, p2));
099:                p1.setDecoupledEndpoint("http://localhost:8080/decoupled");
100:                assertTrue(!PolicyUtils.equals(p1, p2));
101:                p2.setDecoupledEndpoint("http://localhost:8080/decoupled");
102:                assertTrue(PolicyUtils.equals(p1, p2));
103:                p1.setReceiveTimeout(10000L);
104:                assertTrue(!PolicyUtils.equals(p1, p2));
105:            }
106:
107:            @Test
108:            public void testCompatibleServerPolicies() {
109:                HTTPServerPolicy p1 = new HTTPServerPolicy();
110:                assertTrue("Policy is not compatible with itself.", PolicyUtils
111:                        .compatible(p1, p1));
112:                HTTPServerPolicy p2 = new HTTPServerPolicy();
113:                assertTrue("Policies are not compatible.", PolicyUtils
114:                        .compatible(p1, p2));
115:                p1.setServerType("server");
116:                assertTrue("Policies are not compatible.", PolicyUtils
117:                        .compatible(p1, p2));
118:                p1.setServerType(null);
119:                p1.setReceiveTimeout(10000);
120:                assertTrue("Policies are not compatible.", PolicyUtils
121:                        .compatible(p1, p2));
122:                p1.setSuppressClientSendErrors(false);
123:                assertTrue("Policies are compatible.", PolicyUtils.compatible(
124:                        p1, p2));
125:                p1.setSuppressClientSendErrors(true);
126:                assertTrue("Policies are compatible.", !PolicyUtils.compatible(
127:                        p1, p2));
128:                p2.setSuppressClientSendErrors(true);
129:                assertTrue("Policies are compatible.", PolicyUtils.compatible(
130:                        p1, p2));
131:            }
132:
133:            @Test
134:            public void testIntersectServerPolicies() {
135:                HTTPServerPolicy p1 = new HTTPServerPolicy();
136:                HTTPServerPolicy p2 = new HTTPServerPolicy();
137:                HTTPServerPolicy p = null;
138:
139:                p1.setServerType("server");
140:                p = PolicyUtils.intersect(p1, p2);
141:                assertEquals("server", p.getServerType());
142:                p1.setServerType(null);
143:                p1.setReceiveTimeout(10000L);
144:                p = PolicyUtils.intersect(p1, p2);
145:                assertEquals(10000L, p.getReceiveTimeout());
146:                p1.setSuppressClientSendErrors(true);
147:                p2.setSuppressClientSendErrors(true);
148:                p = PolicyUtils.intersect(p1, p2);
149:                assertTrue(p.isSuppressClientSendErrors());
150:            }
151:
152:            @Test
153:            public void testEqualServerPolicies() {
154:                HTTPServerPolicy p1 = new HTTPServerPolicy();
155:                assertTrue(PolicyUtils.equals(p1, p1));
156:                HTTPServerPolicy p2 = new HTTPServerPolicy();
157:                assertTrue(PolicyUtils.equals(p1, p2));
158:                p1.setContentEncoding("encoding");
159:                assertTrue(!PolicyUtils.equals(p1, p2));
160:                p2.setContentEncoding("encoding");
161:                assertTrue(PolicyUtils.equals(p1, p2));
162:                p1.setSuppressClientSendErrors(true);
163:                assertTrue(!PolicyUtils.equals(p1, p2));
164:            }
165:
166:            @Test
167:            public void testAssertClientPolicyNoop() {
168:                testAssertPolicyNoop(true);
169:            }
170:
171:            @Test
172:            public void testAssertServerPolicyNoop() {
173:                testAssertPolicyNoop(false);
174:            }
175:
176:            void testAssertPolicyNoop(boolean isRequestor) {
177:                Message message = control.createMock(Message.class);
178:                EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(
179:                        null);
180:                control.replay();
181:                PolicyUtils.assertClientPolicy(message, null);
182:                control.verify();
183:
184:                control.reset();
185:                Collection<Assertion> as = new ArrayList<Assertion>();
186:                AssertionInfoMap aim = new AssertionInfoMap(as);
187:                EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(
188:                        aim);
189:                control.replay();
190:                if (isRequestor) {
191:                    PolicyUtils.assertClientPolicy(message, null);
192:                } else {
193:                    PolicyUtils.assertServerPolicy(message, null);
194:                }
195:                control.verify();
196:            }
197:
198:            @Test
199:            public void testAssertClientPolicyOutbound() {
200:                testAssertClientPolicy(true);
201:            }
202:
203:            @Test
204:            public void testAssertClientPolicyInbound() {
205:                testAssertClientPolicy(false);
206:            }
207:
208:            void testAssertClientPolicy(boolean outbound) {
209:                Message message = control.createMock(Message.class);
210:                HTTPClientPolicy ep = new HTTPClientPolicy();
211:                HTTPClientPolicy cmp = new HTTPClientPolicy();
212:
213:                cmp.setConnectionTimeout(60000L);
214:                HTTPClientPolicy icmp = new HTTPClientPolicy();
215:                icmp.setAllowChunking(false);
216:
217:                JaxbAssertion<HTTPClientPolicy> ea = new JaxbAssertion<HTTPClientPolicy>(
218:                        PolicyUtils.HTTPCLIENTPOLICY_ASSERTION_QNAME, false);
219:                ea.setData(ep);
220:                JaxbAssertion<HTTPClientPolicy> cma = new JaxbAssertion<HTTPClientPolicy>(
221:                        PolicyUtils.HTTPCLIENTPOLICY_ASSERTION_QNAME, false);
222:                cma.setData(cmp);
223:                JaxbAssertion<HTTPClientPolicy> icma = new JaxbAssertion<HTTPClientPolicy>(
224:                        PolicyUtils.HTTPCLIENTPOLICY_ASSERTION_QNAME, false);
225:                icma.setData(icmp);
226:
227:                AssertionInfo eai = new AssertionInfo(ea);
228:                AssertionInfo cmai = new AssertionInfo(cma);
229:                AssertionInfo icmai = new AssertionInfo(icma);
230:
231:                AssertionInfoMap aim = new AssertionInfoMap(CastUtils.cast(
232:                        Collections.EMPTY_LIST, Assertion.class));
233:                Collection<AssertionInfo> ais = new ArrayList<AssertionInfo>();
234:                ais.add(eai);
235:                ais.add(cmai);
236:                ais.add(icmai);
237:                aim.put(PolicyUtils.HTTPCLIENTPOLICY_ASSERTION_QNAME, ais);
238:                EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(
239:                        aim);
240:                Exchange ex = control.createMock(Exchange.class);
241:                EasyMock.expect(message.getExchange()).andReturn(ex);
242:                EasyMock.expect(ex.getOutMessage()).andReturn(
243:                        outbound ? message : null);
244:                if (!outbound) {
245:                    EasyMock.expect(ex.getOutFaultMessage()).andReturn(null);
246:                }
247:
248:                control.replay();
249:                PolicyUtils.assertClientPolicy(message, ep);
250:                assertTrue(eai.isAsserted());
251:                assertTrue(cmai.isAsserted());
252:                assertTrue(outbound ? !icmai.isAsserted() : icmai.isAsserted());
253:                control.verify();
254:            }
255:
256:            @Test
257:            public void testAssertServerPolicyOutbound() {
258:                testAssertServerPolicy(true);
259:            }
260:
261:            @Test
262:            public void testAssertServerPolicyInbound() {
263:                testAssertServerPolicy(false);
264:            }
265:
266:            void testAssertServerPolicy(boolean outbound) {
267:                Message message = control.createMock(Message.class);
268:                HTTPServerPolicy ep = new HTTPServerPolicy();
269:                HTTPServerPolicy mp = new HTTPServerPolicy();
270:                HTTPServerPolicy cmp = new HTTPServerPolicy();
271:                cmp.setReceiveTimeout(60000L);
272:                HTTPServerPolicy icmp = new HTTPServerPolicy();
273:                icmp.setSuppressClientSendErrors(true);
274:
275:                JaxbAssertion<HTTPServerPolicy> ea = new JaxbAssertion<HTTPServerPolicy>(
276:                        PolicyUtils.HTTPSERVERPOLICY_ASSERTION_QNAME, false);
277:                ea.setData(ep);
278:                JaxbAssertion<HTTPServerPolicy> ma = new JaxbAssertion<HTTPServerPolicy>(
279:                        PolicyUtils.HTTPSERVERPOLICY_ASSERTION_QNAME, false);
280:                ma.setData(mp);
281:                JaxbAssertion<HTTPServerPolicy> cma = new JaxbAssertion<HTTPServerPolicy>(
282:                        PolicyUtils.HTTPSERVERPOLICY_ASSERTION_QNAME, false);
283:                cma.setData(cmp);
284:                JaxbAssertion<HTTPServerPolicy> icma = new JaxbAssertion<HTTPServerPolicy>(
285:                        PolicyUtils.HTTPSERVERPOLICY_ASSERTION_QNAME, false);
286:                icma.setData(icmp);
287:
288:                AssertionInfo eai = new AssertionInfo(ea);
289:                AssertionInfo mai = new AssertionInfo(ma);
290:                AssertionInfo cmai = new AssertionInfo(cma);
291:                AssertionInfo icmai = new AssertionInfo(icma);
292:
293:                AssertionInfoMap aim = new AssertionInfoMap(CastUtils.cast(
294:                        Collections.EMPTY_LIST, Assertion.class));
295:                Collection<AssertionInfo> ais = new ArrayList<AssertionInfo>();
296:                ais.add(eai);
297:                ais.add(mai);
298:                ais.add(cmai);
299:                ais.add(icmai);
300:                aim.put(PolicyUtils.HTTPSERVERPOLICY_ASSERTION_QNAME, ais);
301:                EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(
302:                        aim);
303:                Exchange ex = control.createMock(Exchange.class);
304:                EasyMock.expect(message.getExchange()).andReturn(ex);
305:                EasyMock.expect(ex.getOutMessage()).andReturn(
306:                        outbound ? message : null);
307:                if (!outbound) {
308:                    EasyMock.expect(ex.getOutFaultMessage()).andReturn(null);
309:                }
310:
311:                control.replay();
312:                PolicyUtils.assertServerPolicy(message, ep);
313:                assertTrue(eai.isAsserted());
314:                assertTrue(mai.isAsserted());
315:                assertTrue(outbound ? cmai.isAsserted() : !cmai.isAsserted());
316:                assertTrue(outbound ? icmai.isAsserted() : !icmai.isAsserted());
317:                control.verify();
318:            }
319:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.