diff --git a/core/src/test/java/google/registry/persistence/transaction/JpaEntityCoverage.java b/core/src/test/java/google/registry/persistence/transaction/JpaEntityCoverage.java index b9efe9dd7..4cc5f4771 100644 --- a/core/src/test/java/google/registry/persistence/transaction/JpaEntityCoverage.java +++ b/core/src/test/java/google/registry/persistence/transaction/JpaEntityCoverage.java @@ -14,8 +14,10 @@ package google.registry.persistence.transaction; +import static com.google.common.base.Preconditions.checkState; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; +import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; @@ -33,16 +35,10 @@ import org.junit.rules.ExternalResource; */ public class JpaEntityCoverage extends ExternalResource { - // TODO(weiminyu): remove this set after pr/438 is submitted. The pr is expected to fix the - // problems with these entities and allow them to be tested. + // TODO(weiminyu): update this set when entities written to Cloud SQL and tests are added. private static final ImmutableSet IGNORE_ENTITIES = ImmutableSet.of( - "DomainBase", - "BaseTransferObject", - "DelegationSignerData", - "DesignatedContact", - "GracePeriod", - "RegistrarContact"); + "DelegationSignerData", "DesignatedContact", "GracePeriod", "RegistrarContact"); private static final ImmutableSet ALL_JPA_ENTITIES = PersistenceXmlUtility.getManagedClasses().stream() @@ -107,10 +103,19 @@ public class JpaEntityCoverage extends ExternalResource { jpaTm() .getEntityManager() .createQuery( - String.format("SELECT e FROM %s e", entityType.getSimpleName()), + String.format("SELECT e FROM %s e", getJpaEntityName(entityType)), entityType) .setMaxResults(1) .getResultList()); return !result.isEmpty() && entityType.isInstance(result.get(0)); } + + private static String getJpaEntityName(Class entityType) { + Entity entityAnnotation = (Entity) entityType.getAnnotation(Entity.class); + checkState( + entityAnnotation != null, "Unexpected non-entity type %s", entityType.getSimpleName()); + return Strings.isNullOrEmpty(entityAnnotation.name()) + ? entityType.getSimpleName() + : entityAnnotation.name(); + } } diff --git a/core/src/test/java/google/registry/schema/integration/SqlIntegrationTestSuite.java b/core/src/test/java/google/registry/schema/integration/SqlIntegrationTestSuite.java index edddc864e..e9453742a 100644 --- a/core/src/test/java/google/registry/schema/integration/SqlIntegrationTestSuite.java +++ b/core/src/test/java/google/registry/schema/integration/SqlIntegrationTestSuite.java @@ -15,9 +15,8 @@ package google.registry.schema.integration; import com.google.common.truth.Expect; -import google.registry.model.common.CursorTest; +import google.registry.model.domain.DomainBaseSqlTest; import google.registry.model.registry.RegistryLockDaoTest; -import google.registry.model.server.LockTest; import google.registry.persistence.transaction.JpaEntityCoverage; import google.registry.schema.cursor.CursorDaoTest; import google.registry.schema.registrar.RegistrarDaoTest; @@ -25,18 +24,6 @@ import google.registry.schema.server.LockDaoTest; import google.registry.schema.tld.PremiumListDaoTest; import google.registry.schema.tld.ReservedListDaoTest; import google.registry.schema.tmch.ClaimsListDaoTest; -import google.registry.tools.CreateRegistrarCommandTest; -import google.registry.tools.CreateReservedListCommandTest; -import google.registry.tools.DomainLockUtilsTest; -import google.registry.tools.LockDomainCommandTest; -import google.registry.tools.UnlockDomainCommandTest; -import google.registry.tools.UpdateRegistrarCommandTest; -import google.registry.tools.UpdateReservedListCommandTest; -import google.registry.tools.javascrap.BackfillRegistryLocksCommandTest; -import google.registry.tools.server.CreatePremiumListActionTest; -import google.registry.tools.server.UpdatePremiumListActionTest; -import google.registry.ui.server.registrar.RegistryLockGetActionTest; -import google.registry.ui.server.registrar.RegistryLockVerifyActionTest; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.ClassRule; @@ -48,36 +35,29 @@ import org.junit.runners.Suite.SuiteClasses; * Groups all JPA entity tests in one suite for easy invocation. This suite is used for * server/schema compatibility tests between releases. * - *

Every member class must use the {@link - * google.registry.persistence.transaction.JpaTestRules.JpaIntegrationWithCoverageRule} and have at - * least one test method that persists a JPA entity declared in persistence.xml. + *

Suite members are typically DAO tests, which perform simple create/update/delete operations on + * JPA entities. Each member class must use the {@link + * google.registry.persistence.transaction.JpaTestRules.JpaIntegrationWithCoverageRule} (either + * directly or through a rule chain) and have at least one test method that persists a JPA entity + * declared in persistence.xml. * *

Membership of this suite is monitored by the checks in {@link #checkJpaEntityCoverage()} and * {@link SqlIntegrationMembershipTest#sqlIntegrationMembershipComplete()}. + * + *

Note that with {@code JpaIntegrationWithCoverageRule}, each method starts with an empty + * database. Therefore this is not the right place for verifying backward data compatibility in + * end-to-end functional tests. */ @RunWith(Suite.class) @SuiteClasses({ - BackfillRegistryLocksCommandTest.class, ClaimsListDaoTest.class, - CreatePremiumListActionTest.class, - CreateRegistrarCommandTest.class, - CreateReservedListCommandTest.class, CursorDaoTest.class, - CursorTest.class, - DomainLockUtilsTest.class, + DomainBaseSqlTest.class, LockDaoTest.class, - LockDomainCommandTest.class, - LockTest.class, PremiumListDaoTest.class, RegistrarDaoTest.class, RegistryLockDaoTest.class, - RegistryLockGetActionTest.class, - RegistryLockVerifyActionTest.class, - ReservedListDaoTest.class, - UnlockDomainCommandTest.class, - UpdatePremiumListActionTest.class, - UpdateRegistrarCommandTest.class, - UpdateReservedListCommandTest.class + ReservedListDaoTest.class }) public class SqlIntegrationTestSuite {