-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathAccountingApiAccountsTest.java
More file actions
161 lines (129 loc) · 7.13 KB
/
AccountingApiAccountsTest.java
File metadata and controls
161 lines (129 loc) · 7.13 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
package com.xero.api.client;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
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.util.UUID;
public class AccountingApiAccountsTest {
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 testGetAccounts() throws Exception {
System.out.println("@Test - getAccounts");
OffsetDateTime ifModifiedSince = null;
String where = null;
String order = null;
Accounts accounts = accountingApi.getAccounts(accessToken,xeroTenantId,ifModifiedSince, where, order);
assert(accounts.getAccounts().size() == 2);
assertThat(accounts.getAccounts().get(0).getCode(), is(equalTo("091")));
assertThat(accounts.getAccounts().get(0).getName(), is(equalTo("Business Savings Account")));
assertThat(accounts.getAccounts().get(0).getAccountID().toString(), is(equalTo("ebd06280-af70-4bed-97c6-7451a454ad85")));
assertThat(accounts.getAccounts().get(0).getType(), is(equalTo(com.xero.models.accounting.AccountType.BANK)));
assertThat(accounts.getAccounts().get(0).getBankAccountNumber(), is(equalTo("0209087654321050")));
assertThat(accounts.getAccounts().get(0).getBankAccountType(), is(equalTo(com.xero.models.accounting.Account.BankAccountTypeEnum.BANK)));
assertThat(accounts.getAccounts().get(0).getCurrencyCode(), is(equalTo(com.xero.models.accounting.CurrencyCode.NZD)));
assertThat(accounts.getAccounts().get(0).getTaxType(), is(equalTo("NONE")));
}
@Test
public void testGetAccount() throws Exception {
System.out.println("@Test - getAccount");
UUID accountID = UUID.fromString("297c2dc5-cc47-4afd-8ec8-74990b8761e9");
Accounts oneAccount = accountingApi.getAccount(accessToken,xeroTenantId,accountID);
assertThat(oneAccount.getAccounts().get(0).getName(), is(equalTo("FooBar")));
assertThat(oneAccount.getAccounts().get(0).getCode(), is(equalTo("123456")));
}
@Test
public void testCreateAccount() throws Exception {
System.out.println("@Test - createAccount");
Account acct = new Account();
Accounts newAccount = accountingApi.createAccount(accessToken,xeroTenantId,acct,null);
assertThat(newAccount.getAccounts().get(0).getName(), is(equalTo("Foobar")));
}
@Test
public void testUpdateAccount() throws Exception {
System.out.println("@Test - updateAccount");
UUID accountID = UUID.fromString("297c2dc5-cc47-4afd-8ec8-74990b8761e9");
Accounts accts = new Accounts();
Accounts updatedAccount = accountingApi.updateAccount(accessToken,xeroTenantId,accountID, accts, null);
assertThat(updatedAccount.getAccounts().get(0).getName(), is(equalTo("BarFoo")));
}
@Test
public void testDeleteAccount() throws Exception {
System.out.println("@Test - deleteAccount");
UUID accountID = UUID.fromString("297c2dc5-cc47-4afd-8ec8-74990b8761e9");
Accounts deleteAccount = accountingApi.deleteAccount(accessToken,xeroTenantId,accountID);
assertThat(deleteAccount.getAccounts().get(0).getStatus().toString(), is(equalTo("DELETED")));
}
@Test
public void testGetAccountAttachments() throws Exception {
System.out.println("@Test - getAccountAttachments");
UUID accountID = UUID.fromString("297c2dc5-cc47-4afd-8ec8-74990b8761e9");
Attachments accountsAttachments = accountingApi.getAccountAttachments(accessToken,xeroTenantId,accountID);
assertThat(accountsAttachments.getAttachments().get(0).getAttachmentID().toString(), is(equalTo("52a643be-cd5c-489f-9778-53a9fd337756")));
assertThat(accountsAttachments.getAttachments().get(0).getFileName().toString(), is(equalTo("sample5.jpg")));
assertThat(accountsAttachments.getAttachments().get(0).getMimeType().toString(), is(equalTo("image/jpg")));
assertThat(accountsAttachments.getAttachments().get(0).getUrl().toString(), is(equalTo("https://api.xero.com/api.xro/2.0/Accounts/da962997-a8bd-4dff-9616-01cdc199283f/Attachments/sample5.jpg")));
}
@Ignore("Enable when OpenAPI schema is changed to binary wherever octet/stream is used")
@Test
public void testCreateAccountAttachmentByFileName() throws Exception {
System.out.println("@Test - createAccountAttachmentByFileName");
UUID accountID = UUID.fromString("297c2dc5-cc47-4afd-8ec8-74990b8761e9");
ClassLoader classLoader = getClass().getClassLoader();
File bytes = new File(classLoader.getResource("helo-heros.jpg").getFile());
String newFileName = "sample5.jpg";
Attachments createAccountsAttachments = accountingApi.createAccountAttachmentByFileName(accessToken,xeroTenantId,accountID, newFileName, bytes, null);
assertThat(createAccountsAttachments.getAttachments().get(0).getAttachmentID().toString(), is(equalTo("ab95b276-9dce-4925-9077-439818ba270f")));
assertThat(createAccountsAttachments.getAttachments().get(0).getFileName().toString(), is(equalTo("sample5.jpg")));
assertThat(createAccountsAttachments.getAttachments().get(0).getMimeType().toString(), is(equalTo("image/jpg")));
assertThat(createAccountsAttachments.getAttachments().get(0).getUrl().toString(), is(equalTo("https://api.xero.com/api.xro/2.0/Accounts/da962997-a8bd-4dff-9616-01cdc199283f/Attachments/sample5.jpg")));
}
/*
@Test
public void testUpdateAccountAttachmentByFileName() throws Exception {
System.out.println("@Test - updateAccountAttachmentByFileName");
UUID accountID = UUID.fromString("297c2dc5-cc47-4afd-8ec8-74990b8761e9");
ClassLoader classLoader = getClass().getClassLoader();
File bytes = new File(classLoader.getResource("helo-heros.jpg").getFile());
String newFileName = "sample.jpg";
Attachments createAccountsAttachments = accountingApi.updateAccountAttachmentByFileName(accountID, newFileName, bytes);
assertThat(createAccountsAttachments.getAttachments().get(0).getAttachmentID().toString(), is(equalTo("3fa85f64-5717-4562-b3fc-2c963f66afa6")));
assertThat(createAccountsAttachments.getAttachments().get(0).getFileName().toString(), is(equalTo("sample5.jpg")));
assertThat(createAccountsAttachments.getAttachments().get(0).getMimeType().toString(), is(equalTo("image/jpg")));
assertThat(createAccountsAttachments.getAttachments().get(0).getUrl().toString(), is(equalTo("https://api.xero.com/api.xro/2.0/Accounts/da962997-a8bd-4dff-9616-01cdc199283f/Attachments/sample5.jpg")));
}
*/
}