mirror of
https://github.com/google/nomulus.git
synced 2025-07-08 20:23:24 +02:00
Add HostBase and HostHistory classes (#587)
* Add proof of concept for HostBase and HostHistory classes * Use a PROPERTY accessor for @Ids * Add an unused setter method for Hibernate's sake * Refactor HostHistory * Some responses to CR * Fix relationship and test * Manually manage the foreign keys for HostHistory * Protect HostBase's builder and use text for the enum type * Add responses to CR - Add javadocs - Create an ID sequence for host history objects * Don't try to set the ID * Use a Long and remove the setter * Add some comments and rename a couple fields * Don't change Datastore schema * Use Long in the Datastore schema * Add new createVKey method * Add comments and rename fields * Rename v27->v31 and regenerate the golden * Fix superordinateDomain and inetAddresses in HostHistory * V31 -> V32 * Fix SQL files that got messed up in the merge * Configure and use a manually-created history ID sequence * Add three more indices to HostHistory
This commit is contained in:
parent
26e2a51180
commit
47178d4fb5
15 changed files with 742 additions and 203 deletions
|
@ -0,0 +1,87 @@
|
|||
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.model.history;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
|
||||
import static google.registry.testing.SqlHelper.saveRegistrar;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import google.registry.model.EntityTestCase;
|
||||
import google.registry.model.eppcommon.Trid;
|
||||
import google.registry.model.host.HostHistory;
|
||||
import google.registry.model.host.HostResource;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.persistence.VKey;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Tests for {@link HostHistory}. */
|
||||
public class HostHistoryTest extends EntityTestCase {
|
||||
|
||||
public HostHistoryTest() {
|
||||
super(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPersistence() {
|
||||
saveRegistrar("registrar1");
|
||||
|
||||
HostResource host =
|
||||
new HostResource.Builder()
|
||||
.setRepoId("host1")
|
||||
.setFullyQualifiedHostName("ns1.example.com")
|
||||
.setCreationClientId("TheRegistrar")
|
||||
.setPersistedCurrentSponsorClientId("TheRegistrar")
|
||||
.setInetAddresses(ImmutableSet.of())
|
||||
.build();
|
||||
jpaTm().transact(() -> jpaTm().saveNew(host));
|
||||
VKey<HostResource> hostVKey = VKey.createSql(HostResource.class, "host1");
|
||||
HostResource hostFromDb = jpaTm().transact(() -> jpaTm().load(hostVKey));
|
||||
HostHistory hostHistory =
|
||||
new HostHistory.Builder()
|
||||
.setType(HistoryEntry.Type.HOST_CREATE)
|
||||
.setXmlBytes("<xml></xml>".getBytes(UTF_8))
|
||||
.setModificationTime(fakeClock.nowUtc())
|
||||
.setClientId("registrar1")
|
||||
.setTrid(Trid.create("ABC-123", "server-trid"))
|
||||
.setBySuperuser(false)
|
||||
.setReason("reason")
|
||||
.setRequestedByRegistrar(true)
|
||||
.setHostBase(hostFromDb)
|
||||
.setHostResourceId(hostVKey)
|
||||
.build();
|
||||
jpaTm().transact(() -> jpaTm().saveNew(hostHistory));
|
||||
jpaTm()
|
||||
.transact(
|
||||
() -> {
|
||||
HostHistory fromDatabase = jpaTm().load(VKey.createSql(HostHistory.class, 1L));
|
||||
assertHostHistoriesEqual(fromDatabase, hostHistory);
|
||||
});
|
||||
}
|
||||
|
||||
private void assertHostHistoriesEqual(HostHistory one, HostHistory two) {
|
||||
// enough of the fields get changed during serialization that we can't depend on .equals()
|
||||
assertThat(one.getClientId()).isEqualTo(two.getClientId());
|
||||
assertThat(one.getHostRepoId()).isEqualTo(two.getHostRepoId());
|
||||
assertThat(one.getBySuperuser()).isEqualTo(two.getBySuperuser());
|
||||
assertThat(one.getRequestedByRegistrar()).isEqualTo(two.getRequestedByRegistrar());
|
||||
assertThat(one.getReason()).isEqualTo(two.getReason());
|
||||
assertThat(one.getTrid()).isEqualTo(two.getTrid());
|
||||
assertThat(one.getType()).isEqualTo(two.getType());
|
||||
assertThat(one.getHostBase().getFullyQualifiedHostName())
|
||||
.isEqualTo(two.getHostBase().getFullyQualifiedHostName());
|
||||
}
|
||||
}
|
|
@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assert_;
|
|||
import google.registry.model.billing.BillingEventTest;
|
||||
import google.registry.model.contact.ContactResourceTest;
|
||||
import google.registry.model.domain.DomainBaseSqlTest;
|
||||
import google.registry.model.history.HostHistoryTest;
|
||||
import google.registry.model.poll.PollMessageTest;
|
||||
import google.registry.model.registry.RegistryLockDaoTest;
|
||||
import google.registry.persistence.transaction.JpaEntityCoverage;
|
||||
|
@ -75,6 +76,7 @@ import org.junit.runner.RunWith;
|
|||
ContactResourceTest.class,
|
||||
CursorDaoTest.class,
|
||||
DomainBaseSqlTest.class,
|
||||
HostHistoryTest.class,
|
||||
LockDaoTest.class,
|
||||
PollMessageTest.class,
|
||||
PremiumListDaoTest.class,
|
||||
|
|
|
@ -618,7 +618,7 @@ enum google.registry.model.reporting.DomainTransactionRecord$TransactionReportFi
|
|||
TRANSFER_SUCCESSFUL;
|
||||
}
|
||||
class google.registry.model.reporting.HistoryEntry {
|
||||
@Id long id;
|
||||
@Id java.lang.Long id;
|
||||
@Parent com.googlecode.objectify.Key<? extends google.registry.model.EppResource> parent;
|
||||
boolean bySuperuser;
|
||||
byte[] xmlBytes;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue