forked from goshippo/shippo-java-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomsDeclarationTest.java
148 lines (127 loc) · 7.69 KB
/
CustomsDeclarationTest.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package com.shippo.model;
import com.shippo.Shippo;
import com.shippo.exception.*;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.*;
public class CustomsDeclarationTest extends ShippoTest {
// test data
private static Map<String, Object> customsDeclarationRequestMap;
static {
customsDeclarationRequestMap = new HashMap<String, Object>();
customsDeclarationRequestMap.put("certify_signer", "Laura Behrens Wu");
customsDeclarationRequestMap.put("certify", "true");
customsDeclarationRequestMap.put("non_delivery_option", "ABANDON");
customsDeclarationRequestMap.put("contents_type", "MERCHANDISE");
customsDeclarationRequestMap.put("contents_explanation", "T-Shirt purchase");
customsDeclarationRequestMap.put("exporter_reference", "Exporter Reference");
customsDeclarationRequestMap.put("importer_reference", "Importer Reference");
customsDeclarationRequestMap.put("invoice", "#123123");
customsDeclarationRequestMap.put("license", "License");
customsDeclarationRequestMap.put("certificate", "Certificate");
customsDeclarationRequestMap.put("notes", "Notes");
customsDeclarationRequestMap.put("eel_pfc", "NOEEI_30_37_a");
customsDeclarationRequestMap.put("aes_itn", "X20180426506889");
customsDeclarationRequestMap.put("incoterm", "DDP");
customsDeclarationRequestMap.put("b13a_filing_option", "FILED_ELECTRONICALLY");
customsDeclarationRequestMap.put("b13a_number", "AA9999202008311");
customsDeclarationRequestMap.put("metadata", "Order ID #123123");
Map<String, Object> invoicedChargesMap = new HashMap<String, Object>();
invoicedChargesMap.put("total_shipping", "1.23");
invoicedChargesMap.put("total_taxes", "4.56");
invoicedChargesMap.put("total_duties", "78.90");
invoicedChargesMap.put("other_fees", "9.87");
invoicedChargesMap.put("currency", "USD");
customsDeclarationRequestMap.put("invoiced_charges", invoicedChargesMap);
Map<String, Object> addressImporterMap = new HashMap<String, Object>();
addressImporterMap.put("country", "US");
customsDeclarationRequestMap.put("address_importer", addressImporterMap);
Map<String, Object> taxIdMap = new HashMap<String, Object>();
taxIdMap.put("number", "123456789");
taxIdMap.put("type", "EIN");
Map<String, Object> exporterIdentificationMap = new HashMap<String, Object>();
exporterIdentificationMap.put("tax_id", taxIdMap);
exporterIdentificationMap.put("eori_number", "PL123456789");
customsDeclarationRequestMap.put("exporter_identification", exporterIdentificationMap);
}
@Test
public void testValidCreate() {
Shippo.setDEBUG(true);
CustomsDeclaration testObject = createCustomsDeclarationFixture();
assertEquals(testObject.getObjectState(), "VALID");
assertEquals(Shippo.apiKeyIsTest.get(), testObject.isTest());
assertEquals(testObject.getCertifySigner(), customsDeclarationRequestMap.get("certify_signer"));
assertEquals(testObject.getCertify(),
Boolean.parseBoolean((String) customsDeclarationRequestMap.get("certify")));
assertEquals(testObject.getNonDeliveryOption(), customsDeclarationRequestMap.get("non_delivery_option"));
assertEquals(testObject.getContentsType(), customsDeclarationRequestMap.get("contents_type"));
assertEquals(testObject.getContentsExplanation(), customsDeclarationRequestMap.get("contents_explanation"));
assertEquals(testObject.getExporterReference(),
nullToEmptyString(customsDeclarationRequestMap.get("exporter_reference")));
assertEquals(testObject.getImporterReference(),
nullToEmptyString(customsDeclarationRequestMap.get("importer_reference")));
assertEquals(testObject.getInvoice(), nullToEmptyString(customsDeclarationRequestMap.get("invoice")));
assertEquals(testObject.getLicense(), nullToEmptyString(customsDeclarationRequestMap.get("license")));
assertEquals(testObject.getCertificate(), nullToEmptyString(customsDeclarationRequestMap.get("certificate")));
assertEquals(testObject.getNotes(), nullToEmptyString(customsDeclarationRequestMap.get("notes")));
assertEquals(testObject.getEelPfc(), nullToEmptyString(customsDeclarationRequestMap.get("eel_pfc")));
assertEquals(testObject.getAesItn(), nullToEmptyString(customsDeclarationRequestMap.get("aes_itn")));
assertEquals(testObject.getIncoterm(), nullToEmptyString(customsDeclarationRequestMap.get("incoterm")));
assertEquals(testObject.getB13aFilingOption(),
nullToEmptyString(customsDeclarationRequestMap.get("b13a_filing_option")));
assertEquals(testObject.getB13aNumber(), nullToEmptyString(customsDeclarationRequestMap.get("b13a_number")));
assertEquals(testObject.getMetadata(), nullToEmptyString(customsDeclarationRequestMap.get("metadata")));
assertEquals(testObject.getInvoicedCharges(), customsDeclarationRequestMap.get("invoiced_charges"));
assertEquals(testObject.getExporterIdentification(),
customsDeclarationRequestMap.get("exporter_identification"));
// address_importer should return a new Address ID, which is a nonempty string
Object addressImporter = testObject.getAddressImporter();
assertTrue(addressImporter instanceof String && ((String) addressImporter).length() > 0);
}
@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 = createCustomsDeclarationFixture();
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.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 CustomsDeclaration createCustomsDeclarationFixture() {
CustomsItem customsItem = CustomsItemTest.createCustomsItemFixture();
String[] arr = { customsItem.getObjectId() };
customsDeclarationRequestMap.put("items", arr);
try {
return CustomsDeclaration.create(customsDeclarationRequestMap);
} catch (ShippoException e) {
e.printStackTrace();
}
return null;
}
}