mirror of
https://github.com/google/nomulus.git
synced 2025-06-11 15:04:46 +02:00
Refactor ContactResource into ContactBase and create ContactHistory (#634)
* Create ContactHistory class + table This is similar to #587, but with contacts instead of hosts. This also includes a couple cleanups for HostHistoryTest and RegistryLockDaoTest, just making code more proper (we shouldn't be referencing constant revision IDs when using a sequence that is used by multiple classes, and RLDT can extend EntityTest) Note as well that we set ContactHistory to use the same revision ID sequence as HostHistory. * Move ContactResource -> ContactBase * Alter ContactBase and ContactResource
This commit is contained in:
parent
bd77edb491
commit
43230eee09
14 changed files with 908 additions and 365 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 google.registry.model.EntityTestCase;
|
||||
import google.registry.model.contact.ContactHistory;
|
||||
import google.registry.model.contact.ContactResource;
|
||||
import google.registry.model.eppcommon.Trid;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.model.transfer.ContactTransferData;
|
||||
import google.registry.persistence.VKey;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Tests for {@link ContactHistory}. */
|
||||
public class ContactHistoryTest extends EntityTestCase {
|
||||
|
||||
public ContactHistoryTest() {
|
||||
super(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPersistence() {
|
||||
saveRegistrar("registrar1");
|
||||
|
||||
ContactResource contact =
|
||||
new ContactResource.Builder()
|
||||
.setRepoId("contact1")
|
||||
.setContactId("contactId")
|
||||
.setCreationClientId("registrar1")
|
||||
.setPersistedCurrentSponsorClientId("registrar1")
|
||||
.setTransferData(new ContactTransferData.Builder().build())
|
||||
.build();
|
||||
|
||||
jpaTm().transact(() -> jpaTm().saveNew(contact));
|
||||
VKey<ContactResource> contactVKey = VKey.createSql(ContactResource.class, "contact1");
|
||||
ContactResource contactFromDb = jpaTm().transact(() -> jpaTm().load(contactVKey));
|
||||
ContactHistory contactHistory =
|
||||
new ContactHistory.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)
|
||||
.setContactBase(contactFromDb)
|
||||
.setContactRepoId(contactVKey)
|
||||
.build();
|
||||
jpaTm().transact(() -> jpaTm().saveNew(contactHistory));
|
||||
jpaTm()
|
||||
.transact(
|
||||
() -> {
|
||||
ContactHistory fromDatabase = jpaTm().load(VKey.createSql(ContactHistory.class, 1L));
|
||||
assertContactHistoriesEqual(fromDatabase, contactHistory);
|
||||
});
|
||||
}
|
||||
|
||||
private void assertContactHistoriesEqual(ContactHistory one, ContactHistory two) {
|
||||
// enough of the fields get changed during serialization that we can't depend on .equals()
|
||||
assertThat(one.getClientId()).isEqualTo(two.getClientId());
|
||||
assertThat(one.getContactRepoId()).isEqualTo(two.getContactRepoId());
|
||||
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.getContactBase().getContactId()).isEqualTo(two.getContactBase().getContactId());
|
||||
}
|
||||
}
|
|
@ -61,13 +61,14 @@ public class HostHistoryTest extends EntityTestCase {
|
|||
.setReason("reason")
|
||||
.setRequestedByRegistrar(true)
|
||||
.setHostBase(hostFromDb)
|
||||
.setHostResourceId(hostVKey)
|
||||
.setHostRepoId(hostVKey)
|
||||
.build();
|
||||
jpaTm().transact(() -> jpaTm().saveNew(hostHistory));
|
||||
jpaTm()
|
||||
.transact(
|
||||
() -> {
|
||||
HostHistory fromDatabase = jpaTm().load(VKey.createSql(HostHistory.class, 1L));
|
||||
HostHistory fromDatabase =
|
||||
jpaTm().load(VKey.createSql(HostHistory.class, hostHistory.getId()));
|
||||
assertHostHistoriesEqual(fromDatabase, hostHistory);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -26,26 +26,18 @@ import static google.registry.testing.SqlHelper.getRegistryLocksByRegistrarId;
|
|||
import static google.registry.testing.SqlHelper.saveRegistryLock;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
import google.registry.model.EntityTestCase;
|
||||
import google.registry.schema.domain.RegistryLock;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import google.registry.testing.FakeClock;
|
||||
import java.util.Optional;
|
||||
import org.joda.time.Duration;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
/** Unit tests for {@link RegistryLockDao}. */
|
||||
public final class RegistryLockDaoTest {
|
||||
public final class RegistryLockDaoTest extends EntityTestCase {
|
||||
|
||||
private final FakeClock fakeClock = new FakeClock();
|
||||
|
||||
@RegisterExtension
|
||||
public final AppEngineRule appEngine =
|
||||
AppEngineRule.builder()
|
||||
.withDatastoreAndCloudSql()
|
||||
.enableJpaEntityCoverageCheck(true)
|
||||
.withClock(fakeClock)
|
||||
.build();
|
||||
public RegistryLockDaoTest() {
|
||||
super(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveAndLoad_success() {
|
||||
|
|
|
@ -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.ContactHistoryTest;
|
||||
import google.registry.model.history.HostHistoryTest;
|
||||
import google.registry.model.poll.PollMessageTest;
|
||||
import google.registry.model.registry.RegistryLockDaoTest;
|
||||
|
@ -74,6 +75,7 @@ import org.junit.runner.RunWith;
|
|||
BeforeSuiteTest.class,
|
||||
BillingEventTest.class,
|
||||
ClaimsListDaoTest.class,
|
||||
ContactHistoryTest.class,
|
||||
ContactResourceTest.class,
|
||||
CursorDaoTest.class,
|
||||
DomainBaseSqlTest.class,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue