-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathAccountingApiBankTransactionTest.java
More file actions
175 lines (151 loc) · 9.74 KB
/
AccountingApiBankTransactionTest.java
File metadata and controls
175 lines (151 loc) · 9.74 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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package com.xero.api.client;
import org.junit.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import com.xero.api.ApiClient;
import com.xero.api.util.ConfigurationLoader;
import com.xero.models.accounting.*;
import java.io.File;
import org.threeten.bp.*;
import java.io.IOException;
import java.util.UUID;
public class AccountingApiBankTransactionTest {
ApiClient defaultClient;
AccountingApi accountingApi;
String accessToken;
String xeroTenantId;
private static boolean setUpIsDone = false;
@Before
public void setUp() {
// Set Access Token and Tenant Id
accessToken = "123";
xeroTenantId = "xyz";
defaultClient = new ApiClient(ConfigurationLoader.getProperty("accounting.api.url"),null,null,null,null);
accountingApi = AccountingApi.getInstance(defaultClient);
// ADDED TO MANAGE RATE LIMITS while using SwaggerHub to mock APIs
if (setUpIsDone) {
return;
}
try {
System.out.println("Sleep for 60 seconds");
Thread.sleep(60);
} catch(InterruptedException e) {
System.out.println(e);
}
// do the setup
setUpIsDone = true;
}
public void tearDown() {
accountingApi = null;
defaultClient = null;
}
@Test
public void testGetBankTransactions() throws Exception {
System.out.println("@Test - getBankTransactions");
OffsetDateTime ifModifiedSince = null;
String where = null;
String order = null;
Integer page = null;
Integer unitdp = null;
Integer pageSize = null;
BankTransactions response = accountingApi.getBankTransactions(accessToken,xeroTenantId,ifModifiedSince, where, order, page, unitdp, pageSize);
assertThat(response.getBankTransactions().get(0).getBankTransactionID(), is(equalTo(UUID.fromString("db54aab0-ad40-4ced-bcff-0940ba20db2c"))));
assertThat(response.getBankTransactions().get(0).getStatus(), is(equalTo(com.xero.models.accounting.BankTransaction.StatusEnum.AUTHORISED)));
assertThat(response.getBankTransactions().get(0).getType(), is(equalTo(com.xero.models.accounting.BankTransaction.TypeEnum.RECEIVE)));
assertThat(response.getBankTransactions().get(0).getCurrencyCode(), is(equalTo(com.xero.models.accounting.CurrencyCode.USD)));
assertThat(response.getBankTransactions().get(0).getIsReconciled(), is(equalTo(false)));
assertThat(response.getBankTransactions().get(0).getIsReconciled(), is(equalTo(false)));
assertThat(response.getBankTransactions().get(0).getSubTotal(), is(equalTo(10.0)));
assertThat(response.getBankTransactions().get(0).getTotal(), is(equalTo(10.0)));
//System.out.println(response.getBankTransactions().get(0).toString());
}
@Test
public void testGetBankTransaction() throws Exception {
System.out.println("@Test - getBankTransaction");
UUID bankTransactionID = UUID.fromString("297c2dc5-cc47-4afd-8ec8-74990b8761e9");
Integer unitdp = null;
BankTransactions response = accountingApi.getBankTransaction(accessToken,xeroTenantId,bankTransactionID,unitdp);
assertThat(response.getBankTransactions().get(0).getBankTransactionID(), is(equalTo(UUID.fromString("db54aab0-ad40-4ced-bcff-0940ba20db2c"))));
assertThat(response.getBankTransactions().get(0).getStatus(), is(equalTo(com.xero.models.accounting.BankTransaction.StatusEnum.AUTHORISED)));
assertThat(response.getBankTransactions().get(0).getType(), is(equalTo(com.xero.models.accounting.BankTransaction.TypeEnum.RECEIVE)));
assertThat(response.getBankTransactions().get(0).getCurrencyCode(), is(equalTo(com.xero.models.accounting.CurrencyCode.USD)));
assertThat(response.getBankTransactions().get(0).getIsReconciled(), is(equalTo(false)));
assertThat(response.getBankTransactions().get(0).getSubTotal(), is(equalTo(10.0)));
assertThat(response.getBankTransactions().get(0).getTotal(), is(equalTo(10.0)));
//System.out.println(response.getBankTransactions().get(0).toString());
}
@Test
public void testUpdateBankTransaction() throws Exception {
System.out.println("@Test - updateBankTransaction");
UUID bankTransactionID = UUID.fromString("297c2dc5-cc47-4afd-8ec8-74990b8761e9");
Integer unitdp = null;
BankTransactions newBankTransactions = new BankTransactions();
BankTransactions response = accountingApi.updateBankTransaction(accessToken,xeroTenantId,bankTransactionID,newBankTransactions,unitdp,null);
assertThat(response.getBankTransactions().get(0).getBankTransactionID(), is(equalTo(UUID.fromString("1289c190-e46d-434b-9628-463ffdb52f00"))));
assertThat(response.getBankTransactions().get(0).getStatus(), is(equalTo(com.xero.models.accounting.BankTransaction.StatusEnum.AUTHORISED)));
assertThat(response.getBankTransactions().get(0).getType(), is(equalTo(com.xero.models.accounting.BankTransaction.TypeEnum.SPEND)));
assertThat(response.getBankTransactions().get(0).getCurrencyCode(), is(equalTo(com.xero.models.accounting.CurrencyCode.USD)));
assertThat(response.getBankTransactions().get(0).getIsReconciled(), is(equalTo(false)));
assertThat(response.getBankTransactions().get(0).getSubTotal(), is(equalTo(18.26)));
assertThat(response.getBankTransactions().get(0).getTotal(), is(equalTo(20.00)));
//System.out.println(response.getBankTransactions().get(0).toString());
}
/*
@Test
public void testCreateBankTransaction() throws Exception {
System.out.println("@Test - createBankTransaction");
BankTransaction newBankTransaction = new BankTransaction();
BankTransactions response = accountingApi.createBankTransaction(accessToken,xeroTenantId,newBankTransaction);
assertThat(response.getBankTransactions().get(0).getBankTransactionID(), is(equalTo(UUID.fromString("1289c190-e46d-434b-9628-463ffdb52f00"))));
assertThat(response.getBankTransactions().get(0).getStatus(), is(equalTo(com.xero.models.accounting.BankTransaction.StatusEnum.AUTHORISED)));
assertThat(response.getBankTransactions().get(0).getType(), is(equalTo(com.xero.models.accounting.BankTransaction.TypeEnum.SPEND)));
assertThat(response.getBankTransactions().get(0).getCurrencyCode(), is(equalTo(com.xero.models.accounting.CurrencyCode.USD)));
assertThat(response.getBankTransactions().get(0).getIsReconciled(), is(equalTo(false)));
assertThat(response.getBankTransactions().get(0).getSubTotal(), is(equalTo(18.26)));
assertThat(response.getBankTransactions().get(0).getTotal(), is(equalTo(20.00)));
//System.out.println(response.getBankTransactions().get(0).toString());
}
*/
@Ignore("Enable when OpenAPI schema is changed to binary wherever octet/stream is used")
@Test
public void createBankTransactionAttachmentByFileNameTest() throws IOException {
System.out.println("@Test - createBankTransactionAttachmentByFileNameTest");
UUID bankTransactionID = UUID.fromString("297c2dc5-cc47-4afd-8ec8-74990b8761e9");
ClassLoader classLoader = getClass().getClassLoader();
File bytes = new File(classLoader.getResource("helo-heros.jpg").getFile());
String fileName = "sample5.jpg";
Attachments response = accountingApi.createBankTransactionAttachmentByFileName(accessToken,xeroTenantId,bankTransactionID, fileName, bytes, null);
assertThat(response.getAttachments().get(0).getAttachmentID(), is(equalTo(UUID.fromString("4508a692-e52c-4ad8-a138-2f13e22bf57b"))));
assertThat(response.getAttachments().get(0).getFileName().toString(), is(equalTo("sample5.jpg")));
assertThat(response.getAttachments().get(0).getMimeType().toString(), is(equalTo("image/jpg")));
assertThat(response.getAttachments().get(0).getUrl().toString(), is(equalTo("https://api.xero.com/api.xro/2.0/BankTransactions/db54aab0-ad40-4ced-bcff-0940ba20db2c/Attachments/sample5.jpg")));
//System.out.println(response.getAttachments().get(0).toString());
}
@Test
public void getBankTransactionAttachmentsTest() throws IOException {
System.out.println("@Test - getBankTransactionAttachmentsTest");
UUID bankTransactionID = UUID.fromString("297c2dc5-cc47-4afd-8ec8-74990b8761e9");
Attachments response = accountingApi.getBankTransactionAttachments(accessToken,xeroTenantId,bankTransactionID);
assertThat(response.getAttachments().get(0).getAttachmentID(), is(equalTo(UUID.fromString("4508a692-e52c-4ad8-a138-2f13e22bf57b"))));
assertThat(response.getAttachments().get(0).getFileName(), is(equalTo("sample5.jpg")));
assertThat(response.getAttachments().get(0).getMimeType(), is(equalTo("image/jpg")));
assertThat(response.getAttachments().get(0).getUrl(), is(equalTo("https://api.xero.com/api.xro/2.0/BankTransactions/db54aab0-ad40-4ced-bcff-0940ba20db2c/Attachments/sample5.jpg")));
assertThat(response.getAttachments().get(0).getContentLength(), is(equalTo(2878711)));
//System.out.println(response.getAttachments().get(0).toString());
}
/*
@Test
public void updateBankTransactionAttachmentByFileNameTest() throws IOException {
System.out.println("@Test - updateBankTransactionAttachmentByFileNameTest");
UUID bankTransactionID = UUID.fromString("297c2dc5-cc47-4afd-8ec8-74990b8761e9");
ClassLoader classLoade2 = getClass().getClassLoader();
File bytes = new File(classLoade2.getResource("helo-heros2.jpg").getFile());
String fileName = "sample2.jpg";
Attachments response = accountingApi.updateBankTransactionAttachmentByFileName(bankTransactionID, fileName, bytes);
assertThat(response.getAttachments().get(0).getAttachmentID(), is(equalTo(UUID.fromString("4508a692-e52c-4ad8-a138-2f13e22bf57b"))));
assertThat(response.getAttachments().get(0).getFileName().toString(), is(equalTo("sample5.jpg")));
assertThat(response.getAttachments().get(0).getMimeType().toString(), is(equalTo("image/jpg")));
assertThat(response.getAttachments().get(0).getUrl().toString(), is(equalTo("https://api.xero.com/api.xro/2.0/BankTransactions/db54aab0-ad40-4ced-bcff-0940ba20db2c/Attachments/sample5.jpg")));
}
*/
}