mirror of
https://github.com/google/nomulus.git
synced 2025-07-24 19:48:32 +02:00
Automatically refactor more exception testing to use new JUnit rules
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=178911894
This commit is contained in:
parent
36ad38e5df
commit
7dc224627f
125 changed files with 1970 additions and 1982 deletions
|
@ -33,7 +33,6 @@ import org.joda.time.Duration;
|
|||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -47,9 +46,6 @@ public class EppResourceUtilsTest {
|
|||
.withTaskQueue()
|
||||
.build();
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Rule
|
||||
public final InjectRule inject = new InjectRule();
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ import java.util.Map;
|
|||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -32,9 +31,6 @@ import org.junit.runners.JUnit4;
|
|||
@RunWith(JUnit4.class)
|
||||
public class ModelUtilsTest {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Rule
|
||||
public AppEngineRule appEngineRule = new AppEngineRule.Builder().build();
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
|
|||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.persistActiveDomain;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
||||
import static org.joda.money.CurrencyUnit.USD;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
@ -35,16 +36,10 @@ import google.registry.model.reporting.HistoryEntry;
|
|||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/** Unit tests for {@link BillingEvent}. */
|
||||
public class BillingEventTest extends EntityTestCase {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final DateTime now = DateTime.now(UTC);
|
||||
|
||||
HistoryEntry historyEntry;
|
||||
|
@ -182,44 +177,64 @@ public class BillingEventTest extends EntityTestCase {
|
|||
|
||||
@Test
|
||||
public void testFailure_syntheticFlagWithoutCreationTime() {
|
||||
thrown.expect(IllegalStateException.class);
|
||||
thrown.expectMessage(
|
||||
"Synthetic creation time must be set if and only if the SYNTHETIC flag is set.");
|
||||
oneTime.asBuilder()
|
||||
.setFlags(ImmutableSet.of(BillingEvent.Flag.SYNTHETIC))
|
||||
.setCancellationMatchingBillingEvent(Key.create(recurring))
|
||||
.build();
|
||||
IllegalStateException thrown =
|
||||
expectThrows(
|
||||
IllegalStateException.class,
|
||||
() ->
|
||||
oneTime
|
||||
.asBuilder()
|
||||
.setFlags(ImmutableSet.of(BillingEvent.Flag.SYNTHETIC))
|
||||
.setCancellationMatchingBillingEvent(Key.create(recurring))
|
||||
.build());
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Synthetic creation time must be set if and only if the SYNTHETIC flag is set.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_syntheticCreationTimeWithoutFlag() {
|
||||
thrown.expect(IllegalStateException.class);
|
||||
thrown.expectMessage(
|
||||
"Synthetic creation time must be set if and only if the SYNTHETIC flag is set");
|
||||
oneTime.asBuilder()
|
||||
.setSyntheticCreationTime(now.plusDays(10))
|
||||
.build();
|
||||
IllegalStateException thrown =
|
||||
expectThrows(
|
||||
IllegalStateException.class,
|
||||
() -> oneTime.asBuilder().setSyntheticCreationTime(now.plusDays(10)).build());
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Synthetic creation time must be set if and only if the SYNTHETIC flag is set");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_syntheticFlagWithoutCancellationMatchingKey() {
|
||||
thrown.expect(IllegalStateException.class);
|
||||
thrown.expectMessage(
|
||||
"Cancellation matching billing event must be set if and only if the SYNTHETIC flag is set");
|
||||
oneTime.asBuilder()
|
||||
.setFlags(ImmutableSet.of(BillingEvent.Flag.SYNTHETIC))
|
||||
.setSyntheticCreationTime(END_OF_TIME)
|
||||
.build();
|
||||
IllegalStateException thrown =
|
||||
expectThrows(
|
||||
IllegalStateException.class,
|
||||
() ->
|
||||
oneTime
|
||||
.asBuilder()
|
||||
.setFlags(ImmutableSet.of(BillingEvent.Flag.SYNTHETIC))
|
||||
.setSyntheticCreationTime(END_OF_TIME)
|
||||
.build());
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains(
|
||||
"Cancellation matching billing event must be set "
|
||||
+ "if and only if the SYNTHETIC flag is set");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_cancellationMatchingKeyWithoutFlag() {
|
||||
thrown.expect(IllegalStateException.class);
|
||||
thrown.expectMessage(
|
||||
"Cancellation matching billing event must be set if and only if the SYNTHETIC flag is set");
|
||||
oneTime.asBuilder()
|
||||
.setCancellationMatchingBillingEvent(Key.create(recurring))
|
||||
.build();
|
||||
IllegalStateException thrown =
|
||||
expectThrows(
|
||||
IllegalStateException.class,
|
||||
() ->
|
||||
oneTime
|
||||
.asBuilder()
|
||||
.setCancellationMatchingBillingEvent(Key.create(recurring))
|
||||
.build());
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains(
|
||||
"Cancellation matching billing event must be set "
|
||||
+ "if and only if the SYNTHETIC flag is set");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -250,32 +265,44 @@ public class BillingEventTest extends EntityTestCase {
|
|||
|
||||
@Test
|
||||
public void testFailure_cancellation_forGracePeriodWithoutBillingEvent() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("grace period without billing event");
|
||||
BillingEvent.Cancellation.forGracePeriod(
|
||||
GracePeriod.createWithoutBillingEvent(
|
||||
GracePeriodStatus.REDEMPTION,
|
||||
now.plusDays(1),
|
||||
"a registrar"),
|
||||
historyEntry,
|
||||
"foo.tld");
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
BillingEvent.Cancellation.forGracePeriod(
|
||||
GracePeriod.createWithoutBillingEvent(
|
||||
GracePeriodStatus.REDEMPTION, now.plusDays(1), "a registrar"),
|
||||
historyEntry,
|
||||
"foo.tld"));
|
||||
assertThat(thrown).hasMessageThat().contains("grace period without billing event");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_cancellationWithNoBillingEvent() {
|
||||
thrown.expect(IllegalStateException.class);
|
||||
thrown.expectMessage("exactly one billing event");
|
||||
cancellationOneTime.asBuilder().setOneTimeEventKey(null).setRecurringEventKey(null).build();
|
||||
IllegalStateException thrown =
|
||||
expectThrows(
|
||||
IllegalStateException.class,
|
||||
() ->
|
||||
cancellationOneTime
|
||||
.asBuilder()
|
||||
.setOneTimeEventKey(null)
|
||||
.setRecurringEventKey(null)
|
||||
.build());
|
||||
assertThat(thrown).hasMessageThat().contains("exactly one billing event");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_cancellationWithBothBillingEvents() {
|
||||
thrown.expect(IllegalStateException.class);
|
||||
thrown.expectMessage("exactly one billing event");
|
||||
cancellationOneTime.asBuilder()
|
||||
.setOneTimeEventKey(Key.create(oneTime))
|
||||
.setRecurringEventKey(Key.create(recurring))
|
||||
.build();
|
||||
IllegalStateException thrown =
|
||||
expectThrows(
|
||||
IllegalStateException.class,
|
||||
() ->
|
||||
cancellationOneTime
|
||||
.asBuilder()
|
||||
.setOneTimeEventKey(Key.create(oneTime))
|
||||
.setRecurringEventKey(Key.create(recurring))
|
||||
.build());
|
||||
assertThat(thrown).hasMessageThat().contains("exactly one billing event");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -17,6 +17,8 @@ package google.registry.model.billing;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.DatastoreHelper.loadRegistrar;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static org.joda.money.CurrencyUnit.USD;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
@ -25,9 +27,7 @@ import google.registry.model.EntityTestCase;
|
|||
import org.joda.money.CurrencyMismatchException;
|
||||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -35,9 +35,6 @@ import org.junit.runners.JUnit4;
|
|||
@RunWith(JUnit4.class)
|
||||
public final class RegistrarBillingEntryTest extends EntityTestCase {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void testIndexing() throws Exception {
|
||||
verifyIndexing(
|
||||
|
@ -100,77 +97,88 @@ public final class RegistrarBillingEntryTest extends EntityTestCase {
|
|||
|
||||
@Test
|
||||
public void testBadTimeOrdering_causesError() throws Exception {
|
||||
thrown.expect(IllegalStateException.class);
|
||||
thrown.expectMessage("Created timestamp not after previous");
|
||||
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();
|
||||
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");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegistrarMismatch_causesError() throws Exception {
|
||||
thrown.expect(IllegalStateException.class);
|
||||
thrown.expectMessage("Parent not same as previous");
|
||||
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("TheRegistrar"))
|
||||
.setCreated(DateTime.parse("1984-12-17TZ"))
|
||||
.setTransactionId("goblin")
|
||||
.setDescription("USD Invoice for August")
|
||||
.setAmount(Money.parse("USD 3.50"))
|
||||
.build();
|
||||
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("TheRegistrar"))
|
||||
.setCreated(DateTime.parse("1984-12-17TZ"))
|
||||
.setTransactionId("goblin")
|
||||
.setDescription("USD Invoice for August")
|
||||
.setAmount(Money.parse("USD 3.50"))
|
||||
.build());
|
||||
assertThat(thrown).hasMessageThat().contains("Parent not same as previous");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCurrencyMismatch_causesError() throws Exception {
|
||||
thrown.expect(CurrencyMismatchException.class);
|
||||
new RegistrarBillingEntry.Builder()
|
||||
.setPrevious(
|
||||
assertThrows(
|
||||
CurrencyMismatchException.class,
|
||||
() ->
|
||||
new RegistrarBillingEntry.Builder()
|
||||
.setPrevious(null)
|
||||
.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-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("JPY Invoice for August")
|
||||
.setAmount(Money.parse("JPY 350"))
|
||||
.build();
|
||||
.setCreated(DateTime.parse("1984-12-17TZ"))
|
||||
.setTransactionId("goblin")
|
||||
.setDescription("JPY Invoice for August")
|
||||
.setAmount(Money.parse("JPY 350"))
|
||||
.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZeroAmount_causesError() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Amount can't be zero");
|
||||
new RegistrarBillingEntry.Builder()
|
||||
.setPrevious(null)
|
||||
.setParent(loadRegistrar("NewRegistrar"))
|
||||
.setCreated(DateTime.parse("1984-12-18TZ"))
|
||||
.setDescription("USD Invoice for December")
|
||||
.setAmount(Money.zero(USD))
|
||||
.build();
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
new RegistrarBillingEntry.Builder()
|
||||
.setPrevious(null)
|
||||
.setParent(loadRegistrar("NewRegistrar"))
|
||||
.setCreated(DateTime.parse("1984-12-18TZ"))
|
||||
.setDescription("USD Invoice for December")
|
||||
.setAmount(Money.zero(USD))
|
||||
.build());
|
||||
assertThat(thrown).hasMessageThat().contains("Amount can't be zero");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -20,6 +20,7 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
|
|||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.loadRegistrar;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
|
||||
|
@ -33,16 +34,10 @@ import org.joda.money.CurrencyUnit;
|
|||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/** Unit tests for {@link RegistrarCreditBalance}. */
|
||||
public class RegistrarCreditBalanceTest extends EntityTestCase {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private DateTime then = clock.nowUtc().plusDays(1);
|
||||
|
||||
private Registrar theRegistrar;
|
||||
|
@ -100,19 +95,21 @@ public class RegistrarCreditBalanceTest extends EntityTestCase {
|
|||
|
||||
@Test
|
||||
public void testFailure_balanceNotInCreditCurrency() throws Exception {
|
||||
thrown.expect(IllegalStateException.class);
|
||||
balance.asBuilder()
|
||||
.setAmount(Money.parse("JPY 1"))
|
||||
.build();
|
||||
assertThrows(
|
||||
IllegalStateException.class,
|
||||
() -> balance.asBuilder().setAmount(Money.parse("JPY 1")).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_balanceNotInCreditCurrencyWithUnpersistedCredit() throws Exception {
|
||||
thrown.expect(IllegalStateException.class);
|
||||
balance.asBuilder()
|
||||
.setParent(unpersistedCredit)
|
||||
.setAmount(Money.parse("JPY 1"))
|
||||
.build();
|
||||
assertThrows(
|
||||
IllegalStateException.class,
|
||||
() ->
|
||||
balance
|
||||
.asBuilder()
|
||||
.setParent(unpersistedCredit)
|
||||
.setAmount(Money.parse("JPY 1"))
|
||||
.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -19,6 +19,7 @@ import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
|
|||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static org.joda.money.CurrencyUnit.JPY;
|
||||
import static org.joda.money.CurrencyUnit.USD;
|
||||
|
||||
|
@ -28,16 +29,10 @@ import google.registry.model.registrar.Registrar;
|
|||
import google.registry.model.registry.Registry;
|
||||
import org.joda.money.CurrencyUnit;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/** Unit tests for {@link RegistrarCredit}. */
|
||||
public class RegistrarCreditTest extends EntityTestCase {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private RegistrarCredit auctionCredit;
|
||||
private RegistrarCredit promoCredit;
|
||||
|
||||
|
@ -81,23 +76,28 @@ public class RegistrarCreditTest extends EntityTestCase {
|
|||
|
||||
@Test
|
||||
public void testFailure_missingTld() throws Exception {
|
||||
thrown.expect(NullPointerException.class);
|
||||
thrown.expectMessage("tld");
|
||||
promoCredit.asBuilder().setTld(null).build();
|
||||
NullPointerException thrown =
|
||||
expectThrows(
|
||||
NullPointerException.class, () -> promoCredit.asBuilder().setTld(null).build());
|
||||
assertThat(thrown).hasMessageThat().contains("tld");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_NonexistentTld() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("example");
|
||||
promoCredit.asBuilder().setTld("example").build();
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> promoCredit.asBuilder().setTld("example").build());
|
||||
assertThat(thrown).hasMessageThat().contains("example");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_CurrencyDoesNotMatchTldCurrency() throws Exception {
|
||||
assertThat(Registry.get("tld").getCurrency()).isEqualTo(USD);
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("currency");
|
||||
promoCredit.asBuilder().setTld("tld").setCurrency(JPY).build();
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> promoCredit.asBuilder().setTld("tld").setCurrency(JPY).build());
|
||||
assertThat(thrown).hasMessageThat().contains("currency");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,21 +21,17 @@ import static google.registry.model.common.Cursor.CursorType.RECURRING_BILLING;
|
|||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.persistActiveDomain;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
|
||||
import google.registry.model.EntityTestCase;
|
||||
import google.registry.model.domain.DomainResource;
|
||||
import google.registry.model.registry.Registry;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/** Unit tests for {@link Cursor}. */
|
||||
public class CursorTest extends EntityTestCase {
|
||||
|
||||
@Rule public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void testSuccess_persistScopedCursor() {
|
||||
createTld("tld");
|
||||
|
@ -74,54 +70,72 @@ public class CursorTest extends EntityTestCase {
|
|||
clock.advanceOneMilli();
|
||||
final DateTime time = DateTime.parse("2012-07-12T03:30:00.000Z");
|
||||
final DomainResource domain = persistActiveDomain("notaregistry.tld");
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Class required for cursor does not match scope class");
|
||||
ofy().transact(() -> ofy().save().entity(Cursor.create(RDE_UPLOAD, time, domain)));
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
ofy().transact(() -> ofy().save().entity(Cursor.create(RDE_UPLOAD, time, domain))));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Class required for cursor does not match scope class");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_invalidScopeOnKeyCreate() throws Exception {
|
||||
createTld("tld");
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Class required for cursor does not match scope class");
|
||||
Cursor.createKey(RDE_UPLOAD, persistActiveDomain("notaregistry.tld"));
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> Cursor.createKey(RDE_UPLOAD, persistActiveDomain("notaregistry.tld")));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Class required for cursor does not match scope class");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_createGlobalKeyForScopedCursorType() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Cursor type is not a global cursor");
|
||||
Cursor.createGlobalKey(RDE_UPLOAD);
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(IllegalArgumentException.class, () -> Cursor.createGlobalKey(RDE_UPLOAD));
|
||||
assertThat(thrown).hasMessageThat().contains("Cursor type is not a global cursor");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_invalidScopeOnGlobalKeyCreate() throws Exception {
|
||||
createTld("tld");
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Class required for cursor does not match scope class");
|
||||
Cursor.createKey(RECURRING_BILLING, persistActiveDomain("notaregistry.tld"));
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> Cursor.createKey(RECURRING_BILLING, persistActiveDomain("notaregistry.tld")));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Class required for cursor does not match scope class");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_nullScope() throws Exception {
|
||||
thrown.expect(NullPointerException.class);
|
||||
thrown.expectMessage("Cursor scope cannot be null");
|
||||
Cursor.create(RECURRING_BILLING, START_OF_TIME, null);
|
||||
NullPointerException thrown =
|
||||
expectThrows(
|
||||
NullPointerException.class,
|
||||
() -> Cursor.create(RECURRING_BILLING, START_OF_TIME, null));
|
||||
assertThat(thrown).hasMessageThat().contains("Cursor scope cannot be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_nullCursorType() throws Exception {
|
||||
createTld("tld");
|
||||
thrown.expect(NullPointerException.class);
|
||||
thrown.expectMessage("Cursor type cannot be null");
|
||||
Cursor.create(null, START_OF_TIME, Registry.get("tld"));
|
||||
NullPointerException thrown =
|
||||
expectThrows(
|
||||
NullPointerException.class,
|
||||
() -> Cursor.create(null, START_OF_TIME, Registry.get("tld")));
|
||||
assertThat(thrown).hasMessageThat().contains("Cursor type cannot be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_nullTime() throws Exception {
|
||||
createTld("tld");
|
||||
thrown.expect(NullPointerException.class);
|
||||
thrown.expectMessage("Cursor time cannot be null");
|
||||
Cursor.create(RDE_UPLOAD, null, Registry.get("tld"));
|
||||
NullPointerException thrown =
|
||||
expectThrows(
|
||||
NullPointerException.class, () -> Cursor.create(RDE_UPLOAD, null, Registry.get("tld")));
|
||||
assertThat(thrown).hasMessageThat().contains("Cursor time cannot be null");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,9 +21,7 @@ import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Range;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -35,9 +33,6 @@ public class TimeOfYearTest {
|
|||
private static final DateTime february29 = DateTime.parse("2012-02-29T01:02:03.0Z");
|
||||
private static final DateTime march1 = DateTime.parse("2012-03-01T01:02:03.0Z");
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void testSuccess_fromDateTime() throws Exception {
|
||||
// We intentionally don't allow leap years in TimeOfYear, so February 29 should be February 28.
|
||||
|
|
|
@ -16,6 +16,7 @@ package google.registry.model.common;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.common.TimedTransitionProperty.forMapify;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
@ -26,19 +27,13 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
/** Unit tests for {@link TimedTransitionProperty}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class TimedTransitionPropertyTest {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private static final DateTime A_LONG_TIME_AGO = new DateTime(Long.MIN_VALUE, UTC);
|
||||
|
||||
private static final DateTime DATE_1 = DateTime.parse("2001-01-01T00:00:00.0Z");
|
||||
|
@ -130,31 +125,39 @@ public class TimedTransitionPropertyTest {
|
|||
|
||||
@Test
|
||||
public void testFailure_valueMapNotChronologicallyOrdered() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
TimedTransitionProperty.fromValueMap(
|
||||
ImmutableSortedMap.<DateTime, String>reverseOrder().put(START_OF_TIME, "0").build(),
|
||||
StringTimedTransition.class);
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
TimedTransitionProperty.fromValueMap(
|
||||
ImmutableSortedMap.<DateTime, String>reverseOrder().put(START_OF_TIME, "0").build(),
|
||||
StringTimedTransition.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_transitionTimeBeforeStartOfTime() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
TimedTransitionProperty.fromValueMap(
|
||||
ImmutableSortedMap.of(A_LONG_TIME_AGO, "?"), StringTimedTransition.class);
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
TimedTransitionProperty.fromValueMap(
|
||||
ImmutableSortedMap.of(A_LONG_TIME_AGO, "?"), StringTimedTransition.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_noValues() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
TimedTransitionProperty.fromValueMap(
|
||||
ImmutableSortedMap.<DateTime, String>of(), StringTimedTransition.class);
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
TimedTransitionProperty.fromValueMap(
|
||||
ImmutableSortedMap.<DateTime, String>of(), StringTimedTransition.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_noValueAtStartOfTime() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
TimedTransitionProperty.fromValueMap(
|
||||
ImmutableSortedMap.of(DATE_1, "1"), StringTimedTransition.class);
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
TimedTransitionProperty.fromValueMap(
|
||||
ImmutableSortedMap.of(DATE_1, "1"), StringTimedTransition.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -162,8 +165,7 @@ public class TimedTransitionPropertyTest {
|
|||
timedString = forMapify("0", StringTimedTransition.class);
|
||||
// Simulate a load from Datastore by clearing, but don't insert any transitions.
|
||||
timedString.clear();
|
||||
thrown.expect(IllegalStateException.class);
|
||||
timedString.checkValidity();
|
||||
assertThrows(IllegalStateException.class, () -> timedString.checkValidity());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -175,7 +177,6 @@ public class TimedTransitionPropertyTest {
|
|||
// omit a transition corresponding to START_OF_TIME.
|
||||
timedString.clear();
|
||||
timedString.put(DATE_1, transition1);
|
||||
thrown.expect(IllegalStateException.class);
|
||||
timedString.checkValidity();
|
||||
assertThrows(IllegalStateException.class, () -> timedString.checkValidity());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import static google.registry.testing.ContactResourceSubject.assertAboutContacts
|
|||
import static google.registry.testing.DatastoreHelper.cloneAndSetAutoTimestamps;
|
||||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
@ -37,16 +38,10 @@ import google.registry.model.transfer.TransferData;
|
|||
import google.registry.model.transfer.TransferData.TransferServerApproveEntity;
|
||||
import google.registry.model.transfer.TransferStatus;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/** Unit tests for {@link ContactResource}. */
|
||||
public class ContactResourceTest extends EntityTestCase {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
ContactResource contactResource;
|
||||
|
||||
@Before
|
||||
|
@ -206,9 +201,11 @@ public class ContactResourceTest extends EntityTestCase {
|
|||
|
||||
@Test
|
||||
public void testSetCreationTime_cantBeCalledTwice() {
|
||||
thrown.expect(IllegalStateException.class);
|
||||
thrown.expectMessage("creationTime can only be set once");
|
||||
contactResource.asBuilder().setCreationTime(END_OF_TIME);
|
||||
IllegalStateException thrown =
|
||||
expectThrows(
|
||||
IllegalStateException.class,
|
||||
() -> contactResource.asBuilder().setCreationTime(END_OF_TIME));
|
||||
assertThat(thrown).hasMessageThat().contains("creationTime can only be set once");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -41,16 +41,11 @@ import google.registry.model.host.HostResource;
|
|||
import google.registry.model.smd.EncodedSignedMark;
|
||||
import org.joda.money.Money;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/** Unit tests for {@link DomainApplication}. */
|
||||
public class DomainApplicationTest extends EntityTestCase {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
DomainApplication domainApplication;
|
||||
|
||||
@Before
|
||||
|
|
|
@ -24,6 +24,7 @@ import static google.registry.testing.DatastoreHelper.newDomainResource;
|
|||
import static google.registry.testing.DatastoreHelper.newHostResource;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static org.joda.money.CurrencyUnit.USD;
|
||||
|
||||
|
@ -55,16 +56,10 @@ import java.util.stream.Stream;
|
|||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/** Unit tests for {@link DomainResource}. */
|
||||
public class DomainResourceTest extends EntityTestCase {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
DomainResource domain;
|
||||
|
||||
@Before
|
||||
|
@ -445,15 +440,23 @@ public class DomainResourceTest extends EntityTestCase {
|
|||
|
||||
@Test
|
||||
public void testFailure_uppercaseDomainName() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Domain name must be in puny-coded, lower-case form");
|
||||
domain.asBuilder().setFullyQualifiedDomainName("AAA.BBB");
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> domain.asBuilder().setFullyQualifiedDomainName("AAA.BBB"));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Domain name must be in puny-coded, lower-case form");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_utf8DomainName() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Domain name must be in puny-coded, lower-case form");
|
||||
domain.asBuilder().setFullyQualifiedDomainName("みんな.みんな");
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> domain.asBuilder().setFullyQualifiedDomainName("みんな.みんな"));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Domain name must be in puny-coded, lower-case form");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
package google.registry.model.domain;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
import com.googlecode.objectify.Key;
|
||||
|
@ -30,7 +31,6 @@ import org.joda.time.DateTime;
|
|||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -42,10 +42,6 @@ public class GracePeriodTest {
|
|||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
||||
.withDatastore() // Needed to be able to construct Keys.
|
||||
.build();
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final DateTime now = DateTime.now(UTC);
|
||||
private BillingEvent.OneTime onetime;
|
||||
|
||||
|
@ -96,19 +92,24 @@ public class GracePeriodTest {
|
|||
|
||||
@Test
|
||||
public void testFailure_forBillingEvent_autoRenew() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("autorenew");
|
||||
GracePeriod.forBillingEvent(GracePeriodStatus.AUTO_RENEW, onetime);
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> GracePeriod.forBillingEvent(GracePeriodStatus.AUTO_RENEW, onetime));
|
||||
assertThat(thrown).hasMessageThat().contains("autorenew");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_createForRecurring_notAutoRenew() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("autorenew");
|
||||
GracePeriod.createForRecurring(
|
||||
GracePeriodStatus.RENEW,
|
||||
now.plusDays(1),
|
||||
"TheRegistrar",
|
||||
Key.create(Recurring.class, 12345));
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
GracePeriod.createForRecurring(
|
||||
GracePeriodStatus.RENEW,
|
||||
now.plusDays(1),
|
||||
"TheRegistrar",
|
||||
Key.create(Recurring.class, 12345)));
|
||||
assertThat(thrown).hasMessageThat().contains("autorenew");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,9 +26,7 @@ import com.googlecode.objectify.Key;
|
|||
import google.registry.model.EntityTestCase;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/** Unit tests for {@link LrpTokenEntity}. */
|
||||
public class LrpTokenEntityTest extends EntityTestCase {
|
||||
|
@ -36,9 +34,6 @@ public class LrpTokenEntityTest extends EntityTestCase {
|
|||
LrpTokenEntity unredeemedToken;
|
||||
LrpTokenEntity redeemedToken;
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
createTld("tld");
|
||||
|
|
|
@ -21,6 +21,7 @@ import static google.registry.testing.DatastoreHelper.createTld;
|
|||
import static google.registry.testing.DatastoreHelper.newDomainResource;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.HostResourceSubject.assertAboutHosts;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.net.InetAddresses;
|
||||
|
@ -36,16 +37,10 @@ import google.registry.model.transfer.TransferStatus;
|
|||
import java.net.InetAddress;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/** Unit tests for {@link HostResource}. */
|
||||
public class HostResourceTest extends EntityTestCase {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
final DateTime day3 = clock.nowUtc();
|
||||
final DateTime day2 = day3.minusDays(1);
|
||||
final DateTime day1 = day2.minusDays(1);
|
||||
|
@ -163,16 +158,24 @@ public class HostResourceTest extends EntityTestCase {
|
|||
|
||||
@Test
|
||||
public void testFailure_uppercaseHostName() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Host name must be in puny-coded, lower-case form");
|
||||
host.asBuilder().setFullyQualifiedHostName("AAA.BBB.CCC");
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> host.asBuilder().setFullyQualifiedHostName("AAA.BBB.CCC"));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Host name must be in puny-coded, lower-case form");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_utf8HostName() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Host name must be in puny-coded, lower-case form");
|
||||
host.asBuilder().setFullyQualifiedHostName("みんな.みんな.みんな");
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> host.asBuilder().setFullyQualifiedHostName("みんな.みんな.みんな"));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Host name must be in puny-coded, lower-case form");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -23,6 +23,7 @@ import static google.registry.testing.DatastoreHelper.createTld;
|
|||
import static google.registry.testing.DatastoreHelper.newDomainApplication;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.DatastoreHelper.persistSimpleResource;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
@ -32,16 +33,10 @@ import google.registry.model.EntityTestCase;
|
|||
import google.registry.model.domain.DomainApplication;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/** Unit tests for {@link DomainApplicationIndex}. */
|
||||
public class DomainApplicationIndexTest extends EntityTestCase {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
createTld("com");
|
||||
|
@ -49,16 +44,20 @@ public class DomainApplicationIndexTest extends EntityTestCase {
|
|||
|
||||
@Test
|
||||
public void testFailure_create_nullReferences() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Keys must not be null or empty.");
|
||||
DomainApplicationIndex.createWithSpecifiedKeys("blah.com", null);
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> DomainApplicationIndex.createWithSpecifiedKeys("blah.com", null));
|
||||
assertThat(thrown).hasMessageThat().contains("Keys must not be null or empty.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_create_emptyReferences() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Keys must not be null or empty.");
|
||||
createWithSpecifiedKeys("blah.com", ImmutableSet.<Key<DomainApplication>>of());
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> createWithSpecifiedKeys("blah.com", ImmutableSet.<Key<DomainApplication>>of()));
|
||||
assertThat(thrown).hasMessageThat().contains("Keys must not be null or empty.");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -27,16 +27,11 @@ import google.registry.model.EntityTestCase;
|
|||
import google.registry.model.host.HostResource;
|
||||
import google.registry.model.index.ForeignKeyIndex.ForeignKeyHostIndex;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/** Unit tests for {@link ForeignKeyIndex}. */
|
||||
public class ForeignKeyIndexTest extends EntityTestCase {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
createTld("com");
|
||||
|
|
|
@ -19,6 +19,7 @@ import static google.registry.model.ofy.CommitLogBucket.getBucketKey;
|
|||
import static google.registry.model.ofy.CommitLogBucket.loadAllBuckets;
|
||||
import static google.registry.model.ofy.CommitLogBucket.loadBucket;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
|
@ -29,7 +30,6 @@ import google.registry.testing.InjectRule;
|
|||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -44,10 +44,6 @@ public class CommitLogBucketTest {
|
|||
|
||||
@Rule
|
||||
public final InjectRule inject = new InjectRule();
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
CommitLogBucket bucket;
|
||||
|
||||
@Before
|
||||
|
@ -69,16 +65,16 @@ public class CommitLogBucketTest {
|
|||
|
||||
@Test
|
||||
public void test_getBucketKey_bucketNumberTooLow_throws() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("0 not in [");
|
||||
getBucketKey(0);
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(IllegalArgumentException.class, () -> getBucketKey(0));
|
||||
assertThat(thrown).hasMessageThat().contains("0 not in [");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getBucketKey_bucketNumberTooHigh_throws() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("11 not in [");
|
||||
getBucketKey(11);
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(IllegalArgumentException.class, () -> getBucketKey(11));
|
||||
assertThat(thrown).hasMessageThat().contains("11 not in [");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
package google.registry.model.ofy;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
|
@ -23,7 +24,6 @@ import google.registry.testing.AppEngineRule;
|
|||
import org.joda.time.DateTime;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -36,9 +36,6 @@ public class CommitLogCheckpointTest {
|
|||
.withDatastore()
|
||||
.build();
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private static final DateTime T1 = START_OF_TIME;
|
||||
private static final DateTime T2 = START_OF_TIME.plusMillis(1);
|
||||
private static final DateTime T3 = START_OF_TIME.plusMillis(2);
|
||||
|
@ -60,29 +57,43 @@ public class CommitLogCheckpointTest {
|
|||
|
||||
@Test
|
||||
public void test_create_notEnoughBucketTimestamps_throws() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Bucket ids are incorrect");
|
||||
CommitLogCheckpoint.create(DateTime.now(UTC), ImmutableMap.of(1, T1, 2, T2));
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> CommitLogCheckpoint.create(DateTime.now(UTC), ImmutableMap.of(1, T1, 2, T2)));
|
||||
assertThat(thrown).hasMessageThat().contains("Bucket ids are incorrect");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_create_tooManyBucketTimestamps_throws() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Bucket ids are incorrect");
|
||||
CommitLogCheckpoint.create(DateTime.now(UTC), ImmutableMap.of(1, T1, 2, T2, 3, T3, 4, T1));
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
CommitLogCheckpoint.create(
|
||||
DateTime.now(UTC), ImmutableMap.of(1, T1, 2, T2, 3, T3, 4, T1)));
|
||||
assertThat(thrown).hasMessageThat().contains("Bucket ids are incorrect");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_create_wrongBucketIds_throws() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Bucket ids are incorrect");
|
||||
CommitLogCheckpoint.create(DateTime.now(UTC), ImmutableMap.of(0, T1, 1, T2, 2, T3));
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
CommitLogCheckpoint.create(
|
||||
DateTime.now(UTC), ImmutableMap.of(0, T1, 1, T2, 2, T3)));
|
||||
assertThat(thrown).hasMessageThat().contains("Bucket ids are incorrect");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_create_wrongBucketIdOrder_throws() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Bucket ids are incorrect");
|
||||
CommitLogCheckpoint.create(DateTime.now(UTC), ImmutableMap.of(2, T2, 1, T1, 3, T3));
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
CommitLogCheckpoint.create(
|
||||
DateTime.now(UTC), ImmutableMap.of(2, T2, 1, T1, 3, T3)));
|
||||
assertThat(thrown).hasMessageThat().contains("Bucket ids are incorrect");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import static com.googlecode.objectify.ObjectifyService.register;
|
|||
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
|
||||
import static google.registry.model.ofy.CommitLogBucket.getBucketKey;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.googlecode.objectify.Key;
|
||||
|
@ -37,7 +38,6 @@ import org.joda.time.DateTime;
|
|||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -50,9 +50,6 @@ public class OfyCommitLogTest {
|
|||
.withDatastore()
|
||||
.build();
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Rule
|
||||
public final InjectRule inject = new InjectRule();
|
||||
|
||||
|
@ -163,74 +160,91 @@ public class OfyCommitLogTest {
|
|||
public void testTransactNew_deleteNotBackedUpKind_throws() throws Exception {
|
||||
final CommitLogManifest backupsArentAllowedOnMe =
|
||||
CommitLogManifest.create(getBucketKey(1), clock.nowUtc(), ImmutableSet.<Key<?>>of());
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Can't save/delete a @NotBackedUp");
|
||||
ofy().transactNew(() -> ofy().delete().entity(backupsArentAllowedOnMe));
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> ofy().transactNew(() -> ofy().delete().entity(backupsArentAllowedOnMe)));
|
||||
assertThat(thrown).hasMessageThat().contains("Can't save/delete a @NotBackedUp");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransactNew_saveNotBackedUpKind_throws() throws Exception {
|
||||
final CommitLogManifest backupsArentAllowedOnMe =
|
||||
CommitLogManifest.create(getBucketKey(1), clock.nowUtc(), ImmutableSet.<Key<?>>of());
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Can't save/delete a @NotBackedUp");
|
||||
ofy().transactNew(() -> ofy().save().entity(backupsArentAllowedOnMe));
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> ofy().transactNew(() -> ofy().save().entity(backupsArentAllowedOnMe)));
|
||||
assertThat(thrown).hasMessageThat().contains("Can't save/delete a @NotBackedUp");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransactNew_deleteVirtualEntityKey_throws() throws Exception {
|
||||
final Key<TestVirtualObject> virtualEntityKey = TestVirtualObject.createKey("virtual");
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Can't save/delete a @VirtualEntity");
|
||||
ofy().transactNew(() -> ofy().delete().key(virtualEntityKey));
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> ofy().transactNew(() -> ofy().delete().key(virtualEntityKey)));
|
||||
assertThat(thrown).hasMessageThat().contains("Can't save/delete a @VirtualEntity");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransactNew_saveVirtualEntity_throws() throws Exception {
|
||||
final TestVirtualObject virtualEntity = TestVirtualObject.create("virtual");
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Can't save/delete a @VirtualEntity");
|
||||
ofy().transactNew(() -> ofy().save().entity(virtualEntity));
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> ofy().transactNew(() -> ofy().save().entity(virtualEntity)));
|
||||
assertThat(thrown).hasMessageThat().contains("Can't save/delete a @VirtualEntity");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_deleteWithoutBackup_withVirtualEntityKey_throws() throws Exception {
|
||||
final Key<TestVirtualObject> virtualEntityKey = TestVirtualObject.createKey("virtual");
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Can't save/delete a @VirtualEntity");
|
||||
ofy().deleteWithoutBackup().key(virtualEntityKey);
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> ofy().deleteWithoutBackup().key(virtualEntityKey));
|
||||
assertThat(thrown).hasMessageThat().contains("Can't save/delete a @VirtualEntity");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_saveWithoutBackup_withVirtualEntity_throws() throws Exception {
|
||||
final TestVirtualObject virtualEntity = TestVirtualObject.create("virtual");
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Can't save/delete a @VirtualEntity");
|
||||
ofy().saveWithoutBackup().entity(virtualEntity);
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class, () -> ofy().saveWithoutBackup().entity(virtualEntity));
|
||||
assertThat(thrown).hasMessageThat().contains("Can't save/delete a @VirtualEntity");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransact_twoSavesOnSameKey_throws() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Multiple entries with same key");
|
||||
ofy()
|
||||
.transact(
|
||||
() -> {
|
||||
ofy().save().entity(Root.create(1, getCrossTldKey()));
|
||||
ofy().save().entity(Root.create(1, getCrossTldKey()));
|
||||
});
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
ofy()
|
||||
.transact(
|
||||
() -> {
|
||||
ofy().save().entity(Root.create(1, getCrossTldKey()));
|
||||
ofy().save().entity(Root.create(1, getCrossTldKey()));
|
||||
}));
|
||||
assertThat(thrown).hasMessageThat().contains("Multiple entries with same key");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransact_saveAndDeleteSameKey_throws() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Multiple entries with same key");
|
||||
ofy()
|
||||
.transact(
|
||||
() -> {
|
||||
ofy().save().entity(Root.create(1, getCrossTldKey()));
|
||||
ofy().delete().entity(Root.create(1, getCrossTldKey()));
|
||||
});
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
ofy()
|
||||
.transact(
|
||||
() -> {
|
||||
ofy().save().entity(Root.create(1, getCrossTldKey()));
|
||||
ofy().delete().entity(Root.create(1, getCrossTldKey()));
|
||||
}));
|
||||
assertThat(thrown).hasMessageThat().contains("Multiple entries with same key");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -30,9 +30,7 @@ import com.googlecode.objectify.annotation.Id;
|
|||
import google.registry.model.contact.ContactResource;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -63,9 +61,6 @@ public class OfyFilterTest {
|
|||
helper.tearDown();
|
||||
}
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
/**
|
||||
* Key.create looks up kind metadata for the class of the object it is given. If this happens
|
||||
* before the first reference to ObjectifyService, which statically triggers type registrations,
|
||||
|
|
|
@ -23,6 +23,8 @@ import static google.registry.model.ofy.Ofy.getBaseEntityClassFromEntityOrKey;
|
|||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.newContactResource;
|
||||
import static google.registry.testing.DatastoreHelper.persistActiveContact;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
@ -55,7 +57,6 @@ import org.joda.time.DateTime;
|
|||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -67,10 +68,6 @@ public class OfyTest {
|
|||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
||||
.withDatastore()
|
||||
.build();
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
/** An entity to use in save and delete tests. */
|
||||
private HistoryEntry someObject;
|
||||
|
||||
|
@ -92,13 +89,15 @@ public class OfyTest {
|
|||
.getUpdateAutoTimestamp().getTimestamp();
|
||||
// Set the clock in Ofy to the same time as the backup group root's save time.
|
||||
Ofy ofy = new Ofy(new FakeClock(groupTimestamp));
|
||||
thrown.expect(TimestampInversionException.class);
|
||||
thrown.expectMessage(String.format(
|
||||
"Timestamp inversion between transaction time (%s) and entities rooted under:\n"
|
||||
+ "{Key<?>(ContactResource(\"2-ROID\"))=%s}",
|
||||
groupTimestamp,
|
||||
groupTimestamp));
|
||||
ofy.transact(work);
|
||||
TimestampInversionException thrown =
|
||||
expectThrows(TimestampInversionException.class, () -> ofy.transact(work));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains(
|
||||
String.format(
|
||||
"Timestamp inversion between transaction time (%s) and entities rooted under:\n"
|
||||
+ "{Key<?>(ContactResource(\"2-ROID\"))=%s}",
|
||||
groupTimestamp, groupTimestamp));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -121,60 +120,89 @@ public class OfyTest {
|
|||
|
||||
@Test
|
||||
public void testSavingKeyTwice() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Multiple entries with same key");
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().save().entity(someObject);
|
||||
ofy().save().entity(someObject);
|
||||
}});
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
ofy()
|
||||
.transact(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().save().entity(someObject);
|
||||
ofy().save().entity(someObject);
|
||||
}
|
||||
}));
|
||||
assertThat(thrown).hasMessageThat().contains("Multiple entries with same key");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeletingKeyTwice() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Multiple entries with same key");
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().delete().entity(someObject);
|
||||
ofy().delete().entity(someObject);
|
||||
}});
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
ofy()
|
||||
.transact(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().delete().entity(someObject);
|
||||
ofy().delete().entity(someObject);
|
||||
}
|
||||
}));
|
||||
assertThat(thrown).hasMessageThat().contains("Multiple entries with same key");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveDeleteKey() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Multiple entries with same key");
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().save().entity(someObject);
|
||||
ofy().delete().entity(someObject);
|
||||
}});
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
ofy()
|
||||
.transact(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().save().entity(someObject);
|
||||
ofy().delete().entity(someObject);
|
||||
}
|
||||
}));
|
||||
assertThat(thrown).hasMessageThat().contains("Multiple entries with same key");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteSaveKey() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Multiple entries with same key");
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().delete().entity(someObject);
|
||||
ofy().save().entity(someObject);
|
||||
}});
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
ofy()
|
||||
.transact(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().delete().entity(someObject);
|
||||
ofy().save().entity(someObject);
|
||||
}
|
||||
}));
|
||||
assertThat(thrown).hasMessageThat().contains("Multiple entries with same key");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSavingKeyTwiceInOneCall() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().save().entities(someObject, someObject);
|
||||
}});
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
ofy()
|
||||
.transact(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().save().entities(someObject, someObject);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/** Simple entity class with lifecycle callbacks. */
|
||||
|
@ -375,17 +403,24 @@ public class OfyTest {
|
|||
|
||||
@Test
|
||||
public void test_getBaseEntityClassFromEntityOrKey_unregisteredEntity() {
|
||||
thrown.expect(IllegalStateException.class);
|
||||
thrown.expectMessage("SystemClock");
|
||||
getBaseEntityClassFromEntityOrKey(new SystemClock());
|
||||
IllegalStateException thrown =
|
||||
expectThrows(
|
||||
IllegalStateException.class,
|
||||
() -> getBaseEntityClassFromEntityOrKey(new SystemClock()));
|
||||
assertThat(thrown).hasMessageThat().contains("SystemClock");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getBaseEntityClassFromEntityOrKey_unregisteredEntityKey() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("UnknownKind");
|
||||
getBaseEntityClassFromEntityOrKey(Key.create(
|
||||
com.google.appengine.api.datastore.KeyFactory.createKey("UnknownKind", 1)));
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
getBaseEntityClassFromEntityOrKey(
|
||||
Key.create(
|
||||
com.google.appengine.api.datastore.KeyFactory.createKey(
|
||||
"UnknownKind", 1))));
|
||||
assertThat(thrown).hasMessageThat().contains("UnknownKind");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -38,7 +38,6 @@ import org.joda.time.DateTime;
|
|||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -54,9 +53,6 @@ public class PollMessageExternalKeyConverterTest {
|
|||
@Rule
|
||||
public InjectRule inject = new InjectRule();
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
HistoryEntry historyEntry;
|
||||
FakeClock clock = new FakeClock(DateTime.parse("2007-07-07T01:01:01Z"));
|
||||
|
||||
|
|
|
@ -19,21 +19,16 @@ import static google.registry.model.rde.RdeMode.FULL;
|
|||
import static google.registry.model.rde.RdeMode.THIN;
|
||||
import static google.registry.model.rde.RdeNamingUtils.makePartialName;
|
||||
import static google.registry.model.rde.RdeNamingUtils.makeRydeFilename;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
/** Unit tests for {@link RdeNamingUtils}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class RdeNamingUtilsTest {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void testMakeRydeFilename_rdeDeposit() throws Exception {
|
||||
assertThat(makeRydeFilename("numbness", DateTime.parse("1984-12-18TZ"), FULL, 1, 0))
|
||||
|
@ -54,8 +49,9 @@ public class RdeNamingUtilsTest {
|
|||
|
||||
@Test
|
||||
public void testMakeRydeFilename_timestampNotAtTheWitchingHour_throwsIae() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
makeRydeFilename("wretched", DateTime.parse("2000-12-18T04:20Z"), THIN, 1, 0);
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> makeRydeFilename("wretched", DateTime.parse("2000-12-18T04:20Z"), THIN, 1, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -19,6 +19,7 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
|
|||
import static google.registry.model.rde.RdeMode.FULL;
|
||||
import static google.registry.model.rde.RdeRevision.getNextRevision;
|
||||
import static google.registry.model.rde.RdeRevision.saveRevision;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
|
||||
import com.google.common.base.VerifyException;
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
|
@ -26,7 +27,6 @@ import google.registry.testing.AppEngineRule;
|
|||
import org.joda.time.DateTime;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -36,10 +36,6 @@ public class RdeRevisionTest {
|
|||
|
||||
@Rule
|
||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void testGetNextRevision_objectDoesntExist_returnsZero() throws Exception {
|
||||
assertThat(getNextRevision("torment", DateTime.parse("1984-12-18TZ"), FULL))
|
||||
|
@ -70,25 +66,37 @@ public class RdeRevisionTest {
|
|||
|
||||
@Test
|
||||
public void testSaveRevision_objectDoesntExist_newRevisionIsOne_throwsVe() throws Exception {
|
||||
thrown.expect(VerifyException.class);
|
||||
thrown.expectMessage("object missing");
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
saveRevision("despondency", DateTime.parse("1984-12-18TZ"), FULL, 1);
|
||||
}});
|
||||
VerifyException thrown =
|
||||
expectThrows(
|
||||
VerifyException.class,
|
||||
() ->
|
||||
ofy()
|
||||
.transact(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
saveRevision("despondency", DateTime.parse("1984-12-18TZ"), FULL, 1);
|
||||
}
|
||||
}));
|
||||
assertThat(thrown).hasMessageThat().contains("object missing");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveRevision_objectExistsAtZero_newRevisionIsZero_throwsVe() throws Exception {
|
||||
save("melancholy", DateTime.parse("1984-12-18TZ"), FULL, 0);
|
||||
thrown.expect(VerifyException.class);
|
||||
thrown.expectMessage("object already created");
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
saveRevision("melancholy", DateTime.parse("1984-12-18TZ"), FULL, 0);
|
||||
}});
|
||||
VerifyException thrown =
|
||||
expectThrows(
|
||||
VerifyException.class,
|
||||
() ->
|
||||
ofy()
|
||||
.transact(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
saveRevision("melancholy", DateTime.parse("1984-12-18TZ"), FULL, 0);
|
||||
}
|
||||
}));
|
||||
assertThat(thrown).hasMessageThat().contains("object already created");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -110,31 +118,45 @@ public class RdeRevisionTest {
|
|||
@Test
|
||||
public void testSaveRevision_objectExistsAtZero_newRevisionIsTwo_throwsVe() throws Exception {
|
||||
save("melancholy", DateTime.parse("1984-12-18TZ"), FULL, 0);
|
||||
thrown.expect(VerifyException.class);
|
||||
thrown.expectMessage("should be at 1 ");
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
saveRevision("melancholy", DateTime.parse("1984-12-18TZ"), FULL, 2);
|
||||
}});
|
||||
VerifyException thrown =
|
||||
expectThrows(
|
||||
VerifyException.class,
|
||||
() ->
|
||||
ofy()
|
||||
.transact(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
saveRevision("melancholy", DateTime.parse("1984-12-18TZ"), FULL, 2);
|
||||
}
|
||||
}));
|
||||
assertThat(thrown).hasMessageThat().contains("should be at 1 ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveRevision_negativeRevision_throwsIae() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Negative revision");
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
saveRevision("melancholy", DateTime.parse("1984-12-18TZ"), FULL, -1);
|
||||
}});
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
ofy()
|
||||
.transact(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
saveRevision("melancholy", DateTime.parse("1984-12-18TZ"), FULL, -1);
|
||||
}
|
||||
}));
|
||||
assertThat(thrown).hasMessageThat().contains("Negative revision");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveRevision_callerNotInTransaction_throwsIse() throws Exception {
|
||||
thrown.expect(IllegalStateException.class);
|
||||
thrown.expectMessage("transaction");
|
||||
saveRevision("frenzy", DateTime.parse("1984-12-18TZ"), FULL, 1);
|
||||
IllegalStateException thrown =
|
||||
expectThrows(
|
||||
IllegalStateException.class,
|
||||
() -> saveRevision("frenzy", DateTime.parse("1984-12-18TZ"), FULL, 1));
|
||||
assertThat(thrown).hasMessageThat().contains("transaction");
|
||||
}
|
||||
|
||||
public static void save(String tld, DateTime date, RdeMode mode, int revision) {
|
||||
|
|
|
@ -26,6 +26,8 @@ import static google.registry.testing.DatastoreHelper.createTld;
|
|||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.DatastoreHelper.persistSimpleResource;
|
||||
import static google.registry.testing.DatastoreHelper.persistSimpleResources;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
@ -40,16 +42,10 @@ import google.registry.model.registrar.Registrar.Type;
|
|||
import google.registry.util.CidrAddressBlock;
|
||||
import org.joda.money.CurrencyUnit;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/** Unit tests for {@link Registrar}. */
|
||||
public class RegistrarTest extends EntityTestCase {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private Registrar registrar;
|
||||
private RegistrarContact abuseAdminContact;
|
||||
|
||||
|
@ -143,23 +139,27 @@ public class RegistrarTest extends EntityTestCase {
|
|||
|
||||
@Test
|
||||
public void testFailure_passwordNull() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Password must be 6-16 characters long.");
|
||||
new Registrar.Builder().setPassword(null);
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class, () -> new Registrar.Builder().setPassword(null));
|
||||
assertThat(thrown).hasMessageThat().contains("Password must be 6-16 characters long.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_passwordTooShort() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Password must be 6-16 characters long.");
|
||||
new Registrar.Builder().setPassword("abcde");
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class, () -> new Registrar.Builder().setPassword("abcde"));
|
||||
assertThat(thrown).hasMessageThat().contains("Password must be 6-16 characters long.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_passwordTooLong() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Password must be 6-16 characters long.");
|
||||
new Registrar.Builder().setPassword("abcdefghijklmnopq");
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> new Registrar.Builder().setPassword("abcdefghijklmnopq"));
|
||||
assertThat(thrown).hasMessageThat().contains("Password must be 6-16 characters long.");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -172,14 +172,14 @@ public class RegistrarTest extends EntityTestCase {
|
|||
|
||||
@Test
|
||||
public void testFailure_clientId_tooShort() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
new Registrar.Builder().setClientId("ab");
|
||||
assertThrows(IllegalArgumentException.class, () -> new Registrar.Builder().setClientId("ab"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_clientId_tooLong() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
new Registrar.Builder().setClientId("abcdefghijklmnopq");
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> new Registrar.Builder().setClientId("abcdefghijklmnopq"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -318,87 +318,103 @@ public class RegistrarTest extends EntityTestCase {
|
|||
|
||||
@Test
|
||||
public void testFailure_missingRegistrarType() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Registrar type cannot be null");
|
||||
new Registrar.Builder().setRegistrarName("blah").build();
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> new Registrar.Builder().setRegistrarName("blah").build());
|
||||
assertThat(thrown).hasMessageThat().contains("Registrar type cannot be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_missingRegistrarName() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Registrar name cannot be null");
|
||||
new Registrar.Builder().setClientId("blahid").setType(Registrar.Type.TEST).build();
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
new Registrar.Builder().setClientId("blahid").setType(Registrar.Type.TEST).build());
|
||||
assertThat(thrown).hasMessageThat().contains("Registrar name cannot be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_missingAddress() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Must specify at least one of localized or internationalized address");
|
||||
new Registrar.Builder()
|
||||
.setClientId("blahid")
|
||||
.setType(Registrar.Type.TEST)
|
||||
.setRegistrarName("Blah Co")
|
||||
.build();
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
new Registrar.Builder()
|
||||
.setClientId("blahid")
|
||||
.setType(Registrar.Type.TEST)
|
||||
.setRegistrarName("Blah Co")
|
||||
.build());
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Must specify at least one of localized or internationalized address");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_badIanaIdForInternal() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
new Registrar.Builder().setType(Type.INTERNAL).setIanaIdentifier(8L).build();
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> new Registrar.Builder().setType(Type.INTERNAL).setIanaIdentifier(8L).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_badIanaIdForPdt() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
new Registrar.Builder().setType(Type.PDT).setIanaIdentifier(8L).build();
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> new Registrar.Builder().setType(Type.PDT).setIanaIdentifier(8L).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_badIanaIdForExternalMonitoring() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
registrar.asBuilder().setType(Type.EXTERNAL_MONITORING).setIanaIdentifier(8L).build();
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
registrar.asBuilder().setType(Type.EXTERNAL_MONITORING).setIanaIdentifier(8L).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_missingIanaIdForReal() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
new Registrar.Builder().setType(Type.REAL).build();
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> new Registrar.Builder().setType(Type.REAL).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_missingIanaIdForInternal() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
new Registrar.Builder().setType(Type.INTERNAL).build();
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> new Registrar.Builder().setType(Type.INTERNAL).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_missingIanaIdForPdt() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
new Registrar.Builder().setType(Type.PDT).build();
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> new Registrar.Builder().setType(Type.PDT).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_missingIanaIdForExternalMonitoring() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
new Registrar.Builder().setType(Type.EXTERNAL_MONITORING).build();
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> new Registrar.Builder().setType(Type.EXTERNAL_MONITORING).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_phonePasscodeTooShort() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
new Registrar.Builder().setPhonePasscode("0123");
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> new Registrar.Builder().setPhonePasscode("0123"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_phonePasscodeTooLong() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
new Registrar.Builder().setPhonePasscode("012345");
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> new Registrar.Builder().setPhonePasscode("012345"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_phonePasscodeInvalidCharacters() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
new Registrar.Builder().setPhonePasscode("code1");
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> new Registrar.Builder().setPhonePasscode("code1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -420,29 +436,29 @@ public class RegistrarTest extends EntityTestCase {
|
|||
|
||||
@Test
|
||||
public void testFailure_loadByClientId_clientIdIsNull() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("clientId must be specified");
|
||||
Registrar.loadByClientId(null);
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(IllegalArgumentException.class, () -> Registrar.loadByClientId(null));
|
||||
assertThat(thrown).hasMessageThat().contains("clientId must be specified");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_loadByClientId_clientIdIsEmpty() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("clientId must be specified");
|
||||
Registrar.loadByClientId("");
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(IllegalArgumentException.class, () -> Registrar.loadByClientId(""));
|
||||
assertThat(thrown).hasMessageThat().contains("clientId must be specified");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_loadByClientIdCached_clientIdIsNull() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("clientId must be specified");
|
||||
Registrar.loadByClientIdCached(null);
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(IllegalArgumentException.class, () -> Registrar.loadByClientIdCached(null));
|
||||
assertThat(thrown).hasMessageThat().contains("clientId must be specified");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_loadByClientIdCached_clientIdIsEmpty() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("clientId must be specified");
|
||||
Registrar.loadByClientIdCached("");
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(IllegalArgumentException.class, () -> Registrar.loadByClientIdCached(""));
|
||||
assertThat(thrown).hasMessageThat().contains("clientId must be specified");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,12 +17,12 @@ package google.registry.model.registry;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth8.assertThat;
|
||||
import static google.registry.testing.DatastoreHelper.createTlds;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
|
||||
import com.google.common.net.InternetDomainName;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -32,10 +32,6 @@ public class RegistriesTest {
|
|||
|
||||
@Rule
|
||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private void initTestTlds() {
|
||||
createTlds("foo", "a.b.c"); // Test a multipart tld.
|
||||
}
|
||||
|
@ -61,8 +57,7 @@ public class RegistriesTest {
|
|||
@Test
|
||||
public void testAssertTldExists_doesntExist() {
|
||||
initTestTlds();
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
Registries.assertTldExists("baz");
|
||||
assertThrows(IllegalArgumentException.class, () -> Registries.assertTldExists("baz"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -44,15 +44,10 @@ import java.math.BigDecimal;
|
|||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/** Unit tests for {@link Registry}. */
|
||||
public class RegistryTest extends EntityTestCase {
|
||||
|
||||
@Rule public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
Registry registry;
|
||||
|
||||
@Before
|
||||
|
@ -71,8 +66,7 @@ public class RegistryTest extends EntityTestCase {
|
|||
@Test
|
||||
public void testFailure_registryNotFound() throws Exception {
|
||||
createTld("foo");
|
||||
thrown.expect(RegistryNotFoundException.class);
|
||||
Registry.get("baz");
|
||||
assertThrows(RegistryNotFoundException.class, () -> Registry.get("baz"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -202,11 +196,17 @@ public class RegistryTest extends EntityTestCase {
|
|||
ReservedList rl3 = persistReservedList(
|
||||
"tld-reserved057",
|
||||
"lol,RESERVED_FOR_ANCHOR_TENANT,another_conflict");
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage(
|
||||
"auth code conflicts for labels: [lol=[conflict1, conflict2, another_conflict]]");
|
||||
@SuppressWarnings("unused")
|
||||
Registry unused = Registry.get("tld").asBuilder().setReservedLists(rl1, rl2, rl3).build();
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> {
|
||||
@SuppressWarnings("unused")
|
||||
Registry unused =
|
||||
Registry.get("tld").asBuilder().setReservedLists(rl1, rl2, rl3).build();
|
||||
});
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("auth code conflicts for labels: [lol=[conflict1, conflict2, another_conflict]]");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -354,116 +354,167 @@ public class RegistryTest extends EntityTestCase {
|
|||
|
||||
@Test
|
||||
public void testFailure_tldNeverSet() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("No registry TLD specified");
|
||||
new Registry.Builder().build();
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(IllegalArgumentException.class, () -> new Registry.Builder().build());
|
||||
assertThat(thrown).hasMessageThat().contains("No registry TLD specified");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_setTldStr_null() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("TLD must not be null");
|
||||
new Registry.Builder().setTldStr(null);
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(IllegalArgumentException.class, () -> new Registry.Builder().setTldStr(null));
|
||||
assertThat(thrown).hasMessageThat().contains("TLD must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_setTldStr_invalidTld() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown
|
||||
.expectMessage("Cannot create registry for TLD that is not a valid, canonical domain name");
|
||||
new Registry.Builder().setTldStr(".tld").build();
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class, () -> new Registry.Builder().setTldStr(".tld").build());
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Cannot create registry for TLD that is not a valid, canonical domain name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_setTldStr_nonCanonicalTld() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown
|
||||
.expectMessage("Cannot create registry for TLD that is not a valid, canonical domain name");
|
||||
new Registry.Builder().setTldStr("TLD").build();
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class, () -> new Registry.Builder().setTldStr("TLD").build());
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Cannot create registry for TLD that is not a valid, canonical domain name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_tldStatesOutOfOrder() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
Registry.get("tld").asBuilder()
|
||||
.setTldStateTransitions(ImmutableSortedMap.of(
|
||||
clock.nowUtc(), TldState.SUNRUSH, clock.nowUtc().plusMonths(1), TldState.SUNRISE))
|
||||
.build();
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
Registry.get("tld")
|
||||
.asBuilder()
|
||||
.setTldStateTransitions(
|
||||
ImmutableSortedMap.of(
|
||||
clock.nowUtc(),
|
||||
TldState.SUNRUSH,
|
||||
clock.nowUtc().plusMonths(1),
|
||||
TldState.SUNRISE))
|
||||
.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_duplicateTldState() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
Registry.get("tld").asBuilder()
|
||||
.setTldStateTransitions(ImmutableSortedMap.of(
|
||||
clock.nowUtc(), TldState.SUNRUSH, clock.nowUtc().plusMonths(1), TldState.SUNRUSH))
|
||||
.build();
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
Registry.get("tld")
|
||||
.asBuilder()
|
||||
.setTldStateTransitions(
|
||||
ImmutableSortedMap.of(
|
||||
clock.nowUtc(),
|
||||
TldState.SUNRUSH,
|
||||
clock.nowUtc().plusMonths(1),
|
||||
TldState.SUNRUSH))
|
||||
.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_pricingEngineIsRequired() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("All registries must have a configured pricing engine");
|
||||
new Registry.Builder().setTldStr("invalid").build();
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> new Registry.Builder().setTldStr("invalid").build());
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("All registries must have a configured pricing engine");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_negativeRenewBillingCostTransitionValue() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("billing cost cannot be negative");
|
||||
Registry.get("tld").asBuilder()
|
||||
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, -42)));
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
Registry.get("tld")
|
||||
.asBuilder()
|
||||
.setRenewBillingCostTransitions(
|
||||
ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, -42))));
|
||||
assertThat(thrown).hasMessageThat().contains("billing cost cannot be negative");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_negativeCreateBillingCost() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("createBillingCost cannot be negative");
|
||||
Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, -42));
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, -42)));
|
||||
assertThat(thrown).hasMessageThat().contains("createBillingCost cannot be negative");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_negativeRestoreBillingCost() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("restoreBillingCost cannot be negative");
|
||||
Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, -42));
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, -42)));
|
||||
assertThat(thrown).hasMessageThat().contains("restoreBillingCost cannot be negative");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_negativeServerStatusChangeBillingCost() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("billing cost cannot be negative");
|
||||
Registry.get("tld").asBuilder().setServerStatusChangeBillingCost(Money.of(USD, -42));
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
Registry.get("tld")
|
||||
.asBuilder()
|
||||
.setServerStatusChangeBillingCost(Money.of(USD, -42)));
|
||||
assertThat(thrown).hasMessageThat().contains("billing cost cannot be negative");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_renewBillingCostTransitionValue_wrongCurrency() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("cost must be in the registry's currency");
|
||||
Registry.get("tld").asBuilder()
|
||||
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 42)))
|
||||
.build();
|
||||
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");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_createBillingCost_wrongCurrency() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("cost must be in the registry's currency");
|
||||
Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(EUR, 42)).build();
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(EUR, 42)).build());
|
||||
assertThat(thrown).hasMessageThat().contains("cost must be in the registry's currency");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_restoreBillingCost_wrongCurrency() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("cost must be in the registry's currency");
|
||||
Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(EUR, 42)).build();
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(EUR, 42)).build());
|
||||
assertThat(thrown).hasMessageThat().contains("cost must be in the registry's currency");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_serverStatusChangeBillingCost_wrongCurrency() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("cost must be in the registry's currency");
|
||||
Registry.get("tld").asBuilder().setServerStatusChangeBillingCost(Money.of(EUR, 42)).build();
|
||||
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");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -493,11 +544,15 @@ public class RegistryTest extends EntityTestCase {
|
|||
|
||||
@Test
|
||||
public void testFailure_eapFee_wrongCurrency() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("All EAP fees must be in the registry's currency");
|
||||
Registry.get("tld").asBuilder()
|
||||
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
|
||||
.build();
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
Registry.get("tld")
|
||||
.asBuilder()
|
||||
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
|
||||
.build());
|
||||
assertThat(thrown).hasMessageThat().contains("All EAP fees must be in the registry's currency");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -21,6 +21,8 @@ import static google.registry.testing.DatastoreHelper.createTld;
|
|||
import static google.registry.testing.DatastoreHelper.persistPremiumList;
|
||||
import static google.registry.testing.DatastoreHelper.persistReservedList;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import google.registry.model.registry.Registry;
|
||||
|
@ -29,7 +31,6 @@ import google.registry.testing.AppEngineRule;
|
|||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -37,7 +38,6 @@ import org.junit.runners.JUnit4;
|
|||
@RunWith(JUnit4.class)
|
||||
public class PremiumListTest {
|
||||
|
||||
@Rule public final ExpectedException thrown = ExpectedException.none();
|
||||
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
|
||||
|
||||
@Before
|
||||
|
@ -56,14 +56,15 @@ public class PremiumListTest {
|
|||
|
||||
@Test
|
||||
public void testSave_badSyntax() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
persistPremiumList("gtld1", "lol,nonsense USD,e,e # yup");
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> persistPremiumList("gtld1", "lol,nonsense USD,e,e # yup"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSave_invalidCurrencySymbol() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
persistReservedList("gtld1", "lol,XBTC 200");
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> persistReservedList("gtld1", "lol,XBTC 200"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -80,13 +81,22 @@ public class PremiumListTest {
|
|||
|
||||
@Test
|
||||
public void testParse_cannotIncludeDuplicateLabels() {
|
||||
thrown.expect(IllegalStateException.class);
|
||||
thrown.expectMessage(
|
||||
"List 'tld' cannot contain duplicate labels. Dupes (with counts) were: [lol x 2]");
|
||||
PremiumList.get("tld")
|
||||
.get()
|
||||
.parse(
|
||||
ImmutableList.of(
|
||||
"lol,USD 100", "rofl,USD 90", "paper,USD 80", "wood,USD 70", "lol,USD 200"));
|
||||
IllegalStateException thrown =
|
||||
expectThrows(
|
||||
IllegalStateException.class,
|
||||
() ->
|
||||
PremiumList.get("tld")
|
||||
.get()
|
||||
.parse(
|
||||
ImmutableList.of(
|
||||
"lol,USD 100",
|
||||
"rofl,USD 90",
|
||||
"paper,USD 80",
|
||||
"wood,USD 70",
|
||||
"lol,USD 200")));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains(
|
||||
"List 'tld' cannot contain duplicate labels. Dupes (with counts) were: [lol x 2]");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ import static google.registry.testing.DatastoreHelper.createTld;
|
|||
import static google.registry.testing.DatastoreHelper.loadPremiumListEntries;
|
||||
import static google.registry.testing.DatastoreHelper.persistPremiumList;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static org.joda.time.Duration.standardMinutes;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
@ -52,7 +53,6 @@ import org.joda.money.Money;
|
|||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -60,7 +60,6 @@ import org.junit.runners.JUnit4;
|
|||
@RunWith(JUnit4.class)
|
||||
public class PremiumListUtilsTest {
|
||||
|
||||
@Rule public final ExpectedException thrown = ExpectedException.none();
|
||||
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
|
||||
|
||||
@Before
|
||||
|
@ -112,9 +111,10 @@ public class PremiumListUtilsTest {
|
|||
public void testGetPremiumPrice_throwsExceptionWhenNonExistentPremiumListConfigured()
|
||||
throws Exception {
|
||||
deletePremiumList(PremiumList.get("tld").get());
|
||||
thrown.expect(IllegalStateException.class);
|
||||
thrown.expectMessage("Could not load premium list 'tld'");
|
||||
getPremiumPrice("blah", Registry.get("tld"));
|
||||
IllegalStateException thrown =
|
||||
expectThrows(
|
||||
IllegalStateException.class, () -> getPremiumPrice("blah", Registry.get("tld")));
|
||||
assertThat(thrown).hasMessageThat().contains("Could not load premium list 'tld'");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -33,6 +33,8 @@ import static google.registry.monitoring.metrics.contrib.LongMetricSubject.asser
|
|||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.persistReservedList;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
@ -49,7 +51,6 @@ import org.joda.time.DateTime;
|
|||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -60,9 +61,6 @@ public class ReservedListTest {
|
|||
@Rule
|
||||
public final InjectRule inject = new InjectRule();
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Rule
|
||||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
||||
.withDatastore()
|
||||
|
@ -269,9 +267,13 @@ public class ReservedListTest {
|
|||
assertThat(matchesAnchorTenantReservation(InternetDomainName.from("lol.tld"), "foo")).isTrue();
|
||||
assertThat(matchesAnchorTenantReservation(InternetDomainName.from("lol.tld"), "bar")).isFalse();
|
||||
persistReservedList("reserved2", "lol,RESERVED_FOR_ANCHOR_TENANT,bar");
|
||||
thrown.expect(IllegalStateException.class);
|
||||
thrown.expectMessage("There are conflicting auth codes for domain: lol.tld");
|
||||
matchesAnchorTenantReservation(InternetDomainName.from("lol.tld"), "bar");
|
||||
IllegalStateException thrown =
|
||||
expectThrows(
|
||||
IllegalStateException.class,
|
||||
() -> matchesAnchorTenantReservation(InternetDomainName.from("lol.tld"), "bar"));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("There are conflicting auth codes for domain: lol.tld");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -468,88 +470,120 @@ public class ReservedListTest {
|
|||
|
||||
@Test
|
||||
public void testSave_badSyntax() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Could not parse line in reserved list");
|
||||
persistReservedList("tld", "lol,FULLY_BLOCKED,e,e # yup");
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> persistReservedList("tld", "lol,FULLY_BLOCKED,e,e # yup"));
|
||||
assertThat(thrown).hasMessageThat().contains("Could not parse line in reserved list");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSave_badReservationType() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
persistReservedList("tld", "lol,FULLY_BLOCKZ # yup");
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> persistReservedList("tld", "lol,FULLY_BLOCKZ # yup"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSave_additionalRestrictionWithIncompatibleReservationType() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Only anchor tenant and nameserver restricted reservations "
|
||||
+ "should have restrictions imposed");
|
||||
persistResource(
|
||||
Registry.get("tld")
|
||||
.asBuilder()
|
||||
.setReservedLists(
|
||||
ImmutableSet.of(persistReservedList("reserved1", "lol,FULLY_BLOCKED,foobar1")))
|
||||
.build());
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
persistResource(
|
||||
Registry.get("tld")
|
||||
.asBuilder()
|
||||
.setReservedLists(
|
||||
ImmutableSet.of(
|
||||
persistReservedList("reserved1", "lol,FULLY_BLOCKED,foobar1")))
|
||||
.build()));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains(
|
||||
"Only anchor tenant and nameserver restricted reservations "
|
||||
+ "should have restrictions imposed");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSave_badNameservers_invalidSyntax() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Not a valid domain name: 'ns@.domain.tld'");
|
||||
persistReservedList(
|
||||
"reserved1",
|
||||
"lol,NAMESERVER_RESTRICTED,ns1.domain.tld:ns2.domain.tld",
|
||||
"lol1,NAMESERVER_RESTRICTED,ns1.domain.tld:ns@.domain.tld");
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
persistReservedList(
|
||||
"reserved1",
|
||||
"lol,NAMESERVER_RESTRICTED,ns1.domain.tld:ns2.domain.tld",
|
||||
"lol1,NAMESERVER_RESTRICTED,ns1.domain.tld:ns@.domain.tld"));
|
||||
assertThat(thrown).hasMessageThat().contains("Not a valid domain name: 'ns@.domain.tld'");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSave_badNameservers_tooFewPartsForHostname() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("domain.tld is not a valid nameserver hostname");
|
||||
persistReservedList(
|
||||
"reserved1",
|
||||
"lol,NAMESERVER_RESTRICTED,ns1.domain.tld:ns2.domain.tld",
|
||||
"lol1,NAMESERVER_RESTRICTED,ns1.domain.tld:domain.tld");
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
persistReservedList(
|
||||
"reserved1",
|
||||
"lol,NAMESERVER_RESTRICTED,ns1.domain.tld:ns2.domain.tld",
|
||||
"lol1,NAMESERVER_RESTRICTED,ns1.domain.tld:domain.tld"));
|
||||
assertThat(thrown).hasMessageThat().contains("domain.tld is not a valid nameserver hostname");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSave_noPasswordWithAnchorTenantReservation() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Anchor tenant reservations must have an auth code configured");
|
||||
persistResource(
|
||||
Registry.get("tld")
|
||||
.asBuilder()
|
||||
.setReservedLists(
|
||||
ImmutableSet.of(persistReservedList("reserved1", "lol,RESERVED_FOR_ANCHOR_TENANT")))
|
||||
.build());
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
persistResource(
|
||||
Registry.get("tld")
|
||||
.asBuilder()
|
||||
.setReservedLists(
|
||||
ImmutableSet.of(
|
||||
persistReservedList("reserved1", "lol,RESERVED_FOR_ANCHOR_TENANT")))
|
||||
.build()));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Anchor tenant reservations must have an auth code configured");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSave_noNameserversWithNameserverRestrictedReservation() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage(
|
||||
"Nameserver restricted reservations must have at least one nameserver configured");
|
||||
persistResource(
|
||||
Registry.get("tld")
|
||||
.asBuilder()
|
||||
.setReservedLists(
|
||||
ImmutableSet.of(persistReservedList("reserved1", "lol,NAMESERVER_RESTRICTED")))
|
||||
.build());
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
persistResource(
|
||||
Registry.get("tld")
|
||||
.asBuilder()
|
||||
.setReservedLists(
|
||||
ImmutableSet.of(
|
||||
persistReservedList("reserved1", "lol,NAMESERVER_RESTRICTED")))
|
||||
.build()));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains(
|
||||
"Nameserver restricted reservations must have at least one nameserver configured");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse_cannotIncludeDuplicateLabels() {
|
||||
ReservedList rl = new ReservedList.Builder().setName("blah").build();
|
||||
thrown.expect(IllegalStateException.class);
|
||||
thrown.expectMessage(
|
||||
"List 'blah' cannot contain duplicate labels. Dupes (with counts) were: [lol x 2]");
|
||||
rl.parse(
|
||||
ImmutableList.of(
|
||||
"lol,FULLY_BLOCKED",
|
||||
"rofl,FULLY_BLOCKED",
|
||||
"paper,FULLY_BLOCKED",
|
||||
"wood,FULLY_BLOCKED",
|
||||
"lol,FULLY_BLOCKED"));
|
||||
IllegalStateException thrown =
|
||||
expectThrows(
|
||||
IllegalStateException.class,
|
||||
() ->
|
||||
rl.parse(
|
||||
ImmutableList.of(
|
||||
"lol,FULLY_BLOCKED",
|
||||
"rofl,FULLY_BLOCKED",
|
||||
"paper,FULLY_BLOCKED",
|
||||
"wood,FULLY_BLOCKED",
|
||||
"lol,FULLY_BLOCKED")));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains(
|
||||
"List 'blah' cannot contain duplicate labels. Dupes (with counts) were: [lol x 2]");
|
||||
}
|
||||
|
||||
/** Gets the name of a reserved list. */
|
||||
|
|
|
@ -17,13 +17,13 @@ package google.registry.model.server;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -31,9 +31,6 @@ import org.junit.runners.JUnit4;
|
|||
public class KmsSecretRevisionTest {
|
||||
|
||||
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
|
||||
|
||||
@Rule public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private KmsSecretRevision secretRevision;
|
||||
|
||||
@Before
|
||||
|
@ -49,15 +46,18 @@ public class KmsSecretRevisionTest {
|
|||
|
||||
@Test
|
||||
public void test_setEncryptedValue_tooLong_throwsException() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Secret is greater than 67108864 bytes");
|
||||
secretRevision =
|
||||
persistResource(
|
||||
new KmsSecretRevision.Builder()
|
||||
.setKmsCryptoKeyVersionName("foo")
|
||||
.setParent("bar")
|
||||
.setEncryptedValue(Strings.repeat("a", 64 * 1024 * 1024 + 1))
|
||||
.build());
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
secretRevision =
|
||||
persistResource(
|
||||
new KmsSecretRevision.Builder()
|
||||
.setKmsCryptoKeyVersionName("foo")
|
||||
.setParent("bar")
|
||||
.setEncryptedValue(Strings.repeat("a", 64 * 1024 * 1024 + 1))
|
||||
.build()));
|
||||
assertThat(thrown).hasMessageThat().contains("Secret is greater than 67108864 bytes");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -14,11 +14,13 @@
|
|||
|
||||
package google.registry.model.server;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth8.assertThat;
|
||||
import static google.registry.model.server.Lock.LockState.FREE;
|
||||
import static google.registry.model.server.Lock.LockState.IN_USE;
|
||||
import static google.registry.model.server.Lock.LockState.OWNER_DIED;
|
||||
import static google.registry.model.server.Lock.LockState.TIMED_OUT;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
@ -35,7 +37,6 @@ import org.joda.time.Duration;
|
|||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -56,10 +57,6 @@ public class LockTest {
|
|||
|
||||
@Rule
|
||||
public final InjectRule inject = new InjectRule();
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private Optional<Lock> acquire(String tld, Duration leaseLength, LockState expectedLockState) {
|
||||
Lock.lockMetrics = mock(LockMetrics.class);
|
||||
Optional<Lock> lock = Lock.acquire(RESOURCE_NAME, tld, leaseLength, requestStatusChecker);
|
||||
|
@ -138,8 +135,10 @@ public class LockTest {
|
|||
|
||||
@Test
|
||||
public void testFailure_emptyResourceName() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("resourceName cannot be null or empty");
|
||||
Lock.acquire("", "", TWO_MILLIS, requestStatusChecker);
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> Lock.acquire("", "", TWO_MILLIS, requestStatusChecker));
|
||||
assertThat(thrown).hasMessageThat().contains("resourceName cannot be null or empty");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ package google.registry.model.smd;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.smd.SignedMarkRevocationList.SHARD_SIZE;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static org.joda.time.Duration.standardDays;
|
||||
|
||||
|
@ -26,7 +27,6 @@ import google.registry.testing.FakeClock;
|
|||
import org.joda.time.DateTime;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -38,25 +38,24 @@ public class SignedMarkRevocationListTest {
|
|||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
||||
.withDatastore()
|
||||
.build();
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final FakeClock clock = new FakeClock(DateTime.parse("2013-01-01T00:00:00Z"));
|
||||
|
||||
@Test
|
||||
public void testUnshardedSaveFails() throws Exception {
|
||||
thrown.expect(SignedMarkRevocationList.UnshardedSaveException.class);
|
||||
// Our @Entity's @OnSave method will notice that this shouldn't be saved.
|
||||
ofy()
|
||||
.transact(
|
||||
() -> {
|
||||
SignedMarkRevocationList smdrl =
|
||||
SignedMarkRevocationList.create(
|
||||
ofy().getTransactionTime(), ImmutableMap.of("a", ofy().getTransactionTime()));
|
||||
smdrl.id = 1; // Without an id this won't save anyways.
|
||||
ofy().saveWithoutBackup().entity(smdrl).now();
|
||||
});
|
||||
assertThrows(
|
||||
SignedMarkRevocationList.UnshardedSaveException.class,
|
||||
() ->
|
||||
ofy()
|
||||
.transact(
|
||||
() -> {
|
||||
SignedMarkRevocationList smdrl =
|
||||
SignedMarkRevocationList.create(
|
||||
ofy().getTransactionTime(),
|
||||
ImmutableMap.of("a", ofy().getTransactionTime()));
|
||||
smdrl.id = 1; // Without an id this won't save anyways.
|
||||
ofy().saveWithoutBackup().entity(smdrl).now();
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -112,9 +111,11 @@ public class SignedMarkRevocationListTest {
|
|||
|
||||
@Test
|
||||
public void test_isSmdRevoked_null() throws Exception {
|
||||
thrown.expect(NullPointerException.class);
|
||||
SignedMarkRevocationList.create(START_OF_TIME, ImmutableMap.<String, DateTime>of())
|
||||
.isSmdRevoked(null, clock.nowUtc());
|
||||
assertThrows(
|
||||
NullPointerException.class,
|
||||
() ->
|
||||
SignedMarkRevocationList.create(START_OF_TIME, ImmutableMap.<String, DateTime>of())
|
||||
.isSmdRevoked(null, clock.nowUtc()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -16,6 +16,7 @@ package google.registry.model.tmch;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
|
@ -32,7 +33,6 @@ import org.joda.time.DateTime;
|
|||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -45,9 +45,6 @@ public class ClaimsListShardTest {
|
|||
.withDatastore()
|
||||
.build();
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Rule
|
||||
public final InjectRule inject = new InjectRule();
|
||||
|
||||
|
@ -58,16 +55,19 @@ public class ClaimsListShardTest {
|
|||
|
||||
@Test
|
||||
public void test_unshardedSaveFails() throws Exception {
|
||||
thrown.expect(UnshardedSaveException.class);
|
||||
ofy()
|
||||
.transact(
|
||||
() -> {
|
||||
ClaimsListShard claimsList =
|
||||
ClaimsListShard.create(ofy().getTransactionTime(), ImmutableMap.of("a", "b"));
|
||||
claimsList.id = 1; // Without an id this won't save anyways.
|
||||
claimsList.parent = ClaimsListRevision.createKey();
|
||||
ofy().saveWithoutBackup().entity(claimsList).now();
|
||||
});
|
||||
assertThrows(
|
||||
UnshardedSaveException.class,
|
||||
() ->
|
||||
ofy()
|
||||
.transact(
|
||||
() -> {
|
||||
ClaimsListShard claimsList =
|
||||
ClaimsListShard.create(
|
||||
ofy().getTransactionTime(), ImmutableMap.of("a", "b"));
|
||||
claimsList.id = 1; // Without an id this won't save anyways.
|
||||
claimsList.parent = ClaimsListRevision.createKey();
|
||||
ofy().saveWithoutBackup().entity(claimsList).now();
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -35,7 +35,6 @@ import org.joda.time.DateTime;
|
|||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -58,9 +57,6 @@ public class CommitLogRevisionsTranslatorFactoryTest {
|
|||
@Rule
|
||||
public final InjectRule inject = new InjectRule();
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final FakeClock clock = new FakeClock(START_TIME);
|
||||
|
||||
@Before
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue