From d9fea56f4c7cfa88279f834ee20918d875239253 Mon Sep 17 00:00:00 2001 From: gbrodman Date: Fri, 15 Oct 2021 17:08:51 -0400 Subject: [PATCH] Ignore class visibility in EntityTest (#1389) --- .../registry/model/domain/GracePeriod.java | 3 ++- .../registry/model/tmch/ClaimsEntry.java | 4 ++-- .../registry/model/replay/EntityTest.java | 23 +++++++++++++------ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/google/registry/model/domain/GracePeriod.java b/core/src/main/java/google/registry/model/domain/GracePeriod.java index 0d68683e0..8bd7fb903 100644 --- a/core/src/main/java/google/registry/model/domain/GracePeriod.java +++ b/core/src/main/java/google/registry/model/domain/GracePeriod.java @@ -24,6 +24,7 @@ import google.registry.model.billing.BillingEvent; import google.registry.model.billing.BillingEvent.Recurring; import google.registry.model.domain.rgp.GracePeriodStatus; import google.registry.model.replay.DatastoreAndSqlEntity; +import google.registry.model.replay.SqlOnlyEntity; import google.registry.persistence.BillingVKey.BillingEventVKey; import google.registry.persistence.BillingVKey.BillingRecurrenceVKey; import google.registry.persistence.VKey; @@ -202,7 +203,7 @@ public class GracePeriod extends GracePeriodBase implements DatastoreAndSqlEntit /** Entity class to represent a historic {@link GracePeriod}. */ @Entity(name = "GracePeriodHistory") @Table(indexes = @Index(columnList = "domainRepoId")) - static class GracePeriodHistory extends GracePeriodBase { + static class GracePeriodHistory extends GracePeriodBase implements SqlOnlyEntity { @Id Long gracePeriodHistoryRevisionId; /** ID for the associated {@link DomainHistory} entity. */ diff --git a/core/src/main/java/google/registry/model/tmch/ClaimsEntry.java b/core/src/main/java/google/registry/model/tmch/ClaimsEntry.java index 5c44494fa..cc45933a0 100644 --- a/core/src/main/java/google/registry/model/tmch/ClaimsEntry.java +++ b/core/src/main/java/google/registry/model/tmch/ClaimsEntry.java @@ -15,7 +15,7 @@ package google.registry.model.tmch; import google.registry.model.ImmutableObject; -import google.registry.model.replay.NonReplicatedEntity; +import google.registry.model.replay.SqlOnlyEntity; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; @@ -30,7 +30,7 @@ import javax.persistence.Id; * work. */ @Entity(name = "ClaimsEntry") -class ClaimsEntry extends ImmutableObject implements NonReplicatedEntity, Serializable { +class ClaimsEntry extends ImmutableObject implements SqlOnlyEntity, Serializable { @Id private Long revisionId; @Id private String domainLabel; diff --git a/core/src/test/java/google/registry/model/replay/EntityTest.java b/core/src/test/java/google/registry/model/replay/EntityTest.java index 81414e2b6..ebb4022a8 100644 --- a/core/src/test/java/google/registry/model/replay/EntityTest.java +++ b/core/src/test/java/google/registry/model/replay/EntityTest.java @@ -51,8 +51,7 @@ public class EntityTest { @Test void testSqlEntityPersistence() { - try (ScanResult scanResult = - new ClassGraph().enableAnnotationInfo().whitelistPackages("google.registry").scan()) { + try (ScanResult scanResult = scanForClasses()) { // All javax.persistence entities must implement SqlEntity and vice versa ImmutableSet javaxPersistenceClasses = getAllClassesWithAnnotation(scanResult, javax.persistence.Entity.class.getName()); @@ -75,8 +74,7 @@ public class EntityTest { // For replication, we need to be able to convert from Key -> VKey for the relevant classes. // This means that the relevant classes must have non-composite Objectify keys or must have a // createVKey method - try (ScanResult scanResult = - new ClassGraph().enableAnnotationInfo().whitelistPackages("google.registry").scan()) { + try (ScanResult scanResult = scanForClasses()) { ImmutableSet> datastoreEntityClasses = getClasses(scanResult.getClassesImplementing(DatastoreEntity.class.getName())); // some classes aren't converted so they aren't relevant @@ -126,9 +124,12 @@ public class EntityTest { return classInfoList.stream() .filter(ClassInfo::isStandardClass) .map(ClassInfo::loadClass) - .filter(clazz -> !clazz.isAnnotationPresent(EntityForTesting.class)) - .filter(clazz -> !clazz.isAnnotationPresent(Embed.class)) - .filter(clazz -> !NON_CONVERTED_CLASSES.contains(clazz)) + .filter( + clazz -> + !clazz.isAnnotationPresent(EntityForTesting.class) + && !clazz.isAnnotationPresent(Embed.class) + && !NON_CONVERTED_CLASSES.contains(clazz) + && !clazz.getName().contains("Test")) .collect(toImmutableSet()); } @@ -136,6 +137,14 @@ public class EntityTest { return getClasses(classInfoList).stream().map(Class::getName).collect(toImmutableSet()); } + private ScanResult scanForClasses() { + return new ClassGraph() + .enableAnnotationInfo() + .ignoreClassVisibility() + .acceptPackages("google.registry") + .scan(); + } + /** Entities that are solely used for testing, to avoid scanning them in {@link EntityTest}. */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME)