mirror of
https://github.com/google/nomulus.git
synced 2025-07-09 04:33:28 +02:00
Migrate all model tests from JUnit 4 to JUnit 5 (#675)
* Make first handful of tests JUnit 5 * Migrate rest of model package to JUnit 5
This commit is contained in:
parent
caa0cd9d61
commit
ca756e14e6
65 changed files with 866 additions and 1000 deletions
|
@ -23,16 +23,13 @@ import com.googlecode.objectify.annotation.Entity;
|
||||||
import google.registry.model.common.CrossTldSingleton;
|
import google.registry.model.common.CrossTldSingleton;
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link CreateAutoTimestamp}. */
|
/** Unit tests for {@link CreateAutoTimestamp}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class CreateAutoTimestampTest {
|
public class CreateAutoTimestampTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine =
|
public final AppEngineRule appEngine =
|
||||||
AppEngineRule.builder()
|
AppEngineRule.builder()
|
||||||
.withDatastoreAndCloudSql()
|
.withDatastoreAndCloudSql()
|
||||||
|
@ -50,7 +47,7 @@ public class CreateAutoTimestampTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSaveSetsTime() {
|
void testSaveSetsTime() {
|
||||||
DateTime transactionTime =
|
DateTime transactionTime =
|
||||||
tm()
|
tm()
|
||||||
.transact(
|
.transact(
|
||||||
|
@ -65,7 +62,7 @@ public class CreateAutoTimestampTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResavingRespectsOriginalTime() {
|
void testResavingRespectsOriginalTime() {
|
||||||
final DateTime oldCreateTime = DateTime.now(UTC).minusDays(1);
|
final DateTime oldCreateTime = DateTime.now(UTC).minusDays(1);
|
||||||
tm()
|
tm()
|
||||||
.transact(
|
.transact(
|
||||||
|
|
|
@ -26,13 +26,10 @@ import com.googlecode.objectify.Key;
|
||||||
import com.googlecode.objectify.annotation.Entity;
|
import com.googlecode.objectify.annotation.Entity;
|
||||||
import com.googlecode.objectify.annotation.EntitySubclass;
|
import com.googlecode.objectify.annotation.EntitySubclass;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link EntityClasses}. */
|
/** Unit tests for {@link EntityClasses}. */
|
||||||
@RunWith(JUnit4.class)
|
class EntityClassesTest {
|
||||||
public class EntityClassesTest {
|
|
||||||
|
|
||||||
// This implements the manual ordering we've been using for the EntityClasses class lists.
|
// This implements the manual ordering we've been using for the EntityClasses class lists.
|
||||||
private static final Ordering<Class<?>> QUALIFIED_CLASS_NAME_ORDERING =
|
private static final Ordering<Class<?>> QUALIFIED_CLASS_NAME_ORDERING =
|
||||||
|
@ -41,12 +38,12 @@ public class EntityClassesTest {
|
||||||
clazz -> clazz.getCanonicalName().substring(clazz.getPackage().getName().length()));
|
clazz -> clazz.getCanonicalName().substring(clazz.getPackage().getName().length()));
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEntityClasses_inAlphabeticalOrder() {
|
void testEntityClasses_inAlphabeticalOrder() {
|
||||||
assertThat(ALL_CLASSES).isInStrictOrder(QUALIFIED_CLASS_NAME_ORDERING);
|
assertThat(ALL_CLASSES).isInStrictOrder(QUALIFIED_CLASS_NAME_ORDERING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEntityClasses_baseEntitiesHaveUniqueKinds() {
|
void testEntityClasses_baseEntitiesHaveUniqueKinds() {
|
||||||
assertWithMessage("base entity kinds")
|
assertWithMessage("base entity kinds")
|
||||||
.about(streams())
|
.about(streams())
|
||||||
.that(ALL_CLASSES.stream().filter(hasAnnotation(Entity.class)).map(Key::getKind))
|
.that(ALL_CLASSES.stream().filter(hasAnnotation(Entity.class)).map(Key::getKind))
|
||||||
|
@ -54,7 +51,7 @@ public class EntityClassesTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEntityClasses_entitySubclassesHaveKindsMatchingBaseEntities() {
|
void testEntityClasses_entitySubclassesHaveKindsMatchingBaseEntities() {
|
||||||
Set<String> baseEntityKinds =
|
Set<String> baseEntityKinds =
|
||||||
ALL_CLASSES
|
ALL_CLASSES
|
||||||
.stream()
|
.stream()
|
||||||
|
@ -73,7 +70,7 @@ public class EntityClassesTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEntityClasses_eitherBaseEntityOrEntitySubclass() {
|
void testEntityClasses_eitherBaseEntityOrEntitySubclass() {
|
||||||
for (Class<?> clazz : ALL_CLASSES) {
|
for (Class<?> clazz : ALL_CLASSES) {
|
||||||
boolean isEntityXorEntitySubclass =
|
boolean isEntityXorEntitySubclass =
|
||||||
clazz.isAnnotationPresent(Entity.class) ^ clazz.isAnnotationPresent(EntitySubclass.class);
|
clazz.isAnnotationPresent(Entity.class) ^ clazz.isAnnotationPresent(EntitySubclass.class);
|
||||||
|
|
|
@ -41,8 +41,6 @@ import java.lang.reflect.Type;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
|
@ -61,9 +59,9 @@ public abstract class EntityTestCase {
|
||||||
|
|
||||||
protected FakeClock fakeClock = new FakeClock(DateTime.now(UTC));
|
protected FakeClock fakeClock = new FakeClock(DateTime.now(UTC));
|
||||||
|
|
||||||
@Rule @RegisterExtension public final AppEngineRule appEngine;
|
@RegisterExtension public final AppEngineRule appEngine;
|
||||||
|
|
||||||
@Rule @RegisterExtension public InjectRule inject = new InjectRule();
|
@RegisterExtension public InjectRule inject = new InjectRule();
|
||||||
|
|
||||||
protected EntityTestCase() {
|
protected EntityTestCase() {
|
||||||
this(JpaEntityCoverageCheck.DISABLED);
|
this(JpaEntityCoverageCheck.DISABLED);
|
||||||
|
@ -78,7 +76,6 @@ public abstract class EntityTestCase {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void injectClock() {
|
public void injectClock() {
|
||||||
inject.setStaticField(Ofy.class, "clock", fakeClock);
|
inject.setStaticField(Ofy.class, "clock", fakeClock);
|
||||||
|
|
|
@ -26,18 +26,18 @@ import google.registry.model.contact.ContactResource;
|
||||||
import google.registry.model.host.HostResource;
|
import google.registry.model.host.HostResource;
|
||||||
import google.registry.testing.TestCacheRule;
|
import google.registry.testing.TestCacheRule;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
/** Unit tests for {@link EppResource}. */
|
/** Unit tests for {@link EppResource}. */
|
||||||
public class EppResourceTest extends EntityTestCase {
|
public class EppResourceTest extends EntityTestCase {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final TestCacheRule testCacheRule =
|
public final TestCacheRule testCacheRule =
|
||||||
new TestCacheRule.Builder().withEppResourceCache(Duration.standardDays(1)).build();
|
new TestCacheRule.Builder().withEppResourceCache(Duration.standardDays(1)).build();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_loadCached_ignoresContactChange() {
|
void test_loadCached_ignoresContactChange() {
|
||||||
ContactResource originalContact = persistActiveContact("contact123");
|
ContactResource originalContact = persistActiveContact("contact123");
|
||||||
assertThat(EppResource.loadCached(ImmutableList.of(originalContact.createVKey())))
|
assertThat(EppResource.loadCached(ImmutableList.of(originalContact.createVKey())))
|
||||||
.containsExactly(originalContact.createVKey(), originalContact);
|
.containsExactly(originalContact.createVKey(), originalContact);
|
||||||
|
@ -50,7 +50,7 @@ public class EppResourceTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_loadCached_ignoresHostChange() {
|
void test_loadCached_ignoresHostChange() {
|
||||||
HostResource originalHost = persistActiveHost("ns1.example.com");
|
HostResource originalHost = persistActiveHost("ns1.example.com");
|
||||||
assertThat(EppResource.loadCached(ImmutableList.of(originalHost.createVKey())))
|
assertThat(EppResource.loadCached(ImmutableList.of(originalHost.createVKey())))
|
||||||
.containsExactly(originalHost.createVKey(), originalHost);
|
.containsExactly(originalHost.createVKey(), originalHost);
|
||||||
|
|
|
@ -30,33 +30,29 @@ import google.registry.testing.FakeClock;
|
||||||
import google.registry.testing.InjectRule;
|
import google.registry.testing.InjectRule;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Tests for {@link EppResourceUtils}. */
|
/** Tests for {@link EppResourceUtils}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class EppResourceUtilsTest {
|
public class EppResourceUtilsTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine =
|
public final AppEngineRule appEngine =
|
||||||
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
|
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension public final InjectRule inject = new InjectRule();
|
||||||
public final InjectRule inject = new InjectRule();
|
|
||||||
|
|
||||||
private final FakeClock clock = new FakeClock(DateTime.now(UTC));
|
private final FakeClock clock = new FakeClock(DateTime.now(UTC));
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void init() {
|
void beforeEach() {
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
inject.setStaticField(Ofy.class, "clock", clock);
|
inject.setStaticField(Ofy.class, "clock", clock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoadAtPointInTime_beforeCreated_returnsNull() {
|
void testLoadAtPointInTime_beforeCreated_returnsNull() {
|
||||||
clock.advanceOneMilli();
|
clock.advanceOneMilli();
|
||||||
// Don't save a commit log, we shouldn't need one.
|
// Don't save a commit log, we shouldn't need one.
|
||||||
HostResource host = persistResource(
|
HostResource host = persistResource(
|
||||||
|
@ -67,7 +63,7 @@ public class EppResourceUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoadAtPointInTime_atOrAfterLastAutoUpdateTime_returnsResource() {
|
void testLoadAtPointInTime_atOrAfterLastAutoUpdateTime_returnsResource() {
|
||||||
clock.advanceOneMilli();
|
clock.advanceOneMilli();
|
||||||
// Don't save a commit log, we shouldn't need one.
|
// Don't save a commit log, we shouldn't need one.
|
||||||
HostResource host = persistResource(
|
HostResource host = persistResource(
|
||||||
|
@ -78,7 +74,7 @@ public class EppResourceUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoadAtPointInTime_usingIntactRevisionHistory_returnsMutationValue() {
|
void testLoadAtPointInTime_usingIntactRevisionHistory_returnsMutationValue() {
|
||||||
clock.advanceOneMilli();
|
clock.advanceOneMilli();
|
||||||
// Save resource with a commit log that we can read in later as a revisions map value.
|
// Save resource with a commit log that we can read in later as a revisions map value.
|
||||||
HostResource oldHost = persistResourceWithCommitLog(
|
HostResource oldHost = persistResourceWithCommitLog(
|
||||||
|
@ -99,7 +95,7 @@ public class EppResourceUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoadAtPointInTime_brokenRevisionHistory_returnsResourceAsIs() {
|
void testLoadAtPointInTime_brokenRevisionHistory_returnsResourceAsIs() {
|
||||||
// Don't save a commit log since we want to test the handling of a broken revisions key.
|
// Don't save a commit log since we want to test the handling of a broken revisions key.
|
||||||
HostResource oldHost = persistResource(
|
HostResource oldHost = persistResource(
|
||||||
newHostResource("ns1.cat.tld").asBuilder()
|
newHostResource("ns1.cat.tld").asBuilder()
|
||||||
|
@ -119,7 +115,7 @@ public class EppResourceUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoadAtPointInTime_fallback_returnsMutationValueForOldestRevision() {
|
void testLoadAtPointInTime_fallback_returnsMutationValueForOldestRevision() {
|
||||||
clock.advanceOneMilli();
|
clock.advanceOneMilli();
|
||||||
// Save a commit log that we can fall back to.
|
// Save a commit log that we can fall back to.
|
||||||
HostResource oldHost = persistResourceWithCommitLog(
|
HostResource oldHost = persistResourceWithCommitLog(
|
||||||
|
@ -141,7 +137,7 @@ public class EppResourceUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoadAtPointInTime_ultimateFallback_onlyOneRevision_returnsCurrentResource() {
|
void testLoadAtPointInTime_ultimateFallback_onlyOneRevision_returnsCurrentResource() {
|
||||||
clock.advanceOneMilli();
|
clock.advanceOneMilli();
|
||||||
// Don't save a commit log; we want to test that we load from the current resource.
|
// Don't save a commit log; we want to test that we load from the current resource.
|
||||||
HostResource host = persistResource(
|
HostResource host = persistResource(
|
||||||
|
@ -156,7 +152,7 @@ public class EppResourceUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoadAtPointInTime_moreThanThirtyDaysInPast_historyIsPurged() {
|
void testLoadAtPointInTime_moreThanThirtyDaysInPast_historyIsPurged() {
|
||||||
clock.advanceOneMilli();
|
clock.advanceOneMilli();
|
||||||
HostResource host =
|
HostResource host =
|
||||||
persistResourceWithCommitLog(newHostResource("ns1.example.net"));
|
persistResourceWithCommitLog(newHostResource("ns1.example.net"));
|
||||||
|
|
|
@ -38,16 +38,13 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link ImmutableObject}. */
|
/** Unit tests for {@link ImmutableObject}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class ImmutableObjectTest {
|
public class ImmutableObjectTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine =
|
public final AppEngineRule appEngine =
|
||||||
AppEngineRule.builder()
|
AppEngineRule.builder()
|
||||||
.withDatastoreAndCloudSql()
|
.withDatastoreAndCloudSql()
|
||||||
|
@ -59,14 +56,14 @@ public class ImmutableObjectTest {
|
||||||
String a;
|
String a;
|
||||||
String b;
|
String b;
|
||||||
|
|
||||||
public SimpleObject(String a, String b) {
|
SimpleObject(String a, String b) {
|
||||||
this.a = a;
|
this.a = a;
|
||||||
this.b = b;
|
this.b = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToString_simpleClass() {
|
void testToString_simpleClass() {
|
||||||
SimpleObject object = new SimpleObject("foo", null);
|
SimpleObject object = new SimpleObject("foo", null);
|
||||||
assertThat(object.toString()).isEqualTo(""
|
assertThat(object.toString()).isEqualTo(""
|
||||||
+ "SimpleObject (@" + System.identityHashCode(object) + "): {\n"
|
+ "SimpleObject (@" + System.identityHashCode(object) + "): {\n"
|
||||||
|
@ -76,7 +73,7 @@ public class ImmutableObjectTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToDiffableFieldMap_simpleClass() {
|
void testToDiffableFieldMap_simpleClass() {
|
||||||
SimpleObject object = new SimpleObject("foo", null);
|
SimpleObject object = new SimpleObject("foo", null);
|
||||||
assertThat(object.toDiffableFieldMap()).containsEntry("a", "foo");
|
assertThat(object.toDiffableFieldMap()).containsEntry("a", "foo");
|
||||||
assertThat(object.toDiffableFieldMap()).containsEntry("b", null);
|
assertThat(object.toDiffableFieldMap()).containsEntry("b", null);
|
||||||
|
@ -92,7 +89,7 @@ public class ImmutableObjectTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToDiffableFieldMap_typesClass() {
|
void testToDiffableFieldMap_typesClass() {
|
||||||
TypesObject object = new TypesObject();
|
TypesObject object = new TypesObject();
|
||||||
object.bool = true;
|
object.bool = true;
|
||||||
object.boolObject = true;
|
object.boolObject = true;
|
||||||
|
@ -110,13 +107,13 @@ public class ImmutableObjectTest {
|
||||||
public static class NestedObject extends ImmutableObject {
|
public static class NestedObject extends ImmutableObject {
|
||||||
ImmutableObject nested;
|
ImmutableObject nested;
|
||||||
|
|
||||||
public NestedObject(ImmutableObject nested) {
|
NestedObject(ImmutableObject nested) {
|
||||||
this.nested = nested;
|
this.nested = nested;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToDiffableFieldMap_nestedObjectClass() {
|
void testToDiffableFieldMap_nestedObjectClass() {
|
||||||
SimpleObject innermostObject = new SimpleObject("foo", "bar");
|
SimpleObject innermostObject = new SimpleObject("foo", "bar");
|
||||||
NestedObject innerObject = new NestedObject(innermostObject);
|
NestedObject innerObject = new NestedObject(innermostObject);
|
||||||
NestedObject object = new NestedObject(innerObject);
|
NestedObject object = new NestedObject(innerObject);
|
||||||
|
@ -135,7 +132,7 @@ public class ImmutableObjectTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToDiffableFieldMap_nestedObjectCollectionsClass() {
|
void testToDiffableFieldMap_nestedObjectCollectionsClass() {
|
||||||
SimpleObject obj1 = new SimpleObject("foo", "bar");
|
SimpleObject obj1 = new SimpleObject("foo", "bar");
|
||||||
SimpleObject obj2 = new SimpleObject("bax", "bar");
|
SimpleObject obj2 = new SimpleObject("bax", "bar");
|
||||||
Map<?, ?> obj1map = obj1.toDiffableFieldMap();
|
Map<?, ?> obj1map = obj1.toDiffableFieldMap();
|
||||||
|
@ -158,19 +155,19 @@ public class ImmutableObjectTest {
|
||||||
public static class IterableObject extends ImmutableObject {
|
public static class IterableObject extends ImmutableObject {
|
||||||
Iterable<?> iterable;
|
Iterable<?> iterable;
|
||||||
|
|
||||||
public IterableObject(Iterable<?> iterable) {
|
IterableObject(Iterable<?> iterable) {
|
||||||
this.iterable = iterable;
|
this.iterable = iterable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToDiffableFieldMap_iterableField_notExpanded() {
|
void testToDiffableFieldMap_iterableField_notExpanded() {
|
||||||
IterableObject iterableObject = new IterableObject(new CidrAddressBlock("127.0.0.1/32"));
|
IterableObject iterableObject = new IterableObject(new CidrAddressBlock("127.0.0.1/32"));
|
||||||
assertThat(iterableObject.toDiffableFieldMap()).containsEntry("iterable", "127.0.0.1/32");
|
assertThat(iterableObject.toDiffableFieldMap()).containsEntry("iterable", "127.0.0.1/32");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToDiffableFieldMap_infiniteIterableField_notExpanded() {
|
void testToDiffableFieldMap_infiniteIterableField_notExpanded() {
|
||||||
IterableObject iterableObject = new IterableObject(Iterables.cycle("na"));
|
IterableObject iterableObject = new IterableObject(Iterables.cycle("na"));
|
||||||
assertThat(iterableObject.toDiffableFieldMap()).containsEntry("iterable", "[na] (cycled)");
|
assertThat(iterableObject.toDiffableFieldMap()).containsEntry("iterable", "[na] (cycled)");
|
||||||
}
|
}
|
||||||
|
@ -202,7 +199,7 @@ public class ImmutableObjectTest {
|
||||||
Map<Object, Object> immutableObjectMap = newHashMap();
|
Map<Object, Object> immutableObjectMap = newHashMap();
|
||||||
Map<Object, Object> heterogenousMap = newHashMap();
|
Map<Object, Object> heterogenousMap = newHashMap();
|
||||||
|
|
||||||
public EmptyableObject() {
|
EmptyableObject() {
|
||||||
stringMap.put("a", "");
|
stringMap.put("a", "");
|
||||||
stringMap.put("b", null);
|
stringMap.put("b", null);
|
||||||
immutableObjectMap.put("a", new SimpleObject("", ""));
|
immutableObjectMap.put("a", new SimpleObject("", ""));
|
||||||
|
@ -213,7 +210,7 @@ public class ImmutableObjectTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCloneEmptyToNull() {
|
void testCloneEmptyToNull() {
|
||||||
EmptyableObject cloned = cloneEmptyToNull(new EmptyableObject());
|
EmptyableObject cloned = cloneEmptyToNull(new EmptyableObject());
|
||||||
assertThat(cloned.nullString).isNull();
|
assertThat(cloned.nullString).isNull();
|
||||||
assertThat(cloned.emptyString).isNull();
|
assertThat(cloned.emptyString).isNull();
|
||||||
|
@ -253,13 +250,13 @@ public class ImmutableObjectTest {
|
||||||
Set<?> set = newHashSet((Object) null);
|
Set<?> set = newHashSet((Object) null);
|
||||||
Map<String, ?> map = newHashMap();
|
Map<String, ?> map = newHashMap();
|
||||||
|
|
||||||
public NullInContainersObject() {
|
NullInContainersObject() {
|
||||||
map.put("a", null);
|
map.put("a", null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToDiffableFieldMap_withEmptyAndNulls() {
|
void testToDiffableFieldMap_withEmptyAndNulls() {
|
||||||
Map<String, Object> diffableFieldMap = new NullInContainersObject().toDiffableFieldMap();
|
Map<String, Object> diffableFieldMap = new NullInContainersObject().toDiffableFieldMap();
|
||||||
assertThat((List<?>) diffableFieldMap.get("array")).containsExactly((Object) null);
|
assertThat((List<?>) diffableFieldMap.get("array")).containsExactly((Object) null);
|
||||||
assertThat((List<?>) diffableFieldMap.get("list")).containsExactly((Object) null);
|
assertThat((List<?>) diffableFieldMap.get("list")).containsExactly((Object) null);
|
||||||
|
@ -297,7 +294,7 @@ public class ImmutableObjectTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToHydratedString_skipsDoNotHydrate() {
|
void testToHydratedString_skipsDoNotHydrate() {
|
||||||
RootObject root = new RootObject();
|
RootObject root = new RootObject();
|
||||||
root.hydrateMe = Key.create(persistResource(ValueObject.create(1, "foo")));
|
root.hydrateMe = Key.create(persistResource(ValueObject.create(1, "foo")));
|
||||||
root.skipMe = Key.create(persistResource(ValueObject.create(2, "bar")));
|
root.skipMe = Key.create(persistResource(ValueObject.create(2, "bar")));
|
||||||
|
@ -307,7 +304,7 @@ public class ImmutableObjectTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToHydratedString_expandsMaps() {
|
void testToHydratedString_expandsMaps() {
|
||||||
RootObject root = new RootObject();
|
RootObject root = new RootObject();
|
||||||
root.map = ImmutableMap.of("foo", Key.create(persistResource(ValueObject.create(1, "bar"))));
|
root.map = ImmutableMap.of("foo", Key.create(persistResource(ValueObject.create(1, "bar"))));
|
||||||
String hydratedString = root.toHydratedString();
|
String hydratedString = root.toHydratedString();
|
||||||
|
@ -316,7 +313,7 @@ public class ImmutableObjectTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToHydratedString_expandsCollections() {
|
void testToHydratedString_expandsCollections() {
|
||||||
RootObject root = new RootObject();
|
RootObject root = new RootObject();
|
||||||
root.set = ImmutableSet.of(Key.create(persistResource(ValueObject.create(1, "foo"))));
|
root.set = ImmutableSet.of(Key.create(persistResource(ValueObject.create(1, "foo"))));
|
||||||
assertThat(root.toHydratedString()).contains("foo");
|
assertThat(root.toHydratedString()).contains("foo");
|
||||||
|
|
|
@ -21,18 +21,14 @@ import com.googlecode.objectify.annotation.Id;
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link ModelUtils}. */
|
/** Unit tests for {@link ModelUtils}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class ModelUtilsTest {
|
public class ModelUtilsTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension public AppEngineRule appEngineRule = new AppEngineRule.Builder().build();
|
||||||
public AppEngineRule appEngineRule = new AppEngineRule.Builder().build();
|
|
||||||
|
|
||||||
/** Test class for reflection methods. */
|
/** Test class for reflection methods. */
|
||||||
public static class TestClass extends ImmutableObject implements Buildable {
|
public static class TestClass extends ImmutableObject implements Buildable {
|
||||||
|
@ -79,13 +75,13 @@ public class ModelUtilsTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void resetCaches() {
|
void resetCaches() {
|
||||||
ModelUtils.resetCaches();
|
ModelUtils.resetCaches();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAllFields() throws Exception {
|
void testGetAllFields() throws Exception {
|
||||||
Map<String, Field> expected = ImmutableMap.of(
|
Map<String, Field> expected = ImmutableMap.of(
|
||||||
"id", TestClass.class.getDeclaredField("id"),
|
"id", TestClass.class.getDeclaredField("id"),
|
||||||
"a", TestClass.class.getDeclaredField("a"),
|
"a", TestClass.class.getDeclaredField("a"),
|
||||||
|
@ -101,7 +97,7 @@ public class ModelUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetFieldValues() throws Exception {
|
void testGetFieldValues() throws Exception {
|
||||||
TestClass testInstance = new TestClass();
|
TestClass testInstance = new TestClass();
|
||||||
testInstance.id = "foo";
|
testInstance.id = "foo";
|
||||||
testInstance.a = "a";
|
testInstance.a = "a";
|
||||||
|
@ -125,7 +121,7 @@ public class ModelUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildingResetsHashCode() {
|
void testBuildingResetsHashCode() {
|
||||||
TestClass original = new TestClass();
|
TestClass original = new TestClass();
|
||||||
original.id = "foo";
|
original.id = "foo";
|
||||||
TestClass cloned = original.asBuilder().setId("bar").build();
|
TestClass cloned = original.asBuilder().setId("bar").build();
|
||||||
|
|
|
@ -40,20 +40,17 @@ import org.joda.money.Money;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.DateTimeZone;
|
import org.joda.time.DateTimeZone;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public final class OteAccountBuilderTest {
|
public final class OteAccountBuilderTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetRegistrarToTldMap() {
|
void testGetRegistrarToTldMap() {
|
||||||
assertThat(OteAccountBuilder.forClientId("myclientid").getClientIdToTldMap())
|
assertThat(OteAccountBuilder.forClientId("myclientid").getClientIdToTldMap())
|
||||||
.containsExactly(
|
.containsExactly(
|
||||||
"myclientid-1", "myclientid-sunrise",
|
"myclientid-1", "myclientid-sunrise",
|
||||||
|
@ -62,8 +59,8 @@ public final class OteAccountBuilderTest {
|
||||||
"myclientid-5", "myclientid-eap");
|
"myclientid-5", "myclientid-eap");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void beforeEach() {
|
||||||
persistPremiumList("default_sandbox_list", "sandbox,USD 1000");
|
persistPremiumList("default_sandbox_list", "sandbox,USD 1000");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +102,7 @@ public final class OteAccountBuilderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateOteEntities_success() {
|
void testCreateOteEntities_success() {
|
||||||
OteAccountBuilder.forClientId("myclientid").addContact("email@example.com").buildAndPersist();
|
OteAccountBuilder.forClientId("myclientid").addContact("email@example.com").buildAndPersist();
|
||||||
|
|
||||||
assertTldExists("myclientid-sunrise", START_DATE_SUNRISE, Money.zero(USD));
|
assertTldExists("myclientid-sunrise", START_DATE_SUNRISE, Money.zero(USD));
|
||||||
|
@ -122,7 +119,7 @@ public final class OteAccountBuilderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateOteEntities_multipleContacts_success() {
|
void testCreateOteEntities_multipleContacts_success() {
|
||||||
OteAccountBuilder.forClientId("myclientid")
|
OteAccountBuilder.forClientId("myclientid")
|
||||||
.addContact("email@example.com")
|
.addContact("email@example.com")
|
||||||
.addContact("other@example.com")
|
.addContact("other@example.com")
|
||||||
|
@ -151,7 +148,7 @@ public final class OteAccountBuilderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateOteEntities_setPassword() {
|
void testCreateOteEntities_setPassword() {
|
||||||
OteAccountBuilder.forClientId("myclientid").setPassword("myPassword").buildAndPersist();
|
OteAccountBuilder.forClientId("myclientid").setPassword("myPassword").buildAndPersist();
|
||||||
|
|
||||||
assertThat(Registrar.loadByClientId("myclientid-3").get().verifyPassword("myPassword"))
|
assertThat(Registrar.loadByClientId("myclientid-3").get().verifyPassword("myPassword"))
|
||||||
|
@ -159,7 +156,7 @@ public final class OteAccountBuilderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateOteEntities_setCertificateHash() {
|
void testCreateOteEntities_setCertificateHash() {
|
||||||
OteAccountBuilder.forClientId("myclientid")
|
OteAccountBuilder.forClientId("myclientid")
|
||||||
.setCertificateHash(SAMPLE_CERT_HASH)
|
.setCertificateHash(SAMPLE_CERT_HASH)
|
||||||
.buildAndPersist();
|
.buildAndPersist();
|
||||||
|
@ -169,7 +166,7 @@ public final class OteAccountBuilderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateOteEntities_setCertificate() {
|
void testCreateOteEntities_setCertificate() {
|
||||||
OteAccountBuilder.forClientId("myclientid")
|
OteAccountBuilder.forClientId("myclientid")
|
||||||
.setCertificate(SAMPLE_CERT, new SystemClock().nowUtc())
|
.setCertificate(SAMPLE_CERT, new SystemClock().nowUtc())
|
||||||
.buildAndPersist();
|
.buildAndPersist();
|
||||||
|
@ -181,7 +178,7 @@ public final class OteAccountBuilderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateOteEntities_setIpAllowList() {
|
void testCreateOteEntities_setIpAllowList() {
|
||||||
OteAccountBuilder.forClientId("myclientid")
|
OteAccountBuilder.forClientId("myclientid")
|
||||||
.setIpAllowList(ImmutableList.of("1.1.1.0/24"))
|
.setIpAllowList(ImmutableList.of("1.1.1.0/24"))
|
||||||
.buildAndPersist();
|
.buildAndPersist();
|
||||||
|
@ -191,7 +188,7 @@ public final class OteAccountBuilderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateOteEntities_invalidClientId_fails() {
|
void testCreateOteEntities_invalidClientId_fails() {
|
||||||
assertThat(
|
assertThat(
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class, () -> OteAccountBuilder.forClientId("3blo-bio")))
|
IllegalArgumentException.class, () -> OteAccountBuilder.forClientId("3blo-bio")))
|
||||||
|
@ -200,7 +197,7 @@ public final class OteAccountBuilderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateOteEntities_clientIdTooShort_fails() {
|
void testCreateOteEntities_clientIdTooShort_fails() {
|
||||||
assertThat(
|
assertThat(
|
||||||
assertThrows(IllegalArgumentException.class, () -> OteAccountBuilder.forClientId("bl")))
|
assertThrows(IllegalArgumentException.class, () -> OteAccountBuilder.forClientId("bl")))
|
||||||
.hasMessageThat()
|
.hasMessageThat()
|
||||||
|
@ -208,7 +205,7 @@ public final class OteAccountBuilderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateOteEntities_clientIdTooLong_fails() {
|
void testCreateOteEntities_clientIdTooLong_fails() {
|
||||||
assertThat(
|
assertThat(
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -218,7 +215,7 @@ public final class OteAccountBuilderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateOteEntities_clientIdBadCharacter_fails() {
|
void testCreateOteEntities_clientIdBadCharacter_fails() {
|
||||||
assertThat(
|
assertThat(
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class, () -> OteAccountBuilder.forClientId("blo#bio")))
|
IllegalArgumentException.class, () -> OteAccountBuilder.forClientId("blo#bio")))
|
||||||
|
@ -227,7 +224,7 @@ public final class OteAccountBuilderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateOteEntities_registrarExists_failsWhenNotReplaceExisting() {
|
void testCreateOteEntities_registrarExists_failsWhenNotReplaceExisting() {
|
||||||
persistSimpleResource(makeRegistrar1().asBuilder().setClientId("myclientid-1").build());
|
persistSimpleResource(makeRegistrar1().asBuilder().setClientId("myclientid-1").build());
|
||||||
|
|
||||||
OteAccountBuilder oteSetupHelper = OteAccountBuilder.forClientId("myclientid");
|
OteAccountBuilder oteSetupHelper = OteAccountBuilder.forClientId("myclientid");
|
||||||
|
@ -238,7 +235,7 @@ public final class OteAccountBuilderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateOteEntities_tldExists_failsWhenNotReplaceExisting() {
|
void testCreateOteEntities_tldExists_failsWhenNotReplaceExisting() {
|
||||||
createTld("myclientid-ga", START_DATE_SUNRISE);
|
createTld("myclientid-ga", START_DATE_SUNRISE);
|
||||||
|
|
||||||
OteAccountBuilder oteSetupHelper = OteAccountBuilder.forClientId("myclientid");
|
OteAccountBuilder oteSetupHelper = OteAccountBuilder.forClientId("myclientid");
|
||||||
|
@ -249,7 +246,7 @@ public final class OteAccountBuilderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateOteEntities_entitiesExist_succeedsWhenReplaceExisting() {
|
void testCreateOteEntities_entitiesExist_succeedsWhenReplaceExisting() {
|
||||||
persistSimpleResource(makeRegistrar1().asBuilder().setClientId("myclientid-1").build());
|
persistSimpleResource(makeRegistrar1().asBuilder().setClientId("myclientid-1").build());
|
||||||
// we intentionally create the -ga TLD with the wrong state, to make sure it's overwritten.
|
// we intentionally create the -ga TLD with the wrong state, to make sure it's overwritten.
|
||||||
createTld("myclientid-ga", START_DATE_SUNRISE);
|
createTld("myclientid-ga", START_DATE_SUNRISE);
|
||||||
|
@ -264,7 +261,7 @@ public final class OteAccountBuilderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateOteEntities_doubleCreation_actuallyReplaces() {
|
void testCreateOteEntities_doubleCreation_actuallyReplaces() {
|
||||||
OteAccountBuilder.forClientId("myclientid")
|
OteAccountBuilder.forClientId("myclientid")
|
||||||
.setPassword("oldPassword")
|
.setPassword("oldPassword")
|
||||||
.addContact("email@example.com")
|
.addContact("email@example.com")
|
||||||
|
@ -286,7 +283,7 @@ public final class OteAccountBuilderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateOteEntities_doubleCreation_keepsOldContacts() {
|
void testCreateOteEntities_doubleCreation_keepsOldContacts() {
|
||||||
OteAccountBuilder.forClientId("myclientid").addContact("email@example.com").buildAndPersist();
|
OteAccountBuilder.forClientId("myclientid").addContact("email@example.com").buildAndPersist();
|
||||||
|
|
||||||
assertContactExists("myclientid-3", "email@example.com");
|
assertContactExists("myclientid-3", "email@example.com");
|
||||||
|
@ -301,7 +298,7 @@ public final class OteAccountBuilderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateClientIdToTldMap_validEntries() {
|
void testCreateClientIdToTldMap_validEntries() {
|
||||||
assertThat(OteAccountBuilder.createClientIdToTldMap("myclientid"))
|
assertThat(OteAccountBuilder.createClientIdToTldMap("myclientid"))
|
||||||
.containsExactly(
|
.containsExactly(
|
||||||
"myclientid-1", "myclientid-sunrise",
|
"myclientid-1", "myclientid-sunrise",
|
||||||
|
@ -311,7 +308,7 @@ public final class OteAccountBuilderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateClientIdToTldMap_invalidId() {
|
void testCreateClientIdToTldMap_invalidId() {
|
||||||
IllegalArgumentException exception =
|
IllegalArgumentException exception =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class, () -> OteAccountBuilder.createClientIdToTldMap("a"));
|
IllegalArgumentException.class, () -> OteAccountBuilder.createClientIdToTldMap("a"));
|
||||||
|
@ -319,12 +316,12 @@ public final class OteAccountBuilderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetBaseClientId_validOteId() {
|
void testGetBaseClientId_validOteId() {
|
||||||
assertThat(OteAccountBuilder.getBaseClientId("myclientid-4")).isEqualTo("myclientid");
|
assertThat(OteAccountBuilder.getBaseClientId("myclientid-4")).isEqualTo("myclientid");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetBaseClientId_invalidInput_malformed() {
|
void testGetBaseClientId_invalidInput_malformed() {
|
||||||
assertThat(
|
assertThat(
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -334,7 +331,7 @@ public final class OteAccountBuilderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetBaseClientId_invalidInput_wrongForBase() {
|
void testGetBaseClientId_invalidInput_wrongForBase() {
|
||||||
assertThat(
|
assertThat(
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
|
|
@ -18,19 +18,16 @@ import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import google.registry.model.OteStats.StatType;
|
import google.registry.model.OteStats.StatType;
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public final class OteStatsTest {
|
public final class OteStatsTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_allPass() throws Exception {
|
void testSuccess_allPass() throws Exception {
|
||||||
OteStatsTestHelper.setupCompleteOte("blobio");
|
OteStatsTestHelper.setupCompleteOte("blobio");
|
||||||
OteStats stats = OteStats.getFromRegistrar("blobio");
|
OteStats stats = OteStats.getFromRegistrar("blobio");
|
||||||
assertThat(stats.getFailures()).isEmpty();
|
assertThat(stats.getFailures()).isEmpty();
|
||||||
|
@ -38,7 +35,7 @@ public final class OteStatsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_incomplete() throws Exception {
|
void testSuccess_incomplete() throws Exception {
|
||||||
OteStatsTestHelper.setupIncompleteOte("blobio");
|
OteStatsTestHelper.setupIncompleteOte("blobio");
|
||||||
OteStats stats = OteStats.getFromRegistrar("blobio");
|
OteStats stats = OteStats.getFromRegistrar("blobio");
|
||||||
assertThat(stats.getFailures())
|
assertThat(stats.getFailures())
|
||||||
|
@ -49,7 +46,7 @@ public final class OteStatsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_toString() throws Exception {
|
void testSuccess_toString() throws Exception {
|
||||||
OteStatsTestHelper.setupCompleteOte("blobio");
|
OteStatsTestHelper.setupCompleteOte("blobio");
|
||||||
OteStats stats = OteStats.getFromRegistrar("blobio");
|
OteStats stats = OteStats.getFromRegistrar("blobio");
|
||||||
String expected =
|
String expected =
|
||||||
|
@ -90,7 +87,7 @@ public final class OteStatsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIncomplete_toString() throws Exception {
|
void testIncomplete_toString() throws Exception {
|
||||||
OteStatsTestHelper.setupIncompleteOte("blobio");
|
OteStatsTestHelper.setupIncompleteOte("blobio");
|
||||||
OteStats stats = OteStats.getFromRegistrar("blobio");
|
OteStats stats = OteStats.getFromRegistrar("blobio");
|
||||||
String expected =
|
String expected =
|
||||||
|
|
|
@ -16,24 +16,21 @@ package google.registry.model;
|
||||||
|
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import google.registry.testing.GoldenFileTestHelper;
|
import google.registry.testing.GoldenFileTestHelper;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link SchemaVersion}.
|
* Unit tests for {@link SchemaVersion}.
|
||||||
*
|
*
|
||||||
* <p>If the test breaks, the instructions below will be printed.
|
* <p>If the test breaks, the instructions below will be printed.
|
||||||
*/
|
*/
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class SchemaVersionTest {
|
public class SchemaVersionTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGoldenSchemaFile() {
|
void testGoldenSchemaFile() {
|
||||||
GoldenFileTestHelper.assertThat(SchemaVersion.getSchema())
|
GoldenFileTestHelper.assertThat(SchemaVersion.getSchema())
|
||||||
.describedAs("Datastore schema")
|
.describedAs("Datastore schema")
|
||||||
.createdByNomulusCommand("get_schema")
|
.createdByNomulusCommand("get_schema")
|
||||||
|
|
|
@ -23,39 +23,35 @@ import com.googlecode.objectify.annotation.Entity;
|
||||||
import google.registry.model.common.CrossTldSingleton;
|
import google.registry.model.common.CrossTldSingleton;
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link UpdateAutoTimestamp}. */
|
/** Unit tests for {@link UpdateAutoTimestamp}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class UpdateAutoTimestampTest {
|
public class UpdateAutoTimestampTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine =
|
public final AppEngineRule appEngine =
|
||||||
AppEngineRule.builder()
|
AppEngineRule.builder()
|
||||||
.withDatastoreAndCloudSql()
|
.withDatastoreAndCloudSql()
|
||||||
.withOfyTestEntities(TestObject.class)
|
.withOfyTestEntities(UpdateAutoTimestampTestObject.class)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
/** Timestamped class. */
|
/** Timestamped class. */
|
||||||
@Entity(name = "UatTestEntity")
|
@Entity(name = "UatTestEntity")
|
||||||
public static class TestObject extends CrossTldSingleton {
|
public static class UpdateAutoTimestampTestObject extends CrossTldSingleton {
|
||||||
UpdateAutoTimestamp updateTime = UpdateAutoTimestamp.create(null);
|
UpdateAutoTimestamp updateTime = UpdateAutoTimestamp.create(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private TestObject reload() {
|
private UpdateAutoTimestampTestObject reload() {
|
||||||
return ofy().load().entity(new TestObject()).now();
|
return ofy().load().entity(new UpdateAutoTimestampTestObject()).now();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSaveSetsTime() {
|
void testSaveSetsTime() {
|
||||||
DateTime transactionTime =
|
DateTime transactionTime =
|
||||||
tm()
|
tm().transact(
|
||||||
.transact(
|
|
||||||
() -> {
|
() -> {
|
||||||
TestObject object = new TestObject();
|
UpdateAutoTimestampTestObject object = new UpdateAutoTimestampTestObject();
|
||||||
assertThat(object.updateTime.timestamp).isNull();
|
assertThat(object.updateTime.timestamp).isNull();
|
||||||
ofy().save().entity(object);
|
ofy().save().entity(object);
|
||||||
return tm().getTransactionTime();
|
return tm().getTransactionTime();
|
||||||
|
@ -65,12 +61,11 @@ public class UpdateAutoTimestampTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResavingOverwritesOriginalTime() {
|
void testResavingOverwritesOriginalTime() {
|
||||||
DateTime transactionTime =
|
DateTime transactionTime =
|
||||||
tm()
|
tm().transact(
|
||||||
.transact(
|
|
||||||
() -> {
|
() -> {
|
||||||
TestObject object = new TestObject();
|
UpdateAutoTimestampTestObject object = new UpdateAutoTimestampTestObject();
|
||||||
object.updateTime = UpdateAutoTimestamp.create(DateTime.now(UTC).minusDays(1));
|
object.updateTime = UpdateAutoTimestamp.create(DateTime.now(UTC).minusDays(1));
|
||||||
ofy().save().entity(object);
|
ofy().save().entity(object);
|
||||||
return tm().getTransactionTime();
|
return tm().getTransactionTime();
|
||||||
|
|
|
@ -50,23 +50,23 @@ import org.junit.jupiter.api.Test;
|
||||||
public class BillingEventTest extends EntityTestCase {
|
public class BillingEventTest extends EntityTestCase {
|
||||||
private final DateTime now = DateTime.now(UTC);
|
private final DateTime now = DateTime.now(UTC);
|
||||||
|
|
||||||
public BillingEventTest() {
|
BillingEventTest() {
|
||||||
super(JpaEntityCoverageCheck.ENABLED);
|
super(JpaEntityCoverageCheck.ENABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
HistoryEntry historyEntry;
|
private HistoryEntry historyEntry;
|
||||||
HistoryEntry historyEntry2;
|
private HistoryEntry historyEntry2;
|
||||||
DomainBase domain;
|
private DomainBase domain;
|
||||||
BillingEvent.OneTime sqlOneTime;
|
private BillingEvent.OneTime sqlOneTime;
|
||||||
BillingEvent.OneTime oneTime;
|
private BillingEvent.OneTime oneTime;
|
||||||
BillingEvent.OneTime oneTimeSynthetic;
|
private BillingEvent.OneTime oneTimeSynthetic;
|
||||||
BillingEvent.Recurring recurring;
|
private BillingEvent.Recurring recurring;
|
||||||
BillingEvent.Cancellation cancellationOneTime;
|
private BillingEvent.Cancellation cancellationOneTime;
|
||||||
BillingEvent.Cancellation cancellationRecurring;
|
private BillingEvent.Cancellation cancellationRecurring;
|
||||||
BillingEvent.Modification modification;
|
private BillingEvent.Modification modification;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
domain = persistActiveDomain("foo.tld");
|
domain = persistActiveDomain("foo.tld");
|
||||||
historyEntry = persistResource(
|
historyEntry = persistResource(
|
||||||
|
@ -184,7 +184,7 @@ public class BillingEventTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCloudSqlPersistence_OneTime() {
|
void testCloudSqlPersistence_OneTime() {
|
||||||
saveRegistrar("a registrar");
|
saveRegistrar("a registrar");
|
||||||
saveNewBillingEvent(sqlOneTime);
|
saveNewBillingEvent(sqlOneTime);
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ public class BillingEventTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCloudSqlPersistence_Cancellation() {
|
void testCloudSqlPersistence_Cancellation() {
|
||||||
saveRegistrar("a registrar");
|
saveRegistrar("a registrar");
|
||||||
saveNewBillingEvent(sqlOneTime);
|
saveNewBillingEvent(sqlOneTime);
|
||||||
VKey<BillingEvent.OneTime> sqlVKey = VKey.createSql(BillingEvent.OneTime.class, sqlOneTime.id);
|
VKey<BillingEvent.OneTime> sqlVKey = VKey.createSql(BillingEvent.OneTime.class, sqlOneTime.id);
|
||||||
|
@ -235,7 +235,7 @@ public class BillingEventTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCloudSqlPersistence_Recurring() {
|
void testCloudSqlPersistence_Recurring() {
|
||||||
saveRegistrar("a registrar");
|
saveRegistrar("a registrar");
|
||||||
BillingEvent.Recurring sqlRecurring =
|
BillingEvent.Recurring sqlRecurring =
|
||||||
recurring
|
recurring
|
||||||
|
@ -256,7 +256,7 @@ public class BillingEventTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPersistence() {
|
void testPersistence() {
|
||||||
assertThat(ofy().load().entity(oneTime).now()).isEqualTo(oneTime);
|
assertThat(ofy().load().entity(oneTime).now()).isEqualTo(oneTime);
|
||||||
assertThat(ofy().load().entity(oneTimeSynthetic).now()).isEqualTo(oneTimeSynthetic);
|
assertThat(ofy().load().entity(oneTimeSynthetic).now()).isEqualTo(oneTimeSynthetic);
|
||||||
assertThat(ofy().load().entity(recurring).now()).isEqualTo(recurring);
|
assertThat(ofy().load().entity(recurring).now()).isEqualTo(recurring);
|
||||||
|
@ -266,7 +266,7 @@ public class BillingEventTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParenting() {
|
void testParenting() {
|
||||||
// Note that these are all tested separately because BillingEvent is an abstract base class that
|
// Note that these are all tested separately because BillingEvent is an abstract base class that
|
||||||
// lacks the @Entity annotation, and thus we cannot call .type(BillingEvent.class)
|
// lacks the @Entity annotation, and thus we cannot call .type(BillingEvent.class)
|
||||||
assertThat(ofy().load().type(BillingEvent.OneTime.class).ancestor(domain).list())
|
assertThat(ofy().load().type(BillingEvent.OneTime.class).ancestor(domain).list())
|
||||||
|
@ -288,7 +288,7 @@ public class BillingEventTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCancellationMatching() {
|
void testCancellationMatching() {
|
||||||
Key<?> recurringKey =
|
Key<?> recurringKey =
|
||||||
ofy()
|
ofy()
|
||||||
.load()
|
.load()
|
||||||
|
@ -300,7 +300,7 @@ public class BillingEventTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIndexing() throws Exception {
|
void testIndexing() throws Exception {
|
||||||
verifyIndexing(
|
verifyIndexing(
|
||||||
oneTime,
|
oneTime,
|
||||||
"clientId",
|
"clientId",
|
||||||
|
@ -322,7 +322,7 @@ public class BillingEventTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_syntheticFlagWithoutCreationTime() {
|
void testFailure_syntheticFlagWithoutCreationTime() {
|
||||||
IllegalStateException thrown =
|
IllegalStateException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalStateException.class,
|
IllegalStateException.class,
|
||||||
|
@ -338,7 +338,7 @@ public class BillingEventTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_syntheticCreationTimeWithoutFlag() {
|
void testFailure_syntheticCreationTimeWithoutFlag() {
|
||||||
IllegalStateException thrown =
|
IllegalStateException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalStateException.class,
|
IllegalStateException.class,
|
||||||
|
@ -349,7 +349,7 @@ public class BillingEventTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_syntheticFlagWithoutCancellationMatchingKey() {
|
void testFailure_syntheticFlagWithoutCancellationMatchingKey() {
|
||||||
IllegalStateException thrown =
|
IllegalStateException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalStateException.class,
|
IllegalStateException.class,
|
||||||
|
@ -367,7 +367,7 @@ public class BillingEventTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_cancellationMatchingKeyWithoutFlag() {
|
void testFailure_cancellationMatchingKeyWithoutFlag() {
|
||||||
IllegalStateException thrown =
|
IllegalStateException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalStateException.class,
|
IllegalStateException.class,
|
||||||
|
@ -384,7 +384,7 @@ public class BillingEventTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_cancellation_forGracePeriod_withOneTime() {
|
void testSuccess_cancellation_forGracePeriod_withOneTime() {
|
||||||
BillingEvent.Cancellation newCancellation = BillingEvent.Cancellation.forGracePeriod(
|
BillingEvent.Cancellation newCancellation = BillingEvent.Cancellation.forGracePeriod(
|
||||||
GracePeriod.forBillingEvent(GracePeriodStatus.ADD, oneTime),
|
GracePeriod.forBillingEvent(GracePeriodStatus.ADD, oneTime),
|
||||||
historyEntry2,
|
historyEntry2,
|
||||||
|
@ -395,7 +395,7 @@ public class BillingEventTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_cancellation_forGracePeriod_withRecurring() {
|
void testSuccess_cancellation_forGracePeriod_withRecurring() {
|
||||||
BillingEvent.Cancellation newCancellation = BillingEvent.Cancellation.forGracePeriod(
|
BillingEvent.Cancellation newCancellation = BillingEvent.Cancellation.forGracePeriod(
|
||||||
GracePeriod.createForRecurring(
|
GracePeriod.createForRecurring(
|
||||||
GracePeriodStatus.AUTO_RENEW,
|
GracePeriodStatus.AUTO_RENEW,
|
||||||
|
@ -410,7 +410,7 @@ public class BillingEventTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_cancellation_forGracePeriodWithoutBillingEvent() {
|
void testFailure_cancellation_forGracePeriodWithoutBillingEvent() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -424,7 +424,7 @@ public class BillingEventTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_cancellationWithNoBillingEvent() {
|
void testFailure_cancellationWithNoBillingEvent() {
|
||||||
IllegalStateException thrown =
|
IllegalStateException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalStateException.class,
|
IllegalStateException.class,
|
||||||
|
@ -438,7 +438,7 @@ public class BillingEventTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_cancellationWithBothBillingEvents() {
|
void testFailure_cancellationWithBothBillingEvents() {
|
||||||
IllegalStateException thrown =
|
IllegalStateException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalStateException.class,
|
IllegalStateException.class,
|
||||||
|
@ -452,7 +452,7 @@ public class BillingEventTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeadCodeThatDeletedScrapCommandsReference() {
|
void testDeadCodeThatDeletedScrapCommandsReference() {
|
||||||
assertThat(recurring.getParentKey()).isEqualTo(Key.create(historyEntry));
|
assertThat(recurring.getParentKey()).isEqualTo(Key.create(historyEntry));
|
||||||
new BillingEvent.OneTime.Builder().setParent(Key.create(historyEntry));
|
new BillingEvent.OneTime.Builder().setParent(Key.create(historyEntry));
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,19 +31,19 @@ import google.registry.model.domain.DomainBase;
|
||||||
import google.registry.model.registry.Registry;
|
import google.registry.model.registry.Registry;
|
||||||
import google.registry.schema.cursor.CursorDao;
|
import google.registry.schema.cursor.CursorDao;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/** Unit tests for {@link Cursor}. */
|
/** Unit tests for {@link Cursor}. */
|
||||||
public class CursorTest extends EntityTestCase {
|
class CursorTest extends EntityTestCase {
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
fakeClock.setTo(DateTime.parse("2010-10-17TZ"));
|
fakeClock.setTo(DateTime.parse("2010-10-17TZ"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_persistScopedCursor() {
|
void testSuccess_persistScopedCursor() {
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
this.fakeClock.advanceOneMilli();
|
this.fakeClock.advanceOneMilli();
|
||||||
final DateTime time = DateTime.parse("2012-07-12T03:30:00.000Z");
|
final DateTime time = DateTime.parse("2012-07-12T03:30:00.000Z");
|
||||||
|
@ -61,7 +61,7 @@ public class CursorTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_persistGlobalCursor() {
|
void testSuccess_persistGlobalCursor() {
|
||||||
final DateTime time = DateTime.parse("2012-07-12T03:30:00.000Z");
|
final DateTime time = DateTime.parse("2012-07-12T03:30:00.000Z");
|
||||||
CursorDao.saveCursor(Cursor.createGlobal(RECURRING_BILLING, time), GLOBAL);
|
CursorDao.saveCursor(Cursor.createGlobal(RECURRING_BILLING, time), GLOBAL);
|
||||||
assertThat(ofy().load().key(Cursor.createGlobalKey(RECURRING_BILLING)).now().getCursorTime())
|
assertThat(ofy().load().key(Cursor.createGlobalKey(RECURRING_BILLING)).now().getCursorTime())
|
||||||
|
@ -70,7 +70,7 @@ public class CursorTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIndexing() throws Exception {
|
void testIndexing() throws Exception {
|
||||||
final DateTime time = DateTime.parse("2012-07-12T03:30:00.000Z");
|
final DateTime time = DateTime.parse("2012-07-12T03:30:00.000Z");
|
||||||
CursorDao.saveCursor(Cursor.createGlobal(RECURRING_BILLING, time), GLOBAL);
|
CursorDao.saveCursor(Cursor.createGlobal(RECURRING_BILLING, time), GLOBAL);
|
||||||
Cursor cursor = ofy().load().key(Cursor.createGlobalKey(RECURRING_BILLING)).now();
|
Cursor cursor = ofy().load().key(Cursor.createGlobalKey(RECURRING_BILLING)).now();
|
||||||
|
@ -79,7 +79,7 @@ public class CursorTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_invalidScopeOnCreate() {
|
void testFailure_invalidScopeOnCreate() {
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
this.fakeClock.advanceOneMilli();
|
this.fakeClock.advanceOneMilli();
|
||||||
final DateTime time = DateTime.parse("2012-07-12T03:30:00.000Z");
|
final DateTime time = DateTime.parse("2012-07-12T03:30:00.000Z");
|
||||||
|
@ -94,7 +94,7 @@ public class CursorTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_invalidScopeOnKeyCreate() {
|
void testFailure_invalidScopeOnKeyCreate() {
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
|
@ -106,14 +106,14 @@ public class CursorTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_createGlobalKeyForScopedCursorType() {
|
void testFailure_createGlobalKeyForScopedCursorType() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(IllegalArgumentException.class, () -> Cursor.createGlobalKey(RDE_UPLOAD));
|
assertThrows(IllegalArgumentException.class, () -> Cursor.createGlobalKey(RDE_UPLOAD));
|
||||||
assertThat(thrown).hasMessageThat().contains("Cursor type is not a global cursor");
|
assertThat(thrown).hasMessageThat().contains("Cursor type is not a global cursor");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_invalidScopeOnGlobalKeyCreate() {
|
void testFailure_invalidScopeOnGlobalKeyCreate() {
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
|
@ -125,7 +125,7 @@ public class CursorTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_nullScope() {
|
void testFailure_nullScope() {
|
||||||
NullPointerException thrown =
|
NullPointerException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
NullPointerException.class,
|
NullPointerException.class,
|
||||||
|
@ -134,7 +134,7 @@ public class CursorTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_nullCursorType() {
|
void testFailure_nullCursorType() {
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
NullPointerException thrown =
|
NullPointerException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
|
@ -144,7 +144,7 @@ public class CursorTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_nullTime() {
|
void testFailure_nullTime() {
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
NullPointerException thrown =
|
NullPointerException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
|
|
|
@ -19,32 +19,29 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||||
|
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import org.junit.After;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link GaeUserIdConverter}. */
|
/** Unit tests for {@link GaeUserIdConverter}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class GaeUserIdConverterTest {
|
public class GaeUserIdConverterTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
@After
|
@AfterEach
|
||||||
public void verifyNoLingeringEntities() {
|
void verifyNoLingeringEntities() {
|
||||||
assertThat(ofy().load().type(GaeUserIdConverter.class).count()).isEqualTo(0);
|
assertThat(ofy().load().type(GaeUserIdConverter.class).count()).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess() {
|
void testSuccess() {
|
||||||
assertThat(GaeUserIdConverter.convertEmailAddressToGaeUserId("example@example.com"))
|
assertThat(GaeUserIdConverter.convertEmailAddressToGaeUserId("example@example.com"))
|
||||||
.matches("[0-9]+");
|
.matches("[0-9]+");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_inTransaction() {
|
void testSuccess_inTransaction() {
|
||||||
tm()
|
tm()
|
||||||
.transactNew(
|
.transactNew(
|
||||||
() ->
|
() ->
|
||||||
|
|
|
@ -21,27 +21,24 @@ import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Range;
|
import com.google.common.collect.Range;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link TimeOfYear}. */
|
/** Unit tests for {@link TimeOfYear}. */
|
||||||
@RunWith(JUnit4.class)
|
class TimeOfYearTest {
|
||||||
public class TimeOfYearTest {
|
|
||||||
|
|
||||||
private static final DateTime february28 = DateTime.parse("2012-02-28T01:02:03.0Z");
|
private static final DateTime february28 = DateTime.parse("2012-02-28T01:02:03.0Z");
|
||||||
private static final DateTime february29 = DateTime.parse("2012-02-29T01:02:03.0Z");
|
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");
|
private static final DateTime march1 = DateTime.parse("2012-03-01T01:02:03.0Z");
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_fromDateTime() {
|
void testSuccess_fromDateTime() {
|
||||||
// We intentionally don't allow leap years in TimeOfYear, so February 29 should be February 28.
|
// We intentionally don't allow leap years in TimeOfYear, so February 29 should be February 28.
|
||||||
assertThat(TimeOfYear.fromDateTime(february28)).isEqualTo(TimeOfYear.fromDateTime(february29));
|
assertThat(TimeOfYear.fromDateTime(february28)).isEqualTo(TimeOfYear.fromDateTime(february29));
|
||||||
assertThat(TimeOfYear.fromDateTime(february29)).isNotEqualTo(TimeOfYear.fromDateTime(march1));
|
assertThat(TimeOfYear.fromDateTime(february29)).isNotEqualTo(TimeOfYear.fromDateTime(march1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_nextAfter() {
|
void testSuccess_nextAfter() {
|
||||||
// This should be lossless because atOrAfter includes an exact match.
|
// This should be lossless because atOrAfter includes an exact match.
|
||||||
assertThat(TimeOfYear.fromDateTime(march1).getNextInstanceAtOrAfter(march1)).isEqualTo(march1);
|
assertThat(TimeOfYear.fromDateTime(march1).getNextInstanceAtOrAfter(march1)).isEqualTo(march1);
|
||||||
// This should be a year later because we stepped forward a millisecond
|
// This should be a year later because we stepped forward a millisecond
|
||||||
|
@ -50,7 +47,7 @@ public class TimeOfYearTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_nextBefore() {
|
void testSuccess_nextBefore() {
|
||||||
// This should be lossless because beforeOrAt includes an exact match.
|
// This should be lossless because beforeOrAt includes an exact match.
|
||||||
assertThat(TimeOfYear.fromDateTime(march1).getLastInstanceBeforeOrAt(march1)).isEqualTo(march1);
|
assertThat(TimeOfYear.fromDateTime(march1).getLastInstanceBeforeOrAt(march1)).isEqualTo(march1);
|
||||||
// This should be a year earlier because we stepped backward a millisecond
|
// This should be a year earlier because we stepped backward a millisecond
|
||||||
|
@ -59,7 +56,7 @@ public class TimeOfYearTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_getInstancesInRange_closed() {
|
void testSuccess_getInstancesInRange_closed() {
|
||||||
DateTime startDate = DateTime.parse("2012-05-01T00:00:00Z");
|
DateTime startDate = DateTime.parse("2012-05-01T00:00:00Z");
|
||||||
DateTime endDate = DateTime.parse("2016-05-01T00:00:00Z");
|
DateTime endDate = DateTime.parse("2016-05-01T00:00:00Z");
|
||||||
TimeOfYear timeOfYear = TimeOfYear.fromDateTime(DateTime.parse("2012-05-01T00:00:00Z"));
|
TimeOfYear timeOfYear = TimeOfYear.fromDateTime(DateTime.parse("2012-05-01T00:00:00Z"));
|
||||||
|
@ -74,7 +71,7 @@ public class TimeOfYearTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_getInstancesInRange_openClosed() {
|
void testSuccess_getInstancesInRange_openClosed() {
|
||||||
DateTime startDate = DateTime.parse("2012-05-01T00:00:00Z");
|
DateTime startDate = DateTime.parse("2012-05-01T00:00:00Z");
|
||||||
DateTime endDate = DateTime.parse("2016-05-01T00:00:00Z");
|
DateTime endDate = DateTime.parse("2016-05-01T00:00:00Z");
|
||||||
TimeOfYear timeOfYear = TimeOfYear.fromDateTime(DateTime.parse("2012-05-01T00:00:00Z"));
|
TimeOfYear timeOfYear = TimeOfYear.fromDateTime(DateTime.parse("2012-05-01T00:00:00Z"));
|
||||||
|
@ -88,7 +85,7 @@ public class TimeOfYearTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_getInstancesInRange_closedOpen() {
|
void testSuccess_getInstancesInRange_closedOpen() {
|
||||||
DateTime startDate = DateTime.parse("2012-05-01T00:00:00Z");
|
DateTime startDate = DateTime.parse("2012-05-01T00:00:00Z");
|
||||||
DateTime endDate = DateTime.parse("2016-05-01T00:00:00Z");
|
DateTime endDate = DateTime.parse("2016-05-01T00:00:00Z");
|
||||||
TimeOfYear timeOfYear = TimeOfYear.fromDateTime(DateTime.parse("2012-05-01T00:00:00Z"));
|
TimeOfYear timeOfYear = TimeOfYear.fromDateTime(DateTime.parse("2012-05-01T00:00:00Z"));
|
||||||
|
@ -102,7 +99,7 @@ public class TimeOfYearTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_getInstancesInRange_open() {
|
void testSuccess_getInstancesInRange_open() {
|
||||||
DateTime startDate = DateTime.parse("2012-05-01T00:00:00Z");
|
DateTime startDate = DateTime.parse("2012-05-01T00:00:00Z");
|
||||||
DateTime endDate = DateTime.parse("2016-05-01T00:00:00Z");
|
DateTime endDate = DateTime.parse("2016-05-01T00:00:00Z");
|
||||||
TimeOfYear timeOfYear = TimeOfYear.fromDateTime(DateTime.parse("2012-05-01T00:00:00Z"));
|
TimeOfYear timeOfYear = TimeOfYear.fromDateTime(DateTime.parse("2012-05-01T00:00:00Z"));
|
||||||
|
@ -115,7 +112,7 @@ public class TimeOfYearTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_getInstancesInRange_normalizedLowerBound() {
|
void testSuccess_getInstancesInRange_normalizedLowerBound() {
|
||||||
TimeOfYear timeOfYear = TimeOfYear.fromDateTime(START_OF_TIME);
|
TimeOfYear timeOfYear = TimeOfYear.fromDateTime(START_OF_TIME);
|
||||||
ImmutableSet<DateTime> expected =
|
ImmutableSet<DateTime> expected =
|
||||||
ImmutableSet.of(START_OF_TIME, START_OF_TIME.plusYears(1), START_OF_TIME.plusYears(2));
|
ImmutableSet.of(START_OF_TIME, START_OF_TIME.plusYears(1), START_OF_TIME.plusYears(2));
|
||||||
|
@ -124,7 +121,7 @@ public class TimeOfYearTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_getInstancesInRange_normalizedUpperBound() {
|
void testSuccess_getInstancesInRange_normalizedUpperBound() {
|
||||||
TimeOfYear timeOfYear = TimeOfYear.fromDateTime(END_OF_TIME);
|
TimeOfYear timeOfYear = TimeOfYear.fromDateTime(END_OF_TIME);
|
||||||
ImmutableSet<DateTime> expected =
|
ImmutableSet<DateTime> expected =
|
||||||
ImmutableSet.of(END_OF_TIME.minusYears(2), END_OF_TIME.minusYears(1), END_OF_TIME);
|
ImmutableSet.of(END_OF_TIME.minusYears(2), END_OF_TIME.minusYears(1), END_OF_TIME);
|
||||||
|
@ -133,7 +130,7 @@ public class TimeOfYearTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_getInstancesOfTimeOfYearInRange_empty() {
|
void testSuccess_getInstancesOfTimeOfYearInRange_empty() {
|
||||||
DateTime startDate = DateTime.parse("2012-05-01T00:00:00Z");
|
DateTime startDate = DateTime.parse("2012-05-01T00:00:00Z");
|
||||||
DateTime endDate = DateTime.parse("2013-02-01T00:00:00Z");
|
DateTime endDate = DateTime.parse("2013-02-01T00:00:00Z");
|
||||||
TimeOfYear timeOfYear = TimeOfYear.fromDateTime(DateTime.parse("2012-03-01T00:00:00Z"));
|
TimeOfYear timeOfYear = TimeOfYear.fromDateTime(DateTime.parse("2012-03-01T00:00:00Z"));
|
||||||
|
|
|
@ -26,14 +26,11 @@ import com.google.common.collect.ImmutableSortedMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link TimedTransitionProperty}. */
|
/** Unit tests for {@link TimedTransitionProperty}. */
|
||||||
@RunWith(JUnit4.class)
|
class TimedTransitionPropertyTest {
|
||||||
public class TimedTransitionPropertyTest {
|
|
||||||
private static final DateTime A_LONG_TIME_AGO = new DateTime(Long.MIN_VALUE, UTC);
|
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");
|
private static final DateTime DATE_1 = DateTime.parse("2001-01-01T00:00:00.0Z");
|
||||||
|
@ -64,15 +61,15 @@ public class TimedTransitionPropertyTest {
|
||||||
DATE_2, "2",
|
DATE_2, "2",
|
||||||
DATE_3, "3");
|
DATE_3, "3");
|
||||||
|
|
||||||
TimedTransitionProperty<String, StringTimedTransition> timedString;
|
private TimedTransitionProperty<String, StringTimedTransition> timedString;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void init() {
|
void init() {
|
||||||
timedString = TimedTransitionProperty.fromValueMap(values, StringTimedTransition.class);
|
timedString = TimedTransitionProperty.fromValueMap(values, StringTimedTransition.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_toValueMap() {
|
void testSuccess_toValueMap() {
|
||||||
assertThat(timedString.toValueMap()).isEqualTo(values);
|
assertThat(timedString.toValueMap()).isEqualTo(values);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,12 +91,12 @@ public class TimedTransitionPropertyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_getValueAtTime() {
|
void testSuccess_getValueAtTime() {
|
||||||
testGetValueAtTime(timedString);
|
testGetValueAtTime(timedString);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_getNextTransitionAfter() {
|
void testSuccess_getNextTransitionAfter() {
|
||||||
assertThat(timedString.getNextTransitionAfter(A_LONG_TIME_AGO)).isEqualTo(DATE_1);
|
assertThat(timedString.getNextTransitionAfter(A_LONG_TIME_AGO)).isEqualTo(DATE_1);
|
||||||
assertThat(timedString.getNextTransitionAfter(START_OF_TIME.plusMillis(1))).isEqualTo(DATE_1);
|
assertThat(timedString.getNextTransitionAfter(START_OF_TIME.plusMillis(1))).isEqualTo(DATE_1);
|
||||||
assertThat(timedString.getNextTransitionAfter(DATE_1.minusMillis(1))).isEqualTo(DATE_1);
|
assertThat(timedString.getNextTransitionAfter(DATE_1.minusMillis(1))).isEqualTo(DATE_1);
|
||||||
|
@ -110,7 +107,7 @@ public class TimedTransitionPropertyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_simulatedLoad() {
|
void testSuccess_simulatedLoad() {
|
||||||
// Just for testing, don't extract transitions from a TimedTransitionProperty in real code.
|
// Just for testing, don't extract transitions from a TimedTransitionProperty in real code.
|
||||||
Set<Map.Entry<DateTime, StringTimedTransition>> transitions = timedString.entrySet();
|
Set<Map.Entry<DateTime, StringTimedTransition>> transitions = timedString.entrySet();
|
||||||
timedString = forMapify("0", StringTimedTransition.class);
|
timedString = forMapify("0", StringTimedTransition.class);
|
||||||
|
@ -124,7 +121,7 @@ public class TimedTransitionPropertyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_valueMapNotChronologicallyOrdered() {
|
void testFailure_valueMapNotChronologicallyOrdered() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
() ->
|
() ->
|
||||||
|
@ -134,7 +131,7 @@ public class TimedTransitionPropertyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_transitionTimeBeforeStartOfTime() {
|
void testFailure_transitionTimeBeforeStartOfTime() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
() ->
|
() ->
|
||||||
|
@ -143,7 +140,7 @@ public class TimedTransitionPropertyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_noValues() {
|
void testFailure_noValues() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
() ->
|
() ->
|
||||||
|
@ -152,7 +149,7 @@ public class TimedTransitionPropertyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_noValueAtStartOfTime() {
|
void testFailure_noValueAtStartOfTime() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
() ->
|
() ->
|
||||||
|
@ -161,7 +158,7 @@ public class TimedTransitionPropertyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_noValuesAfterSimulatedEmptyLoad() {
|
void testFailure_noValuesAfterSimulatedEmptyLoad() {
|
||||||
timedString = forMapify("0", StringTimedTransition.class);
|
timedString = forMapify("0", StringTimedTransition.class);
|
||||||
// Simulate a load from Datastore by clearing, but don't insert any transitions.
|
// Simulate a load from Datastore by clearing, but don't insert any transitions.
|
||||||
timedString.clear();
|
timedString.clear();
|
||||||
|
@ -169,7 +166,7 @@ public class TimedTransitionPropertyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_noValueAtStartOfTimeAfterSimulatedLoad() {
|
void testFailure_noValueAtStartOfTimeAfterSimulatedLoad() {
|
||||||
// Just for testing, don't extract transitions from a TimedTransitionProperty in real code.
|
// Just for testing, don't extract transitions from a TimedTransitionProperty in real code.
|
||||||
StringTimedTransition transition1 = timedString.get(DATE_1);
|
StringTimedTransition transition1 = timedString.get(DATE_1);
|
||||||
timedString = forMapify("0", StringTimedTransition.class);
|
timedString = forMapify("0", StringTimedTransition.class);
|
||||||
|
|
|
@ -22,16 +22,13 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import google.registry.testing.EppLoader;
|
import google.registry.testing.EppLoader;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Test xml roundtripping of commands. */
|
/** Test xml roundtripping of commands. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class ContactCommandTest {
|
public class ContactCommandTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
private void doXmlRoundtripTest(String inputFilename) throws Exception {
|
private void doXmlRoundtripTest(String inputFilename) throws Exception {
|
||||||
|
@ -49,52 +46,52 @@ public class ContactCommandTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreate() throws Exception {
|
void testCreate() throws Exception {
|
||||||
doXmlRoundtripTest("contact_create.xml");
|
doXmlRoundtripTest("contact_create.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDelete() throws Exception {
|
void testDelete() throws Exception {
|
||||||
doXmlRoundtripTest("contact_delete.xml");
|
doXmlRoundtripTest("contact_delete.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdate() throws Exception {
|
void testUpdate() throws Exception {
|
||||||
doXmlRoundtripTest("contact_update.xml");
|
doXmlRoundtripTest("contact_update.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInfo() throws Exception {
|
void testInfo() throws Exception {
|
||||||
doXmlRoundtripTest("contact_info.xml");
|
doXmlRoundtripTest("contact_info.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCheck() throws Exception {
|
void testCheck() throws Exception {
|
||||||
doXmlRoundtripTest("contact_check.xml");
|
doXmlRoundtripTest("contact_check.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransferApprove() throws Exception {
|
void testTransferApprove() throws Exception {
|
||||||
doXmlRoundtripTest("contact_transfer_approve.xml");
|
doXmlRoundtripTest("contact_transfer_approve.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransferReject() throws Exception {
|
void testTransferReject() throws Exception {
|
||||||
doXmlRoundtripTest("contact_transfer_reject.xml");
|
doXmlRoundtripTest("contact_transfer_reject.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransferCancel() throws Exception {
|
void testTransferCancel() throws Exception {
|
||||||
doXmlRoundtripTest("contact_transfer_cancel.xml");
|
doXmlRoundtripTest("contact_transfer_cancel.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransferQuery() throws Exception {
|
void testTransferQuery() throws Exception {
|
||||||
doXmlRoundtripTest("contact_transfer_query.xml");
|
doXmlRoundtripTest("contact_transfer_query.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransferRequest() throws Exception {
|
void testTransferRequest() throws Exception {
|
||||||
doXmlRoundtripTest("contact_transfer_request.xml");
|
doXmlRoundtripTest("contact_transfer_request.xml");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,15 +45,15 @@ import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/** Unit tests for {@link ContactResource}. */
|
/** Unit tests for {@link ContactResource}. */
|
||||||
public class ContactResourceTest extends EntityTestCase {
|
public class ContactResourceTest extends EntityTestCase {
|
||||||
ContactResource originalContact;
|
private ContactResource originalContact;
|
||||||
ContactResource contactResource;
|
private ContactResource contactResource;
|
||||||
|
|
||||||
public ContactResourceTest() {
|
ContactResourceTest() {
|
||||||
super(JpaEntityCoverageCheck.ENABLED);
|
super(JpaEntityCoverageCheck.ENABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
createTld("foobar");
|
createTld("foobar");
|
||||||
originalContact =
|
originalContact =
|
||||||
new ContactResource.Builder()
|
new ContactResource.Builder()
|
||||||
|
@ -124,12 +124,12 @@ public class ContactResourceTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCloudSqlPersistence_failWhenViolateForeignKeyConstraint() {
|
void testCloudSqlPersistence_failWhenViolateForeignKeyConstraint() {
|
||||||
assertThrowForeignKeyViolation(() -> jpaTm().transact(() -> jpaTm().saveNew(originalContact)));
|
assertThrowForeignKeyViolation(() -> jpaTm().transact(() -> jpaTm().saveNew(originalContact)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCloudSqlPersistence_succeed() {
|
void testCloudSqlPersistence_succeed() {
|
||||||
saveRegistrar("registrar1");
|
saveRegistrar("registrar1");
|
||||||
saveRegistrar("registrar2");
|
saveRegistrar("registrar2");
|
||||||
saveRegistrar("registrar3");
|
saveRegistrar("registrar3");
|
||||||
|
@ -158,7 +158,7 @@ public class ContactResourceTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPersistence() {
|
void testPersistence() {
|
||||||
assertThat(
|
assertThat(
|
||||||
loadByForeignKey(
|
loadByForeignKey(
|
||||||
ContactResource.class, contactResource.getForeignKey(), fakeClock.nowUtc()))
|
ContactResource.class, contactResource.getForeignKey(), fakeClock.nowUtc()))
|
||||||
|
@ -166,12 +166,12 @@ public class ContactResourceTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIndexing() throws Exception {
|
void testIndexing() throws Exception {
|
||||||
verifyIndexing(contactResource, "deletionTime", "currentSponsorClientId", "searchName");
|
verifyIndexing(contactResource, "deletionTime", "currentSponsorClientId", "searchName");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyStringsBecomeNull() {
|
void testEmptyStringsBecomeNull() {
|
||||||
assertThat(new ContactResource.Builder().setContactId(null).build().getContactId()).isNull();
|
assertThat(new ContactResource.Builder().setContactId(null).build().getContactId()).isNull();
|
||||||
assertThat(new ContactResource.Builder().setContactId("").build().getContactId()).isNull();
|
assertThat(new ContactResource.Builder().setContactId("").build().getContactId()).isNull();
|
||||||
assertThat(new ContactResource.Builder().setContactId(" ").build().getContactId()).isNotNull();
|
assertThat(new ContactResource.Builder().setContactId(" ").build().getContactId()).isNotNull();
|
||||||
|
@ -203,7 +203,7 @@ public class ContactResourceTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyTransferDataBecomesNull() {
|
void testEmptyTransferDataBecomesNull() {
|
||||||
ContactResource withNull = new ContactResource.Builder().setTransferData(null).build();
|
ContactResource withNull = new ContactResource.Builder().setTransferData(null).build();
|
||||||
ContactResource withEmpty =
|
ContactResource withEmpty =
|
||||||
withNull.asBuilder().setTransferData(ContactTransferData.EMPTY).build();
|
withNull.asBuilder().setTransferData(ContactTransferData.EMPTY).build();
|
||||||
|
@ -212,7 +212,7 @@ public class ContactResourceTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImplicitStatusValues() {
|
void testImplicitStatusValues() {
|
||||||
// OK is implicit if there's no other statuses.
|
// OK is implicit if there's no other statuses.
|
||||||
assertAboutContacts()
|
assertAboutContacts()
|
||||||
.that(new ContactResource.Builder().build())
|
.that(new ContactResource.Builder().build())
|
||||||
|
@ -234,7 +234,7 @@ public class ContactResourceTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExpiredTransfer() {
|
void testExpiredTransfer() {
|
||||||
ContactResource afterTransfer =
|
ContactResource afterTransfer =
|
||||||
contactResource
|
contactResource
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
|
@ -255,7 +255,7 @@ public class ContactResourceTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetCreationTime_cantBeCalledTwice() {
|
void testSetCreationTime_cantBeCalledTwice() {
|
||||||
IllegalStateException thrown =
|
IllegalStateException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalStateException.class,
|
IllegalStateException.class,
|
||||||
|
@ -264,7 +264,7 @@ public class ContactResourceTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToHydratedString_notCircular() {
|
void testToHydratedString_notCircular() {
|
||||||
// If there are circular references, this will overflow the stack.
|
// If there are circular references, this will overflow the stack.
|
||||||
contactResource.toHydratedString();
|
contactResource.toHydratedString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,16 +55,16 @@ public class DomainBaseSqlTest {
|
||||||
JpaIntegrationWithCoverageExtension jpa =
|
JpaIntegrationWithCoverageExtension jpa =
|
||||||
new JpaTestRules.Builder().withClock(fakeClock).buildIntegrationWithCoverageExtension();
|
new JpaTestRules.Builder().withClock(fakeClock).buildIntegrationWithCoverageExtension();
|
||||||
|
|
||||||
DomainBase domain;
|
private DomainBase domain;
|
||||||
VKey<ContactResource> contactKey;
|
private VKey<ContactResource> contactKey;
|
||||||
VKey<ContactResource> contact2Key;
|
private VKey<ContactResource> contact2Key;
|
||||||
VKey<HostResource> host1VKey;
|
private VKey<HostResource> host1VKey;
|
||||||
HostResource host;
|
private HostResource host;
|
||||||
ContactResource contact;
|
private ContactResource contact;
|
||||||
ContactResource contact2;
|
private ContactResource contact2;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
saveRegistrar("registrar1");
|
saveRegistrar("registrar1");
|
||||||
saveRegistrar("registrar2");
|
saveRegistrar("registrar2");
|
||||||
saveRegistrar("registrar3");
|
saveRegistrar("registrar3");
|
||||||
|
@ -114,7 +114,7 @@ public class DomainBaseSqlTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDomainBasePersistence() {
|
void testDomainBasePersistence() {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
|
@ -159,7 +159,7 @@ public class DomainBaseSqlTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHostForeignKeyConstraints() {
|
void testHostForeignKeyConstraints() {
|
||||||
assertThrowForeignKeyViolation(
|
assertThrowForeignKeyViolation(
|
||||||
() -> {
|
() -> {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
|
@ -174,7 +174,7 @@ public class DomainBaseSqlTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testContactForeignKeyConstraints() {
|
void testContactForeignKeyConstraints() {
|
||||||
assertThrowForeignKeyViolation(
|
assertThrowForeignKeyViolation(
|
||||||
() -> {
|
() -> {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
|
@ -187,7 +187,7 @@ public class DomainBaseSqlTest {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ContactResource makeContact(String repoId) {
|
static ContactResource makeContact(String repoId) {
|
||||||
return new ContactResource.Builder()
|
return new ContactResource.Builder()
|
||||||
.setRepoId(repoId)
|
.setRepoId(repoId)
|
||||||
.setCreationClientId("registrar1")
|
.setCreationClientId("registrar1")
|
||||||
|
|
|
@ -57,8 +57,8 @@ import google.registry.model.transfer.TransferStatus;
|
||||||
import google.registry.persistence.VKey;
|
import google.registry.persistence.VKey;
|
||||||
import org.joda.money.Money;
|
import org.joda.money.Money;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/** Unit tests for {@link DomainBase}. */
|
/** Unit tests for {@link DomainBase}. */
|
||||||
public class DomainBaseTest extends EntityTestCase {
|
public class DomainBaseTest extends EntityTestCase {
|
||||||
|
@ -68,8 +68,8 @@ public class DomainBaseTest extends EntityTestCase {
|
||||||
private Key<BillingEvent.Recurring> recurringBillKey;
|
private Key<BillingEvent.Recurring> recurringBillKey;
|
||||||
private Key<DomainBase> domainKey;
|
private Key<DomainBase> domainKey;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
createTld("com");
|
createTld("com");
|
||||||
domainKey = Key.create(null, DomainBase.class, "4-COM");
|
domainKey = Key.create(null, DomainBase.class, "4-COM");
|
||||||
VKey<HostResource> hostKey =
|
VKey<HostResource> hostKey =
|
||||||
|
@ -163,13 +163,13 @@ public class DomainBaseTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPersistence() {
|
void testPersistence() {
|
||||||
assertThat(loadByForeignKey(DomainBase.class, domain.getForeignKey(), fakeClock.nowUtc()))
|
assertThat(loadByForeignKey(DomainBase.class, domain.getForeignKey(), fakeClock.nowUtc()))
|
||||||
.hasValue(domain);
|
.hasValue(domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIndexing() throws Exception {
|
void testIndexing() throws Exception {
|
||||||
verifyIndexing(
|
verifyIndexing(
|
||||||
domain,
|
domain,
|
||||||
"allContacts.contact",
|
"allContacts.contact",
|
||||||
|
@ -181,7 +181,7 @@ public class DomainBaseTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyStringsBecomeNull() {
|
void testEmptyStringsBecomeNull() {
|
||||||
assertThat(
|
assertThat(
|
||||||
newDomainBase("example.com")
|
newDomainBase("example.com")
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
|
@ -206,7 +206,7 @@ public class DomainBaseTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptySetsAndArraysBecomeNull() {
|
void testEmptySetsAndArraysBecomeNull() {
|
||||||
assertThat(
|
assertThat(
|
||||||
newDomainBase("example.com")
|
newDomainBase("example.com")
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
|
@ -262,7 +262,7 @@ public class DomainBaseTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyTransferDataBecomesNull() {
|
void testEmptyTransferDataBecomesNull() {
|
||||||
DomainBase withNull = newDomainBase("example.com").asBuilder().setTransferData(null).build();
|
DomainBase withNull = newDomainBase("example.com").asBuilder().setTransferData(null).build();
|
||||||
DomainBase withEmpty = withNull.asBuilder().setTransferData(DomainTransferData.EMPTY).build();
|
DomainBase withEmpty = withNull.asBuilder().setTransferData(DomainTransferData.EMPTY).build();
|
||||||
assertThat(withNull).isEqualTo(withEmpty);
|
assertThat(withNull).isEqualTo(withEmpty);
|
||||||
|
@ -270,7 +270,7 @@ public class DomainBaseTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImplicitStatusValues() {
|
void testImplicitStatusValues() {
|
||||||
ImmutableSet<VKey<HostResource>> nameservers =
|
ImmutableSet<VKey<HostResource>> nameservers =
|
||||||
ImmutableSet.of(newHostResource("foo.example.tld").createVKey());
|
ImmutableSet.of(newHostResource("foo.example.tld").createVKey());
|
||||||
StatusValue[] statuses = {StatusValue.OK};
|
StatusValue[] statuses = {StatusValue.OK};
|
||||||
|
@ -402,12 +402,12 @@ public class DomainBaseTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExpiredTransfer() {
|
void testExpiredTransfer() {
|
||||||
doExpiredTransferTest(fakeClock.nowUtc().plusMonths(1));
|
doExpiredTransferTest(fakeClock.nowUtc().plusMonths(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExpiredTransfer_autoRenewBeforeTransfer() {
|
void testExpiredTransfer_autoRenewBeforeTransfer() {
|
||||||
// Since transfer swallows a preceding autorenew, this should be identical to the regular
|
// Since transfer swallows a preceding autorenew, this should be identical to the regular
|
||||||
// transfer case (and specifically, the new expiration and grace periods will be the same as if
|
// transfer case (and specifically, the new expiration and grace periods will be the same as if
|
||||||
// there was no autorenew).
|
// there was no autorenew).
|
||||||
|
@ -434,7 +434,7 @@ public class DomainBaseTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEppLastUpdateTimeAndClientId_autoRenewBeforeTransferSuccess() {
|
void testEppLastUpdateTimeAndClientId_autoRenewBeforeTransferSuccess() {
|
||||||
DateTime now = fakeClock.nowUtc();
|
DateTime now = fakeClock.nowUtc();
|
||||||
DateTime transferRequestDateTime = now.plusDays(1);
|
DateTime transferRequestDateTime = now.plusDays(1);
|
||||||
DateTime autorenewDateTime = now.plusDays(3);
|
DateTime autorenewDateTime = now.plusDays(3);
|
||||||
|
@ -453,7 +453,7 @@ public class DomainBaseTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEppLastUpdateTimeAndClientId_autoRenewAfterTransferSuccess() {
|
void testEppLastUpdateTimeAndClientId_autoRenewAfterTransferSuccess() {
|
||||||
DateTime now = fakeClock.nowUtc();
|
DateTime now = fakeClock.nowUtc();
|
||||||
DateTime transferRequestDateTime = now.plusDays(1);
|
DateTime transferRequestDateTime = now.plusDays(1);
|
||||||
DateTime autorenewDateTime = now.plusDays(3);
|
DateTime autorenewDateTime = now.plusDays(3);
|
||||||
|
@ -483,7 +483,7 @@ public class DomainBaseTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEppLastUpdateTimeAndClientId_isSetCorrectlyWithNullPreviousValue() {
|
void testEppLastUpdateTimeAndClientId_isSetCorrectlyWithNullPreviousValue() {
|
||||||
DateTime now = fakeClock.nowUtc();
|
DateTime now = fakeClock.nowUtc();
|
||||||
DateTime autorenewDateTime = now.plusDays(3);
|
DateTime autorenewDateTime = now.plusDays(3);
|
||||||
setupUnmodifiedDomain(autorenewDateTime);
|
setupUnmodifiedDomain(autorenewDateTime);
|
||||||
|
@ -498,7 +498,7 @@ public class DomainBaseTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStackedGracePeriods() {
|
void testStackedGracePeriods() {
|
||||||
ImmutableList<GracePeriod> gracePeriods =
|
ImmutableList<GracePeriod> gracePeriods =
|
||||||
ImmutableList.of(
|
ImmutableList.of(
|
||||||
GracePeriod.create(GracePeriodStatus.ADD, fakeClock.nowUtc().plusDays(3), "foo", null),
|
GracePeriod.create(GracePeriodStatus.ADD, fakeClock.nowUtc().plusDays(3), "foo", null),
|
||||||
|
@ -512,7 +512,7 @@ public class DomainBaseTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGracePeriodsByType() {
|
void testGracePeriodsByType() {
|
||||||
ImmutableSet<GracePeriod> addGracePeriods =
|
ImmutableSet<GracePeriod> addGracePeriods =
|
||||||
ImmutableSet.of(
|
ImmutableSet.of(
|
||||||
GracePeriod.create(GracePeriodStatus.ADD, fakeClock.nowUtc().plusDays(3), "foo", null),
|
GracePeriod.create(GracePeriodStatus.ADD, fakeClock.nowUtc().plusDays(3), "foo", null),
|
||||||
|
@ -536,7 +536,7 @@ public class DomainBaseTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRenewalsHappenAtExpiration() {
|
void testRenewalsHappenAtExpiration() {
|
||||||
DomainBase renewed = domain.cloneProjectedAtTime(domain.getRegistrationExpirationTime());
|
DomainBase renewed = domain.cloneProjectedAtTime(domain.getRegistrationExpirationTime());
|
||||||
assertThat(renewed.getRegistrationExpirationTime())
|
assertThat(renewed.getRegistrationExpirationTime())
|
||||||
.isEqualTo(domain.getRegistrationExpirationTime().plusYears(1));
|
.isEqualTo(domain.getRegistrationExpirationTime().plusYears(1));
|
||||||
|
@ -546,14 +546,14 @@ public class DomainBaseTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTldGetsSet() {
|
void testTldGetsSet() {
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
domain = newDomainBase("foo.tld");
|
domain = newDomainBase("foo.tld");
|
||||||
assertThat(domain.getTld()).isEqualTo("tld");
|
assertThat(domain.getTld()).isEqualTo("tld");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRenewalsDontHappenOnFebruary29() {
|
void testRenewalsDontHappenOnFebruary29() {
|
||||||
domain =
|
domain =
|
||||||
domain
|
domain
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
|
@ -565,7 +565,7 @@ public class DomainBaseTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultipleAutoRenews() {
|
void testMultipleAutoRenews() {
|
||||||
// Change the registry so that renewal costs change every year to make sure we are using the
|
// Change the registry so that renewal costs change every year to make sure we are using the
|
||||||
// autorenew time as the lookup time for the cost.
|
// autorenew time as the lookup time for the cost.
|
||||||
DateTime oldExpirationTime = domain.getRegistrationExpirationTime();
|
DateTime oldExpirationTime = domain.getRegistrationExpirationTime();
|
||||||
|
@ -599,12 +599,12 @@ public class DomainBaseTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToHydratedString_notCircular() {
|
void testToHydratedString_notCircular() {
|
||||||
domain.toHydratedString(); // If there are circular references, this will overflow the stack.
|
domain.toHydratedString(); // If there are circular references, this will overflow the stack.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_uppercaseDomainName() {
|
void testFailure_uppercaseDomainName() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class, () -> domain.asBuilder().setDomainName("AAA.BBB"));
|
IllegalArgumentException.class, () -> domain.asBuilder().setDomainName("AAA.BBB"));
|
||||||
|
@ -614,7 +614,7 @@ public class DomainBaseTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_utf8DomainName() {
|
void testFailure_utf8DomainName() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class, () -> domain.asBuilder().setDomainName("みんな.みんな"));
|
IllegalArgumentException.class, () -> domain.asBuilder().setDomainName("みんな.みんな"));
|
||||||
|
@ -624,7 +624,7 @@ public class DomainBaseTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClone_doNotExtendExpirationOnDeletedDomain() {
|
void testClone_doNotExtendExpirationOnDeletedDomain() {
|
||||||
DateTime now = DateTime.now(UTC);
|
DateTime now = DateTime.now(UTC);
|
||||||
domain =
|
domain =
|
||||||
persistResource(
|
persistResource(
|
||||||
|
@ -639,7 +639,7 @@ public class DomainBaseTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClone_doNotExtendExpirationOnFutureDeletedDomain() {
|
void testClone_doNotExtendExpirationOnFutureDeletedDomain() {
|
||||||
// if a domain is in pending deletion (StatusValue.PENDING_DELETE), don't extend expiration
|
// if a domain is in pending deletion (StatusValue.PENDING_DELETE), don't extend expiration
|
||||||
DateTime now = DateTime.now(UTC);
|
DateTime now = DateTime.now(UTC);
|
||||||
domain =
|
domain =
|
||||||
|
@ -655,7 +655,7 @@ public class DomainBaseTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClone_extendsExpirationForExpiredTransferredDomain() {
|
void testClone_extendsExpirationForExpiredTransferredDomain() {
|
||||||
// If the transfer implicitly succeeded, the expiration time should be extended
|
// If the transfer implicitly succeeded, the expiration time should be extended
|
||||||
DateTime now = DateTime.now(UTC);
|
DateTime now = DateTime.now(UTC);
|
||||||
DateTime transferExpirationTime = now.minusDays(1);
|
DateTime transferExpirationTime = now.minusDays(1);
|
||||||
|
@ -682,7 +682,7 @@ public class DomainBaseTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClone_extendsExpirationForNonExpiredTransferredDomain() {
|
void testClone_extendsExpirationForNonExpiredTransferredDomain() {
|
||||||
// If the transfer implicitly succeeded, the expiration time should be extended even if it
|
// If the transfer implicitly succeeded, the expiration time should be extended even if it
|
||||||
// hadn't already expired
|
// hadn't already expired
|
||||||
DateTime now = DateTime.now(UTC);
|
DateTime now = DateTime.now(UTC);
|
||||||
|
@ -710,7 +710,7 @@ public class DomainBaseTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClone_doesNotExtendExpirationForPendingTransfer() {
|
void testClone_doesNotExtendExpirationForPendingTransfer() {
|
||||||
// Pending transfers shouldn't affect the expiration time
|
// Pending transfers shouldn't affect the expiration time
|
||||||
DateTime now = DateTime.now(UTC);
|
DateTime now = DateTime.now(UTC);
|
||||||
DateTime transferExpirationTime = now.plusDays(1);
|
DateTime transferExpirationTime = now.plusDays(1);
|
||||||
|
@ -735,7 +735,7 @@ public class DomainBaseTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClone_transferDuringAutorenew() {
|
void testClone_transferDuringAutorenew() {
|
||||||
// When the domain is an an autorenew grace period, we should not extend the registration
|
// When the domain is an an autorenew grace period, we should not extend the registration
|
||||||
// expiration by a further year--it should just be whatever the autorenew was
|
// expiration by a further year--it should just be whatever the autorenew was
|
||||||
DateTime now = DateTime.now(UTC);
|
DateTime now = DateTime.now(UTC);
|
||||||
|
|
|
@ -22,60 +22,60 @@ import google.registry.model.eppinput.EppInput;
|
||||||
import google.registry.model.eppinput.EppInput.ResourceCommandWrapper;
|
import google.registry.model.eppinput.EppInput.ResourceCommandWrapper;
|
||||||
import google.registry.model.eppinput.ResourceCommand;
|
import google.registry.model.eppinput.ResourceCommand;
|
||||||
import google.registry.testing.EppLoader;
|
import google.registry.testing.EppLoader;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/** Tests for DomainCommand. */
|
/** Tests for DomainCommand. */
|
||||||
public class DomainCommandTest extends ResourceCommandTestCase {
|
class DomainCommandTest extends ResourceCommandTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreate() throws Exception {
|
void testCreate() throws Exception {
|
||||||
doXmlRoundtripTest("domain_create.xml");
|
doXmlRoundtripTest("domain_create.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreate_sunriseSignedMark() throws Exception {
|
void testCreate_sunriseSignedMark() throws Exception {
|
||||||
doXmlRoundtripTest("domain_create_sunrise_signed_mark.xml");
|
doXmlRoundtripTest("domain_create_sunrise_signed_mark.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreate_sunriseCode() throws Exception {
|
void testCreate_sunriseCode() throws Exception {
|
||||||
doXmlRoundtripTest("domain_create_sunrise_code.xml");
|
doXmlRoundtripTest("domain_create_sunrise_code.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreate_sunriseMark() throws Exception {
|
void testCreate_sunriseMark() throws Exception {
|
||||||
doXmlRoundtripTest("domain_create_sunrise_mark.xml");
|
doXmlRoundtripTest("domain_create_sunrise_mark.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreate_sunriseCodeWithMark() throws Exception {
|
void testCreate_sunriseCodeWithMark() throws Exception {
|
||||||
doXmlRoundtripTest("domain_create_sunrise_code_with_mark.xml");
|
doXmlRoundtripTest("domain_create_sunrise_code_with_mark.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreate_sunriseEncodedSignedMark() throws Exception {
|
void testCreate_sunriseEncodedSignedMark() throws Exception {
|
||||||
doXmlRoundtripTest("domain_create_sunrise_encoded_signed_mark.xml");
|
doXmlRoundtripTest("domain_create_sunrise_encoded_signed_mark.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreate_fee() throws Exception {
|
void testCreate_fee() throws Exception {
|
||||||
doXmlRoundtripTest("domain_create_fee.xml");
|
doXmlRoundtripTest("domain_create_fee.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreate_emptyCommand() throws Exception {
|
void testCreate_emptyCommand() throws Exception {
|
||||||
// This EPP command wouldn't be allowed for policy reasons, but should marshal/unmarshal fine.
|
// This EPP command wouldn't be allowed for policy reasons, but should marshal/unmarshal fine.
|
||||||
doXmlRoundtripTest("domain_create_empty.xml");
|
doXmlRoundtripTest("domain_create_empty.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreate_missingNonRegistrantContacts() throws Exception {
|
void testCreate_missingNonRegistrantContacts() throws Exception {
|
||||||
// This EPP command wouldn't be allowed for policy reasons, but should marshal/unmarshal fine.
|
// This EPP command wouldn't be allowed for policy reasons, but should marshal/unmarshal fine.
|
||||||
doXmlRoundtripTest("domain_create_missing_non_registrant_contacts.xml");
|
doXmlRoundtripTest("domain_create_missing_non_registrant_contacts.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreate_cloneAndLinkReferences() throws Exception {
|
void testCreate_cloneAndLinkReferences() throws Exception {
|
||||||
persistActiveHost("ns1.example.net");
|
persistActiveHost("ns1.example.net");
|
||||||
persistActiveHost("ns2.example.net");
|
persistActiveHost("ns2.example.net");
|
||||||
persistActiveContact("sh8013");
|
persistActiveContact("sh8013");
|
||||||
|
@ -86,7 +86,7 @@ public class DomainCommandTest extends ResourceCommandTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreate_emptyCommand_cloneAndLinkReferences() throws Exception {
|
void testCreate_emptyCommand_cloneAndLinkReferences() throws Exception {
|
||||||
// This EPP command wouldn't be allowed for policy reasons, but should clone-and-link fine.
|
// This EPP command wouldn't be allowed for policy reasons, but should clone-and-link fine.
|
||||||
DomainCommand.Create create =
|
DomainCommand.Create create =
|
||||||
(DomainCommand.Create) loadEppResourceCommand("domain_create_empty.xml");
|
(DomainCommand.Create) loadEppResourceCommand("domain_create_empty.xml");
|
||||||
|
@ -94,7 +94,7 @@ public class DomainCommandTest extends ResourceCommandTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreate_missingNonRegistrantContacts_cloneAndLinkReferences() throws Exception {
|
void testCreate_missingNonRegistrantContacts_cloneAndLinkReferences() throws Exception {
|
||||||
persistActiveContact("jd1234");
|
persistActiveContact("jd1234");
|
||||||
// This EPP command wouldn't be allowed for policy reasons, but should clone-and-link fine.
|
// This EPP command wouldn't be allowed for policy reasons, but should clone-and-link fine.
|
||||||
DomainCommand.Create create =
|
DomainCommand.Create create =
|
||||||
|
@ -104,28 +104,28 @@ public class DomainCommandTest extends ResourceCommandTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDelete() throws Exception {
|
void testDelete() throws Exception {
|
||||||
doXmlRoundtripTest("domain_delete.xml");
|
doXmlRoundtripTest("domain_delete.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdate() throws Exception {
|
void testUpdate() throws Exception {
|
||||||
doXmlRoundtripTest("domain_update.xml");
|
doXmlRoundtripTest("domain_update.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdate_fee() throws Exception {
|
void testUpdate_fee() throws Exception {
|
||||||
doXmlRoundtripTest("domain_update_fee.xml");
|
doXmlRoundtripTest("domain_update_fee.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdate_emptyCommand() throws Exception {
|
void testUpdate_emptyCommand() throws Exception {
|
||||||
// This EPP command wouldn't be allowed for policy reasons, but should marshal/unmarshal fine.
|
// This EPP command wouldn't be allowed for policy reasons, but should marshal/unmarshal fine.
|
||||||
doXmlRoundtripTest("domain_update_empty.xml");
|
doXmlRoundtripTest("domain_update_empty.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdate_cloneAndLinkReferences() throws Exception {
|
void testUpdate_cloneAndLinkReferences() throws Exception {
|
||||||
persistActiveHost("ns1.example.com");
|
persistActiveHost("ns1.example.com");
|
||||||
persistActiveHost("ns2.example.com");
|
persistActiveHost("ns2.example.com");
|
||||||
persistActiveContact("mak21");
|
persistActiveContact("mak21");
|
||||||
|
@ -136,7 +136,7 @@ public class DomainCommandTest extends ResourceCommandTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdate_emptyCommand_cloneAndLinkReferences() throws Exception {
|
void testUpdate_emptyCommand_cloneAndLinkReferences() throws Exception {
|
||||||
// This EPP command wouldn't be allowed for policy reasons, but should clone-and-link fine.
|
// This EPP command wouldn't be allowed for policy reasons, but should clone-and-link fine.
|
||||||
DomainCommand.Update update =
|
DomainCommand.Update update =
|
||||||
(DomainCommand.Update) loadEppResourceCommand("domain_update_empty.xml");
|
(DomainCommand.Update) loadEppResourceCommand("domain_update_empty.xml");
|
||||||
|
@ -144,77 +144,77 @@ public class DomainCommandTest extends ResourceCommandTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInfo() throws Exception {
|
void testInfo() throws Exception {
|
||||||
doXmlRoundtripTest("domain_info.xml");
|
doXmlRoundtripTest("domain_info.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInfo_sunrise() throws Exception {
|
void testInfo_sunrise() throws Exception {
|
||||||
doXmlRoundtripTest("domain_info_sunrise.xml");
|
doXmlRoundtripTest("domain_info_sunrise.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInfo_feeExtension() throws Exception {
|
void testInfo_feeExtension() throws Exception {
|
||||||
doXmlRoundtripTest("domain_info_fee.xml");
|
doXmlRoundtripTest("domain_info_fee.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCheck() throws Exception {
|
void testCheck() throws Exception {
|
||||||
doXmlRoundtripTest("domain_check.xml");
|
doXmlRoundtripTest("domain_check.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCheck_avail() throws Exception {
|
void testCheck_avail() throws Exception {
|
||||||
doXmlRoundtripTest("domain_check_avail.xml");
|
doXmlRoundtripTest("domain_check_avail.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCheck_claims() throws Exception {
|
void testCheck_claims() throws Exception {
|
||||||
doXmlRoundtripTest("domain_check_claims.xml");
|
doXmlRoundtripTest("domain_check_claims.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCheck_fee() throws Exception {
|
void testCheck_fee() throws Exception {
|
||||||
doXmlRoundtripTest("domain_check_fee.xml");
|
doXmlRoundtripTest("domain_check_fee.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransferApprove() throws Exception {
|
void testTransferApprove() throws Exception {
|
||||||
doXmlRoundtripTest("domain_transfer_approve.xml");
|
doXmlRoundtripTest("domain_transfer_approve.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransferReject() throws Exception {
|
void testTransferReject() throws Exception {
|
||||||
doXmlRoundtripTest("domain_transfer_reject.xml");
|
doXmlRoundtripTest("domain_transfer_reject.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransferCancel() throws Exception {
|
void testTransferCancel() throws Exception {
|
||||||
doXmlRoundtripTest("domain_transfer_cancel.xml");
|
doXmlRoundtripTest("domain_transfer_cancel.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransferQuery() throws Exception {
|
void testTransferQuery() throws Exception {
|
||||||
doXmlRoundtripTest("domain_transfer_query.xml");
|
doXmlRoundtripTest("domain_transfer_query.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransferRequest() throws Exception {
|
void testTransferRequest() throws Exception {
|
||||||
doXmlRoundtripTest("domain_transfer_request.xml");
|
doXmlRoundtripTest("domain_transfer_request.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransferRequest_fee() throws Exception {
|
void testTransferRequest_fee() throws Exception {
|
||||||
doXmlRoundtripTest("domain_transfer_request_fee.xml");
|
doXmlRoundtripTest("domain_transfer_request_fee.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRenew() throws Exception {
|
void testRenew() throws Exception {
|
||||||
doXmlRoundtripTest("domain_renew.xml");
|
doXmlRoundtripTest("domain_renew.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRenew_fee() throws Exception {
|
void testRenew_fee() throws Exception {
|
||||||
doXmlRoundtripTest("domain_renew_fee.xml");
|
doXmlRoundtripTest("domain_renew_fee.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,17 +28,14 @@ import google.registry.testing.AppEngineRule;
|
||||||
import org.joda.money.CurrencyUnit;
|
import org.joda.money.CurrencyUnit;
|
||||||
import org.joda.money.Money;
|
import org.joda.money.Money;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link GracePeriod}. */
|
/** Unit tests for {@link GracePeriod}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class GracePeriodTest {
|
public class GracePeriodTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine =
|
public final AppEngineRule appEngine =
|
||||||
AppEngineRule.builder()
|
AppEngineRule.builder()
|
||||||
.withDatastoreAndCloudSql() // Needed to be able to construct Keys.
|
.withDatastoreAndCloudSql() // Needed to be able to construct Keys.
|
||||||
|
@ -47,8 +44,8 @@ public class GracePeriodTest {
|
||||||
private final DateTime now = DateTime.now(UTC);
|
private final DateTime now = DateTime.now(UTC);
|
||||||
private BillingEvent.OneTime onetime;
|
private BillingEvent.OneTime onetime;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
onetime = new BillingEvent.OneTime.Builder()
|
onetime = new BillingEvent.OneTime.Builder()
|
||||||
.setEventTime(now)
|
.setEventTime(now)
|
||||||
.setBillingTime(now.plusDays(1))
|
.setBillingTime(now.plusDays(1))
|
||||||
|
@ -62,7 +59,7 @@ public class GracePeriodTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_forBillingEvent() {
|
void testSuccess_forBillingEvent() {
|
||||||
GracePeriod gracePeriod = GracePeriod.forBillingEvent(GracePeriodStatus.ADD, onetime);
|
GracePeriod gracePeriod = GracePeriod.forBillingEvent(GracePeriodStatus.ADD, onetime);
|
||||||
assertThat(gracePeriod.getType()).isEqualTo(GracePeriodStatus.ADD);
|
assertThat(gracePeriod.getType()).isEqualTo(GracePeriodStatus.ADD);
|
||||||
assertThat(gracePeriod.getOneTimeBillingEvent()).isEqualTo(Key.create(onetime));
|
assertThat(gracePeriod.getOneTimeBillingEvent()).isEqualTo(Key.create(onetime));
|
||||||
|
@ -73,7 +70,7 @@ public class GracePeriodTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_createWithoutBillingEvent() {
|
void testSuccess_createWithoutBillingEvent() {
|
||||||
GracePeriod gracePeriod = GracePeriod.createWithoutBillingEvent(
|
GracePeriod gracePeriod = GracePeriod.createWithoutBillingEvent(
|
||||||
GracePeriodStatus.REDEMPTION, now, "TheRegistrar");
|
GracePeriodStatus.REDEMPTION, now, "TheRegistrar");
|
||||||
assertThat(gracePeriod.getType()).isEqualTo(GracePeriodStatus.REDEMPTION);
|
assertThat(gracePeriod.getType()).isEqualTo(GracePeriodStatus.REDEMPTION);
|
||||||
|
@ -85,7 +82,7 @@ public class GracePeriodTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_forBillingEvent_autoRenew() {
|
void testFailure_forBillingEvent_autoRenew() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -94,7 +91,7 @@ public class GracePeriodTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_createForRecurring_notAutoRenew() {
|
void testFailure_createForRecurring_notAutoRenew() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
|
|
@ -37,19 +37,19 @@ import google.registry.model.domain.token.AllocationToken.TokenStatus;
|
||||||
import google.registry.model.domain.token.AllocationToken.TokenType;
|
import google.registry.model.domain.token.AllocationToken.TokenType;
|
||||||
import google.registry.model.reporting.HistoryEntry;
|
import google.registry.model.reporting.HistoryEntry;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/** Unit tests for {@link AllocationToken}. */
|
/** Unit tests for {@link AllocationToken}. */
|
||||||
public class AllocationTokenTest extends EntityTestCase {
|
class AllocationTokenTest extends EntityTestCase {
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setup() {
|
void setup() {
|
||||||
createTld("foo");
|
createTld("foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPersistence() {
|
void testPersistence() {
|
||||||
AllocationToken unlimitedUseToken =
|
AllocationToken unlimitedUseToken =
|
||||||
persistResource(
|
persistResource(
|
||||||
new AllocationToken.Builder()
|
new AllocationToken.Builder()
|
||||||
|
@ -81,7 +81,7 @@ public class AllocationTokenTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIndexing() throws Exception {
|
void testIndexing() throws Exception {
|
||||||
verifyIndexing(
|
verifyIndexing(
|
||||||
persistResource(
|
persistResource(
|
||||||
new AllocationToken.Builder()
|
new AllocationToken.Builder()
|
||||||
|
@ -97,7 +97,7 @@ public class AllocationTokenTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreationTime_autoPopulates() {
|
void testCreationTime_autoPopulates() {
|
||||||
AllocationToken tokenBeforePersisting =
|
AllocationToken tokenBeforePersisting =
|
||||||
new AllocationToken.Builder().setToken("abc123").setTokenType(SINGLE_USE).build();
|
new AllocationToken.Builder().setToken("abc123").setTokenType(SINGLE_USE).build();
|
||||||
assertThat(tokenBeforePersisting.getCreationTime()).isEmpty();
|
assertThat(tokenBeforePersisting.getCreationTime()).isEmpty();
|
||||||
|
@ -106,7 +106,7 @@ public class AllocationTokenTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetCreationTime_cantCallMoreThanOnce() {
|
void testSetCreationTime_cantCallMoreThanOnce() {
|
||||||
AllocationToken.Builder builder =
|
AllocationToken.Builder builder =
|
||||||
new AllocationToken.Builder()
|
new AllocationToken.Builder()
|
||||||
.setToken("foobar")
|
.setToken("foobar")
|
||||||
|
@ -120,7 +120,7 @@ public class AllocationTokenTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetToken_cantCallMoreThanOnce() {
|
void testSetToken_cantCallMoreThanOnce() {
|
||||||
AllocationToken.Builder builder = new AllocationToken.Builder().setToken("foobar");
|
AllocationToken.Builder builder = new AllocationToken.Builder().setToken("foobar");
|
||||||
IllegalStateException thrown =
|
IllegalStateException thrown =
|
||||||
assertThrows(IllegalStateException.class, () -> builder.setToken("barfoo"));
|
assertThrows(IllegalStateException.class, () -> builder.setToken("barfoo"));
|
||||||
|
@ -128,7 +128,7 @@ public class AllocationTokenTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetTokenType_cantCallMoreThanOnce() {
|
void testSetTokenType_cantCallMoreThanOnce() {
|
||||||
AllocationToken.Builder builder =
|
AllocationToken.Builder builder =
|
||||||
new AllocationToken.Builder().setTokenType(TokenType.UNLIMITED_USE);
|
new AllocationToken.Builder().setTokenType(TokenType.UNLIMITED_USE);
|
||||||
IllegalStateException thrown =
|
IllegalStateException thrown =
|
||||||
|
@ -137,7 +137,7 @@ public class AllocationTokenTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuild_DomainNameWithLessThanTwoParts() {
|
void testBuild_DomainNameWithLessThanTwoParts() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -155,7 +155,7 @@ public class AllocationTokenTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuild_invalidTLD() {
|
void testBuild_invalidTLD() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -173,7 +173,7 @@ public class AllocationTokenTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuild_domainNameOnlyOnSingleUse() {
|
void testBuild_domainNameOnlyOnSingleUse() {
|
||||||
AllocationToken.Builder builder =
|
AllocationToken.Builder builder =
|
||||||
new AllocationToken.Builder()
|
new AllocationToken.Builder()
|
||||||
.setToken("foobar")
|
.setToken("foobar")
|
||||||
|
@ -186,7 +186,7 @@ public class AllocationTokenTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuild_redemptionHistoryEntryOnlyInSingleUse() {
|
void testBuild_redemptionHistoryEntryOnlyInSingleUse() {
|
||||||
AllocationToken.Builder builder =
|
AllocationToken.Builder builder =
|
||||||
new AllocationToken.Builder()
|
new AllocationToken.Builder()
|
||||||
.setToken("foobar")
|
.setToken("foobar")
|
||||||
|
@ -199,7 +199,7 @@ public class AllocationTokenTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetTransitions_notStartOfTime() {
|
void testSetTransitions_notStartOfTime() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -217,7 +217,7 @@ public class AllocationTokenTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetTransitions_badInitialValue() {
|
void testSetTransitions_badInitialValue() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -234,14 +234,14 @@ public class AllocationTokenTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetTransitions_invalidInitialTransitions() {
|
void testSetTransitions_invalidInitialTransitions() {
|
||||||
// NOT_STARTED can only go to VALID or CANCELLED
|
// NOT_STARTED can only go to VALID or CANCELLED
|
||||||
assertBadInitialTransition(NOT_STARTED);
|
assertBadInitialTransition(NOT_STARTED);
|
||||||
assertBadInitialTransition(ENDED);
|
assertBadInitialTransition(ENDED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetTransitions_badTransitionsFromValid() {
|
void testSetTransitions_badTransitionsFromValid() {
|
||||||
// VALID can only go to ENDED or CANCELLED
|
// VALID can only go to ENDED or CANCELLED
|
||||||
assertBadTransition(
|
assertBadTransition(
|
||||||
ImmutableSortedMap.<DateTime, TokenStatus>naturalOrder()
|
ImmutableSortedMap.<DateTime, TokenStatus>naturalOrder()
|
||||||
|
@ -262,14 +262,14 @@ public class AllocationTokenTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetTransitions_terminalTransitions() {
|
void testSetTransitions_terminalTransitions() {
|
||||||
// both ENDED and CANCELLED are terminal
|
// both ENDED and CANCELLED are terminal
|
||||||
assertTerminal(ENDED);
|
assertTerminal(ENDED);
|
||||||
assertTerminal(CANCELLED);
|
assertTerminal(CANCELLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuild_noTokenType() {
|
void testBuild_noTokenType() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -278,7 +278,7 @@ public class AllocationTokenTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuild_noToken() {
|
void testBuild_noToken() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -287,7 +287,7 @@ public class AllocationTokenTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuild_emptyToken() {
|
void testBuild_emptyToken() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
|
|
@ -17,15 +17,13 @@ package google.registry.model.eppcommon;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Tests for {@link Address}. */
|
/** Tests for {@link Address}. */
|
||||||
@RunWith(JUnit4.class)
|
class AddressTest {
|
||||||
public class AddressTest {
|
|
||||||
@Test
|
@Test
|
||||||
public void onLoad_setsIndividualStreetLinesSuccessfully() {
|
void onLoad_setsIndividualStreetLinesSuccessfully() {
|
||||||
Address address = new Address();
|
Address address = new Address();
|
||||||
address.onLoad(ImmutableList.of("line1", "line2", "line3"));
|
address.onLoad(ImmutableList.of("line1", "line2", "line3"));
|
||||||
assertThat(address.streetLine1).isEqualTo("line1");
|
assertThat(address.streetLine1).isEqualTo("line1");
|
||||||
|
@ -34,7 +32,7 @@ public class AddressTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onLoad_setsOnlyNonNullStreetLines() {
|
void onLoad_setsOnlyNonNullStreetLines() {
|
||||||
Address address = new Address();
|
Address address = new Address();
|
||||||
address.onLoad(ImmutableList.of("line1", "line2"));
|
address.onLoad(ImmutableList.of("line1", "line2"));
|
||||||
assertThat(address.streetLine1).isEqualTo("line1");
|
assertThat(address.streetLine1).isEqualTo("line1");
|
||||||
|
@ -43,7 +41,7 @@ public class AddressTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onLoad_doNothingIfInputIsNull() {
|
void onLoad_doNothingIfInputIsNull() {
|
||||||
Address address = new Address();
|
Address address = new Address();
|
||||||
address.onLoad(null);
|
address.onLoad(null);
|
||||||
assertThat(address.streetLine1).isNull();
|
assertThat(address.streetLine1).isNull();
|
||||||
|
@ -52,7 +50,7 @@ public class AddressTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void postLoad_setsStreetListSuccessfully() {
|
void postLoad_setsStreetListSuccessfully() {
|
||||||
Address address = new Address();
|
Address address = new Address();
|
||||||
address.streetLine1 = "line1";
|
address.streetLine1 = "line1";
|
||||||
address.streetLine2 = "line2";
|
address.streetLine2 = "line2";
|
||||||
|
@ -62,7 +60,7 @@ public class AddressTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void postLoad_setsOnlyNonNullStreetLines() {
|
void postLoad_setsOnlyNonNullStreetLines() {
|
||||||
Address address = new Address();
|
Address address = new Address();
|
||||||
address.streetLine1 = "line1";
|
address.streetLine1 = "line1";
|
||||||
address.streetLine2 = "line2";
|
address.streetLine2 = "line2";
|
||||||
|
@ -71,7 +69,7 @@ public class AddressTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void postLoad_doNothingIfInputIsNull() {
|
void postLoad_doNothingIfInputIsNull() {
|
||||||
Address address = new Address();
|
Address address = new Address();
|
||||||
address.postLoad();
|
address.postLoad();
|
||||||
assertThat(address.street).isNull();
|
assertThat(address.street).isNull();
|
||||||
|
|
|
@ -21,22 +21,19 @@ import static org.junit.Assert.assertThrows;
|
||||||
|
|
||||||
import google.registry.model.eppinput.EppInput;
|
import google.registry.model.eppinput.EppInput;
|
||||||
import google.registry.model.eppoutput.EppOutput;
|
import google.registry.model.eppoutput.EppOutput;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Tests for {@link EppXmlTransformer}. */
|
/** Tests for {@link EppXmlTransformer}. */
|
||||||
@RunWith(JUnit4.class)
|
class EppXmlTransformerTest {
|
||||||
public class EppXmlTransformerTest {
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnmarshalingEppInput() throws Exception {
|
void testUnmarshalingEppInput() throws Exception {
|
||||||
EppInput input = unmarshal(EppInput.class, loadBytes(getClass(), "contact_info.xml").read());
|
EppInput input = unmarshal(EppInput.class, loadBytes(getClass(), "contact_info.xml").read());
|
||||||
assertThat(input.getCommandType()).isEqualTo("info");
|
assertThat(input.getCommandType()).isEqualTo("info");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnmarshalingWrongClassThrows() {
|
void testUnmarshalingWrongClassThrows() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
ClassCastException.class,
|
ClassCastException.class,
|
||||||
() -> unmarshal(EppOutput.class, loadBytes(getClass(), "contact_info.xml").read()));
|
() -> unmarshal(EppOutput.class, loadBytes(getClass(), "contact_info.xml").read()));
|
||||||
|
|
|
@ -25,16 +25,13 @@ import google.registry.model.domain.DomainBaseTest;
|
||||||
import google.registry.model.eppinput.EppInput.InnerCommand;
|
import google.registry.model.eppinput.EppInput.InnerCommand;
|
||||||
import google.registry.model.eppinput.EppInput.Login;
|
import google.registry.model.eppinput.EppInput.Login;
|
||||||
import google.registry.xml.XmlException;
|
import google.registry.xml.XmlException;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link EppInput}. */
|
/** Unit tests for {@link EppInput}. */
|
||||||
@RunWith(JUnit4.class)
|
class EppInputTest {
|
||||||
public class EppInputTest {
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnmarshalling_contactInfo() throws Exception {
|
void testUnmarshalling_contactInfo() throws Exception {
|
||||||
EppInput input =
|
EppInput input =
|
||||||
unmarshal(EppInput.class, loadBytes(ContactResourceTest.class, "contact_info.xml").read());
|
unmarshal(EppInput.class, loadBytes(ContactResourceTest.class, "contact_info.xml").read());
|
||||||
assertThat(input.getCommandWrapper().getClTrid()).hasValue("ABC-12345");
|
assertThat(input.getCommandWrapper().getClTrid()).hasValue("ABC-12345");
|
||||||
|
@ -45,7 +42,7 @@ public class EppInputTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnmarshalling_domainCheck() throws Exception {
|
void testUnmarshalling_domainCheck() throws Exception {
|
||||||
EppInput input =
|
EppInput input =
|
||||||
unmarshal(EppInput.class, loadBytes(DomainBaseTest.class, "domain_check.xml").read());
|
unmarshal(EppInput.class, loadBytes(DomainBaseTest.class, "domain_check.xml").read());
|
||||||
assertThat(input.getCommandWrapper().getClTrid()).hasValue("ABC-12345");
|
assertThat(input.getCommandWrapper().getClTrid()).hasValue("ABC-12345");
|
||||||
|
@ -56,7 +53,7 @@ public class EppInputTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnmarshalling_login() throws Exception {
|
void testUnmarshalling_login() throws Exception {
|
||||||
EppInput input = unmarshal(EppInput.class, loadBytes(getClass(), "login_valid.xml").read());
|
EppInput input = unmarshal(EppInput.class, loadBytes(getClass(), "login_valid.xml").read());
|
||||||
assertThat(input.getCommandWrapper().getClTrid()).hasValue("ABC-12345");
|
assertThat(input.getCommandWrapper().getClTrid()).hasValue("ABC-12345");
|
||||||
assertThat(input.getCommandType()).isEqualTo("login");
|
assertThat(input.getCommandType()).isEqualTo("login");
|
||||||
|
@ -81,7 +78,7 @@ public class EppInputTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnmarshalling_loginTagInWrongCase_throws() {
|
void testUnmarshalling_loginTagInWrongCase_throws() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
XmlException.class,
|
XmlException.class,
|
||||||
() -> unmarshal(EppInput.class, loadBytes(getClass(), "login_wrong_case.xml").read()));
|
() -> unmarshal(EppInput.class, loadBytes(getClass(), "login_wrong_case.xml").read()));
|
||||||
|
|
|
@ -16,16 +16,13 @@ package google.registry.model.eppoutput;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link Result}. */
|
/** Unit tests for {@link Result}. */
|
||||||
@RunWith(JUnit4.class)
|
final class ResultTest {
|
||||||
public final class ResultTest {
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeadCodeWeDontWantToDelete() {
|
void testDeadCodeWeDontWantToDelete() {
|
||||||
Result result = new Result();
|
Result result = new Result();
|
||||||
result.msg = "hello";
|
result.msg = "hello";
|
||||||
assertThat(result.getMsg()).isEqualTo("hello");
|
assertThat(result.getMsg()).isEqualTo("hello");
|
||||||
|
|
|
@ -31,12 +31,12 @@ import org.junit.jupiter.api.Test;
|
||||||
/** Tests for {@link ContactHistory}. */
|
/** Tests for {@link ContactHistory}. */
|
||||||
public class ContactHistoryTest extends EntityTestCase {
|
public class ContactHistoryTest extends EntityTestCase {
|
||||||
|
|
||||||
public ContactHistoryTest() {
|
ContactHistoryTest() {
|
||||||
super(JpaEntityCoverageCheck.ENABLED);
|
super(JpaEntityCoverageCheck.ENABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPersistence() {
|
void testPersistence() {
|
||||||
saveRegistrar("registrar1");
|
saveRegistrar("registrar1");
|
||||||
|
|
||||||
ContactResource contact =
|
ContactResource contact =
|
||||||
|
|
|
@ -31,12 +31,12 @@ import org.junit.jupiter.api.Test;
|
||||||
/** Tests for {@link HostHistory}. */
|
/** Tests for {@link HostHistory}. */
|
||||||
public class HostHistoryTest extends EntityTestCase {
|
public class HostHistoryTest extends EntityTestCase {
|
||||||
|
|
||||||
public HostHistoryTest() {
|
HostHistoryTest() {
|
||||||
super(JpaEntityCoverageCheck.ENABLED);
|
super(JpaEntityCoverageCheck.ENABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPersistence() {
|
void testPersistence() {
|
||||||
saveRegistrar("registrar1");
|
saveRegistrar("registrar1");
|
||||||
|
|
||||||
HostResource host =
|
HostResource host =
|
||||||
|
|
|
@ -15,33 +15,33 @@
|
||||||
package google.registry.model.host;
|
package google.registry.model.host;
|
||||||
|
|
||||||
import google.registry.model.ResourceCommandTestCase;
|
import google.registry.model.ResourceCommandTestCase;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/** Test xml roundtripping of commands. */
|
/** Test xml roundtripping of commands. */
|
||||||
public class HostCommandTest extends ResourceCommandTestCase {
|
class HostCommandTest extends ResourceCommandTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreate() throws Exception {
|
void testCreate() throws Exception {
|
||||||
doXmlRoundtripTest("host_create.xml");
|
doXmlRoundtripTest("host_create.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDelete() throws Exception {
|
void testDelete() throws Exception {
|
||||||
doXmlRoundtripTest("host_delete.xml");
|
doXmlRoundtripTest("host_delete.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdate() throws Exception {
|
void testUpdate() throws Exception {
|
||||||
doXmlRoundtripTest("host_update.xml");
|
doXmlRoundtripTest("host_update.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInfo() throws Exception {
|
void testInfo() throws Exception {
|
||||||
doXmlRoundtripTest("host_info.xml");
|
doXmlRoundtripTest("host_info.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCheck() throws Exception {
|
void testCheck() throws Exception {
|
||||||
doXmlRoundtripTest("host_check.xml");
|
doXmlRoundtripTest("host_check.xml");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,21 +35,21 @@ import google.registry.model.transfer.DomainTransferData;
|
||||||
import google.registry.model.transfer.TransferStatus;
|
import google.registry.model.transfer.TransferStatus;
|
||||||
import google.registry.persistence.VKey;
|
import google.registry.persistence.VKey;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/** Unit tests for {@link HostResource}. */
|
/** Unit tests for {@link HostResource}. */
|
||||||
public class HostResourceTest extends EntityTestCase {
|
class HostResourceTest extends EntityTestCase {
|
||||||
|
|
||||||
final DateTime day3 = fakeClock.nowUtc();
|
private final DateTime day3 = fakeClock.nowUtc();
|
||||||
final DateTime day2 = day3.minusDays(1);
|
private final DateTime day2 = day3.minusDays(1);
|
||||||
final DateTime day1 = day2.minusDays(1);
|
private final DateTime day1 = day2.minusDays(1);
|
||||||
|
|
||||||
DomainBase domain;
|
private DomainBase domain;
|
||||||
HostResource host;
|
private HostResource host;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
createTld("com");
|
createTld("com");
|
||||||
// Set up a new persisted registrar entity.
|
// Set up a new persisted registrar entity.
|
||||||
domain =
|
domain =
|
||||||
|
@ -86,13 +86,13 @@ public class HostResourceTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPersistence() {
|
void testPersistence() {
|
||||||
assertThat(loadByForeignKey(HostResource.class, host.getForeignKey(), fakeClock.nowUtc()))
|
assertThat(loadByForeignKey(HostResource.class, host.getForeignKey(), fakeClock.nowUtc()))
|
||||||
.hasValue(host);
|
.hasValue(host);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIndexing() throws Exception {
|
void testIndexing() throws Exception {
|
||||||
// Clone it and save it before running the indexing test so that its transferData fields are
|
// Clone it and save it before running the indexing test so that its transferData fields are
|
||||||
// populated from the superordinate domain.
|
// populated from the superordinate domain.
|
||||||
verifyIndexing(
|
verifyIndexing(
|
||||||
|
@ -105,7 +105,7 @@ public class HostResourceTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyStringsBecomeNull() {
|
void testEmptyStringsBecomeNull() {
|
||||||
assertThat(
|
assertThat(
|
||||||
new HostResource.Builder()
|
new HostResource.Builder()
|
||||||
.setPersistedCurrentSponsorClientId(null)
|
.setPersistedCurrentSponsorClientId(null)
|
||||||
|
@ -127,7 +127,7 @@ public class HostResourceTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptySetsBecomeNull() {
|
void testEmptySetsBecomeNull() {
|
||||||
assertThat(new HostResource.Builder().setInetAddresses(null).build().inetAddresses).isNull();
|
assertThat(new HostResource.Builder().setInetAddresses(null).build().inetAddresses).isNull();
|
||||||
assertThat(new HostResource.Builder().setInetAddresses(ImmutableSet.of()).build().inetAddresses)
|
assertThat(new HostResource.Builder().setInetAddresses(ImmutableSet.of()).build().inetAddresses)
|
||||||
.isNull();
|
.isNull();
|
||||||
|
@ -140,7 +140,7 @@ public class HostResourceTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImplicitStatusValues() {
|
void testImplicitStatusValues() {
|
||||||
// OK is implicit if there's no other statuses.
|
// OK is implicit if there's no other statuses.
|
||||||
assertAboutHosts()
|
assertAboutHosts()
|
||||||
.that(new HostResource.Builder().build())
|
.that(new HostResource.Builder().build())
|
||||||
|
@ -162,13 +162,13 @@ public class HostResourceTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToHydratedString_notCircular() {
|
void testToHydratedString_notCircular() {
|
||||||
// If there are circular references, this will overflow the stack.
|
// If there are circular references, this will overflow the stack.
|
||||||
host.toHydratedString();
|
host.toHydratedString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_uppercaseHostName() {
|
void testFailure_uppercaseHostName() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class, () -> host.asBuilder().setHostName("AAA.BBB.CCC"));
|
IllegalArgumentException.class, () -> host.asBuilder().setHostName("AAA.BBB.CCC"));
|
||||||
|
@ -178,7 +178,7 @@ public class HostResourceTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_utf8HostName() {
|
void testFailure_utf8HostName() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class, () -> host.asBuilder().setHostName("みんな.みんな.みんな"));
|
IllegalArgumentException.class, () -> host.asBuilder().setHostName("みんな.みんな.みんな"));
|
||||||
|
@ -188,14 +188,14 @@ public class HostResourceTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testComputeLastTransferTime_hostNeverSwitchedDomains_domainWasNeverTransferred() {
|
void testComputeLastTransferTime_hostNeverSwitchedDomains_domainWasNeverTransferred() {
|
||||||
domain = domain.asBuilder().setLastTransferTime(null).build();
|
domain = domain.asBuilder().setLastTransferTime(null).build();
|
||||||
host = host.asBuilder().setLastTransferTime(null).setLastSuperordinateChange(null).build();
|
host = host.asBuilder().setLastTransferTime(null).setLastSuperordinateChange(null).build();
|
||||||
assertThat(host.computeLastTransferTime(domain)).isNull();
|
assertThat(host.computeLastTransferTime(domain)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testComputeLastTransferTime_hostNeverSwitchedDomains_domainWasTransferred() {
|
void testComputeLastTransferTime_hostNeverSwitchedDomains_domainWasTransferred() {
|
||||||
// Host was created on Day 1.
|
// Host was created on Day 1.
|
||||||
// Domain was transferred on Day 2.
|
// Domain was transferred on Day 2.
|
||||||
// Host was always subordinate to domain (and was created before the transfer).
|
// Host was always subordinate to domain (and was created before the transfer).
|
||||||
|
@ -210,7 +210,7 @@ public class HostResourceTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testComputeLastTransferTime_hostCreatedAfterDomainWasTransferred() {
|
void testComputeLastTransferTime_hostCreatedAfterDomainWasTransferred() {
|
||||||
// Domain was transferred on Day 1.
|
// Domain was transferred on Day 1.
|
||||||
// Host was created subordinate to domain on Day 2.
|
// Host was created subordinate to domain on Day 2.
|
||||||
domain = domain.asBuilder().setLastTransferTime(day1).build();
|
domain = domain.asBuilder().setLastTransferTime(day1).build();
|
||||||
|
@ -232,7 +232,7 @@ public class HostResourceTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testComputeLastTransferTime_hostWasTransferred_domainWasNeverTransferred() {
|
void testComputeLastTransferTime_hostWasTransferred_domainWasNeverTransferred() {
|
||||||
// Host was transferred on Day 1.
|
// Host was transferred on Day 1.
|
||||||
// Host was made subordinate to domain on Day 2.
|
// Host was made subordinate to domain on Day 2.
|
||||||
// Domain was never transferred.
|
// Domain was never transferred.
|
||||||
|
@ -242,7 +242,7 @@ public class HostResourceTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testComputeLastTransferTime_domainWasTransferredBeforeHostBecameSubordinate() {
|
void testComputeLastTransferTime_domainWasTransferredBeforeHostBecameSubordinate() {
|
||||||
// Host was transferred on Day 1.
|
// Host was transferred on Day 1.
|
||||||
// Domain was transferred on Day 2.
|
// Domain was transferred on Day 2.
|
||||||
// Host was made subordinate to domain on Day 3.
|
// Host was made subordinate to domain on Day 3.
|
||||||
|
@ -252,7 +252,7 @@ public class HostResourceTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testComputeLastTransferTime_domainWasTransferredAfterHostBecameSubordinate() {
|
void testComputeLastTransferTime_domainWasTransferredAfterHostBecameSubordinate() {
|
||||||
// Host was transferred on Day 1.
|
// Host was transferred on Day 1.
|
||||||
// Host was made subordinate to domain on Day 2.
|
// Host was made subordinate to domain on Day 2.
|
||||||
// Domain was transferred on Day 3.
|
// Domain was transferred on Day 3.
|
||||||
|
|
|
@ -26,34 +26,34 @@ import com.google.common.collect.Iterables;
|
||||||
import com.googlecode.objectify.Key;
|
import com.googlecode.objectify.Key;
|
||||||
import google.registry.model.EntityTestCase;
|
import google.registry.model.EntityTestCase;
|
||||||
import google.registry.model.contact.ContactResource;
|
import google.registry.model.contact.ContactResource;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/** Unit tests for {@link EppResourceIndex}. */
|
/** Unit tests for {@link EppResourceIndex}. */
|
||||||
public class EppResourceIndexTest extends EntityTestCase {
|
class EppResourceIndexTest extends EntityTestCase {
|
||||||
|
|
||||||
ContactResource contact;
|
private ContactResource contact;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
// The DatastoreHelper here creates the EppResourceIndex for us.
|
// The DatastoreHelper here creates the EppResourceIndex for us.
|
||||||
contact = persistActiveContact("abcd1357");
|
contact = persistActiveContact("abcd1357");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPersistence() {
|
void testPersistence() {
|
||||||
EppResourceIndex loadedIndex = Iterables.getOnlyElement(getEppResourceIndexObjects());
|
EppResourceIndex loadedIndex = Iterables.getOnlyElement(getEppResourceIndexObjects());
|
||||||
assertThat(ofy().load().key(loadedIndex.reference).now()).isEqualTo(contact);
|
assertThat(ofy().load().key(loadedIndex.reference).now()).isEqualTo(contact);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIndexing() throws Exception {
|
void testIndexing() throws Exception {
|
||||||
verifyIndexing(Iterables.getOnlyElement(getEppResourceIndexObjects()), "kind");
|
verifyIndexing(Iterables.getOnlyElement(getEppResourceIndexObjects()), "kind");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIdempotentOnUpdate() {
|
void testIdempotentOnUpdate() {
|
||||||
contact = persistResource(contact.asBuilder().setEmailAddress("abc@def.fake").build());
|
contact = persistResource(contact.asBuilder().setEmailAddress("abc@def.fake").build());
|
||||||
EppResourceIndex loadedIndex = Iterables.getOnlyElement(getEppResourceIndexObjects());
|
EppResourceIndex loadedIndex = Iterables.getOnlyElement(getEppResourceIndexObjects());
|
||||||
assertThat(ofy().load().key(loadedIndex.reference).now()).isEqualTo(contact);
|
assertThat(ofy().load().key(loadedIndex.reference).now()).isEqualTo(contact);
|
||||||
|
|
|
@ -33,24 +33,24 @@ import google.registry.model.host.HostResource;
|
||||||
import google.registry.model.index.ForeignKeyIndex.ForeignKeyHostIndex;
|
import google.registry.model.index.ForeignKeyIndex.ForeignKeyHostIndex;
|
||||||
import google.registry.testing.TestCacheRule;
|
import google.registry.testing.TestCacheRule;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
/** Unit tests for {@link ForeignKeyIndex}. */
|
/** Unit tests for {@link ForeignKeyIndex}. */
|
||||||
public class ForeignKeyIndexTest extends EntityTestCase {
|
public class ForeignKeyIndexTest extends EntityTestCase {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final TestCacheRule testCacheRule =
|
public final TestCacheRule testCacheRule =
|
||||||
new TestCacheRule.Builder().withForeignIndexKeyCache(Duration.standardDays(1)).build();
|
new TestCacheRule.Builder().withForeignIndexKeyCache(Duration.standardDays(1)).build();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
createTld("com");
|
createTld("com");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPersistence() {
|
void testPersistence() {
|
||||||
// Persist a host and implicitly persist a ForeignKeyIndex for it.
|
// Persist a host and implicitly persist a ForeignKeyIndex for it.
|
||||||
HostResource host = persistActiveHost("ns1.example.com");
|
HostResource host = persistActiveHost("ns1.example.com");
|
||||||
ForeignKeyIndex<HostResource> fki =
|
ForeignKeyIndex<HostResource> fki =
|
||||||
|
@ -60,7 +60,7 @@ public class ForeignKeyIndexTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIndexing() throws Exception {
|
void testIndexing() throws Exception {
|
||||||
// Persist a host and implicitly persist a ForeignKeyIndex for it.
|
// Persist a host and implicitly persist a ForeignKeyIndex for it.
|
||||||
persistActiveHost("ns1.example.com");
|
persistActiveHost("ns1.example.com");
|
||||||
verifyIndexing(
|
verifyIndexing(
|
||||||
|
@ -69,13 +69,13 @@ public class ForeignKeyIndexTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoadForNonexistentForeignKey_returnsNull() {
|
void testLoadForNonexistentForeignKey_returnsNull() {
|
||||||
assertThat(ForeignKeyIndex.load(HostResource.class, "ns1.example.com", fakeClock.nowUtc()))
|
assertThat(ForeignKeyIndex.load(HostResource.class, "ns1.example.com", fakeClock.nowUtc()))
|
||||||
.isNull();
|
.isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoadForDeletedForeignKey_returnsNull() {
|
void testLoadForDeletedForeignKey_returnsNull() {
|
||||||
HostResource host = persistActiveHost("ns1.example.com");
|
HostResource host = persistActiveHost("ns1.example.com");
|
||||||
persistResource(ForeignKeyIndex.create(host, fakeClock.nowUtc().minusDays(1)));
|
persistResource(ForeignKeyIndex.create(host, fakeClock.nowUtc().minusDays(1)));
|
||||||
assertThat(ForeignKeyIndex.load(HostResource.class, "ns1.example.com", fakeClock.nowUtc()))
|
assertThat(ForeignKeyIndex.load(HostResource.class, "ns1.example.com", fakeClock.nowUtc()))
|
||||||
|
@ -83,7 +83,7 @@ public class ForeignKeyIndexTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoad_newerKeyHasBeenSoftDeleted() {
|
void testLoad_newerKeyHasBeenSoftDeleted() {
|
||||||
HostResource host1 = persistActiveHost("ns1.example.com");
|
HostResource host1 = persistActiveHost("ns1.example.com");
|
||||||
fakeClock.advanceOneMilli();
|
fakeClock.advanceOneMilli();
|
||||||
ForeignKeyHostIndex fki = new ForeignKeyHostIndex();
|
ForeignKeyHostIndex fki = new ForeignKeyHostIndex();
|
||||||
|
@ -96,7 +96,7 @@ public class ForeignKeyIndexTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBatchLoad_skipsDeletedAndNonexistent() {
|
void testBatchLoad_skipsDeletedAndNonexistent() {
|
||||||
persistActiveHost("ns1.example.com");
|
persistActiveHost("ns1.example.com");
|
||||||
HostResource host = persistActiveHost("ns2.example.com");
|
HostResource host = persistActiveHost("ns2.example.com");
|
||||||
persistResource(ForeignKeyIndex.create(host, fakeClock.nowUtc().minusDays(1)));
|
persistResource(ForeignKeyIndex.create(host, fakeClock.nowUtc().minusDays(1)));
|
||||||
|
@ -110,7 +110,7 @@ public class ForeignKeyIndexTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeadCodeThatDeletedScrapCommandsReference() {
|
void testDeadCodeThatDeletedScrapCommandsReference() {
|
||||||
persistActiveHost("omg");
|
persistActiveHost("omg");
|
||||||
assertThat(ForeignKeyIndex.load(HostResource.class, "omg", fakeClock.nowUtc()).getForeignKey())
|
assertThat(ForeignKeyIndex.load(HostResource.class, "omg", fakeClock.nowUtc()).getForeignKey())
|
||||||
.isEqualTo("omg");
|
.isEqualTo("omg");
|
||||||
|
@ -125,7 +125,7 @@ public class ForeignKeyIndexTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_loadCached_cachesNonexistenceOfHosts() {
|
void test_loadCached_cachesNonexistenceOfHosts() {
|
||||||
assertThat(
|
assertThat(
|
||||||
ForeignKeyIndex.loadCached(
|
ForeignKeyIndex.loadCached(
|
||||||
HostResource.class,
|
HostResource.class,
|
||||||
|
@ -145,7 +145,7 @@ public class ForeignKeyIndexTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_loadCached_cachesExistenceOfHosts() {
|
void test_loadCached_cachesExistenceOfHosts() {
|
||||||
HostResource host1 = persistActiveHost("ns1.example.com");
|
HostResource host1 = persistActiveHost("ns1.example.com");
|
||||||
HostResource host2 = persistActiveHost("ns2.example.com");
|
HostResource host2 = persistActiveHost("ns2.example.com");
|
||||||
assertThat(
|
assertThat(
|
||||||
|
@ -173,7 +173,7 @@ public class ForeignKeyIndexTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_loadCached_doesntSeeHostChangesWhileCacheIsValid() {
|
void test_loadCached_doesntSeeHostChangesWhileCacheIsValid() {
|
||||||
HostResource originalHost = persistActiveHost("ns1.example.com");
|
HostResource originalHost = persistActiveHost("ns1.example.com");
|
||||||
ForeignKeyIndex<HostResource> originalFki = loadHostFki("ns1.example.com");
|
ForeignKeyIndex<HostResource> originalFki = loadHostFki("ns1.example.com");
|
||||||
fakeClock.advanceOneMilli();
|
fakeClock.advanceOneMilli();
|
||||||
|
@ -196,7 +196,7 @@ public class ForeignKeyIndexTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_loadCached_filtersOutSoftDeletedHosts() {
|
void test_loadCached_filtersOutSoftDeletedHosts() {
|
||||||
persistActiveHost("ns1.example.com");
|
persistActiveHost("ns1.example.com");
|
||||||
persistDeletedHost("ns2.example.com", fakeClock.nowUtc().minusDays(1));
|
persistDeletedHost("ns2.example.com", fakeClock.nowUtc().minusDays(1));
|
||||||
assertThat(
|
assertThat(
|
||||||
|
@ -208,7 +208,7 @@ public class ForeignKeyIndexTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_loadCached_cachesContactFkis() {
|
void test_loadCached_cachesContactFkis() {
|
||||||
persistActiveContact("contactid1");
|
persistActiveContact("contactid1");
|
||||||
ForeignKeyIndex<ContactResource> fki1 = loadContactFki("contactid1");
|
ForeignKeyIndex<ContactResource> fki1 = loadContactFki("contactid1");
|
||||||
assertThat(
|
assertThat(
|
||||||
|
|
|
@ -16,16 +16,13 @@ package google.registry.model.mark;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link MarkContact}. */
|
/** Unit tests for {@link MarkContact}. */
|
||||||
@RunWith(JUnit4.class)
|
final class MarkContactTest {
|
||||||
public final class MarkContactTest {
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeadCodeWeDontWantToDelete() {
|
void testDeadCodeWeDontWantToDelete() {
|
||||||
MarkContact mc = new MarkContact();
|
MarkContact mc = new MarkContact();
|
||||||
mc.type = MarkContact.ContactType.OWNER;
|
mc.type = MarkContact.ContactType.OWNER;
|
||||||
assertThat(mc.getType()).isEqualTo(MarkContact.ContactType.OWNER);
|
assertThat(mc.getType()).isEqualTo(MarkContact.ContactType.OWNER);
|
||||||
|
|
|
@ -16,16 +16,13 @@ package google.registry.model.mark;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link MarkHolder}. */
|
/** Unit tests for {@link MarkHolder}. */
|
||||||
@RunWith(JUnit4.class)
|
final class MarkHolderTest {
|
||||||
public final class MarkHolderTest {
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeadCodeWeDontWantToDelete() {
|
void testDeadCodeWeDontWantToDelete() {
|
||||||
MarkHolder mc = new MarkHolder();
|
MarkHolder mc = new MarkHolder();
|
||||||
mc.entitlement = MarkHolder.EntitlementType.OWNER;
|
mc.entitlement = MarkHolder.EntitlementType.OWNER;
|
||||||
assertThat(mc.getEntitlementType()).isEqualTo(MarkHolder.EntitlementType.OWNER);
|
assertThat(mc.getEntitlementType()).isEqualTo(MarkHolder.EntitlementType.OWNER);
|
||||||
|
|
|
@ -17,16 +17,13 @@ package google.registry.model.mark;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link MarkProtection}. */
|
/** Unit tests for {@link MarkProtection}. */
|
||||||
@RunWith(JUnit4.class)
|
final class MarkProtectionTest {
|
||||||
public final class MarkProtectionTest {
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeadCodeWeDontWantToDelete() {
|
void testDeadCodeWeDontWantToDelete() {
|
||||||
MarkProtection mp = new MarkProtection();
|
MarkProtection mp = new MarkProtection();
|
||||||
mp.countryCode = "US";
|
mp.countryCode = "US";
|
||||||
assertThat(mp.getCountryCode()).isEqualTo("US");
|
assertThat(mp.getCountryCode()).isEqualTo("US");
|
||||||
|
|
|
@ -27,25 +27,21 @@ import com.google.common.collect.ImmutableSet;
|
||||||
import com.googlecode.objectify.annotation.Cache;
|
import com.googlecode.objectify.annotation.Cache;
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import google.registry.testing.InjectRule;
|
import google.registry.testing.InjectRule;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Tests for {@link CommitLogBucket}. */
|
/** Tests for {@link CommitLogBucket}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class CommitLogBucketTest {
|
public class CommitLogBucketTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension public final InjectRule inject = new InjectRule();
|
||||||
public final InjectRule inject = new InjectRule();
|
private CommitLogBucket bucket;
|
||||||
CommitLogBucket bucket;
|
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
// Save the bucket with some non-default properties set so that we can distinguish a correct
|
// Save the bucket with some non-default properties set so that we can distinguish a correct
|
||||||
// load from one that returns a newly created bucket instance.
|
// load from one that returns a newly created bucket instance.
|
||||||
bucket = persistResource(
|
bucket = persistResource(
|
||||||
|
@ -56,27 +52,27 @@ public class CommitLogBucketTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_getBucketKey_createsBucketKeyInDefaultNamespace() {
|
void test_getBucketKey_createsBucketKeyInDefaultNamespace() {
|
||||||
// Key.getNamespace() returns the empty string for the default namespace, not null.
|
// Key.getNamespace() returns the empty string for the default namespace, not null.
|
||||||
assertThat(getBucketKey(1).getRaw().getNamespace()).isEmpty();
|
assertThat(getBucketKey(1).getRaw().getNamespace()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_getBucketKey_bucketNumberTooLow_throws() {
|
void test_getBucketKey_bucketNumberTooLow_throws() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(IllegalArgumentException.class, () -> getBucketKey(0));
|
assertThrows(IllegalArgumentException.class, () -> getBucketKey(0));
|
||||||
assertThat(thrown).hasMessageThat().contains("0 not in [");
|
assertThat(thrown).hasMessageThat().contains("0 not in [");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_getBucketKey_bucketNumberTooHigh_throws() {
|
void test_getBucketKey_bucketNumberTooHigh_throws() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(IllegalArgumentException.class, () -> getBucketKey(11));
|
assertThrows(IllegalArgumentException.class, () -> getBucketKey(11));
|
||||||
assertThat(thrown).hasMessageThat().contains("11 not in [");
|
assertThat(thrown).hasMessageThat().contains("11 not in [");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_getArbitraryBucketId_withSupplierOverridden() {
|
void test_getArbitraryBucketId_withSupplierOverridden() {
|
||||||
inject.setStaticField(
|
inject.setStaticField(
|
||||||
CommitLogBucket.class, "bucketIdSupplier", Suppliers.ofInstance(4)); // xkcd.com/221
|
CommitLogBucket.class, "bucketIdSupplier", Suppliers.ofInstance(4)); // xkcd.com/221
|
||||||
// Try multiple times just in case it's actually still random. If it is, the probability of
|
// Try multiple times just in case it's actually still random. If it is, the probability of
|
||||||
|
@ -87,18 +83,18 @@ public class CommitLogBucketTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_loadBucket_loadsTheBucket() {
|
void test_loadBucket_loadsTheBucket() {
|
||||||
assertThat(loadBucket(getBucketKey(1))).isEqualTo(bucket);
|
assertThat(loadBucket(getBucketKey(1))).isEqualTo(bucket);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_loadBucket_forNonexistentBucket_returnsNewBucket() {
|
void test_loadBucket_forNonexistentBucket_returnsNewBucket() {
|
||||||
assertThat(loadBucket(getBucketKey(3))).isEqualTo(
|
assertThat(loadBucket(getBucketKey(3))).isEqualTo(
|
||||||
new CommitLogBucket.Builder().setBucketNum(3).build());
|
new CommitLogBucket.Builder().setBucketNum(3).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_loadAllBuckets_loadsExistingBuckets_orNewOnesIfNonexistent() {
|
void test_loadAllBuckets_loadsExistingBuckets_orNewOnesIfNonexistent() {
|
||||||
ImmutableSet<CommitLogBucket> buckets = loadAllBuckets();
|
ImmutableSet<CommitLogBucket> buckets = loadAllBuckets();
|
||||||
assertThat(buckets).hasSize(3);
|
assertThat(buckets).hasSize(3);
|
||||||
assertThat(buckets).contains(bucket);
|
assertThat(buckets).contains(bucket);
|
||||||
|
@ -107,7 +103,7 @@ public class CommitLogBucketTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_noCacheAnnotation() {
|
void test_noCacheAnnotation() {
|
||||||
// Don't ever put @Cache on CommitLogBucket; it could mess up the checkpointing algorithm.
|
// Don't ever put @Cache on CommitLogBucket; it could mess up the checkpointing algorithm.
|
||||||
assertThat(CommitLogBucket.class.isAnnotationPresent(Cache.class)).isFalse();
|
assertThat(CommitLogBucket.class.isAnnotationPresent(Cache.class)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,16 +22,13 @@ import static org.junit.Assert.assertThrows;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Tests for {@link CommitLogCheckpoint}. */
|
/** Tests for {@link CommitLogCheckpoint}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class CommitLogCheckpointTest {
|
public class CommitLogCheckpointTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
private static final DateTime T1 = START_OF_TIME;
|
private static final DateTime T1 = START_OF_TIME;
|
||||||
|
@ -39,7 +36,7 @@ public class CommitLogCheckpointTest {
|
||||||
private static final DateTime T3 = START_OF_TIME.plusMillis(2);
|
private static final DateTime T3 = START_OF_TIME.plusMillis(2);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_getCheckpointTime() {
|
void test_getCheckpointTime() {
|
||||||
DateTime now = DateTime.now(UTC);
|
DateTime now = DateTime.now(UTC);
|
||||||
CommitLogCheckpoint checkpoint =
|
CommitLogCheckpoint checkpoint =
|
||||||
CommitLogCheckpoint.create(now, ImmutableMap.of(1, T1, 2, T2, 3, T3));
|
CommitLogCheckpoint.create(now, ImmutableMap.of(1, T1, 2, T2, 3, T3));
|
||||||
|
@ -47,14 +44,14 @@ public class CommitLogCheckpointTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_getBucketTimestamps() {
|
void test_getBucketTimestamps() {
|
||||||
CommitLogCheckpoint checkpoint =
|
CommitLogCheckpoint checkpoint =
|
||||||
CommitLogCheckpoint.create(DateTime.now(UTC), ImmutableMap.of(1, T1, 2, T2, 3, T3));
|
CommitLogCheckpoint.create(DateTime.now(UTC), ImmutableMap.of(1, T1, 2, T2, 3, T3));
|
||||||
assertThat(checkpoint.getBucketTimestamps()).containsExactly(1, T1, 2, T2, 3, T3);
|
assertThat(checkpoint.getBucketTimestamps()).containsExactly(1, T1, 2, T2, 3, T3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_create_notEnoughBucketTimestamps_throws() {
|
void test_create_notEnoughBucketTimestamps_throws() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -63,7 +60,7 @@ public class CommitLogCheckpointTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_create_tooManyBucketTimestamps_throws() {
|
void test_create_tooManyBucketTimestamps_throws() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -74,7 +71,7 @@ public class CommitLogCheckpointTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_create_wrongBucketIds_throws() {
|
void test_create_wrongBucketIds_throws() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -85,7 +82,7 @@ public class CommitLogCheckpointTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_create_wrongBucketIdOrder_throws() {
|
void test_create_wrongBucketIdOrder_throws() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
|
|
@ -28,17 +28,14 @@ import google.registry.model.registry.Registry;
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.DateTimeZone;
|
import org.joda.time.DateTimeZone;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Tests for {@link CommitLogMutation}. */
|
/** Tests for {@link CommitLogMutation}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class CommitLogMutationTest {
|
public class CommitLogMutationTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
private static final DateTime NOW = DateTime.now(DateTimeZone.UTC);
|
private static final DateTime NOW = DateTime.now(DateTimeZone.UTC);
|
||||||
|
@ -46,8 +43,8 @@ public class CommitLogMutationTest {
|
||||||
private Key<CommitLogManifest> manifestKey;
|
private Key<CommitLogManifest> manifestKey;
|
||||||
private ImmutableObject someObject;
|
private ImmutableObject someObject;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
// Initialize this late to avoid dependency on NamespaceManager prior to AppEngineRule.
|
// Initialize this late to avoid dependency on NamespaceManager prior to AppEngineRule.
|
||||||
manifestKey = CommitLogManifest.createKey(CommitLogBucket.getBucketKey(1), NOW);
|
manifestKey = CommitLogManifest.createKey(CommitLogBucket.getBucketKey(1), NOW);
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
|
@ -55,7 +52,7 @@ public class CommitLogMutationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_createKey_createsKeyWithWebsafeKeystring() {
|
void test_createKey_createsKeyWithWebsafeKeystring() {
|
||||||
Key<CommitLogMutation> mutationKey =
|
Key<CommitLogMutation> mutationKey =
|
||||||
CommitLogMutation.createKey(manifestKey, Key.create(someObject));
|
CommitLogMutation.createKey(manifestKey, Key.create(someObject));
|
||||||
assertThat(mutationKey.getParent()).isEqualTo(manifestKey);
|
assertThat(mutationKey.getParent()).isEqualTo(manifestKey);
|
||||||
|
@ -64,7 +61,7 @@ public class CommitLogMutationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_create_createsExpectedMutation() {
|
void test_create_createsExpectedMutation() {
|
||||||
Entity rawEntity = convertToEntityInTxn(someObject);
|
Entity rawEntity = convertToEntityInTxn(someObject);
|
||||||
// Needs to be in a transaction so that registry-saving-to-entity will work.
|
// Needs to be in a transaction so that registry-saving-to-entity will work.
|
||||||
CommitLogMutation mutation =
|
CommitLogMutation mutation =
|
||||||
|
@ -77,7 +74,7 @@ public class CommitLogMutationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_createRaw_createsExpectedMutation() {
|
void test_createRaw_createsExpectedMutation() {
|
||||||
Entity rawEntity = convertToEntityInTxn(someObject);
|
Entity rawEntity = convertToEntityInTxn(someObject);
|
||||||
CommitLogMutation mutation = CommitLogMutation.createFromRaw(manifestKey, rawEntity);
|
CommitLogMutation mutation = CommitLogMutation.createFromRaw(manifestKey, rawEntity);
|
||||||
assertThat(Key.create(mutation))
|
assertThat(Key.create(mutation))
|
||||||
|
|
|
@ -15,20 +15,17 @@
|
||||||
package google.registry.model.ofy;
|
package google.registry.model.ofy;
|
||||||
|
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Tests for our replacement for ObjectifyService. */
|
/** Tests for our replacement for ObjectifyService. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class ObjectifyServiceTest {
|
public class ObjectifyServiceTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_initOfy_canBeCalledTwice() {
|
void test_initOfy_canBeCalledTwice() {
|
||||||
ObjectifyService.initOfy();
|
ObjectifyService.initOfy();
|
||||||
ObjectifyService.initOfy();
|
ObjectifyService.initOfy();
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,41 +35,37 @@ import google.registry.testing.FakeClock;
|
||||||
import google.registry.testing.InjectRule;
|
import google.registry.testing.InjectRule;
|
||||||
import google.registry.testing.TestObject.TestVirtualObject;
|
import google.registry.testing.TestObject.TestVirtualObject;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests ensuring {@link Ofy} saves transactions to {@link CommitLogManifest}. */
|
/** Unit tests ensuring {@link Ofy} saves transactions to {@link CommitLogManifest}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class OfyCommitLogTest {
|
public class OfyCommitLogTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine =
|
public final AppEngineRule appEngine =
|
||||||
AppEngineRule.builder()
|
AppEngineRule.builder()
|
||||||
.withDatastoreAndCloudSql()
|
.withDatastoreAndCloudSql()
|
||||||
.withOfyTestEntities(TestVirtualObject.class, Root.class, Child.class)
|
.withOfyTestEntities(TestVirtualObject.class, Root.class, Child.class)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension public final InjectRule inject = new InjectRule();
|
||||||
public final InjectRule inject = new InjectRule();
|
|
||||||
|
|
||||||
private final FakeClock clock = new FakeClock(DateTime.parse("2000-01-01TZ"));
|
private final FakeClock clock = new FakeClock(DateTime.parse("2000-01-01TZ"));
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void beforeEach() {
|
||||||
inject.setStaticField(Ofy.class, "clock", clock);
|
inject.setStaticField(Ofy.class, "clock", clock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransact_doesNothing_noCommitLogIsSaved() {
|
void testTransact_doesNothing_noCommitLogIsSaved() {
|
||||||
tm().transact(() -> {});
|
tm().transact(() -> {});
|
||||||
assertThat(ofy().load().type(CommitLogManifest.class)).isEmpty();
|
assertThat(ofy().load().type(CommitLogManifest.class)).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransact_savesDataAndCommitLog() {
|
void testTransact_savesDataAndCommitLog() {
|
||||||
tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())).now());
|
tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())).now());
|
||||||
assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now().value)
|
assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now().value)
|
||||||
.isEqualTo("value");
|
.isEqualTo("value");
|
||||||
|
@ -78,7 +74,7 @@ public class OfyCommitLogTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransact_saveWithoutBackup_noCommitLogIsSaved() {
|
void testTransact_saveWithoutBackup_noCommitLogIsSaved() {
|
||||||
tm().transact(() -> ofy().saveWithoutBackup().entity(Root.create(1, getCrossTldKey())).now());
|
tm().transact(() -> ofy().saveWithoutBackup().entity(Root.create(1, getCrossTldKey())).now());
|
||||||
assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now().value)
|
assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now().value)
|
||||||
.isEqualTo("value");
|
.isEqualTo("value");
|
||||||
|
@ -87,7 +83,7 @@ public class OfyCommitLogTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransact_deleteWithoutBackup_noCommitLogIsSaved() {
|
void testTransact_deleteWithoutBackup_noCommitLogIsSaved() {
|
||||||
tm().transact(() -> ofy().saveWithoutBackup().entity(Root.create(1, getCrossTldKey())).now());
|
tm().transact(() -> ofy().saveWithoutBackup().entity(Root.create(1, getCrossTldKey())).now());
|
||||||
tm().transact(() -> ofy().deleteWithoutBackup().key(Key.create(Root.class, 1)));
|
tm().transact(() -> ofy().deleteWithoutBackup().key(Key.create(Root.class, 1)));
|
||||||
assertThat(ofy().load().key(Key.create(Root.class, 1)).now()).isNull();
|
assertThat(ofy().load().key(Key.create(Root.class, 1)).now()).isNull();
|
||||||
|
@ -96,7 +92,7 @@ public class OfyCommitLogTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransact_savesEntity_itsProtobufFormIsStoredInCommitLog() {
|
void testTransact_savesEntity_itsProtobufFormIsStoredInCommitLog() {
|
||||||
tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())).now());
|
tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())).now());
|
||||||
final byte[] entityProtoBytes =
|
final byte[] entityProtoBytes =
|
||||||
ofy().load().type(CommitLogMutation.class).first().now().entityProtoBytes;
|
ofy().load().type(CommitLogMutation.class).first().now().entityProtoBytes;
|
||||||
|
@ -112,7 +108,7 @@ public class OfyCommitLogTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransact_savesEntity_mutationIsChildOfManifest() {
|
void testTransact_savesEntity_mutationIsChildOfManifest() {
|
||||||
tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())).now());
|
tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())).now());
|
||||||
assertThat(
|
assertThat(
|
||||||
ofy()
|
ofy()
|
||||||
|
@ -123,7 +119,7 @@ public class OfyCommitLogTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransactNew_savesDataAndCommitLog() {
|
void testTransactNew_savesDataAndCommitLog() {
|
||||||
tm().transactNew(() -> ofy().save().entity(Root.create(1, getCrossTldKey())).now());
|
tm().transactNew(() -> ofy().save().entity(Root.create(1, getCrossTldKey())).now());
|
||||||
assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now().value)
|
assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now().value)
|
||||||
.isEqualTo("value");
|
.isEqualTo("value");
|
||||||
|
@ -132,7 +128,7 @@ public class OfyCommitLogTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransact_multipleSaves_logsMultipleMutations() {
|
void testTransact_multipleSaves_logsMultipleMutations() {
|
||||||
tm()
|
tm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
|
@ -144,7 +140,7 @@ public class OfyCommitLogTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransact_deletion_deletesAndLogsWithoutMutation() {
|
void testTransact_deletion_deletesAndLogsWithoutMutation() {
|
||||||
tm().transact(() -> ofy().saveWithoutBackup().entity(Root.create(1, getCrossTldKey())).now());
|
tm().transact(() -> ofy().saveWithoutBackup().entity(Root.create(1, getCrossTldKey())).now());
|
||||||
clock.advanceOneMilli();
|
clock.advanceOneMilli();
|
||||||
final Key<Root> otherTldKey = Key.create(getCrossTldKey(), Root.class, 1);
|
final Key<Root> otherTldKey = Key.create(getCrossTldKey(), Root.class, 1);
|
||||||
|
@ -157,7 +153,7 @@ public class OfyCommitLogTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransactNew_deleteNotBackedUpKind_throws() {
|
void testTransactNew_deleteNotBackedUpKind_throws() {
|
||||||
final CommitLogManifest backupsArentAllowedOnMe =
|
final CommitLogManifest backupsArentAllowedOnMe =
|
||||||
CommitLogManifest.create(getBucketKey(1), clock.nowUtc(), ImmutableSet.of());
|
CommitLogManifest.create(getBucketKey(1), clock.nowUtc(), ImmutableSet.of());
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
|
@ -168,7 +164,7 @@ public class OfyCommitLogTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransactNew_saveNotBackedUpKind_throws() {
|
void testTransactNew_saveNotBackedUpKind_throws() {
|
||||||
final CommitLogManifest backupsArentAllowedOnMe =
|
final CommitLogManifest backupsArentAllowedOnMe =
|
||||||
CommitLogManifest.create(getBucketKey(1), clock.nowUtc(), ImmutableSet.of());
|
CommitLogManifest.create(getBucketKey(1), clock.nowUtc(), ImmutableSet.of());
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
|
@ -179,7 +175,7 @@ public class OfyCommitLogTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransactNew_deleteVirtualEntityKey_throws() {
|
void testTransactNew_deleteVirtualEntityKey_throws() {
|
||||||
final Key<TestVirtualObject> virtualEntityKey = TestVirtualObject.createKey("virtual");
|
final Key<TestVirtualObject> virtualEntityKey = TestVirtualObject.createKey("virtual");
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
|
@ -189,7 +185,7 @@ public class OfyCommitLogTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransactNew_saveVirtualEntity_throws() {
|
void testTransactNew_saveVirtualEntity_throws() {
|
||||||
final TestVirtualObject virtualEntity = TestVirtualObject.create("virtual");
|
final TestVirtualObject virtualEntity = TestVirtualObject.create("virtual");
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
|
@ -199,7 +195,7 @@ public class OfyCommitLogTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_deleteWithoutBackup_withVirtualEntityKey_throws() {
|
void test_deleteWithoutBackup_withVirtualEntityKey_throws() {
|
||||||
final Key<TestVirtualObject> virtualEntityKey = TestVirtualObject.createKey("virtual");
|
final Key<TestVirtualObject> virtualEntityKey = TestVirtualObject.createKey("virtual");
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
|
@ -209,7 +205,7 @@ public class OfyCommitLogTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_saveWithoutBackup_withVirtualEntity_throws() {
|
void test_saveWithoutBackup_withVirtualEntity_throws() {
|
||||||
final TestVirtualObject virtualEntity = TestVirtualObject.create("virtual");
|
final TestVirtualObject virtualEntity = TestVirtualObject.create("virtual");
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
|
@ -218,7 +214,7 @@ public class OfyCommitLogTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransact_twoSavesOnSameKey_throws() {
|
void testTransact_twoSavesOnSameKey_throws() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -233,7 +229,7 @@ public class OfyCommitLogTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransact_saveAndDeleteSameKey_throws() {
|
void testTransact_saveAndDeleteSameKey_throws() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -248,7 +244,7 @@ public class OfyCommitLogTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSavingRootAndChild_updatesTimestampOnBackupGroupRoot() {
|
void testSavingRootAndChild_updatesTimestampOnBackupGroupRoot() {
|
||||||
tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())));
|
tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())));
|
||||||
ofy().clearSessionCache();
|
ofy().clearSessionCache();
|
||||||
assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now()
|
assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now()
|
||||||
|
@ -266,7 +262,7 @@ public class OfyCommitLogTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSavingOnlyChild_updatesTimestampOnBackupGroupRoot() {
|
void testSavingOnlyChild_updatesTimestampOnBackupGroupRoot() {
|
||||||
tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())));
|
tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())));
|
||||||
ofy().clearSessionCache();
|
ofy().clearSessionCache();
|
||||||
assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now()
|
assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now()
|
||||||
|
@ -279,7 +275,7 @@ public class OfyCommitLogTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeletingChild_updatesTimestampOnBackupGroupRoot() {
|
void testDeletingChild_updatesTimestampOnBackupGroupRoot() {
|
||||||
tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())));
|
tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())));
|
||||||
ofy().clearSessionCache();
|
ofy().clearSessionCache();
|
||||||
assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now()
|
assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now()
|
||||||
|
@ -293,7 +289,7 @@ public class OfyCommitLogTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReadingRoot_doesntUpdateTimestamp() {
|
void testReadingRoot_doesntUpdateTimestamp() {
|
||||||
tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())));
|
tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())));
|
||||||
ofy().clearSessionCache();
|
ofy().clearSessionCache();
|
||||||
assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now()
|
assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now()
|
||||||
|
@ -313,7 +309,7 @@ public class OfyCommitLogTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReadingChild_doesntUpdateTimestampOnBackupGroupRoot() {
|
void testReadingChild_doesntUpdateTimestampOnBackupGroupRoot() {
|
||||||
tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())));
|
tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())));
|
||||||
ofy().clearSessionCache();
|
ofy().clearSessionCache();
|
||||||
assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now()
|
assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now()
|
||||||
|
@ -333,7 +329,7 @@ public class OfyCommitLogTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSavingAcrossBackupGroupRoots_updatesCorrectTimestamps() {
|
void testSavingAcrossBackupGroupRoots_updatesCorrectTimestamps() {
|
||||||
// Create three roots.
|
// Create three roots.
|
||||||
tm()
|
tm()
|
||||||
.transact(
|
.transact(
|
||||||
|
|
|
@ -28,23 +28,20 @@ import com.googlecode.objectify.ObjectifyService;
|
||||||
import com.googlecode.objectify.annotation.Entity;
|
import com.googlecode.objectify.annotation.Entity;
|
||||||
import com.googlecode.objectify.annotation.Id;
|
import com.googlecode.objectify.annotation.Id;
|
||||||
import google.registry.model.contact.ContactResource;
|
import google.registry.model.contact.ContactResource;
|
||||||
import org.junit.After;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Tests for our replacement Objectify filter. */
|
/** Tests for our replacement Objectify filter. */
|
||||||
@RunWith(JUnit4.class)
|
class OfyFilterTest {
|
||||||
public class OfyFilterTest {
|
|
||||||
|
|
||||||
private LocalServiceTestHelper helper;
|
private LocalServiceTestHelper helper;
|
||||||
private ObjectifyFactory factory;
|
private ObjectifyFactory factory;
|
||||||
|
|
||||||
// We can't use AppEngineRule, because it triggers the precise behavior that we are testing.
|
// We can't use AppEngineRule, because it triggers the precise behavior that we are testing.
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void beforeEach() {
|
||||||
helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig()).setUp();
|
helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig()).setUp();
|
||||||
// Clear out the factory so that it requires re-registration on each test method.
|
// Clear out the factory so that it requires re-registration on each test method.
|
||||||
// Otherwise, static registration of types in one method would persist across methods.
|
// Otherwise, static registration of types in one method would persist across methods.
|
||||||
|
@ -53,8 +50,8 @@ public class OfyFilterTest {
|
||||||
ObjectifyService.setFactory(new ObjectifyFactory(false));
|
ObjectifyService.setFactory(new ObjectifyFactory(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterEach
|
||||||
public void after() {
|
void afterEach() {
|
||||||
ObjectifyFilter.complete();
|
ObjectifyFilter.complete();
|
||||||
ObjectifyService.setFactory(factory);
|
ObjectifyService.setFactory(factory);
|
||||||
ObjectifyFilter.complete();
|
ObjectifyFilter.complete();
|
||||||
|
@ -65,12 +62,12 @@ public class OfyFilterTest {
|
||||||
* Key.create looks up kind metadata for the class of the object it is given. If this happens
|
* 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,
|
* before the first reference to ObjectifyService, which statically triggers type registrations,
|
||||||
* then the create will fail. Note that this is only a problem if the type in question doesn't
|
* then the create will fail. Note that this is only a problem if the type in question doesn't
|
||||||
* call ObjectifyService.allocateId() inside its own builder or create method, since if it
|
* call ObjectifyService.allocateId() inside its own builder or create method, since if it does
|
||||||
* does that would trigger the statics as well. In this example, Registrar has a string id, so
|
* that would trigger the statics as well. In this example, Registrar has a string id, so the bug
|
||||||
* the bug occurs, were it not for OfyFilter.
|
* occurs, were it not for OfyFilter.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testFilterRegistersTypes() {
|
void testFilterRegistersTypes() {
|
||||||
UnregisteredEntity entity = new UnregisteredEntity(5L);
|
UnregisteredEntity entity = new UnregisteredEntity(5L);
|
||||||
IllegalStateException e = assertThrows(IllegalStateException.class, () -> Key.create(entity));
|
IllegalStateException e = assertThrows(IllegalStateException.class, () -> Key.create(entity));
|
||||||
assertThat(e)
|
assertThat(e)
|
||||||
|
@ -82,7 +79,7 @@ public class OfyFilterTest {
|
||||||
|
|
||||||
/** The filter should register all types for us. */
|
/** The filter should register all types for us. */
|
||||||
@Test
|
@Test
|
||||||
public void testKeyCreateAfterFilter() {
|
void testKeyCreateAfterFilter() {
|
||||||
new OfyFilter().init(null);
|
new OfyFilter().init(null);
|
||||||
ContactResource contact = newContactResource("contact1234");
|
ContactResource contact = newContactResource("contact1234");
|
||||||
Key.create(contact);
|
Key.create(contact);
|
||||||
|
|
|
@ -52,23 +52,21 @@ import google.registry.util.SystemClock;
|
||||||
import java.util.ConcurrentModificationException;
|
import java.util.ConcurrentModificationException;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Tests for our wrapper around Objectify. */
|
/** Tests for our wrapper around Objectify. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class OfyTest {
|
public class OfyTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
/** An entity to use in save and delete tests. */
|
/** An entity to use in save and delete tests. */
|
||||||
private HistoryEntry someObject;
|
private HistoryEntry someObject;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void init() {
|
void beforeEach() {
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
someObject = new HistoryEntry.Builder()
|
someObject = new HistoryEntry.Builder()
|
||||||
.setClientId("client id")
|
.setClientId("client id")
|
||||||
|
@ -97,17 +95,17 @@ public class OfyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBackupGroupRootTimestampsMustIncreaseOnSave() {
|
void testBackupGroupRootTimestampsMustIncreaseOnSave() {
|
||||||
doBackupGroupRootTimestampInversionTest(() -> ofy().save().entity(someObject));
|
doBackupGroupRootTimestampInversionTest(() -> ofy().save().entity(someObject));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBackupGroupRootTimestampsMustIncreaseOnDelete() {
|
void testBackupGroupRootTimestampsMustIncreaseOnDelete() {
|
||||||
doBackupGroupRootTimestampInversionTest(() -> ofy().delete().entity(someObject));
|
doBackupGroupRootTimestampInversionTest(() -> ofy().delete().entity(someObject));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSavingKeyTwice() {
|
void testSavingKeyTwice() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -122,7 +120,7 @@ public class OfyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeletingKeyTwice() {
|
void testDeletingKeyTwice() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -137,7 +135,7 @@ public class OfyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSaveDeleteKey() {
|
void testSaveDeleteKey() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -152,7 +150,7 @@ public class OfyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteSaveKey() {
|
void testDeleteSaveKey() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -167,7 +165,7 @@ public class OfyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSavingKeyTwiceInOneCall() {
|
void testSavingKeyTwiceInOneCall() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
() -> tm().transact(() -> ofy().save().entities(someObject, someObject)));
|
() -> tm().transact(() -> ofy().save().entities(someObject, someObject)));
|
||||||
|
@ -198,7 +196,7 @@ public class OfyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLifecycleCallbacks_loadFromEntity() {
|
void testLifecycleCallbacks_loadFromEntity() {
|
||||||
ofy().factory().register(LifecycleObject.class);
|
ofy().factory().register(LifecycleObject.class);
|
||||||
LifecycleObject object = new LifecycleObject();
|
LifecycleObject object = new LifecycleObject();
|
||||||
Entity entity = ofy().save().toEntity(object);
|
Entity entity = ofy().save().toEntity(object);
|
||||||
|
@ -207,7 +205,7 @@ public class OfyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLifecycleCallbacks_loadFromDatastore() {
|
void testLifecycleCallbacks_loadFromDatastore() {
|
||||||
ofy().factory().register(LifecycleObject.class);
|
ofy().factory().register(LifecycleObject.class);
|
||||||
final LifecycleObject object = new LifecycleObject();
|
final LifecycleObject object = new LifecycleObject();
|
||||||
tm().transact(() -> ofy().save().entity(object).now());
|
tm().transact(() -> ofy().save().entity(object).now());
|
||||||
|
@ -218,7 +216,7 @@ public class OfyTest {
|
||||||
|
|
||||||
/** Avoid regressions of b/21309102 where transaction time did not change on each retry. */
|
/** Avoid regressions of b/21309102 where transaction time did not change on each retry. */
|
||||||
@Test
|
@Test
|
||||||
public void testTransact_getsNewTimestampOnEachTry() {
|
void testTransact_getsNewTimestampOnEachTry() {
|
||||||
tm().transact(new Runnable() {
|
tm().transact(new Runnable() {
|
||||||
|
|
||||||
DateTime firstAttemptTime;
|
DateTime firstAttemptTime;
|
||||||
|
@ -236,7 +234,7 @@ public class OfyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransact_transientFailureException_retries() {
|
void testTransact_transientFailureException_retries() {
|
||||||
assertThat(
|
assertThat(
|
||||||
tm().transact(
|
tm().transact(
|
||||||
new Supplier<Integer>() {
|
new Supplier<Integer>() {
|
||||||
|
@ -256,7 +254,7 @@ public class OfyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransact_datastoreTimeoutException_noManifest_retries() {
|
void testTransact_datastoreTimeoutException_noManifest_retries() {
|
||||||
assertThat(
|
assertThat(
|
||||||
tm().transact(
|
tm().transact(
|
||||||
new Supplier<Integer>() {
|
new Supplier<Integer>() {
|
||||||
|
@ -279,7 +277,7 @@ public class OfyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransact_datastoreTimeoutException_manifestNotWrittenToDatastore_retries() {
|
void testTransact_datastoreTimeoutException_manifestNotWrittenToDatastore_retries() {
|
||||||
assertThat(
|
assertThat(
|
||||||
tm().transact(
|
tm().transact(
|
||||||
new Supplier<Integer>() {
|
new Supplier<Integer>() {
|
||||||
|
@ -302,7 +300,7 @@ public class OfyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransact_datastoreTimeoutException_manifestWrittenToDatastore_returnsSuccess() {
|
void testTransact_datastoreTimeoutException_manifestWrittenToDatastore_returnsSuccess() {
|
||||||
// A work unit that throws if it is ever retried.
|
// A work unit that throws if it is ever retried.
|
||||||
Supplier work =
|
Supplier work =
|
||||||
new Supplier<Void>() {
|
new Supplier<Void>() {
|
||||||
|
@ -356,22 +354,22 @@ public class OfyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransactNewReadOnly_transientFailureException_retries() {
|
void testTransactNewReadOnly_transientFailureException_retries() {
|
||||||
doReadOnlyRetryTest(new TransientFailureException(""));
|
doReadOnlyRetryTest(new TransientFailureException(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransactNewReadOnly_datastoreTimeoutException_retries() {
|
void testTransactNewReadOnly_datastoreTimeoutException_retries() {
|
||||||
doReadOnlyRetryTest(new DatastoreTimeoutException(""));
|
doReadOnlyRetryTest(new DatastoreTimeoutException(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransactNewReadOnly_datastoreFailureException_retries() {
|
void testTransactNewReadOnly_datastoreFailureException_retries() {
|
||||||
doReadOnlyRetryTest(new DatastoreFailureException(""));
|
doReadOnlyRetryTest(new DatastoreFailureException(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_getBaseEntityClassFromEntityOrKey_regularEntity() {
|
void test_getBaseEntityClassFromEntityOrKey_regularEntity() {
|
||||||
ContactResource contact = newContactResource("testcontact");
|
ContactResource contact = newContactResource("testcontact");
|
||||||
assertThat(getBaseEntityClassFromEntityOrKey(contact)).isEqualTo(ContactResource.class);
|
assertThat(getBaseEntityClassFromEntityOrKey(contact)).isEqualTo(ContactResource.class);
|
||||||
assertThat(getBaseEntityClassFromEntityOrKey(Key.create(contact)))
|
assertThat(getBaseEntityClassFromEntityOrKey(Key.create(contact)))
|
||||||
|
@ -379,7 +377,7 @@ public class OfyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_getBaseEntityClassFromEntityOrKey_subclassEntity() {
|
void test_getBaseEntityClassFromEntityOrKey_subclassEntity() {
|
||||||
DomainBase domain = DatastoreHelper.newDomainBase("test.tld");
|
DomainBase domain = DatastoreHelper.newDomainBase("test.tld");
|
||||||
assertThat(getBaseEntityClassFromEntityOrKey(domain)).isEqualTo(DomainBase.class);
|
assertThat(getBaseEntityClassFromEntityOrKey(domain)).isEqualTo(DomainBase.class);
|
||||||
assertThat(getBaseEntityClassFromEntityOrKey(Key.create(domain)))
|
assertThat(getBaseEntityClassFromEntityOrKey(Key.create(domain)))
|
||||||
|
@ -387,7 +385,7 @@ public class OfyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_getBaseEntityClassFromEntityOrKey_unregisteredEntity() {
|
void test_getBaseEntityClassFromEntityOrKey_unregisteredEntity() {
|
||||||
IllegalStateException thrown =
|
IllegalStateException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalStateException.class,
|
IllegalStateException.class,
|
||||||
|
@ -396,7 +394,7 @@ public class OfyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_getBaseEntityClassFromEntityOrKey_unregisteredEntityKey() {
|
void test_getBaseEntityClassFromEntityOrKey_unregisteredEntityKey() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -409,7 +407,7 @@ public class OfyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_doWithFreshSessionCache() {
|
void test_doWithFreshSessionCache() {
|
||||||
ofy().saveWithoutBackup().entity(someObject).now();
|
ofy().saveWithoutBackup().entity(someObject).now();
|
||||||
final HistoryEntry modifiedObject =
|
final HistoryEntry modifiedObject =
|
||||||
someObject.asBuilder().setModificationTime(END_OF_TIME).build();
|
someObject.asBuilder().setModificationTime(END_OF_TIME).build();
|
||||||
|
|
|
@ -35,27 +35,23 @@ import google.registry.testing.AppEngineRule;
|
||||||
import google.registry.testing.FakeClock;
|
import google.registry.testing.FakeClock;
|
||||||
import google.registry.testing.InjectRule;
|
import google.registry.testing.InjectRule;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link PollMessageExternalKeyConverter}. */
|
/** Unit tests for {@link PollMessageExternalKeyConverter}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class PollMessageExternalKeyConverterTest {
|
public class PollMessageExternalKeyConverterTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension public InjectRule inject = new InjectRule();
|
||||||
public InjectRule inject = new InjectRule();
|
|
||||||
|
|
||||||
HistoryEntry historyEntry;
|
private HistoryEntry historyEntry;
|
||||||
FakeClock clock = new FakeClock(DateTime.parse("2007-07-07T01:01:01Z"));
|
private FakeClock clock = new FakeClock(DateTime.parse("2007-07-07T01:01:01Z"));
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void beforeEach() {
|
||||||
inject.setStaticField(Ofy.class, "clock", clock);
|
inject.setStaticField(Ofy.class, "clock", clock);
|
||||||
createTld("foobar");
|
createTld("foobar");
|
||||||
historyEntry = persistResource(new HistoryEntry.Builder()
|
historyEntry = persistResource(new HistoryEntry.Builder()
|
||||||
|
@ -73,7 +69,7 @@ public class PollMessageExternalKeyConverterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_domain() {
|
void testSuccess_domain() {
|
||||||
PollMessage.OneTime pollMessage =
|
PollMessage.OneTime pollMessage =
|
||||||
persistResource(
|
persistResource(
|
||||||
new PollMessage.OneTime.Builder()
|
new PollMessage.OneTime.Builder()
|
||||||
|
@ -88,7 +84,7 @@ public class PollMessageExternalKeyConverterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_contact() {
|
void testSuccess_contact() {
|
||||||
historyEntry =
|
historyEntry =
|
||||||
persistResource(historyEntry.asBuilder().setParent(persistActiveContact("tim")).build());
|
persistResource(historyEntry.asBuilder().setParent(persistActiveContact("tim")).build());
|
||||||
PollMessage.OneTime pollMessage =
|
PollMessage.OneTime pollMessage =
|
||||||
|
@ -104,7 +100,7 @@ public class PollMessageExternalKeyConverterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_host() {
|
void testSuccess_host() {
|
||||||
historyEntry =
|
historyEntry =
|
||||||
persistResource(historyEntry.asBuilder().setParent(persistActiveHost("time.zyx")).build());
|
persistResource(historyEntry.asBuilder().setParent(persistActiveHost("time.zyx")).build());
|
||||||
PollMessage.OneTime pollMessage =
|
PollMessage.OneTime pollMessage =
|
||||||
|
@ -120,14 +116,14 @@ public class PollMessageExternalKeyConverterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_missingYearField() {
|
void testFailure_missingYearField() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
PollMessageExternalKeyParseException.class,
|
PollMessageExternalKeyParseException.class,
|
||||||
() -> parsePollMessageExternalId("1-2-FOOBAR-4-5"));
|
() -> parsePollMessageExternalId("1-2-FOOBAR-4-5"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_invalidEppResourceTypeId() {
|
void testFailure_invalidEppResourceTypeId() {
|
||||||
// Populate the testdata correctly as for 1-2-FOOBAR-4-5 so we know that the only thing that
|
// Populate the testdata correctly as for 1-2-FOOBAR-4-5 so we know that the only thing that
|
||||||
// is wrong here is the EppResourceTypeId.
|
// is wrong here is the EppResourceTypeId.
|
||||||
testSuccess_domain();
|
testSuccess_domain();
|
||||||
|
@ -137,22 +133,21 @@ public class PollMessageExternalKeyConverterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_tooFewComponentParts() {
|
void testFailure_tooFewComponentParts() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
PollMessageExternalKeyParseException.class,
|
PollMessageExternalKeyParseException.class,
|
||||||
() -> parsePollMessageExternalId("1-3-EXAMPLE"));
|
() -> parsePollMessageExternalId("1-3-EXAMPLE"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_tooManyComponentParts() {
|
void testFailure_tooManyComponentParts() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
PollMessageExternalKeyParseException.class,
|
PollMessageExternalKeyParseException.class,
|
||||||
() -> parsePollMessageExternalId("1-3-EXAMPLE-4-5-2007-2009"));
|
() -> parsePollMessageExternalId("1-3-EXAMPLE-4-5-2007-2009"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_nonNumericIds() {
|
void testFailure_nonNumericIds() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
PollMessageExternalKeyParseException.class,
|
PollMessageExternalKeyParseException.class,
|
||||||
() -> parsePollMessageExternalId("A-B-FOOBAR-D-E-F"));
|
() -> parsePollMessageExternalId("A-B-FOOBAR-D-E-F"));
|
||||||
|
|
|
@ -34,16 +34,16 @@ import org.junit.jupiter.api.Test;
|
||||||
/** Unit tests for {@link PollMessage}. */
|
/** Unit tests for {@link PollMessage}. */
|
||||||
public class PollMessageTest extends EntityTestCase {
|
public class PollMessageTest extends EntityTestCase {
|
||||||
|
|
||||||
HistoryEntry historyEntry;
|
private HistoryEntry historyEntry;
|
||||||
PollMessage.OneTime oneTime;
|
private PollMessage.OneTime oneTime;
|
||||||
PollMessage.Autorenew autoRenew;
|
private PollMessage.Autorenew autoRenew;
|
||||||
|
|
||||||
public PollMessageTest() {
|
PollMessageTest() {
|
||||||
super(JpaEntityCoverageCheck.ENABLED);
|
super(JpaEntityCoverageCheck.ENABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
createTld("foobar");
|
createTld("foobar");
|
||||||
historyEntry =
|
historyEntry =
|
||||||
persistResource(
|
persistResource(
|
||||||
|
@ -123,7 +123,7 @@ public class PollMessageTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPersistenceOneTime() {
|
void testPersistenceOneTime() {
|
||||||
PollMessage.OneTime pollMessage =
|
PollMessage.OneTime pollMessage =
|
||||||
persistResource(
|
persistResource(
|
||||||
new PollMessage.OneTime.Builder()
|
new PollMessage.OneTime.Builder()
|
||||||
|
@ -136,7 +136,7 @@ public class PollMessageTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPersistenceAutorenew() {
|
void testPersistenceAutorenew() {
|
||||||
PollMessage.Autorenew pollMessage =
|
PollMessage.Autorenew pollMessage =
|
||||||
persistResource(
|
persistResource(
|
||||||
new PollMessage.Autorenew.Builder()
|
new PollMessage.Autorenew.Builder()
|
||||||
|
@ -151,7 +151,7 @@ public class PollMessageTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIndexingAutorenew() throws Exception {
|
void testIndexingAutorenew() throws Exception {
|
||||||
PollMessage.Autorenew pollMessage =
|
PollMessage.Autorenew pollMessage =
|
||||||
persistResource(
|
persistResource(
|
||||||
new PollMessage.Autorenew.Builder()
|
new PollMessage.Autorenew.Builder()
|
||||||
|
|
|
@ -44,16 +44,16 @@ import google.registry.model.registrar.Registrar.Type;
|
||||||
import google.registry.model.registry.Registries;
|
import google.registry.model.registry.Registries;
|
||||||
import google.registry.util.CidrAddressBlock;
|
import google.registry.util.CidrAddressBlock;
|
||||||
import org.joda.money.CurrencyUnit;
|
import org.joda.money.CurrencyUnit;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/** Unit tests for {@link Registrar}. */
|
/** Unit tests for {@link Registrar}. */
|
||||||
public class RegistrarTest extends EntityTestCase {
|
class RegistrarTest extends EntityTestCase {
|
||||||
private Registrar registrar;
|
private Registrar registrar;
|
||||||
private RegistrarContact abuseAdminContact;
|
private RegistrarContact abuseAdminContact;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
createTld("xn--q9jyb4c");
|
createTld("xn--q9jyb4c");
|
||||||
// Set up a new persisted registrar entity.
|
// Set up a new persisted registrar entity.
|
||||||
registrar =
|
registrar =
|
||||||
|
@ -127,7 +127,7 @@ public class RegistrarTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPersistence() {
|
void testPersistence() {
|
||||||
assertThat(registrar)
|
assertThat(registrar)
|
||||||
.isEqualTo(
|
.isEqualTo(
|
||||||
ofy()
|
ofy()
|
||||||
|
@ -139,12 +139,12 @@ public class RegistrarTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIndexing() throws Exception {
|
void testIndexing() throws Exception {
|
||||||
verifyIndexing(registrar, "registrarName", "ianaIdentifier");
|
verifyIndexing(registrar, "registrarName", "ianaIdentifier");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_passwordNull() {
|
void testFailure_passwordNull() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class, () -> new Registrar.Builder().setPassword(null));
|
IllegalArgumentException.class, () -> new Registrar.Builder().setPassword(null));
|
||||||
|
@ -152,7 +152,7 @@ public class RegistrarTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_passwordTooShort() {
|
void testFailure_passwordTooShort() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class, () -> new Registrar.Builder().setPassword("abcde"));
|
IllegalArgumentException.class, () -> new Registrar.Builder().setPassword("abcde"));
|
||||||
|
@ -160,7 +160,7 @@ public class RegistrarTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_passwordTooLong() {
|
void testFailure_passwordTooLong() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -169,7 +169,7 @@ public class RegistrarTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_clientId_bounds() {
|
void testSuccess_clientId_bounds() {
|
||||||
registrar = registrar.asBuilder().setClientId("abc").build();
|
registrar = registrar.asBuilder().setClientId("abc").build();
|
||||||
assertThat(registrar.getClientId()).isEqualTo("abc");
|
assertThat(registrar.getClientId()).isEqualTo("abc");
|
||||||
registrar = registrar.asBuilder().setClientId("abcdefghijklmnop").build();
|
registrar = registrar.asBuilder().setClientId("abcdefghijklmnop").build();
|
||||||
|
@ -177,19 +177,19 @@ public class RegistrarTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_clientId_tooShort() {
|
void testFailure_clientId_tooShort() {
|
||||||
assertThrows(IllegalArgumentException.class, () -> new Registrar.Builder().setClientId("ab"));
|
assertThrows(IllegalArgumentException.class, () -> new Registrar.Builder().setClientId("ab"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_clientId_tooLong() {
|
void testFailure_clientId_tooLong() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
() -> new Registrar.Builder().setClientId("abcdefghijklmnopq"));
|
() -> new Registrar.Builder().setClientId("abcdefghijklmnopq"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetCertificateHash_alsoSetsHash() {
|
void testSetCertificateHash_alsoSetsHash() {
|
||||||
registrar = registrar.asBuilder().setClientCertificate(null, fakeClock.nowUtc()).build();
|
registrar = registrar.asBuilder().setClientCertificate(null, fakeClock.nowUtc()).build();
|
||||||
fakeClock.advanceOneMilli();
|
fakeClock.advanceOneMilli();
|
||||||
registrar = registrar.asBuilder().setClientCertificate(SAMPLE_CERT, fakeClock.nowUtc()).build();
|
registrar = registrar.asBuilder().setClientCertificate(SAMPLE_CERT, fakeClock.nowUtc()).build();
|
||||||
|
@ -199,7 +199,7 @@ public class RegistrarTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteCertificateHash_alsoDeletesHash() {
|
void testDeleteCertificateHash_alsoDeletesHash() {
|
||||||
assertThat(registrar.getClientCertificateHash()).isNotNull();
|
assertThat(registrar.getClientCertificateHash()).isNotNull();
|
||||||
fakeClock.advanceOneMilli();
|
fakeClock.advanceOneMilli();
|
||||||
registrar = registrar.asBuilder().setClientCertificate(null, fakeClock.nowUtc()).build();
|
registrar = registrar.asBuilder().setClientCertificate(null, fakeClock.nowUtc()).build();
|
||||||
|
@ -209,7 +209,7 @@ public class RegistrarTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetFailoverCertificateHash_alsoSetsHash() {
|
void testSetFailoverCertificateHash_alsoSetsHash() {
|
||||||
fakeClock.advanceOneMilli();
|
fakeClock.advanceOneMilli();
|
||||||
registrar =
|
registrar =
|
||||||
registrar
|
registrar
|
||||||
|
@ -222,7 +222,7 @@ public class RegistrarTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteFailoverCertificateHash_alsoDeletesHash() {
|
void testDeleteFailoverCertificateHash_alsoDeletesHash() {
|
||||||
registrar =
|
registrar =
|
||||||
registrar.asBuilder().setFailoverClientCertificate(SAMPLE_CERT, fakeClock.nowUtc()).build();
|
registrar.asBuilder().setFailoverClientCertificate(SAMPLE_CERT, fakeClock.nowUtc()).build();
|
||||||
assertThat(registrar.getFailoverClientCertificateHash()).isNotNull();
|
assertThat(registrar.getFailoverClientCertificateHash()).isNotNull();
|
||||||
|
@ -235,7 +235,7 @@ public class RegistrarTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_clearingIanaAndBillingIds() {
|
void testSuccess_clearingIanaAndBillingIds() {
|
||||||
registrar
|
registrar
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
.setType(Type.TEST)
|
.setType(Type.TEST)
|
||||||
|
@ -245,30 +245,30 @@ public class RegistrarTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_clearingBillingAccountMap() {
|
void testSuccess_clearingBillingAccountMap() {
|
||||||
registrar = registrar.asBuilder().setBillingAccountMap(null).build();
|
registrar = registrar.asBuilder().setBillingAccountMap(null).build();
|
||||||
assertThat(registrar.getBillingAccountMap()).isEmpty();
|
assertThat(registrar.getBillingAccountMap()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_ianaIdForInternal() {
|
void testSuccess_ianaIdForInternal() {
|
||||||
registrar.asBuilder().setType(Type.INTERNAL).setIanaIdentifier(9998L).build();
|
registrar.asBuilder().setType(Type.INTERNAL).setIanaIdentifier(9998L).build();
|
||||||
registrar.asBuilder().setType(Type.INTERNAL).setIanaIdentifier(9999L).build();
|
registrar.asBuilder().setType(Type.INTERNAL).setIanaIdentifier(9999L).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_ianaIdForPdt() {
|
void testSuccess_ianaIdForPdt() {
|
||||||
registrar.asBuilder().setType(Type.PDT).setIanaIdentifier(9995L).build();
|
registrar.asBuilder().setType(Type.PDT).setIanaIdentifier(9995L).build();
|
||||||
registrar.asBuilder().setType(Type.PDT).setIanaIdentifier(9996L).build();
|
registrar.asBuilder().setType(Type.PDT).setIanaIdentifier(9996L).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_ianaIdForExternalMonitoring() {
|
void testSuccess_ianaIdForExternalMonitoring() {
|
||||||
registrar.asBuilder().setType(Type.EXTERNAL_MONITORING).setIanaIdentifier(9997L).build();
|
registrar.asBuilder().setType(Type.EXTERNAL_MONITORING).setIanaIdentifier(9997L).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_emptyContactTypesAllowed() {
|
void testSuccess_emptyContactTypesAllowed() {
|
||||||
persistSimpleResource(
|
persistSimpleResource(
|
||||||
new RegistrarContact.Builder()
|
new RegistrarContact.Builder()
|
||||||
.setParent(registrar)
|
.setParent(registrar)
|
||||||
|
@ -284,7 +284,7 @@ public class RegistrarTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_getContactsByType() {
|
void testSuccess_getContactsByType() {
|
||||||
RegistrarContact newTechContact =
|
RegistrarContact newTechContact =
|
||||||
persistSimpleResource(
|
persistSimpleResource(
|
||||||
new RegistrarContact.Builder()
|
new RegistrarContact.Builder()
|
||||||
|
@ -318,7 +318,7 @@ public class RegistrarTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_missingRegistrarType() {
|
void testFailure_missingRegistrarType() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -327,7 +327,7 @@ public class RegistrarTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_missingRegistrarName() {
|
void testFailure_missingRegistrarName() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -337,7 +337,7 @@ public class RegistrarTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_missingAddress() {
|
void testFailure_missingAddress() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -353,21 +353,21 @@ public class RegistrarTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_badIanaIdForInternal() {
|
void testFailure_badIanaIdForInternal() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
() -> new Registrar.Builder().setType(Type.INTERNAL).setIanaIdentifier(8L).build());
|
() -> new Registrar.Builder().setType(Type.INTERNAL).setIanaIdentifier(8L).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_badIanaIdForPdt() {
|
void testFailure_badIanaIdForPdt() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
() -> new Registrar.Builder().setType(Type.PDT).setIanaIdentifier(8L).build());
|
() -> new Registrar.Builder().setType(Type.PDT).setIanaIdentifier(8L).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_badIanaIdForExternalMonitoring() {
|
void testFailure_badIanaIdForExternalMonitoring() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
() ->
|
() ->
|
||||||
|
@ -375,51 +375,51 @@ public class RegistrarTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_missingIanaIdForReal() {
|
void testFailure_missingIanaIdForReal() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class, () -> new Registrar.Builder().setType(Type.REAL).build());
|
IllegalArgumentException.class, () -> new Registrar.Builder().setType(Type.REAL).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_missingIanaIdForInternal() {
|
void testFailure_missingIanaIdForInternal() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
() -> new Registrar.Builder().setType(Type.INTERNAL).build());
|
() -> new Registrar.Builder().setType(Type.INTERNAL).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_missingIanaIdForPdt() {
|
void testFailure_missingIanaIdForPdt() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class, () -> new Registrar.Builder().setType(Type.PDT).build());
|
IllegalArgumentException.class, () -> new Registrar.Builder().setType(Type.PDT).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_missingIanaIdForExternalMonitoring() {
|
void testFailure_missingIanaIdForExternalMonitoring() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
() -> new Registrar.Builder().setType(Type.EXTERNAL_MONITORING).build());
|
() -> new Registrar.Builder().setType(Type.EXTERNAL_MONITORING).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_phonePasscodeTooShort() {
|
void testFailure_phonePasscodeTooShort() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class, () -> new Registrar.Builder().setPhonePasscode("0123"));
|
IllegalArgumentException.class, () -> new Registrar.Builder().setPhonePasscode("0123"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_phonePasscodeTooLong() {
|
void testFailure_phonePasscodeTooLong() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class, () -> new Registrar.Builder().setPhonePasscode("012345"));
|
IllegalArgumentException.class, () -> new Registrar.Builder().setPhonePasscode("012345"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_phonePasscodeInvalidCharacters() {
|
void testFailure_phonePasscodeInvalidCharacters() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class, () -> new Registrar.Builder().setPhonePasscode("code1"));
|
IllegalArgumentException.class, () -> new Registrar.Builder().setPhonePasscode("code1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_setAllowedTlds() {
|
void testSuccess_setAllowedTlds() {
|
||||||
assertThat(
|
assertThat(
|
||||||
registrar
|
registrar
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
|
@ -430,7 +430,7 @@ public class RegistrarTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_setAllowedTldsUncached() {
|
void testSuccess_setAllowedTldsUncached() {
|
||||||
assertThat(
|
assertThat(
|
||||||
registrar
|
registrar
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
|
@ -441,21 +441,21 @@ public class RegistrarTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_setAllowedTlds_nonexistentTld() {
|
void testFailure_setAllowedTlds_nonexistentTld() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
() -> registrar.asBuilder().setAllowedTlds(ImmutableSet.of("bad")));
|
() -> registrar.asBuilder().setAllowedTlds(ImmutableSet.of("bad")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_setAllowedTldsUncached_nonexistentTld() {
|
void testFailure_setAllowedTldsUncached_nonexistentTld() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
() -> registrar.asBuilder().setAllowedTldsUncached(ImmutableSet.of("bad")));
|
() -> registrar.asBuilder().setAllowedTldsUncached(ImmutableSet.of("bad")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_driveFolderId_asFullUrl() {
|
void testFailure_driveFolderId_asFullUrl() {
|
||||||
String driveFolderId =
|
String driveFolderId =
|
||||||
"https://drive.google.com/drive/folders/1j3v7RZkU25DjbTx2-Q93H04zKOBau89M";
|
"https://drive.google.com/drive/folders/1j3v7RZkU25DjbTx2-Q93H04zKOBau89M";
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
|
@ -466,14 +466,14 @@ public class RegistrarTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_nullEmail() {
|
void testFailure_nullEmail() {
|
||||||
NullPointerException thrown =
|
NullPointerException thrown =
|
||||||
assertThrows(NullPointerException.class, () -> registrar.asBuilder().setEmailAddress(null));
|
assertThrows(NullPointerException.class, () -> registrar.asBuilder().setEmailAddress(null));
|
||||||
assertThat(thrown).hasMessageThat().isEqualTo("Provided email was null");
|
assertThat(thrown).hasMessageThat().isEqualTo("Provided email was null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_invalidEmail() {
|
void testFailure_invalidEmail() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class, () -> registrar.asBuilder().setEmailAddress("lolcat"));
|
IllegalArgumentException.class, () -> registrar.asBuilder().setEmailAddress("lolcat"));
|
||||||
|
@ -483,7 +483,7 @@ public class RegistrarTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_emptyEmail() {
|
void testFailure_emptyEmail() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class, () -> registrar.asBuilder().setEmailAddress(""));
|
IllegalArgumentException.class, () -> registrar.asBuilder().setEmailAddress(""));
|
||||||
|
@ -491,7 +491,7 @@ public class RegistrarTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_nullIcannReferralEmail() {
|
void testFailure_nullIcannReferralEmail() {
|
||||||
NullPointerException thrown =
|
NullPointerException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
NullPointerException.class, () -> registrar.asBuilder().setIcannReferralEmail(null));
|
NullPointerException.class, () -> registrar.asBuilder().setIcannReferralEmail(null));
|
||||||
|
@ -499,7 +499,7 @@ public class RegistrarTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_invalidIcannReferralEmail() {
|
void testFailure_invalidIcannReferralEmail() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -510,7 +510,7 @@ public class RegistrarTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_emptyIcannReferralEmail() {
|
void testFailure_emptyIcannReferralEmail() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class, () -> registrar.asBuilder().setEmailAddress(""));
|
IllegalArgumentException.class, () -> registrar.asBuilder().setEmailAddress(""));
|
||||||
|
@ -518,7 +518,7 @@ public class RegistrarTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_setAllowedTldsUncached_newTldNotInCache() {
|
void testSuccess_setAllowedTldsUncached_newTldNotInCache() {
|
||||||
int origSingletonCacheRefreshSeconds =
|
int origSingletonCacheRefreshSeconds =
|
||||||
RegistryConfig.CONFIG_SETTINGS.get().caching.singletonCacheRefreshSeconds;
|
RegistryConfig.CONFIG_SETTINGS.get().caching.singletonCacheRefreshSeconds;
|
||||||
// Sanity check for Gradle-based open-source build.
|
// Sanity check for Gradle-based open-source build.
|
||||||
|
@ -567,7 +567,7 @@ public class RegistrarTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoadByClientIdCached_isTransactionless() {
|
void testLoadByClientIdCached_isTransactionless() {
|
||||||
tm().transact(
|
tm().transact(
|
||||||
() -> {
|
() -> {
|
||||||
assertThat(Registrar.loadByClientIdCached("registrar")).isPresent();
|
assertThat(Registrar.loadByClientIdCached("registrar")).isPresent();
|
||||||
|
@ -584,28 +584,28 @@ public class RegistrarTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_loadByClientId_clientIdIsNull() {
|
void testFailure_loadByClientId_clientIdIsNull() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(IllegalArgumentException.class, () -> Registrar.loadByClientId(null));
|
assertThrows(IllegalArgumentException.class, () -> Registrar.loadByClientId(null));
|
||||||
assertThat(thrown).hasMessageThat().contains("clientId must be specified");
|
assertThat(thrown).hasMessageThat().contains("clientId must be specified");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_loadByClientId_clientIdIsEmpty() {
|
void testFailure_loadByClientId_clientIdIsEmpty() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(IllegalArgumentException.class, () -> Registrar.loadByClientId(""));
|
assertThrows(IllegalArgumentException.class, () -> Registrar.loadByClientId(""));
|
||||||
assertThat(thrown).hasMessageThat().contains("clientId must be specified");
|
assertThat(thrown).hasMessageThat().contains("clientId must be specified");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_loadByClientIdCached_clientIdIsNull() {
|
void testFailure_loadByClientIdCached_clientIdIsNull() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(IllegalArgumentException.class, () -> Registrar.loadByClientIdCached(null));
|
assertThrows(IllegalArgumentException.class, () -> Registrar.loadByClientIdCached(null));
|
||||||
assertThat(thrown).hasMessageThat().contains("clientId must be specified");
|
assertThat(thrown).hasMessageThat().contains("clientId must be specified");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_loadByClientIdCached_clientIdIsEmpty() {
|
void testFailure_loadByClientIdCached_clientIdIsEmpty() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(IllegalArgumentException.class, () -> Registrar.loadByClientIdCached(""));
|
assertThrows(IllegalArgumentException.class, () -> Registrar.loadByClientIdCached(""));
|
||||||
assertThat(thrown).hasMessageThat().contains("clientId must be specified");
|
assertThat(thrown).hasMessageThat().contains("clientId must be specified");
|
||||||
|
|
|
@ -35,12 +35,12 @@ import org.junit.jupiter.api.Test;
|
||||||
/** Unit tests for {@link RegistryLockDao}. */
|
/** Unit tests for {@link RegistryLockDao}. */
|
||||||
public final class RegistryLockDaoTest extends EntityTestCase {
|
public final class RegistryLockDaoTest extends EntityTestCase {
|
||||||
|
|
||||||
public RegistryLockDaoTest() {
|
RegistryLockDaoTest() {
|
||||||
super(JpaEntityCoverageCheck.ENABLED);
|
super(JpaEntityCoverageCheck.ENABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSaveAndLoad_success() {
|
void testSaveAndLoad_success() {
|
||||||
RegistryLock lock = createLock();
|
RegistryLock lock = createLock();
|
||||||
saveRegistryLock(lock);
|
saveRegistryLock(lock);
|
||||||
RegistryLock fromDatabase = getRegistryLockByVerificationCode(lock.getVerificationCode()).get();
|
RegistryLock fromDatabase = getRegistryLockByVerificationCode(lock.getVerificationCode()).get();
|
||||||
|
@ -50,7 +50,7 @@ public final class RegistryLockDaoTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSaveTwiceAndLoad_returnsLatest() {
|
void testSaveTwiceAndLoad_returnsLatest() {
|
||||||
RegistryLock lock = createLock();
|
RegistryLock lock = createLock();
|
||||||
saveRegistryLock(lock);
|
saveRegistryLock(lock);
|
||||||
fakeClock.advanceOneMilli();
|
fakeClock.advanceOneMilli();
|
||||||
|
@ -74,7 +74,7 @@ public final class RegistryLockDaoTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSave_load_withUnlock() {
|
void testSave_load_withUnlock() {
|
||||||
RegistryLock lock =
|
RegistryLock lock =
|
||||||
saveRegistryLock(
|
saveRegistryLock(
|
||||||
createLock()
|
createLock()
|
||||||
|
@ -93,7 +93,7 @@ public final class RegistryLockDaoTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateLock_usingSamePrimaryKey() {
|
void testUpdateLock_usingSamePrimaryKey() {
|
||||||
RegistryLock lock = saveRegistryLock(createLock());
|
RegistryLock lock = saveRegistryLock(createLock());
|
||||||
fakeClock.advanceOneMilli();
|
fakeClock.advanceOneMilli();
|
||||||
RegistryLock updatedLock =
|
RegistryLock updatedLock =
|
||||||
|
@ -110,17 +110,17 @@ public final class RegistryLockDaoTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_saveNull() {
|
void testFailure_saveNull() {
|
||||||
assertThrows(NullPointerException.class, () -> saveRegistryLock(null));
|
assertThrows(NullPointerException.class, () -> saveRegistryLock(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getLock_unknownCode() {
|
void getLock_unknownCode() {
|
||||||
assertThat(getRegistryLockByVerificationCode("hi").isPresent()).isFalse();
|
assertThat(getRegistryLockByVerificationCode("hi").isPresent()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testByRevisionId_valid() {
|
void testByRevisionId_valid() {
|
||||||
RegistryLock lock = saveRegistryLock(createLock());
|
RegistryLock lock = saveRegistryLock(createLock());
|
||||||
RegistryLock otherLock = getRegistryLockByRevisionId(lock.getRevisionId()).get();
|
RegistryLock otherLock = getRegistryLockByRevisionId(lock.getRevisionId()).get();
|
||||||
// can't do direct comparison due to update time
|
// can't do direct comparison due to update time
|
||||||
|
@ -129,12 +129,12 @@ public final class RegistryLockDaoTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testByRevisionId_invalid() {
|
void testByRevisionId_invalid() {
|
||||||
assertThat(getRegistryLockByRevisionId(8675309L).isPresent()).isFalse();
|
assertThat(getRegistryLockByRevisionId(8675309L).isPresent()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoad_lockedDomains_byRegistrarId() {
|
void testLoad_lockedDomains_byRegistrarId() {
|
||||||
RegistryLock lock = createLock();
|
RegistryLock lock = createLock();
|
||||||
RegistryLock secondLock =
|
RegistryLock secondLock =
|
||||||
createLock()
|
createLock()
|
||||||
|
@ -163,7 +163,7 @@ public final class RegistryLockDaoTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoad_byRepoId() {
|
void testLoad_byRepoId() {
|
||||||
RegistryLock completedLock =
|
RegistryLock completedLock =
|
||||||
createLock().asBuilder().setLockCompletionTimestamp(fakeClock.nowUtc()).build();
|
createLock().asBuilder().setLockCompletionTimestamp(fakeClock.nowUtc()).build();
|
||||||
saveRegistryLock(completedLock);
|
saveRegistryLock(completedLock);
|
||||||
|
@ -178,12 +178,12 @@ public final class RegistryLockDaoTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoad_byRepoId_empty() {
|
void testLoad_byRepoId_empty() {
|
||||||
assertThat(getMostRecentRegistryLockByRepoId("nonexistent").isPresent()).isFalse();
|
assertThat(getMostRecentRegistryLockByRepoId("nonexistent").isPresent()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoad_verified_byRepoId() {
|
void testLoad_verified_byRepoId() {
|
||||||
RegistryLock completedLock =
|
RegistryLock completedLock =
|
||||||
createLock().asBuilder().setLockCompletionTimestamp(fakeClock.nowUtc()).build();
|
createLock().asBuilder().setLockCompletionTimestamp(fakeClock.nowUtc()).build();
|
||||||
saveRegistryLock(completedLock);
|
saveRegistryLock(completedLock);
|
||||||
|
@ -198,14 +198,14 @@ public final class RegistryLockDaoTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoad_verified_byRepoId_empty() {
|
void testLoad_verified_byRepoId_empty() {
|
||||||
saveRegistryLock(createLock());
|
saveRegistryLock(createLock());
|
||||||
Optional<RegistryLock> mostRecent = getMostRecentVerifiedRegistryLockByRepoId("repoId");
|
Optional<RegistryLock> mostRecent = getMostRecentVerifiedRegistryLockByRepoId("repoId");
|
||||||
assertThat(mostRecent.isPresent()).isFalse();
|
assertThat(mostRecent.isPresent()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoad_verifiedUnlock_byRepoId() {
|
void testLoad_verifiedUnlock_byRepoId() {
|
||||||
RegistryLock lock =
|
RegistryLock lock =
|
||||||
saveRegistryLock(
|
saveRegistryLock(
|
||||||
createLock()
|
createLock()
|
||||||
|
@ -220,7 +220,7 @@ public final class RegistryLockDaoTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoad_verifiedUnlock_empty() {
|
void testLoad_verifiedUnlock_empty() {
|
||||||
RegistryLock completedLock =
|
RegistryLock completedLock =
|
||||||
createLock().asBuilder().setLockCompletionTimestamp(fakeClock.nowUtc()).build();
|
createLock().asBuilder().setLockCompletionTimestamp(fakeClock.nowUtc()).build();
|
||||||
saveRegistryLock(completedLock);
|
saveRegistryLock(completedLock);
|
||||||
|
|
|
@ -46,40 +46,37 @@ import google.registry.model.registry.label.ReservedList;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import org.joda.money.Money;
|
import org.joda.money.Money;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/** Unit tests for {@link Registry}. */
|
/** Unit tests for {@link Registry}. */
|
||||||
public class RegistryTest extends EntityTestCase {
|
class RegistryTest extends EntityTestCase {
|
||||||
|
|
||||||
Registry registry;
|
@BeforeEach
|
||||||
|
void beforeEach() {
|
||||||
@Before
|
|
||||||
public void setup() {
|
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
registry = Registry.get("tld");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPersistence() {
|
void testPersistence() {
|
||||||
assertWithMessage("Registry not found").that(Registry.get("tld")).isNotNull();
|
assertWithMessage("Registry not found").that(Registry.get("tld")).isNotNull();
|
||||||
assertThat(ofy().load().type(Registry.class).parent(getCrossTldKey()).id("tld").now())
|
assertThat(ofy().load().type(Registry.class).parent(getCrossTldKey()).id("tld").now())
|
||||||
.isEqualTo(Registry.get("tld"));
|
.isEqualTo(Registry.get("tld"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_registryNotFound() {
|
void testFailure_registryNotFound() {
|
||||||
createTld("foo");
|
createTld("foo");
|
||||||
assertThrows(RegistryNotFoundException.class, () -> Registry.get("baz"));
|
assertThrows(RegistryNotFoundException.class, () -> Registry.get("baz"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIndexing() throws Exception {
|
void testIndexing() throws Exception {
|
||||||
verifyIndexing(Registry.get("tld"));
|
verifyIndexing(Registry.get("tld"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSettingEscrowEnabled_null() {
|
void testSettingEscrowEnabled_null() {
|
||||||
assertThat(Registry.get("tld").asBuilder().setEscrowEnabled(true).build().getEscrowEnabled())
|
assertThat(Registry.get("tld").asBuilder().setEscrowEnabled(true).build().getEscrowEnabled())
|
||||||
.isTrue();
|
.isTrue();
|
||||||
assertThat(Registry.get("tld").asBuilder().setEscrowEnabled(false).build().getEscrowEnabled())
|
assertThat(Registry.get("tld").asBuilder().setEscrowEnabled(false).build().getEscrowEnabled())
|
||||||
|
@ -87,7 +84,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSettingCreateBillingCost() {
|
void testSettingCreateBillingCost() {
|
||||||
Registry registry =
|
Registry registry =
|
||||||
Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 42)).build();
|
Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 42)).build();
|
||||||
assertThat(registry.getStandardCreateCost()).isEqualTo(Money.of(USD, 42));
|
assertThat(registry.getStandardCreateCost()).isEqualTo(Money.of(USD, 42));
|
||||||
|
@ -96,7 +93,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSettingRestoreBillingCost() {
|
void testSettingRestoreBillingCost() {
|
||||||
Registry registry =
|
Registry registry =
|
||||||
Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, 42)).build();
|
Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, 42)).build();
|
||||||
// The default value of 13 is set in createTld().
|
// The default value of 13 is set in createTld().
|
||||||
|
@ -105,19 +102,19 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultNumDnsPublishShards_equalToOne() {
|
void testDefaultNumDnsPublishShards_equalToOne() {
|
||||||
Registry registry = Registry.get("tld").asBuilder().build();
|
Registry registry = Registry.get("tld").asBuilder().build();
|
||||||
assertThat(registry.getNumDnsPublishLocks()).isEqualTo(1);
|
assertThat(registry.getNumDnsPublishLocks()).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSettingNumDnsPublishShards() {
|
void testSettingNumDnsPublishShards() {
|
||||||
Registry registry = Registry.get("tld").asBuilder().setNumDnsPublishLocks(2).build();
|
Registry registry = Registry.get("tld").asBuilder().setNumDnsPublishLocks(2).build();
|
||||||
assertThat(registry.getNumDnsPublishLocks()).isEqualTo(2);
|
assertThat(registry.getNumDnsPublishLocks()).isEqualTo(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetReservedList_doesntMutateExistingRegistry() {
|
void testSetReservedList_doesntMutateExistingRegistry() {
|
||||||
ReservedList rl15 =
|
ReservedList rl15 =
|
||||||
persistReservedList("tld-reserved15", "potato,FULLY_BLOCKED", "phone,FULLY_BLOCKED");
|
persistReservedList("tld-reserved15", "potato,FULLY_BLOCKED", "phone,FULLY_BLOCKED");
|
||||||
ReservedList rl16 =
|
ReservedList rl16 =
|
||||||
|
@ -135,14 +132,14 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetReservedLists_doesntReturnNullWhenUninitialized() {
|
void testGetReservedLists_doesntReturnNullWhenUninitialized() {
|
||||||
Registry registry = newRegistry("foo", "FOO");
|
Registry registry = newRegistry("foo", "FOO");
|
||||||
assertThat(registry.getReservedLists()).isNotNull();
|
assertThat(registry.getReservedLists()).isNotNull();
|
||||||
assertThat(registry.getReservedLists()).isEmpty();
|
assertThat(registry.getReservedLists()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAll() {
|
void testGetAll() {
|
||||||
createTld("foo");
|
createTld("foo");
|
||||||
assertThat(Registry.getAll(ImmutableSet.of("foo", "tld")))
|
assertThat(Registry.getAll(ImmutableSet.of("foo", "tld")))
|
||||||
.containsExactlyElementsIn(
|
.containsExactlyElementsIn(
|
||||||
|
@ -155,7 +152,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetReservedLists() {
|
void testSetReservedLists() {
|
||||||
ReservedList rl5 =
|
ReservedList rl5 =
|
||||||
persistReservedList("tld-reserved5", "lol,FULLY_BLOCKED", "cat,FULLY_BLOCKED");
|
persistReservedList("tld-reserved5", "lol,FULLY_BLOCKED", "cat,FULLY_BLOCKED");
|
||||||
ReservedList rl6 =
|
ReservedList rl6 =
|
||||||
|
@ -169,7 +166,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetReservedListsByName() {
|
void testSetReservedListsByName() {
|
||||||
persistReservedList("tld-reserved24", "lol,FULLY_BLOCKED", "cat,FULLY_BLOCKED");
|
persistReservedList("tld-reserved24", "lol,FULLY_BLOCKED", "cat,FULLY_BLOCKED");
|
||||||
persistReservedList("tld-reserved25", "mit,FULLY_BLOCKED", "tim,FULLY_BLOCKED");
|
persistReservedList("tld-reserved25", "mit,FULLY_BLOCKED", "tim,FULLY_BLOCKED");
|
||||||
Registry r =
|
Registry r =
|
||||||
|
@ -184,7 +181,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetPremiumList() {
|
void testSetPremiumList() {
|
||||||
PremiumList pl2 = persistPremiumList("tld2", "lol,USD 50", "cat,USD 700");
|
PremiumList pl2 = persistPremiumList("tld2", "lol,USD 50", "cat,USD 700");
|
||||||
Registry registry = Registry.get("tld").asBuilder().setPremiumList(pl2).build();
|
Registry registry = Registry.get("tld").asBuilder().setPremiumList(pl2).build();
|
||||||
Key<PremiumList> plKey = registry.getPremiumList();
|
Key<PremiumList> plKey = registry.getPremiumList();
|
||||||
|
@ -194,20 +191,20 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSettingServerStatusChangeBillingCost() {
|
void testSettingServerStatusChangeBillingCost() {
|
||||||
Registry registry =
|
Registry registry =
|
||||||
Registry.get("tld").asBuilder().setServerStatusChangeBillingCost(Money.of(USD, 42)).build();
|
Registry.get("tld").asBuilder().setServerStatusChangeBillingCost(Money.of(USD, 42)).build();
|
||||||
assertThat(registry.getServerStatusChangeCost()).isEqualTo(Money.of(USD, 42));
|
assertThat(registry.getServerStatusChangeCost()).isEqualTo(Money.of(USD, 42));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSettingLordnUsername() {
|
void testSettingLordnUsername() {
|
||||||
Registry registry = Registry.get("tld").asBuilder().setLordnUsername("username").build();
|
Registry registry = Registry.get("tld").asBuilder().setLordnUsername("username").build();
|
||||||
assertThat(registry.getLordnUsername()).isEqualTo("username");
|
assertThat(registry.getLordnUsername()).isEqualTo("username");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSettingDnsWriters() {
|
void testSettingDnsWriters() {
|
||||||
Registry registry = Registry.get("tld");
|
Registry registry = Registry.get("tld");
|
||||||
assertThat(registry.getDnsWriters()).containsExactly(VoidDnsWriter.NAME);
|
assertThat(registry.getDnsWriters()).containsExactly(VoidDnsWriter.NAME);
|
||||||
registry = registry.asBuilder().setDnsWriters(ImmutableSet.of("baz", "bang")).build();
|
registry = registry.asBuilder().setDnsWriters(ImmutableSet.of("baz", "bang")).build();
|
||||||
|
@ -215,7 +212,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPdtLooksLikeGa() {
|
void testPdtLooksLikeGa() {
|
||||||
Registry registry =
|
Registry registry =
|
||||||
Registry.get("tld")
|
Registry.get("tld")
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
|
@ -225,7 +222,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTldStateTransitionTimes() {
|
void testTldStateTransitionTimes() {
|
||||||
Registry registry =
|
Registry registry =
|
||||||
Registry.get("tld")
|
Registry.get("tld")
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
|
@ -260,7 +257,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testQuietPeriodCanAppearMultipleTimesAnywhere() {
|
void testQuietPeriodCanAppearMultipleTimesAnywhere() {
|
||||||
Registry.get("tld")
|
Registry.get("tld")
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
.setTldStateTransitions(
|
.setTldStateTransitions(
|
||||||
|
@ -275,7 +272,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRenewBillingCostTransitionTimes() {
|
void testRenewBillingCostTransitionTimes() {
|
||||||
Registry registry =
|
Registry registry =
|
||||||
Registry.get("tld")
|
Registry.get("tld")
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
|
@ -314,7 +311,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRenewBillingCostNoTransitions() {
|
void testRenewBillingCostNoTransitions() {
|
||||||
Registry registry = Registry.get("tld");
|
Registry registry = Registry.get("tld");
|
||||||
// The default value of 11 is set in createTld().
|
// The default value of 11 is set in createTld().
|
||||||
assertThat(registry.getStandardRenewCost(START_OF_TIME)).isEqualTo(Money.of(USD, 11));
|
assertThat(registry.getStandardRenewCost(START_OF_TIME)).isEqualTo(Money.of(USD, 11));
|
||||||
|
@ -327,21 +324,21 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_tldNeverSet() {
|
void testFailure_tldNeverSet() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(IllegalArgumentException.class, () -> new Registry.Builder().build());
|
assertThrows(IllegalArgumentException.class, () -> new Registry.Builder().build());
|
||||||
assertThat(thrown).hasMessageThat().contains("No registry TLD specified");
|
assertThat(thrown).hasMessageThat().contains("No registry TLD specified");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_setTldStr_null() {
|
void testFailure_setTldStr_null() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(IllegalArgumentException.class, () -> new Registry.Builder().setTldStr(null));
|
assertThrows(IllegalArgumentException.class, () -> new Registry.Builder().setTldStr(null));
|
||||||
assertThat(thrown).hasMessageThat().contains("TLD must not be null");
|
assertThat(thrown).hasMessageThat().contains("TLD must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_setTldStr_invalidTld() {
|
void testFailure_setTldStr_invalidTld() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class, () -> new Registry.Builder().setTldStr(".tld").build());
|
IllegalArgumentException.class, () -> new Registry.Builder().setTldStr(".tld").build());
|
||||||
|
@ -351,7 +348,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_setTldStr_nonCanonicalTld() {
|
void testFailure_setTldStr_nonCanonicalTld() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class, () -> new Registry.Builder().setTldStr("TLD").build());
|
IllegalArgumentException.class, () -> new Registry.Builder().setTldStr("TLD").build());
|
||||||
|
@ -361,7 +358,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_tldStatesOutOfOrder() {
|
void testFailure_tldStatesOutOfOrder() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
() ->
|
() ->
|
||||||
|
@ -375,7 +372,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_duplicateTldState() {
|
void testFailure_duplicateTldState() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
() ->
|
() ->
|
||||||
|
@ -389,7 +386,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_pricingEngineIsRequired() {
|
void testFailure_pricingEngineIsRequired() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -400,7 +397,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_negativeRenewBillingCostTransitionValue() {
|
void testFailure_negativeRenewBillingCostTransitionValue() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -413,7 +410,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_negativeCreateBillingCost() {
|
void testFailure_negativeCreateBillingCost() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -422,7 +419,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_negativeRestoreBillingCost() {
|
void testFailure_negativeRestoreBillingCost() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -431,7 +428,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_nonPositiveNumDnsPublishLocks() {
|
void testFailure_nonPositiveNumDnsPublishLocks() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -451,7 +448,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_negativeServerStatusChangeBillingCost() {
|
void testFailure_negativeServerStatusChangeBillingCost() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -463,7 +460,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_renewBillingCostTransitionValue_wrongCurrency() {
|
void testFailure_renewBillingCostTransitionValue_wrongCurrency() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -477,7 +474,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_createBillingCost_wrongCurrency() {
|
void testFailure_createBillingCost_wrongCurrency() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -486,7 +483,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_restoreBillingCost_wrongCurrency() {
|
void testFailure_restoreBillingCost_wrongCurrency() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -495,7 +492,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_serverStatusChangeBillingCost_wrongCurrency() {
|
void testFailure_serverStatusChangeBillingCost_wrongCurrency() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -508,13 +505,13 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEapFee_undefined() {
|
void testEapFee_undefined() {
|
||||||
assertThat(Registry.get("tld").getEapFeeFor(fakeClock.nowUtc()).getCost())
|
assertThat(Registry.get("tld").getEapFeeFor(fakeClock.nowUtc()).getCost())
|
||||||
.isEqualTo(BigDecimal.ZERO.setScale(2, ROUND_UNNECESSARY));
|
.isEqualTo(BigDecimal.ZERO.setScale(2, ROUND_UNNECESSARY));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEapFee_specified() {
|
void testEapFee_specified() {
|
||||||
DateTime a = fakeClock.nowUtc().minusDays(1);
|
DateTime a = fakeClock.nowUtc().minusDays(1);
|
||||||
DateTime b = fakeClock.nowUtc().plusDays(1);
|
DateTime b = fakeClock.nowUtc().plusDays(1);
|
||||||
Registry registry =
|
Registry registry =
|
||||||
|
@ -536,7 +533,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_eapFee_wrongCurrency() {
|
void testFailure_eapFee_wrongCurrency() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -549,7 +546,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_roidSuffixTooLong() {
|
void testFailure_roidSuffixTooLong() {
|
||||||
IllegalArgumentException e =
|
IllegalArgumentException e =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -558,14 +555,14 @@ public class RegistryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_roidSuffixNotUppercased() {
|
void testFailure_roidSuffixNotUppercased() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
() -> Registry.get("tld").asBuilder().setRoidSuffix("abcd"));
|
() -> Registry.get("tld").asBuilder().setRoidSuffix("abcd"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_roidSuffixContainsInvalidCharacters() {
|
void testFailure_roidSuffixContainsInvalidCharacters() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
() -> Registry.get("tld").asBuilder().setRoidSuffix("ABC-DEF"));
|
() -> Registry.get("tld").asBuilder().setRoidSuffix("ABC-DEF"));
|
||||||
|
|
|
@ -51,29 +51,26 @@ import google.registry.testing.AppEngineRule;
|
||||||
import google.registry.testing.TestCacheRule;
|
import google.registry.testing.TestCacheRule;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.joda.money.Money;
|
import org.joda.money.Money;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link PremiumListUtils}. */
|
/** Unit tests for {@link PremiumListUtils}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class PremiumListUtilsTest {
|
public class PremiumListUtilsTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
// Set long persist times on caches so they can be tested (cache times default to 0 in tests).
|
// Set long persist times on caches so they can be tested (cache times default to 0 in tests).
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final TestCacheRule testCacheRule =
|
public final TestCacheRule testCacheRule =
|
||||||
new TestCacheRule.Builder()
|
new TestCacheRule.Builder()
|
||||||
.withPremiumListsCache(standardDays(1))
|
.withPremiumListsCache(standardDays(1))
|
||||||
.withPremiumListEntriesCache(standardDays(1))
|
.withPremiumListEntriesCache(standardDays(1))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
// createTld() overwrites the premium list, so call it before persisting pl.
|
// createTld() overwrites the premium list, so call it before persisting pl.
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
PremiumList pl =
|
PremiumList pl =
|
||||||
|
@ -101,7 +98,7 @@ public class PremiumListUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetPremiumPrice_returnsNoPriceWhenNoPremiumListConfigured() {
|
void testGetPremiumPrice_returnsNoPriceWhenNoPremiumListConfigured() {
|
||||||
createTld("ghost");
|
createTld("ghost");
|
||||||
persistResource(
|
persistResource(
|
||||||
new Registry.Builder()
|
new Registry.Builder()
|
||||||
|
@ -116,7 +113,7 @@ public class PremiumListUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetPremiumPrice_throwsExceptionWhenNonExistentPremiumListConfigured() {
|
void testGetPremiumPrice_throwsExceptionWhenNonExistentPremiumListConfigured() {
|
||||||
deletePremiumList(PremiumList.getUncached("tld").get());
|
deletePremiumList(PremiumList.getUncached("tld").get());
|
||||||
IllegalStateException thrown =
|
IllegalStateException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
|
@ -125,7 +122,7 @@ public class PremiumListUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSave_largeNumberOfEntries_succeeds() {
|
void testSave_largeNumberOfEntries_succeeds() {
|
||||||
PremiumList premiumList = persistHumongousPremiumList("tld", 2500);
|
PremiumList premiumList = persistHumongousPremiumList("tld", 2500);
|
||||||
assertThat(loadPremiumListEntries(premiumList)).hasSize(2500);
|
assertThat(loadPremiumListEntries(premiumList)).hasSize(2500);
|
||||||
assertThat(getPremiumPrice("7", Registry.get("tld"))).hasValue(Money.parse("USD 100"));
|
assertThat(getPremiumPrice("7", Registry.get("tld"))).hasValue(Money.parse("USD 100"));
|
||||||
|
@ -133,7 +130,7 @@ public class PremiumListUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSave_updateTime_isUpdatedOnEverySave() {
|
void testSave_updateTime_isUpdatedOnEverySave() {
|
||||||
PremiumList pl =
|
PremiumList pl =
|
||||||
savePremiumListAndEntries(
|
savePremiumListAndEntries(
|
||||||
new PremiumList.Builder().setName("tld3").build(), ImmutableList.of("slime,USD 10"));
|
new PremiumList.Builder().setName("tld3").build(), ImmutableList.of("slime,USD 10"));
|
||||||
|
@ -145,20 +142,20 @@ public class PremiumListUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSave_creationTime_onlyUpdatedOnFirstCreation() {
|
void testSave_creationTime_onlyUpdatedOnFirstCreation() {
|
||||||
PremiumList pl = persistPremiumList("tld3", "sludge,JPY 1000");
|
PremiumList pl = persistPremiumList("tld3", "sludge,JPY 1000");
|
||||||
PremiumList newPl = savePremiumListAndEntries(pl, ImmutableList.of("sleighbells,CHF 2000"));
|
PremiumList newPl = savePremiumListAndEntries(pl, ImmutableList.of("sleighbells,CHF 2000"));
|
||||||
assertThat(newPl.creationTime).isEqualTo(pl.creationTime);
|
assertThat(newPl.creationTime).isEqualTo(pl.creationTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExists() {
|
void testExists() {
|
||||||
assertThat(doesPremiumListExist("tld")).isTrue();
|
assertThat(doesPremiumListExist("tld")).isTrue();
|
||||||
assertThat(doesPremiumListExist("nonExistentPremiumList")).isFalse();
|
assertThat(doesPremiumListExist("nonExistentPremiumList")).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetPremiumPrice_comesFromBloomFilter() throws Exception {
|
void testGetPremiumPrice_comesFromBloomFilter() throws Exception {
|
||||||
PremiumList pl = PremiumList.getCached("tld").get();
|
PremiumList pl = PremiumList.getCached("tld").get();
|
||||||
PremiumListEntry entry =
|
PremiumListEntry entry =
|
||||||
persistResource(
|
persistResource(
|
||||||
|
@ -179,7 +176,7 @@ public class PremiumListUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetPremiumPrice_cachedSecondTime() {
|
void testGetPremiumPrice_cachedSecondTime() {
|
||||||
assertThat(getPremiumPrice("rich", Registry.get("tld"))).hasValue(Money.parse("USD 1999"));
|
assertThat(getPremiumPrice("rich", Registry.get("tld"))).hasValue(Money.parse("USD 1999"));
|
||||||
assertThat(getPremiumPrice("rich", Registry.get("tld"))).hasValue(Money.parse("USD 1999"));
|
assertThat(getPremiumPrice("rich", Registry.get("tld"))).hasValue(Money.parse("USD 1999"));
|
||||||
assertThat(premiumListChecks)
|
assertThat(premiumListChecks)
|
||||||
|
@ -197,7 +194,7 @@ public class PremiumListUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetPremiumPrice_bloomFilterFalsePositive() {
|
void testGetPremiumPrice_bloomFilterFalsePositive() {
|
||||||
// Remove one of the premium list entries from behind the Bloom filter's back.
|
// Remove one of the premium list entries from behind the Bloom filter's back.
|
||||||
tm()
|
tm()
|
||||||
.transactNew(
|
.transactNew(
|
||||||
|
@ -229,7 +226,7 @@ public class PremiumListUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSave_removedPremiumListEntries_areNoLongerInDatastore() {
|
void testSave_removedPremiumListEntries_areNoLongerInDatastore() {
|
||||||
Registry registry = Registry.get("tld");
|
Registry registry = Registry.get("tld");
|
||||||
PremiumList pl = persistPremiumList("tld", "genius,USD 10", "dolt,JPY 1000");
|
PremiumList pl = persistPremiumList("tld", "genius,USD 10", "dolt,JPY 1000");
|
||||||
assertThat(getPremiumPrice("genius", registry)).hasValue(Money.parse("USD 10"));
|
assertThat(getPremiumPrice("genius", registry)).hasValue(Money.parse("USD 10"));
|
||||||
|
@ -262,14 +259,14 @@ public class PremiumListUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetPremiumPrice_allLabelsAreNonPremium_whenNotInList() {
|
void testGetPremiumPrice_allLabelsAreNonPremium_whenNotInList() {
|
||||||
assertThat(getPremiumPrice("blah", Registry.get("tld"))).isEmpty();
|
assertThat(getPremiumPrice("blah", Registry.get("tld"))).isEmpty();
|
||||||
assertThat(getPremiumPrice("slinge", Registry.get("tld"))).isEmpty();
|
assertThat(getPremiumPrice("slinge", Registry.get("tld"))).isEmpty();
|
||||||
assertMetricOutcomeCount(2, BLOOM_FILTER_NEGATIVE);
|
assertMetricOutcomeCount(2, BLOOM_FILTER_NEGATIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSave_simple() {
|
void testSave_simple() {
|
||||||
PremiumList pl =
|
PremiumList pl =
|
||||||
savePremiumListAndEntries(
|
savePremiumListAndEntries(
|
||||||
new PremiumList.Builder().setName("tld2").build(),
|
new PremiumList.Builder().setName("tld2").build(),
|
||||||
|
@ -301,7 +298,7 @@ public class PremiumListUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_saveAndUpdateEntriesTwice() {
|
void test_saveAndUpdateEntriesTwice() {
|
||||||
PremiumList pl =
|
PremiumList pl =
|
||||||
savePremiumListAndEntries(
|
savePremiumListAndEntries(
|
||||||
new PremiumList.Builder().setName("pl").build(), ImmutableList.of("test,USD 1"));
|
new PremiumList.Builder().setName("pl").build(), ImmutableList.of("test,USD 1"));
|
||||||
|
@ -319,7 +316,7 @@ public class PremiumListUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_savePremiumListAndEntries_clearsCache() {
|
void test_savePremiumListAndEntries_clearsCache() {
|
||||||
assertThat(PremiumList.cachePremiumLists.getIfPresent("tld")).isNull();
|
assertThat(PremiumList.cachePremiumLists.getIfPresent("tld")).isNull();
|
||||||
PremiumList pl = PremiumList.getCached("tld").get();
|
PremiumList pl = PremiumList.getCached("tld").get();
|
||||||
assertThat(PremiumList.cachePremiumLists.getIfPresent("tld")).isEqualTo(pl);
|
assertThat(PremiumList.cachePremiumLists.getIfPresent("tld")).isEqualTo(pl);
|
||||||
|
@ -329,7 +326,7 @@ public class PremiumListUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDelete() {
|
void testDelete() {
|
||||||
persistPremiumList("gtld1", "trombone,USD 10");
|
persistPremiumList("gtld1", "trombone,USD 10");
|
||||||
assertThat(PremiumList.getUncached("gtld1")).isPresent();
|
assertThat(PremiumList.getUncached("gtld1")).isPresent();
|
||||||
Key<PremiumListRevision> parent = PremiumList.getUncached("gtld1").get().getRevisionKey();
|
Key<PremiumListRevision> parent = PremiumList.getUncached("gtld1").get().getRevisionKey();
|
||||||
|
@ -339,7 +336,7 @@ public class PremiumListUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDelete_largeNumberOfEntries_succeeds() {
|
void testDelete_largeNumberOfEntries_succeeds() {
|
||||||
persistHumongousPremiumList("ginormous", 2500);
|
persistHumongousPremiumList("ginormous", 2500);
|
||||||
deletePremiumList(PremiumList.getUncached("ginormous").get());
|
deletePremiumList(PremiumList.getUncached("ginormous").get());
|
||||||
assertThat(PremiumList.getUncached("ginormous")).isEmpty();
|
assertThat(PremiumList.getUncached("ginormous")).isEmpty();
|
||||||
|
|
|
@ -26,16 +26,16 @@ import google.registry.model.EntityTestCase;
|
||||||
import google.registry.model.domain.Period;
|
import google.registry.model.domain.Period;
|
||||||
import google.registry.model.eppcommon.Trid;
|
import google.registry.model.eppcommon.Trid;
|
||||||
import google.registry.model.reporting.DomainTransactionRecord.TransactionReportField;
|
import google.registry.model.reporting.DomainTransactionRecord.TransactionReportField;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/** Unit tests for {@link HistoryEntry}. */
|
/** Unit tests for {@link HistoryEntry}. */
|
||||||
public class HistoryEntryTest extends EntityTestCase {
|
class HistoryEntryTest extends EntityTestCase {
|
||||||
|
|
||||||
HistoryEntry historyEntry;
|
private HistoryEntry historyEntry;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
createTld("foobar");
|
createTld("foobar");
|
||||||
DomainTransactionRecord transactionRecord =
|
DomainTransactionRecord transactionRecord =
|
||||||
new DomainTransactionRecord.Builder()
|
new DomainTransactionRecord.Builder()
|
||||||
|
@ -64,12 +64,12 @@ public class HistoryEntryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPersistence() {
|
void testPersistence() {
|
||||||
assertThat(ofy().load().entity(historyEntry).now()).isEqualTo(historyEntry);
|
assertThat(ofy().load().entity(historyEntry).now()).isEqualTo(historyEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIndexing() throws Exception {
|
void testIndexing() throws Exception {
|
||||||
verifyIndexing(historyEntry, "modificationTime", "clientId");
|
verifyIndexing(historyEntry, "modificationTime", "clientId");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,12 +46,12 @@ public class Spec11ThreatMatchTest extends EntityTestCase {
|
||||||
private HostResource host;
|
private HostResource host;
|
||||||
private ContactResource registrantContact;
|
private ContactResource registrantContact;
|
||||||
|
|
||||||
public Spec11ThreatMatchTest() {
|
Spec11ThreatMatchTest() {
|
||||||
super(JpaEntityCoverageCheck.ENABLED);
|
super(JpaEntityCoverageCheck.ENABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
VKey<HostResource> hostVKey = VKey.createSql(HostResource.class, "host");
|
VKey<HostResource> hostVKey = VKey.createSql(HostResource.class, "host");
|
||||||
VKey<ContactResource> registrantContactVKey =
|
VKey<ContactResource> registrantContactVKey =
|
||||||
VKey.createSql(ContactResource.class, "contact_id");
|
VKey.createSql(ContactResource.class, "contact_id");
|
||||||
|
@ -100,7 +100,7 @@ public class Spec11ThreatMatchTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPersistence() {
|
void testPersistence() {
|
||||||
saveRegistrar(REGISTRAR_ID);
|
saveRegistrar(REGISTRAR_ID);
|
||||||
|
|
||||||
jpaTm()
|
jpaTm()
|
||||||
|
@ -119,7 +119,7 @@ public class Spec11ThreatMatchTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testThreatForeignKeyConstraints() {
|
void testThreatForeignKeyConstraints() {
|
||||||
assertThrowForeignKeyViolation(
|
assertThrowForeignKeyViolation(
|
||||||
() -> {
|
() -> {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
|
@ -149,7 +149,7 @@ public class Spec11ThreatMatchTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_threatsWithInvalidFields() {
|
void testFailure_threatsWithInvalidFields() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class, () -> threat.asBuilder().setRegistrarId(null).build());
|
IllegalArgumentException.class, () -> threat.asBuilder().setRegistrarId(null).build());
|
||||||
|
|
||||||
|
|
|
@ -21,22 +21,20 @@ import static org.junit.Assert.assertThrows;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
@RunWith(JUnit4.class)
|
/** Unit tests for {@link google.registry.model.server.KmsSecretRevision}. */
|
||||||
public class KmsSecretRevisionTest {
|
public class KmsSecretRevisionTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
private KmsSecretRevision secretRevision;
|
private KmsSecretRevision secretRevision;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void beforeEach() {
|
||||||
secretRevision =
|
secretRevision =
|
||||||
persistResource(
|
persistResource(
|
||||||
new KmsSecretRevision.Builder()
|
new KmsSecretRevision.Builder()
|
||||||
|
@ -47,7 +45,7 @@ public class KmsSecretRevisionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_setEncryptedValue_tooLong_throwsException() {
|
void test_setEncryptedValue_tooLong_throwsException() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -63,7 +61,7 @@ public class KmsSecretRevisionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPersistence() {
|
void testPersistence() {
|
||||||
assertThat(ofy().load().entity(secretRevision).now()).isEqualTo(secretRevision);
|
assertThat(ofy().load().entity(secretRevision).now()).isEqualTo(secretRevision);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,23 +19,20 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||||
|
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class KmsSecretTest {
|
public class KmsSecretTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
private KmsSecret secret;
|
private KmsSecret secret;
|
||||||
private KmsSecretRevision secretRevision;
|
private KmsSecretRevision secretRevision;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
secretRevision =
|
secretRevision =
|
||||||
persistResource(
|
persistResource(
|
||||||
new KmsSecretRevision.Builder()
|
new KmsSecretRevision.Builder()
|
||||||
|
@ -48,7 +45,7 @@ public class KmsSecretTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPersistence() {
|
void testPersistence() {
|
||||||
assertThat(ofy().load().entity(secret).now()).isEqualTo(secret);
|
assertThat(ofy().load().entity(secret).now()).isEqualTo(secret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,15 +34,12 @@ import google.registry.testing.InjectRule;
|
||||||
import google.registry.util.RequestStatusChecker;
|
import google.registry.util.RequestStatusChecker;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
import org.junit.After;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link Lock}. */
|
/** Unit tests for {@link Lock}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class LockTest {
|
public class LockTest {
|
||||||
|
|
||||||
private static final String RESOURCE_NAME = "foo";
|
private static final String RESOURCE_NAME = "foo";
|
||||||
|
@ -53,11 +50,11 @@ public class LockTest {
|
||||||
|
|
||||||
private LockMetrics origLockMetrics;
|
private LockMetrics origLockMetrics;
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine =
|
public final AppEngineRule appEngine =
|
||||||
AppEngineRule.builder().withDatastoreAndCloudSql().withClock(clock).build();
|
AppEngineRule.builder().withDatastoreAndCloudSql().withClock(clock).build();
|
||||||
|
|
||||||
@Rule public final InjectRule inject = new InjectRule();
|
@RegisterExtension public final InjectRule inject = new InjectRule();
|
||||||
|
|
||||||
private Optional<Lock> acquire(String tld, Duration leaseLength, LockState expectedLockState) {
|
private Optional<Lock> acquire(String tld, Duration leaseLength, LockState expectedLockState) {
|
||||||
Lock.lockMetrics = mock(LockMetrics.class);
|
Lock.lockMetrics = mock(LockMetrics.class);
|
||||||
|
@ -77,7 +74,8 @@ public class LockTest {
|
||||||
Lock.lockMetrics = null;
|
Lock.lockMetrics = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before public void setUp() {
|
@BeforeEach
|
||||||
|
void beforeEach() {
|
||||||
inject.setStaticField(Ofy.class, "clock", clock);
|
inject.setStaticField(Ofy.class, "clock", clock);
|
||||||
origLockMetrics = Lock.lockMetrics;
|
origLockMetrics = Lock.lockMetrics;
|
||||||
Lock.lockMetrics = null;
|
Lock.lockMetrics = null;
|
||||||
|
@ -85,13 +83,13 @@ public class LockTest {
|
||||||
when(requestStatusChecker.isRunning("current-request-id")).thenReturn(true);
|
when(requestStatusChecker.isRunning("current-request-id")).thenReturn(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterEach
|
||||||
public void restoreLockMetric() {
|
void restoreLockMetric() {
|
||||||
Lock.lockMetrics = origLockMetrics;
|
Lock.lockMetrics = origLockMetrics;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReleasedExplicitly() {
|
void testReleasedExplicitly() {
|
||||||
Optional<Lock> lock = acquire("", ONE_DAY, FREE);
|
Optional<Lock> lock = acquire("", ONE_DAY, FREE);
|
||||||
assertThat(lock).isPresent();
|
assertThat(lock).isPresent();
|
||||||
// We can't get it again at the same time.
|
// We can't get it again at the same time.
|
||||||
|
@ -103,7 +101,7 @@ public class LockTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReleasedAfterTimeout() {
|
void testReleasedAfterTimeout() {
|
||||||
assertThat(acquire("", TWO_MILLIS, FREE)).isPresent();
|
assertThat(acquire("", TWO_MILLIS, FREE)).isPresent();
|
||||||
// We can't get it again at the same time.
|
// We can't get it again at the same time.
|
||||||
assertThat(acquire("", TWO_MILLIS, IN_USE)).isEmpty();
|
assertThat(acquire("", TWO_MILLIS, IN_USE)).isEmpty();
|
||||||
|
@ -116,7 +114,7 @@ public class LockTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReleasedAfterRequestFinish() {
|
void testReleasedAfterRequestFinish() {
|
||||||
assertThat(acquire("", ONE_DAY, FREE)).isPresent();
|
assertThat(acquire("", ONE_DAY, FREE)).isPresent();
|
||||||
// We can't get it again while request is active
|
// We can't get it again while request is active
|
||||||
assertThat(acquire("", ONE_DAY, IN_USE)).isEmpty();
|
assertThat(acquire("", ONE_DAY, IN_USE)).isEmpty();
|
||||||
|
@ -126,7 +124,7 @@ public class LockTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTldsAreIndependent() {
|
void testTldsAreIndependent() {
|
||||||
Optional<Lock> lockA = acquire("a", ONE_DAY, FREE);
|
Optional<Lock> lockA = acquire("a", ONE_DAY, FREE);
|
||||||
assertThat(lockA).isPresent();
|
assertThat(lockA).isPresent();
|
||||||
// For a different tld we can still get a lock with the same name.
|
// For a different tld we can still get a lock with the same name.
|
||||||
|
@ -141,7 +139,7 @@ public class LockTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_emptyResourceName() {
|
void testFailure_emptyResourceName() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
|
|
@ -20,32 +20,30 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||||
import google.registry.model.ofy.RequestCapturingAsyncDatastoreService;
|
import google.registry.model.ofy.RequestCapturingAsyncDatastoreService;
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link ServerSecret}. */
|
/** Unit tests for {@link ServerSecret}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class ServerSecretTest {
|
public class ServerSecretTest {
|
||||||
@Rule
|
|
||||||
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void beforeEach() {
|
||||||
ServerSecret.resetCache();
|
ServerSecret.resetCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGet_bootstrapping_savesSecretToDatastore() {
|
void testGet_bootstrapping_savesSecretToDatastore() {
|
||||||
ServerSecret secret = ServerSecret.get();
|
ServerSecret secret = ServerSecret.get();
|
||||||
assertThat(secret).isNotNull();
|
assertThat(secret).isNotNull();
|
||||||
assertThat(ofy().load().entity(new ServerSecret()).now()).isEqualTo(secret);
|
assertThat(ofy().load().entity(new ServerSecret()).now()).isEqualTo(secret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGet_existingSecret_returned() {
|
void testGet_existingSecret_returned() {
|
||||||
ServerSecret secret = ServerSecret.create(123, 456);
|
ServerSecret secret = ServerSecret.create(123, 456);
|
||||||
ofy().saveWithoutBackup().entity(secret).now();
|
ofy().saveWithoutBackup().entity(secret).now();
|
||||||
assertThat(ServerSecret.get()).isEqualTo(secret);
|
assertThat(ServerSecret.get()).isEqualTo(secret);
|
||||||
|
@ -53,7 +51,7 @@ public class ServerSecretTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGet_cachedSecret_returnedWithoutDatastoreRead() {
|
void testGet_cachedSecret_returnedWithoutDatastoreRead() {
|
||||||
int numInitialReads = RequestCapturingAsyncDatastoreService.getReads().size();
|
int numInitialReads = RequestCapturingAsyncDatastoreService.getReads().size();
|
||||||
ServerSecret secret = ServerSecret.get();
|
ServerSecret secret = ServerSecret.get();
|
||||||
int numReads = RequestCapturingAsyncDatastoreService.getReads().size();
|
int numReads = RequestCapturingAsyncDatastoreService.getReads().size();
|
||||||
|
@ -63,14 +61,14 @@ public class ServerSecretTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAsUuid() {
|
void testAsUuid() {
|
||||||
UUID uuid = ServerSecret.create(123, 456).asUuid();
|
UUID uuid = ServerSecret.create(123, 456).asUuid();
|
||||||
assertThat(uuid.getMostSignificantBits()).isEqualTo(123);
|
assertThat(uuid.getMostSignificantBits()).isEqualTo(123);
|
||||||
assertThat(uuid.getLeastSignificantBits()).isEqualTo(456);
|
assertThat(uuid.getLeastSignificantBits()).isEqualTo(456);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAsBytes() {
|
void testAsBytes() {
|
||||||
byte[] bytes = ServerSecret.create(123, 0x456).asBytes();
|
byte[] bytes = ServerSecret.create(123, 0x456).asBytes();
|
||||||
assertThat(bytes)
|
assertThat(bytes)
|
||||||
.isEqualTo(new byte[] {0, 0, 0, 0, 0, 0, 0, 123, 0, 0, 0, 0, 0, 0, 0x4, 0x56});
|
.isEqualTo(new byte[] {0, 0, 0, 0, 0, 0, 0, 123, 0, 0, 0, 0, 0, 0, 0x4, 0x56});
|
||||||
|
|
|
@ -16,16 +16,13 @@ package google.registry.model.smd;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link IssuerInfo}. */
|
/** Unit tests for {@link IssuerInfo}. */
|
||||||
@RunWith(JUnit4.class)
|
final class IssuerInfoTest {
|
||||||
public final class IssuerInfoTest {
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeadCodeWeDontWantToDelete() {
|
void testDeadCodeWeDontWantToDelete() {
|
||||||
IssuerInfo mp = new IssuerInfo();
|
IssuerInfo mp = new IssuerInfo();
|
||||||
mp.issuerId = "sloth";
|
mp.issuerId = "sloth";
|
||||||
assertThat(mp.getIssuerId()).isEqualTo("sloth");
|
assertThat(mp.getIssuerId()).isEqualTo("sloth");
|
||||||
|
|
|
@ -26,22 +26,19 @@ import com.google.common.collect.ImmutableMap;
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import google.registry.testing.FakeClock;
|
import google.registry.testing.FakeClock;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link SignedMarkRevocationList}. */
|
/** Unit tests for {@link SignedMarkRevocationList}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class SignedMarkRevocationListTest {
|
public class SignedMarkRevocationListTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
private final FakeClock clock = new FakeClock(DateTime.parse("2013-01-01T00:00:00Z"));
|
private final FakeClock clock = new FakeClock(DateTime.parse("2013-01-01T00:00:00Z"));
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnshardedSaveFails() {
|
void testUnshardedSaveFails() {
|
||||||
// Our @Entity's @OnSave method will notice that this shouldn't be saved.
|
// Our @Entity's @OnSave method will notice that this shouldn't be saved.
|
||||||
assertThrows(
|
assertThrows(
|
||||||
SignedMarkRevocationList.UnshardedSaveException.class,
|
SignedMarkRevocationList.UnshardedSaveException.class,
|
||||||
|
@ -59,14 +56,14 @@ public class SignedMarkRevocationListTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmpty() {
|
void testEmpty() {
|
||||||
// When Datastore is empty, it should give us an empty thing.
|
// When Datastore is empty, it should give us an empty thing.
|
||||||
assertThat(SignedMarkRevocationList.get())
|
assertThat(SignedMarkRevocationList.get())
|
||||||
.isEqualTo(SignedMarkRevocationList.create(START_OF_TIME, ImmutableMap.of()));
|
.isEqualTo(SignedMarkRevocationList.create(START_OF_TIME, ImmutableMap.of()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSharding2() {
|
void testSharding2() {
|
||||||
final int rows = SHARD_SIZE + 1;
|
final int rows = SHARD_SIZE + 1;
|
||||||
// Create a SignedMarkRevocationList that will need 2 shards to save.
|
// Create a SignedMarkRevocationList that will need 2 shards to save.
|
||||||
ImmutableMap.Builder<String, DateTime> revokes = new ImmutableMap.Builder<>();
|
ImmutableMap.Builder<String, DateTime> revokes = new ImmutableMap.Builder<>();
|
||||||
|
@ -82,7 +79,7 @@ public class SignedMarkRevocationListTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSharding4() {
|
void testSharding4() {
|
||||||
final int rows = SHARD_SIZE * 3 + 1;
|
final int rows = SHARD_SIZE * 3 + 1;
|
||||||
// Create a SignedMarkRevocationList that will need 4 shards to save.
|
// Create a SignedMarkRevocationList that will need 4 shards to save.
|
||||||
ImmutableMap.Builder<String, DateTime> revokes = new ImmutableMap.Builder<>();
|
ImmutableMap.Builder<String, DateTime> revokes = new ImmutableMap.Builder<>();
|
||||||
|
@ -109,7 +106,7 @@ public class SignedMarkRevocationListTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_isSmdRevoked_null() {
|
void test_isSmdRevoked_null() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
NullPointerException.class,
|
NullPointerException.class,
|
||||||
() ->
|
() ->
|
||||||
|
@ -118,7 +115,7 @@ public class SignedMarkRevocationListTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_isSmdRevoked_garbage() {
|
void test_isSmdRevoked_garbage() {
|
||||||
SignedMarkRevocationList smdrl = createSaveGetHelper(SHARD_SIZE + 1);
|
SignedMarkRevocationList smdrl = createSaveGetHelper(SHARD_SIZE + 1);
|
||||||
assertThat(smdrl.getCreationTime()).isEqualTo(clock.nowUtc());
|
assertThat(smdrl.getCreationTime()).isEqualTo(clock.nowUtc());
|
||||||
assertThat(smdrl.isSmdRevoked("rofl", clock.nowUtc())).isFalse();
|
assertThat(smdrl.isSmdRevoked("rofl", clock.nowUtc())).isFalse();
|
||||||
|
@ -126,7 +123,7 @@ public class SignedMarkRevocationListTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_getCreationTime() {
|
void test_getCreationTime() {
|
||||||
clock.setTo(DateTime.parse("2000-01-01T00:00:00Z"));
|
clock.setTo(DateTime.parse("2000-01-01T00:00:00Z"));
|
||||||
createSaveGetHelper(5);
|
createSaveGetHelper(5);
|
||||||
assertThat(SignedMarkRevocationList.get().getCreationTime())
|
assertThat(SignedMarkRevocationList.get().getCreationTime())
|
||||||
|
@ -137,7 +134,7 @@ public class SignedMarkRevocationListTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_isSmdRevoked_present() {
|
void test_isSmdRevoked_present() {
|
||||||
final int rows = SHARD_SIZE + 1;
|
final int rows = SHARD_SIZE + 1;
|
||||||
SignedMarkRevocationList smdrl = createSaveGetHelper(rows);
|
SignedMarkRevocationList smdrl = createSaveGetHelper(rows);
|
||||||
assertThat(smdrl.isSmdRevoked("0", clock.nowUtc())).isTrue();
|
assertThat(smdrl.isSmdRevoked("0", clock.nowUtc())).isTrue();
|
||||||
|
@ -146,7 +143,7 @@ public class SignedMarkRevocationListTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_isSmdRevoked_future() {
|
void test_isSmdRevoked_future() {
|
||||||
final int rows = SHARD_SIZE;
|
final int rows = SHARD_SIZE;
|
||||||
SignedMarkRevocationList smdrl = createSaveGetHelper(rows);
|
SignedMarkRevocationList smdrl = createSaveGetHelper(rows);
|
||||||
clock.advanceOneMilli();
|
clock.advanceOneMilli();
|
||||||
|
@ -156,7 +153,7 @@ public class SignedMarkRevocationListTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_isSmdRevoked_past() {
|
void test_isSmdRevoked_past() {
|
||||||
final int rows = SHARD_SIZE;
|
final int rows = SHARD_SIZE;
|
||||||
SignedMarkRevocationList smdrl = createSaveGetHelper(rows);
|
SignedMarkRevocationList smdrl = createSaveGetHelper(rows);
|
||||||
clock.setTo(clock.nowUtc().minusMillis(1));
|
clock.setTo(clock.nowUtc().minusMillis(1));
|
||||||
|
|
|
@ -31,22 +31,19 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link ClaimsListShard}. */
|
/** Unit tests for {@link ClaimsListShard}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class ClaimsListShardTest {
|
public class ClaimsListShardTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
private final int shardSize = 10;
|
private final int shardSize = 10;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_unshardedSaveFails() {
|
void test_unshardedSaveFails() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
UnshardedSaveException.class,
|
UnshardedSaveException.class,
|
||||||
() ->
|
() ->
|
||||||
|
@ -63,13 +60,13 @@ public class ClaimsListShardTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGet_safelyLoadsEmptyClaimsList_whenNoShardsExist() {
|
void testGet_safelyLoadsEmptyClaimsList_whenNoShardsExist() {
|
||||||
assertThat(ClaimsListShard.get().labelsToKeys).isEmpty();
|
assertThat(ClaimsListShard.get().labelsToKeys).isEmpty();
|
||||||
assertThat(ClaimsListShard.get().creationTime).isEqualTo(START_OF_TIME);
|
assertThat(ClaimsListShard.get().creationTime).isEqualTo(START_OF_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_savesAndGets_withSharding() {
|
void test_savesAndGets_withSharding() {
|
||||||
// Create a ClaimsList that will need 4 shards to save.
|
// Create a ClaimsList that will need 4 shards to save.
|
||||||
Map<String, String> labelsToKeys = new HashMap<>();
|
Map<String, String> labelsToKeys = new HashMap<>();
|
||||||
for (int i = 0; i <= shardSize * 3; i++) {
|
for (int i = 0; i <= shardSize * 3; i++) {
|
||||||
|
|
|
@ -17,20 +17,17 @@ package google.registry.model.tmch;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link TmchCrl}. */
|
/** Unit tests for {@link TmchCrl}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class TmchCrlTest {
|
public class TmchCrlTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess() {
|
void testSuccess() {
|
||||||
assertThat(TmchCrl.get()).isNull();
|
assertThat(TmchCrl.get()).isNull();
|
||||||
TmchCrl.set("lolcat", "http://lol.cat");
|
TmchCrl.set("lolcat", "http://lol.cat");
|
||||||
assertThat(TmchCrl.get().getCrl()).isEqualTo("lolcat");
|
assertThat(TmchCrl.get().getCrl()).isEqualTo("lolcat");
|
||||||
|
|
|
@ -25,17 +25,14 @@ import google.registry.model.poll.PollMessage;
|
||||||
import google.registry.persistence.VKey;
|
import google.registry.persistence.VKey;
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link TransferData}. */
|
/** Unit tests for {@link TransferData}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class TransferDataTest {
|
public class TransferDataTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
private final DateTime now = DateTime.now(UTC);
|
private final DateTime now = DateTime.now(UTC);
|
||||||
|
@ -46,8 +43,8 @@ public class TransferDataTest {
|
||||||
private VKey<PollMessage.Autorenew> autorenewPollMessageKey;
|
private VKey<PollMessage.Autorenew> autorenewPollMessageKey;
|
||||||
private VKey<PollMessage.OneTime> otherServerApprovePollMessageKey;
|
private VKey<PollMessage.OneTime> otherServerApprovePollMessageKey;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void beforeEach() {
|
||||||
transferBillingEventKey = VKey.create(BillingEvent.OneTime.class, 12345);
|
transferBillingEventKey = VKey.create(BillingEvent.OneTime.class, 12345);
|
||||||
otherServerApproveBillingEventKey = VKey.create(BillingEvent.Cancellation.class, 2468);
|
otherServerApproveBillingEventKey = VKey.create(BillingEvent.Cancellation.class, 2468);
|
||||||
recurringBillingEventKey = VKey.create(BillingEvent.Recurring.class, 13579);
|
recurringBillingEventKey = VKey.create(BillingEvent.Recurring.class, 13579);
|
||||||
|
@ -56,7 +53,7 @@ public class TransferDataTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_copyConstantFieldsToBuilder() {
|
void test_copyConstantFieldsToBuilder() {
|
||||||
DomainTransferData constantTransferData =
|
DomainTransferData constantTransferData =
|
||||||
new DomainTransferData.Builder()
|
new DomainTransferData.Builder()
|
||||||
.setTransferRequestTrid(Trid.create("server-trid", "client-trid"))
|
.setTransferRequestTrid(Trid.create("server-trid", "client-trid"))
|
||||||
|
|
|
@ -32,14 +32,11 @@ import google.registry.testing.FakeClock;
|
||||||
import google.registry.testing.InjectRule;
|
import google.registry.testing.InjectRule;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link CommitLogRevisionsTranslatorFactory}. */
|
/** Unit tests for {@link CommitLogRevisionsTranslatorFactory}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class CommitLogRevisionsTranslatorFactoryTest {
|
public class CommitLogRevisionsTranslatorFactoryTest {
|
||||||
|
|
||||||
private static final DateTime START_TIME = DateTime.parse("2000-01-01TZ");
|
private static final DateTime START_TIME = DateTime.parse("2000-01-01TZ");
|
||||||
|
@ -49,20 +46,19 @@ public class CommitLogRevisionsTranslatorFactoryTest {
|
||||||
ImmutableSortedMap<DateTime, Key<CommitLogManifest>> revisions = ImmutableSortedMap.of();
|
ImmutableSortedMap<DateTime, Key<CommitLogManifest>> revisions = ImmutableSortedMap.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine =
|
public final AppEngineRule appEngine =
|
||||||
AppEngineRule.builder()
|
AppEngineRule.builder()
|
||||||
.withDatastoreAndCloudSql()
|
.withDatastoreAndCloudSql()
|
||||||
.withOfyTestEntities(TestObject.class)
|
.withOfyTestEntities(TestObject.class)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension public final InjectRule inject = new InjectRule();
|
||||||
public final InjectRule inject = new InjectRule();
|
|
||||||
|
|
||||||
private final FakeClock clock = new FakeClock(START_TIME);
|
private final FakeClock clock = new FakeClock(START_TIME);
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void beforeEach() {
|
||||||
inject.setStaticField(Ofy.class, "clock", clock);
|
inject.setStaticField(Ofy.class, "clock", clock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +72,7 @@ public class CommitLogRevisionsTranslatorFactoryTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSave_doesNotMutateOriginalResource() {
|
void testSave_doesNotMutateOriginalResource() {
|
||||||
TestObject object = new TestObject();
|
TestObject object = new TestObject();
|
||||||
save(object);
|
save(object);
|
||||||
assertThat(object.revisions).isEmpty();
|
assertThat(object.revisions).isEmpty();
|
||||||
|
@ -84,7 +80,7 @@ public class CommitLogRevisionsTranslatorFactoryTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSave_translatorAddsKeyToCommitLogToField() {
|
void testSave_translatorAddsKeyToCommitLogToField() {
|
||||||
save(new TestObject());
|
save(new TestObject());
|
||||||
TestObject object = reload();
|
TestObject object = reload();
|
||||||
assertThat(object.revisions).hasSize(1);
|
assertThat(object.revisions).hasSize(1);
|
||||||
|
@ -94,7 +90,7 @@ public class CommitLogRevisionsTranslatorFactoryTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSave_twoVersionsOnOneDay_keyToLastCommitLogsGetsStored() {
|
void testSave_twoVersionsOnOneDay_keyToLastCommitLogsGetsStored() {
|
||||||
save(new TestObject());
|
save(new TestObject());
|
||||||
clock.advanceBy(standardHours(1));
|
clock.advanceBy(standardHours(1));
|
||||||
save(reload());
|
save(reload());
|
||||||
|
@ -104,7 +100,7 @@ public class CommitLogRevisionsTranslatorFactoryTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSave_twoVersionsOnTwoDays_keyToBothCommitLogsGetsStored() {
|
void testSave_twoVersionsOnTwoDays_keyToBothCommitLogsGetsStored() {
|
||||||
save(new TestObject());
|
save(new TestObject());
|
||||||
clock.advanceBy(standardDays(1));
|
clock.advanceBy(standardDays(1));
|
||||||
save(reload());
|
save(reload());
|
||||||
|
@ -115,7 +111,7 @@ public class CommitLogRevisionsTranslatorFactoryTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSave_moreThanThirtyDays_truncatedAtThirtyPlusOne() {
|
void testSave_moreThanThirtyDays_truncatedAtThirtyPlusOne() {
|
||||||
save(new TestObject());
|
save(new TestObject());
|
||||||
for (int i = 0; i < 35; i++) {
|
for (int i = 0; i < 35; i++) {
|
||||||
clock.advanceBy(standardDays(1));
|
clock.advanceBy(standardDays(1));
|
||||||
|
@ -127,7 +123,7 @@ public class CommitLogRevisionsTranslatorFactoryTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSave_moreThanThirtySparse_keepsOneEntryPrecedingThirtyDays() {
|
void testSave_moreThanThirtySparse_keepsOneEntryPrecedingThirtyDays() {
|
||||||
save(new TestObject());
|
save(new TestObject());
|
||||||
assertThat(reload().revisions).hasSize(1);
|
assertThat(reload().revisions).hasSize(1);
|
||||||
assertThat(reload().revisions.firstKey()).isEqualTo(clock.nowUtc().minusDays(0));
|
assertThat(reload().revisions.firstKey()).isEqualTo(clock.nowUtc().minusDays(0));
|
||||||
|
@ -147,7 +143,7 @@ public class CommitLogRevisionsTranslatorFactoryTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testRawEntityLayout() {
|
void testRawEntityLayout() {
|
||||||
save(new TestObject());
|
save(new TestObject());
|
||||||
clock.advanceBy(standardDays(1));
|
clock.advanceBy(standardDays(1));
|
||||||
com.google.appengine.api.datastore.Entity entity =
|
com.google.appengine.api.datastore.Entity entity =
|
||||||
|
@ -161,12 +157,12 @@ public class CommitLogRevisionsTranslatorFactoryTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoad_neverSaved_returnsNull() {
|
void testLoad_neverSaved_returnsNull() {
|
||||||
assertThat(ofy().load().entity(new TestObject()).now()).isNull();
|
assertThat(ofy().load().entity(new TestObject()).now()).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoad_missingRevisionRawProperties_createsEmptyObject() {
|
void testLoad_missingRevisionRawProperties_createsEmptyObject() {
|
||||||
com.google.appengine.api.datastore.Entity entity =
|
com.google.appengine.api.datastore.Entity entity =
|
||||||
tm().transactNewReadOnly(() -> ofy().save().toEntity(new TestObject()));
|
tm().transactNewReadOnly(() -> ofy().save().toEntity(new TestObject()));
|
||||||
entity.removeProperty("revisions.key");
|
entity.removeProperty("revisions.key");
|
||||||
|
|
|
@ -31,20 +31,17 @@ import google.registry.model.host.HostInfoData;
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import google.registry.testing.EppLoader;
|
import google.registry.testing.EppLoader;
|
||||||
import google.registry.xml.ValidationMode;
|
import google.registry.xml.ValidationMode;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class StatusValueAdapterTest {
|
public class StatusValueAdapterTest {
|
||||||
|
|
||||||
// Needed to create HostResources.
|
// Needed to create HostResources.
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public AppEngineRule appEngine = new AppEngineRule.Builder().withDatastoreAndCloudSql().build();
|
public AppEngineRule appEngine = new AppEngineRule.Builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMarshalling() throws Exception {
|
void testMarshalling() throws Exception {
|
||||||
// Mangle the status value through marshalling by stuffing it in a host info response and then
|
// Mangle the status value through marshalling by stuffing it in a host info response and then
|
||||||
// ripping it out of the marshalled xml. Use lenient marshalling so we can omit other fields.
|
// ripping it out of the marshalled xml. Use lenient marshalling so we can omit other fields.
|
||||||
String marshalled = new String(
|
String marshalled = new String(
|
||||||
|
@ -77,19 +74,19 @@ public class StatusValueAdapterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoOptionalFields_unmarshallsWithoutException() throws Exception {
|
void testNoOptionalFields_unmarshallsWithoutException() throws Exception {
|
||||||
assertThat(unmarshal("<host:status s=\"clientUpdateProhibited\"/>"))
|
assertThat(unmarshal("<host:status s=\"clientUpdateProhibited\"/>"))
|
||||||
.isEqualTo(StatusValue.CLIENT_UPDATE_PROHIBITED);
|
.isEqualTo(StatusValue.CLIENT_UPDATE_PROHIBITED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHasLang_unmarshallsWithoutException() throws Exception {
|
void testHasLang_unmarshallsWithoutException() throws Exception {
|
||||||
assertThat(unmarshal("<host:status s=\"clientUpdateProhibited\" lang=\"fr\"/>"))
|
assertThat(unmarshal("<host:status s=\"clientUpdateProhibited\" lang=\"fr\"/>"))
|
||||||
.isEqualTo(StatusValue.CLIENT_UPDATE_PROHIBITED);
|
.isEqualTo(StatusValue.CLIENT_UPDATE_PROHIBITED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHasMessage_unmarshallsWithoutException() throws Exception {
|
void testHasMessage_unmarshallsWithoutException() throws Exception {
|
||||||
assertThat(unmarshal("<host:status s=\"clientUpdateProhibited\">my message</host:status>"))
|
assertThat(unmarshal("<host:status s=\"clientUpdateProhibited\">my message</host:status>"))
|
||||||
.isEqualTo(StatusValue.CLIENT_UPDATE_PROHIBITED);
|
.isEqualTo(StatusValue.CLIENT_UPDATE_PROHIBITED);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class VKeyTranslatorFactoryTest {
|
||||||
@RegisterExtension
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
|
||||||
|
|
||||||
public VKeyTranslatorFactoryTest() {}
|
VKeyTranslatorFactoryTest() {}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testEntityWithFlatKey() {
|
void testEntityWithFlatKey() {
|
||||||
|
|
|
@ -22,7 +22,9 @@ import google.registry.model.registry.label.PremiumList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
import org.junit.rules.ExternalResource;
|
import org.junit.jupiter.api.extension.AfterEachCallback;
|
||||||
|
import org.junit.jupiter.api.extension.BeforeEachCallback;
|
||||||
|
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up caches with desired data expiry for testing and restores their default configurations
|
* Sets up caches with desired data expiry for testing and restores their default configurations
|
||||||
|
@ -31,7 +33,7 @@ import org.junit.rules.ExternalResource;
|
||||||
* <p>This rule is necessary because many caches in the system are singleton and referenced through
|
* <p>This rule is necessary because many caches in the system are singleton and referenced through
|
||||||
* static fields.
|
* static fields.
|
||||||
*/
|
*/
|
||||||
public class TestCacheRule extends ExternalResource {
|
public class TestCacheRule implements BeforeEachCallback, AfterEachCallback {
|
||||||
|
|
||||||
private final ImmutableList<TestCacheHandler> cacheHandlers;
|
private final ImmutableList<TestCacheHandler> cacheHandlers;
|
||||||
|
|
||||||
|
@ -40,12 +42,12 @@ public class TestCacheRule extends ExternalResource {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void before() {
|
public void beforeEach(ExtensionContext context) {
|
||||||
cacheHandlers.forEach(TestCacheHandler::before);
|
cacheHandlers.forEach(TestCacheHandler::before);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void after() {
|
public void afterEach(ExtensionContext context) {
|
||||||
cacheHandlers.forEach(TestCacheHandler::after);
|
cacheHandlers.forEach(TestCacheHandler::after);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,23 +66,20 @@ import java.io.Reader;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Ignore;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link WhoisAction}. */
|
/** Unit tests for {@link WhoisAction}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class WhoisActionTest {
|
public class WhoisActionTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
@Rule public final InjectRule inject = new InjectRule();
|
@RegisterExtension public final InjectRule inject = new InjectRule();
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final TestCacheRule testCacheRule =
|
public final TestCacheRule testCacheRule =
|
||||||
new TestCacheRule.Builder()
|
new TestCacheRule.Builder()
|
||||||
.withEppResourceCache(Duration.standardDays(1))
|
.withEppResourceCache(Duration.standardDays(1))
|
||||||
|
@ -107,15 +104,15 @@ public class WhoisActionTest {
|
||||||
return whoisAction;
|
return whoisAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
clock = new FakeClock(DateTime.parse("2009-06-29T20:13:00Z"));
|
clock = new FakeClock(DateTime.parse("2009-06-29T20:13:00Z"));
|
||||||
createTlds("lol", "xn--q9jyb4c", "1.test");
|
createTlds("lol", "xn--q9jyb4c", "1.test");
|
||||||
inject.setStaticField(Ofy.class, "clock", clock);
|
inject.setStaticField(Ofy.class, "clock", clock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_badRequest_stillSends200() {
|
void testRun_badRequest_stillSends200() {
|
||||||
newWhoisAction("\r\n").run();
|
newWhoisAction("\r\n").run();
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_no_command.txt"));
|
assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_no_command.txt"));
|
||||||
|
@ -133,7 +130,7 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_domainQuery_works() {
|
void testRun_domainQuery_works() {
|
||||||
Registrar registrar =
|
Registrar registrar =
|
||||||
persistResource(makeRegistrar("evilregistrar", "Yes Virginia", ACTIVE));
|
persistResource(makeRegistrar("evilregistrar", "Yes Virginia", ACTIVE));
|
||||||
persistResource(makeDomainBaseWithRegistrar(registrar));
|
persistResource(makeDomainBaseWithRegistrar(registrar));
|
||||||
|
@ -144,7 +141,7 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_domainQuery_usesCache() {
|
void testRun_domainQuery_usesCache() {
|
||||||
Registrar registrar =
|
Registrar registrar =
|
||||||
persistResource(makeRegistrar("evilregistrar", "Yes Virginia", ACTIVE));
|
persistResource(makeRegistrar("evilregistrar", "Yes Virginia", ACTIVE));
|
||||||
persistResource(makeDomainBaseWithRegistrar(registrar));
|
persistResource(makeDomainBaseWithRegistrar(registrar));
|
||||||
|
@ -172,7 +169,7 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_domainAfterTransfer_hasUpdatedEppTimeAndClientId() {
|
void testRun_domainAfterTransfer_hasUpdatedEppTimeAndClientId() {
|
||||||
Registrar registrar = persistResource(makeRegistrar("TheRegistrar", "Yes Virginia", ACTIVE));
|
Registrar registrar = persistResource(makeRegistrar("TheRegistrar", "Yes Virginia", ACTIVE));
|
||||||
persistResource(
|
persistResource(
|
||||||
makeDomainBaseWithRegistrar(registrar)
|
makeDomainBaseWithRegistrar(registrar)
|
||||||
|
@ -197,7 +194,7 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_idnDomain_works() {
|
void testRun_idnDomain_works() {
|
||||||
Registrar registrar = persistResource(makeRegistrar(
|
Registrar registrar = persistResource(makeRegistrar(
|
||||||
"evilregistrar", "Yes Virginia", ACTIVE));
|
"evilregistrar", "Yes Virginia", ACTIVE));
|
||||||
persistResource(makeDomainBase(
|
persistResource(makeDomainBase(
|
||||||
|
@ -215,7 +212,7 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_punycodeDomain_works() {
|
void testRun_punycodeDomain_works() {
|
||||||
Registrar registrar = persistResource(makeRegistrar(
|
Registrar registrar = persistResource(makeRegistrar(
|
||||||
"evilregistrar", "Yes Virginia", ACTIVE));
|
"evilregistrar", "Yes Virginia", ACTIVE));
|
||||||
persistResource(makeDomainBase(
|
persistResource(makeDomainBase(
|
||||||
|
@ -233,14 +230,14 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_domainNotFound_returns200OkAndPlainTextResponse() {
|
void testRun_domainNotFound_returns200OkAndPlainTextResponse() {
|
||||||
newWhoisAction("domain cat.lol\r\n").run();
|
newWhoisAction("domain cat.lol\r\n").run();
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_domain_not_found.txt"));
|
assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_domain_not_found.txt"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_domainNotFound_usesCache() {
|
void testRun_domainNotFound_usesCache() {
|
||||||
// Populate the cache with the nonexistence of this domain.
|
// Populate the cache with the nonexistence of this domain.
|
||||||
assertThat(loadByForeignKeyCached(DomainBase.class, "cat.lol", clock.nowUtc())).isEmpty();
|
assertThat(loadByForeignKeyCached(DomainBase.class, "cat.lol", clock.nowUtc())).isEmpty();
|
||||||
// Add a new valid cat.lol domain that won't be found because the cache will be hit instead.
|
// Add a new valid cat.lol domain that won't be found because the cache will be hit instead.
|
||||||
|
@ -251,9 +248,9 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo (b/27378695): reenable or delete this test
|
// todo (b/27378695): reenable or delete this test
|
||||||
@Ignore
|
@Disabled
|
||||||
@Test
|
@Test
|
||||||
public void testRun_domainInTestTld_isConsideredNotFound() {
|
void testRun_domainInTestTld_isConsideredNotFound() {
|
||||||
persistResource(Registry.get("lol").asBuilder().setTldType(Registry.TldType.TEST).build());
|
persistResource(Registry.get("lol").asBuilder().setTldType(Registry.TldType.TEST).build());
|
||||||
Registrar registrar = persistResource(makeRegistrar(
|
Registrar registrar = persistResource(makeRegistrar(
|
||||||
"evilregistrar", "Yes Virginia", ACTIVE));
|
"evilregistrar", "Yes Virginia", ACTIVE));
|
||||||
|
@ -272,7 +269,7 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_domainFlaggedAsDeletedInDatastore_isConsideredNotFound() {
|
void testRun_domainFlaggedAsDeletedInDatastore_isConsideredNotFound() {
|
||||||
Registrar registrar;
|
Registrar registrar;
|
||||||
persistResource(makeDomainBase("cat.lol",
|
persistResource(makeDomainBase("cat.lol",
|
||||||
persistResource(
|
persistResource(
|
||||||
|
@ -293,11 +290,11 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a deleted domain and an active domain with the same label, and make sure only the
|
* Create a deleted domain and an active domain with the same label, and make sure only the active
|
||||||
* active one is returned.
|
* one is returned.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testRun_domainDeletedThenRecreated_isFound() {
|
void testRun_domainDeletedThenRecreated_isFound() {
|
||||||
Registrar registrar;
|
Registrar registrar;
|
||||||
DomainBase domain1 = persistResource(makeDomainBase("cat.lol",
|
DomainBase domain1 = persistResource(makeDomainBase("cat.lol",
|
||||||
persistResource(
|
persistResource(
|
||||||
|
@ -333,7 +330,7 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_nameserverQuery_works() {
|
void testRun_nameserverQuery_works() {
|
||||||
persistResource(loadRegistrar("TheRegistrar").asBuilder().setUrl("http://my.fake.url").build());
|
persistResource(loadRegistrar("TheRegistrar").asBuilder().setUrl("http://my.fake.url").build());
|
||||||
persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4"));
|
persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4"));
|
||||||
newWhoisAction("nameserver ns1.cat.lol\r\n").run();
|
newWhoisAction("nameserver ns1.cat.lol\r\n").run();
|
||||||
|
@ -342,7 +339,7 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_ipv6_displaysInCollapsedReadableFormat() {
|
void testRun_ipv6_displaysInCollapsedReadableFormat() {
|
||||||
persistResource(makeHostResource("ns1.cat.lol", "bad:f00d:cafe::15:beef"));
|
persistResource(makeHostResource("ns1.cat.lol", "bad:f00d:cafe::15:beef"));
|
||||||
newWhoisAction("nameserver ns1.cat.lol\r\n").run();
|
newWhoisAction("nameserver ns1.cat.lol\r\n").run();
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
@ -353,7 +350,7 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_idnNameserver_works() {
|
void testRun_idnNameserver_works() {
|
||||||
persistResource(makeHostResource("ns1.cat.みんな", "1.2.3.4"));
|
persistResource(makeHostResource("ns1.cat.みんな", "1.2.3.4"));
|
||||||
newWhoisAction("nameserver ns1.cat.みんな\r\n").run();
|
newWhoisAction("nameserver ns1.cat.みんな\r\n").run();
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
@ -362,7 +359,7 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_nameserver_usesCache() {
|
void testRun_nameserver_usesCache() {
|
||||||
persistResource(makeHostResource("ns1.cat.xn--q9jyb4c", "1.2.3.4"));
|
persistResource(makeHostResource("ns1.cat.xn--q9jyb4c", "1.2.3.4"));
|
||||||
// Populate the cache.
|
// Populate the cache.
|
||||||
HostResource host =
|
HostResource host =
|
||||||
|
@ -379,7 +376,7 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_punycodeNameserver_works() {
|
void testRun_punycodeNameserver_works() {
|
||||||
persistResource(makeHostResource("ns1.cat.みんな", "1.2.3.4"));
|
persistResource(makeHostResource("ns1.cat.みんな", "1.2.3.4"));
|
||||||
newWhoisAction("nameserver ns1.cat.xn--q9jyb4c\r\n").run();
|
newWhoisAction("nameserver ns1.cat.xn--q9jyb4c\r\n").run();
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
@ -388,7 +385,7 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_nameserverNotFound_returns200AndText() {
|
void testRun_nameserverNotFound_returns200AndText() {
|
||||||
persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4"));
|
persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4"));
|
||||||
newWhoisAction("nameserver ns1.cat.lulz\r\n").run();
|
newWhoisAction("nameserver ns1.cat.lulz\r\n").run();
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
@ -396,7 +393,7 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_nameserverFlaggedAsDeletedInDatastore_doesntGetLeaked() {
|
void testRun_nameserverFlaggedAsDeletedInDatastore_doesntGetLeaked() {
|
||||||
persistResource(
|
persistResource(
|
||||||
makeHostResource("ns1.cat.lol", "1.2.3.4").asBuilder()
|
makeHostResource("ns1.cat.lol", "1.2.3.4").asBuilder()
|
||||||
.setDeletionTime(clock.nowUtc().minusDays(1)).build());
|
.setDeletionTime(clock.nowUtc().minusDays(1)).build());
|
||||||
|
@ -406,7 +403,7 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_ipNameserverLookup_works() {
|
void testRun_ipNameserverLookup_works() {
|
||||||
persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4"));
|
persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4"));
|
||||||
newWhoisAction("nameserver 1.2.3.4").run();
|
newWhoisAction("nameserver 1.2.3.4").run();
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
@ -414,7 +411,7 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_ipMapsToMultipleNameservers_theyAllGetReturned() {
|
void testRun_ipMapsToMultipleNameservers_theyAllGetReturned() {
|
||||||
persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4"));
|
persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4"));
|
||||||
persistResource(makeHostResource("ns2.cat.lol", "1.2.3.4"));
|
persistResource(makeHostResource("ns2.cat.lol", "1.2.3.4"));
|
||||||
newWhoisAction("nameserver 1.2.3.4").run();
|
newWhoisAction("nameserver 1.2.3.4").run();
|
||||||
|
@ -424,7 +421,7 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_ipMapsToMultipleNameserverInDifferentTlds_showsThemAll() {
|
void testRun_ipMapsToMultipleNameserverInDifferentTlds_showsThemAll() {
|
||||||
persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4"));
|
persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4"));
|
||||||
persistResource(
|
persistResource(
|
||||||
makeHostResource("ns1.cat.xn--q9jyb4c", "1.2.3.4"));
|
makeHostResource("ns1.cat.xn--q9jyb4c", "1.2.3.4"));
|
||||||
|
@ -435,14 +432,14 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_ipNameserverEntityDoesNotExist_returns200NotFound() {
|
void testRun_ipNameserverEntityDoesNotExist_returns200NotFound() {
|
||||||
newWhoisAction("nameserver feed:a:bee::acab\r\n").run();
|
newWhoisAction("nameserver feed:a:bee::acab\r\n").run();
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_ip_not_found.txt"));
|
assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_ip_not_found.txt"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_ipMapsToNameserverUnderNonAuthoritativeTld_notFound() {
|
void testRun_ipMapsToNameserverUnderNonAuthoritativeTld_notFound() {
|
||||||
assertThat(getTlds()).doesNotContain("com");
|
assertThat(getTlds()).doesNotContain("com");
|
||||||
persistResource(makeHostResource("ns1.google.com", "1.2.3.4"));
|
persistResource(makeHostResource("ns1.google.com", "1.2.3.4"));
|
||||||
newWhoisAction("nameserver 1.2.3.4").run();
|
newWhoisAction("nameserver 1.2.3.4").run();
|
||||||
|
@ -451,7 +448,7 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_nameserverUnderNonAuthoritativeTld_notFound() {
|
void testRun_nameserverUnderNonAuthoritativeTld_notFound() {
|
||||||
assertThat(getTlds()).doesNotContain("com");
|
assertThat(getTlds()).doesNotContain("com");
|
||||||
persistResource(makeHostResource("ns1.google.com", "1.2.3.4"));
|
persistResource(makeHostResource("ns1.google.com", "1.2.3.4"));
|
||||||
newWhoisAction("nameserver ns1.google.com").run();
|
newWhoisAction("nameserver ns1.google.com").run();
|
||||||
|
@ -460,9 +457,9 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo (b/27378695): reenable or delete this test
|
// todo (b/27378695): reenable or delete this test
|
||||||
@Ignore
|
@Disabled
|
||||||
@Test
|
@Test
|
||||||
public void testRun_nameserverInTestTld_notFound() {
|
void testRun_nameserverInTestTld_notFound() {
|
||||||
persistResource(Registry.get("lol").asBuilder().setTldType(Registry.TldType.TEST).build());
|
persistResource(Registry.get("lol").asBuilder().setTldType(Registry.TldType.TEST).build());
|
||||||
persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4"));
|
persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4"));
|
||||||
newWhoisAction("nameserver ns1.cat.lol").run();
|
newWhoisAction("nameserver ns1.cat.lol").run();
|
||||||
|
@ -471,7 +468,7 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_registrarLookup_works() {
|
void testRun_registrarLookup_works() {
|
||||||
Registrar registrar = persistResource(
|
Registrar registrar = persistResource(
|
||||||
makeRegistrar("example", "Example Registrar, Inc.", ACTIVE));
|
makeRegistrar("example", "Example Registrar, Inc.", ACTIVE));
|
||||||
persistSimpleResources(makeRegistrarContacts(registrar));
|
persistSimpleResources(makeRegistrarContacts(registrar));
|
||||||
|
@ -482,7 +479,7 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_pdtRegistrarLookup_works() {
|
void testRun_pdtRegistrarLookup_works() {
|
||||||
Registrar registrar =
|
Registrar registrar =
|
||||||
persistResource(
|
persistResource(
|
||||||
makeRegistrar("example", "Example Registrar, Inc.", ACTIVE)
|
makeRegistrar("example", "Example Registrar, Inc.", ACTIVE)
|
||||||
|
@ -498,7 +495,7 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_registrarLookupInPendingState_returnsNotFound() {
|
void testRun_registrarLookupInPendingState_returnsNotFound() {
|
||||||
Registrar registrar = persistResource(
|
Registrar registrar = persistResource(
|
||||||
makeRegistrar("example", "Example Registrar, Inc.", Registrar.State.PENDING));
|
makeRegistrar("example", "Example Registrar, Inc.", Registrar.State.PENDING));
|
||||||
persistSimpleResources(makeRegistrarContacts(registrar));
|
persistSimpleResources(makeRegistrarContacts(registrar));
|
||||||
|
@ -508,7 +505,7 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_registrarLookupWithTestType_returnsNotFound() {
|
void testRun_registrarLookupWithTestType_returnsNotFound() {
|
||||||
Registrar registrar = persistResource(
|
Registrar registrar = persistResource(
|
||||||
makeRegistrar("example", "Example Registrar, Inc.", ACTIVE)
|
makeRegistrar("example", "Example Registrar, Inc.", ACTIVE)
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
|
@ -522,7 +519,7 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_multilevelDomain_isNotConsideredAHostname() {
|
void testRun_multilevelDomain_isNotConsideredAHostname() {
|
||||||
Registrar registrar =
|
Registrar registrar =
|
||||||
persistResource(makeRegistrar("example", "Example Registrar", ACTIVE));
|
persistResource(makeRegistrar("example", "Example Registrar", ACTIVE));
|
||||||
persistResource(makeDomainBase("cat.1.test",
|
persistResource(makeDomainBase("cat.1.test",
|
||||||
|
@ -540,7 +537,7 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_hostnameWithMultilevelTld_isStillConsideredHostname() {
|
void testRun_hostnameWithMultilevelTld_isStillConsideredHostname() {
|
||||||
persistResource(makeHostResource("ns1.cat.1.test", "1.2.3.4"));
|
persistResource(makeHostResource("ns1.cat.1.test", "1.2.3.4"));
|
||||||
newWhoisAction("nameserver ns1.cat.1.test\r\n").run();
|
newWhoisAction("nameserver ns1.cat.1.test\r\n").run();
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
@ -549,7 +546,7 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_metricsLoggedForSuccessfulCommand() {
|
void testRun_metricsLoggedForSuccessfulCommand() {
|
||||||
persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4"));
|
persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4"));
|
||||||
persistResource(makeHostResource("ns2.cat.lol", "1.2.3.4"));
|
persistResource(makeHostResource("ns2.cat.lol", "1.2.3.4"));
|
||||||
WhoisAction action = newWhoisAction("nameserver 1.2.3.4");
|
WhoisAction action = newWhoisAction("nameserver 1.2.3.4");
|
||||||
|
@ -565,7 +562,7 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_metricsLoggedForUnsuccessfulCommand() {
|
void testRun_metricsLoggedForUnsuccessfulCommand() {
|
||||||
WhoisAction action = newWhoisAction("domain cat.lol\r\n");
|
WhoisAction action = newWhoisAction("domain cat.lol\r\n");
|
||||||
action.whoisMetrics = mock(WhoisMetrics.class);
|
action.whoisMetrics = mock(WhoisMetrics.class);
|
||||||
action.run();
|
action.run();
|
||||||
|
@ -579,7 +576,7 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_metricsLoggedForInternalServerError() throws Exception {
|
void testRun_metricsLoggedForInternalServerError() throws Exception {
|
||||||
persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4"));
|
persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4"));
|
||||||
WhoisAction action = newWhoisAction("ns1.cat.lol");
|
WhoisAction action = newWhoisAction("ns1.cat.lol");
|
||||||
action.whoisReader = mock(WhoisReader.class);
|
action.whoisReader = mock(WhoisReader.class);
|
||||||
|
@ -598,7 +595,7 @@ public class WhoisActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_retryOnTransientFailure() throws Exception {
|
void testRun_retryOnTransientFailure() throws Exception {
|
||||||
persistResource(loadRegistrar("TheRegistrar").asBuilder().setUrl("http://my.fake.url").build());
|
persistResource(loadRegistrar("TheRegistrar").asBuilder().setUrl("http://my.fake.url").build());
|
||||||
persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4"));
|
persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4"));
|
||||||
WhoisAction action = newWhoisAction("ns1.cat.lol");
|
WhoisAction action = newWhoisAction("ns1.cat.lol");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue