Populate the host in HostHistory objects in Host flows (#1129)

* Populate the host in HostHistory objects in Host flows
This commit is contained in:
gbrodman
2021-05-12 19:11:30 -04:00
committed by GitHub
parent 66ac000ef4
commit 2073f5b59f
40 changed files with 68 additions and 58 deletions
@@ -196,7 +196,7 @@ public abstract class ResourceFlowTestCase<F extends Flow, R extends EppResource
// Don't use direct equals comparison since one might be a subclass of the other
assertAboutImmutableObjects()
.that(contactHistory.getContactBase().get())
.isEqualExceptFields(resource);
.hasFieldsEqualTo(resource);
} else if (resource instanceof DomainContent) {
DomainHistory domainHistory = (DomainHistory) historyEntry;
assertAboutImmutableObjects()
@@ -204,7 +204,10 @@ public abstract class ResourceFlowTestCase<F extends Flow, R extends EppResource
.isEqualExceptFields(resource, "gracePeriods", "dsData", "nsHosts");
} else if (resource instanceof HostBase) {
HostHistory hostHistory = (HostHistory) historyEntry;
assertThat(hostHistory.getHostBase().get()).isEqualTo(resource);
// Don't use direct equals comparison since one might be a subclass of the other
assertAboutImmutableObjects()
.that(hostHistory.getHostBase().get())
.hasFieldsEqualTo(resource);
}
}
}
@@ -404,7 +404,7 @@ class DomainTransferCancelFlowTest
persistResource(
new DomainHistory.Builder()
.setType(DOMAIN_TRANSFER_REQUEST)
.setDomainContent(domain)
.setDomain(domain)
.setModificationTime(clock.nowUtc().minusDays(4))
.setDomainTransactionRecords(
ImmutableSet.of(previousSuccessRecord, notCancellableRecord))
@@ -92,17 +92,19 @@ class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, HostResour
clock.advanceOneMilli();
assertTransactionalFlow(true);
runFlowAssertResponse(loadFile("host_create_response.xml"));
HostResource host = reloadResourceByForeignKey();
// Check that the host was created and persisted with a history entry.
assertAboutHosts()
.that(reloadResourceByForeignKey())
.that(host)
.hasLastSuperordinateChange(null)
.and()
.hasOnlyOneHistoryEntryWhich()
.hasType(HistoryEntry.Type.HOST_CREATE);
assertNoBillingEvents();
if (tm().isOfy()) {
assertEppResourceIndexEntityFor(reloadResourceByForeignKey());
assertEppResourceIndexEntityFor(host);
}
assertLastHistoryContainsResource(host);
}
private void doSuccessfulInternalTest(String tld) throws Exception {
@@ -375,6 +375,7 @@ class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, HostResour
} else {
assertNoDnsTasksEnqueued();
}
assertLastHistoryContainsResource(deletedHost);
assertNoTasksEnqueued(QUEUE_ASYNC_DELETE);
}
@@ -176,6 +176,7 @@ class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, HostResour
.hasOnlyOneHistoryEntryWhich()
.hasType(HistoryEntry.Type.HOST_UPDATE);
assertNoBillingEvents();
assertLastHistoryContainsResource(renamedHost);
return renamedHost;
}
@@ -80,10 +80,10 @@ class ChildEntityInputTest {
domainA = persistEppResourceInFirstBucket(newDomainBase("a.tld", contact));
domainHistoryEntryA =
persistResource(
new DomainHistory.Builder().setDomainContent(domainA).setModificationTime(now).build());
new DomainHistory.Builder().setDomain(domainA).setModificationTime(now).build());
contactHistoryEntry =
persistResource(
new ContactHistory.Builder().setContactBase(contact).setModificationTime(now).build());
new ContactHistory.Builder().setContact(contact).setModificationTime(now).build());
oneTimeA =
persistResource(
new BillingEvent.OneTime.Builder()
@@ -113,7 +113,7 @@ class ChildEntityInputTest {
domainB = persistEppResourceInFirstBucket(newDomainBase("b.tld"));
domainHistoryEntryB =
persistResource(
new DomainHistory.Builder().setDomainContent(domainB).setModificationTime(now).build());
new DomainHistory.Builder().setDomain(domainB).setModificationTime(now).build());
oneTimeB =
persistResource(
new BillingEvent.OneTime.Builder()
@@ -294,7 +294,7 @@ class ChildEntityInputTest {
historyEntries.add(
persistResource(
new DomainHistory.Builder()
.setDomainContent(domain)
.setDomain(domain)
.setModificationTime(now)
.setClientId(i + ".tld")
.build())
@@ -51,6 +51,10 @@ public final class ImmutableObjectSubject extends Subject {
this.actual = actual;
}
public void hasFieldsEqualTo(@Nullable ImmutableObject expected) {
isEqualExceptFields(expected);
}
public void isEqualExceptFields(
@Nullable ImmutableObject expected, Iterable<String> ignoredFields) {
isEqualExceptFields(expected, Iterables.toArray(ignoredFields, String.class));
@@ -77,7 +77,7 @@ public class BillingEventTest extends EntityTestCase {
domainHistory =
persistResource(
new DomainHistory.Builder()
.setDomainContent(domain)
.setDomain(domain)
.setModificationTime(now)
.setRequestedByRegistrar(false)
.setType(HistoryEntry.Type.DOMAIN_CREATE)
@@ -86,7 +86,7 @@ public class BillingEventTest extends EntityTestCase {
domainHistory2 =
persistResource(
new DomainHistory.Builder()
.setDomainContent(domain)
.setDomain(domain)
.setModificationTime(now.plusDays(1))
.setRequestedByRegistrar(false)
.setType(HistoryEntry.Type.DOMAIN_CREATE)
@@ -522,7 +522,7 @@ public class DomainBaseSqlTest {
.setTransferData(transferData)
.setGracePeriods(gracePeriods)
.build();
historyEntry = historyEntry.asBuilder().setDomainContent(domain).build();
historyEntry = historyEntry.asBuilder().setDomain(domain).build();
jpaTm().insert(historyEntry);
jpaTm().insert(autorenewPollMessage);
jpaTm().insert(billEvent);
@@ -661,7 +661,7 @@ public class DomainBaseSqlTest {
.setTransferData(transferData)
.setGracePeriods(gracePeriods)
.build();
historyEntry = historyEntry.asBuilder().setDomainContent(domain).build();
historyEntry = historyEntry.asBuilder().setDomain(domain).build();
jpaTm().insert(historyEntry);
jpaTm().insert(autorenewPollMessage);
jpaTm().insert(billEvent);
@@ -69,7 +69,7 @@ public class ContactHistoryTest extends EntityTestCase {
ContactHistory contactHistory =
createContactHistory(contactFromDb, contact.getRepoId())
.asBuilder()
.setContactBase(null)
.setContact(null)
.build();
jpaTm().transact(() -> jpaTm().insert(contactHistory));
@@ -116,7 +116,7 @@ public class ContactHistoryTest extends EntityTestCase {
.setBySuperuser(false)
.setReason("reason")
.setRequestedByRegistrar(true)
.setContactBase(contact)
.setContact(contact)
.setContactRepoId(contactRepoId)
.build();
}
@@ -86,8 +86,7 @@ public class DomainHistoryTest extends EntityTestCase {
@TestSqlOnly
void testLegacyPersistence_nullResource() {
DomainBase domain = addGracePeriodForSql(createDomainWithContactsAndHosts());
DomainHistory domainHistory =
createDomainHistory(domain).asBuilder().setDomainContent(null).build();
DomainHistory domainHistory = createDomainHistory(domain).asBuilder().setDomain(null).build();
jpaTm().transact(() -> jpaTm().insert(domainHistory));
jpaTm()
@@ -255,7 +254,7 @@ public class DomainHistoryTest extends EntityTestCase {
.setBySuperuser(false)
.setReason("reason")
.setRequestedByRegistrar(true)
.setDomainContent(domain)
.setDomain(domain)
.setDomainRepoId(domain.getRepoId())
.setDomainTransactionRecords(ImmutableSet.of(transactionRecord))
.setOtherClientId("otherClient")
@@ -67,7 +67,7 @@ public class HostHistoryTest extends EntityTestCase {
HostResource hostFromDb = jpaTm().transact(() -> jpaTm().loadByKey(host.createVKey()));
HostHistory hostHistory =
createHostHistory(hostFromDb, host.getRepoId()).asBuilder().setHostBase(null).build();
createHostHistory(hostFromDb, host.getRepoId()).asBuilder().setHost(null).build();
jpaTm().transact(() -> jpaTm().insert(hostHistory));
jpaTm()
@@ -121,7 +121,7 @@ public class HostHistoryTest extends EntityTestCase {
.setBySuperuser(false)
.setReason("reason")
.setRequestedByRegistrar(true)
.setHostBase(hostBase)
.setHost(hostBase)
.setHostRepoId(hostRepoId)
.build();
}
@@ -62,7 +62,7 @@ public class PollMessageExternalKeyConverterTest {
historyEntry =
persistResource(
new DomainHistory.Builder()
.setDomainContent(persistActiveDomain("foo.foobar"))
.setDomain(persistActiveDomain("foo.foobar"))
.setType(HistoryEntry.Type.DOMAIN_CREATE)
.setPeriod(Period.create(1, Period.Unit.YEARS))
.setXmlBytes("<xml></xml>".getBytes(UTF_8))
@@ -58,7 +58,7 @@ class HistoryEntryDaoTest extends EntityTestCase {
// Set up a new persisted DomainHistory entity.
domainHistory =
new DomainHistory.Builder()
.setDomainContent(domain)
.setDomain(domain)
.setType(HistoryEntry.Type.DOMAIN_CREATE)
.setPeriod(Period.create(1, Period.Unit.YEARS))
.setXmlBytes("<xml></xml>".getBytes(UTF_8))
@@ -55,7 +55,7 @@ class HistoryEntryTest extends EntityTestCase {
// Set up a new persisted HistoryEntry entity.
domainHistory =
new DomainHistory.Builder()
.setDomainContent(domain)
.setDomain(domain)
.setType(HistoryEntry.Type.DOMAIN_CREATE)
.setPeriod(Period.create(1, Period.Unit.YEARS))
.setXmlBytes("<xml></xml>".getBytes(UTF_8))
@@ -224,7 +224,7 @@ public class DomainBaseToXjcConverterTest {
new DomainHistory.Builder()
.setModificationTime(clock.nowUtc())
.setType(HistoryEntry.Type.DOMAIN_CREATE)
.setDomainContent(domain)
.setDomain(domain)
.build());
BillingEvent.OneTime billingEvent =
persistResource(
@@ -636,7 +636,7 @@ public class DatabaseHelper {
new DomainHistory.Builder()
.setType(HistoryEntry.Type.DOMAIN_CREATE)
.setModificationTime(now)
.setDomainContent(domain)
.setDomain(domain)
.build());
BillingEvent.Recurring autorenewEvent =
persistResource(
@@ -677,7 +677,7 @@ public class DatabaseHelper {
new DomainHistory.Builder()
.setType(HistoryEntry.Type.DOMAIN_TRANSFER_REQUEST)
.setModificationTime(tm().transact(() -> tm().getTransactionTime()))
.setDomainContent(domain)
.setDomain(domain)
.build());
BillingEvent.OneTime transferBillingEvent =
persistResource(
@@ -298,7 +298,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
new DomainHistory.Builder()
.setModificationTime(fakeClock.nowUtc())
.setType(DOMAIN_CREATE)
.setDomainContent(domain)
.setDomain(domain)
.build());
BillingEvent.Recurring autorenewBillingEvent =
persistResource(