Update SqlIntegrationTestSuite (#510)

* Update SqlIntegrationTestSuite

Edited Javadoc to emphasize that suite members should be DAO tests.

Removed functional tests from the suite. They do not benefit much
from running against different schemas when the entities they use
are already covered by DAO tests.

Added DomainBaseSqlTest to the suite, which tests DomainBase.
This commit is contained in:
Weimin Yu 2020-03-11 14:11:53 -04:00 committed by GitHub
parent 6e1231233e
commit 6ed7e00b00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 41 deletions

View file

@ -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<String> IGNORE_ENTITIES =
ImmutableSet.of(
"DomainBase",
"BaseTransferObject",
"DelegationSignerData",
"DesignatedContact",
"GracePeriod",
"RegistrarContact");
"DelegationSignerData", "DesignatedContact", "GracePeriod", "RegistrarContact");
private static final ImmutableSet<Class> 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();
}
}

View file

@ -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.
*
* <p>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.
* <p>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.
*
* <p>Membership of this suite is monitored by the checks in {@link #checkJpaEntityCoverage()} and
* {@link SqlIntegrationMembershipTest#sqlIntegrationMembershipComplete()}.
*
* <p>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 {