forked from goshippo/shippo-java-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomsDeclarationTest.java
More file actions
102 lines (84 loc) · 3.84 KB
/
CustomsDeclarationTest.java
File metadata and controls
102 lines (84 loc) · 3.84 KB
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 CustomsDeclarationTest extends ShippoTest {
@Test
public void testValidCreate() {
Shippo.setDEBUG(true);
CustomsDeclaration testObject = (CustomsDeclaration) getDefaultObject();
assertEquals(testObject.getObjectState(), "VALID");
}
@Test(expected = InvalidRequestException.class)
public void testInvalidCreate() throws AuthenticationException, InvalidRequestException, APIConnectionException,
APIException {
CustomsDeclaration.create(getInvalidObjectMap());
}
@Test
public void testRetrieve() throws AuthenticationException, InvalidRequestException, APIConnectionException,
APIException {
Shippo.setDEBUG(true);
CustomsDeclaration testObject = (CustomsDeclaration) getDefaultObject();
CustomsDeclaration retrievedObject;
retrievedObject = CustomsDeclaration.retrieve((String) testObject.objectId);
assertEquals(testObject.objectId, retrievedObject.objectId);
}
@Test(expected = InvalidRequestException.class)
public void testInvalidRetrieve() throws AuthenticationException, InvalidRequestException, APIConnectionException,
APIException {
CustomsDeclaration.retrieve("invalid_id");
}
@Test
public void testListAll() throws AuthenticationException, InvalidRequestException, APIConnectionException,
APIException {
CustomsDeclarationCollection objectCollection = CustomsDeclaration.all(null);
assertNotNull(objectCollection.getCount());
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
CustomsDeclarationCollection CustomsDeclarationCollection = CustomsDeclaration.all(objectMap);
assertEquals(CustomsDeclarationCollection.getData().size(), 1);
}
public static Object getDefaultObject() {
CustomsItem customsItem = (CustomsItem) CustomsItemTest.getDefaultObject();
Map<String, Object> objectMap = new HashMap<String, Object>();
objectMap.put("exporter_reference", null);
objectMap.put("importer_reference", null);
objectMap.put("contents_type", "MERCHANDISE");
objectMap.put("contents_explanation", "T-Shirt purchase");
objectMap.put("invoice", "#123123");
objectMap.put("license", null);
objectMap.put("certificate", null);
objectMap.put("notes", null);
objectMap.put("eel_pfc", "NOEEI_30_37_a");
objectMap.put("aes_itn", null);
objectMap.put("non_delivery_option", "ABANDON");
objectMap.put("certify", "true");
objectMap.put("certify_signer", "Laura Behrens Wu");
objectMap.put("disclaimer", null);
objectMap.put("incoterm", null);
Map<String, Object> customsItemsMap = new HashMap<String, Object>();
String[] arr = {customsItem.getObjectId()};
objectMap.put("items", arr);
objectMap.put("metadata", "Order ID #123123");
try {
CustomsDeclaration testObject = CustomsDeclaration.create(objectMap);
return testObject;
} catch (ShippoException e) {
e.printStackTrace();
}
return null;
}
}