diff --git a/server/src/test/java/com/ning/billing/jaxrs/TestCredit.java b/server/src/test/java/com/ning/billing/jaxrs/TestCredit.java
index 50a58a7..dc67b41 100644
--- a/server/src/test/java/com/ning/billing/jaxrs/TestCredit.java
+++ b/server/src/test/java/com/ning/billing/jaxrs/TestCredit.java
@@ -17,19 +17,31 @@
package com.ning.billing.jaxrs;
import java.math.BigDecimal;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.UUID;
import javax.ws.rs.core.Response.Status;
import org.joda.time.DateTime;
+import org.joda.time.Interval;
+import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import com.ning.billing.catalog.api.BillingPeriod;
+import com.ning.billing.catalog.api.ProductCategory;
import com.ning.billing.jaxrs.json.AccountJson;
+import com.ning.billing.jaxrs.json.BundleJsonNoSubscriptions;
import com.ning.billing.jaxrs.json.CreditJson;
+import com.ning.billing.jaxrs.json.InvoiceJsonSimple;
+import com.ning.billing.jaxrs.json.SubscriptionJsonNoEvents;
import com.ning.billing.jaxrs.resources.JaxrsResource;
import com.ning.http.client.Response;
+import com.fasterxml.jackson.core.type.TypeReference;
+
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
@@ -47,7 +59,8 @@ public class TestCredit extends TestJaxrsBase {
public void testAddCreditToInvoice() throws Exception {
final DateTime requestedDate = clock.getUTCNow();
final DateTime effectiveDate = clock.getUTCNow();
- final CreditJson input = new CreditJson(BigDecimal.TEN, UUID.randomUUID(), UUID.randomUUID().toString(),
+ final InvoiceJsonSimple invoice = createInvoice();
+ final CreditJson input = new CreditJson(BigDecimal.TEN, UUID.fromString(invoice.getInvoiceId()), UUID.randomUUID().toString(),
requestedDate, effectiveDate,
UUID.randomUUID().toString(), UUID.fromString(accountJson.getAccountId()));
final String jsonInput = mapper.writeValueAsString(input);
@@ -70,6 +83,38 @@ public class TestCredit extends TestJaxrsBase {
assertEquals(objFromJson.getEffectiveDate().toLocalDate().compareTo(input.getEffectiveDate().toLocalDate()), 0);
}
+ private InvoiceJsonSimple createInvoice() throws Exception {
+ final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
+ clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
+
+ final AccountJson accountJson = createAccountWithDefaultPaymentMethod("poupou", "qhddffrwe", "poupou@yahoo.com");
+ assertNotNull(accountJson);
+
+ final BundleJsonNoSubscriptions bundleJson = createBundle(accountJson.getAccountId(), "9967599");
+ assertNotNull(bundleJson);
+
+ final SubscriptionJsonNoEvents subscriptionJson = createSubscription(bundleJson.getBundleId(), "Shotgun", ProductCategory.BASE.toString(), BillingPeriod.MONTHLY.toString(), true);
+ assertNotNull(subscriptionJson);
+
+ // MOVE AFTER TRIAL
+ final Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(30));
+ clock.addDeltaFromReality(it.toDurationMillis());
+ crappyWaitForLackOfProperSynchonization();
+
+ final String uri = JaxrsResource.INVOICES_PATH;
+ final Map<String, String> queryParams = new HashMap<String, String>();
+ queryParams.put(JaxrsResource.QUERY_ACCOUNT_ID, accountJson.getAccountId());
+
+ final Response response = doGet(uri, queryParams, DEFAULT_HTTP_TIMEOUT_SEC);
+ Assert.assertEquals(response.getStatusCode(), Status.OK.getStatusCode());
+ final String baseJson = response.getResponseBody();
+ final List<InvoiceJsonSimple> objFromJson = mapper.readValue(baseJson, new TypeReference<List<InvoiceJsonSimple>>() {});
+ assertNotNull(objFromJson);
+ assertEquals(objFromJson.size(), 2);
+
+ return objFromJson.get(1);
+ }
+
@Test(groups = "slow")
public void testAccountDoesNotExist() throws Exception {
final DateTime requestedDate = clock.getUTCNow();