Details
diff --git a/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/BundleResource.java b/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/BundleResource.java
index c9f4032..09e6032 100644
--- a/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/BundleResource.java
+++ b/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/BundleResource.java
@@ -133,7 +133,7 @@ public class BundleResource extends JaxRsResourceBase {
@TimedResource
@GET
@Produces(APPLICATION_JSON)
- @ApiOperation(value = "Retrieve a bundle by external key", response = BundleJson.class)
+ @ApiOperation(value = "Retrieve a bundle by external key", response = BundleJson.class, responseContainer = "List")
@ApiResponses(value = {@ApiResponse(code = 404, message = "Bundle not found")})
public Response getBundleByKey(@ApiParam(required=true) @QueryParam(QUERY_EXTERNAL_KEY) final String externalKey,
@QueryParam(QUERY_INCLUDED_DELETED) @DefaultValue("false") final Boolean includedDeleted,
diff --git a/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/InvoiceResource.java b/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/InvoiceResource.java
index bac709a..cb4b4f5 100644
--- a/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/InvoiceResource.java
+++ b/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/InvoiceResource.java
@@ -548,7 +548,7 @@ public class InvoiceResource extends JaxRsResourceBase {
@Override
public InvoiceItemJson apply(final InvoiceItemJson input) {
if (input.getCurrency() != null) {
- if (!input.getCurrency().equals(accountCurrency.name())) {
+ if (!input.getCurrency().equals(accountCurrency)) {
throw new IllegalArgumentException(input.getCurrency().toString());
}
return input;
diff --git a/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/PaymentResource.java b/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/PaymentResource.java
index 35b4ce1..b448674 100644
--- a/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/PaymentResource.java
+++ b/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/PaymentResource.java
@@ -157,9 +157,9 @@ public class PaymentResource extends ComboPaymentResource {
@QueryParam(QUERY_SEARCH_LIMIT) @DefaultValue("100") final Long limit,
@QueryParam(QUERY_PAYMENT_PLUGIN_NAME) final String pluginName,
@QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString,
- @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode,
@QueryParam(QUERY_WITH_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo,
@QueryParam(QUERY_WITH_ATTEMPTS) @DefaultValue("false") final Boolean withAttempts,
+ @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode,
@javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException {
final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
final TenantContext tenantContext = context.createTenantContextNoAccountId(request);
diff --git a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestAccountEmailNotifications.java b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestAccountEmailNotifications.java
index fb0af86..0d44ee3 100644
--- a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestAccountEmailNotifications.java
+++ b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestAccountEmailNotifications.java
@@ -20,8 +20,8 @@ package org.killbill.billing.jaxrs;
import java.util.UUID;
-import org.killbill.billing.client.model.Account;
-import org.killbill.billing.client.model.InvoiceEmail;
+import org.killbill.billing.client.model.gen.Account;
+import org.killbill.billing.client.model.gen.InvoiceEmail;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -32,28 +32,28 @@ public class TestAccountEmailNotifications extends TestJaxrsBase {
final Account input = createAccount();
final UUID accountId = input.getAccountId();
- final InvoiceEmail invoiceEmailJsonWithNotifications = new InvoiceEmail(accountId, true);
- final InvoiceEmail invoiceEmailJsonWithoutNotifications = new InvoiceEmail(accountId, false);
+ final InvoiceEmail invoiceEmailJsonWithNotifications = new InvoiceEmail(accountId, true, null);
+ final InvoiceEmail invoiceEmailJsonWithoutNotifications = new InvoiceEmail(accountId, false, null);
// Verify the initial state
- final InvoiceEmail firstInvoiceEmailJson = killBillClient.getEmailNotificationsForAccount(accountId);
+ final InvoiceEmail firstInvoiceEmailJson = accountApi.getEmailNotificationsForAccount(accountId, requestOptions);
Assert.assertEquals(firstInvoiceEmailJson.getAccountId(), accountId);
- Assert.assertFalse(firstInvoiceEmailJson.isNotifiedForInvoices());
+ Assert.assertFalse(firstInvoiceEmailJson.isIsNotifiedForInvoices());
// Enable email notifications
- killBillClient.updateEmailNotificationsForAccount(invoiceEmailJsonWithNotifications, createdBy, reason, comment);
+ accountApi.setEmailNotificationsForAccount(invoiceEmailJsonWithNotifications, accountId, requestOptions);
// Verify we can retrieve it
- final InvoiceEmail secondInvoiceEmailJson = killBillClient.getEmailNotificationsForAccount(accountId);
+ final InvoiceEmail secondInvoiceEmailJson = accountApi.getEmailNotificationsForAccount(accountId, requestOptions);
Assert.assertEquals(secondInvoiceEmailJson.getAccountId(), accountId);
- Assert.assertTrue(secondInvoiceEmailJson.isNotifiedForInvoices());
+ Assert.assertTrue(secondInvoiceEmailJson.isIsNotifiedForInvoices());
// Disable email notifications
- killBillClient.updateEmailNotificationsForAccount(invoiceEmailJsonWithoutNotifications, createdBy, reason, comment);
+ accountApi.setEmailNotificationsForAccount(invoiceEmailJsonWithoutNotifications, accountId, requestOptions);
// Verify we can retrieve it
- final InvoiceEmail thirdInvoiceEmailJson = killBillClient.getEmailNotificationsForAccount(accountId);
+ final InvoiceEmail thirdInvoiceEmailJson = accountApi.getEmailNotificationsForAccount(accountId, requestOptions );
Assert.assertEquals(thirdInvoiceEmailJson.getAccountId(), accountId);
- Assert.assertFalse(thirdInvoiceEmailJson.isNotifiedForInvoices());
+ Assert.assertFalse(thirdInvoiceEmailJson.isIsNotifiedForInvoices());
}
}
diff --git a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestAccountTimeline.java b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestAccountTimeline.java
index 953b902..5856c8a 100644
--- a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestAccountTimeline.java
+++ b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestAccountTimeline.java
@@ -27,27 +27,23 @@ import javax.annotation.Nullable;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.killbill.billing.client.KillBillClientException;
-import org.killbill.billing.client.RequestOptions;
-import org.killbill.billing.client.model.Account;
-import org.killbill.billing.client.model.AccountTimeline;
-import org.killbill.billing.client.model.AuditLog;
-import org.killbill.billing.client.model.Credit;
-import org.killbill.billing.client.model.EventSubscription;
-import org.killbill.billing.client.model.Invoice;
-import org.killbill.billing.client.model.InvoicePayment;
-import org.killbill.billing.client.model.InvoicePaymentTransaction;
-import org.killbill.billing.client.model.Payment;
-import org.killbill.billing.client.model.PaymentTransaction;
+import org.killbill.billing.client.model.gen.Account;
+import org.killbill.billing.client.model.gen.AccountTimeline;
+import org.killbill.billing.client.model.gen.AuditLog;
+import org.killbill.billing.client.model.gen.Credit;
+import org.killbill.billing.client.model.gen.EventSubscription;
+import org.killbill.billing.client.model.gen.Invoice;
+import org.killbill.billing.client.model.gen.InvoicePayment;
+import org.killbill.billing.client.model.gen.InvoicePaymentTransaction;
+import org.killbill.billing.client.model.gen.Payment;
+import org.killbill.billing.client.model.gen.PaymentTransaction;
+import org.killbill.billing.entitlement.api.SubscriptionEventType;
import org.killbill.billing.payment.api.TransactionType;
import org.killbill.billing.util.api.AuditLevel;
import org.killbill.billing.util.audit.ChangeType;
import org.testng.Assert;
import org.testng.annotations.Test;
-import com.google.common.collect.HashMultimap;
-
-import static org.killbill.billing.jaxrs.resources.JaxrsResource.QUERY_PARALLEL;
-
public class TestAccountTimeline extends TestJaxrsBase {
private static final String PAYMENT_REQUEST_PROCESSOR = "PaymentRequestProcessor";
@@ -69,11 +65,11 @@ public class TestAccountTimeline extends TestJaxrsBase {
final List<EventSubscription> events = timeline.getBundles().get(0).getSubscriptions().get(0).getEvents();
Assert.assertEquals(events.get(0).getEffectiveDate(), new LocalDate(2012, 4, 25));
- Assert.assertEquals(events.get(0).getEventType(), "START_ENTITLEMENT");
+ Assert.assertEquals(events.get(0).getEventType(), SubscriptionEventType.START_ENTITLEMENT);
Assert.assertEquals(events.get(1).getEffectiveDate(), new LocalDate(2012, 4, 25));
- Assert.assertEquals(events.get(1).getEventType(), "START_BILLING");
+ Assert.assertEquals(events.get(1).getEventType(), SubscriptionEventType.START_BILLING);
Assert.assertEquals(events.get(2).getEffectiveDate(), new LocalDate(2012, 5, 25));
- Assert.assertEquals(events.get(2).getEventType(), "PHASE");
+ Assert.assertEquals(events.get(2).getEventType(), SubscriptionEventType.PHASE);
}
@Test(groups = "slow", description = "Can retrieve the timeline with audits")
@@ -83,27 +79,27 @@ public class TestAccountTimeline extends TestJaxrsBase {
final DateTime endTime = clock.getUTCNow();
// Add credit
- final Invoice invoice = killBillClient.getInvoicesForAccount(accountJson.getAccountId()).get(1);
+ final Invoice invoice = accountApi.getInvoices(accountJson.getAccountId(), requestOptions).get(1);
final BigDecimal creditAmount = BigDecimal.ONE;
final Credit credit = new Credit();
credit.setAccountId(accountJson.getAccountId());
credit.setCreditAmount(creditAmount);
- killBillClient.createCredit(credit, true, createdBy, reason, comment);
+ creditApi.createCredit(credit, true, requestOptions);
// Add refund
- final Payment postedPayment = killBillClient.getPaymentsForAccount(accountJson.getAccountId()).get(0);
+ final Payment postedPayment = accountApi.getPayments(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions).get(0);
final BigDecimal refundAmount = BigDecimal.ONE;
final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
refund.setPaymentId(postedPayment.getPaymentId());
refund.setAmount(refundAmount);
- killBillClient.createInvoicePaymentRefund(refund, createdBy, reason, comment);
+ invoicePaymentApi.createRefundWithAdjustments(refund, postedPayment.getPaymentId(), accountJson.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
// Add chargeback
final BigDecimal chargebackAmount = BigDecimal.ONE;
final InvoicePaymentTransaction chargeback = new InvoicePaymentTransaction();
chargeback.setPaymentId(postedPayment.getPaymentId());
chargeback.setAmount(chargebackAmount);
- killBillClient.createInvoicePaymentChargeback(chargeback, createdBy, reason, comment);
+ invoicePaymentApi.createChargeback(chargeback, postedPayment.getPaymentId(), requestOptions);
// Verify payments
verifyPayments(accountJson.getAccountId(), startTime, endTime, refundAmount, chargebackAmount);
@@ -127,18 +123,18 @@ public class TestAccountTimeline extends TestJaxrsBase {
final InvoicePayment payment = timeline.getPayments().get(0);
// Verify payments
- final List<PaymentTransaction> purchaseTransactions = getPaymentTransactions(timeline.getPayments(), TransactionType.PURCHASE.toString());
+ final List<PaymentTransaction> purchaseTransactions = getInvoicePaymentTransactions(timeline.getPayments(), TransactionType.PURCHASE);
Assert.assertEquals(purchaseTransactions.size(), 1);
final PaymentTransaction purchaseTransaction = purchaseTransactions.get(0);
// Verify refunds
- final List<PaymentTransaction> refundTransactions = getPaymentTransactions(timeline.getPayments(), TransactionType.REFUND.toString());
+ final List<PaymentTransaction> refundTransactions = getInvoicePaymentTransactions(timeline.getPayments(), TransactionType.REFUND);
Assert.assertEquals(refundTransactions.size(), 1);
final PaymentTransaction refundTransaction = refundTransactions.get(0);
Assert.assertEquals(refundTransaction.getPaymentId(), payment.getPaymentId());
Assert.assertEquals(refundTransaction.getAmount().compareTo(refundAmount), 0);
- final List<PaymentTransaction> chargebackTransactions = getPaymentTransactions(timeline.getPayments(), TransactionType.CHARGEBACK.toString());
+ final List<PaymentTransaction> chargebackTransactions = getInvoicePaymentTransactions(timeline.getPayments(), TransactionType.CHARGEBACK);
Assert.assertEquals(chargebackTransactions.size(), 1);
final PaymentTransaction chargebackTransaction = chargebackTransactions.get(0);
Assert.assertEquals(chargebackTransaction.getPaymentId(), payment.getPaymentId());
@@ -308,13 +304,10 @@ public class TestAccountTimeline extends TestJaxrsBase {
}
private AccountTimeline getAccountTimeline(final UUID accountId, final AuditLevel auditLevel) throws KillBillClientException {
- final AccountTimeline accountTimeline = killBillClient.getAccountTimeline(accountId, auditLevel, RequestOptions.empty());
+ final AccountTimeline accountTimeline = accountApi.getAccountTimeline(accountId, auditLevel, false, requestOptions);
// Verify also the parallel path
- final HashMultimap<String, String> queryParams = HashMultimap.<String, String>create();
- queryParams.put(QUERY_PARALLEL, "true");
- final RequestOptions requestOptions = RequestOptions.builder().withQueryParams(queryParams).build();
- final AccountTimeline accountTimelineInParallel = killBillClient.getAccountTimeline(accountId, auditLevel, requestOptions);
+ final AccountTimeline accountTimelineInParallel = accountApi.getAccountTimeline(accountId, auditLevel, true, requestOptions);
Assert.assertEquals(accountTimelineInParallel, accountTimeline);
return accountTimeline;
diff --git a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestAdmin.java b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestAdmin.java
index 26e2a9c..e5264fe 100644
--- a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestAdmin.java
+++ b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestAdmin.java
@@ -30,14 +30,14 @@ import org.killbill.billing.catalog.api.BillingPeriod;
import org.killbill.billing.catalog.api.ProductCategory;
import org.killbill.billing.client.JaxrsResource;
import org.killbill.billing.client.KillBillClientException;
-import org.killbill.billing.client.KillBillHttpClient;
import org.killbill.billing.client.RequestOptions;
-import org.killbill.billing.client.model.Account;
-import org.killbill.billing.client.model.Invoice;
-import org.killbill.billing.client.model.Payment;
-import org.killbill.billing.client.model.PaymentTransaction;
-import org.killbill.billing.jaxrs.json.AdminPaymentJson;
+import org.killbill.billing.client.model.gen.Account;
+import org.killbill.billing.client.model.gen.AdminPayment;
+import org.killbill.billing.client.model.gen.Invoice;
+import org.killbill.billing.client.model.gen.Payment;
+import org.killbill.billing.client.model.gen.PaymentTransaction;
import org.killbill.billing.payment.api.TransactionStatus;
+import org.killbill.billing.payment.api.TransactionType;
import org.killbill.billing.util.api.AuditLevel;
import org.killbill.billing.util.jackson.ObjectMapper;
import org.testng.Assert;
@@ -46,9 +46,7 @@ import org.testng.annotations.Test;
import com.ning.http.client.Response;
import com.fasterxml.jackson.core.type.TypeReference;
-import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableMultimap;
-import com.google.common.collect.Multimap;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
@@ -69,35 +67,36 @@ public class TestAdmin extends TestJaxrsBase {
authTransaction.setCurrency(account.getCurrency());
authTransaction.setPaymentExternalKey(paymentExternalKey);
authTransaction.setTransactionExternalKey(authTransactionExternalKey);
- authTransaction.setTransactionType("AUTHORIZE");
- final Payment authPayment = killBillClient.createPayment(account.getAccountId(), account.getPaymentMethodId(), authTransaction, requestOptions);
+ authTransaction.setTransactionType(TransactionType.AUTHORIZE);
+ final Payment authPayment = accountApi.processPayment(authTransaction, account.getAccountId(), account.getPaymentMethodId(), NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptions);
// First fix transactionStatus and paymentSstate (but not lastSuccessPaymentState
// Note that state is not consistent between TransactionStatus and lastSuccessPaymentState but we don't care.
- fixPaymentState(authPayment, null, "AUTH_FAILED", TransactionStatus.PAYMENT_FAILURE);
+ fixPaymentState(authPayment, "AUTH_SUCCESS", "AUTH_FAILED", TransactionStatus.PAYMENT_FAILURE);
- final Payment updatedPayment1 = killBillClient.getPayment(authPayment.getPaymentId());
+ final Payment updatedPayment1 = paymentApi.getPayment(authPayment.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
Assert.assertEquals(updatedPayment1.getTransactions().size(), 1);
final PaymentTransaction authTransaction1 = updatedPayment1.getTransactions().get(0);
- Assert.assertEquals(authTransaction1.getStatus(), TransactionStatus.PAYMENT_FAILURE.toString());
+ Assert.assertEquals(authTransaction1.getStatus(), TransactionStatus.PAYMENT_FAILURE);
// Capture should succeed because lastSuccessPaymentState was left untouched
doCapture(updatedPayment1, false);
fixPaymentState(authPayment, "AUTH_FAILED", "AUTH_FAILED", TransactionStatus.PAYMENT_FAILURE);
- final Payment updatedPayment2 = killBillClient.getPayment(authPayment.getPaymentId());
+ final Payment updatedPayment2 = paymentApi.getPayment(authPayment.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
Assert.assertEquals(updatedPayment2.getTransactions().size(), 2);
final PaymentTransaction authTransaction2 = updatedPayment2.getTransactions().get(0);
- Assert.assertEquals(authTransaction2.getStatus(), TransactionStatus.PAYMENT_FAILURE.toString());
+ Assert.assertEquals(authTransaction2.getStatus(), TransactionStatus.PAYMENT_FAILURE);
final PaymentTransaction captureTransaction2 = updatedPayment2.getTransactions().get(1);
- Assert.assertEquals(captureTransaction2.getStatus(), TransactionStatus.SUCCESS.toString());
+ Assert.assertEquals(captureTransaction2.getStatus(), TransactionStatus.SUCCESS);
// Capture should now failed because lastSuccessPaymentState was moved to AUTH_FAILED
doCapture(updatedPayment2, true);
}
+
@Test(groups = "slow")
public void testAdminInvoiceEndpoint() throws Exception {
final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
@@ -109,17 +108,17 @@ public class TestAdmin extends TestJaxrsBase {
assertNotNull(accountJson);
accounts.add(accountJson.getAccountId());
- createEntitlement(accountJson.getAccountId(),
- UUID.randomUUID().toString(),
- "Shotgun",
- ProductCategory.BASE,
- BillingPeriod.MONTHLY,
- true);
+ createSubscription(accountJson.getAccountId(),
+ UUID.randomUUID().toString(),
+ "Shotgun",
+ ProductCategory.BASE,
+ BillingPeriod.MONTHLY,
+ true);
clock.addDays(2);
crappyWaitForLackOfProperSynchonization();
- Assert.assertEquals(killBillClient.getInvoices(requestOptions).getPaginationMaxNbRecords(), i + 1);
- final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), false, false, false, false, AuditLevel.NONE, requestOptions);
+ Assert.assertEquals(invoiceApi.getInvoices(requestOptions).getPaginationMaxNbRecords(), i + 1);
+ final List<Invoice> invoices = accountApi.getInvoices(accountJson.getAccountId(), false, false, false, false, AuditLevel.NONE, requestOptions);
assertEquals(invoices.size(), 1);
}
@@ -127,9 +126,9 @@ public class TestAdmin extends TestJaxrsBase {
clock.addDays(32);
crappyWaitForLackOfProperSynchonization();
- Assert.assertEquals(killBillClient.getInvoices(requestOptions).getPaginationMaxNbRecords(), 10);
+ Assert.assertEquals(invoiceApi.getInvoices(requestOptions).getPaginationMaxNbRecords(), 10);
for (final UUID accountId : accounts) {
- final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountId, false, false, false, false, AuditLevel.NONE, requestOptions);
+ final List<Invoice> invoices = accountApi.getInvoices(accountId, false, false, false, false, AuditLevel.NONE, requestOptions);
assertEquals(invoices.size(), 2);
}
@@ -138,33 +137,33 @@ public class TestAdmin extends TestJaxrsBase {
final Map<String, String> perTenantProperties = new HashMap<String, String>();
perTenantProperties.put("org.killbill.invoice.enabled", "false");
final String perTenantConfig = mapper.writeValueAsString(perTenantProperties);
- killBillClient.postConfigurationPropertiesForTenant(perTenantConfig, requestOptions);
+ tenantApi.uploadPerTenantConfiguration(perTenantConfig, requestOptions);
crappyWaitForLackOfProperSynchonization();
// Verify the second invoice isn't generated
clock.addDays(32);
crappyWaitForLackOfProperSynchonization();
- Assert.assertEquals(killBillClient.getInvoices(requestOptions).getPaginationMaxNbRecords(), 10);
+ Assert.assertEquals(invoiceApi.getInvoices(requestOptions).getPaginationMaxNbRecords(), 10);
for (final UUID accountId : accounts) {
- final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountId, false, false, false, false, AuditLevel.NONE, requestOptions);
+ final List<Invoice> invoices = accountApi.getInvoices(accountId, false, false, false, false, AuditLevel.NONE, requestOptions);
assertEquals(invoices.size(), 2);
}
// Fix one account
final Response response = triggerInvoiceGenerationForParkedAccounts(1);
Assert.assertEquals(response.getResponseBody(), "{\"" + accounts.get(0) + "\":\"OK\"}");
- Assert.assertEquals(killBillClient.getInvoices(requestOptions).getPaginationMaxNbRecords(), 11);
+ Assert.assertEquals(invoiceApi.getInvoices(requestOptions).getPaginationMaxNbRecords(), 11);
// Fix all accounts
final Response response2 = triggerInvoiceGenerationForParkedAccounts(5);
- final Map<String,String> fixedAccounts = mapper.readValue(response2.getResponseBody(), new TypeReference<Map<String,String>>() {});
+ final Map<String, String> fixedAccounts = mapper.readValue(response2.getResponseBody(), new TypeReference<Map<String, String>>() {});
Assert.assertEquals(fixedAccounts.size(), 4);
Assert.assertEquals(fixedAccounts.get(accounts.get(1).toString()), "OK");
Assert.assertEquals(fixedAccounts.get(accounts.get(2).toString()), "OK");
Assert.assertEquals(fixedAccounts.get(accounts.get(3).toString()), "OK");
Assert.assertEquals(fixedAccounts.get(accounts.get(4).toString()), "OK");
- Assert.assertEquals(killBillClient.getInvoices(requestOptions).getPaginationMaxNbRecords(), 15);
+ Assert.assertEquals(invoiceApi.getInvoices(requestOptions).getPaginationMaxNbRecords(), 15);
}
private void doCapture(final Payment payment, final boolean expectException) throws KillBillClientException {
@@ -178,7 +177,7 @@ public class TestAdmin extends TestJaxrsBase {
captureTransaction.setPaymentExternalKey(payment.getPaymentExternalKey());
captureTransaction.setTransactionExternalKey(capture1TransactionExternalKey);
try {
- killBillClient.captureAuthorization(captureTransaction, requestOptions);
+ paymentApi.captureAuthorization(captureTransaction, payment.getPaymentId(), NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptions);
if (expectException) {
Assert.fail("Capture should not succeed, after auth was moved to a PAYMENT_FAILURE");
}
@@ -191,18 +190,8 @@ public class TestAdmin extends TestJaxrsBase {
}
private void fixPaymentState(final Payment payment, final String lastSuccessPaymentState, final String currentPaymentStateName, final TransactionStatus transactionStatus) throws KillBillClientException {
- //
- // We do not expose the endpoint in the client API on purpose since this should only be accessed using special permission ADMIN_CAN_FIX_DATA
- // for when there is a need to fix payment state.
- //
- final String uri = "/1.0/kb/admin/payments/" + payment.getPaymentId().toString() + "/transactions/" + payment.getTransactions().get(0).getTransactionId().toString();
-
- final AdminPaymentJson body = new AdminPaymentJson(lastSuccessPaymentState, currentPaymentStateName, transactionStatus.toString());
- final Multimap result = HashMultimap.create();
- result.put(KillBillHttpClient.AUDIT_OPTION_CREATED_BY, createdBy);
- result.put(KillBillHttpClient.AUDIT_OPTION_REASON, reason);
- result.put(KillBillHttpClient.AUDIT_OPTION_COMMENT, comment);
- killBillHttpClient.doPut(uri, body, result);
+ final AdminPayment body = new AdminPayment(lastSuccessPaymentState, currentPaymentStateName, transactionStatus.toString());
+ adminApi.updatePaymentTransactionState(body, payment.getPaymentId(), payment.getTransactions().get(0).getTransactionId(), requestOptions);
}
private Response triggerInvoiceGenerationForParkedAccounts(final int limit) throws KillBillClientException {
diff --git a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestBundle.java b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestBundle.java
index 4323f25..f746579 100644
--- a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestBundle.java
+++ b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestBundle.java
@@ -25,12 +25,12 @@ import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.killbill.billing.catalog.api.BillingPeriod;
import org.killbill.billing.catalog.api.ProductCategory;
-import org.killbill.billing.client.model.Account;
-import org.killbill.billing.client.model.BlockingState;
import org.killbill.billing.client.model.BlockingStates;
-import org.killbill.billing.client.model.Bundle;
import org.killbill.billing.client.model.Bundles;
-import org.killbill.billing.client.model.Subscription;
+import org.killbill.billing.client.model.gen.Account;
+import org.killbill.billing.client.model.gen.BlockingState;
+import org.killbill.billing.client.model.gen.Bundle;
+import org.killbill.billing.client.model.gen.Subscription;
import org.killbill.billing.entitlement.api.BlockingStateType;
import org.killbill.billing.entitlement.api.Entitlement.EntitlementState;
import org.killbill.billing.util.api.AuditLevel;
@@ -50,9 +50,10 @@ public class TestBundle extends TestJaxrsBase {
@Test(groups = "slow", description = "Can create bundles without an external key")
public void testCreateBundleWithNoExternalKey() throws Exception {
- final Account accountJson = createAccount();
+ final Account accountJson;
+ accountJson = createAccount();
- final Subscription subscription = createEntitlement(accountJson.getAccountId(), null, "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, true);
+ final Subscription subscription = createSubscription(accountJson.getAccountId(), null, "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, true);
Assert.assertNotNull(subscription.getExternalKey());
}
@@ -60,20 +61,20 @@ public class TestBundle extends TestJaxrsBase {
public void testBundleOk() throws Exception {
final Account accountJson = createAccount();
- createEntitlement(accountJson.getAccountId(), "123467", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, true);
+ createSubscription(accountJson.getAccountId(), "123467", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, true);
// Retrieves by external key
- final List<Bundle> objFromJson = killBillClient.getAccountBundles(accountJson.getAccountId(), "123467");
+ final List<Bundle> objFromJson = accountApi.getAccountBundles(accountJson.getAccountId(), "123467", null, requestOptions);
Assert.assertEquals(objFromJson.size(), 1);
}
@Test(groups = "slow", description = "Can retrieve account bundles")
public void testBundleFromAccount() throws Exception {
final Account accountJson = createAccount();
- createEntitlement(accountJson.getAccountId(), "156567", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, true);
- createEntitlement(accountJson.getAccountId(), "265658", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, true);
+ createSubscription(accountJson.getAccountId(), "156567", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, true);
+ createSubscription(accountJson.getAccountId(), "265658", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, true);
- final List<Bundle> objFromJson = killBillClient.getAccountBundles(accountJson.getAccountId());
+ final List<Bundle> objFromJson = accountApi.getAccountBundles(accountJson.getAccountId(), null, null, requestOptions);
Assert.assertEquals(objFromJson.size(), 2);
}
@@ -82,21 +83,22 @@ public class TestBundle extends TestJaxrsBase {
final Account accountJson = createAccount();
// ID
- Assert.assertNull(killBillClient.getBundle(UUID.randomUUID(), requestOptions));
+ Assert.assertNull(bundleApi.getBundle(UUID.randomUUID(), requestOptions));
// External Key
- Assert.assertNull(killBillClient.getBundle(UUID.randomUUID().toString(), requestOptions));
- Assert.assertTrue(killBillClient.getAllBundlesForExternalKey(UUID.randomUUID().toString(), requestOptions).isEmpty());
+ Assert.assertTrue(bundleApi.getBundleByKey(UUID.randomUUID().toString(), requestOptions).isEmpty());
+
+ Assert.assertTrue(bundleApi.getBundleByKey(UUID.randomUUID().toString(), requestOptions).isEmpty());
// Account Id
- Assert.assertTrue(killBillClient.getAccountBundles(accountJson.getAccountId(), "98374982743892", requestOptions).isEmpty());
- Assert.assertTrue(killBillClient.getAccountBundles(accountJson.getAccountId(), requestOptions).isEmpty());
+ Assert.assertTrue(accountApi.getAccountBundles(accountJson.getAccountId(), "98374982743892", null, requestOptions).isEmpty());
+ Assert.assertTrue(accountApi.getAccountBundles(accountJson.getAccountId(), null, null, requestOptions).isEmpty());
}
@Test(groups = "slow", description = "Can handle non existent account")
public void testAccountNonExistent() throws Exception {
- Assert.assertTrue(killBillClient.getAccountBundles(UUID.randomUUID()).isEmpty());
+ Assert.assertTrue(accountApi.getAccountBundles(UUID.randomUUID(), null, null, requestOptions).isEmpty());
}
@Test(groups = "slow", description = "Can transfer bundle")
@@ -110,10 +112,16 @@ public class TestBundle extends TestJaxrsBase {
final BillingPeriod term = BillingPeriod.MONTHLY;
final String bundleExternalKey = "93199";
- final Subscription entitlementJsonNoEvents = createEntitlement(accountJson.getAccountId(), bundleExternalKey, productName,
+ final Subscription entitlementJsonNoEvents = createSubscription(accountJson.getAccountId(), bundleExternalKey, productName,
ProductCategory.BASE, term, true);
- final Bundle originalBundle = killBillClient.getBundle(bundleExternalKey, requestOptions);
+ Bundles existingBundles = bundleApi.getBundleByKey(bundleExternalKey, requestOptions);
+ assertEquals(existingBundles.size(), 1);
+ Bundle originalBundle = existingBundles.get(0);
+ existingBundles = bundleApi.getBundleByKey(bundleExternalKey, requestOptions);
+ assertEquals(existingBundles.size(), 1);
+ originalBundle = existingBundles.get(0);
+ assertEquals(originalBundle.getAccountId(), accountJson.getAccountId());
assertEquals(originalBundle.getAccountId(), accountJson.getAccountId());
assertEquals(originalBundle.getExternalKey(), bundleExternalKey);
@@ -122,15 +130,16 @@ public class TestBundle extends TestJaxrsBase {
final Bundle bundle = new Bundle();
bundle.setAccountId(newAccount.getAccountId());
bundle.setBundleId(entitlementJsonNoEvents.getBundleId());
- assertEquals(killBillClient.transferBundle(bundle, createdBy, reason, comment).getAccountId(), newAccount.getAccountId());
+ bundleApi.transferBundle(bundle, entitlementJsonNoEvents.getBundleId(), null, NULL_PLUGIN_PROPERTIES, requestOptions);
- final Bundle newBundle = killBillClient.getBundle(bundleExternalKey, requestOptions);
+ existingBundles = bundleApi.getBundleByKey(bundleExternalKey, requestOptions);
+ assertEquals(existingBundles.size(), 1);
+ final Bundle newBundle = existingBundles.get(0);
assertNotEquals(newBundle.getBundleId(), originalBundle.getBundleId());
assertEquals(newBundle.getExternalKey(), originalBundle.getExternalKey());
assertEquals(newBundle.getAccountId(), newAccount.getAccountId());
-
- final Bundles bundles = killBillClient.getAllBundlesForExternalKey(bundleExternalKey, requestOptions);
+ final Bundles bundles = bundleApi.getBundleByKey(bundleExternalKey, true, AuditLevel.NONE, requestOptions);
assertEquals(bundles.size(), 2);
assertSubscriptionState(bundles, originalBundle.getBundleId(), EntitlementState.CANCELLED);
assertSubscriptionState(bundles, newBundle.getBundleId(), EntitlementState.ACTIVE);
@@ -159,34 +168,36 @@ public class TestBundle extends TestJaxrsBase {
final BillingPeriod term = BillingPeriod.MONTHLY;
final String bundleExternalKey = "93199";
- final Subscription entitlement = createEntitlement(accountJson.getAccountId(), bundleExternalKey, productName,
+ final Subscription entitlement = createSubscription(accountJson.getAccountId(), bundleExternalKey, productName,
ProductCategory.BASE, term, true);
- final Bundle bundle = killBillClient.getBundle(bundleExternalKey);
+ Bundles existingBundles = bundleApi.getBundleByKey(bundleExternalKey, requestOptions);
+ assertEquals(existingBundles.size(), 1);
+ final Bundle bundle = existingBundles.get(0);
assertEquals(bundle.getAccountId(), accountJson.getAccountId());
assertEquals(bundle.getExternalKey(), bundleExternalKey);
final BlockingState blockingState = new BlockingState(bundle.getBundleId(), "block", "service", false, true, true, null, BlockingStateType.SUBSCRIPTION_BUNDLE, null);
- killBillClient.setBlockingState(bundle.getBundleId(), blockingState, clock.getToday(DateTimeZone.forID(accountJson.getTimeZone())), ImmutableMap.<String, String>of(), createdBy, reason, comment);
+ bundleApi.addBundleBlockingState(blockingState, bundle.getBundleId(), clock.getToday(DateTimeZone.forID(accountJson.getTimeZone())), ImmutableMap.<String, String>of(), requestOptions);
- final Subscription subscription = killBillClient.getSubscription(entitlement.getSubscriptionId());
+ final Subscription subscription = subscriptionApi.getSubscription(entitlement.getSubscriptionId(), requestOptions);
assertEquals(subscription.getState(), EntitlementState.BLOCKED);
clock.addDays(1);
final BlockingState unblockingState = new BlockingState(bundle.getBundleId(), "unblock", "service", false, false, false, null, BlockingStateType.SUBSCRIPTION_BUNDLE, null);
- killBillClient.setBlockingState(bundle.getBundleId(), unblockingState, clock.getToday(DateTimeZone.forID(accountJson.getTimeZone())), ImmutableMap.<String, String>of(), createdBy, reason, comment);
+ bundleApi.addBundleBlockingState(unblockingState, bundle.getBundleId(), clock.getToday(DateTimeZone.forID(accountJson.getTimeZone())), ImmutableMap.<String, String>of(), requestOptions);
- final Subscription subscription2 = killBillClient.getSubscription(entitlement.getSubscriptionId());
+ final Subscription subscription2 = subscriptionApi.getSubscription(entitlement.getSubscriptionId(), requestOptions);
assertEquals(subscription2.getState(), EntitlementState.ACTIVE);
- final BlockingStates blockingStates = killBillClient.getBlockingStates(accountJson.getAccountId(), null, ImmutableList.<String>of("service"), AuditLevel.FULL, requestOptions);
+ final BlockingStates blockingStates = accountApi.getBlockingStates(accountJson.getAccountId(), null, ImmutableList.<String>of("service"), AuditLevel.FULL, requestOptions);
Assert.assertEquals(blockingStates.size(), 2);
- final BlockingStates blockingStates2 = killBillClient.getBlockingStates(accountJson.getAccountId(), ImmutableList.<BlockingStateType>of(BlockingStateType.SUBSCRIPTION_BUNDLE), null, AuditLevel.FULL, requestOptions);
+ final BlockingStates blockingStates2 = accountApi.getBlockingStates(accountJson.getAccountId(), ImmutableList.<BlockingStateType>of(BlockingStateType.SUBSCRIPTION_BUNDLE), null, AuditLevel.FULL, requestOptions);
Assert.assertEquals(blockingStates2.size(), 2);
- final BlockingStates blockingStates3 = killBillClient.getBlockingStates(accountJson.getAccountId(), null, null, AuditLevel.FULL, requestOptions);
+ final BlockingStates blockingStates3 = accountApi.getBlockingStates(accountJson.getAccountId(), null, null, AuditLevel.FULL, requestOptions);
Assert.assertEquals(blockingStates3.size(), 3);
}
@@ -195,19 +206,19 @@ public class TestBundle extends TestJaxrsBase {
final Account accountJson = createAccount();
for (int i = 0; i < 5; i++) {
- createEntitlement(accountJson.getAccountId(), UUID.randomUUID().toString(), "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, true);
+ createSubscription(accountJson.getAccountId(), UUID.randomUUID().toString(), "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, true);
}
- final Bundles allBundles = killBillClient.getBundles();
+ final Bundles allBundles = bundleApi.getBundles(requestOptions);
Assert.assertEquals(allBundles.size(), 5);
for (final Bundle bundle : allBundles) {
- Assert.assertEquals(killBillClient.searchBundles(bundle.getBundleId().toString()).size(), 1);
- Assert.assertEquals(killBillClient.searchBundles(bundle.getAccountId().toString()).size(), 5);
- Assert.assertEquals(killBillClient.searchBundles(bundle.getExternalKey()).size(), 1);
+ Assert.assertEquals(bundleApi.searchBundles(bundle.getBundleId().toString(), requestOptions).size(), 1);
+ Assert.assertEquals(bundleApi.searchBundles(bundle.getAccountId().toString(), requestOptions).size(), 5);
+ Assert.assertEquals(bundleApi.searchBundles(bundle.getExternalKey(), requestOptions).size(), 1);
}
- Bundles page = killBillClient.getBundles(0L, 1L);
+ Bundles page = bundleApi.getBundles(0L, 1L, AuditLevel.NONE, requestOptions);
for (int i = 0; i < 5; i++) {
Assert.assertNotNull(page);
Assert.assertEquals(page.size(), 1);
diff --git a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestInvoicePayment.java b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestInvoicePayment.java
index 14b0023..d0a95fd 100644
--- a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestInvoicePayment.java
+++ b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestInvoicePayment.java
@@ -27,29 +27,30 @@ import org.joda.time.DateTime;
import org.killbill.billing.catalog.api.BillingPeriod;
import org.killbill.billing.catalog.api.ProductCategory;
import org.killbill.billing.client.KillBillClientException;
-import org.killbill.billing.client.model.Account;
-import org.killbill.billing.client.model.Invoice;
-import org.killbill.billing.client.model.InvoiceItem;
-import org.killbill.billing.client.model.InvoicePayment;
-import org.killbill.billing.client.model.InvoicePaymentTransaction;
import org.killbill.billing.client.model.InvoicePayments;
import org.killbill.billing.client.model.Invoices;
-import org.killbill.billing.client.model.Payment;
-import org.killbill.billing.client.model.PaymentMethod;
-import org.killbill.billing.client.model.PaymentTransaction;
import org.killbill.billing.client.model.Payments;
-import org.killbill.billing.client.model.Subscription;
+import org.killbill.billing.client.model.gen.Account;
+import org.killbill.billing.client.model.gen.Invoice;
+import org.killbill.billing.client.model.gen.InvoiceItem;
+import org.killbill.billing.client.model.gen.InvoicePayment;
+import org.killbill.billing.client.model.gen.InvoicePaymentTransaction;
+import org.killbill.billing.client.model.gen.Payment;
+import org.killbill.billing.client.model.gen.PaymentMethod;
+import org.killbill.billing.client.model.gen.PaymentTransaction;
+import org.killbill.billing.client.model.gen.Subscription;
import org.killbill.billing.osgi.api.OSGIServiceRegistration;
+import org.killbill.billing.payment.api.TransactionStatus;
import org.killbill.billing.payment.api.TransactionType;
import org.killbill.billing.payment.plugin.api.PaymentPluginApi;
import org.killbill.billing.payment.provider.MockPaymentProviderPlugin;
+import org.killbill.billing.util.api.AuditLevel;
import org.killbill.billing.util.tag.ControlTagType;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
import com.google.inject.Inject;
import static org.testng.Assert.assertEquals;
@@ -70,38 +71,35 @@ public class TestInvoicePayment extends TestJaxrsBase {
mockPaymentProviderPlugin = (MockPaymentProviderPlugin) registry.getServiceForName(PLUGIN_NAME);
}
-
-
-
@Test(groups = "slow")
public void testRetrievePayment() throws Exception {
final InvoicePayment paymentJson = setupScenarioWithPayment();
- final Payment retrievedPaymentJson = killBillClient.getPayment(paymentJson.getPaymentId(), false, requestOptions);
- Assert.assertTrue(retrievedPaymentJson.equals((Payment) paymentJson));
+ final Payment retrievedPaymentJson = paymentApi.getPayment(paymentJson.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
+ verifyInvoicePaymentAgainstPayment(paymentJson, retrievedPaymentJson);
}
-
@Test(groups = "slow")
public void testInvoicePaymentCompletion() throws Exception {
mockPaymentProviderPlugin.makeNextPaymentPending();
final InvoicePayment paymentJson = setupScenarioWithPayment();
- final Payment retrievedPaymentJson = killBillClient.getPayment(paymentJson.getPaymentId(), false, requestOptions);
- Assert.assertTrue(retrievedPaymentJson.equals((Payment) paymentJson));
+ final Payment retrievedPaymentJson = paymentApi.getPayment(paymentJson.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
+ verifyInvoicePaymentAgainstPayment(paymentJson, retrievedPaymentJson);
Assert.assertEquals(retrievedPaymentJson.getTransactions().size(), 1);
- Assert.assertEquals(retrievedPaymentJson.getTransactions().get(0).getStatus(), "PENDING");
+ Assert.assertEquals(retrievedPaymentJson.getTransactions().get(0).getStatus(), TransactionStatus.PENDING);
final PaymentTransaction completeTransactionByPaymentId = new PaymentTransaction();
completeTransactionByPaymentId.setPaymentId(retrievedPaymentJson.getPaymentId());
- final Account accountWithBalance = killBillClient.getAccount(paymentJson.getAccountId(), true, false, requestOptions);
+ final Account accountWithBalance = accountApi.getAccount(paymentJson.getAccountId(), true, false, AuditLevel.NONE, requestOptions);
Assert.assertTrue(accountWithBalance.getAccountBalance().compareTo(BigDecimal.ZERO) > 0);
- final Payment completedPayment = killBillClient.completeInvoicePayment(completeTransactionByPaymentId, null, ImmutableMap.<String, String>of(), requestOptions);
- Assert.assertEquals(completedPayment.getTransactions().get(0).getStatus(), "SUCCESS");
+ invoicePaymentApi.completeInvoicePaymentTransaction(new PaymentTransaction(), retrievedPaymentJson.getPaymentId(), NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptions);
+ final Payment completedPayment = paymentApi.getPayment(paymentJson.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
+ Assert.assertEquals(completedPayment.getTransactions().get(0).getStatus(), TransactionStatus.SUCCESS);
- final Account accountWithBalance2 = killBillClient.getAccount(paymentJson.getAccountId(), true, false, requestOptions);
+ final Account accountWithBalance2 = accountApi.getAccount(paymentJson.getAccountId(), true, false, AuditLevel.NONE, requestOptions);
Assert.assertEquals(accountWithBalance2.getAccountBalance().compareTo(BigDecimal.ZERO), 0);
}
@@ -118,7 +116,8 @@ public class TestInvoicePayment extends TestJaxrsBase {
final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
refund.setPaymentId(invoicePaymentJson.getPaymentId());
refund.setAmount(refundAmount);
- final Payment paymentAfterRefundJson = killBillClient.createInvoicePaymentRefund(refund, requestOptions);
+ invoicePaymentApi.createRefundWithAdjustments(refund, invoicePaymentJson.getPaymentId(), invoicePaymentJson.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
+ final Payment paymentAfterRefundJson = paymentApi.getPayment(invoicePaymentJson.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
verifyRefund(invoicePaymentJson, paymentAfterRefundJson, refundAmount);
// Verify the invoice balance
@@ -137,7 +136,9 @@ public class TestInvoicePayment extends TestJaxrsBase {
final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
refund.setPaymentId(paymentJson.getPaymentId());
refund.setAmount(refundAmount);
- final Payment paymentAfterRefundJson = killBillClient.createInvoicePaymentRefund(refund, requestOptions);
+
+ invoicePaymentApi.createRefundWithAdjustments(refund, paymentJson.getPaymentId(), paymentJson.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
+ final Payment paymentAfterRefundJson = paymentApi.getPayment(paymentJson.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
verifyRefund(paymentJson, paymentAfterRefundJson, refundAmount);
// Verify the invoice balance
@@ -149,7 +150,7 @@ public class TestInvoicePayment extends TestJaxrsBase {
final InvoicePayment paymentJson = setupScenarioWithPayment();
// Get the individual items for the invoice
- final Invoice invoice = killBillClient.getInvoice(paymentJson.getTargetInvoiceId(), true, false, requestOptions);
+ final Invoice invoice = invoiceApi.getInvoice(paymentJson.getTargetInvoiceId(), true, false, AuditLevel.NONE, requestOptions);
final InvoiceItem itemToAdjust = invoice.getItems().get(0);
// Issue a refund for the full amount
@@ -163,9 +164,11 @@ public class TestInvoicePayment extends TestJaxrsBase {
refund.setIsAdjusted(true);
final InvoiceItem adjustment = new InvoiceItem();
adjustment.setInvoiceItemId(itemToAdjust.getInvoiceItemId());
- /* null amount means full adjustment for that item */
+ //null amount means full adjustment for that item
refund.setAdjustments(ImmutableList.<InvoiceItem>of(adjustment));
- final Payment paymentAfterRefundJson = killBillClient.createInvoicePaymentRefund(refund, requestOptions);
+
+ invoicePaymentApi.createRefundWithAdjustments(refund, paymentJson.getPaymentId(), paymentJson.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
+ final Payment paymentAfterRefundJson = paymentApi.getPayment(paymentJson.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
verifyRefund(paymentJson, paymentAfterRefundJson, refundAmount);
// Verify the invoice balance
@@ -177,7 +180,7 @@ public class TestInvoicePayment extends TestJaxrsBase {
final InvoicePayment paymentJson = setupScenarioWithPayment();
// Get the individual items for the invoice
- final Invoice invoice = killBillClient.getInvoice(paymentJson.getTargetInvoiceId(), true, false, requestOptions);
+ final Invoice invoice = invoiceApi.getInvoice(paymentJson.getTargetInvoiceId(), true, false, AuditLevel.NONE, requestOptions);
final InvoiceItem itemToAdjust = invoice.getItems().get(0);
// Issue a refund for a fraction of the amount
@@ -192,7 +195,9 @@ public class TestInvoicePayment extends TestJaxrsBase {
adjustment.setInvoiceItemId(itemToAdjust.getInvoiceItemId());
adjustment.setAmount(refundAmount);
refund.setAdjustments(ImmutableList.<InvoiceItem>of(adjustment));
- final Payment paymentAfterRefundJson = killBillClient.createInvoicePaymentRefund(refund, requestOptions);
+
+ invoicePaymentApi.createRefundWithAdjustments(refund, paymentJson.getPaymentId(), paymentJson.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
+ final Payment paymentAfterRefundJson = paymentApi.getPayment(paymentJson.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
verifyRefund(paymentJson, paymentAfterRefundJson, refundAmount);
// Verify the invoice balance
@@ -204,7 +209,7 @@ public class TestInvoicePayment extends TestJaxrsBase {
final InvoicePayment paymentJson = setupScenarioWithPayment();
// Get the individual items for the invoice
- final Invoice invoice = killBillClient.getInvoice(paymentJson.getTargetInvoiceId(), true, false, requestOptions);
+ final Invoice invoice = invoiceApi.getInvoice(paymentJson.getTargetInvoiceId(), true, false, AuditLevel.NONE, requestOptions);
final InvoiceItem itemToAdjust = invoice.getItems().get(0);
// Issue a refund for a fraction of the amount
@@ -221,7 +226,9 @@ public class TestInvoicePayment extends TestJaxrsBase {
// Ask for an adjustment for the full amount (bigger than the refund amount)
adjustment.setAmount(itemToAdjust.getAmount());
refund.setAdjustments(ImmutableList.<InvoiceItem>of(adjustment));
- final Payment paymentAfterRefundJson = killBillClient.createInvoicePaymentRefund(refund, requestOptions);
+
+ invoicePaymentApi.createRefundWithAdjustments(refund, paymentJson.getPaymentId(), paymentJson.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
+ final Payment paymentAfterRefundJson = paymentApi.getPayment(paymentJson.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
// The refund did go through
verifyRefund(paymentJson, paymentAfterRefundJson, refundAmount);
@@ -238,27 +245,28 @@ public class TestInvoicePayment extends TestJaxrsBase {
final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
refund.setPaymentId(lastPayment.getPaymentId());
refund.setAmount(lastPayment.getPurchasedAmount());
- killBillClient.createInvoicePaymentRefund(refund, requestOptions);
+
+ invoicePaymentApi.createRefundWithAdjustments(refund, lastPayment.getPaymentId(), lastPayment.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
final InvoicePayment invoicePayment = new InvoicePayment();
invoicePayment.setPurchasedAmount(lastPayment.getPurchasedAmount());
invoicePayment.setAccountId(lastPayment.getAccountId());
invoicePayment.setTargetInvoiceId(lastPayment.getTargetInvoiceId());
- final InvoicePayment payment = killBillClient.createInvoicePayment(invoicePayment, false, requestOptions);
+ final InvoicePayment payment = invoiceApi.createInstantPayment(invoicePayment, lastPayment.getTargetInvoiceId(), NULL_PLUGIN_PROPERTIES, requestOptions);
lastPayment = payment;
}
- final InvoicePayments allPayments = killBillClient.getInvoicePaymentsForAccount(lastPayment.getAccountId(), requestOptions);
+ final InvoicePayments allPayments = accountApi.getInvoicePayments(lastPayment.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
Assert.assertEquals(allPayments.size(), 6);
- final List<PaymentTransaction> objRefundFromJson = getPaymentTransactions(allPayments, TransactionType.REFUND.toString());
+ final List<PaymentTransaction> objRefundFromJson = getInvoicePaymentTransactions(allPayments, TransactionType.REFUND);
Assert.assertEquals(objRefundFromJson.size(), 5);
- Payments paymentsPage = killBillClient.getPayments(0L, 1L, requestOptions);
+ Payments paymentsPage = paymentApi.getPayments(0L, 1L, null, NULL_PLUGIN_PROPERTIES, false, false, AuditLevel.NONE, requestOptions);
for (int i = 0; i < 6; i++) {
Assert.assertNotNull(paymentsPage);
Assert.assertEquals(paymentsPage.size(), 1);
- Assert.assertTrue(paymentsPage.get(0).equals((Payment) allPayments.get(i)));
+ verifyInvoicePaymentAgainstPayment(allPayments.get(i), paymentsPage.get(0));
paymentsPage = paymentsPage.getNext();
}
assertNull(paymentsPage);
@@ -274,29 +282,28 @@ public class TestInvoicePayment extends TestJaxrsBase {
final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
- InvoicePayments invoicePayments = killBillClient.getInvoicePaymentsForAccount(accountJson.getAccountId(), requestOptions);
+ InvoicePayments invoicePayments = accountApi.getInvoicePayments(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
assertEquals(invoicePayments.size(), 1);
final InvoicePayment invoicePayment = invoicePayments.get(0);
// Verify targetInvoiceId is not Null. See #593
assertNotNull(invoicePayment.getTargetInvoiceId());
- final Invoices invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), requestOptions);
+ final Invoices invoices = accountApi.getInvoices(accountJson.getAccountId(), requestOptions);
assertEquals(invoices.size(), 2);
final Invoice invoice = invoices.get(1);
// Verify this is the correct value
assertEquals(invoicePayment.getTargetInvoiceId(), invoice.getInvoiceId());
// Make a payment and verify both invoice payment point to the same targetInvoiceId
- killBillClient.payAllInvoices(accountJson.getAccountId(), false, null, requestOptions);
- invoicePayments = killBillClient.getInvoicePaymentsForAccount(accountJson.getAccountId(), requestOptions);
+ accountApi.payAllInvoices(accountJson.getAccountId(), false, null, NULL_PLUGIN_PROPERTIES, requestOptions);
+ invoicePayments = accountApi.getInvoicePayments(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
assertEquals(invoicePayments.size(), 2);
for (final InvoicePayment cur : invoicePayments) {
assertEquals(cur.getTargetInvoiceId(), invoice.getInvoiceId());
}
}
-
@Test(groups = "slow")
public void testManualInvoicePayment() throws Exception {
@@ -304,19 +311,18 @@ public class TestInvoicePayment extends TestJaxrsBase {
assertNotNull(accountJson);
// Disable automatic payments
- killBillClient.createAccountTag(accountJson.getAccountId(), ControlTagType.AUTO_PAY_OFF.getId(), requestOptions);
+ accountApi.createTags(accountJson.getAccountId(), ImmutableList.<String>of(ControlTagType.AUTO_PAY_OFF.getId().toString()), requestOptions);
// Add a bundle, subscription and move the clock to get the first invoice
- final Subscription subscriptionJson = createEntitlement(accountJson.getAccountId(), UUID.randomUUID().toString(), "Shotgun",
- ProductCategory.BASE, BillingPeriod.MONTHLY, true);
+ final Subscription subscriptionJson = createSubscription(accountJson.getAccountId(), UUID.randomUUID().toString(), "Shotgun",
+ ProductCategory.BASE, BillingPeriod.MONTHLY, true);
assertNotNull(subscriptionJson);
clock.addDays(32);
crappyWaitForLackOfProperSynchonization();
- final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), requestOptions);
+ final List<Invoice> invoices = accountApi.getInvoices(accountJson.getAccountId(), requestOptions);
assertEquals(invoices.size(), 2);
-
final InvoicePayment invoicePayment1 = new InvoicePayment();
invoicePayment1.setPurchasedAmount(invoices.get(1).getBalance().add(BigDecimal.TEN));
invoicePayment1.setAccountId(accountJson.getAccountId());
@@ -324,25 +330,24 @@ public class TestInvoicePayment extends TestJaxrsBase {
// Pay too too much => 400
try {
- killBillClient.createInvoicePayment(invoicePayment1, false, requestOptions);
+ invoiceApi.createInstantPayment(invoicePayment1, invoicePayment1.getTargetInvoiceId(), NULL_PLUGIN_PROPERTIES, requestOptions);
Assert.fail("InvoicePayment call should fail with 400");
} catch (final KillBillClientException e) {
assertTrue(true);
}
-
final InvoicePayment invoicePayment2 = new InvoicePayment();
invoicePayment2.setPurchasedAmount(invoices.get(1).getBalance());
invoicePayment2.setAccountId(accountJson.getAccountId());
invoicePayment2.setTargetInvoiceId(invoices.get(1).getInvoiceId());
// Just right, Yah! => 201
- final InvoicePayment result2 = killBillClient.createInvoicePayment(invoicePayment2, false, requestOptions);
+ final InvoicePayment result2 = invoiceApi.createInstantPayment(invoicePayment2, invoicePayment2.getTargetInvoiceId(), NULL_PLUGIN_PROPERTIES, requestOptions);
assertEquals(result2.getTransactions().size(), 1);
assertTrue(result2.getTransactions().get(0).getAmount().compareTo(invoices.get(1).getBalance()) == 0);
// Already paid -> 204
- final InvoicePayment result3 = killBillClient.createInvoicePayment(invoicePayment2, false, requestOptions);
+ final InvoicePayment result3 = invoiceApi.createInstantPayment(invoicePayment2, invoicePayment2.getTargetInvoiceId(), NULL_PLUGIN_PROPERTIES, requestOptions);
assertNull(result3);
}
@@ -353,39 +358,39 @@ public class TestInvoicePayment extends TestJaxrsBase {
private InvoicePayment setupScenarioWithPayment() throws Exception {
final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
- final List<InvoicePayment> paymentsForAccount = killBillClient.getInvoicePaymentsForAccount(accountJson.getAccountId(), requestOptions);
+ final List<InvoicePayment> paymentsForAccount = accountApi.getInvoicePayments(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
Assert.assertEquals(paymentsForAccount.size(), 1);
final InvoicePayment paymentJson = paymentsForAccount.get(0);
// Check the PaymentMethod from paymentMethodId returned in the Payment object
final UUID paymentMethodId = paymentJson.getPaymentMethodId();
- final PaymentMethod paymentMethodJson = killBillClient.getPaymentMethod(paymentMethodId, true, requestOptions);
+ final PaymentMethod paymentMethodJson = paymentMethodApi.getPaymentMethod(paymentMethodId, NULL_PLUGIN_PROPERTIES, requestOptions);
Assert.assertEquals(paymentMethodJson.getPaymentMethodId(), paymentMethodId);
Assert.assertEquals(paymentMethodJson.getAccountId(), accountJson.getAccountId());
// Verify the refunds
- final List<PaymentTransaction> objRefundFromJson = getPaymentTransactions(paymentsForAccount, TransactionType.REFUND.toString());
+ final List<PaymentTransaction> objRefundFromJson = getInvoicePaymentTransactions(paymentsForAccount, TransactionType.REFUND);
Assert.assertEquals(objRefundFromJson.size(), 0);
return paymentJson;
}
private void verifyRefund(final InvoicePayment paymentJson, final Payment paymentAfterRefund, final BigDecimal refundAmount) throws KillBillClientException {
- final List<PaymentTransaction> transactions = getPaymentTransactions(ImmutableList.of(paymentAfterRefund), TransactionType.REFUND.toString());
+ final List<PaymentTransaction> transactions = getPaymentTransactions(ImmutableList.of(paymentAfterRefund), TransactionType.REFUND);
Assert.assertEquals(transactions.size(), 1);
final PaymentTransaction refund = transactions.get(0);
Assert.assertEquals(refund.getPaymentId(), paymentJson.getPaymentId());
Assert.assertEquals(refund.getAmount().setScale(2, RoundingMode.HALF_UP), refundAmount.setScale(2, RoundingMode.HALF_UP));
Assert.assertEquals(refund.getCurrency(), DEFAULT_CURRENCY);
- Assert.assertEquals(refund.getStatus(), "SUCCESS");
+ Assert.assertEquals(refund.getStatus(), TransactionStatus.SUCCESS);
Assert.assertEquals(refund.getEffectiveDate().getYear(), clock.getUTCNow().getYear());
Assert.assertEquals(refund.getEffectiveDate().getMonthOfYear(), clock.getUTCNow().getMonthOfYear());
Assert.assertEquals(refund.getEffectiveDate().getDayOfMonth(), clock.getUTCNow().getDayOfMonth());
// Verify the refund via the payment API
- final Payment retrievedPaymentJson = killBillClient.getPayment(paymentJson.getPaymentId(), true, requestOptions);
+ final Payment retrievedPaymentJson = paymentApi.getPayment(paymentJson.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
Assert.assertEquals(retrievedPaymentJson.getPaymentId(), paymentJson.getPaymentId());
Assert.assertEquals(retrievedPaymentJson.getPurchasedAmount().setScale(2, RoundingMode.HALF_UP), paymentJson.getPurchasedAmount().setScale(2, RoundingMode.HALF_UP));
Assert.assertEquals(retrievedPaymentJson.getAccountId(), paymentJson.getAccountId());
@@ -394,8 +399,23 @@ public class TestInvoicePayment extends TestJaxrsBase {
}
private void verifyInvoice(final InvoicePayment paymentJson, final BigDecimal expectedInvoiceBalance) throws KillBillClientException {
- final Invoice invoiceJson = killBillClient.getInvoice(paymentJson.getTargetInvoiceId(), requestOptions);
+ final Invoice invoiceJson = invoiceApi.getInvoice(paymentJson.getTargetInvoiceId(), requestOptions);
Assert.assertEquals(invoiceJson.getBalance().setScale(2, BigDecimal.ROUND_HALF_UP),
expectedInvoiceBalance.setScale(2, BigDecimal.ROUND_HALF_UP));
}
+
+ private void verifyInvoicePaymentAgainstPayment(final InvoicePayment ip, final Payment p) {
+ Assert.assertEquals(ip.getAccountId(), p.getAccountId());
+ Assert.assertEquals(ip.getPaymentId(), p.getPaymentId());
+ Assert.assertEquals(ip.getPaymentNumber(), p.getPaymentNumber());
+ Assert.assertEquals(ip.getAccountId(), p.getAccountId());
+ Assert.assertEquals(ip.getAuthAmount(), p.getAuthAmount());
+ Assert.assertEquals(ip.getCapturedAmount(), p.getCapturedAmount());
+ Assert.assertEquals(ip.getPurchasedAmount(), p.getPurchasedAmount());
+ Assert.assertEquals(ip.getRefundedAmount(), p.getRefundedAmount());
+ Assert.assertEquals(ip.getCreditedAmount(), p.getCreditedAmount());
+ Assert.assertEquals(ip.getCurrency(), p.getCurrency());
+ Assert.assertEquals(ip.getPaymentMethodId(), p.getPaymentMethodId());
+ }
+
}
diff --git a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestJaxrsBase.java b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestJaxrsBase.java
index 6d31b0c..fd5f44d 100644
--- a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestJaxrsBase.java
+++ b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestJaxrsBase.java
@@ -27,6 +27,7 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
+import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.Servlet;
@@ -62,6 +63,7 @@ import org.killbill.billing.client.api.gen.TagApi;
import org.killbill.billing.client.api.gen.TagDefinitionApi;
import org.killbill.billing.client.api.gen.TenantApi;
import org.killbill.billing.client.api.gen.UsageApi;
+import org.killbill.billing.client.model.gen.InvoicePayment;
import org.killbill.billing.client.model.gen.Payment;
import org.killbill.billing.client.model.gen.PaymentTransaction;
import org.killbill.billing.client.model.gen.Tenant;
@@ -70,6 +72,7 @@ import org.killbill.billing.jetty.HttpServer;
import org.killbill.billing.jetty.HttpServerConfig;
import org.killbill.billing.lifecycle.glue.BusModule;
import org.killbill.billing.osgi.api.OSGIServiceRegistration;
+import org.killbill.billing.payment.api.TransactionType;
import org.killbill.billing.payment.glue.PaymentModule;
import org.killbill.billing.payment.provider.MockPaymentProviderPluginModule;
import org.killbill.billing.platform.api.KillbillConfigSource;
@@ -338,20 +341,38 @@ public class TestJaxrsBase extends KillbillClient {
}
}
- protected static <T extends Payment> List<PaymentTransaction> getPaymentTransactions(final List<T> payments, final String transactionType) {
- return ImmutableList.copyOf(Iterables.concat(Iterables.transform(payments, new Function<T, Iterable<PaymentTransaction>>() {
+ protected static List<PaymentTransaction> getInvoicePaymentTransactions(final List<InvoicePayment> payments, final TransactionType transactionType) {
+ final Iterable<PaymentTransaction> transform = Iterables.concat(Iterables.transform(payments, new Function<InvoicePayment, Iterable<PaymentTransaction>>() {
@Override
- public Iterable<PaymentTransaction> apply(final T input) {
- return Iterables.filter(input.getTransactions(), new Predicate<PaymentTransaction>() {
- @Override
- public boolean apply(final PaymentTransaction input) {
- return input.getTransactionType().equals(transactionType);
- }
- });
+ public Iterable<PaymentTransaction> apply(final InvoicePayment input) {
+ return input.getTransactions();
}
- })));
+ }));
+ return filterTransactions(transform, transactionType);
}
+
+ protected static List<PaymentTransaction> getPaymentTransactions(final List<Payment> payments, final TransactionType transactionType) {
+ final Iterable<PaymentTransaction> transform = Iterables.concat(Iterables.transform(payments, new Function<Payment, Iterable<PaymentTransaction>>() {
+ @Override
+ public Iterable<PaymentTransaction> apply(final Payment input) {
+ return input.getTransactions();
+ }
+ }));
+ return filterTransactions(transform, transactionType);
+ }
+
+
+ protected static List<PaymentTransaction> filterTransactions(final Iterable<PaymentTransaction> paymentTransaction, final TransactionType transactionType) {
+ return ImmutableList.copyOf(Iterables.filter(paymentTransaction, new Predicate<PaymentTransaction>() {
+ @Override
+ public boolean apply(final PaymentTransaction input) {
+ return input.getTransactionType().equals(transactionType);
+ }
+ }));
+ }
+
+
protected void printThreadDump() {
final StringBuilder dump = new StringBuilder("Thread dump:\n");
final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
diff --git a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestPayment.java b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestPayment.java
index 249d131..196432a 100644
--- a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestPayment.java
+++ b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestPayment.java
@@ -267,7 +267,7 @@ public class TestPayment extends TestJaxrsBase {
.withComment(comment)
.withQueryParams(queryParams).build();
- Payments payments = paymentApi.getPayments(0L, 100L, null, NULL_PLUGIN_PROPERTIES, AuditLevel.NONE, false, true, inputOptions);
+ Payments payments = paymentApi.getPayments(0L, 100L, null, NULL_PLUGIN_PROPERTIES, false, true, AuditLevel.NONE, inputOptions);
Assert.assertNotNull(payments.get(0).getPaymentAttempts());
Assert.assertEquals(payments.get(0).getPaymentAttempts().get(0).getStateName(), "RETRIED");
diff --git a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestUsage.java b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestUsage.java
index 3909fa6..d1cc6fe 100644
--- a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestUsage.java
+++ b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestUsage.java
@@ -19,22 +19,21 @@ package org.killbill.billing.jaxrs;
import java.util.UUID;
-import javax.annotation.Nullable;
-
import org.killbill.billing.ErrorCode;
import org.killbill.billing.catalog.api.BillingPeriod;
import org.killbill.billing.catalog.api.PriceListSet;
import org.killbill.billing.catalog.api.ProductCategory;
import org.killbill.billing.client.KillBillClientException;
-import org.killbill.billing.client.model.Account;
-import org.killbill.billing.client.model.Bundle;
-import org.killbill.billing.client.model.InvoiceItem;
import org.killbill.billing.client.model.Invoices;
-import org.killbill.billing.client.model.RolledUpUsage;
-import org.killbill.billing.client.model.Subscription;
-import org.killbill.billing.client.model.SubscriptionUsageRecord;
-import org.killbill.billing.client.model.UnitUsageRecord;
-import org.killbill.billing.client.model.UsageRecord;
+import org.killbill.billing.client.model.Subscriptions;
+import org.killbill.billing.client.model.gen.Account;
+import org.killbill.billing.client.model.gen.Bundle;
+import org.killbill.billing.client.model.gen.InvoiceItem;
+import org.killbill.billing.client.model.gen.RolledUpUsage;
+import org.killbill.billing.client.model.gen.Subscription;
+import org.killbill.billing.client.model.gen.SubscriptionUsageRecord;
+import org.killbill.billing.client.model.gen.UnitUsageRecord;
+import org.killbill.billing.client.model.gen.UsageRecord;
import org.killbill.billing.invoice.api.InvoiceItemType;
import org.killbill.billing.util.api.AuditLevel;
import org.testng.Assert;
@@ -64,10 +63,15 @@ public class TestUsage extends TestJaxrsBase {
addOn.setBillingPeriod(BillingPeriod.NO_BILLING_PERIOD);
addOn.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
- final Bundle bundle = killBillClient.createSubscriptionWithAddOns(ImmutableList.<Subscription>of(base, addOn),
- null,
- DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC,
- requestOptions);
+ final Subscriptions body = new Subscriptions();
+ body.add(base);
+ body.add(addOn);
+
+ final Bundle bundle = subscriptionApi.createSubscriptionWithAddOns(body,
+ null,
+ null,
+ NULL_PLUGIN_PROPERTIES,
+ requestOptions);
final UUID addOnSubscriptionId = Iterables.<Subscription>find(bundle.getSubscriptions(),
new Predicate<Subscription>() {
@Override
@@ -94,28 +98,28 @@ public class TestUsage extends TestJaxrsBase {
usage.setSubscriptionId(addOnSubscriptionId);
usage.setUnitUsageRecords(ImmutableList.<UnitUsageRecord>of(unitUsageRecord));
- killBillClient.createSubscriptionUsageRecord(usage, requestOptions);
+ usageApi.recordUsage(usage, requestOptions);
- final RolledUpUsage retrievedUsage1 = killBillClient.getRolledUpUsage(addOnSubscriptionId, unitUsageRecord.getUnitType(), clock.getUTCToday().minusDays(1), clock.getUTCToday(), requestOptions);
+ final RolledUpUsage retrievedUsage1 = usageApi.getUsage(addOnSubscriptionId, unitUsageRecord.getUnitType(), clock.getUTCToday().minusDays(1), clock.getUTCToday(), requestOptions);
Assert.assertEquals(retrievedUsage1.getSubscriptionId(), usage.getSubscriptionId());
Assert.assertEquals(retrievedUsage1.getRolledUpUnits().size(), 1);
Assert.assertEquals(retrievedUsage1.getRolledUpUnits().get(0).getUnitType(), unitUsageRecord.getUnitType());
// endDate is excluded
Assert.assertEquals((long) retrievedUsage1.getRolledUpUnits().get(0).getAmount(), 10);
- final RolledUpUsage retrievedUsage2 = killBillClient.getRolledUpUsage(addOnSubscriptionId, unitUsageRecord.getUnitType(), clock.getUTCToday().minusDays(1), clock.getUTCToday().plusDays(1), requestOptions);
+ final RolledUpUsage retrievedUsage2 = usageApi.getUsage(addOnSubscriptionId, unitUsageRecord.getUnitType(), clock.getUTCToday().minusDays(1), clock.getUTCToday().plusDays(1), requestOptions);
Assert.assertEquals(retrievedUsage2.getSubscriptionId(), usage.getSubscriptionId());
Assert.assertEquals(retrievedUsage2.getRolledUpUnits().size(), 1);
Assert.assertEquals(retrievedUsage2.getRolledUpUnits().get(0).getUnitType(), unitUsageRecord.getUnitType());
Assert.assertEquals((long) retrievedUsage2.getRolledUpUnits().get(0).getAmount(), 15);
- final RolledUpUsage retrievedUsage3 = killBillClient.getRolledUpUsage(addOnSubscriptionId, unitUsageRecord.getUnitType(), clock.getUTCToday(), clock.getUTCToday().plusDays(1), requestOptions);
+ final RolledUpUsage retrievedUsage3 = usageApi.getUsage(addOnSubscriptionId, unitUsageRecord.getUnitType(), clock.getUTCToday(), clock.getUTCToday().plusDays(1), requestOptions);
Assert.assertEquals(retrievedUsage3.getSubscriptionId(), usage.getSubscriptionId());
Assert.assertEquals(retrievedUsage3.getRolledUpUnits().size(), 1);
Assert.assertEquals(retrievedUsage3.getRolledUpUnits().get(0).getUnitType(), unitUsageRecord.getUnitType());
Assert.assertEquals((long) retrievedUsage3.getRolledUpUnits().get(0).getAmount(), 5);
- final RolledUpUsage retrievedUsage4 = killBillClient.getRolledUpUsage(addOnSubscriptionId, null, clock.getUTCToday(), clock.getUTCToday().plusDays(1), requestOptions);
+ final RolledUpUsage retrievedUsage4 = usageApi.getAllUsage(addOnSubscriptionId, clock.getUTCToday(), clock.getUTCToday().plusDays(1), requestOptions);
Assert.assertEquals(retrievedUsage4.getSubscriptionId(), usage.getSubscriptionId());
Assert.assertEquals(retrievedUsage4.getRolledUpUnits().size(), 1);
Assert.assertEquals(retrievedUsage4.getRolledUpUnits().get(0).getUnitType(), "bullets");
@@ -124,14 +128,13 @@ public class TestUsage extends TestJaxrsBase {
clock.addMonths(1);
crappyWaitForLackOfProperSynchonization();
-
- final Invoices invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), true, false, false, false, AuditLevel.MINIMAL, requestOptions);
+ final Invoices invoices = accountApi.getInvoices(accountJson.getAccountId(), true, false, false, false, AuditLevel.MINIMAL, requestOptions);
Assert.assertEquals(invoices.size(), 2);
- final InvoiceItem usageItem = Iterables.tryFind(invoices.get(1).getItems(), new Predicate<InvoiceItem>() {
+ final InvoiceItem usageItem = Iterables.tryFind(invoices.get(1).getItems(), new Predicate<InvoiceItem>() {
@Override
public boolean apply(final InvoiceItem input) {
- return InvoiceItemType.valueOf(input.getItemType()) == InvoiceItemType.USAGE;
+ return input.getItemType() == InvoiceItemType.USAGE;
}
}).orNull();
Assert.assertNotNull(usageItem);
@@ -160,9 +163,14 @@ public class TestUsage extends TestJaxrsBase {
addOn.setBillingPeriod(BillingPeriod.NO_BILLING_PERIOD);
addOn.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
- final Bundle bundle = killBillClient.createSubscriptionWithAddOns(ImmutableList.<Subscription>of(base, addOn),
- null,
- DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, requestOptions);
+ final Subscriptions body = new Subscriptions();
+ body.add(base);
+ body.add(addOn);
+
+ final Bundle bundle = subscriptionApi.createSubscriptionWithAddOns(body,
+ null,
+ null,
+ NULL_PLUGIN_PROPERTIES, requestOptions);
final UUID addOnSubscriptionId = Iterables.<Subscription>find(bundle.getSubscriptions(),
new Predicate<Subscription>() {
@Override
@@ -184,13 +192,12 @@ public class TestUsage extends TestJaxrsBase {
usage.setTrackingId(UUID.randomUUID().toString());
usage.setUnitUsageRecords(ImmutableList.<UnitUsageRecord>of(unitUsageRecord));
- killBillClient.createSubscriptionUsageRecord(usage, requestOptions);
+ usageApi.recordUsage(usage, requestOptions);
try {
- killBillClient.createSubscriptionUsageRecord(usage, requestOptions );
+ usageApi.recordUsage(usage, requestOptions);
Assert.fail();
- }
- catch (final KillBillClientException e) {
+ } catch (final KillBillClientException e) {
Assert.assertEquals(e.getBillingException().getCode(), (Integer) ErrorCode.USAGE_RECORD_TRACKING_ID_ALREADY_EXISTS.getCode());
}