Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced Postman Mock Server with PRISM Server and fixed failing test cases - Accounting Related #384

Merged
merged 12 commits into from
Sep 24, 2024
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The **Xero-Java** SDK makes it easy for developers to access Xero's APIs in thei
- [App Store Subscriptions](#app-store-subscriptions)
- [API Clients](#api-clients)
- [Usage Examples](#usage-examples)
- [Running Test(s) in Local](#running-tests-in-local)
- [SDK conventions](#sdk-conventions)
- [Participating in Xero’s developer community](#participating-in-xeros-developoer-community)

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

---
## SDK conventions

### Working with dates
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/xero/api/client/AccountingApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ public HttpResponse createAccountAttachmentByFileNameForHttpResponse(
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setContentType("application/octet-stream");
headers.setAccept("application/json");
headers.setContentType("application/octet-stream");
headers.setUserAgent(this.getUserAgent());
Expand Down
43 changes: 6 additions & 37 deletions src/test/java/com/xero/api/client/AccountingApiAccountsTest.java
Original file line number Diff line number Diff line change
@@ -1,45 +1,17 @@
package com.xero.api.client;

import static org.junit.Assert.assertTrue;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.*;

import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.hamcrest.core.Every.everyItem;

import com.xero.api.ApiClient;
import com.xero.api.client.*;
import com.xero.api.util.ConfigurationLoader;
import com.xero.models.accounting.*;

import java.io.File;
import java.net.URL;

import com.google.api.client.auth.oauth2.BearerToken;
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;

import org.threeten.bp.*;
import java.io.IOException;
import com.fasterxml.jackson.core.type.TypeReference;

import java.util.Calendar;
import java.util.Map;
import java.util.UUID;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.IOUtils;

public class AccountingApiAccountsTest {

ApiClient defaultClient;
Expand All @@ -56,11 +28,8 @@ public void setUp() {
accessToken = "123";
xeroTenantId = "xyz";

// Init AccountingApi client
// NEW Sandbox for API Mocking
defaultClient = new ApiClient("https://25faf04a-c71e-40e7-b7ce-f1fae0149465.mock.pstmn.io/api.xro/2.0",null,null,null,null);

accountingApi = AccountingApi.getInstance(defaultClient);
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) {
Expand Down Expand Up @@ -156,13 +125,13 @@ public void testGetAccountAttachments() throws Exception {
public void testCreateAccountAttachmentByFileName() throws Exception {

System.out.println("@Test - createAccountAttachmentByFileName");
UUID accountID = UUID.fromString("297c2dc5-cc47-4afd-8ec8-74990b8761e9");
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);
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")));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,17 @@
package com.xero.api.client;

import static org.junit.Assert.assertTrue;

import org.junit.*;

import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.hamcrest.core.Every.everyItem;

import com.xero.api.ApiClient;
import com.xero.api.client.*;
import com.xero.api.util.ConfigurationLoader;
import com.xero.models.accounting.*;

import java.io.File;
import java.net.URL;

import com.google.api.client.auth.oauth2.BearerToken;
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;

import org.threeten.bp.*;
import java.io.IOException;
import com.fasterxml.jackson.core.type.TypeReference;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.IOUtils;

import java.util.Calendar;
import java.util.Map;
import java.util.UUID;
import java.util.List;
import java.util.ArrayList;
import java.math.BigDecimal;

public class AccountingApiBankTransactionTest {

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

// Init AccountingApi client
// NEW Sandbox for API Mocking
defaultClient = new ApiClient("https://25faf04a-c71e-40e7-b7ce-f1fae0149465.mock.pstmn.io/api.xro/2.0",null,null,null,null);

accountingApi = AccountingApi.getInstance(defaultClient);
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) {
Expand Down Expand Up @@ -159,7 +131,6 @@ public void createBankTransactionAttachmentByFileNameTest() throws IOException {
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")));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,17 @@
package com.xero.api.client;

import static org.junit.Assert.assertTrue;
import org.junit.*;

import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.hamcrest.core.Every.everyItem;

import com.xero.api.ApiClient;
import com.xero.api.client.*;
import com.xero.api.util.ConfigurationLoader;
import com.xero.models.accounting.*;

import java.io.File;
import java.net.URL;

import com.google.api.client.auth.oauth2.BearerToken;
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;

import org.threeten.bp.*;
import java.io.IOException;
import com.fasterxml.jackson.core.type.TypeReference;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.IOUtils;

import java.util.Calendar;
import java.util.Map;
import java.util.UUID;
import java.util.List;
import java.util.ArrayList;
import java.math.BigDecimal;

public class AccountingApiBankTransferTest {

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

// NEW Sandbox for API Mocking
defaultClient = new ApiClient("https://25faf04a-c71e-40e7-b7ce-f1fae0149465.mock.pstmn.io/api.xro/2.0",null,null,null,null);

accountingApi = AccountingApi.getInstance(defaultClient);
defaultClient = new ApiClient(ConfigurationLoader.getProperty("accounting.api.url"),null,null,null,null);
accountingApi = AccountingApi.getInstance(defaultClient);

ClassLoader classLoader = getClass().getClassLoader();
bytes = new File(classLoader.getResource("helo-heros.jpg").getFile());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,15 @@
package com.xero.api.client;

import static org.junit.Assert.assertTrue;

import org.junit.*;

import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.hamcrest.core.Every.everyItem;

import com.xero.api.ApiClient;
import com.xero.api.client.*;
import com.xero.api.util.ConfigurationLoader;
import com.xero.models.accounting.*;

import java.io.File;
import java.net.URL;

import com.google.api.client.auth.oauth2.BearerToken;
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;

import org.threeten.bp.*;
import java.io.IOException;
import com.fasterxml.jackson.core.type.TypeReference;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.IOUtils;

import java.util.Calendar;
import java.util.Map;
import java.util.UUID;

public class AccountingApiBatchPaymentTest {
Expand All @@ -53,11 +28,8 @@ public void setUp() {
accessToken = "123";
xeroTenantId = "xyz";

// Init AccountingApi client
// NEW Sandbox for API Mocking
defaultClient = new ApiClient("https://25faf04a-c71e-40e7-b7ce-f1fae0149465.mock.pstmn.io/api.xro/2.0",null,null,null,null);

accountingApi = AccountingApi.getInstance(defaultClient);
defaultClient = new ApiClient(ConfigurationLoader.getProperty("accounting.api.url"),null,null,null,null);
accountingApi = AccountingApi.getInstance(defaultClient);

ClassLoader classLoader = getClass().getClassLoader();
bytes = new File(classLoader.getResource("helo-heros.jpg").getFile());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,13 @@
package com.xero.api.client;

import static org.junit.Assert.assertTrue;

import org.junit.*;

import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.hamcrest.core.Every.everyItem;

import com.xero.api.ApiClient;
import com.xero.api.client.*;
import com.xero.api.util.ConfigurationLoader;
import com.xero.models.accounting.*;

import java.io.File;
import java.net.URL;

import com.google.api.client.auth.oauth2.BearerToken;
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;

import org.threeten.bp.*;
import java.io.IOException;
import com.fasterxml.jackson.core.type.TypeReference;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.IOUtils;

import java.util.Calendar;
import java.util.Map;
import java.util.UUID;

public class AccountingApiBrandingThemeTest {
Expand All @@ -52,12 +25,9 @@ public void setUp() {
// Set Access Token and Tenant Id
accessToken = "123";
xeroTenantId = "xyz";

// Init AccountingApi client
// NEW Sandbox for API Mocking
defaultClient = new ApiClient("https://25faf04a-c71e-40e7-b7ce-f1fae0149465.mock.pstmn.io/api.xro/2.0",null,null,null,null);

accountingApi = AccountingApi.getInstance(defaultClient);

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) {
Expand Down
Loading