Skip to content

Commit 7dcdd2f

Browse files
authored
Merge pull request #384 from XeroAPI/fix/replace-postman-with-prism
Replaced Postman Mock Server with PRISM Server and fixed failing test cases - Accounting Related
2 parents 7d19f0c + 5f0112b commit 7dcdd2f

38 files changed

+162
-1038
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The **Xero-Java** SDK makes it easy for developers to access Xero's APIs in thei
1515
- [App Store Subscriptions](#app-store-subscriptions)
1616
- [API Clients](#api-clients)
1717
- [Usage Examples](#usage-examples)
18+
- [Running Test(s) in Local](#running-tests-in-local)
1819
- [SDK conventions](#sdk-conventions)
1920
- [Participating in Xero’s developer community](#participating-in-xeros-developoer-community)
2021

@@ -677,7 +678,17 @@ try {
677678
System.out.println(e.getMessage());
678679
}
679680
```
681+
## Running Test(s) in Local
682+
For Running Test cases PRISM Mock Server needs to be started in the local machine.
683+
Steps to Run Test(s)
684+
* Install PRISM from npm using the command: **npm install -g @stoplight/prism-cli**
685+
* Verify Installation: **prism --version**
686+
* Navigate to **Xero-Java--> src--> test--> util** folder in the terminal
687+
* Execute the script **./start-prism.sh**
688+
* This will start the PRISM Server in Local
689+
* Run **mvn clean verify -DskipTests=false** to build the Java code along with Test Cases.
680690

691+
---
681692
## SDK conventions
682693

683694
### Working with dates

src/main/java/com/xero/api/client/AccountingApi.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ public HttpResponse createAccountAttachmentByFileNameForHttpResponse(
528528
HttpHeaders headers = new HttpHeaders();
529529
headers.set("xero-tenant-id", xeroTenantId);
530530
headers.set("Idempotency-Key", idempotencyKey);
531+
headers.setContentType("application/octet-stream");
531532
headers.setAccept("application/json");
532533
headers.setContentType("application/octet-stream");
533534
headers.setUserAgent(this.getUserAgent());

src/test/java/com/xero/api/client/AccountingApiAccountsTest.java

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,17 @@
11
package com.xero.api.client;
22

3-
import static org.junit.Assert.assertTrue;
4-
5-
import org.junit.After;
63
import org.junit.Before;
74
import org.junit.Test;
8-
import org.junit.*;
9-
105
import static org.hamcrest.MatcherAssert.*;
116
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-
177
import com.xero.api.ApiClient;
18-
import com.xero.api.client.*;
8+
import com.xero.api.util.ConfigurationLoader;
199
import com.xero.models.accounting.*;
2010

2111
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-
3012
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;
3613
import java.util.UUID;
3714

38-
import java.io.File;
39-
import java.io.IOException;
40-
41-
import org.apache.commons.io.IOUtils;
42-
4315
public class AccountingApiAccountsTest {
4416

4517
ApiClient defaultClient;
@@ -56,11 +28,8 @@ public void setUp() {
5628
accessToken = "123";
5729
xeroTenantId = "xyz";
5830

59-
// Init AccountingApi client
60-
// 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);
62-
63-
accountingApi = AccountingApi.getInstance(defaultClient);
31+
defaultClient = new ApiClient(ConfigurationLoader.getProperty("accounting.api.url"),null,null,null,null);
32+
accountingApi = AccountingApi.getInstance(defaultClient);
6433

6534
// ADDED TO MANAGE RATE LIMITS while using SwaggerHub to mock APIs
6635
if (setUpIsDone) {
@@ -156,13 +125,13 @@ public void testGetAccountAttachments() throws Exception {
156125
public void testCreateAccountAttachmentByFileName() throws Exception {
157126

158127
System.out.println("@Test - createAccountAttachmentByFileName");
159-
UUID accountID = UUID.fromString("297c2dc5-cc47-4afd-8ec8-74990b8761e9");
160-
128+
UUID accountID = UUID.fromString("297c2dc5-cc47-4afd-8ec8-74990b8761e9");
129+
161130
ClassLoader classLoader = getClass().getClassLoader();
162131
File bytes = new File(classLoader.getResource("helo-heros.jpg").getFile());
163132

164133
String newFileName = "sample5.jpg";
165-
Attachments createAccountsAttachments = accountingApi.createAccountAttachmentByFileName(accessToken,xeroTenantId,accountID, newFileName, bytes, null);
134+
Attachments createAccountsAttachments = accountingApi.createAccountAttachmentByFileName(accessToken,xeroTenantId,accountID, newFileName, bytes, null);
166135

167136
assertThat(createAccountsAttachments.getAttachments().get(0).getAttachmentID().toString(), is(equalTo("ab95b276-9dce-4925-9077-439818ba270f")));
168137
assertThat(createAccountsAttachments.getAttachments().get(0).getFileName().toString(), is(equalTo("sample5.jpg")));

src/test/java/com/xero/api/client/AccountingApiBankTransactionTest.java

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,17 @@
11
package com.xero.api.client;
22

3-
import static org.junit.Assert.assertTrue;
4-
53
import org.junit.*;
64

75
import static org.hamcrest.MatcherAssert.*;
86
import static org.hamcrest.Matchers.*;
9-
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
10-
import static org.hamcrest.core.Every.everyItem;
11-
127
import com.xero.api.ApiClient;
13-
import com.xero.api.client.*;
8+
import com.xero.api.util.ConfigurationLoader;
149
import com.xero.models.accounting.*;
1510

1611
import java.io.File;
17-
import java.net.URL;
18-
19-
import com.google.api.client.auth.oauth2.BearerToken;
20-
import com.google.api.client.auth.oauth2.Credential;
21-
import com.google.api.client.http.HttpRequestFactory;
22-
import com.google.api.client.http.HttpTransport;
23-
import com.google.api.client.http.javanet.NetHttpTransport;
24-
2512
import org.threeten.bp.*;
2613
import java.io.IOException;
27-
import com.fasterxml.jackson.core.type.TypeReference;
28-
29-
import java.io.File;
30-
import java.io.IOException;
31-
32-
import org.apache.commons.io.IOUtils;
33-
34-
import java.util.Calendar;
35-
import java.util.Map;
3614
import java.util.UUID;
37-
import java.util.List;
38-
import java.util.ArrayList;
39-
import java.math.BigDecimal;
4015

4116
public class AccountingApiBankTransactionTest {
4217

@@ -53,11 +28,8 @@ public void setUp() {
5328
accessToken = "123";
5429
xeroTenantId = "xyz";
5530

56-
// Init AccountingApi client
57-
// NEW Sandbox for API Mocking
58-
defaultClient = new ApiClient("https://25faf04a-c71e-40e7-b7ce-f1fae0149465.mock.pstmn.io/api.xro/2.0",null,null,null,null);
59-
60-
accountingApi = AccountingApi.getInstance(defaultClient);
31+
defaultClient = new ApiClient(ConfigurationLoader.getProperty("accounting.api.url"),null,null,null,null);
32+
accountingApi = AccountingApi.getInstance(defaultClient);
6133

6234
// ADDED TO MANAGE RATE LIMITS while using SwaggerHub to mock APIs
6335
if (setUpIsDone) {
@@ -159,7 +131,6 @@ public void createBankTransactionAttachmentByFileNameTest() throws IOException {
159131
ClassLoader classLoader = getClass().getClassLoader();
160132
File bytes = new File(classLoader.getResource("helo-heros.jpg").getFile());
161133
String fileName = "sample5.jpg";
162-
163134
Attachments response = accountingApi.createBankTransactionAttachmentByFileName(accessToken,xeroTenantId,bankTransactionID, fileName, bytes, null);
164135
assertThat(response.getAttachments().get(0).getAttachmentID(), is(equalTo(UUID.fromString("4508a692-e52c-4ad8-a138-2f13e22bf57b"))));
165136
assertThat(response.getAttachments().get(0).getFileName().toString(), is(equalTo("sample5.jpg")));

src/test/java/com/xero/api/client/AccountingApiBankTransferTest.java

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,17 @@
11
package com.xero.api.client;
22

3-
import static org.junit.Assert.assertTrue;
43
import org.junit.*;
54

65
import static org.hamcrest.MatcherAssert.*;
76
import static org.hamcrest.Matchers.*;
8-
import static org.hamcrest.Matchers.containsInAnyOrder;
9-
import static org.hamcrest.Matchers.greaterThan;
10-
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
11-
import static org.hamcrest.core.Every.everyItem;
12-
137
import com.xero.api.ApiClient;
14-
import com.xero.api.client.*;
8+
import com.xero.api.util.ConfigurationLoader;
159
import com.xero.models.accounting.*;
1610

1711
import java.io.File;
18-
import java.net.URL;
19-
20-
import com.google.api.client.auth.oauth2.BearerToken;
21-
import com.google.api.client.auth.oauth2.Credential;
22-
import com.google.api.client.http.HttpRequestFactory;
23-
import com.google.api.client.http.HttpTransport;
24-
import com.google.api.client.http.javanet.NetHttpTransport;
25-
2612
import org.threeten.bp.*;
2713
import java.io.IOException;
28-
import com.fasterxml.jackson.core.type.TypeReference;
29-
30-
import java.io.File;
31-
import java.io.IOException;
32-
33-
import org.apache.commons.io.IOUtils;
34-
35-
import java.util.Calendar;
36-
import java.util.Map;
3714
import java.util.UUID;
38-
import java.util.List;
39-
import java.util.ArrayList;
40-
import java.math.BigDecimal;
4115

4216
public class AccountingApiBankTransferTest {
4317

@@ -56,10 +30,8 @@ public void setUp() {
5630
accessToken = "123";
5731
xeroTenantId = "xyz";
5832

59-
// NEW Sandbox for API Mocking
60-
defaultClient = new ApiClient("https://25faf04a-c71e-40e7-b7ce-f1fae0149465.mock.pstmn.io/api.xro/2.0",null,null,null,null);
61-
62-
accountingApi = AccountingApi.getInstance(defaultClient);
33+
defaultClient = new ApiClient(ConfigurationLoader.getProperty("accounting.api.url"),null,null,null,null);
34+
accountingApi = AccountingApi.getInstance(defaultClient);
6335

6436
ClassLoader classLoader = getClass().getClassLoader();
6537
bytes = new File(classLoader.getResource("helo-heros.jpg").getFile());

src/test/java/com/xero/api/client/AccountingApiBatchPaymentTest.java

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,15 @@
11
package com.xero.api.client;
22

3-
import static org.junit.Assert.assertTrue;
4-
53
import org.junit.*;
64

75
import static org.hamcrest.MatcherAssert.*;
86
import static org.hamcrest.Matchers.*;
9-
import static org.hamcrest.Matchers.containsInAnyOrder;
10-
import static org.hamcrest.Matchers.greaterThan;
11-
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
12-
import static org.hamcrest.core.Every.everyItem;
13-
147
import com.xero.api.ApiClient;
15-
import com.xero.api.client.*;
8+
import com.xero.api.util.ConfigurationLoader;
169
import com.xero.models.accounting.*;
1710

1811
import java.io.File;
19-
import java.net.URL;
20-
21-
import com.google.api.client.auth.oauth2.BearerToken;
22-
import com.google.api.client.auth.oauth2.Credential;
23-
import com.google.api.client.http.HttpRequestFactory;
24-
import com.google.api.client.http.HttpTransport;
25-
import com.google.api.client.http.javanet.NetHttpTransport;
26-
2712
import org.threeten.bp.*;
28-
import java.io.IOException;
29-
import com.fasterxml.jackson.core.type.TypeReference;
30-
31-
import java.io.File;
32-
import java.io.IOException;
33-
34-
import org.apache.commons.io.IOUtils;
35-
36-
import java.util.Calendar;
37-
import java.util.Map;
3813
import java.util.UUID;
3914

4015
public class AccountingApiBatchPaymentTest {
@@ -53,11 +28,8 @@ public void setUp() {
5328
accessToken = "123";
5429
xeroTenantId = "xyz";
5530

56-
// Init AccountingApi client
57-
// NEW Sandbox for API Mocking
58-
defaultClient = new ApiClient("https://25faf04a-c71e-40e7-b7ce-f1fae0149465.mock.pstmn.io/api.xro/2.0",null,null,null,null);
59-
60-
accountingApi = AccountingApi.getInstance(defaultClient);
31+
defaultClient = new ApiClient(ConfigurationLoader.getProperty("accounting.api.url"),null,null,null,null);
32+
accountingApi = AccountingApi.getInstance(defaultClient);
6133

6234
ClassLoader classLoader = getClass().getClassLoader();
6335
bytes = new File(classLoader.getResource("helo-heros.jpg").getFile());

src/test/java/com/xero/api/client/AccountingApiBrandingThemeTest.java

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,13 @@
11
package com.xero.api.client;
22

3-
import static org.junit.Assert.assertTrue;
4-
53
import org.junit.*;
64

75
import static org.hamcrest.MatcherAssert.*;
86
import static org.hamcrest.Matchers.*;
9-
import static org.hamcrest.Matchers.containsInAnyOrder;
10-
import static org.hamcrest.Matchers.greaterThan;
11-
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
12-
import static org.hamcrest.core.Every.everyItem;
13-
147
import com.xero.api.ApiClient;
15-
import com.xero.api.client.*;
8+
import com.xero.api.util.ConfigurationLoader;
169
import com.xero.models.accounting.*;
1710

18-
import java.io.File;
19-
import java.net.URL;
20-
21-
import com.google.api.client.auth.oauth2.BearerToken;
22-
import com.google.api.client.auth.oauth2.Credential;
23-
import com.google.api.client.http.HttpRequestFactory;
24-
import com.google.api.client.http.HttpTransport;
25-
import com.google.api.client.http.javanet.NetHttpTransport;
26-
27-
import org.threeten.bp.*;
28-
import java.io.IOException;
29-
import com.fasterxml.jackson.core.type.TypeReference;
30-
31-
import java.io.File;
32-
import java.io.IOException;
33-
34-
import org.apache.commons.io.IOUtils;
35-
36-
import java.util.Calendar;
37-
import java.util.Map;
3811
import java.util.UUID;
3912

4013
public class AccountingApiBrandingThemeTest {
@@ -52,12 +25,9 @@ public void setUp() {
5225
// Set Access Token and Tenant Id
5326
accessToken = "123";
5427
xeroTenantId = "xyz";
55-
56-
// Init AccountingApi client
57-
// NEW Sandbox for API Mocking
58-
defaultClient = new ApiClient("https://25faf04a-c71e-40e7-b7ce-f1fae0149465.mock.pstmn.io/api.xro/2.0",null,null,null,null);
59-
60-
accountingApi = AccountingApi.getInstance(defaultClient);
28+
29+
defaultClient = new ApiClient(ConfigurationLoader.getProperty("accounting.api.url"),null,null,null,null);
30+
accountingApi = AccountingApi.getInstance(defaultClient);
6131

6232
// ADDED TO MANAGE RATE LIMITS while using SwaggerHub to mock APIs
6333
if (setUpIsDone) {

0 commit comments

Comments
 (0)