Source Code Cross Referenced for UspsServicesTests.java in  » ERP-CRM-Financial » ofbiz » org » ofbiz » shipment » thirdparty » usps » 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 » ERP CRM Financial » ofbiz » org.ofbiz.shipment.thirdparty.usps 
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.ofbiz.shipment.thirdparty.usps;
019:
020:        import java.util.List;
021:        import java.util.Map;
022:        import java.util.HashMap;
023:
024:        import junit.framework.TestCase;
025:        import org.ofbiz.base.util.Debug;
026:        import org.ofbiz.base.util.UtilMisc;
027:        import org.ofbiz.entity.GenericDelegator;
028:        import org.ofbiz.service.GenericDispatcher;
029:        import org.ofbiz.service.LocalDispatcher;
030:        import org.ofbiz.service.ModelService;
031:
032:        /**
033:         * Tests for USPS Webtools API services
034:         *
035:         * These were created for simple validation only.
036:         */
037:        public class UspsServicesTests extends TestCase {
038:
039:            public static String module = UspsServicesTests.class.getName();
040:
041:            public static final String DELEGATOR_NAME = "test";
042:            public static final String DISPATCHER_NAME = "test-dispatcher";
043:
044:            private GenericDelegator delegator = null;
045:            private LocalDispatcher dispatcher = null;
046:
047:            public UspsServicesTests(String name) {
048:                super (name);
049:            }
050:
051:            protected void setUp() throws Exception {
052:                delegator = GenericDelegator
053:                        .getGenericDelegator(DELEGATOR_NAME);
054:                dispatcher = GenericDispatcher.getLocalDispatcher(
055:                        DISPATCHER_NAME, delegator);
056:            }
057:
058:            protected void tearDown() throws Exception {
059:                dispatcher.deregister();
060:            }
061:
062:            public void testUspsTrackConfirm() throws Exception {
063:
064:                // run the service
065:                Map result = dispatcher.runSync("uspsTrackConfirm", UtilMisc
066:                        .toMap("trackingId", "EJ958083578US"));
067:
068:                // verify the results
069:                String responseMessage = (String) result
070:                        .get(ModelService.RESPONSE_MESSAGE);
071:                Debug.log("[testUspsTrackConfirm] responseMessage: "
072:                        + responseMessage, module);
073:                assertEquals("Service result is success",
074:                        ModelService.RESPOND_SUCCESS, responseMessage);
075:
076:                String trackingSummary = (String) result.get("trackingSummary");
077:                Debug.log("[testUspsTrackConfirm] trackingSummary: "
078:                        + trackingSummary, module);
079:                assertEquals(
080:                        "trackingSummary is correct",
081:                        "Your item was delivered at 8:10 am on June 1 in Wilmington DE 19801.",
082:                        trackingSummary);
083:
084:                List trackingDetailList = (List) result
085:                        .get("trackingDetailList");
086:                assertEquals("trackingDetailList has 3 elements", 3,
087:                        trackingDetailList.size());
088:
089:                Debug.log("[testUspsTrackConfirm] trackingDetailList[0]: "
090:                        + trackingDetailList.get(0), module);
091:                assertEquals("trackingDetailList element 0 is correct",
092:                        "May 30 11:07 am NOTICE LEFT WILMINGTON DE 19801.",
093:                        trackingDetailList.get(0));
094:
095:                Debug.log("[testUspsTrackConfirm] trackingDetailList[1]: "
096:                        + trackingDetailList.get(1), module);
097:                assertEquals("trackingDetailList element 0 is correct",
098:                        "May 30 10:08 am ARRIVAL AT UNIT WILMINGTON DE 19850.",
099:                        trackingDetailList.get(1));
100:
101:                Debug.log("[testUspsTrackConfirm] trackingDetailList[2]: "
102:                        + trackingDetailList.get(2), module);
103:                assertEquals("trackingDetailList element 0 is correct",
104:                        "May 29 9:55 am ACCEPT OR PICKUP EDGEWATER NJ 07020.",
105:                        trackingDetailList.get(2));
106:            }
107:
108:            public void testUspsAddressValidation() throws Exception {
109:
110:                // run the service
111:                Map result = dispatcher.runSync("uspsAddressValidation",
112:                        UtilMisc.toMap("address1", "6406 Ivy Lane", "city",
113:                                "Greenbelt", "state", "MD"));
114:
115:                // verify the results
116:                String responseMessage = (String) result
117:                        .get(ModelService.RESPONSE_MESSAGE);
118:                Debug.log("[testUspsAddressValidation] responseMessage: "
119:                        + responseMessage, module);
120:                assertEquals("Service result is success",
121:                        ModelService.RESPOND_SUCCESS, responseMessage);
122:
123:                String address1 = (String) result.get("address1");
124:                Debug.log("[testUspsAddressValidation] address1: " + address1,
125:                        module);
126:                assertEquals("address1 is correct", "6406 IVY LN", address1);
127:
128:                String city = (String) result.get("city");
129:                Debug.log("[testUspsAddressValidation] city: " + city, module);
130:                assertEquals("city is correct", "GREENBELT", city);
131:
132:                String state = (String) result.get("state");
133:                Debug
134:                        .log("[testUspsAddressValidation] state: " + state,
135:                                module);
136:                assertEquals("state is correct", "MD", state);
137:
138:                String zip5 = (String) result.get("zip5");
139:                Debug.log("[testUspsAddressValidation] zip5: " + zip5, module);
140:                assertEquals("zip5 is correct", "20770", zip5);
141:
142:                String zip4 = (String) result.get("zip4");
143:                Debug.log("[testUspsAddressValidation] zip4: " + zip4, module);
144:                assertEquals("zip4 is correct", "1440", zip4);
145:            }
146:
147:            public void testUspsCityStateLookup() throws Exception {
148:
149:                // run the service
150:                Map result = dispatcher.runSync("uspsCityStateLookup", UtilMisc
151:                        .toMap("zip5", "90210"));
152:
153:                // verify the results
154:                String responseMessage = (String) result
155:                        .get(ModelService.RESPONSE_MESSAGE);
156:                Debug.log("[testUspsCityStateLookup] responseMessage: "
157:                        + responseMessage, module);
158:                assertEquals("Service result is success",
159:                        ModelService.RESPOND_SUCCESS, responseMessage);
160:
161:                String city = (String) result.get("city");
162:                Debug.log("[testUspsCityStateLookup] city: " + city, module);
163:                assertEquals("city is correct", "BEVERLY HILLS", city);
164:
165:                String state = (String) result.get("state");
166:                Debug.log("[testUspsCityStateLookup] state: " + state, module);
167:                assertEquals("state is correct", "CA", state);
168:            }
169:
170:            public void testUspsPriorityMailStandard() throws Exception {
171:
172:                // run the service
173:                Map result = dispatcher
174:                        .runSync("uspsPriorityMailStandard", UtilMisc.toMap(
175:                                "originZip", "4", "destinationZip", "4"));
176:
177:                // verify the results
178:                String responseMessage = (String) result
179:                        .get(ModelService.RESPONSE_MESSAGE);
180:                Debug.log("[testUspsPriorityMailStandard] responseMessage: "
181:                        + responseMessage, module);
182:                assertEquals("Service result is success",
183:                        ModelService.RESPOND_SUCCESS, responseMessage);
184:
185:                String days = (String) result.get("days");
186:                Debug.log("[testUspsPriorityMailStandard] days: " + days,
187:                        module);
188:                assertEquals("days is correct", "1", days);
189:            }
190:
191:            public void testUspsPackageServicesStandard() throws Exception {
192:
193:                // run the service
194:                Map result = dispatcher
195:                        .runSync("uspsPackageServicesStandard", UtilMisc.toMap(
196:                                "originZip", "4", "destinationZip", "4"));
197:
198:                // verify the results
199:                String responseMessage = (String) result
200:                        .get(ModelService.RESPONSE_MESSAGE);
201:                Debug.log("[testUspsPackageServicesStandard] responseMessage: "
202:                        + responseMessage, module);
203:                assertEquals("Service result is success",
204:                        ModelService.RESPOND_SUCCESS, responseMessage);
205:
206:                String days = (String) result.get("days");
207:                Debug.log("[testUspsPackageServicesStandard] days: " + days,
208:                        module);
209:                assertEquals("days is correct", "2", days);
210:            }
211:
212:            public void testUspsDomesticRate() throws Exception {
213:
214:                // prepare the context
215:                Map context = new HashMap();
216:
217:                context.put("service", "Priority");
218:                context.put("originZip", "20770");
219:                context.put("destinationZip", "09021");
220:                context.put("pounds", "5");
221:                context.put("ounces", "1");
222:                context.put("container", "None");
223:                context.put("size", "Regular");
224:                context.put("machinable", "False");
225:
226:                // run the service
227:                Map result = dispatcher.runSync("uspsDomesticRate", context);
228:
229:                // verify the results
230:                String responseMessage = (String) result
231:                        .get(ModelService.RESPONSE_MESSAGE);
232:                Debug.log("[testUspsDomesticRate] responseMessage: "
233:                        + responseMessage, module);
234:                assertEquals("Service result is success",
235:                        ModelService.RESPOND_SUCCESS, responseMessage);
236:
237:                String postage = (String) result.get("postage");
238:                Debug.log("[testUspsDomesticRate] postage: " + postage, module);
239:                assertEquals("postage is correct", "7.90", postage);
240:
241:                String restrictionCodes = (String) result
242:                        .get("restrictionCodes");
243:                Debug.log("[testUspsDomesticRate] restrictionCodes: "
244:                        + restrictionCodes, module);
245:                assertEquals("restrictionCodes is correct", "B-B1-C-D-U",
246:                        restrictionCodes);
247:
248:                String restrictionDesc = (String) result.get("restrictionDesc");
249:                Debug.log("[testUspsDomesticRate] restrictionDesc: "
250:                        + restrictionDesc, module);
251:                assertEquals("restrictionDesc is correct", "B. Form 2976-A",
252:                        restrictionDesc.substring(0, 14));
253:            }
254:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.