KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > shipment > thirdparty > usps > UspsServicesTests


1 /*
2  * $Id: UspsServicesTests.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2004 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */

24
25 package org.ofbiz.shipment.thirdparty.usps;
26
27 import java.util.List JavaDoc;
28 import java.util.Map JavaDoc;
29 import java.util.HashMap JavaDoc;
30
31 import junit.framework.TestCase;
32 import org.ofbiz.base.util.Debug;
33 import org.ofbiz.base.util.UtilMisc;
34 import org.ofbiz.entity.GenericDelegator;
35 import org.ofbiz.service.GenericDispatcher;
36 import org.ofbiz.service.LocalDispatcher;
37 import org.ofbiz.service.ModelService;
38
39
40 /**
41  * Tests for USPS Webtools API services
42  *
43  * These were created for simple validation only.
44  *
45  * @author <a HREF="mailto:eckardjf@pobox.com">J. Eckard</a>
46  * @version $Rev: 5462 $
47  * @since 3.2
48  */

49 public class UspsServicesTests extends TestCase {
50
51     public static String JavaDoc module = UspsServicesTests.class.getName();
52
53     public static final String JavaDoc DELEGATOR_NAME = "test";
54     public static final String JavaDoc DISPATCHER_NAME = "test-dispatcher";
55
56     private GenericDelegator delegator = null;
57     private LocalDispatcher dispatcher = null;
58
59
60     public UspsServicesTests(String JavaDoc name) {
61         super(name);
62     }
63
64     protected void setUp() throws Exception JavaDoc {
65         delegator = GenericDelegator.getGenericDelegator(DELEGATOR_NAME);
66         dispatcher = new GenericDispatcher(DISPATCHER_NAME, delegator);
67     }
68
69     protected void tearDown() throws Exception JavaDoc {
70         dispatcher.deregister();
71     }
72
73     public void testUspsTrackConfirm() throws Exception JavaDoc {
74
75         // run the service
76
Map JavaDoc result = dispatcher.runSync("uspsTrackConfirm", UtilMisc.toMap("trackingId", "EJ958083578US"));
77
78         // verify the results
79
String JavaDoc responseMessage = (String JavaDoc) result.get(ModelService.RESPONSE_MESSAGE);
80         Debug.log("[testUspsTrackConfirm] responseMessage: " + responseMessage, module);
81         assertEquals("Service result is success", ModelService.RESPOND_SUCCESS, responseMessage);
82
83         String JavaDoc trackingSummary = (String JavaDoc) result.get("trackingSummary");
84         Debug.log("[testUspsTrackConfirm] trackingSummary: " + trackingSummary, module);
85         assertEquals("trackingSummary is correct",
86                 "Your item was delivered at 8:10 am on June 1 in Wilmington DE 19801.", trackingSummary);
87
88         List JavaDoc trackingDetailList = (List JavaDoc) result.get("trackingDetailList");
89         assertEquals("trackingDetailList has 3 elements", 3, trackingDetailList.size());
90
91         Debug.log("[testUspsTrackConfirm] trackingDetailList[0]: " + trackingDetailList.get(0), module);
92         assertEquals("trackingDetailList element 0 is correct",
93                 "May 30 11:07 am NOTICE LEFT WILMINGTON DE 19801.", trackingDetailList.get(0));
94
95         Debug.log("[testUspsTrackConfirm] trackingDetailList[1]: " + trackingDetailList.get(1), module);
96         assertEquals("trackingDetailList element 0 is correct",
97                 "May 30 10:08 am ARRIVAL AT UNIT WILMINGTON DE 19850.", trackingDetailList.get(1));
98
99         Debug.log("[testUspsTrackConfirm] trackingDetailList[2]: " + trackingDetailList.get(2), module);
100         assertEquals("trackingDetailList element 0 is correct",
101                 "May 29 9:55 am ACCEPT OR PICKUP EDGEWATER NJ 07020.", trackingDetailList.get(2));
102     }
103
104     public void testUspsAddressValidation() throws Exception JavaDoc {
105
106         // run the service
107
Map JavaDoc result = dispatcher.runSync("uspsAddressValidation",
108                 UtilMisc.toMap("address1", "6406 Ivy Lane", "city", "Greenbelt", "state", "MD"));
109
110         // verify the results
111
String JavaDoc responseMessage = (String JavaDoc) result.get(ModelService.RESPONSE_MESSAGE);
112         Debug.log("[testUspsAddressValidation] responseMessage: " + responseMessage, module);
113         assertEquals("Service result is success", ModelService.RESPOND_SUCCESS, responseMessage);
114
115         String JavaDoc address1 = (String JavaDoc) result.get("address1");
116         Debug.log("[testUspsAddressValidation] address1: " + address1, module);
117         assertEquals("address1 is correct", "6406 IVY LN", address1);
118
119         String JavaDoc city = (String JavaDoc) result.get("city");
120         Debug.log("[testUspsAddressValidation] city: " + city, module);
121         assertEquals("city is correct", "GREENBELT", city);
122
123         String JavaDoc state = (String JavaDoc) result.get("state");
124         Debug.log("[testUspsAddressValidation] state: " + state, module);
125         assertEquals("state is correct", "MD", state);
126
127         String JavaDoc zip5 = (String JavaDoc) result.get("zip5");
128         Debug.log("[testUspsAddressValidation] zip5: " + zip5, module);
129         assertEquals("zip5 is correct", "20770", zip5);
130
131         String JavaDoc zip4 = (String JavaDoc) result.get("zip4");
132         Debug.log("[testUspsAddressValidation] zip4: " + zip4, module);
133         assertEquals("zip4 is correct", "1440", zip4);
134     }
135
136     public void testUspsCityStateLookup() throws Exception JavaDoc {
137
138         // run the service
139
Map JavaDoc result = dispatcher.runSync("uspsCityStateLookup", UtilMisc.toMap("zip5", "90210"));
140
141         // verify the results
142
String JavaDoc responseMessage = (String JavaDoc) result.get(ModelService.RESPONSE_MESSAGE);
143         Debug.log("[testUspsCityStateLookup] responseMessage: " + responseMessage, module);
144         assertEquals("Service result is success", ModelService.RESPOND_SUCCESS, responseMessage);
145
146         String JavaDoc city = (String JavaDoc) result.get("city");
147         Debug.log("[testUspsCityStateLookup] city: " + city, module);
148         assertEquals("city is correct", "BEVERLY HILLS", city);
149
150         String JavaDoc state = (String JavaDoc) result.get("state");
151         Debug.log("[testUspsCityStateLookup] state: " + state, module);
152         assertEquals("state is correct", "CA", state);
153     }
154
155     public void testUspsPriorityMailStandard() throws Exception JavaDoc {
156
157         // run the service
158
Map JavaDoc result = dispatcher.runSync("uspsPriorityMailStandard", UtilMisc.toMap("originZip", "4", "destinationZip", "4"));
159
160         // verify the results
161
String JavaDoc responseMessage = (String JavaDoc) result.get(ModelService.RESPONSE_MESSAGE);
162         Debug.log("[testUspsPriorityMailStandard] responseMessage: " + responseMessage, module);
163         assertEquals("Service result is success", ModelService.RESPOND_SUCCESS, responseMessage);
164
165         String JavaDoc days = (String JavaDoc) result.get("days");
166         Debug.log("[testUspsPriorityMailStandard] days: " + days, module);
167         assertEquals("days is correct", "1", days);
168     }
169
170     public void testUspsPackageServicesStandard() throws Exception JavaDoc {
171
172         // run the service
173
Map JavaDoc result = dispatcher.runSync("uspsPackageServicesStandard", UtilMisc.toMap("originZip", "4", "destinationZip", "4"));
174
175         // verify the results
176
String JavaDoc responseMessage = (String JavaDoc) result.get(ModelService.RESPONSE_MESSAGE);
177         Debug.log("[testUspsPackageServicesStandard] responseMessage: " + responseMessage, module);
178         assertEquals("Service result is success", ModelService.RESPOND_SUCCESS, responseMessage);
179
180         String JavaDoc days = (String JavaDoc) result.get("days");
181         Debug.log("[testUspsPackageServicesStandard] days: " + days, module);
182         assertEquals("days is correct", "2", days);
183     }
184
185     public void testUspsDomesticRate() throws Exception JavaDoc {
186
187         // prepare the context
188
Map JavaDoc context = new HashMap JavaDoc();
189
190         context.put("service", "Priority");
191         context.put("originZip", "20770");
192         context.put("destinationZip", "09021");
193         context.put("pounds", "5");
194         context.put("ounces", "1");
195         context.put("container", "None");
196         context.put("size", "Regular");
197         context.put("machinable", "False");
198
199         // run the service
200
Map JavaDoc result = dispatcher.runSync("uspsDomesticRate", context);
201
202         // verify the results
203
String JavaDoc responseMessage = (String JavaDoc) result.get(ModelService.RESPONSE_MESSAGE);
204         Debug.log("[testUspsDomesticRate] responseMessage: " + responseMessage, module);
205         assertEquals("Service result is success", ModelService.RESPOND_SUCCESS, responseMessage);
206
207         String JavaDoc postage = (String JavaDoc) result.get("postage");
208         Debug.log("[testUspsDomesticRate] postage: " + postage, module);
209         assertEquals("postage is correct", "7.90", postage);
210
211         String JavaDoc restrictionCodes = (String JavaDoc) result.get("restrictionCodes");
212         Debug.log("[testUspsDomesticRate] restrictionCodes: " + restrictionCodes, module);
213         assertEquals("restrictionCodes is correct", "B-B1-C-D-U", restrictionCodes);
214
215         String JavaDoc restrictionDesc = (String JavaDoc) result.get("restrictionDesc");
216         Debug.log("[testUspsDomesticRate] restrictionDesc: " + restrictionDesc, module);
217         assertEquals("restrictionDesc is correct", "B. Form 2976-A", restrictionDesc.substring(0,14));
218     }
219 }
220
Popular Tags