0

I am exploring the xero java-sdk https://github.com/XeroAPI/Xero-Java. There are Junit tests. I want to use the tests with respect to my "Demo Company' or with my any other company.

What should be changed in the tests?. The tests are located at

https://github.com/XeroAPI/Xero-Java/tree/master/src/test/java/com/xero/api

Rajesh
  • 91
  • 1
  • 6

1 Answers1

1

The unit tests are built to expect the values from the static API responses in Xero's OpenAPI spec.

https://app.swaggerhub.com/apis/Xero/accounting/2.0.0

If you wanted to modify the tests for your Demo Company you can, you'd start by changing base URL to https://api.xero.com/api.xro/2.0/

new ApiClient("https://api.xero.com/api.xro/2.0/",null,null,null);

But your tests will fail as the data in your Demo Company will not match the static responses. That is one of the challenges of creating tests against a live API. I also found challenges testing values that are unique in Xero. For example a Contact name must be unique, so once I create a contact with the name "John Smith" and test that "John Smith" was returned, the second time you run that test, the API will return a validation error that a contact named "John Smith" already exists.

Not saying, our choice to use swaggerhub virtual server to host our static responses is the only way to test the models, but it's the choice we've made.

Hopefully, this information helps.

  • Agreed, you have made your choise in your own style. I don't know about swaggerhub. Normally using test fixtures, ie, teardown, the data can be cleaned. If you don't know what data is created in the company, then there must be a reset api to reset the data in the company. In this way, the next test starts from a clean state. – Rajesh Apr 12 '19 at 05:58
  • In the CustomJsonConfig, what is the variable to specify the company name. – Rajesh Apr 12 '19 at 05:59
  • You'll need to follow the getting started to create a Xero user account and login to app.xero.com to create a Private App. https://developer.xero.com/documentation/getting-started/getting-started-guide When creating your private app, you can select the "Demo Company" as the one Xero org you wish to connect with. https://developer.xero.com/documentation/auth-and-limits/private-applications The Consumer Key and Secret ARE your long lived oauth_token and oauth_token_secret. In other words, they don't expire. You can add these to the CustomJsonConfig – sidney.maestre Apr 15 '19 at 14:26