-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathCustomsItemTest.java
102 lines (87 loc) · 4.12 KB
/
CustomsItemTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package com.shippo.model;
import static org.junit.Assert.*;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import com.shippo.Shippo;
import com.shippo.exception.APIConnectionException;
import com.shippo.exception.APIException;
import com.shippo.exception.AuthenticationException;
import com.shippo.exception.InvalidRequestException;
import com.shippo.exception.ShippoException;
public class CustomsItemTest extends ShippoTest {
// test data
private static Map<String, Object> objectMap;
static {
objectMap = new HashMap<String, Object>();
objectMap.put("description", "T-Shirt");
objectMap.put("quantity", "2");
objectMap.put("net_weight", "400");
objectMap.put("mass_unit", "g");
objectMap.put("value_amount", "20");
objectMap.put("value_currency", "USD");
objectMap.put("origin_country", "US");
objectMap.put("tariff_number", null);
objectMap.put("sku_code", null);
objectMap.put("eccn_ear99", "3A001");
objectMap.put("metadata", "Order ID #123123");
}
@Test
public void testValidCreate() {
CustomsItem testObject = createCustomsItemFixture();
assertEquals(Shippo.apiKeyIsTest, testObject.isTest());
assertEquals(testObject.getObjectState(), "VALID");
assertEquals(testObject.getDescription(), objectMap.get("description"));
assertEquals(testObject.getQuantity(), Double.parseDouble((String) objectMap.get("quantity")));
assertEquals(testObject.getNetWeight(), objectMap.get("net_weight"));
assertEquals(testObject.getMassUnit(), objectMap.get("mass_unit"));
assertEquals(testObject.getValueAmount(), objectMap.get("value_amount"));
assertEquals(testObject.getValueCurrency(), objectMap.get("value_currency"));
assertEquals(testObject.getOriginCountry(), objectMap.get("origin_country"));
assertEquals(testObject.getTariffNumber(), nullToEmptyString(objectMap.get("tariff_number")));
assertEquals(testObject.getSkuCode(), objectMap.get("sku_code"));
assertEquals(testObject.getEccnEar99(), nullToEmptyString(objectMap.get("eccn_ear99")));
assertEquals(testObject.getMetadata(), nullToEmptyString(objectMap.get("metadata")));
}
@Test(expected = InvalidRequestException.class)
public void testInvalidCreate() throws AuthenticationException, InvalidRequestException, APIConnectionException,
APIException {
CustomsItem.create(getInvalidObjectMap());
}
@Test
public void testRetrieve() throws AuthenticationException, InvalidRequestException, APIConnectionException,
APIException {
CustomsItem testObject = createCustomsItemFixture();
CustomsItem retrievedObject;
retrievedObject = CustomsItem.retrieve((String) testObject.objectId);
assertEquals(testObject.objectId, retrievedObject.objectId);
}
@Test(expected = InvalidRequestException.class)
public void testInvalidRetrieve() throws AuthenticationException, InvalidRequestException, APIConnectionException,
APIException {
CustomsItem.retrieve("invalid_id");
}
@Test
public void testListAll() throws AuthenticationException, InvalidRequestException, APIConnectionException,
APIException {
CustomsItemCollection objectCollection = CustomsItem.all(null);
assertNotNull(objectCollection.getData());
}
@Test
public void testListPageSize() throws AuthenticationException, InvalidRequestException, APIConnectionException,
APIException {
Map<String, Object> objectMap = new HashMap<String, Object>();
objectMap.put("results", "1"); // one result per page
objectMap.put("page", "1"); // the first page of results
CustomsItemCollection CustomsItemCollection = CustomsItem.all(objectMap);
assertEquals(CustomsItemCollection.getData().size(), 1);
}
public static CustomsItem createCustomsItemFixture() {
try {
return CustomsItem.create(objectMap);
} catch (ShippoException e) {
e.printStackTrace();
}
return null;
}
}