Add billing account map to Registrar entity

A CurrencyUnit-to-BillingAccountEntry map is persisted in the Registrar entity. It provides flexibility for billing systems that assign different account ids for accounts under different currencies of the same registrar.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=151022753
This commit is contained in:
jianglai 2017-03-23 10:42:05 -07:00 committed by Ben McIlwain
parent ab9b7c613d
commit d7e2009ddf
8 changed files with 225 additions and 39 deletions

View file

@ -18,8 +18,11 @@ import static com.google.common.truth.Truth.assertThat;
import com.google.common.collect.ImmutableMap;
import google.registry.testing.ExceptionRule;
import google.registry.tools.params.KeyValueMapParameter.CurrencyUnitToStringMap;
import google.registry.tools.params.KeyValueMapParameter.StringToIntegerMap;
import google.registry.tools.params.KeyValueMapParameter.StringToStringMap;
import org.joda.money.CurrencyUnit;
import org.joda.money.IllegalCurrencyException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -34,6 +37,7 @@ public class KeyValueMapParameterTest {
private final StringToStringMap stringToStringInstance = new StringToStringMap();
private final StringToIntegerMap stringToIntegerInstance = new StringToIntegerMap();
private final CurrencyUnitToStringMap currencyUnitToStringMap = new CurrencyUnitToStringMap();
@Test
public void testSuccess_convertStringToString_singleEntry() throws Exception {
@ -47,6 +51,12 @@ public class KeyValueMapParameterTest {
.isEqualTo(ImmutableMap.of("key", 1));
}
@Test
public void testSuccess_convertCurrencyUnitToString_singleEntry() throws Exception {
assertThat(currencyUnitToStringMap.convert("USD=123abc"))
.isEqualTo(ImmutableMap.of(CurrencyUnit.USD, "123abc"));
}
@Test
public void testSuccess_convertStringToString() throws Exception {
assertThat(stringToStringInstance.convert("key=foo,key2=bar"))
@ -59,6 +69,12 @@ public class KeyValueMapParameterTest {
.isEqualTo(ImmutableMap.of("key", 1, "key2", 2));
}
@Test
public void testSuccess_convertCurrencyUnitToString() throws Exception {
assertThat(currencyUnitToStringMap.convert("USD=123abc,JPY=xyz789"))
.isEqualTo(ImmutableMap.of(CurrencyUnit.USD, "123abc", CurrencyUnit.JPY, "xyz789"));
}
@Test
public void testSuccess_convertStringToString_empty() throws Exception {
assertThat(stringToStringInstance.convert("")).isEmpty();
@ -69,12 +85,23 @@ public class KeyValueMapParameterTest {
assertThat(stringToIntegerInstance.convert("")).isEmpty();
}
@Test
public void testSuccess_convertCurrencyUnitToString_empty() throws Exception {
assertThat(currencyUnitToStringMap.convert("")).isEmpty();
}
@Test
public void testFailure_convertStringToInteger_badType() throws Exception {
thrown.expect(NumberFormatException.class);
stringToIntegerInstance.convert("key=1,key2=foo");
}
@Test
public void testFailure_convertCurrencyUnitToString_badType() throws Exception {
thrown.expect(IllegalCurrencyException.class, "XYZ");
currencyUnitToStringMap.convert("USD=123abc,XYZ=xyz789");
}
@Test
public void testFailure_convertStringToString_badSeparator() throws Exception {
thrown.expect(IllegalArgumentException.class);
@ -87,6 +114,12 @@ public class KeyValueMapParameterTest {
stringToIntegerInstance.convert("key=1&key2=2");
}
@Test
public void testFailure_convertCurrencyUnitToString_badSeparator() throws Exception {
thrown.expect(IllegalArgumentException.class);
currencyUnitToStringMap.convert("USD=123abc&JPY=xyz789");
}
@Test
public void testFailure_convertStringToString_badFormat() throws Exception {
thrown.expect(IllegalArgumentException.class);
@ -98,4 +131,11 @@ public class KeyValueMapParameterTest {
thrown.expect(IllegalArgumentException.class);
stringToIntegerInstance.convert("foo");
}
@Test
public void testFailure_convertCurrencyUnitToString_badFormat() throws Exception {
thrown.expect(IllegalArgumentException.class);
currencyUnitToStringMap.convert("foo");
}
}