mirror of
https://github.com/google/nomulus.git
synced 2025-06-30 00:03:37 +02:00
Disable JpaEntityCoverageCheck by default (#555)
* Disable JpaEntityCoverageCheck by default Only members of SqlIntegrationTestSuite should enable the check, which incurs per-test overhead.
This commit is contained in:
parent
b618ee6a0b
commit
a23e5d064b
7 changed files with 75 additions and 13 deletions
|
@ -50,12 +50,23 @@ public abstract class EntityTestCase {
|
||||||
|
|
||||||
protected FakeClock fakeClock = new FakeClock(DateTime.now(UTC));
|
protected FakeClock fakeClock = new FakeClock(DateTime.now(UTC));
|
||||||
|
|
||||||
@Rule @RegisterExtension
|
@Rule @RegisterExtension public final AppEngineRule appEngine;
|
||||||
public final AppEngineRule appEngine =
|
|
||||||
AppEngineRule.builder().withDatastoreAndCloudSql().withClock(fakeClock).build();
|
|
||||||
|
|
||||||
@Rule @RegisterExtension public InjectRule inject = new InjectRule();
|
@Rule @RegisterExtension public InjectRule inject = new InjectRule();
|
||||||
|
|
||||||
|
protected EntityTestCase() {
|
||||||
|
this(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected EntityTestCase(boolean enableJpaEntityCheck) {
|
||||||
|
appEngine =
|
||||||
|
AppEngineRule.builder()
|
||||||
|
.withDatastoreAndCloudSql()
|
||||||
|
.enableJpaEntityCoverageCheck(enableJpaEntityCheck)
|
||||||
|
.withClock(fakeClock)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void injectClock() {
|
public void injectClock() {
|
||||||
|
|
|
@ -38,6 +38,10 @@ public class DomainBaseSqlTest extends EntityTestCase {
|
||||||
Key<ContactResource> contactKey;
|
Key<ContactResource> contactKey;
|
||||||
Key<ContactResource> contact2Key;
|
Key<ContactResource> contact2Key;
|
||||||
|
|
||||||
|
public DomainBaseSqlTest() {
|
||||||
|
super(true);
|
||||||
|
}
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
contactKey = Key.create(ContactResource.class, "contact_id1");
|
contactKey = Key.create(ContactResource.class, "contact_id1");
|
||||||
|
|
|
@ -41,7 +41,11 @@ public final class RegistryLockDaoTest {
|
||||||
|
|
||||||
@RegisterExtension
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine =
|
public final AppEngineRule appEngine =
|
||||||
AppEngineRule.builder().withDatastoreAndCloudSql().withClock(fakeClock).build();
|
AppEngineRule.builder()
|
||||||
|
.withDatastoreAndCloudSql()
|
||||||
|
.enableJpaEntityCoverageCheck(true)
|
||||||
|
.withClock(fakeClock)
|
||||||
|
.build();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSaveAndLoad_success() {
|
public void testSaveAndLoad_success() {
|
||||||
|
|
|
@ -43,7 +43,11 @@ public class CursorDaoTest {
|
||||||
|
|
||||||
@RegisterExtension
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine =
|
public final AppEngineRule appEngine =
|
||||||
AppEngineRule.builder().withDatastoreAndCloudSql().withClock(fakeClock).build();
|
AppEngineRule.builder()
|
||||||
|
.withDatastoreAndCloudSql()
|
||||||
|
.enableJpaEntityCoverageCheck(true)
|
||||||
|
.withClock(fakeClock)
|
||||||
|
.build();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void save_worksSuccessfullyOnNewCursor() {
|
public void save_worksSuccessfullyOnNewCursor() {
|
||||||
|
|
|
@ -33,6 +33,10 @@ public class RegistrarDaoTest extends EntityTestCase {
|
||||||
|
|
||||||
private Registrar testRegistrar;
|
private Registrar testRegistrar;
|
||||||
|
|
||||||
|
public RegistrarDaoTest() {
|
||||||
|
super(true);
|
||||||
|
}
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
testRegistrar =
|
testRegistrar =
|
||||||
|
|
|
@ -45,7 +45,11 @@ public class PremiumListDaoTest {
|
||||||
|
|
||||||
@RegisterExtension
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine =
|
public final AppEngineRule appEngine =
|
||||||
AppEngineRule.builder().withDatastoreAndCloudSql().withClock(fakeClock).build();
|
AppEngineRule.builder()
|
||||||
|
.withDatastoreAndCloudSql()
|
||||||
|
.enableJpaEntityCoverageCheck(true)
|
||||||
|
.withClock(fakeClock)
|
||||||
|
.build();
|
||||||
|
|
||||||
private static final ImmutableMap<String, BigDecimal> TEST_PRICES =
|
private static final ImmutableMap<String, BigDecimal> TEST_PRICES =
|
||||||
ImmutableMap.of(
|
ImmutableMap.of(
|
||||||
|
|
|
@ -41,6 +41,7 @@ import google.registry.model.registrar.Registrar.State;
|
||||||
import google.registry.model.registrar.RegistrarAddress;
|
import google.registry.model.registrar.RegistrarAddress;
|
||||||
import google.registry.model.registrar.RegistrarContact;
|
import google.registry.model.registrar.RegistrarContact;
|
||||||
import google.registry.persistence.transaction.JpaTestRules;
|
import google.registry.persistence.transaction.JpaTestRules;
|
||||||
|
import google.registry.persistence.transaction.JpaTestRules.JpaIntegrationTestRule;
|
||||||
import google.registry.persistence.transaction.JpaTestRules.JpaIntegrationWithCoverageExtension;
|
import google.registry.persistence.transaction.JpaTestRules.JpaIntegrationWithCoverageExtension;
|
||||||
import google.registry.persistence.transaction.JpaTestRules.JpaIntegrationWithCoverageRule;
|
import google.registry.persistence.transaction.JpaTestRules.JpaIntegrationWithCoverageRule;
|
||||||
import google.registry.util.Clock;
|
import google.registry.util.Clock;
|
||||||
|
@ -104,10 +105,19 @@ public final class AppEngineRule extends ExternalResource
|
||||||
|
|
||||||
/** A rule-within-a-rule to provide a temporary folder for AppEngineRule's internal temp files. */
|
/** A rule-within-a-rule to provide a temporary folder for AppEngineRule's internal temp files. */
|
||||||
TemporaryFolder temporaryFolder = new TemporaryFolder();
|
TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||||
// Sets up a SQL database when running on JUnit 5.
|
/**
|
||||||
|
* Sets up a SQL database when running on JUnit 5. This is for test classes that are not member of
|
||||||
|
* the {@code SqlIntegrationTestSuite}.
|
||||||
|
*/
|
||||||
|
JpaIntegrationTestRule jpaIntegrationTestRule = null;
|
||||||
|
/**
|
||||||
|
* Sets up a SQL database when running on JUnit 5 and records the JPA entities tested by each test
|
||||||
|
* class. This is for {@code SqlIntegrationTestSuite} members.
|
||||||
|
*/
|
||||||
JpaIntegrationWithCoverageExtension jpaIntegrationWithCoverageExtension = null;
|
JpaIntegrationWithCoverageExtension jpaIntegrationWithCoverageExtension = null;
|
||||||
|
|
||||||
private boolean withDatastoreAndCloudSql;
|
private boolean withDatastoreAndCloudSql;
|
||||||
|
private boolean enableJpaEntityCoverageCheck;
|
||||||
private boolean withLocalModules;
|
private boolean withLocalModules;
|
||||||
private boolean withTaskQueue;
|
private boolean withTaskQueue;
|
||||||
private boolean withUserService;
|
private boolean withUserService;
|
||||||
|
@ -127,6 +137,14 @@ public final class AppEngineRule extends ExternalResource
|
||||||
rule.withDatastoreAndCloudSql = true;
|
rule.withDatastoreAndCloudSql = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Enables JPA entity coverage check if {@code enabled} is true. This should only be enabled for
|
||||||
|
* members of SqlIntegrationTestSuite.
|
||||||
|
*/
|
||||||
|
public Builder enableJpaEntityCoverageCheck(boolean enabled) {
|
||||||
|
rule.enableJpaEntityCoverageCheck = enabled;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/** Turn on the use of local modules. */
|
/** Turn on the use of local modules. */
|
||||||
public Builder withLocalModules() {
|
public Builder withLocalModules() {
|
||||||
|
@ -164,6 +182,9 @@ public final class AppEngineRule extends ExternalResource
|
||||||
}
|
}
|
||||||
|
|
||||||
public AppEngineRule build() {
|
public AppEngineRule build() {
|
||||||
|
checkState(
|
||||||
|
!rule.enableJpaEntityCoverageCheck || rule.withDatastoreAndCloudSql,
|
||||||
|
"withJpaEntityCoverageCheck enabled without Cloud SQL");
|
||||||
return rule;
|
return rule;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -279,8 +300,13 @@ public final class AppEngineRule extends ExternalResource
|
||||||
if (clock != null) {
|
if (clock != null) {
|
||||||
builder.withClock(clock);
|
builder.withClock(clock);
|
||||||
}
|
}
|
||||||
|
if (enableJpaEntityCoverageCheck) {
|
||||||
jpaIntegrationWithCoverageExtension = builder.buildIntegrationWithCoverageExtension();
|
jpaIntegrationWithCoverageExtension = builder.buildIntegrationWithCoverageExtension();
|
||||||
jpaIntegrationWithCoverageExtension.beforeEach(context);
|
jpaIntegrationWithCoverageExtension.beforeEach(context);
|
||||||
|
} else {
|
||||||
|
jpaIntegrationTestRule = builder.buildIntegrationTestRule();
|
||||||
|
jpaIntegrationTestRule.before();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,9 +314,11 @@ public final class AppEngineRule extends ExternalResource
|
||||||
@Override
|
@Override
|
||||||
public void afterEach(ExtensionContext context) throws Exception {
|
public void afterEach(ExtensionContext context) throws Exception {
|
||||||
if (withDatastoreAndCloudSql) {
|
if (withDatastoreAndCloudSql) {
|
||||||
checkState(
|
if (enableJpaEntityCoverageCheck) {
|
||||||
jpaIntegrationWithCoverageExtension != null, "Null jpaIntegrationWithCoverageExtension");
|
|
||||||
jpaIntegrationWithCoverageExtension.afterEach(context);
|
jpaIntegrationWithCoverageExtension.afterEach(context);
|
||||||
|
} else {
|
||||||
|
jpaIntegrationTestRule.after();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
after();
|
after();
|
||||||
}
|
}
|
||||||
|
@ -310,7 +338,10 @@ public final class AppEngineRule extends ExternalResource
|
||||||
if (clock != null) {
|
if (clock != null) {
|
||||||
builder.withClock(clock);
|
builder.withClock(clock);
|
||||||
}
|
}
|
||||||
statement = builder.buildIntegrationWithCoverageRule().apply(base, description);
|
checkState(
|
||||||
|
!enableJpaEntityCoverageCheck,
|
||||||
|
"JUnit4 tests must not enable withJpaEntityCoverageCheck.");
|
||||||
|
statement = builder.buildIntegrationTestRule().apply(base, description);
|
||||||
}
|
}
|
||||||
return super.apply(statement, description);
|
return super.apply(statement, description);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue