Java Code Examples for org.joda.money.Money

The following are top voted examples for showing how to use org.joda.money.Money. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: nomulus   File: DomainApplicationCreateFlowTest.java   View source code 6 votes vote down vote up
@Test
public void testFailure_wrongCurrency_v12() throws Exception {
  createTld("tld", TldState.LANDRUSH);
  setEppInput("domain_create_landrush_fee.xml", ImmutableMap.of("FEE_VERSION", "0.12"));
  persistResource(
      Registry.get("tld")
          .asBuilder()
          .setCurrency(CurrencyUnit.EUR)
          .setCreateBillingCost(Money.of(EUR, 13))
          .setRestoreBillingCost(Money.of(EUR, 11))
          .setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 7)))
          .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
          .setServerStatusChangeBillingCost(Money.of(EUR, 19))
          .build());
  persistContactsAndHosts();
  clock.advanceOneMilli();
  EppException thrown = expectThrows(CurrencyUnitMismatchException.class, this::runFlow);
  assertAboutEppExceptions().that(thrown).marshalsToXml();
}
 
Example 2
Project: nomulus   File: DomainCreateFlowTest.java   View source code 6 votes vote down vote up
@Test
public void testSuccess_eapFeeApplied_v06() throws Exception {
  setEppInput("domain_create_eap_fee.xml", ImmutableMap.of("FEE_VERSION", "0.6"));
  persistContactsAndHosts();
  persistResource(
      Registry.get("tld")
          .asBuilder()
          .setEapFeeSchedule(
              ImmutableSortedMap.of(
                  START_OF_TIME,
                  Money.of(USD, 0),
                  clock.nowUtc().minusDays(1),
                  Money.of(USD, 100),
                  clock.nowUtc().plusDays(1),
                  Money.of(USD, 0)))
          .build());
  doSuccessfulTest(
      "tld", "domain_create_response_eap_fee.xml", ImmutableMap.of("FEE_VERSION", "0.6"));
}
 
Example 3
Project: nomulus   File: DomainCreateFlowTest.java   View source code 6 votes vote down vote up
@Test
public void testSuccess_eapFeeApplied_v11() throws Exception {
  setEppInput("domain_create_eap_fee.xml", ImmutableMap.of("FEE_VERSION", "0.11"));
  persistContactsAndHosts();
  persistResource(
      Registry.get("tld")
          .asBuilder()
          .setEapFeeSchedule(
              ImmutableSortedMap.of(
                  START_OF_TIME,
                  Money.of(USD, 0),
                  clock.nowUtc().minusDays(1),
                  Money.of(USD, 100),
                  clock.nowUtc().plusDays(1),
                  Money.of(USD, 0)))
          .build());
  doSuccessfulTest(
      "tld", "domain_create_response_eap_fee.xml", ImmutableMap.of("FEE_VERSION", "0.11"));
}
 
Example 4
Project: nomulus   File: RegistrarBillingEntryTest.java   View source code 6 votes vote down vote up
@Test
public void testBadTimeOrdering_causesError() throws Exception {
  IllegalStateException thrown =
      expectThrows(
          IllegalStateException.class,
          () ->
              new RegistrarBillingEntry.Builder()
                  .setPrevious(
                      new RegistrarBillingEntry.Builder()
                          .setPrevious(null)
                          .setParent(loadRegistrar("NewRegistrar"))
                          .setCreated(DateTime.parse("1984-12-18TZ"))
                          .setDescription("USD Invoice for December")
                          .setAmount(Money.parse("USD 10.00"))
                          .build())
                  .setParent(loadRegistrar("NewRegistrar"))
                  .setCreated(DateTime.parse("1984-12-17TZ"))
                  .setTransactionId("goblin")
                  .setDescription("USD Invoice for August")
                  .setAmount(Money.parse("USD 3.50"))
                  .build());
  assertThat(thrown).hasMessageThat().contains("Created timestamp not after previous");
}
 
Example 5
Project: nomulus   File: DomainCreateFlowTest.java   View source code 6 votes vote down vote up
@Test
public void testFailure_wrongCurrency_v06() throws Exception {
  setEppInput("domain_create_fee.xml", ImmutableMap.of("FEE_VERSION", "0.6"));
  persistResource(
      Registry.get("tld")
          .asBuilder()
          .setCurrency(CurrencyUnit.EUR)
          .setCreateBillingCost(Money.of(EUR, 13))
          .setRestoreBillingCost(Money.of(EUR, 11))
          .setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 7)))
          .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
          .setServerStatusChangeBillingCost(Money.of(EUR, 19))
          .build());
  persistContactsAndHosts();
  EppException thrown = expectThrows(CurrencyUnitMismatchException.class, this::runFlow);
  assertAboutEppExceptions().that(thrown).marshalsToXml();
}
 
Example 6
Project: nomulus   File: PremiumList.java   View source code 6 votes vote down vote up
@Override
@Nullable
PremiumListEntry createFromLine(String originalLine) {
  List<String> lineAndComment = splitOnComment(originalLine);
  if (lineAndComment.isEmpty()) {
    return null;
  }
  String line = lineAndComment.get(0);
  String comment = lineAndComment.get(1);
  List<String> parts = Splitter.on(',').trimResults().splitToList(line);
  checkArgument(parts.size() == 2, "Could not parse line in premium list: %s", originalLine);
  return new PremiumListEntry.Builder()
      .setLabel(parts.get(0))
      .setPrice(Money.parse(parts.get(1)))
      .setComment(comment)
      .build();
}
 
Example 7
Project: nomulus   File: PremiumListUtilsTest.java   View source code 6 votes vote down vote up
@Test
public void testGetPremiumPrice_cachedSecondTime() throws Exception {
  assertThat(getPremiumPrice("rich", Registry.get("tld"))).hasValue(Money.parse("USD 1999"));
  assertThat(getPremiumPrice("rich", Registry.get("tld"))).hasValue(Money.parse("USD 1999"));
  assertThat(premiumListChecks)
      .hasValueForLabels(1, "tld", "tld", UNCACHED_POSITIVE.toString())
      .and()
      .hasValueForLabels(1, "tld", "tld", CACHED_POSITIVE.toString())
      .and()
      .hasNoOtherValues();
  assertThat(premiumListProcessingTime)
      .hasAnyValueForLabels("tld", "tld", UNCACHED_POSITIVE.toString())
      .and()
      .hasAnyValueForLabels("tld", "tld", CACHED_POSITIVE.toString())
      .and()
      .hasNoOtherValues();
}
 
Example 8
Project: nomulus   File: DomainCreateFlowTest.java   View source code 6 votes vote down vote up
@Test
public void testSuccess_eapFee_beforeEntireSchedule() throws Exception {
  persistContactsAndHosts();
  persistResource(
      Registry.get("tld")
          .asBuilder()
          .setEapFeeSchedule(
              ImmutableSortedMap.of(
                  START_OF_TIME,
                  Money.of(USD, 0),
                  clock.nowUtc().plusDays(1),
                  Money.of(USD, 10),
                  clock.nowUtc().plusDays(2),
                  Money.of(USD, 0)))
          .build());
  doSuccessfulTest("tld", "domain_create_response.xml");
}
 
Example 9
Project: nomulus   File: UpdateRegistrarCommandTest.java   View source code 6 votes vote down vote up
@Test
public void testFailure_changeBillingMethodWhenBalanceIsNonZero() throws Exception {
  createTlds("xn--q9jyb4c");
  Registrar registrar = loadRegistrar("NewRegistrar");
  persistResource(
      new RegistrarBillingEntry.Builder()
          .setPrevious(null)
          .setParent(registrar)
          .setCreated(DateTime.parse("1984-12-18TZ"))
          .setDescription("USD Invoice for December")
          .setAmount(Money.parse("USD 10.00"))
          .build());
  assertThat(registrar.getBillingMethod()).isEqualTo(BillingMethod.EXTERNAL);
  IllegalStateException thrown =
      expectThrows(
          IllegalStateException.class,
          () -> runCommand("--billing_method=braintree", "--force", "NewRegistrar"));
  assertThat(thrown)
      .hasMessageThat()
      .isEqualTo(
          "Refusing to change billing method on Registrar 'NewRegistrar' from EXTERNAL to "
              + "BRAINTREE because current balance is non-zero: {USD=USD 10.00}");
}
 
Example 10
Project: nomulus   File: DomainRestoreRequestFlowTest.java   View source code 6 votes vote down vote up
private void runWrongCurrencyTest(Map<String, String> substitutions) throws Exception {
  setEppInput("domain_update_restore_request_fee.xml", substitutions);
  persistPendingDeleteDomain();
  persistResource(
      Registry.get("tld")
          .asBuilder()
          .setCurrency(EUR)
          .setCreateBillingCost(Money.of(EUR, 13))
          .setRestoreBillingCost(Money.of(EUR, 11))
          .setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 7)))
          .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
          .setServerStatusChangeBillingCost(Money.of(EUR, 19))
          .build());
  EppException thrown = expectThrows(CurrencyUnitMismatchException.class, this::runFlow);
  assertAboutEppExceptions().that(thrown).marshalsToXml();
}
 
Example 11
Project: nomulus   File: UpdateTldCommandTest.java   View source code 6 votes vote down vote up
@Test
public void testSuccess_nonUsdBillingCostFlag() throws Exception {
  persistResource(
      Registry.get("xn--q9jyb4c")
          .asBuilder()
          .setCurrency(JPY)
          .setCreateBillingCost(Money.ofMajor(JPY, 1))
          .setRestoreBillingCost(Money.ofMajor(JPY, 1))
          .setRenewBillingCostTransitions(
              ImmutableSortedMap.of(START_OF_TIME, Money.ofMajor(JPY, 1)))
          .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(JPY)))
          .setServerStatusChangeBillingCost(Money.ofMajor(JPY, 1))
          .build());
  runCommandForced(
      "--create_billing_cost=\"JPY 12345\"",
      "--restore_billing_cost=\"JPY 67890\"",
      "--renew_billing_cost_transitions=\"0=JPY 101112\"",
      "--server_status_change_cost=\"JPY 97865\"",
      "xn--q9jyb4c");
  assertThat(Registry.get("xn--q9jyb4c").getStandardCreateCost())
      .isEqualTo(Money.ofMajor(JPY, 12345));
  assertThat(Registry.get("xn--q9jyb4c").getStandardRestoreCost())
      .isEqualTo(Money.ofMajor(JPY, 67890));
  assertThat(Registry.get("xn--q9jyb4c").getStandardRenewCost(START_OF_TIME))
      .isEqualTo(Money.ofMajor(JPY, 101112));
}
 
Example 12
Project: nomulus   File: DomainDeleteFlowTest.java   View source code 6 votes vote down vote up
@Test
public void testSuccess_autoRenewGracePeriod_priceChanges_v11() throws Exception {
  removeServiceExtensionUri(ServiceExtension.FEE_0_12.getUri());
  persistResource(
      Registry.get("tld")
          .asBuilder()
          .setRenewBillingCostTransitions(
              ImmutableSortedMap.of(
                  START_OF_TIME,
                  Money.of(USD, 11),
                  TIME_BEFORE_FLOW.minusDays(5),
                  Money.of(USD, 20)))
          .build());
  setUpAutorenewGracePeriod();
  clock.advanceOneMilli();
  runFlowAssertResponse(loadFile("domain_delete_response_autorenew_fee.xml", FEE_11_MAP));
}
 
Example 13
Project: nomulus   File: DomainRenewFlowTest.java   View source code 6 votes vote down vote up
@Test
public void testFailure_wrongCurrency_v06() throws Exception {
  setEppInput("domain_renew_fee.xml", FEE_06_MAP);
  persistResource(
      Registry.get("tld")
          .asBuilder()
          .setCurrency(EUR)
          .setCreateBillingCost(Money.of(EUR, 13))
          .setRestoreBillingCost(Money.of(EUR, 11))
          .setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 7)))
          .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
          .setServerStatusChangeBillingCost(Money.of(EUR, 19))
          .build());
  persistDomain();
  EppException thrown = expectThrows(CurrencyUnitMismatchException.class, this::runFlow);
  assertAboutEppExceptions().that(thrown).marshalsToXml();
}
 
Example 14
Project: nomulus   File: DomainRenewFlowTest.java   View source code 6 votes vote down vote up
@Test
public void testFailure_wrongCurrency_v12() throws Exception {
  setEppInput("domain_renew_fee.xml", FEE_12_MAP);
  persistResource(
      Registry.get("tld")
          .asBuilder()
          .setCurrency(EUR)
          .setCreateBillingCost(Money.of(EUR, 13))
          .setRestoreBillingCost(Money.of(EUR, 11))
          .setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 7)))
          .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
          .setServerStatusChangeBillingCost(Money.of(EUR, 19))
          .build());
  persistDomain();
  EppException thrown = expectThrows(CurrencyUnitMismatchException.class, this::runFlow);
  assertAboutEppExceptions().that(thrown).marshalsToXml();
}
 
Example 15
Project: nomulus   File: DomainCreateFlowTest.java   View source code 6 votes vote down vote up
@Test
public void testFailure_wrongCurrency_v12() throws Exception {
  setEppInput("domain_create_fee.xml", ImmutableMap.of("FEE_VERSION", "0.12"));
  persistResource(
      Registry.get("tld")
          .asBuilder()
          .setCurrency(CurrencyUnit.EUR)
          .setCreateBillingCost(Money.of(EUR, 13))
          .setRestoreBillingCost(Money.of(EUR, 11))
          .setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 7)))
          .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
          .setServerStatusChangeBillingCost(Money.of(EUR, 19))
          .build());
  persistContactsAndHosts();
  EppException thrown = expectThrows(CurrencyUnitMismatchException.class, this::runFlow);
  assertAboutEppExceptions().that(thrown).marshalsToXml();
}
 
Example 16
Project: nomulus   File: DomainPricingLogic.java   View source code 6 votes vote down vote up
/** Returns a new update price for the pricer. */
public FeesAndCredits getUpdatePrice(Registry registry, String domainName, DateTime date)
    throws EppException {
  CurrencyUnit currency = registry.getCurrency();
  BaseFee feeOrCredit =
      Fee.create(Money.zero(registry.getCurrency()).getAmount(), FeeType.UPDATE);
  return customLogic.customizeUpdatePrice(
      UpdatePriceParameters.newBuilder()
          .setFeesAndCredits(
              new FeesAndCredits.Builder()
                  .setCurrency(currency)
                  .addFeeOrCredit(feeOrCredit)
                  .build())
          .setRegistry(registry)
          .setDomainName(InternetDomainName.from(domainName))
          .setAsOfDate(date)
          .build());
}
 
Example 17
Project: nomulus   File: UpdateTldCommandTest.java   View source code 6 votes vote down vote up
@Test
public void testSuccess_renewBillingCostTransitions() throws Exception {
  DateTime later = now.plusMonths(1);
  runCommandForced(
      String.format(
          "--renew_billing_cost_transitions=\"%s=USD 1,%s=USD 2.00,%s=USD 100\"",
          START_OF_TIME,
          now,
          later),
      "xn--q9jyb4c");

  Registry registry = Registry.get("xn--q9jyb4c");
  assertThat(registry.getStandardRenewCost(START_OF_TIME)).isEqualTo(Money.of(USD, 1));
  assertThat(registry.getStandardRenewCost(now.minusMillis(1))).isEqualTo(Money.of(USD, 1));
  assertThat(registry.getStandardRenewCost(now)).isEqualTo(Money.of(USD, 2));
  assertThat(registry.getStandardRenewCost(now.plusMillis(1))).isEqualTo(Money.of(USD, 2));
  assertThat(registry.getStandardRenewCost(later.minusMillis(1))).isEqualTo(Money.of(USD, 2));
  assertThat(registry.getStandardRenewCost(later)).isEqualTo(Money.of(USD, 100));
  assertThat(registry.getStandardRenewCost(later.plusMillis(1))).isEqualTo(Money.of(USD, 100));
  assertThat(registry.getStandardRenewCost(END_OF_TIME)).isEqualTo(Money.of(USD, 100));
}
 
Example 18
Project: nomulus   File: DomainCreateFlowTest.java   View source code 6 votes vote down vote up
@Test
public void testFailure_wrongCurrency_v11() throws Exception {
  setEppInput("domain_create_fee.xml", ImmutableMap.of("FEE_VERSION", "0.11"));
  persistResource(
      Registry.get("tld")
          .asBuilder()
          .setCurrency(CurrencyUnit.EUR)
          .setCreateBillingCost(Money.of(EUR, 13))
          .setRestoreBillingCost(Money.of(EUR, 11))
          .setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 7)))
          .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
          .setServerStatusChangeBillingCost(Money.of(EUR, 19))
          .build());
  persistContactsAndHosts();
  EppException thrown = expectThrows(CurrencyUnitMismatchException.class, this::runFlow);
  assertAboutEppExceptions().that(thrown).marshalsToXml();
}
 
Example 19
Project: nomulus   File: DomainTransferUtils.java   View source code 6 votes vote down vote up
private static BillingEvent.OneTime createTransferBillingEvent(
    DateTime automaticTransferTime,
    HistoryEntry historyEntry,
    String targetId,
    String gainingClientId,
    Registry registry,
    Money transferCost) {
  return new BillingEvent.OneTime.Builder()
      .setReason(Reason.TRANSFER)
      .setTargetId(targetId)
      .setClientId(gainingClientId)
      .setCost(transferCost)
      .setPeriodYears(1)
      .setEventTime(automaticTransferTime)
      .setBillingTime(automaticTransferTime.plus(registry.getTransferGracePeriodLength()))
      .setParent(historyEntry)
      .build();
}
 
Example 20
Project: nomulus   File: DomainDeleteFlowTest.java   View source code 6 votes vote down vote up
@Test
public void testSuccess_autoRenewGracePeriod_priceChanges_v12() throws Exception {
  persistResource(
      Registry.get("tld")
          .asBuilder()
          .setRenewBillingCostTransitions(
              ImmutableSortedMap.of(
                  START_OF_TIME,
                  Money.of(USD, 11),
                  TIME_BEFORE_FLOW.minusDays(5),
                  Money.of(USD, 20)))
          .build());
  setUpAutorenewGracePeriod();
  clock.advanceOneMilli();
  runFlowAssertResponse(loadFile("domain_delete_response_autorenew_fee.xml", FEE_12_MAP));
}
 
Example 21
Project: nomulus   File: ListCreditsCommand.java   View source code 6 votes vote down vote up
private ImmutableList<String> createCreditStrings(final Registrar registrar) {
  return ofy()
      .transactNewReadOnly(
          () -> {
            ImmutableList.Builder<String> builder = new ImmutableList.Builder<>();
            for (RegistrarCredit credit : RegistrarCredit.loadAllForRegistrar(registrar)) {
              BalanceMap balanceMap = BalanceMap.createForCredit(credit);
              Optional<Money> activeBalance =
                  balanceMap.getActiveBalanceAtTime(ofy().getTransactionTime());
              // Unless showAll is true, only show credits with a positive active balance (which
              // excludes just zero-balance credits since credit balances cannot be negative).
              if (showAll || (activeBalance.isPresent() && activeBalance.get().isPositive())) {
                builder.add(credit.getSummary() + "\n" + balanceMap);
              }
            }
            return builder.build();
          });
}
 
Example 22
Project: nomulus   File: RegistrarBillingEntryTest.java   View source code 5 votes vote down vote up
@Test
public void testIndexing() throws Exception {
  verifyIndexing(
      persistResource(
          new RegistrarBillingEntry.Builder()
              .setPrevious(null)
              .setParent(loadRegistrar("NewRegistrar"))
              .setCreated(DateTime.parse("1984-12-18TZ"))
              .setTransactionId("goblin-market")
              .setDescription("USD Invoice for December 1984")
              .setAmount(Money.parse("USD 10.00"))
              .build()),
      "currency",
      "created");
}
 
Example 23
Project: nomulus   File: RdeDomainImportActionTest.java   View source code 5 votes vote down vote up
private static void checkTransferBillingEvent(
    DomainResource domain, DateTime automaticTransferTime) {
  for (BillingEvent.OneTime event :
      ofy().load().type(BillingEvent.OneTime.class).ancestor(domain).list()) {
    if (event.getReason() == BillingEvent.Reason.TRANSFER) {
      assertThat(event.getCost()).isEqualTo(Money.of(USD, 11));
      assertThat(event.getClientId()).isEqualTo("RegistrarY");
      assertThat(event.getBillingTime()).isEqualTo(automaticTransferTime);
    }
  }
}
 
Example 24
Project: nomulus   File: RegistryTest.java   View source code 5 votes vote down vote up
@Test
public void testFailure_renewBillingCostTransitionValue_wrongCurrency() {
  IllegalArgumentException thrown =
      expectThrows(
          IllegalArgumentException.class,
          () ->
              Registry.get("tld")
                  .asBuilder()
                  .setRenewBillingCostTransitions(
                      ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 42)))
                  .build());
  assertThat(thrown).hasMessageThat().contains("cost must be in the registry's currency");
}
 
Example 25
Project: nomulus   File: RegistryTest.java   View source code 5 votes vote down vote up
@Test
public void testFailure_serverStatusChangeBillingCost_wrongCurrency() {
  IllegalArgumentException thrown =
      expectThrows(
          IllegalArgumentException.class,
          () ->
              Registry.get("tld")
                  .asBuilder()
                  .setServerStatusChangeBillingCost(Money.of(EUR, 42))
                  .build());
  assertThat(thrown).hasMessageThat().contains("cost must be in the registry's currency");
}
 
Example 26
Project: nomulus   File: RegistrarBillingUtilsTest.java   View source code 5 votes vote down vote up
@Test
public void testLoadBalance_noHistory_returnsZeroes() {
  Map<CurrencyUnit, Money> balance = RegistrarBillingUtils.loadBalance(registrar);
  assertThat(balance).hasSize(2);
  assertThat(balance).containsEntry(USD, Money.parse("USD 0.00"));
  assertThat(balance).containsEntry(JPY, Money.parse("JPY 0"));
}
 
Example 27
Project: nomulus   File: RegistrarCreditBalanceTest.java   View source code 5 votes vote down vote up
@Test
public void testSuccess_balanceMap_getActiveBalanceAtTime() throws Exception {
  BalanceMap map = new BalanceMap(rawBalanceMap);
  assertThat(map.getActiveBalanceAtTime(START_OF_TIME)).isEmpty();
  assertThat(map.getActiveBalanceAtTime(clock.nowUtc().minusMillis(1))).isEmpty();
  assertThat(map.getActiveBalanceAtTime(clock.nowUtc()).get()).isEqualTo(Money.parse("USD 70"));
  assertThat(map.getActiveBalanceAtTime(clock.nowUtc().plusMillis(1)).get())
      .isEqualTo(Money.parse("USD 70"));
  assertThat(map.getActiveBalanceAtTime(then.minusMillis(1)).get())
      .isEqualTo(Money.parse("USD 70"));
  assertThat(map.getActiveBalanceAtTime(then).get()).isEqualTo(Money.parse("USD 20"));
  assertThat(map.getActiveBalanceAtTime(then.plusMillis(1)).get())
      .isEqualTo(Money.parse("USD 20"));
  assertThat(map.getActiveBalanceAtTime(END_OF_TIME).get()).isEqualTo(Money.parse("USD 20"));
}
 
Example 28
Project: nomulus   File: RegistryTest.java   View source code 5 votes vote down vote up
@Test
public void testSettingCreateBillingCost() {
  Registry registry =
      Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 42)).build();
  assertThat(registry.getStandardCreateCost()).isEqualTo(Money.of(USD, 42));
  // The default value of 17 is set in createTld().
  assertThat(registry.getStandardRestoreCost()).isEqualTo(Money.of(USD, 17));
}
 
Example 29
Project: nomulus   File: DomainCreateFlowTest.java   View source code 5 votes vote down vote up
@Test
public void testFailure_wrongFeeAmount_v12() throws Exception {
  setEppInput("domain_create_fee.xml", ImmutableMap.of("FEE_VERSION", "0.12"));
  persistResource(
      Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 20)).build());
  persistContactsAndHosts();
  EppException thrown = expectThrows(FeesMismatchException.class, this::runFlow);
  assertAboutEppExceptions().that(thrown).marshalsToXml();
}
 
Example 30
Project: jdbi-examples   File: Example05SqlObjectApi.java   View source code 5 votes vote down vote up
@Test
public void test() throws Exception {
  Jdbi jdbi = Jdbi.create(ds.getDataSource());
  jdbi.installPlugin(new SqlObjectPlugin());

  jdbi.useExtension(AccountDao.class, dao -> {
    Money tenDollars = Money.of(USD, 10);
    Money fiveDollars = Money.of(USD, 5);

    dao.createTable();
    dao.insert(new Account(1, "Alice", tenDollars));
    dao.insert(new Account(2, "Bob", fiveDollars));

    assertThat(dao.list())
        .extracting(Account::getId, Account::getName, Account::getBalance)
        .containsExactly(tuple(1, "Alice", tenDollars),
                         tuple(2, "Bob", fiveDollars));

    assertThat(dao.getById(2))
        .extracting(Account::getId, Account::getName, Account::getBalance)
        .containsExactly(2, "Bob", fiveDollars);

    dao.update(new Account(2, "Robert", tenDollars));

    assertThat(dao.getById(2))
        .extracting(Account::getId, Account::getName, Account::getBalance)
        .containsExactly(2, "Robert", tenDollars);
  });
}
 
Example 31
Project: nomulus   File: DomainRestoreRequestFlowTest.java   View source code 5 votes vote down vote up
@Test
public void testFailure_wrongFeeAmount_v11() throws Exception {
  setEppInput("domain_update_restore_request_fee.xml", FEE_11_MAP);
  persistPendingDeleteDomain();
  persistResource(
      Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, 100)).build());
  EppException thrown = expectThrows(FeesMismatchException.class, this::runFlow);
  assertAboutEppExceptions().that(thrown).marshalsToXml();
}
 
Example 32
Project: nomulus   File: DomainRenewFlowTest.java   View source code 5 votes vote down vote up
private void doSuccessfulTest(
    String responseFilename, int renewalYears, Map<String, String> substitutions)
    throws Exception {
  doSuccessfulTest(
      responseFilename,
      renewalYears,
      substitutions,
      Money.of(USD, 11).multipliedBy(renewalYears));
}
 
Example 33
Project: nomulus   File: CreatePremiumListActionTest.java   View source code 5 votes vote down vote up
@Test
public void test_success() throws Exception {
  action.name = "foo";
  action.inputData = "rich,USD 25\nricher,USD 1000\n";
  action.run();
  assertThat(response.getStatus()).isEqualTo(SC_OK);
  assertThat(loadPremiumListEntries(PremiumList.get("foo").get())).hasSize(2);
  assertThat(getPremiumPrice("rich", Registry.get("foo"))).hasValue(Money.parse("USD 25"));
  assertThat(getPremiumPrice("diamond", Registry.get("foo"))).isEmpty();
}
 
Example 34
Project: nomulus   File: CreateTldCommandTest.java   View source code 5 votes vote down vote up
@Test
public void testSuccess_createBillingCostFlag() throws Exception {
  runCommandForced(
      "--create_billing_cost=\"USD 42.42\"",
      "--roid_suffix=Q9JYB4C",
      "--dns_writers=VoidDnsWriter",
      "xn--q9jyb4c");
  assertThat(Registry.get("xn--q9jyb4c").getStandardCreateCost()).isEqualTo(Money.of(USD, 42.42));
}
 
Example 35
Project: nomulus   File: DomainRestoreRequestFlowTest.java   View source code 5 votes vote down vote up
@Test
public void testFailure_wrongFeeAmount_v06() throws Exception {
  setEppInput("domain_update_restore_request_fee.xml", FEE_06_MAP);
  persistPendingDeleteDomain();
  persistResource(
      Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, 100)).build());
  EppException thrown = expectThrows(FeesMismatchException.class, this::runFlow);
  assertAboutEppExceptions().that(thrown).marshalsToXml();
}
 
Example 36
Project: nomulus   File: PricingEngineProxyTest.java   View source code 5 votes vote down vote up
@Test
public void testGetDomainRenewCost() throws Exception {
  // The example tld has a premium price for "rich".
  createTld("example");
  persistResource(
      Registry.get("example")
          .asBuilder()
          .setRenewBillingCostTransitions(
              ImmutableSortedMap.of(
                  START_OF_TIME, Money.of(USD, 8), clock.nowUtc(), Money.of(USD, 10)))
          .build());
  assertThat(getDomainRenewCost("poor.example", START_OF_TIME, 1))
      .isEqualTo(Money.of(USD, 8));
  assertThat(getDomainRenewCost("poor.example", START_OF_TIME, 2))
      .isEqualTo(Money.of(USD, 16));
  assertThat(getDomainRenewCost("poor.example", clock.nowUtc(), 1))
      .isEqualTo(Money.of(USD, 10));
  assertThat(getDomainRenewCost("poor.example", clock.nowUtc(), 2))
      .isEqualTo(Money.of(USD, 20));
  assertThat(getDomainRenewCost("rich.example", START_OF_TIME, 1))
      .isEqualTo(Money.of(USD, 100));
  assertThat(getDomainRenewCost("rich.example", START_OF_TIME, 2))
      .isEqualTo(Money.of(USD, 200));
  assertThat(getDomainRenewCost("rich.example", clock.nowUtc(), 1))
      .isEqualTo(Money.of(USD, 100));
  assertThat(getDomainRenewCost("rich.example", clock.nowUtc(), 2))
      .isEqualTo(Money.of(USD, 200));
}
 
Example 37
Project: nomulus   File: PremiumListUtilsTest.java   View source code 5 votes vote down vote up
@Test
public void testSave_simple() throws Exception {
  PremiumList pl =
      savePremiumListAndEntries(
          new PremiumList.Builder().setName("tld2").build(),
          ImmutableList.of("lol , USD 999 # yupper rooni "));
  createTld("tld");
  persistResource(Registry.get("tld").asBuilder().setPremiumList(pl).build());
  assertThat(getPremiumPrice("lol", Registry.get("tld"))).hasValue(Money.parse("USD 999"));
  assertThat(getPremiumPrice("lol ", Registry.get("tld"))).isEmpty();
  ImmutableMap<String, PremiumListEntry> entries =
      loadPremiumListEntries(PremiumList.get("tld2").get());
  assertThat(entries.keySet()).containsExactly("lol");
  assertThat(entries).doesNotContainKey("lol ");
  PremiumListEntry entry = entries.get("lol");
  assertThat(entry.comment).isEqualTo("yupper rooni");
  assertThat(entry.price).isEqualTo(Money.parse("USD 999"));
  assertThat(entry.label).isEqualTo("lol");
  assertThat(premiumListChecks)
      .hasValueForLabels(1, "tld", "tld2", UNCACHED_POSITIVE.toString())
      .and()
      .hasValueForLabels(1, "tld", "tld2", BLOOM_FILTER_NEGATIVE.toString())
      .and()
      .hasNoOtherValues();
  assertThat(premiumListProcessingTime)
      .hasAnyValueForLabels("tld", "tld2", UNCACHED_POSITIVE.toString())
      .and()
      .hasAnyValueForLabels("tld", "tld2", BLOOM_FILTER_NEGATIVE.toString())
      .and()
      .hasNoOtherValues();
}
 
Example 38
Project: nomulus   File: RegistrarBillingUtilsTest.java   View source code 5 votes vote down vote up
@Test
public void testLoadBalance_twoCurrencies_hasTwoEntriesWithSum() {
  RegistrarBillingEntry entry1 = new RegistrarBillingEntry.Builder()
      .setPrevious(null)
      .setParent(registrar)
      .setCreated(clock.nowUtc())
      .setDescription("USD Invoice for July")
      .setAmount(Money.parse("USD 10.00"))
      .build();
  clock.advanceBy(Duration.standardDays(30));
  RegistrarBillingEntry entry2 = new RegistrarBillingEntry.Builder()
      .setPrevious(entry1)
      .setParent(registrar)
      .setCreated(clock.nowUtc())
      .setDescription("USD Invoice for August")
      .setAmount(Money.parse("USD 3.50"))
      .build();
  RegistrarBillingEntry entry3 = new RegistrarBillingEntry.Builder()
      .setPrevious(null)
      .setParent(registrar)
      .setCreated(clock.nowUtc())
      .setDescription("JPY Invoice for August")
      .setAmount(Money.parse("JPY 666"))
      .build();
  persistSimpleResources(asList(entry1, entry2, entry3));
  Map<CurrencyUnit, Money> balance = RegistrarBillingUtils.loadBalance(registrar);
  assertThat(balance).hasSize(2);
  assertThat(balance).containsEntry(USD, Money.parse("USD 13.50"));
  assertThat(balance).containsEntry(JPY, Money.parse("JPY 666"));
}
 
Example 39
Project: nomulus   File: DomainApplicationCreateFlowTest.java   View source code 5 votes vote down vote up
@Test
public void testFailure_wrongFeeLandrushApplication_v11() throws Exception {
  createTld("tld", TldState.LANDRUSH);
  setEppInput("domain_create_landrush_fee.xml", ImmutableMap.of("FEE_VERSION", "0.11"));
  persistResource(
      Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 20)).build());
  persistContactsAndHosts();
  clock.advanceOneMilli();
  EppException thrown = expectThrows(FeesMismatchException.class, this::runFlow);
  assertAboutEppExceptions().that(thrown).marshalsToXml();
}
 
Example 40
Project: nomulus   File: RegistryTest.java   View source code 5 votes vote down vote up
@Test
public void testFailure_negativeServerStatusChangeBillingCost() {
  IllegalArgumentException thrown =
      expectThrows(
          IllegalArgumentException.class,
          () ->
              Registry.get("tld")
                  .asBuilder()
                  .setServerStatusChangeBillingCost(Money.of(USD, -42)));
  assertThat(thrown).hasMessageThat().contains("billing cost cannot be negative");
}