diff --git a/src/main/java/com/trolley/trolley/InvoiceGateway.java b/src/main/java/com/trolley/trolley/InvoiceGateway.java index 7fd42cc..b4fb26a 100644 --- a/src/main/java/com/trolley/trolley/InvoiceGateway.java +++ b/src/main/java/com/trolley/trolley/InvoiceGateway.java @@ -125,8 +125,8 @@ public Invoice fetch(final String invoiceId) throws Exception { * These options correspond to our documentation. * @param searchBy Enum of type Invoice.SearchBy denoting which field you want to search by * @param paramsList {@code List} Required if 'searchBy' is either of these: 'invoiceId' - * 'recipientId', 'invoiceNumber', 'tags'. Set to 'null' otherwise. - * @param param String Required if 'searchBy' is either 'invoiceDate' or 'externalId'. Set to null otherwise. + * 'recipientId', 'invoiceNumber', 'tags', or 'externalId'. Set to 'null' otherwise. + * @param param String Required if 'searchBy' is 'invoiceDate'. Set to null otherwise. * @return {@code List} * @throws Exception */ @@ -141,11 +141,12 @@ public List search(final SearchBy searchBy, case INVOICE_ID: case RECIPIENT_ID: case INVOICE_NUMBER: + case EXTERNAL_ID: case TAGS: if(null == paramsList){ throw new InvalidFieldException("variable paramsList can not be null for the provided searchBy parameter. Refer to method's Javadoc for more details."); } - body = "{\""+searchBy.name()+"\":" + body = "{\""+searchBy.getKey()+"\":" +new ObjectMapper() .setSerializationInclusion(Include.NON_EMPTY) .writeValueAsString(paramsList) @@ -153,11 +154,10 @@ public List search(final SearchBy searchBy, break; case INVOICE_DATE: - case EXTERNAL_ID: if(null == param){ throw new InvalidFieldException("variable param can not be null for the provided searchBy parameter. Refer to method's Javadoc for more details."); } - body = "{\""+searchBy.name()+"\":\""+param+"\"}"; + body = "{\""+searchBy.getKey()+"\":\""+param+"\"}"; break; } final String endPoint = "/v1/invoices/search/"; @@ -176,8 +176,8 @@ public List search(final SearchBy searchBy, * These options correspond to our documentation. * @param searchBy Enum of type Invoice.SearchBy denoting which field you want to search by * @param paramsList {@code List} Required if 'searchBy' is either of these: 'invoiceId' - * 'recipientId', 'invoiceNumber', 'tags'. Set to 'null' otherwise. - * @param param String Required if 'searchBy' is either 'invoiceDate' or 'externalId'. Set to null otherwise. + * 'recipientId', 'invoiceNumber', 'tags', or 'externalId'. Set to 'null' otherwise. + * @param param String Required if 'searchBy' is 'invoiceDate'. Set to null otherwise. * @return Invoices object that contains {@code List} that you can traverse through, and a Meta object with pagination information * @throws Exception */ @@ -198,7 +198,7 @@ public Invoices search(final SearchBy searchBy, if(null == paramsList){ throw new InvalidFieldException("variable paramsList can not be null for the provided searchBy parameter. Refer to method's Javadoc for more details."); } - body = "{\""+searchBy.name()+"\":" + body = "{\""+searchBy.getKey()+"\":" +new ObjectMapper() .setSerializationInclusion(Include.NON_EMPTY) .writeValueAsString(paramsList) @@ -212,7 +212,7 @@ public Invoices search(final SearchBy searchBy, if(null == param){ throw new InvalidFieldException("variable param can not be null for the provided searchBy parameter. Refer to method's Javadoc for more details."); } - body = "{\""+searchBy.name()+"\":\""+param+"\"}"; + body = "{\""+searchBy.getKey()+"\":\""+param+"\"}"; break; } final String endPoint = "/v1/invoices/search/"; diff --git a/src/main/java/com/trolley/trolley/InvoiceLine.java b/src/main/java/com/trolley/trolley/InvoiceLine.java index 884ae9b..a5e58f0 100644 --- a/src/main/java/com/trolley/trolley/InvoiceLine.java +++ b/src/main/java/com/trolley/trolley/InvoiceLine.java @@ -1,6 +1,5 @@ package com.trolley.trolley; -import java.io.IOException; import java.util.List; import java.util.Locale; diff --git a/src/main/java/com/trolley/trolley/Recipient.java b/src/main/java/com/trolley/trolley/Recipient.java index bddce74..76952dd 100644 --- a/src/main/java/com/trolley/trolley/Recipient.java +++ b/src/main/java/com/trolley/trolley/Recipient.java @@ -6,8 +6,6 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonValue; -import com.fasterxml.jackson.databind.ser.std.StdKeySerializers.Default; -import com.trolley.trolley.Invoice.SearchBy; @JsonInclude(JsonInclude.Include.NON_NULL) public class Recipient diff --git a/src/test/java/com/trolley/sdk/integration/InvoiceTests.java b/src/test/java/com/trolley/sdk/integration/InvoiceTests.java index 2c18111..e9e0161 100644 --- a/src/test/java/com/trolley/sdk/integration/InvoiceTests.java +++ b/src/test/java/com/trolley/sdk/integration/InvoiceTests.java @@ -48,7 +48,7 @@ public void testInvoices() throws Exception { } }; - // Create a new invoice - request body + // Create a new invoice - prepare request body Invoice invoice = new Invoice(); invoice.setRecipientId(recipient.getId()); invoice.setInvoiceNumber("invoice-123"); @@ -56,7 +56,7 @@ public void testInvoices() throws Exception { invoice.setExternalId("ext-id-"+System.currentTimeMillis()); invoice.setLines(invoiceLines); - // Create a new invoice - receiving response + // Create a new invoice - send request and receive response invoice = client.invoice.create(invoice); assertEquals(invoice.getRecipientId(), recipient.getId()); @@ -84,7 +84,7 @@ public void testInvoices() throws Exception { Invoices invoices = client.invoice.search(Invoice.SearchBy.RECIPIENT_ID, recipientIds, null,1,2); List invoiceList = invoices.getInvoices(); assertEquals(invoiceList.get(0).getRecipientId(),invoice.getRecipientId()); - assertTrue(invoices.getMeta().getPages()>1); + assertTrue(invoices.getMeta().getPages() >= 1); //Cleanup - Delete Recipient boolean recDelResult = testHelper.deleteRecipient(recipient);