mirror of
https://github.com/google/nomulus.git
synced 2025-07-25 12:08:36 +02:00
Ignore class visibility in EntityTest (#1389)
This commit is contained in:
parent
1fd179d041
commit
d9fea56f4c
3 changed files with 20 additions and 10 deletions
|
@ -24,6 +24,7 @@ import google.registry.model.billing.BillingEvent;
|
||||||
import google.registry.model.billing.BillingEvent.Recurring;
|
import google.registry.model.billing.BillingEvent.Recurring;
|
||||||
import google.registry.model.domain.rgp.GracePeriodStatus;
|
import google.registry.model.domain.rgp.GracePeriodStatus;
|
||||||
import google.registry.model.replay.DatastoreAndSqlEntity;
|
import google.registry.model.replay.DatastoreAndSqlEntity;
|
||||||
|
import google.registry.model.replay.SqlOnlyEntity;
|
||||||
import google.registry.persistence.BillingVKey.BillingEventVKey;
|
import google.registry.persistence.BillingVKey.BillingEventVKey;
|
||||||
import google.registry.persistence.BillingVKey.BillingRecurrenceVKey;
|
import google.registry.persistence.BillingVKey.BillingRecurrenceVKey;
|
||||||
import google.registry.persistence.VKey;
|
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 class to represent a historic {@link GracePeriod}. */
|
||||||
@Entity(name = "GracePeriodHistory")
|
@Entity(name = "GracePeriodHistory")
|
||||||
@Table(indexes = @Index(columnList = "domainRepoId"))
|
@Table(indexes = @Index(columnList = "domainRepoId"))
|
||||||
static class GracePeriodHistory extends GracePeriodBase {
|
static class GracePeriodHistory extends GracePeriodBase implements SqlOnlyEntity {
|
||||||
@Id Long gracePeriodHistoryRevisionId;
|
@Id Long gracePeriodHistoryRevisionId;
|
||||||
|
|
||||||
/** ID for the associated {@link DomainHistory} entity. */
|
/** ID for the associated {@link DomainHistory} entity. */
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
package google.registry.model.tmch;
|
package google.registry.model.tmch;
|
||||||
|
|
||||||
import google.registry.model.ImmutableObject;
|
import google.registry.model.ImmutableObject;
|
||||||
import google.registry.model.replay.NonReplicatedEntity;
|
import google.registry.model.replay.SqlOnlyEntity;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
@ -30,7 +30,7 @@ import javax.persistence.Id;
|
||||||
* work.
|
* work.
|
||||||
*/
|
*/
|
||||||
@Entity(name = "ClaimsEntry")
|
@Entity(name = "ClaimsEntry")
|
||||||
class ClaimsEntry extends ImmutableObject implements NonReplicatedEntity, Serializable {
|
class ClaimsEntry extends ImmutableObject implements SqlOnlyEntity, Serializable {
|
||||||
@Id private Long revisionId;
|
@Id private Long revisionId;
|
||||||
@Id private String domainLabel;
|
@Id private String domainLabel;
|
||||||
|
|
||||||
|
|
|
@ -51,8 +51,7 @@ public class EntityTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testSqlEntityPersistence() {
|
void testSqlEntityPersistence() {
|
||||||
try (ScanResult scanResult =
|
try (ScanResult scanResult = scanForClasses()) {
|
||||||
new ClassGraph().enableAnnotationInfo().whitelistPackages("google.registry").scan()) {
|
|
||||||
// All javax.persistence entities must implement SqlEntity and vice versa
|
// All javax.persistence entities must implement SqlEntity and vice versa
|
||||||
ImmutableSet<String> javaxPersistenceClasses =
|
ImmutableSet<String> javaxPersistenceClasses =
|
||||||
getAllClassesWithAnnotation(scanResult, javax.persistence.Entity.class.getName());
|
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.
|
// 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
|
// This means that the relevant classes must have non-composite Objectify keys or must have a
|
||||||
// createVKey method
|
// createVKey method
|
||||||
try (ScanResult scanResult =
|
try (ScanResult scanResult = scanForClasses()) {
|
||||||
new ClassGraph().enableAnnotationInfo().whitelistPackages("google.registry").scan()) {
|
|
||||||
ImmutableSet<Class<?>> datastoreEntityClasses =
|
ImmutableSet<Class<?>> datastoreEntityClasses =
|
||||||
getClasses(scanResult.getClassesImplementing(DatastoreEntity.class.getName()));
|
getClasses(scanResult.getClassesImplementing(DatastoreEntity.class.getName()));
|
||||||
// some classes aren't converted so they aren't relevant
|
// some classes aren't converted so they aren't relevant
|
||||||
|
@ -126,9 +124,12 @@ public class EntityTest {
|
||||||
return classInfoList.stream()
|
return classInfoList.stream()
|
||||||
.filter(ClassInfo::isStandardClass)
|
.filter(ClassInfo::isStandardClass)
|
||||||
.map(ClassInfo::loadClass)
|
.map(ClassInfo::loadClass)
|
||||||
.filter(clazz -> !clazz.isAnnotationPresent(EntityForTesting.class))
|
.filter(
|
||||||
.filter(clazz -> !clazz.isAnnotationPresent(Embed.class))
|
clazz ->
|
||||||
.filter(clazz -> !NON_CONVERTED_CLASSES.contains(clazz))
|
!clazz.isAnnotationPresent(EntityForTesting.class)
|
||||||
|
&& !clazz.isAnnotationPresent(Embed.class)
|
||||||
|
&& !NON_CONVERTED_CLASSES.contains(clazz)
|
||||||
|
&& !clazz.getName().contains("Test"))
|
||||||
.collect(toImmutableSet());
|
.collect(toImmutableSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,6 +137,14 @@ public class EntityTest {
|
||||||
return getClasses(classInfoList).stream().map(Class::getName).collect(toImmutableSet());
|
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}. */
|
/** Entities that are solely used for testing, to avoid scanning them in {@link EntityTest}. */
|
||||||
@Target(ElementType.TYPE)
|
@Target(ElementType.TYPE)
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue