Skip to content

Commit

Permalink
server: trivial fixed in TestPaymentMethod
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
  • Loading branch information
pierre committed Nov 2, 2015
1 parent 6fa2af8 commit 9697006
Showing 1 changed file with 46 additions and 62 deletions.
@@ -1,7 +1,7 @@
/*
* Copyright 2010-2013 Ning, Inc.
* Copyright 2014 Groupon, Inc
* Copyright 2014 The Billing Project, LLC
* Copyright 2014-2015 Groupon, Inc
* Copyright 2014-2015 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
Expand All @@ -19,12 +19,11 @@
package org.killbill.billing.jaxrs;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.UUID;

import org.killbill.billing.ObjectType;
import org.killbill.billing.client.KillBillClientException;
import org.killbill.billing.client.model.Account;
import org.killbill.billing.client.model.CustomField;
import org.killbill.billing.client.model.CustomFields;
Expand All @@ -35,8 +34,6 @@
import org.testng.Assert;
import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;

public class TestPaymentMethod extends TestJaxrsBase {

@Test(groups = "slow", description = "Create/retrieve by externalKey")
Expand All @@ -47,7 +44,7 @@ public void testGePaymentMethodsByKey() throws Exception {
final PaymentMethod paymentMethodJson1 = killBillClient.getPaymentMethodByKey("foo", true);

final PaymentMethod paymentMethodJson2 = killBillClient.getPaymentMethod(accountJson.getPaymentMethodId(), true);
assertEquals(paymentMethodJson1, paymentMethodJson2);
Assert.assertEquals(paymentMethodJson1, paymentMethodJson2);

final PaymentMethod paymentMethodJson3 = killBillClient.getPaymentMethodByKey("doesnotexist", true);
Assert.assertNull(paymentMethodJson3);
Expand All @@ -56,8 +53,8 @@ public void testGePaymentMethodsByKey() throws Exception {
@Test(groups = "slow", description = "Can search payment methods")
public void testSearchPaymentMethods() throws Exception {
// Search random key
assertEquals(killBillClient.searchPaymentMethodsByKey(UUID.randomUUID().toString()).size(), 0);
assertEquals(killBillClient.searchPaymentMethodsByKeyAndPlugin(UUID.randomUUID().toString(), PLUGIN_NAME).size(), 0);
Assert.assertEquals(killBillClient.searchPaymentMethodsByKey(UUID.randomUUID().toString()).size(), 0);
Assert.assertEquals(killBillClient.searchPaymentMethodsByKeyAndPlugin(UUID.randomUUID().toString(), PLUGIN_NAME).size(), 0);

// Create a payment method
final List<PluginProperty> pmProperties = new ArrayList<PluginProperty>();
Expand All @@ -71,8 +68,8 @@ public void testSearchPaymentMethods() throws Exception {
final PaymentMethod paymentMethodJson = killBillClient.getPaymentMethod(accountJson.getPaymentMethodId(), true);

// Search random key again
assertEquals(killBillClient.searchPaymentMethodsByKey(UUID.randomUUID().toString()).size(), 0);
assertEquals(killBillClient.searchPaymentMethodsByKeyAndPlugin(UUID.randomUUID().toString(), PLUGIN_NAME).size(), 0);
Assert.assertEquals(killBillClient.searchPaymentMethodsByKey(UUID.randomUUID().toString()).size(), 0);
Assert.assertEquals(killBillClient.searchPaymentMethodsByKeyAndPlugin(UUID.randomUUID().toString(), PLUGIN_NAME).size(), 0);

// Last 4
doSearch("4365", paymentMethodJson);
Expand All @@ -93,73 +90,60 @@ public void testPaymentMethodsPagination() throws Exception {
}

final PaymentMethods allPaymentMethods = killBillClient.getPaymentMethods();
assertEquals(allPaymentMethods.size(), 5);
Assert.assertEquals(allPaymentMethods.size(), 5);

PaymentMethods page = killBillClient.getPaymentMethods(0L, 1L);
for (int i = 0; i < 5; i++) {
Assert.assertNotNull(page);
assertEquals(page.size(), 1);
assertEquals(page.get(0), allPaymentMethods.get(i));
Assert.assertEquals(page.size(), 1);
Assert.assertEquals(page.get(0), allPaymentMethods.get(i));
page = page.getNext();
}
Assert.assertNull(page);
}

@Test(groups = "slow", description = "Can create, retrieve and delete custom fields")
public void testPaymentMethodCustomFields() throws Exception {
Account account = createAccountWithDefaultPaymentMethod();
UUID paymentMethodId = account.getPaymentMethodId();

// create custom field
CustomField customField = createCustomFieldJson(paymentMethodId, ObjectType.PAYMENT_METHOD, "testKey", "testValue");
CustomFields createdCustomFields = killBillClient.createPaymentMethodCustomField(paymentMethodId,customField, createdBy, reason, comment);
assertEquals(createdCustomFields.size(), 1);
CustomField createdCustomField = createdCustomFields.get(0);
assertEquals(createdCustomField.getName(), "testKey");
assertEquals(createdCustomField.getValue(), "testValue");
assertEquals(createdCustomField.getObjectId(), paymentMethodId);
assertEquals(createdCustomField.getObjectType(), ObjectType.PAYMENT_METHOD);

// retrieve custom field
CustomFields retrievedCustomFields = killBillClient.getPaymentMethodCustomFields(paymentMethodId, AuditLevel.NONE);
assertEquals(retrievedCustomFields.size(), 1);
CustomField retrievedCustomField = retrievedCustomFields.get(0);
assertEquals(retrievedCustomField.getName(), "testKey");
assertEquals(retrievedCustomField.getValue(), "testValue");
assertEquals(retrievedCustomField.getObjectId(), paymentMethodId);
assertEquals(retrievedCustomField.getObjectType(), ObjectType.PAYMENT_METHOD);

// delete custom field
killBillClient.deletePaymentMethodCustomFields(paymentMethodId, Arrays.asList(createdCustomField.getCustomFieldId()), createdBy, reason, comment);
CustomFields deletedCustomFields = killBillClient.getPaymentMethodCustomFields(paymentMethodId, AuditLevel.NONE);
assertEquals(deletedCustomFields.size(), 0);
}

private CustomField createCustomFieldJson(final UUID objectId, final ObjectType objectType, final String name, final String value) {
return new CustomField() {
{
setObjectId(objectId);
setObjectType(objectType);
setName(name);
setValue(value);
}
};
}

private CustomField createCustomField(final UUID paymentMethodId, final String name, final String value) throws KillBillClientException {
CustomField customField = createCustomFieldJson(paymentMethodId, ObjectType.PAYMENT_METHOD, name, value);
CustomFields customFields = killBillClient.createPaymentMethodCustomField(paymentMethodId,customField, createdBy, reason, comment);
assertEquals(customFields.size(), 1);
return customFields.get(0);
final Account account = createAccountWithDefaultPaymentMethod();
final UUID paymentMethodId = account.getPaymentMethodId();

final CustomField customField = new CustomField();
customField.setObjectId(paymentMethodId);
customField.setObjectType(ObjectType.PAYMENT_METHOD);
customField.setName("testKey");
customField.setValue("testValue");

// Create custom field
final CustomFields createdCustomFields = killBillClient.createPaymentMethodCustomField(paymentMethodId, customField, createdBy, reason, comment);
Assert.assertEquals(createdCustomFields.size(), 1);
final CustomField createdCustomField = createdCustomFields.get(0);
Assert.assertEquals(createdCustomField.getName(), "testKey");
Assert.assertEquals(createdCustomField.getValue(), "testValue");
Assert.assertEquals(createdCustomField.getObjectId(), paymentMethodId);
Assert.assertEquals(createdCustomField.getObjectType(), ObjectType.PAYMENT_METHOD);

// Retrieve custom field
final CustomFields retrievedCustomFields = killBillClient.getPaymentMethodCustomFields(paymentMethodId, AuditLevel.NONE);
Assert.assertEquals(retrievedCustomFields.size(), 1);
final CustomField retrievedCustomField = retrievedCustomFields.get(0);
Assert.assertEquals(retrievedCustomField.getName(), "testKey");
Assert.assertEquals(retrievedCustomField.getValue(), "testValue");
Assert.assertEquals(retrievedCustomField.getObjectId(), paymentMethodId);
Assert.assertEquals(retrievedCustomField.getObjectType(), ObjectType.PAYMENT_METHOD);

// Delete custom field
killBillClient.deletePaymentMethodCustomFields(paymentMethodId, Collections.<UUID>singletonList(createdCustomField.getCustomFieldId()), createdBy, reason, comment);
final CustomFields deletedCustomFields = killBillClient.getPaymentMethodCustomFields(paymentMethodId, AuditLevel.NONE);
Assert.assertEquals(deletedCustomFields.size(), 0);
}

private void doSearch(final String searchKey, final PaymentMethod paymentMethodJson) throws Exception {
final List<PaymentMethod> results1 = killBillClient.searchPaymentMethodsByKey(searchKey, true);
assertEquals(results1.size(), 1);
assertEquals(results1.get(0), paymentMethodJson);
Assert.assertEquals(results1.size(), 1);
Assert.assertEquals(results1.get(0), paymentMethodJson);

final List<PaymentMethod> results2 = killBillClient.searchPaymentMethodsByKeyAndPlugin(searchKey, PLUGIN_NAME);
assertEquals(results2.size(), 1);
assertEquals(results2.get(0), paymentMethodJson);
Assert.assertEquals(results2.size(), 1);
Assert.assertEquals(results2.get(0), paymentMethodJson);
}
}

0 comments on commit 9697006

Please sign in to comment.