mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 00:17:20 +02:00
Move EPP XML testdata to server/testdata
This will allow tests in server to reference the xml files. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=161582503
This commit is contained in:
parent
3372ed718a
commit
39c3706321
59 changed files with 61 additions and 18 deletions
|
@ -15,8 +15,6 @@
|
|||
package google.registry.tools;
|
||||
|
||||
import static com.google.common.io.BaseEncoding.base16;
|
||||
import static com.google.common.io.Resources.getResource;
|
||||
import static com.google.common.io.Resources.toByteArray;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.flows.EppXmlTransformer.unmarshal;
|
||||
import static google.registry.flows.picker.FlowPicker.getFlowClass;
|
||||
|
@ -31,7 +29,6 @@ import static google.registry.testing.DatastoreHelper.persistActiveContact;
|
|||
import static google.registry.testing.DatastoreHelper.persistActiveHost;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static google.registry.util.ResourceUtils.readResourceBytes;
|
||||
|
||||
import com.beust.jcommander.ParameterException;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
@ -45,6 +42,7 @@ import google.registry.model.eppcommon.Trid;
|
|||
import google.registry.model.eppinput.EppInput;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.tools.ServerSideCommand.Connection;
|
||||
import google.registry.tools.server.ToolsTestData;
|
||||
import java.io.IOException;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Before;
|
||||
|
@ -61,8 +59,8 @@ public class AllocateDomainCommandTest extends CommandTestCase<AllocateDomainCom
|
|||
public void init() throws IOException {
|
||||
command.setConnection(connection);
|
||||
createTld("tld", QUIET_PERIOD);
|
||||
createApplication("example-one.tld", "testdata/domain_create_sunrush.xml", "1-TLD");
|
||||
createApplication("example-two.tld", "testdata/domain_create_sunrush2.xml", "2-TLD");
|
||||
createApplication("example-one.tld", "domain_create_sunrush.xml", "1-TLD");
|
||||
createApplication("example-two.tld", "domain_create_sunrush2.xml", "2-TLD");
|
||||
}
|
||||
|
||||
private void createApplication(String name, String xmlFile, String repoId) throws IOException {
|
||||
|
@ -103,7 +101,7 @@ public class AllocateDomainCommandTest extends CommandTestCase<AllocateDomainCom
|
|||
.setClientId("NewRegistrar")
|
||||
.setModificationTime(application.getCreationTime())
|
||||
.setTrid(Trid.create("ABC-123", "server-trid"))
|
||||
.setXmlBytes(toByteArray(getResource(AllocateDomainCommandTest.class, xmlFile)))
|
||||
.setXmlBytes(ToolsTestData.get(xmlFile).read())
|
||||
.build());
|
||||
}
|
||||
|
||||
|
@ -153,7 +151,7 @@ public class AllocateDomainCommandTest extends CommandTestCase<AllocateDomainCom
|
|||
|
||||
@Test
|
||||
public void testXmlInstantiatesFlow() throws Exception {
|
||||
byte[] xmlBytes = readResourceBytes(getClass(), "testdata/allocate_domain.xml").read();
|
||||
byte[] xmlBytes = ToolsTestData.get("allocate_domain.xml").read();
|
||||
assertThat(getFlowClass(unmarshal(EppInput.class, xmlBytes)))
|
||||
.isEqualTo(DomainAllocateFlow.class);
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ java_library(
|
|||
]),
|
||||
resources = glob([
|
||||
"testdata/*.*",
|
||||
"server/testdata/*.*",
|
||||
]),
|
||||
deps = [
|
||||
"//java/google/registry/backup",
|
||||
|
@ -33,6 +34,7 @@ java_library(
|
|||
"//javatests/google/registry/model",
|
||||
"//javatests/google/registry/rde",
|
||||
"//javatests/google/registry/testing",
|
||||
"//javatests/google/registry/tools/server",
|
||||
"//javatests/google/registry/xml",
|
||||
"//third_party/java/objectify:objectify-v4_1",
|
||||
"@com_beust_jcommander",
|
||||
|
|
|
@ -14,10 +14,9 @@
|
|||
|
||||
package google.registry.tools;
|
||||
|
||||
import static google.registry.util.ResourceUtils.readResourceUtf8;
|
||||
|
||||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
import google.registry.tools.server.ToolsTestData;
|
||||
import java.util.List;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -52,7 +51,7 @@ public class EppToolCommandTest extends EppToolCommandTestCase<EppToolCommand> {
|
|||
// The choice of xml file is arbitrary.
|
||||
runCommandForced(
|
||||
"--client=NewRegistrar",
|
||||
readResourceUtf8(getClass(), "testdata/contact_create.xml"));
|
||||
ToolsTestData.loadUtf8("contact_create.xml"));
|
||||
eppVerifier().verifySent("contact_create.xml");
|
||||
}
|
||||
|
||||
|
@ -61,9 +60,9 @@ public class EppToolCommandTest extends EppToolCommandTestCase<EppToolCommand> {
|
|||
// The choice of xml files is arbitrary.
|
||||
runCommandForced(
|
||||
"--client=NewRegistrar",
|
||||
readResourceUtf8(getClass(), "testdata/contact_create.xml"),
|
||||
readResourceUtf8(getClass(), "testdata/domain_check.xml"),
|
||||
readResourceUtf8(getClass(), "testdata/domain_check_fee.xml"));
|
||||
ToolsTestData.loadUtf8("contact_create.xml"),
|
||||
ToolsTestData.loadUtf8("domain_check.xml"),
|
||||
ToolsTestData.loadUtf8("domain_check_fee.xml"));
|
||||
eppVerifier().verifySent("contact_create.xml", "domain_check.xml", "domain_check_fee.xml");
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
package google.registry.tools;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.util.ResourceUtils.readResourceUtf8;
|
||||
import static google.registry.xml.XmlTestUtils.assertXmlEquals;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.mockito.Matchers.eq;
|
||||
|
@ -26,6 +25,7 @@ import com.google.common.base.Splitter;
|
|||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.net.MediaType;
|
||||
import google.registry.tools.ServerSideCommand.Connection;
|
||||
import google.registry.tools.server.ToolsTestData;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -85,7 +85,7 @@ public class EppToolVerifier {
|
|||
.split(new String(capturedParam, UTF_8));
|
||||
assertThat(map).hasSize(4);
|
||||
assertXmlEquals(
|
||||
readResourceUtf8(getClass(), "testdata/" + xml),
|
||||
ToolsTestData.loadUtf8(xml),
|
||||
URLDecoder.decode(map.get("xml"), UTF_8.toString()));
|
||||
assertThat(map).containsEntry("dryRun", Boolean.toString(dryRun));
|
||||
assertThat(map).containsEntry("clientId", clientId);
|
||||
|
|
|
@ -14,11 +14,11 @@
|
|||
|
||||
package google.registry.tools;
|
||||
|
||||
import static google.registry.util.ResourceUtils.readResourceUtf8;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.beust.jcommander.ParameterException;
|
||||
import google.registry.testing.InjectRule;
|
||||
import google.registry.tools.server.ToolsTestData;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
|
@ -35,7 +35,7 @@ public class ExecuteEppCommandTest extends EppToolCommandTestCase<ExecuteEppComm
|
|||
|
||||
@Before
|
||||
public void initCommand() throws Exception {
|
||||
xmlInput = readResourceUtf8(ExecuteEppCommandTest.class, "testdata/contact_create.xml");
|
||||
xmlInput = ToolsTestData.loadUtf8("contact_create.xml");
|
||||
eppFile = writeToNamedTmpFile("eppFile", xmlInput);
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ public class ExecuteEppCommandTest extends EppToolCommandTestCase<ExecuteEppComm
|
|||
|
||||
@Test
|
||||
public void testSuccess_multipleFiles() throws Exception {
|
||||
String xmlInput2 = readResourceUtf8(ExecuteEppCommandTest.class, "testdata/domain_check.xml");
|
||||
String xmlInput2 = ToolsTestData.loadUtf8("domain_check.xml");
|
||||
String eppFile2 = writeToNamedTmpFile("eppFile2", xmlInput2);
|
||||
runCommand("--client=NewRegistrar", "--force", eppFile, eppFile2);
|
||||
eppVerifier().verifySent("contact_create.xml", "domain_check.xml");
|
||||
|
|
44
javatests/google/registry/tools/server/ToolsTestData.java
Normal file
44
javatests/google/registry/tools/server/ToolsTestData.java
Normal file
|
@ -0,0 +1,44 @@
|
|||
// 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.tools.server;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.common.io.ByteSource;
|
||||
import com.google.common.io.Resources;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
/** Utility class providing easy access to contents of the {@code testdata/} directory. */
|
||||
public final class ToolsTestData {
|
||||
|
||||
/** Returns {@link ByteSource} for file in {@code tools/server/testdata/} directory. */
|
||||
public static ByteSource get(String filename) {
|
||||
return Resources.asByteSource(getUrl(filename));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads data from file in {@code tools/server/testdata/} as a String (assuming file is UTF-8).
|
||||
*
|
||||
* @throws IOException if the file couldn't be loaded from the jar.
|
||||
*/
|
||||
public static String loadUtf8(String filename) throws IOException {
|
||||
return Resources.asCharSource(getUrl(filename), UTF_8).read();
|
||||
}
|
||||
|
||||
private static URL getUrl(String filename) {
|
||||
return Resources.getResource(ToolsTestData.class, "testdata/" + filename);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue