diff --git a/java/google/registry/module/backend/BackendRequestComponent.java b/java/google/registry/module/backend/BackendRequestComponent.java
index f9d68a6a3..0c2dd2498 100644
--- a/java/google/registry/module/backend/BackendRequestComponent.java
+++ b/java/google/registry/module/backend/BackendRequestComponent.java
@@ -50,6 +50,7 @@ import google.registry.monitoring.whitebox.VerifyEntityIntegrityAction;
import google.registry.monitoring.whitebox.WhiteboxModule;
import google.registry.rde.BrdaCopyAction;
import google.registry.rde.RdeContactImportAction;
+import google.registry.rde.RdeHostImportAction;
import google.registry.rde.RdeModule;
import google.registry.rde.RdeReportAction;
import google.registry.rde.RdeReporter;
@@ -103,6 +104,7 @@ interface BackendRequestComponent {
PublishDnsUpdatesAction publishDnsUpdatesAction();
ReadDnsQueueAction readDnsQueueAction();
RdeContactImportAction rdeContactImportAction();
+ RdeHostImportAction rdeHostImportAction();
RdeReportAction rdeReportAction();
RdeStagingAction rdeStagingAction();
RdeUploadAction rdeUploadAction();
diff --git a/java/google/registry/rde/RdeHostImportAction.java b/java/google/registry/rde/RdeHostImportAction.java
new file mode 100644
index 000000000..67948fdcb
--- /dev/null
+++ b/java/google/registry/rde/RdeHostImportAction.java
@@ -0,0 +1,114 @@
+// Copyright 2016 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.rde;
+
+import static google.registry.mapreduce.MapreduceRunner.PARAM_MAP_SHARDS;
+import static google.registry.model.ofy.ObjectifyService.ofy;
+import static google.registry.rde.RdeModule.PATH;
+import static google.registry.util.PipelineUtils.createJobPath;
+
+import com.google.appengine.tools.cloudstorage.GcsService;
+import com.google.appengine.tools.cloudstorage.GcsServiceFactory;
+import com.google.appengine.tools.cloudstorage.RetryParams;
+import com.google.appengine.tools.mapreduce.Mapper;
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
+import google.registry.config.ConfigModule;
+import google.registry.config.ConfigModule.Config;
+import google.registry.gcs.GcsUtils;
+import google.registry.mapreduce.MapreduceRunner;
+import google.registry.model.host.HostResource;
+import google.registry.request.Action;
+import google.registry.request.Parameter;
+import google.registry.request.Response;
+import google.registry.util.SystemClock;
+import javax.inject.Inject;
+
+/**
+ * A mapreduce that imports hosts from an escrow file.
+ *
+ * Specify the escrow file to import with the "path" parameter.
+ */
+@Action(path = "/_dr/task/importRdeHosts")
+public class RdeHostImportAction implements Runnable {
+
+ private static final GcsService GCS_SERVICE =
+ GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());
+
+ private final MapreduceRunner mrRunner;
+ private final Response response;
+ private final String importBucketName;
+ private final String importFileName;
+ private final Optional mapShards;
+
+ @Inject
+ public RdeHostImportAction(
+ MapreduceRunner mrRunner,
+ Response response,
+ @Config("rdeImportBucket") String importBucketName,
+ @Parameter(PATH) String importFileName,
+ @Parameter(PARAM_MAP_SHARDS) Optional mapShards) {
+ this.mrRunner = mrRunner;
+ this.response = response;
+ this.importBucketName = importBucketName;
+ this.importFileName = importFileName;
+ this.mapShards = mapShards;
+ }
+
+ @Override
+ public void run() {
+ response.sendJavaScriptRedirect(createJobPath(mrRunner
+ .setJobName("Import hosts from escrow file")
+ .setModuleName("backend")
+ .runMapOnly(
+ new RdeHostImportMapper(importBucketName),
+ ImmutableList.of(new RdeHostInput(mapShards, importBucketName, importFileName)))));
+ }
+
+ /** Mapper to import hosts from an escrow file. */
+ public static class RdeHostImportMapper extends Mapper {
+
+ private static final long serialVersionUID = -2898753709127134419L;
+ private final String importBucketName;
+ private transient RdeImportUtils importUtils;
+
+ public RdeHostImportMapper(String importBucketName) {
+ this.importBucketName = importBucketName;
+ }
+
+ private RdeImportUtils getImportUtils() {
+ if (importUtils == null) {
+ importUtils = createRdeImportUtils();
+ }
+ return importUtils;
+ }
+
+ /**
+ * Creates a new instance of RdeImportUtils.
+ */
+ private RdeImportUtils createRdeImportUtils() {
+ return new RdeImportUtils(
+ ofy(),
+ new SystemClock(),
+ importBucketName,
+ new GcsUtils(GCS_SERVICE, ConfigModule.provideGcsBufferSize()));
+ }
+
+ @Override
+ public void map(HostResource host) {
+ getImportUtils().importHost(host);
+ }
+ }
+}
diff --git a/java/google/registry/rde/RdeHostInput.java b/java/google/registry/rde/RdeHostInput.java
new file mode 100644
index 000000000..cc2832577
--- /dev/null
+++ b/java/google/registry/rde/RdeHostInput.java
@@ -0,0 +1,132 @@
+// Copyright 2016 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.rde;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import com.google.appengine.tools.cloudstorage.GcsFilename;
+import com.google.appengine.tools.cloudstorage.GcsService;
+import com.google.appengine.tools.cloudstorage.GcsServiceFactory;
+import com.google.appengine.tools.cloudstorage.RetryParams;
+import com.google.appengine.tools.mapreduce.Input;
+import com.google.appengine.tools.mapreduce.InputReader;
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
+import google.registry.config.ConfigModule;
+import google.registry.gcs.GcsUtils;
+import google.registry.model.host.HostResource;
+import google.registry.rde.RdeParser.RdeHeader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+
+/**
+ * A MapReduce {@link Input} that imports {@link HostResource} objects from an escrow file.
+ *
+ * If a mapShards parameter has been specified, up to that many readers will be created
+ * so that each map shard has one reader. If a mapShards parameter has not been specified, a
+ * default number of readers will be created.
+ */
+public class RdeHostInput extends Input {
+
+ private static final long serialVersionUID = 9218225041307602452L;
+
+ private static final GcsService GCS_SERVICE =
+ GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());
+
+ /**
+ * Default number of readers if map shards are not specified.
+ */
+ private static final int DEFAULT_READERS = 50;
+
+ /**
+ * Minimum number of records per reader.
+ */
+ private static final int MINIMUM_RECORDS_PER_READER = 100;
+
+ /**
+ * Optional argument to explicitly specify the number of readers.
+ */
+ private final int numReaders;
+ private final String importBucketName;
+ private final String importFileName;
+
+ /**
+ * Creates a new {@link RdeHostInput}
+ *
+ * @param mapShards Number of readers that should be created
+ * @param importBucketName Name of GCS bucket for escrow file imports
+ * @param importFileName Name of escrow file in GCS
+ */
+ public RdeHostInput(Optional mapShards, String importBucketName,
+ String importFileName) {
+ this.numReaders = mapShards.or(DEFAULT_READERS);
+ checkArgument(numReaders > 0, "Number of shards must be greater than zero");
+ this.importBucketName = importBucketName;
+ this.importFileName = importFileName;
+ }
+
+ @Override
+ public List extends InputReader> createReaders() throws IOException {
+ int numReaders = this.numReaders;
+ RdeHeader header = createParser().getHeader();
+ int numberOfHosts = header.getHostCount().intValue();
+ if (numberOfHosts / numReaders < MINIMUM_RECORDS_PER_READER) {
+ numReaders = numberOfHosts / MINIMUM_RECORDS_PER_READER;
+ // use at least one reader
+ numReaders = Math.max(numReaders, 1);
+ }
+ ImmutableList.Builder builder = new ImmutableList.Builder<>();
+ int hostsPerReader =
+ Math.max(MINIMUM_RECORDS_PER_READER, (int) Math.ceil((double) numberOfHosts / numReaders));
+ int offset = 0;
+ for (int i = 0; i < numReaders; i++) {
+ builder = builder.add(createReader(offset, hostsPerReader));
+ offset += hostsPerReader;
+ }
+ return builder.build();
+ }
+
+ /**
+ * Creates a new instance of {@link RdeHostReader}
+ */
+ private RdeHostReader createReader(int offset, int maxResults) {
+ return new RdeHostReader(importBucketName, importFileName, offset, maxResults);
+ }
+
+ /**
+ * Creates a new instance of {@link RdeParser}
+ */
+ private RdeParser createParser() {
+ GcsUtils utils = new GcsUtils(GCS_SERVICE, ConfigModule.provideGcsBufferSize());
+ GcsFilename filename = new GcsFilename(importBucketName, importFileName);
+ InputStream xmlInput = utils.openInputStream(filename);
+ try {
+ return new RdeParser(xmlInput);
+ } catch (Exception e) {
+ throw new InitializationException(
+ String.format("Error opening rde file %s/%s", importBucketName, importFileName), e);
+ }
+ }
+
+ /**
+ * Thrown when the input cannot initialize properly.
+ */
+ private static class InitializationException extends RuntimeException {
+ public InitializationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+ }
+}
diff --git a/java/google/registry/rde/RdeHostReader.java b/java/google/registry/rde/RdeHostReader.java
new file mode 100644
index 000000000..c5e52d75f
--- /dev/null
+++ b/java/google/registry/rde/RdeHostReader.java
@@ -0,0 +1,107 @@
+// Copyright 2016 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.rde;
+
+import com.google.appengine.tools.cloudstorage.GcsFilename;
+import com.google.appengine.tools.cloudstorage.GcsService;
+import com.google.appengine.tools.cloudstorage.GcsServiceFactory;
+import com.google.appengine.tools.cloudstorage.RetryParams;
+import com.google.appengine.tools.mapreduce.InputReader;
+import google.registry.config.ConfigModule;
+import google.registry.gcs.GcsUtils;
+import google.registry.model.host.HostResource;
+import google.registry.util.FormattingLogger;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.util.NoSuchElementException;
+import javax.annotation.concurrent.NotThreadSafe;
+
+/** Mapreduce {@link InputReader} for reading hosts from escrow files */
+@NotThreadSafe
+public class RdeHostReader extends InputReader implements Serializable {
+
+ private static final long serialVersionUID = 3037264959150412846L;
+
+ private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
+ private static final GcsService GCS_SERVICE =
+ GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());
+
+ final String importBucketName;
+ final String importFileName;
+ final int offset;
+ final int maxResults;
+
+ private int count = 0;
+
+ transient RdeParser parser;
+
+ /**
+ * Creates a new instance of {@link RdeParser}
+ */
+ private RdeParser newParser() {
+ GcsUtils utils = new GcsUtils(GCS_SERVICE, ConfigModule.provideGcsBufferSize());
+ GcsFilename filename = new GcsFilename(importBucketName, importFileName);
+ InputStream xmlInput = utils.openInputStream(filename);
+ try {
+ RdeParser parser = new RdeParser(xmlInput);
+ // skip the file offset and count
+ // if count is greater than 0, the reader has been rehydrated after doing some work.
+ // skip any already processed records.
+ parser.skipHosts(offset + count);
+ return parser;
+ } catch (Exception e) {
+ logger.severefmt(e, "Error opening rde file %s/%s", importBucketName, importFileName);
+ throw new RuntimeException(e);
+ }
+ }
+
+ public RdeHostReader(
+ String importBucketName,
+ String importFileName,
+ int offset,
+ int maxResults) {
+ this.importBucketName = importBucketName;
+ this.importFileName = importFileName;
+ this.offset = offset;
+ this.maxResults = maxResults;
+ }
+
+ @Override
+ public HostResource next() throws IOException {
+ if (count < maxResults) {
+ if (parser == null) {
+ parser = newParser();
+ if (parser.isAtHost()) {
+ count++;
+ return XjcToHostResourceConverter.convert(parser.getHost());
+ }
+ }
+ if (parser.nextHost()) {
+ count++;
+ return XjcToHostResourceConverter.convert(parser.getHost());
+ }
+ }
+ throw new NoSuchElementException();
+ }
+
+ @Override
+ public void endSlice() throws IOException {
+ super.endSlice();
+ if (parser != null) {
+ parser.close();
+ }
+ }
+}
diff --git a/java/google/registry/rde/RdeImportUtils.java b/java/google/registry/rde/RdeImportUtils.java
index 0e4a17e65..920038765 100644
--- a/java/google/registry/rde/RdeImportUtils.java
+++ b/java/google/registry/rde/RdeImportUtils.java
@@ -24,6 +24,7 @@ import google.registry.config.ConfigModule.Config;
import google.registry.gcs.GcsUtils;
import google.registry.model.EppResource;
import google.registry.model.contact.ContactResource;
+import google.registry.model.host.HostResource;
import google.registry.model.index.EppResourceIndex;
import google.registry.model.index.ForeignKeyIndex;
import google.registry.model.ofy.Ofy;
@@ -99,6 +100,19 @@ public class RdeImportUtils {
}
/**
+ * Imports a host from an escrow file.
+ *
+ * The host will only be imported if it has not been previously imported.
+ *
+ *
If the host is imported, {@link ForeignKeyIndex} and {@link EppResourceIndex} are also
+ * created.
+ *
+ * @return true if the host was created or updated, false otherwise.
+ */
+ public boolean importHost(final HostResource resource) {
+ return importEppResource(resource, "host");
+ }
+
/**
* Imports a contact from an escrow file.
*
diff --git a/java/google/registry/rde/XjcToHostResourceConverter.java b/java/google/registry/rde/XjcToHostResourceConverter.java
new file mode 100644
index 000000000..287bfe268
--- /dev/null
+++ b/java/google/registry/rde/XjcToHostResourceConverter.java
@@ -0,0 +1,76 @@
+// Copyright 2016 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.rde;
+
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Lists;
+import com.google.common.net.InetAddresses;
+import google.registry.model.contact.ContactResource;
+import google.registry.model.eppcommon.StatusValue;
+import google.registry.model.host.HostResource;
+import google.registry.xjc.host.XjcHostAddrType;
+import google.registry.xjc.host.XjcHostStatusType;
+import google.registry.xjc.rdecontact.XjcRdeContact;
+import google.registry.xjc.rdehost.XjcRdeHost;
+import java.net.InetAddress;
+
+/** Utility class that converts an {@link XjcRdeContact} into a {@link ContactResource}. */
+public class XjcToHostResourceConverter {
+
+ private static final Function STATUS_VALUE_CONVERTER =
+ new Function() {
+ @Override
+ public StatusValue apply(XjcHostStatusType status) {
+ return convertStatusType(status);
+ }
+ };
+
+ private static final Function ADDR_CONVERTER =
+ new Function() {
+ @Override
+ public InetAddress apply(XjcHostAddrType addr) {
+ return convertAddrType(addr);
+ }
+ };
+
+ static HostResource convert(XjcRdeHost host) {
+ return new HostResource.Builder()
+ .setFullyQualifiedHostName(host.getName())
+ .setRepoId(host.getRoid())
+ .setCurrentSponsorClientId(host.getClID())
+ .setLastTransferTime(host.getTrDate())
+ .setCreationTime(host.getCrDate())
+ .setLastEppUpdateTime(host.getUpDate())
+ .setCreationClientId(host.getCrRr().getValue())
+ .setLastEppUpdateClientId(host.getUpRr() == null ? null : host.getUpRr().getValue())
+ .setStatusValues(
+ ImmutableSet.copyOf(Lists.transform(host.getStatuses(), STATUS_VALUE_CONVERTER)))
+ .setInetAddresses(ImmutableSet.copyOf(Lists.transform(host.getAddrs(), ADDR_CONVERTER)))
+ .build();
+ }
+
+ /** Converts {@link XjcHostStatusType} to {@link StatusValue}. */
+ private static StatusValue convertStatusType(XjcHostStatusType status) {
+ return StatusValue.fromXmlName(status.getS().value());
+ }
+
+ /** Converts {@link XjcHostAddrType} to {@link InetAddress}. */
+ private static InetAddress convertAddrType(XjcHostAddrType addr) {
+ return InetAddresses.forString(addr.getValue());
+ }
+
+ private XjcToHostResourceConverter() {}
+}
diff --git a/javatests/google/registry/rde/RdeHostImportActionTest.java b/javatests/google/registry/rde/RdeHostImportActionTest.java
new file mode 100644
index 000000000..3a486bd8b
--- /dev/null
+++ b/javatests/google/registry/rde/RdeHostImportActionTest.java
@@ -0,0 +1,100 @@
+// Copyright 2016 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.rde;
+
+import static com.google.common.truth.Truth.assertThat;
+import static google.registry.model.ofy.ObjectifyService.ofy;
+
+import com.google.appengine.tools.cloudstorage.GcsFilename;
+import com.google.appengine.tools.cloudstorage.GcsService;
+import com.google.appengine.tools.cloudstorage.GcsServiceFactory;
+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 google.registry.config.ConfigModule;
+import google.registry.gcs.GcsUtils;
+import google.registry.mapreduce.MapreduceRunner;
+import google.registry.model.host.HostResource;
+import google.registry.request.Response;
+import google.registry.testing.FakeResponse;
+import google.registry.testing.mapreduce.MapreduceTestCase;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+
+/** Unit tests for {@link RdeHostImportAction}. */
+@RunWith(MockitoJUnitRunner.class)
+public class RdeHostImportActionTest extends MapreduceTestCase {
+
+ private static final ByteSource DEPOSIT_1_HOST = RdeTestData.get("deposit_1_host.xml");
+ private static final String IMPORT_BUCKET_NAME = "import-bucket";
+ private static final String IMPORT_FILE_NAME = "escrow-file.xml";
+
+ private static final GcsService GCS_SERVICE =
+ GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());
+
+ private MapreduceRunner mrRunner;
+
+ private Response response;
+
+ private final Optional mapShards = Optional.absent();
+
+ @Before
+ public void before() throws Exception {
+ response = new FakeResponse();
+ mrRunner = new MapreduceRunner(Optional.absent(), Optional.absent());
+ action = new RdeHostImportAction(
+ mrRunner,
+ response,
+ IMPORT_BUCKET_NAME,
+ IMPORT_FILE_NAME,
+ mapShards);
+ }
+
+ @Test
+ public void test_mapreduceSuccessfullyImportsHost() throws Exception {
+ pushToGcs(DEPOSIT_1_HOST);
+ runMapreduce();
+ List hosts = ofy().load().type(HostResource.class).list();
+ assertThat(hosts).hasSize(1);
+ checkHost(hosts.get(0));
+ }
+
+ /** Verifies that host id and ROID match expected values */
+ private void checkHost(HostResource host) {
+ assertThat(host.getFullyQualifiedHostName()).isEqualTo("ns1.example1.test");
+ assertThat(host.getRepoId()).isEqualTo("Hns1_example1_test-TEST");
+ }
+
+ private void runMapreduce() throws Exception {
+ action.run();
+ executeTasksUntilEmpty("mapreduce");
+ }
+
+ private void pushToGcs(ByteSource source) throws IOException {
+ try (OutputStream outStream =
+ new GcsUtils(GCS_SERVICE, ConfigModule.provideGcsBufferSize())
+ .openOutputStream(new GcsFilename(IMPORT_BUCKET_NAME, IMPORT_FILE_NAME));
+ InputStream inStream = source.openStream()) {
+ ByteStreams.copy(inStream, outStream);
+ }
+ }
+}
diff --git a/javatests/google/registry/rde/RdeHostInputTest.java b/javatests/google/registry/rde/RdeHostInputTest.java
new file mode 100644
index 000000000..acd608d61
--- /dev/null
+++ b/javatests/google/registry/rde/RdeHostInputTest.java
@@ -0,0 +1,273 @@
+// Copyright 2016 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.rde;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.appengine.tools.cloudstorage.GcsFilename;
+import com.google.appengine.tools.cloudstorage.GcsService;
+import com.google.appengine.tools.cloudstorage.GcsServiceFactory;
+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 google.registry.config.ConfigModule;
+import google.registry.gcs.GcsUtils;
+import google.registry.testing.AppEngineRule;
+import google.registry.testing.ExceptionRule;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+
+/** Unit tests for {@link RdeHostInput} */
+@RunWith(MockitoJUnitRunner.class)
+public class RdeHostInputTest {
+
+ private static final ByteSource DEPOSIT_0_HOST = RdeTestData.get("deposit_0_host_header.xml");
+ private static final ByteSource DEPOSIT_1_HOST = RdeTestData.get("deposit_1_host.xml");
+ private static final ByteSource DEPOSIT_199_HOST = RdeTestData.get("deposit_199_host_header.xml");
+ private static final ByteSource DEPOSIT_200_HOST = RdeTestData.get("deposit_200_host_header.xml");
+ private static final ByteSource DEPOSIT_1000_HOST =
+ RdeTestData.get("deposit_1000_host_header.xml");
+ private static final ByteSource DEPOSIT_10000_HOST =
+ RdeTestData.get("deposit_10000_host_header.xml");
+ private static final String IMPORT_BUCKET_NAME = "import-bucket";
+ private static final String IMPORT_FILE_NAME = "escrow-file.xml";
+
+ private static final GcsService GCS_SERVICE =
+ GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());
+
+ @Rule
+ public final AppEngineRule appEngine = AppEngineRule.builder()
+ .withDatastore()
+ .build();
+
+ @Rule
+ public final ExceptionRule thrown = new ExceptionRule();
+
+ /** Number of shards cannot be negative */
+ @Test
+ public void testNegativeShards_throwsIllegalArgumentException() throws Exception {
+ thrown.expect(IllegalArgumentException.class, "Number of shards must be greater than zero");
+ getInput(Optional.of(-1));
+ }
+
+ /** Number of shards cannot be zero */
+ @Test
+ public void testZeroShards_throwsIllegalArgumentException() throws Exception {
+ thrown.expect(IllegalArgumentException.class, "Number of shards must be greater than zero");
+ getInput(Optional.of(0));
+ }
+
+ /** Escrow file with zero hosts results in one reader */
+ @Test
+ public void testZeroHostsDefaultShards_returnsOneReader() throws Exception {
+ pushToGcs(DEPOSIT_0_HOST);
+ assertNumberOfReaders(Optional.absent(), 1);
+ }
+
+ /** Escrow file with zero hosts results in expected reader configuration */
+ @Test
+ public void testZeroHostsDefaultShardsReaderConfigurations() throws Exception {
+ pushToGcs(DEPOSIT_0_HOST);
+ assertReaderConfigurations(Optional.absent(), 0, 0, 100);
+ }
+
+ /** Escrow file with zero hosts and 75 shards results in one reader */
+ @Test
+ public void testZeroHosts75Shards_returnsOneReader() throws Exception {
+ pushToGcs(DEPOSIT_0_HOST);
+ assertNumberOfReaders(Optional.of(75), 1);
+ }
+
+ /** Escrow file with one host results in one reader */
+ @Test
+ public void testOneHostDefaultShards_returnsOneReader() throws Exception {
+ pushToGcs(DEPOSIT_1_HOST);
+ assertNumberOfReaders(Optional.absent(), 1);
+ }
+
+ /** Escrow file with one host results in expected reader configuration */
+ @Test
+ public void testOneHostDefaultShardsReaderConfigurations() throws Exception {
+ pushToGcs(DEPOSIT_1_HOST);
+ assertReaderConfigurations(Optional.absent(), 0, 0, 100);
+ }
+
+ /** Escrow file with one host and 75 shards results in one reader */
+ @Test
+ public void testOneHost75Shards_returnsOneReader() throws Exception {
+ pushToGcs(DEPOSIT_1_HOST);
+ assertNumberOfReaders(Optional.of(75), 1);
+ }
+
+ /** Escrow file with 199 hosts results in one reader */
+ @Test
+ public void test199HostsDefaultShards_returnsOneReader() throws Exception {
+ pushToGcs(DEPOSIT_199_HOST);
+ assertNumberOfReaders(Optional.absent(), 1);
+ }
+
+ /** Escrow file with 199 hosts results in expected reader configuration */
+ @Test
+ public void test199HostsDefaultShardsReaderConfigurations() throws Exception {
+ pushToGcs(DEPOSIT_199_HOST);
+ assertReaderConfigurations(Optional.absent(), 0, 0, 199);
+ }
+
+ /** Escrow file with 199 hosts and 75 shards results in one reader */
+ @Test
+ public void test199Hosts75Shards_returnsOneReader() throws Exception {
+ pushToGcs(DEPOSIT_199_HOST);
+ assertNumberOfReaders(Optional.of(75), 1);
+ }
+
+ /** Escrow file with 200 hosts results in two readers */
+ @Test
+ public void test200HostsDefaultShards_returnsTwoReaders() throws Exception {
+ pushToGcs(DEPOSIT_200_HOST);
+ assertNumberOfReaders(Optional.absent(), 2);
+ }
+
+ /** Escrow file with 200 hosts results in expected reader configurations */
+ @Test
+ public void test200HostsDefaultShardsReaderConfigurations() throws Exception {
+ pushToGcs(DEPOSIT_200_HOST);
+ assertReaderConfigurations(Optional.absent(), 0, 0, 100);
+ assertReaderConfigurations(Optional.absent(), 1, 100, 100);
+ }
+
+ /** Escrow file with 200 hosts and 75 shards results in two readers */
+ @Test
+ public void test200Hosts75Shards_returnsOneReader() throws Exception {
+ pushToGcs(DEPOSIT_200_HOST);
+ assertNumberOfReaders(Optional.of(75), 2);
+ }
+
+ /** Escrow file with 1000 hosts results in ten readers */
+ @Test
+ public void test1000HostsDefaultShards_returns10Readers() throws Exception {
+ pushToGcs(DEPOSIT_1000_HOST);
+ assertNumberOfReaders(Optional.absent(), 10);
+ }
+
+ /** Escrow file with 1000 hosts results in expected reader configurations */
+ @Test
+ public void test1000HostsDefaultShardsReaderConfigurations() throws Exception {
+ pushToGcs(DEPOSIT_1000_HOST);
+ for (int i = 0; i < 10; i++) {
+ assertReaderConfigurations(Optional.absent(), i, i * 100, 100);
+ }
+ }
+
+ /** Escrow file with 1000 hosts and 75 shards results in ten readers */
+ @Test
+ public void test1000Hosts75Shards_returns10Readers() throws Exception {
+ pushToGcs(DEPOSIT_1000_HOST);
+ assertNumberOfReaders(Optional.of(75), 10);
+ }
+
+ /** Escrow file with 10000 hosts results in 50 readers */
+ @Test
+ public void test10000HostsDefaultShards_returns50Readers() throws Exception {
+ pushToGcs(DEPOSIT_10000_HOST);
+ assertNumberOfReaders(Optional.absent(), 50);
+ }
+
+ /** Escrow file with 10000 hosts results in expected reader configurations */
+ @Test
+ public void test10000HostsDefaultShardsReaderConfigurations() throws Exception {
+ pushToGcs(DEPOSIT_10000_HOST);
+ for (int i = 0; i < 50; i++) {
+ assertReaderConfigurations(Optional.absent(), i, i * 200, 200);
+ }
+ }
+
+ /** Escrow file with 10000 hosts and 75 shards results in 75 readers */
+ @Test
+ public void test10000Hosts75Shards_returns75Readers() throws Exception {
+ pushToGcs(DEPOSIT_10000_HOST);
+ assertNumberOfReaders(Optional.of(75), 75);
+ }
+
+ /** Escrow file with 10000 hosts and 150 shards results in 100 readers */
+ @Test
+ public void test10000Hosts150Shards_returns100Readers() throws Exception {
+ pushToGcs(DEPOSIT_10000_HOST);
+ assertNumberOfReaders(Optional.of(150), 100);
+ }
+
+ /**
+ * Verify bucket, filename, offset and max results for a specific reader
+ *
+ * @param numberOfShards Number of desired shards ({@link Optional#absent} uses default of 50)
+ * @param whichReader Index of the reader in the list that is produced by the
+ * {@link RdeHostInput}
+ * @param expectedOffset Expected offset of the reader
+ * @param expectedMaxResults Expected maxResults of the reader
+ */
+ private void assertReaderConfigurations(Optional numberOfShards,
+ int whichReader, int expectedOffset, int expectedMaxResults) throws Exception {
+ RdeHostInput input = getInput(numberOfShards);
+ List> readers = input.createReaders();
+ RdeHostReader reader = (RdeHostReader) readers.get(whichReader);
+ assertImportBucketAndFilename(reader);
+ assertThat(reader.offset).isEqualTo(expectedOffset);
+ assertThat(reader.maxResults).isEqualTo(expectedMaxResults);
+ }
+
+ private void pushToGcs(ByteSource source) throws IOException {
+ try (OutputStream outStream =
+ new GcsUtils(GCS_SERVICE, ConfigModule.provideGcsBufferSize())
+ .openOutputStream(new GcsFilename(IMPORT_BUCKET_NAME, IMPORT_FILE_NAME));
+ InputStream inStream = source.openStream()) {
+ ByteStreams.copy(inStream, outStream);
+ }
+ }
+
+ /**
+ * Verify the number of readers produced by the {@link RdeHostInput}
+ *
+ * @param numberOfShards Number of desired shards ({@link Optional#absent} uses default of 50)
+ * @param expectedNumberOfReaders Expected size of the list returned
+ */
+ private void assertNumberOfReaders(Optional numberOfShards,
+ int expectedNumberOfReaders) throws Exception {
+ RdeHostInput input = getInput(numberOfShards);
+ List> readers = input.createReaders();
+ assertThat(readers).hasSize(expectedNumberOfReaders);
+ }
+
+ /**
+ * Creates a new testable instance of {@link RdeHostInput}
+ * @param mapShards Number of desired shards ({@link Optional#absent} uses default of 50)
+ */
+ private RdeHostInput getInput(Optional mapShards) {
+ return new RdeHostInput(mapShards, IMPORT_BUCKET_NAME, IMPORT_FILE_NAME);
+ }
+
+ /**
+ * Verifies the configured import bucket and file names.
+ */
+ private void assertImportBucketAndFilename(RdeHostReader reader) {
+ assertThat(reader.importBucketName).isEqualTo("import-bucket");
+ assertThat(reader.importFileName).isEqualTo("escrow-file.xml");
+ }
+}
diff --git a/javatests/google/registry/rde/RdeHostReaderTest.java b/javatests/google/registry/rde/RdeHostReaderTest.java
new file mode 100644
index 000000000..ef3f37c55
--- /dev/null
+++ b/javatests/google/registry/rde/RdeHostReaderTest.java
@@ -0,0 +1,214 @@
+// Copyright 2016 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.rde;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.appengine.tools.cloudstorage.GcsFilename;
+import com.google.appengine.tools.cloudstorage.GcsService;
+import com.google.appengine.tools.cloudstorage.GcsServiceFactory;
+import com.google.appengine.tools.cloudstorage.RetryParams;
+import com.google.common.io.ByteSource;
+import com.google.common.io.ByteStreams;
+import google.registry.config.ConfigModule;
+import google.registry.gcs.GcsUtils;
+import google.registry.model.host.HostResource;
+import google.registry.testing.AppEngineRule;
+import google.registry.testing.ExceptionRule;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.util.NoSuchElementException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+
+/** Unit tests for {@link RdeHostReader} */
+@RunWith(MockitoJUnitRunner.class)
+public class RdeHostReaderTest {
+
+ private static final ByteSource DEPOSIT_1_HOST = RdeTestData.get("deposit_1_host.xml");
+ private static final ByteSource DEPOSIT_3_HOST = RdeTestData.get("deposit_3_host.xml");
+ private static final ByteSource DEPOSIT_4_HOST = RdeTestData.get("deposit_4_host.xml");
+ private static final ByteSource DEPOSIT_10_HOST = RdeTestData.get("deposit_10_host.xml");
+ private static final String IMPORT_BUCKET_NAME = "rde-import";
+ private static final String IMPORT_FILE_NAME = "escrow-file.xml";
+
+ private static final GcsService GCS_SERVICE =
+ GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());
+
+ @Rule
+ public final AppEngineRule appEngine = AppEngineRule.builder()
+ .withDatastore()
+ .build();
+
+ @Rule
+ public final ExceptionRule thrown = new ExceptionRule();
+
+ /** Reads at least one result at 0 offset 1 maxResults */
+ @Test
+ public void testZeroOffsetOneResult_readsOne() throws Exception {
+ pushToGcs(DEPOSIT_1_HOST);
+ RdeHostReader reader = getReader(0, 1);
+ HostResource host1 = reader.next();
+ checkHost(host1, "ns1.example1.test", "Hns1_example1_test-TEST");
+ }
+
+ /** Reads at most one at 0 offset 1 maxResults */
+ @Test
+ public void testZeroOffsetOneResult_stopsAfterOne() throws Exception {
+ pushToGcs(DEPOSIT_3_HOST);
+ RdeHostReader reader = getReader(0, 1);
+ reader.next();
+ thrown.expect(NoSuchElementException.class);
+ reader.next();
+ }
+
+ /** Skips already-processed records after rehydration */
+ @Test
+ public void testZeroOffsetOneResult_skipsOneAfterRehydration() throws Exception {
+ pushToGcs(DEPOSIT_3_HOST);
+ RdeHostReader reader = getReader(0, 1);
+ reader.next();
+ reader.endSlice();
+
+ reader = cloneReader(reader);
+ reader.beginSlice();
+ // reader will not advance any further
+ thrown.expect(NoSuchElementException.class);
+ reader.next();
+ }
+
+ /** Reads three hosts */
+ @Test
+ public void testZeroOffsetThreeResult_readsThree() throws Exception {
+ pushToGcs(DEPOSIT_3_HOST);
+ RdeHostReader reader = getReader(0, 3);
+ checkHost(reader.next(), "ns1.example1.test", "Hns1_example1_test-TEST");
+ checkHost(reader.next(), "ns1.example2.test", "Hns1_example2_test-TEST");
+ checkHost(reader.next(), "ns1.example3.test", "Hns1_example3_test-TEST");
+ }
+
+ /** Stops reading at 3 maxResults */
+ @Test
+ public void testZeroOffsetThreeResult_stopsAtThree() throws Exception {
+ pushToGcs(DEPOSIT_4_HOST);
+ RdeHostReader reader = getReader(0, 3);
+ for (int i = 0; i < 3; i++) {
+ reader.next();
+ }
+ thrown.expect(NoSuchElementException.class);
+ reader.next();
+ }
+
+ /** Reads one host from file then stops at end of file */
+ @Test
+ public void testZeroOffsetThreeResult_endOfFile() throws Exception {
+ pushToGcs(DEPOSIT_1_HOST);
+ RdeHostReader reader = getReader(0, 3);
+ reader.next();
+ thrown.expect(NoSuchElementException.class);
+ reader.next();
+ }
+
+ /** Skips three hosts with offset of three */
+ @Test
+ public void testThreeOffsetOneResult_skipsThree() throws Exception {
+ pushToGcs(DEPOSIT_4_HOST);
+ RdeHostReader reader = getReader(3, 1);
+ checkHost(reader.next(), "ns1.example4.test", "Hns1_example4_test-TEST");
+ }
+
+ /** Skips four hosts after advancing once at three offset, then rehydrating */
+ @Test
+ public void testThreeOffsetTwoResult_skipsFourAfterRehydration() throws Exception {
+ pushToGcs(DEPOSIT_10_HOST);
+ RdeHostReader reader = getReader(3, 2);
+ reader.next();
+ reader.endSlice();
+ reader = cloneReader(reader);
+ reader.beginSlice();
+ checkHost(reader.next(), "ns1.example5.test", "Hns1_example5_test-TEST");
+ }
+
+ /** Reads three at zero offset three results with rehydration in the middle */
+ @Test
+ public void testZeroOffsetThreeResult_readsThreeWithRehydration() throws Exception {
+ pushToGcs(DEPOSIT_4_HOST);
+ RdeHostReader reader = getReader(0, 3);
+ checkHost(reader.next(), "ns1.example1.test", "Hns1_example1_test-TEST");
+ reader.endSlice();
+ reader = cloneReader(reader);
+ reader.beginSlice();
+ checkHost(reader.next(), "ns1.example2.test", "Hns1_example2_test-TEST");
+ checkHost(reader.next(), "ns1.example3.test", "Hns1_example3_test-TEST");
+ }
+
+ /** Stops reading at three with zero offset three results with rehydration in the middle */
+ @Test
+ public void testZeroOffsetThreeResult_stopsAtThreeWithRehydration() throws Exception {
+ pushToGcs(DEPOSIT_4_HOST);
+ RdeHostReader reader = getReader(0, 3);
+ reader.next();
+ reader.endSlice();
+ reader = cloneReader(reader);
+ reader.beginSlice();
+ reader.next();
+ reader.next();
+ thrown.expect(NoSuchElementException.class);
+ reader.next();
+ }
+
+ private void pushToGcs(ByteSource source) throws IOException {
+ try (OutputStream outStream =
+ new GcsUtils(GCS_SERVICE, ConfigModule.provideGcsBufferSize())
+ .openOutputStream(new GcsFilename(IMPORT_BUCKET_NAME, IMPORT_FILE_NAME));
+ InputStream inStream = source.openStream()) {
+ ByteStreams.copy(inStream, outStream);
+ }
+ }
+
+ /** Creates a deep copy of the {@link RdeHostReader} */
+ private RdeHostReader cloneReader(
+ RdeHostReader reader) throws Exception {
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ ObjectOutputStream oout = new ObjectOutputStream(bout);
+ oout.writeObject(reader);
+ ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
+ ObjectInputStream oin = new ObjectInputStream(bin);
+ RdeHostReader result = (RdeHostReader) oin.readObject();
+ return result;
+ }
+
+ /** Verifies that domain name and ROID match expected values */
+ private void checkHost(HostResource host, String domainName, String repoId) {
+ assertThat(host).isNotNull();
+ assertThat(host.getFullyQualifiedHostName()).isEqualTo(domainName);
+ assertThat(host.getRepoId()).isEqualTo(repoId);
+ }
+
+ /** Gets a new {@link RdeHostReader} with specified offset and maxResults */
+ private RdeHostReader getReader(int offset, int maxResults) throws Exception {
+ RdeHostReader reader =
+ new RdeHostReader(IMPORT_BUCKET_NAME, IMPORT_FILE_NAME, offset, maxResults);
+ reader.beginSlice();
+ return reader;
+ }
+}
diff --git a/javatests/google/registry/rde/RdeImportUtilsTest.java b/javatests/google/registry/rde/RdeImportUtilsTest.java
index b6ae4f490..6c066c28c 100644
--- a/javatests/google/registry/rde/RdeImportUtilsTest.java
+++ b/javatests/google/registry/rde/RdeImportUtilsTest.java
@@ -28,12 +28,14 @@ import com.google.appengine.tools.cloudstorage.GcsFilename;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
import com.google.common.io.ByteSource;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.Work;
import google.registry.gcs.GcsUtils;
import google.registry.model.EppResource;
import google.registry.model.contact.ContactResource;
+import google.registry.model.host.HostResource;
import google.registry.model.index.EppResourceIndex;
import google.registry.model.index.EppResourceIndexBucket;
import google.registry.model.index.ForeignKeyIndex;
@@ -44,6 +46,8 @@ import google.registry.testing.FakeClock;
import google.registry.testing.ShardableTestCase;
import java.io.IOException;
import java.io.InputStream;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import org.joda.time.DateTime;
import org.junit.After;
import org.junit.Before;
@@ -130,6 +134,46 @@ public class RdeImportUtilsTest extends ShardableTestCase {
assertThat(saved.getLastEppUpdateTime()).isEqualTo(newContact.getLastEppUpdateTime());
}
+ /** Verifies import of a host that has not been previously imported */
+ @Test
+ public void testImportNewHost() throws UnknownHostException {
+ HostResource newHost = buildNewHost();
+ assertThat(rdeImportUtils.importHost(newHost)).isTrue();
+ assertEppResourceIndexEntityFor(newHost);
+ assertForeignKeyIndexFor(newHost);
+
+ // verify the new contact was saved
+ HostResource saved = getHost("FOO_ROID");
+ assertThat(saved).isNotNull();
+ assertThat(saved.getFullyQualifiedHostName()).isEqualTo(
+ newHost.getFullyQualifiedHostName());
+ assertThat(saved.getInetAddresses()).isEqualTo(
+ newHost.getInetAddresses());
+ assertThat(saved.getLastEppUpdateTime()).isEqualTo(newHost.getLastEppUpdateTime());
+ }
+
+ /** Verifies that a host will not be imported more than once */
+ @Test
+ public void testImportExistingHost() throws UnknownHostException {
+ HostResource newHost = buildNewHost();
+ persistResource(newHost);
+ HostResource updatedHost =
+ newHost
+ .asBuilder()
+ .setLastEppUpdateTime(newHost.getLastEppUpdateTime().plusSeconds(1))
+ .build();
+ assertThat(rdeImportUtils.importHost(updatedHost)).isFalse();
+
+ // verify the new contact was saved
+ HostResource saved = getHost("FOO_ROID");
+ assertThat(saved).isNotNull();
+ assertThat(saved.getFullyQualifiedHostName()).isEqualTo(
+ newHost.getFullyQualifiedHostName());
+ assertThat(saved.getInetAddresses()).isEqualTo(
+ newHost.getInetAddresses());
+ assertThat(saved.getLastEppUpdateTime()).isEqualTo(newHost.getLastEppUpdateTime());
+ }
+
private static ContactResource buildNewContact() {
return new ContactResource.Builder()
.setContactId("sh8013")
@@ -139,6 +183,19 @@ public class RdeImportUtilsTest extends ShardableTestCase {
.build();
}
+ private static HostResource buildNewHost() throws UnknownHostException {
+ return new HostResource.Builder()
+ .setFullyQualifiedHostName("foo.bar.example")
+ .setInetAddresses(ImmutableSet.of(
+ InetAddress.getByName("192.0.2.2"),
+ InetAddress.getByName("192.0.2.29"),
+ InetAddress.getByName("1080:0:0:0:8:800:200C:417A")
+ ))
+ .setLastEppUpdateTime(DateTime.parse("2010-10-10T00:00:00.000Z"))
+ .setRepoId("FOO_ROID")
+ .build();
+ }
+
/** Verifies that no errors are thrown when a valid escrow file is validated */
@Test
@SuppressWarnings("CheckReturnValue")
@@ -189,6 +246,17 @@ public class RdeImportUtilsTest extends ShardableTestCase {
}});
}
+ /** Gets the contact with the specified ROID */
+ private static HostResource getHost(String repoId) {
+ final Key key = Key.create(HostResource.class, repoId);
+ return ofy().transact(new Work() {
+ @Override
+ public HostResource run() {
+ return ofy().load().key(key).now();
+ }
+ });
+ }
+
/** Confirms that a ForeignKeyIndex exists in the datastore for a given resource. */
private void assertForeignKeyIndexFor(final T resource) {
assertThat(ForeignKeyIndex.load(resource.getClass(), resource.getForeignKey(), clock.nowUtc()))
diff --git a/javatests/google/registry/rde/XjcToHostResourceConverterTest.java b/javatests/google/registry/rde/XjcToHostResourceConverterTest.java
new file mode 100644
index 000000000..020cc23ea
--- /dev/null
+++ b/javatests/google/registry/rde/XjcToHostResourceConverterTest.java
@@ -0,0 +1,117 @@
+// Copyright 2016 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.rde;
+
+import static com.google.common.truth.Truth.assertThat;
+import static google.registry.testing.DatastoreHelper.createTld;
+
+import com.google.appengine.repackaged.com.google.common.net.InetAddresses;
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.io.ByteSource;
+import google.registry.model.eppcommon.StatusValue;
+import google.registry.model.host.HostResource;
+import google.registry.testing.AppEngineRule;
+import google.registry.xjc.rdehost.XjcRdeHost;
+import google.registry.xjc.rdehost.XjcRdeHostElement;
+import java.io.InputStream;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+import org.joda.time.DateTime;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/**
+ * Unit tests for {@link XjcToHostResourceConverter}
+ */
+@RunWith(JUnit4.class)
+public class XjcToHostResourceConverterTest {
+
+ private static final ByteSource HOST_XML = RdeTestData.get("host_fragment.xml");
+
+ //List of packages to initialize JAXBContext
+ private static final String JAXB_CONTEXT_PACKAGES = Joiner.on(":")
+ .join(ImmutableList.of(
+ "google.registry.xjc.contact",
+ "google.registry.xjc.domain",
+ "google.registry.xjc.host",
+ "google.registry.xjc.mark",
+ "google.registry.xjc.rde",
+ "google.registry.xjc.rdecontact",
+ "google.registry.xjc.rdedomain",
+ "google.registry.xjc.rdeeppparams",
+ "google.registry.xjc.rdeheader",
+ "google.registry.xjc.rdeidn",
+ "google.registry.xjc.rdenndn",
+ "google.registry.xjc.rderegistrar",
+ "google.registry.xjc.smd"));
+
+ @Rule
+ public final AppEngineRule appEngine = AppEngineRule.builder()
+ .withDatastore()
+ .build();
+
+ private Unmarshaller unmarshaller;
+
+ @Before
+ public void before() throws Exception {
+ createTld("example");
+ unmarshaller = JAXBContext.newInstance(JAXB_CONTEXT_PACKAGES)
+ .createUnmarshaller();
+ }
+
+ @Test
+ public void testConvertHostResource() throws Exception {
+ XjcRdeHost xjcHost = getHost();
+ HostResource host = XjcToHostResourceConverter.convert(xjcHost);
+ assertThat(host.getFullyQualifiedHostName()).isEqualTo("ns1.example1.test");
+ assertThat(host.getRepoId()).isEqualTo("Hns1_example1_test-TEST");
+ assertThat(host.getStatusValues())
+ .isEqualTo(ImmutableSet.of(StatusValue.OK, StatusValue.LINKED));
+ assertThat(host.getInetAddresses()).isEqualTo(
+ ImmutableSet.of(
+ InetAddresses.forString("192.0.2.2"),
+ InetAddresses.forString("192.0.2.29"),
+ InetAddresses.forString("1080:0:0:0:8:800:200C:417A")));
+ assertThat(host.getCurrentSponsorClientId()).isEqualTo("RegistrarX");
+ assertThat(host.getCreationClientId()).isEqualTo("RegistrarX");
+ assertThat(host.getCreationTime()).isEqualTo(DateTime.parse("1999-05-08T12:10:00.0Z"));
+ assertThat(host.getLastEppUpdateClientId()).isEqualTo("RegistrarX");
+ assertThat(host.getLastEppUpdateTime()).isEqualTo(DateTime.parse("2009-10-03T09:34:00.0Z"));
+ assertThat(host.getLastTransferTime()).isEqualTo(DateTime.parse("2008-10-03T09:34:00.0Z"));
+ }
+
+ // included to pass the round-robin sharding filter
+ @Test
+ public void testNothing1() {}
+
+ // included to pass the round-robin sharding filter
+ @Test
+ public void testNothing2() {}
+
+ // included to pass the round-robin sharding filter
+ @Test
+ public void testNothing3() {}
+
+ private XjcRdeHost getHost() throws Exception {
+ try (InputStream ins = HOST_XML.openStream()) {
+ return ((XjcRdeHostElement) unmarshaller.unmarshal(ins)).getValue();
+ }
+ }
+}
diff --git a/javatests/google/registry/rde/testdata/deposit_0_host_header.xml b/javatests/google/registry/rde/testdata/deposit_0_host_header.xml
new file mode 100644
index 000000000..adb8768c1
--- /dev/null
+++ b/javatests/google/registry/rde/testdata/deposit_0_host_header.xml
@@ -0,0 +1,242 @@
+
+
+
+ 2010-10-17T00:00:00Z
+
+ 1.0
+ urn:ietf:params:xml:ns:rdeHeader-1.0
+ urn:ietf:params:xml:ns:rdeContact-1.0
+ urn:ietf:params:xml:ns:rdeHost-1.0
+ urn:ietf:params:xml:ns:rdeDomain-1.0
+ urn:ietf:params:xml:ns:rdeRegistrar-1.0
+ urn:ietf:params:xml:ns:rdeIDN-1.0
+ urn:ietf:params:xml:ns:rdeNNDN-1.0
+ urn:ietf:params:xml:ns:rdeEppParams-1.0
+
+
+
+
+
+
+ test
+ 2
+
+ 0
+
+ 1
+
+ 1
+
+ 1
+
+ 1
+
+ 1
+
+
+
+
+
+ example1.test
+ Dexample1-TEST
+
+ jd1234
+ sh8013
+ sh8013
+
+ ns1.example.com
+ ns1.example1.test
+
+ RegistrarX
+ RegistrarX
+ 1999-04-03T22:00:00.0Z
+ 2015-04-03T22:00:00.0Z
+
+
+
+
+ example2.test
+ Dexample2-TEST
+
+
+ jd1234
+ sh8013
+ sh8013
+ RegistrarX
+ RegistrarX
+ 1999-04-03T22:00:00.0Z
+ 2015-04-03T22:00:00.0Z
+
+
+
+
+ ns1.example1.test
+ Hns1_example1_test-TEST
+
+
+ 192.0.2.2
+ 192.0.2.29
+ 1080:0:0:0:8:800:200C:417A
+
+ RegistrarX
+ RegistrarX
+ 1999-05-08T12:10:00.0Z
+ RegistrarX
+ 2009-10-03T09:34:00.0Z
+
+
+
+
+ contact1
+ contact1-TEST
+
+
+
+ John Doe
+ Example Inc.
+
+ 123 Example Dr.
+ Suite 100
+ Dulles
+ VA
+ 20166-6503
+ US
+
+
+ +1.7035555555
+
+ +1.7035555556
+
+ jdoe@example.test
+
+ RegistrarX
+ RegistrarX
+
+ 2009-09-13T08:01:00.0Z
+ RegistrarX
+
+ 2009-11-26T09:10:00.0Z
+ 2009-12-03T09:05:00.0Z
+
+
+
+
+
+
+
+
+ RegistrarX
+ Registrar X
+ 123
+ ok
+
+
+ 123 Example Dr.
+
+ Suite 100
+
+ Dulles
+ VA
+ 20166-6503
+ US
+
+
+ +1.7035555555
+
+ +1.7035555556
+
+ jdoe@example.test
+
+ http://www.example.test
+
+
+ whois.example.test
+
+ http://whois.example.test
+
+
+ 2005-04-23T11:49:00.0Z
+ 2009-02-17T17:51:00.0Z
+
+
+
+
+
+ http://www.iana.org/domains/idn-tables/tables/br_pt-br_1.0.html
+
+
+ http://registro.br/dominio/regras.html
+
+
+
+
+
+ xn--exampl-gva.test
+ pt-BR
+ example1.test
+ withheld
+ 2005-04-23T11:49:00.0Z
+
+
+
+
+ 1.0
+ en
+
+ urn:ietf:params:xml:ns:domain-1.0
+
+
+ urn:ietf:params:xml:ns:contact-1.0
+
+
+ urn:ietf:params:xml:ns:host-1.0
+
+
+ urn:ietf:params:xml:ns:rgp-1.0
+
+ urn:ietf:params:xml:ns:secDNS-1.1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/javatests/google/registry/rde/testdata/deposit_10000_host_header.xml b/javatests/google/registry/rde/testdata/deposit_10000_host_header.xml
new file mode 100644
index 000000000..4e39e5b95
--- /dev/null
+++ b/javatests/google/registry/rde/testdata/deposit_10000_host_header.xml
@@ -0,0 +1,242 @@
+
+
+
+ 2010-10-17T00:00:00Z
+
+ 1.0
+ urn:ietf:params:xml:ns:rdeHeader-1.0
+ urn:ietf:params:xml:ns:rdeContact-1.0
+ urn:ietf:params:xml:ns:rdeHost-1.0
+ urn:ietf:params:xml:ns:rdeDomain-1.0
+ urn:ietf:params:xml:ns:rdeRegistrar-1.0
+ urn:ietf:params:xml:ns:rdeIDN-1.0
+ urn:ietf:params:xml:ns:rdeNNDN-1.0
+ urn:ietf:params:xml:ns:rdeEppParams-1.0
+
+
+
+
+
+
+ test
+ 2
+
+ 10000
+
+ 1
+
+ 1
+
+ 1
+
+ 1
+
+ 1
+
+
+
+
+
+ example1.test
+ Dexample1-TEST
+
+ jd1234
+ sh8013
+ sh8013
+
+ ns1.example.com
+ ns1.example1.test
+
+ RegistrarX
+ RegistrarX
+ 1999-04-03T22:00:00.0Z
+ 2015-04-03T22:00:00.0Z
+
+
+
+
+ example2.test
+ Dexample2-TEST
+
+
+ jd1234
+ sh8013
+ sh8013
+ RegistrarX
+ RegistrarX
+ 1999-04-03T22:00:00.0Z
+ 2015-04-03T22:00:00.0Z
+
+
+
+
+ ns1.example1.test
+ Hns1_example1_test-TEST
+
+
+ 192.0.2.2
+ 192.0.2.29
+ 1080:0:0:0:8:800:200C:417A
+
+ RegistrarX
+ RegistrarX
+ 1999-05-08T12:10:00.0Z
+ RegistrarX
+ 2009-10-03T09:34:00.0Z
+
+
+
+
+ contact1
+ contact1-TEST
+
+
+
+ John Doe
+ Example Inc.
+
+ 123 Example Dr.
+ Suite 100
+ Dulles
+ VA
+ 20166-6503
+ US
+
+
+ +1.7035555555
+
+ +1.7035555556
+
+ jdoe@example.test
+
+ RegistrarX
+ RegistrarX
+
+ 2009-09-13T08:01:00.0Z
+ RegistrarX
+
+ 2009-11-26T09:10:00.0Z
+ 2009-12-03T09:05:00.0Z
+
+
+
+
+
+
+
+
+ RegistrarX
+ Registrar X
+ 123
+ ok
+
+
+ 123 Example Dr.
+
+ Suite 100
+
+ Dulles
+ VA
+ 20166-6503
+ US
+
+
+ +1.7035555555
+
+ +1.7035555556
+
+ jdoe@example.test
+
+ http://www.example.test
+
+
+ whois.example.test
+
+ http://whois.example.test
+
+
+ 2005-04-23T11:49:00.0Z
+ 2009-02-17T17:51:00.0Z
+
+
+
+
+
+ http://www.iana.org/domains/idn-tables/tables/br_pt-br_1.0.html
+
+
+ http://registro.br/dominio/regras.html
+
+
+
+
+
+ xn--exampl-gva.test
+ pt-BR
+ example1.test
+ withheld
+ 2005-04-23T11:49:00.0Z
+
+
+
+
+ 1.0
+ en
+
+ urn:ietf:params:xml:ns:domain-1.0
+
+
+ urn:ietf:params:xml:ns:contact-1.0
+
+
+ urn:ietf:params:xml:ns:host-1.0
+
+
+ urn:ietf:params:xml:ns:rgp-1.0
+
+ urn:ietf:params:xml:ns:secDNS-1.1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/javatests/google/registry/rde/testdata/deposit_1000_host_header.xml b/javatests/google/registry/rde/testdata/deposit_1000_host_header.xml
new file mode 100644
index 000000000..d499788b5
--- /dev/null
+++ b/javatests/google/registry/rde/testdata/deposit_1000_host_header.xml
@@ -0,0 +1,242 @@
+
+
+
+ 2010-10-17T00:00:00Z
+
+ 1.0
+ urn:ietf:params:xml:ns:rdeHeader-1.0
+ urn:ietf:params:xml:ns:rdeContact-1.0
+ urn:ietf:params:xml:ns:rdeHost-1.0
+ urn:ietf:params:xml:ns:rdeDomain-1.0
+ urn:ietf:params:xml:ns:rdeRegistrar-1.0
+ urn:ietf:params:xml:ns:rdeIDN-1.0
+ urn:ietf:params:xml:ns:rdeNNDN-1.0
+ urn:ietf:params:xml:ns:rdeEppParams-1.0
+
+
+
+
+
+
+ test
+ 2
+
+ 1000
+
+ 1
+
+ 1
+
+ 1
+
+ 1
+
+ 1
+
+
+
+
+
+ example1.test
+ Dexample1-TEST
+
+ jd1234
+ sh8013
+ sh8013
+
+ ns1.example.com
+ ns1.example1.test
+
+ RegistrarX
+ RegistrarX
+ 1999-04-03T22:00:00.0Z
+ 2015-04-03T22:00:00.0Z
+
+
+
+
+ example2.test
+ Dexample2-TEST
+
+
+ jd1234
+ sh8013
+ sh8013
+ RegistrarX
+ RegistrarX
+ 1999-04-03T22:00:00.0Z
+ 2015-04-03T22:00:00.0Z
+
+
+
+
+ ns1.example1.test
+ Hns1_example1_test-TEST
+
+
+ 192.0.2.2
+ 192.0.2.29
+ 1080:0:0:0:8:800:200C:417A
+
+ RegistrarX
+ RegistrarX
+ 1999-05-08T12:10:00.0Z
+ RegistrarX
+ 2009-10-03T09:34:00.0Z
+
+
+
+
+ contact1
+ contact1-TEST
+
+
+
+ John Doe
+ Example Inc.
+
+ 123 Example Dr.
+ Suite 100
+ Dulles
+ VA
+ 20166-6503
+ US
+
+
+ +1.7035555555
+
+ +1.7035555556
+
+ jdoe@example.test
+
+ RegistrarX
+ RegistrarX
+
+ 2009-09-13T08:01:00.0Z
+ RegistrarX
+
+ 2009-11-26T09:10:00.0Z
+ 2009-12-03T09:05:00.0Z
+
+
+
+
+
+
+
+
+ RegistrarX
+ Registrar X
+ 123
+ ok
+
+
+ 123 Example Dr.
+
+ Suite 100
+
+ Dulles
+ VA
+ 20166-6503
+ US
+
+
+ +1.7035555555
+
+ +1.7035555556
+
+ jdoe@example.test
+
+ http://www.example.test
+
+
+ whois.example.test
+
+ http://whois.example.test
+
+
+ 2005-04-23T11:49:00.0Z
+ 2009-02-17T17:51:00.0Z
+
+
+
+
+
+ http://www.iana.org/domains/idn-tables/tables/br_pt-br_1.0.html
+
+
+ http://registro.br/dominio/regras.html
+
+
+
+
+
+ xn--exampl-gva.test
+ pt-BR
+ example1.test
+ withheld
+ 2005-04-23T11:49:00.0Z
+
+
+
+
+ 1.0
+ en
+
+ urn:ietf:params:xml:ns:domain-1.0
+
+
+ urn:ietf:params:xml:ns:contact-1.0
+
+
+ urn:ietf:params:xml:ns:host-1.0
+
+
+ urn:ietf:params:xml:ns:rgp-1.0
+
+ urn:ietf:params:xml:ns:secDNS-1.1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/javatests/google/registry/rde/testdata/deposit_10_host.xml b/javatests/google/registry/rde/testdata/deposit_10_host.xml
new file mode 100644
index 000000000..e42b72404
--- /dev/null
+++ b/javatests/google/registry/rde/testdata/deposit_10_host.xml
@@ -0,0 +1,395 @@
+
+
+
+ 2010-10-17T00:00:00Z
+
+ 1.0
+ urn:ietf:params:xml:ns:rdeHeader-1.0
+ urn:ietf:params:xml:ns:rdeContact-1.0
+ urn:ietf:params:xml:ns:rdeHost-1.0
+ urn:ietf:params:xml:ns:rdeDomain-1.0
+ urn:ietf:params:xml:ns:rdeRegistrar-1.0
+ urn:ietf:params:xml:ns:rdeIDN-1.0
+ urn:ietf:params:xml:ns:rdeNNDN-1.0
+ urn:ietf:params:xml:ns:rdeEppParams-1.0
+
+
+
+
+
+
+ test
+ 2
+
+ 3
+
+ 1
+
+ 1
+
+ 1
+
+ 1
+
+ 1
+
+
+
+
+
+ example1.test
+ Dexample1-TEST
+
+ jd1234
+ sh8013
+ sh8013
+
+ ns1.example.com
+ ns1.example1.test
+
+ RegistrarX
+ RegistrarX
+ 1999-04-03T22:00:00.0Z
+ 2015-04-03T22:00:00.0Z
+
+
+
+
+ example2.test
+ Dexample2-TEST
+
+
+ jd1234
+ sh8013
+ sh8013
+ RegistrarX
+ RegistrarX
+ 1999-04-03T22:00:00.0Z
+ 2015-04-03T22:00:00.0Z
+
+
+
+
+ ns1.example1.test
+ Hns1_example1_test-TEST
+
+
+ 192.0.2.2
+ 192.0.2.29
+ 1080:0:0:0:8:800:200C:417A
+
+ RegistrarX
+ RegistrarX
+ 1999-05-08T12:10:00.0Z
+ RegistrarX
+ 2009-10-03T09:34:00.0Z
+
+
+
+
+ ns1.example2.test
+ Hns1_example2_test-TEST
+
+
+ 192.0.2.2
+ 192.0.2.29
+ 1080:0:0:0:8:800:200C:417A
+
+ RegistrarX
+ RegistrarX
+ 1999-05-08T12:10:00.0Z
+ RegistrarX
+ 2009-10-03T09:34:00.0Z
+
+
+
+
+ ns1.example3.test
+ Hns1_example3_test-TEST
+
+
+ 192.0.2.2
+ 192.0.2.29
+ 1080:0:0:0:8:800:200C:417A
+
+ RegistrarX
+ RegistrarX
+ 1999-05-08T12:10:00.0Z
+ RegistrarX
+ 2009-10-03T09:34:00.0Z
+
+
+
+
+ ns1.example4.test
+ Hns1_example4_test-TEST
+
+
+ 192.0.2.2
+ 192.0.2.29
+ 1080:0:0:0:8:800:200C:417A
+
+ RegistrarX
+ RegistrarX
+ 1999-05-08T12:10:00.0Z
+ RegistrarX
+ 2009-10-03T09:34:00.0Z
+
+
+
+
+ ns1.example5.test
+ Hns1_example5_test-TEST
+
+
+ 192.0.2.2
+ 192.0.2.29
+ 1080:0:0:0:8:800:200C:417A
+
+ RegistrarX
+ RegistrarX
+ 1999-05-08T12:10:00.0Z
+ RegistrarX
+ 2009-10-03T09:34:00.0Z
+
+
+
+
+ ns1.example6.test
+ Hns1_example6_test-TEST
+
+
+ 192.0.2.2
+ 192.0.2.29
+ 1080:0:0:0:8:800:200C:417A
+
+ RegistrarX
+ RegistrarX
+ 1999-05-08T12:10:00.0Z
+ RegistrarX
+ 2009-10-03T09:34:00.0Z
+
+
+
+
+ ns1.example7.test
+ Hns1_example7_test-TEST
+
+
+ 192.0.2.2
+ 192.0.2.29
+ 1080:0:0:0:8:800:200C:417A
+
+ RegistrarX
+ RegistrarX
+ 1999-05-08T12:10:00.0Z
+ RegistrarX
+ 2009-10-03T09:34:00.0Z
+
+
+
+
+ ns1.example8.test
+ Hns1_example8_test-TEST
+
+
+ 192.0.2.2
+ 192.0.2.29
+ 1080:0:0:0:8:800:200C:417A
+
+ RegistrarX
+ RegistrarX
+ 1999-05-08T12:10:00.0Z
+ RegistrarX
+ 2009-10-03T09:34:00.0Z
+
+
+
+
+ ns1.example9.test
+ Hns1_example9_test-TEST
+
+
+ 192.0.2.2
+ 192.0.2.29
+ 1080:0:0:0:8:800:200C:417A
+
+ RegistrarX
+ RegistrarX
+ 1999-05-08T12:10:00.0Z
+ RegistrarX
+ 2009-10-03T09:34:00.0Z
+
+
+
+
+ ns1.example10.test
+ Hns1_example10_test-TEST
+
+
+ 192.0.2.2
+ 192.0.2.29
+ 1080:0:0:0:8:800:200C:417A
+
+ RegistrarX
+ RegistrarX
+ 1999-05-08T12:10:00.0Z
+ RegistrarX
+ 2009-10-03T09:34:00.0Z
+
+
+
+
+ contact1
+ contact1-TEST
+
+
+
+ John Doe
+ Example Inc.
+
+ 123 Example Dr.
+ Suite 100
+ Dulles
+ VA
+ 20166-6503
+ US
+
+
+ +1.7035555555
+
+ +1.7035555556
+
+ jdoe@example.test
+
+ RegistrarX
+ RegistrarX
+
+ 2009-09-13T08:01:00.0Z
+ RegistrarX
+
+ 2009-11-26T09:10:00.0Z
+ 2009-12-03T09:05:00.0Z
+
+
+
+
+
+
+
+
+ RegistrarX
+ Registrar X
+ 123
+ ok
+
+
+ 123 Example Dr.
+
+ Suite 100
+
+ Dulles
+ VA
+ 20166-6503
+ US
+
+
+ +1.7035555555
+
+ +1.7035555556
+
+ jdoe@example.test
+
+ http://www.example.test
+
+
+ whois.example.test
+
+ http://whois.example.test
+
+
+ 2005-04-23T11:49:00.0Z
+ 2009-02-17T17:51:00.0Z
+
+
+
+
+
+ http://www.iana.org/domains/idn-tables/tables/br_pt-br_1.0.html
+
+
+ http://registro.br/dominio/regras.html
+
+
+
+
+
+ xn--exampl-gva.test
+ pt-BR
+ example1.test
+ withheld
+ 2005-04-23T11:49:00.0Z
+
+
+
+
+ 1.0
+ en
+
+ urn:ietf:params:xml:ns:domain-1.0
+
+
+ urn:ietf:params:xml:ns:contact-1.0
+
+
+ urn:ietf:params:xml:ns:host-1.0
+
+
+ urn:ietf:params:xml:ns:rgp-1.0
+
+ urn:ietf:params:xml:ns:secDNS-1.1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/javatests/google/registry/rde/testdata/deposit_199_host_header.xml b/javatests/google/registry/rde/testdata/deposit_199_host_header.xml
new file mode 100644
index 000000000..eb9d2156b
--- /dev/null
+++ b/javatests/google/registry/rde/testdata/deposit_199_host_header.xml
@@ -0,0 +1,242 @@
+
+
+
+ 2010-10-17T00:00:00Z
+
+ 1.0
+ urn:ietf:params:xml:ns:rdeHeader-1.0
+ urn:ietf:params:xml:ns:rdeContact-1.0
+ urn:ietf:params:xml:ns:rdeHost-1.0
+ urn:ietf:params:xml:ns:rdeDomain-1.0
+ urn:ietf:params:xml:ns:rdeRegistrar-1.0
+ urn:ietf:params:xml:ns:rdeIDN-1.0
+ urn:ietf:params:xml:ns:rdeNNDN-1.0
+ urn:ietf:params:xml:ns:rdeEppParams-1.0
+
+
+
+
+
+
+ test
+ 2
+
+ 199
+
+ 1
+
+ 1
+
+ 1
+
+ 1
+
+ 1
+
+
+
+
+
+ example1.test
+ Dexample1-TEST
+
+ jd1234
+ sh8013
+ sh8013
+
+ ns1.example.com
+ ns1.example1.test
+
+ RegistrarX
+ RegistrarX
+ 1999-04-03T22:00:00.0Z
+ 2015-04-03T22:00:00.0Z
+
+
+
+
+ example2.test
+ Dexample2-TEST
+
+
+ jd1234
+ sh8013
+ sh8013
+ RegistrarX
+ RegistrarX
+ 1999-04-03T22:00:00.0Z
+ 2015-04-03T22:00:00.0Z
+
+
+
+
+ ns1.example1.test
+ Hns1_example1_test-TEST
+
+
+ 192.0.2.2
+ 192.0.2.29
+ 1080:0:0:0:8:800:200C:417A
+
+ RegistrarX
+ RegistrarX
+ 1999-05-08T12:10:00.0Z
+ RegistrarX
+ 2009-10-03T09:34:00.0Z
+
+
+
+
+ contact1
+ contact1-TEST
+
+
+
+ John Doe
+ Example Inc.
+
+ 123 Example Dr.
+ Suite 100
+ Dulles
+ VA
+ 20166-6503
+ US
+
+
+ +1.7035555555
+
+ +1.7035555556
+
+ jdoe@example.test
+
+ RegistrarX
+ RegistrarX
+
+ 2009-09-13T08:01:00.0Z
+ RegistrarX
+
+ 2009-11-26T09:10:00.0Z
+ 2009-12-03T09:05:00.0Z
+
+
+
+
+
+
+
+
+ RegistrarX
+ Registrar X
+ 123
+ ok
+
+
+ 123 Example Dr.
+
+ Suite 100
+
+ Dulles
+ VA
+ 20166-6503
+ US
+
+
+ +1.7035555555
+
+ +1.7035555556
+
+ jdoe@example.test
+
+ http://www.example.test
+
+
+ whois.example.test
+
+ http://whois.example.test
+
+
+ 2005-04-23T11:49:00.0Z
+ 2009-02-17T17:51:00.0Z
+
+
+
+
+
+ http://www.iana.org/domains/idn-tables/tables/br_pt-br_1.0.html
+
+
+ http://registro.br/dominio/regras.html
+
+
+
+
+
+ xn--exampl-gva.test
+ pt-BR
+ example1.test
+ withheld
+ 2005-04-23T11:49:00.0Z
+
+
+
+
+ 1.0
+ en
+
+ urn:ietf:params:xml:ns:domain-1.0
+
+
+ urn:ietf:params:xml:ns:contact-1.0
+
+
+ urn:ietf:params:xml:ns:host-1.0
+
+
+ urn:ietf:params:xml:ns:rgp-1.0
+
+ urn:ietf:params:xml:ns:secDNS-1.1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/javatests/google/registry/rde/testdata/deposit_1_host.xml b/javatests/google/registry/rde/testdata/deposit_1_host.xml
new file mode 100644
index 000000000..dba51527a
--- /dev/null
+++ b/javatests/google/registry/rde/testdata/deposit_1_host.xml
@@ -0,0 +1,242 @@
+
+
+
+ 2010-10-17T00:00:00Z
+
+ 1.0
+ urn:ietf:params:xml:ns:rdeHeader-1.0
+ urn:ietf:params:xml:ns:rdeContact-1.0
+ urn:ietf:params:xml:ns:rdeHost-1.0
+ urn:ietf:params:xml:ns:rdeDomain-1.0
+ urn:ietf:params:xml:ns:rdeRegistrar-1.0
+ urn:ietf:params:xml:ns:rdeIDN-1.0
+ urn:ietf:params:xml:ns:rdeNNDN-1.0
+ urn:ietf:params:xml:ns:rdeEppParams-1.0
+
+
+
+
+
+
+ test
+ 2
+
+ 1
+
+ 1
+
+ 1
+
+ 1
+
+ 1
+
+ 1
+
+
+
+
+
+ example1.test
+ Dexample1-TEST
+
+ jd1234
+ sh8013
+ sh8013
+
+ ns1.example.com
+ ns1.example1.test
+
+ RegistrarX
+ RegistrarX
+ 1999-04-03T22:00:00.0Z
+ 2015-04-03T22:00:00.0Z
+
+
+
+
+ example2.test
+ Dexample2-TEST
+
+
+ jd1234
+ sh8013
+ sh8013
+ RegistrarX
+ RegistrarX
+ 1999-04-03T22:00:00.0Z
+ 2015-04-03T22:00:00.0Z
+
+
+
+
+ ns1.example1.test
+ Hns1_example1_test-TEST
+
+
+ 192.0.2.2
+ 192.0.2.29
+ 1080:0:0:0:8:800:200C:417A
+
+ RegistrarX
+ RegistrarX
+ 1999-05-08T12:10:00.0Z
+ RegistrarX
+ 2009-10-03T09:34:00.0Z
+
+
+
+
+ contact1
+ contact1-TEST
+
+
+
+ John Doe
+ Example Inc.
+
+ 123 Example Dr.
+ Suite 100
+ Dulles
+ VA
+ 20166-6503
+ US
+
+
+ +1.7035555555
+
+ +1.7035555556
+
+ jdoe@example.test
+
+ RegistrarX
+ RegistrarX
+
+ 2009-09-13T08:01:00.0Z
+ RegistrarX
+
+ 2009-11-26T09:10:00.0Z
+ 2009-12-03T09:05:00.0Z
+
+
+
+
+
+
+
+
+ RegistrarX
+ Registrar X
+ 123
+ ok
+
+
+ 123 Example Dr.
+
+ Suite 100
+
+ Dulles
+ VA
+ 20166-6503
+ US
+
+
+ +1.7035555555
+
+ +1.7035555556
+
+ jdoe@example.test
+
+ http://www.example.test
+
+
+ whois.example.test
+
+ http://whois.example.test
+
+
+ 2005-04-23T11:49:00.0Z
+ 2009-02-17T17:51:00.0Z
+
+
+
+
+
+ http://www.iana.org/domains/idn-tables/tables/br_pt-br_1.0.html
+
+
+ http://registro.br/dominio/regras.html
+
+
+
+
+
+ xn--exampl-gva.test
+ pt-BR
+ example1.test
+ withheld
+ 2005-04-23T11:49:00.0Z
+
+
+
+
+ 1.0
+ en
+
+ urn:ietf:params:xml:ns:domain-1.0
+
+
+ urn:ietf:params:xml:ns:contact-1.0
+
+
+ urn:ietf:params:xml:ns:host-1.0
+
+
+ urn:ietf:params:xml:ns:rgp-1.0
+
+ urn:ietf:params:xml:ns:secDNS-1.1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/javatests/google/registry/rde/testdata/deposit_200_host_header.xml b/javatests/google/registry/rde/testdata/deposit_200_host_header.xml
new file mode 100644
index 000000000..289662150
--- /dev/null
+++ b/javatests/google/registry/rde/testdata/deposit_200_host_header.xml
@@ -0,0 +1,242 @@
+
+
+
+ 2010-10-17T00:00:00Z
+
+ 1.0
+ urn:ietf:params:xml:ns:rdeHeader-1.0
+ urn:ietf:params:xml:ns:rdeContact-1.0
+ urn:ietf:params:xml:ns:rdeHost-1.0
+ urn:ietf:params:xml:ns:rdeDomain-1.0
+ urn:ietf:params:xml:ns:rdeRegistrar-1.0
+ urn:ietf:params:xml:ns:rdeIDN-1.0
+ urn:ietf:params:xml:ns:rdeNNDN-1.0
+ urn:ietf:params:xml:ns:rdeEppParams-1.0
+
+
+
+
+
+
+ test
+ 2
+
+ 200
+
+ 1
+
+ 1
+
+ 1
+
+ 1
+
+ 1
+
+
+
+
+
+ example1.test
+ Dexample1-TEST
+
+ jd1234
+ sh8013
+ sh8013
+
+ ns1.example.com
+ ns1.example1.test
+
+ RegistrarX
+ RegistrarX
+ 1999-04-03T22:00:00.0Z
+ 2015-04-03T22:00:00.0Z
+
+
+
+
+ example2.test
+ Dexample2-TEST
+
+
+ jd1234
+ sh8013
+ sh8013
+ RegistrarX
+ RegistrarX
+ 1999-04-03T22:00:00.0Z
+ 2015-04-03T22:00:00.0Z
+
+
+
+
+ ns1.example1.test
+ Hns1_example1_test-TEST
+
+
+ 192.0.2.2
+ 192.0.2.29
+ 1080:0:0:0:8:800:200C:417A
+
+ RegistrarX
+ RegistrarX
+ 1999-05-08T12:10:00.0Z
+ RegistrarX
+ 2009-10-03T09:34:00.0Z
+
+
+
+
+ contact1
+ contact1-TEST
+
+
+
+ John Doe
+ Example Inc.
+
+ 123 Example Dr.
+ Suite 100
+ Dulles
+ VA
+ 20166-6503
+ US
+
+
+ +1.7035555555
+
+ +1.7035555556
+
+ jdoe@example.test
+
+ RegistrarX
+ RegistrarX
+
+ 2009-09-13T08:01:00.0Z
+ RegistrarX
+
+ 2009-11-26T09:10:00.0Z
+ 2009-12-03T09:05:00.0Z
+
+
+
+
+
+
+
+
+ RegistrarX
+ Registrar X
+ 123
+ ok
+
+
+ 123 Example Dr.
+
+ Suite 100
+
+ Dulles
+ VA
+ 20166-6503
+ US
+
+
+ +1.7035555555
+
+ +1.7035555556
+
+ jdoe@example.test
+
+ http://www.example.test
+
+
+ whois.example.test
+
+ http://whois.example.test
+
+
+ 2005-04-23T11:49:00.0Z
+ 2009-02-17T17:51:00.0Z
+
+
+
+
+
+ http://www.iana.org/domains/idn-tables/tables/br_pt-br_1.0.html
+
+
+ http://registro.br/dominio/regras.html
+
+
+
+
+
+ xn--exampl-gva.test
+ pt-BR
+ example1.test
+ withheld
+ 2005-04-23T11:49:00.0Z
+
+
+
+
+ 1.0
+ en
+
+ urn:ietf:params:xml:ns:domain-1.0
+
+
+ urn:ietf:params:xml:ns:contact-1.0
+
+
+ urn:ietf:params:xml:ns:host-1.0
+
+
+ urn:ietf:params:xml:ns:rgp-1.0
+
+ urn:ietf:params:xml:ns:secDNS-1.1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/javatests/google/registry/rde/testdata/deposit_3_host.xml b/javatests/google/registry/rde/testdata/deposit_3_host.xml
new file mode 100644
index 000000000..4cf7159e4
--- /dev/null
+++ b/javatests/google/registry/rde/testdata/deposit_3_host.xml
@@ -0,0 +1,276 @@
+
+
+
+ 2010-10-17T00:00:00Z
+
+ 1.0
+ urn:ietf:params:xml:ns:rdeHeader-1.0
+ urn:ietf:params:xml:ns:rdeContact-1.0
+ urn:ietf:params:xml:ns:rdeHost-1.0
+ urn:ietf:params:xml:ns:rdeDomain-1.0
+ urn:ietf:params:xml:ns:rdeRegistrar-1.0
+ urn:ietf:params:xml:ns:rdeIDN-1.0
+ urn:ietf:params:xml:ns:rdeNNDN-1.0
+ urn:ietf:params:xml:ns:rdeEppParams-1.0
+
+
+
+
+
+
+ test
+ 2
+
+ 3
+
+ 1
+
+ 1
+
+ 1
+
+ 1
+
+ 1
+
+
+
+
+
+ example1.test
+ Dexample1-TEST
+
+ jd1234
+ sh8013
+ sh8013
+
+ ns1.example.com
+ ns1.example1.test
+
+ RegistrarX
+ RegistrarX
+ 1999-04-03T22:00:00.0Z
+ 2015-04-03T22:00:00.0Z
+
+
+
+
+ example2.test
+ Dexample2-TEST
+
+
+ jd1234
+ sh8013
+ sh8013
+ RegistrarX
+ RegistrarX
+ 1999-04-03T22:00:00.0Z
+ 2015-04-03T22:00:00.0Z
+
+
+
+
+ ns1.example1.test
+ Hns1_example1_test-TEST
+
+
+ 192.0.2.2
+ 192.0.2.29
+ 1080:0:0:0:8:800:200C:417A
+
+ RegistrarX
+ RegistrarX
+ 1999-05-08T12:10:00.0Z
+ RegistrarX
+ 2009-10-03T09:34:00.0Z
+
+
+
+
+ ns1.example2.test
+ Hns1_example2_test-TEST
+
+
+ 192.0.2.2
+ 192.0.2.29
+ 1080:0:0:0:8:800:200C:417A
+
+ RegistrarX
+ RegistrarX
+ 1999-05-08T12:10:00.0Z
+ RegistrarX
+ 2009-10-03T09:34:00.0Z
+
+
+
+
+ ns1.example3.test
+ Hns1_example3_test-TEST
+
+
+ 192.0.2.2
+ 192.0.2.29
+ 1080:0:0:0:8:800:200C:417A
+
+ RegistrarX
+ RegistrarX
+ 1999-05-08T12:10:00.0Z
+ RegistrarX
+ 2009-10-03T09:34:00.0Z
+
+
+
+
+ contact1
+ contact1-TEST
+
+
+
+ John Doe
+ Example Inc.
+
+ 123 Example Dr.
+ Suite 100
+ Dulles
+ VA
+ 20166-6503
+ US
+
+
+ +1.7035555555
+
+ +1.7035555556
+
+ jdoe@example.test
+
+ RegistrarX
+ RegistrarX
+
+ 2009-09-13T08:01:00.0Z
+ RegistrarX
+
+ 2009-11-26T09:10:00.0Z
+ 2009-12-03T09:05:00.0Z
+
+
+
+
+
+
+
+
+ RegistrarX
+ Registrar X
+ 123
+ ok
+
+
+ 123 Example Dr.
+
+ Suite 100
+
+ Dulles
+ VA
+ 20166-6503
+ US
+
+
+ +1.7035555555
+
+ +1.7035555556
+
+ jdoe@example.test
+
+ http://www.example.test
+
+
+ whois.example.test
+
+ http://whois.example.test
+
+
+ 2005-04-23T11:49:00.0Z
+ 2009-02-17T17:51:00.0Z
+
+
+
+
+
+ http://www.iana.org/domains/idn-tables/tables/br_pt-br_1.0.html
+
+
+ http://registro.br/dominio/regras.html
+
+
+
+
+
+ xn--exampl-gva.test
+ pt-BR
+ example1.test
+ withheld
+ 2005-04-23T11:49:00.0Z
+
+
+
+
+ 1.0
+ en
+
+ urn:ietf:params:xml:ns:domain-1.0
+
+
+ urn:ietf:params:xml:ns:contact-1.0
+
+
+ urn:ietf:params:xml:ns:host-1.0
+
+
+ urn:ietf:params:xml:ns:rgp-1.0
+
+ urn:ietf:params:xml:ns:secDNS-1.1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/javatests/google/registry/rde/testdata/deposit_4_host.xml b/javatests/google/registry/rde/testdata/deposit_4_host.xml
new file mode 100644
index 000000000..4b49d10b7
--- /dev/null
+++ b/javatests/google/registry/rde/testdata/deposit_4_host.xml
@@ -0,0 +1,293 @@
+
+
+
+ 2010-10-17T00:00:00Z
+
+ 1.0
+ urn:ietf:params:xml:ns:rdeHeader-1.0
+ urn:ietf:params:xml:ns:rdeContact-1.0
+ urn:ietf:params:xml:ns:rdeHost-1.0
+ urn:ietf:params:xml:ns:rdeDomain-1.0
+ urn:ietf:params:xml:ns:rdeRegistrar-1.0
+ urn:ietf:params:xml:ns:rdeIDN-1.0
+ urn:ietf:params:xml:ns:rdeNNDN-1.0
+ urn:ietf:params:xml:ns:rdeEppParams-1.0
+
+
+
+
+
+
+ test
+ 2
+
+ 3
+
+ 1
+
+ 1
+
+ 1
+
+ 1
+
+ 1
+
+
+
+
+
+ example1.test
+ Dexample1-TEST
+
+ jd1234
+ sh8013
+ sh8013
+
+ ns1.example.com
+ ns1.example1.test
+
+ RegistrarX
+ RegistrarX
+ 1999-04-03T22:00:00.0Z
+ 2015-04-03T22:00:00.0Z
+
+
+
+
+ example2.test
+ Dexample2-TEST
+
+
+ jd1234
+ sh8013
+ sh8013
+ RegistrarX
+ RegistrarX
+ 1999-04-03T22:00:00.0Z
+ 2015-04-03T22:00:00.0Z
+
+
+
+
+ ns1.example1.test
+ Hns1_example1_test-TEST
+
+
+ 192.0.2.2
+ 192.0.2.29
+ 1080:0:0:0:8:800:200C:417A
+
+ RegistrarX
+ RegistrarX
+ 1999-05-08T12:10:00.0Z
+ RegistrarX
+ 2009-10-03T09:34:00.0Z
+
+
+
+
+ ns1.example2.test
+ Hns1_example2_test-TEST
+
+
+ 192.0.2.2
+ 192.0.2.29
+ 1080:0:0:0:8:800:200C:417A
+
+ RegistrarX
+ RegistrarX
+ 1999-05-08T12:10:00.0Z
+ RegistrarX
+ 2009-10-03T09:34:00.0Z
+
+
+
+
+ ns1.example3.test
+ Hns1_example3_test-TEST
+
+
+ 192.0.2.2
+ 192.0.2.29
+ 1080:0:0:0:8:800:200C:417A
+
+ RegistrarX
+ RegistrarX
+ 1999-05-08T12:10:00.0Z
+ RegistrarX
+ 2009-10-03T09:34:00.0Z
+
+
+
+
+ ns1.example4.test
+ Hns1_example4_test-TEST
+
+
+ 192.0.2.2
+ 192.0.2.29
+ 1080:0:0:0:8:800:200C:417A
+
+ RegistrarX
+ RegistrarX
+ 1999-05-08T12:10:00.0Z
+ RegistrarX
+ 2009-10-03T09:34:00.0Z
+
+
+
+
+ contact1
+ contact1-TEST
+
+
+
+ John Doe
+ Example Inc.
+
+ 123 Example Dr.
+ Suite 100
+ Dulles
+ VA
+ 20166-6503
+ US
+
+
+ +1.7035555555
+
+ +1.7035555556
+
+ jdoe@example.test
+
+ RegistrarX
+ RegistrarX
+
+ 2009-09-13T08:01:00.0Z
+ RegistrarX
+
+ 2009-11-26T09:10:00.0Z
+ 2009-12-03T09:05:00.0Z
+
+
+
+
+
+
+
+
+ RegistrarX
+ Registrar X
+ 123
+ ok
+
+
+ 123 Example Dr.
+
+ Suite 100
+
+ Dulles
+ VA
+ 20166-6503
+ US
+
+
+ +1.7035555555
+
+ +1.7035555556
+
+ jdoe@example.test
+
+ http://www.example.test
+
+
+ whois.example.test
+
+ http://whois.example.test
+
+
+ 2005-04-23T11:49:00.0Z
+ 2009-02-17T17:51:00.0Z
+
+
+
+
+
+ http://www.iana.org/domains/idn-tables/tables/br_pt-br_1.0.html
+
+
+ http://registro.br/dominio/regras.html
+
+
+
+
+
+ xn--exampl-gva.test
+ pt-BR
+ example1.test
+ withheld
+ 2005-04-23T11:49:00.0Z
+
+
+
+
+ 1.0
+ en
+
+ urn:ietf:params:xml:ns:domain-1.0
+
+
+ urn:ietf:params:xml:ns:contact-1.0
+
+
+ urn:ietf:params:xml:ns:host-1.0
+
+
+ urn:ietf:params:xml:ns:rgp-1.0
+
+ urn:ietf:params:xml:ns:secDNS-1.1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/javatests/google/registry/rde/testdata/host_fragment.xml b/javatests/google/registry/rde/testdata/host_fragment.xml
new file mode 100644
index 000000000..0a9856a7d
--- /dev/null
+++ b/javatests/google/registry/rde/testdata/host_fragment.xml
@@ -0,0 +1,15 @@
+
+ ns1.example1.test
+ Hns1_example1_test-TEST
+
+
+ 192.0.2.2
+ 192.0.2.29
+ 1080:0:0:0:8:800:200C:417A
+ RegistrarX
+ RegistrarX
+ 1999-05-08T12:10:00.0Z
+ RegistrarX
+ 2009-10-03T09:34:00.0Z
+ 2008-10-03T09:34:00.0Z
+