mirror of
https://github.com/google/nomulus.git
synced 2025-07-25 03:58:34 +02:00
Add mapper to import domains from RDE deposits
With some additional cleanup by Ben McIlwain. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=146695665
This commit is contained in:
parent
d6e6e8a49c
commit
a904f2c6ee
37 changed files with 2916 additions and 268 deletions
|
@ -16,6 +16,10 @@ package google.registry.rde.imports;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.testing.DatastoreHelper.getHistoryEntries;
|
||||
import static google.registry.testing.DatastoreHelper.newContactResource;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.DatastoreHelper.persistSimpleResource;
|
||||
|
||||
import com.google.appengine.tools.cloudstorage.GcsFilename;
|
||||
import com.google.appengine.tools.cloudstorage.GcsService;
|
||||
|
@ -24,10 +28,13 @@ import com.google.appengine.tools.cloudstorage.RetryParams;
|
|||
import com.google.common.base.Optional;
|
||||
import com.google.common.io.ByteSource;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.config.RegistryConfig.ConfigModule;
|
||||
import google.registry.gcs.GcsUtils;
|
||||
import google.registry.mapreduce.MapreduceRunner;
|
||||
import google.registry.model.contact.ContactResource;
|
||||
import google.registry.model.eppcommon.Trid;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.request.Response;
|
||||
import google.registry.testing.FakeResponse;
|
||||
import google.registry.testing.mapreduce.MapreduceTestCase;
|
||||
|
@ -35,6 +42,7 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -77,6 +85,69 @@ public class RdeContactImportActionTest extends MapreduceTestCase<RdeContactImpo
|
|||
checkContact(contacts.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_mapreduceSuccessfullyCreatesHistoryEntry() throws Exception {
|
||||
pushToGcs(DEPOSIT_1_CONTACT);
|
||||
runMapreduce();
|
||||
List<ContactResource> contacts = ofy().load().type(ContactResource.class).list();
|
||||
ContactResource contact = contacts.get(0);
|
||||
// verify history entry
|
||||
List<HistoryEntry> historyEntries = getHistoryEntries(contact);
|
||||
assertThat(historyEntries).hasSize(1);
|
||||
checkHistoryEntry(historyEntries.get(0), contact);
|
||||
}
|
||||
|
||||
/** Ensures that a second pass on a contact does not import a new contact. */
|
||||
@Test
|
||||
public void test_mapreduceTwiceDoesNotDuplicateResources() throws Exception {
|
||||
pushToGcs(DEPOSIT_1_CONTACT);
|
||||
// Create contact and history entry first
|
||||
ContactResource existingContact = persistResource(
|
||||
newContactResource("contact1")
|
||||
.asBuilder()
|
||||
.setRepoId("contact1-TEST")
|
||||
.build());
|
||||
persistSimpleResource(createHistoryEntry(
|
||||
existingContact.getRepoId(),
|
||||
existingContact.getCurrentSponsorClientId(),
|
||||
loadContactXml(DEPOSIT_1_CONTACT)));
|
||||
// Simulate running a second import and verify that the resources
|
||||
// aren't imported twice (only one host, and one history entry)
|
||||
runMapreduce();
|
||||
List<ContactResource> contacts = ofy().load().type(ContactResource.class).list();
|
||||
assertThat(contacts).hasSize(1);
|
||||
ContactResource contact = contacts.get(0);
|
||||
// verify history entry
|
||||
List<HistoryEntry> historyEntries = getHistoryEntries(contact);
|
||||
assertThat(historyEntries).hasSize(1);
|
||||
checkHistoryEntry(historyEntries.get(0), contact);
|
||||
}
|
||||
|
||||
private static HistoryEntry createHistoryEntry(String roid, String clid, byte[] objectXml) {
|
||||
return new HistoryEntry.Builder()
|
||||
.setType(HistoryEntry.Type.RDE_IMPORT)
|
||||
.setClientId(clid)
|
||||
.setTrid(Trid.create(null))
|
||||
.setModificationTime(DateTime.now())
|
||||
.setXmlBytes(objectXml)
|
||||
.setBySuperuser(true)
|
||||
.setReason("RDE Import")
|
||||
.setRequestedByRegistrar(false)
|
||||
.setParent(Key.create(null, ContactResource.class, roid))
|
||||
.build();
|
||||
}
|
||||
|
||||
/** Verify history entry fields are correct */
|
||||
private void checkHistoryEntry(HistoryEntry entry, ContactResource parent) {
|
||||
assertThat(entry.getType()).isEqualTo(HistoryEntry.Type.RDE_IMPORT);
|
||||
assertThat(entry.getClientId()).isEqualTo(parent.getCurrentSponsorClientId());
|
||||
assertThat(entry.getXmlBytes().length).isGreaterThan(0);
|
||||
assertThat(entry.getBySuperuser()).isTrue();
|
||||
assertThat(entry.getReason()).isEqualTo("RDE Import");
|
||||
assertThat(entry.getRequestedByRegistrar()).isEqualTo(false);
|
||||
assertThat(entry.getParent()).isEqualTo(Key.create(parent));
|
||||
}
|
||||
|
||||
/** Verifies that contact id and ROID match expected values */
|
||||
private void checkContact(ContactResource contact) {
|
||||
assertThat(contact.getContactId()).isEqualTo("contact1");
|
||||
|
@ -96,4 +167,12 @@ public class RdeContactImportActionTest extends MapreduceTestCase<RdeContactImpo
|
|||
ByteStreams.copy(inStream, outStream);
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] loadContactXml(ByteSource source) throws IOException {
|
||||
byte[] result = new byte[((int) source.size())];
|
||||
try (InputStream inStream = source.openStream()) {
|
||||
ByteStreams.readFully(inStream, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue