1
1
package com .xero .api .client ;
2
2
3
- import static org .junit .Assert .assertTrue ;
4
-
5
- import org .junit .After ;
6
3
import org .junit .Before ;
7
4
import org .junit .Test ;
8
- import org .junit .*;
9
-
10
5
import static org .hamcrest .MatcherAssert .*;
11
6
import static org .hamcrest .Matchers .*;
12
- import static org .hamcrest .Matchers .containsInAnyOrder ;
13
- import static org .hamcrest .Matchers .greaterThan ;
14
- import static org .hamcrest .collection .IsCollectionWithSize .hasSize ;
15
- import static org .hamcrest .core .Every .everyItem ;
16
-
17
7
import com .xero .api .ApiClient ;
18
- import com .xero .api .client .*;
19
8
import com .xero .models .accounting .*;
20
9
21
10
import java .io .File ;
22
- import java .net .URL ;
23
-
24
- import com .google .api .client .auth .oauth2 .BearerToken ;
25
- import com .google .api .client .auth .oauth2 .Credential ;
26
- import com .google .api .client .http .HttpRequestFactory ;
27
- import com .google .api .client .http .HttpTransport ;
28
- import com .google .api .client .http .javanet .NetHttpTransport ;
29
-
30
11
import org .threeten .bp .*;
31
- import java .io .IOException ;
32
- import com .fasterxml .jackson .core .type .TypeReference ;
33
-
34
- import java .util .Calendar ;
35
- import java .util .Map ;
36
12
import java .util .UUID ;
37
13
38
- import java .io .File ;
39
- import java .io .IOException ;
40
-
41
- import org .apache .commons .io .IOUtils ;
42
-
43
14
public class AccountingApiAccountsTest {
44
15
45
16
ApiClient defaultClient ;
@@ -58,7 +29,7 @@ public void setUp() {
58
29
59
30
// Init AccountingApi client
60
31
// NEW Sandbox for API Mocking
61
- defaultClient = new ApiClient ("https ://25faf04a-c71e-40e7-b7ce-f1fae0149465.mock.pstmn.io/api.xro/2.0 " ,null ,null ,null ,null );
32
+ defaultClient = new ApiClient ("http ://127.0.0.1:4010 " ,null ,null ,null ,null );
62
33
63
34
accountingApi = AccountingApi .getInstance (defaultClient );
64
35
@@ -156,13 +127,17 @@ public void testGetAccountAttachments() throws Exception {
156
127
public void testCreateAccountAttachmentByFileName () throws Exception {
157
128
158
129
System .out .println ("@Test - createAccountAttachmentByFileName" );
159
- UUID accountID = UUID .fromString ("297c2dc5-cc47-4afd-8ec8-74990b8761e9" );
160
-
130
+ Accounts accounts = accountingApi .getAccounts (accessToken ,xeroTenantId ,null , null , null );
131
+ UUID accountID = accounts .getAccounts ().get (0 ).getAccountID ();
132
+ // UUID accountID = UUID.fromString("297c2dc5-cc47-4afd-8ec8-74990b8761e9");
133
+
161
134
ClassLoader classLoader = getClass ().getClassLoader ();
162
135
File bytes = new File (classLoader .getResource ("helo-heros.jpg" ).getFile ());
163
136
164
- String newFileName = "sample5.jpg" ;
165
- Attachments createAccountsAttachments = accountingApi .createAccountAttachmentByFileName (accessToken ,xeroTenantId ,accountID , newFileName , bytes , null );
137
+ String newFileName = bytes .getName ();
138
+ String idempotencyKey = null ;
139
+ // String idempotencyKey = "KEY_VALUE";
140
+ Attachments createAccountsAttachments = accountingApi .createAccountAttachmentByFileName (accessToken ,xeroTenantId ,accountID , newFileName , bytes , idempotencyKey );
166
141
167
142
assertThat (createAccountsAttachments .getAttachments ().get (0 ).getAttachmentID ().toString (), is (equalTo ("ab95b276-9dce-4925-9077-439818ba270f" )));
168
143
assertThat (createAccountsAttachments .getAttachments ().get (0 ).getFileName ().toString (), is (equalTo ("sample5.jpg" )));
0 commit comments