mirror of
https://github.com/google/nomulus.git
synced 2025-07-23 19:20:44 +02:00
Move tests to use TestDataHelper for reading resources
TestDataHelper is build exactly to prevent direct reads of resources. It caches the resources and makes sure they are in the correct directory. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=191785004
This commit is contained in:
parent
e5c0a85b3b
commit
6699915132
16 changed files with 70 additions and 78 deletions
|
@ -18,7 +18,7 @@ package google.registry.flows;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static google.registry.flows.EppXmlTransformer.unmarshal;
|
import static google.registry.flows.EppXmlTransformer.unmarshal;
|
||||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||||
import static google.registry.util.ResourceUtils.readResourceBytes;
|
import static google.registry.testing.TestDataHelper.loadBytes;
|
||||||
|
|
||||||
import google.registry.model.eppinput.EppInput;
|
import google.registry.model.eppinput.EppInput;
|
||||||
import google.registry.model.eppoutput.EppOutput;
|
import google.registry.model.eppoutput.EppOutput;
|
||||||
|
@ -33,8 +33,7 @@ public class EppXmlTransformerTest extends ShardableTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnmarshalingEppInput() throws Exception {
|
public void testUnmarshalingEppInput() throws Exception {
|
||||||
EppInput input = unmarshal(
|
EppInput input = unmarshal(EppInput.class, loadBytes(getClass(), "contact_info.xml").read());
|
||||||
EppInput.class, readResourceBytes(getClass(), "testdata/contact_info.xml").read());
|
|
||||||
assertThat(input.getCommandType()).isEqualTo("info");
|
assertThat(input.getCommandType()).isEqualTo("info");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +43,6 @@ public class EppXmlTransformerTest extends ShardableTestCase {
|
||||||
ClassCastException.class,
|
ClassCastException.class,
|
||||||
() ->
|
() ->
|
||||||
EppXmlTransformer.unmarshal(
|
EppXmlTransformer.unmarshal(
|
||||||
EppOutput.class,
|
EppOutput.class, loadBytes(getClass(), "contact_info.xml").read()));
|
||||||
readResourceBytes(getClass(), "testdata/contact_info.xml").read()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ package google.registry.model.eppinput;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static com.google.common.truth.Truth8.assertThat;
|
import static com.google.common.truth.Truth8.assertThat;
|
||||||
import static google.registry.flows.EppXmlTransformer.unmarshal;
|
import static google.registry.flows.EppXmlTransformer.unmarshal;
|
||||||
import static google.registry.util.ResourceUtils.readResourceBytes;
|
import static google.registry.testing.TestDataHelper.loadBytes;
|
||||||
|
|
||||||
import google.registry.model.contact.ContactResourceTest;
|
import google.registry.model.contact.ContactResourceTest;
|
||||||
import google.registry.model.domain.DomainResourceTest;
|
import google.registry.model.domain.DomainResourceTest;
|
||||||
|
@ -34,9 +34,7 @@ public class EppInputTest {
|
||||||
@Test
|
@Test
|
||||||
public void testUnmarshalling_contactInfo() throws Exception {
|
public void testUnmarshalling_contactInfo() throws Exception {
|
||||||
EppInput input =
|
EppInput input =
|
||||||
unmarshal(
|
unmarshal(EppInput.class, loadBytes(ContactResourceTest.class, "contact_info.xml").read());
|
||||||
EppInput.class,
|
|
||||||
readResourceBytes(ContactResourceTest.class, "testdata/contact_info.xml").read());
|
|
||||||
assertThat(input.getCommandWrapper().getClTrid()).isEqualTo("ABC-12345");
|
assertThat(input.getCommandWrapper().getClTrid()).isEqualTo("ABC-12345");
|
||||||
assertThat(input.getCommandType()).isEqualTo("info");
|
assertThat(input.getCommandType()).isEqualTo("info");
|
||||||
assertThat(input.getResourceType()).hasValue("contact");
|
assertThat(input.getResourceType()).hasValue("contact");
|
||||||
|
@ -47,9 +45,7 @@ public class EppInputTest {
|
||||||
@Test
|
@Test
|
||||||
public void testUnmarshalling_domainCheck() throws Exception {
|
public void testUnmarshalling_domainCheck() throws Exception {
|
||||||
EppInput input =
|
EppInput input =
|
||||||
unmarshal(
|
unmarshal(EppInput.class, loadBytes(DomainResourceTest.class, "domain_check.xml").read());
|
||||||
EppInput.class,
|
|
||||||
readResourceBytes(DomainResourceTest.class, "testdata/domain_check.xml").read());
|
|
||||||
assertThat(input.getCommandWrapper().getClTrid()).isEqualTo("ABC-12345");
|
assertThat(input.getCommandWrapper().getClTrid()).isEqualTo("ABC-12345");
|
||||||
assertThat(input.getCommandType()).isEqualTo("check");
|
assertThat(input.getCommandType()).isEqualTo("check");
|
||||||
assertThat(input.getResourceType()).hasValue("domain");
|
assertThat(input.getResourceType()).hasValue("domain");
|
||||||
|
@ -59,8 +55,7 @@ public class EppInputTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnmarshalling_login() throws Exception {
|
public void testUnmarshalling_login() throws Exception {
|
||||||
EppInput input =
|
EppInput input = unmarshal(EppInput.class, loadBytes(getClass(), "login_valid.xml").read());
|
||||||
unmarshal(EppInput.class, readResourceBytes(getClass(), "testdata/login_valid.xml").read());
|
|
||||||
assertThat(input.getCommandWrapper().getClTrid()).isEqualTo("ABC-12345");
|
assertThat(input.getCommandWrapper().getClTrid()).isEqualTo("ABC-12345");
|
||||||
assertThat(input.getCommandType()).isEqualTo("login");
|
assertThat(input.getCommandType()).isEqualTo("login");
|
||||||
assertThat(input.getResourceType()).isEmpty();
|
assertThat(input.getResourceType()).isEmpty();
|
||||||
|
@ -83,4 +78,3 @@ public class EppInputTest {
|
||||||
.containsExactly("urn:ietf:params:xml:ns:launch-1.0", "urn:ietf:params:xml:ns:rgp-1.0");
|
.containsExactly("urn:ietf:params:xml:ns:launch-1.0", "urn:ietf:params:xml:ns:rgp-1.0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,8 @@ import static google.registry.testing.JUnitBackports.assertThrows;
|
||||||
import static google.registry.testing.TaskQueueHelper.assertAtLeastOneTaskIsEnqueued;
|
import static google.registry.testing.TaskQueueHelper.assertAtLeastOneTaskIsEnqueued;
|
||||||
import static google.registry.testing.TaskQueueHelper.assertNoTasksEnqueued;
|
import static google.registry.testing.TaskQueueHelper.assertNoTasksEnqueued;
|
||||||
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
|
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
|
||||||
|
import static google.registry.testing.TestDataHelper.loadFile;
|
||||||
import static google.registry.tldconfig.idn.IdnTableEnum.EXTENDED_LATIN;
|
import static google.registry.tldconfig.idn.IdnTableEnum.EXTENDED_LATIN;
|
||||||
import static google.registry.util.ResourceUtils.readResourceUtf8;
|
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
|
|
||||||
|
@ -550,7 +550,7 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
|
||||||
executeTasksUntilEmpty("mapreduce", clock);
|
executeTasksUntilEmpty("mapreduce", clock);
|
||||||
|
|
||||||
XmlTestUtils.assertXmlEquals(
|
XmlTestUtils.assertXmlEquals(
|
||||||
readResourceUtf8(getClass(), "testdata/testMapReduce_withDomain_producesExpectedXml.xml"),
|
loadFile(getClass(), "testMapReduce_withDomain_producesExpectedXml.xml"),
|
||||||
readXml("lol_2000-01-01_full_S1_R0.xml.ghostryde"),
|
readXml("lol_2000-01-01_full_S1_R0.xml.ghostryde"),
|
||||||
"deposit.contents.registrar.crDate",
|
"deposit.contents.registrar.crDate",
|
||||||
"deposit.contents.registrar.upDate");
|
"deposit.contents.registrar.upDate");
|
||||||
|
@ -582,7 +582,7 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
|
||||||
executeTasksUntilEmpty("mapreduce", clock);
|
executeTasksUntilEmpty("mapreduce", clock);
|
||||||
|
|
||||||
XmlTestUtils.assertXmlEquals(
|
XmlTestUtils.assertXmlEquals(
|
||||||
readResourceUtf8(getClass(), "testdata/testMapReduce_withDomain_producesReportXml.xml"),
|
loadFile(getClass(), "testMapReduce_withDomain_producesReportXml.xml"),
|
||||||
readXml("lol_2000-01-01_full_S1_R0-report.xml.ghostryde"),
|
readXml("lol_2000-01-01_full_S1_R0-report.xml.ghostryde"),
|
||||||
"deposit.contents.registrar.crDate",
|
"deposit.contents.registrar.crDate",
|
||||||
"deposit.contents.registrar.upDate");
|
"deposit.contents.registrar.upDate");
|
||||||
|
@ -799,14 +799,13 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
|
||||||
throws Exception {
|
throws Exception {
|
||||||
doManualModeMapReduceTest(0, ImmutableSet.of("lol"));
|
doManualModeMapReduceTest(0, ImmutableSet.of("lol"));
|
||||||
XmlTestUtils.assertXmlEquals(
|
XmlTestUtils.assertXmlEquals(
|
||||||
readResourceUtf8(getClass(), "testdata/testMapReduce_withDomain_producesExpectedXml.xml"),
|
loadFile(getClass(), "testMapReduce_withDomain_producesExpectedXml.xml"),
|
||||||
readXml("manual/test/lol_2000-01-01_full_S1_R0.xml.ghostryde"),
|
readXml("manual/test/lol_2000-01-01_full_S1_R0.xml.ghostryde"),
|
||||||
"deposit.contents.registrar.crDate",
|
"deposit.contents.registrar.crDate",
|
||||||
"deposit.contents.registrar.upDate");
|
"deposit.contents.registrar.upDate");
|
||||||
XmlTestUtils.assertXmlEquals(
|
XmlTestUtils.assertXmlEquals(
|
||||||
readResourceUtf8(getClass(), "testdata/testMapReduce_withDomain_producesReportXml.xml"),
|
loadFile(getClass(), "testMapReduce_withDomain_producesReportXml.xml"),
|
||||||
readXml(
|
readXml("manual/test/lol_2000-01-01_full_S1_R0-report.xml.ghostryde"),
|
||||||
"manual/test/lol_2000-01-01_full_S1_R0-report.xml.ghostryde"),
|
|
||||||
"deposit.contents.registrar.crDate",
|
"deposit.contents.registrar.crDate",
|
||||||
"deposit.contents.registrar.upDate");
|
"deposit.contents.registrar.upDate");
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,8 @@ package google.registry.testing;
|
||||||
|
|
||||||
import static google.registry.keyring.api.PgpHelper.KeyRequirement.ENCRYPT;
|
import static google.registry.keyring.api.PgpHelper.KeyRequirement.ENCRYPT;
|
||||||
import static google.registry.keyring.api.PgpHelper.KeyRequirement.SIGN;
|
import static google.registry.keyring.api.PgpHelper.KeyRequirement.SIGN;
|
||||||
import static google.registry.util.ResourceUtils.readResourceBytes;
|
import static google.registry.testing.TestDataHelper.loadBytes;
|
||||||
import static google.registry.util.ResourceUtils.readResourceUtf8;
|
import static google.registry.testing.TestDataHelper.loadFile;
|
||||||
|
|
||||||
import com.google.common.io.ByteSource;
|
import com.google.common.io.ByteSource;
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
|
@ -47,9 +47,9 @@ public final class FakeKeyringModule {
|
||||||
private static final String SIGNING_KEY_EMAIL = "rde-unittest@registry.test";
|
private static final String SIGNING_KEY_EMAIL = "rde-unittest@registry.test";
|
||||||
private static final String RECEIVER_KEY_EMAIL = "rde-unittest@escrow.test";
|
private static final String RECEIVER_KEY_EMAIL = "rde-unittest@escrow.test";
|
||||||
private static final ByteSource PGP_PUBLIC_KEYRING =
|
private static final ByteSource PGP_PUBLIC_KEYRING =
|
||||||
readResourceBytes(FakeKeyringModule.class, "testdata/pgp-public-keyring.asc");
|
loadBytes(FakeKeyringModule.class, "pgp-public-keyring.asc");
|
||||||
private static final ByteSource PGP_PRIVATE_KEYRING =
|
private static final ByteSource PGP_PRIVATE_KEYRING =
|
||||||
readResourceBytes(FakeKeyringModule.class, "testdata/pgp-private-keyring-registry.asc");
|
loadBytes(FakeKeyringModule.class, "pgp-private-keyring-registry.asc");
|
||||||
private static final String ICANN_REPORTING_PASSWORD = "yolo";
|
private static final String ICANN_REPORTING_PASSWORD = "yolo";
|
||||||
private static final String MARKSDB_DNL_LOGIN = "dnl:yolo";
|
private static final String MARKSDB_DNL_LOGIN = "dnl:yolo";
|
||||||
private static final String MARKSDB_LORDN_PASSWORD = "yolo";
|
private static final String MARKSDB_LORDN_PASSWORD = "yolo";
|
||||||
|
@ -76,10 +76,8 @@ public final class FakeKeyringModule {
|
||||||
PgpHelper.lookupKeyPair(publics, privates, SIGNING_KEY_EMAIL, SIGN);
|
PgpHelper.lookupKeyPair(publics, privates, SIGNING_KEY_EMAIL, SIGN);
|
||||||
final PGPPublicKey rdeReceiverKey =
|
final PGPPublicKey rdeReceiverKey =
|
||||||
PgpHelper.lookupPublicKey(publics, RECEIVER_KEY_EMAIL, ENCRYPT);
|
PgpHelper.lookupPublicKey(publics, RECEIVER_KEY_EMAIL, ENCRYPT);
|
||||||
final String sshPublic =
|
final String sshPublic = loadFile(FakeKeyringModule.class, "registry-unittest.id_rsa.pub");
|
||||||
readResourceUtf8(FakeKeyringModule.class, "testdata/registry-unittest.id_rsa.pub");
|
final String sshPrivate = loadFile(FakeKeyringModule.class, "registry-unittest.id_rsa");
|
||||||
final String sshPrivate =
|
|
||||||
readResourceUtf8(FakeKeyringModule.class, "testdata/registry-unittest.id_rsa");
|
|
||||||
|
|
||||||
return new Keyring() {
|
return new Keyring() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -74,4 +74,12 @@ public final class TestDataHelper {
|
||||||
FileKey.create(context, filename),
|
FileKey.create(context, filename),
|
||||||
k -> readResourceBytes(context, "testdata/" + filename));
|
k -> readResourceBytes(context, "testdata/" + filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the "real" location of the file loaded by the other commands, starting from javatests/.
|
||||||
|
*/
|
||||||
|
public static String filePath(Class<?> context, String filename) {
|
||||||
|
String packagePath = context.getPackage().getName().replace('.', '/');
|
||||||
|
return String.format("javatests/%s/testdata/%s", packagePath, filename);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
package google.registry.tools;
|
package google.registry.tools;
|
||||||
|
|
||||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||||
import static google.registry.util.ResourceUtils.readResourceUtf8;
|
import static google.registry.testing.TestDataHelper.loadFile;
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
|
||||||
import com.beust.jcommander.ParameterException;
|
import com.beust.jcommander.ParameterException;
|
||||||
|
@ -40,8 +40,8 @@ public abstract class CreateOrUpdateReservedListCommandTestCase
|
||||||
public void init() throws IOException {
|
public void init() throws IOException {
|
||||||
File reservedTermsFile = tmpDir.newFile("xn--q9jyb4c_common-reserved.txt");
|
File reservedTermsFile = tmpDir.newFile("xn--q9jyb4c_common-reserved.txt");
|
||||||
File invalidReservedTermsFile = tmpDir.newFile("reserved-terms-wontparse.csv");
|
File invalidReservedTermsFile = tmpDir.newFile("reserved-terms-wontparse.csv");
|
||||||
String reservedTermsCsv = readResourceUtf8(
|
String reservedTermsCsv =
|
||||||
CreateOrUpdateReservedListCommandTestCase.class, "testdata/example_reserved_terms.csv");
|
loadFile(CreateOrUpdateReservedListCommandTestCase.class, "example_reserved_terms.csv");
|
||||||
Files.asCharSink(reservedTermsFile, UTF_8).write(reservedTermsCsv);
|
Files.asCharSink(reservedTermsFile, UTF_8).write(reservedTermsCsv);
|
||||||
Files.asCharSink(invalidReservedTermsFile, UTF_8)
|
Files.asCharSink(invalidReservedTermsFile, UTF_8)
|
||||||
.write("sdfgagmsdgs,sdfgsd\nasdf234tafgs,asdfaw\n\n");
|
.write("sdfgagmsdgs,sdfgsd\nasdf234tafgs,asdfaw\n\n");
|
||||||
|
|
|
@ -17,7 +17,7 @@ package google.registry.tools;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static google.registry.request.JsonResponse.JSON_SAFETY_PREFIX;
|
import static google.registry.request.JsonResponse.JSON_SAFETY_PREFIX;
|
||||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||||
import static google.registry.util.ResourceUtils.readResourceUtf8;
|
import static google.registry.testing.TestDataHelper.loadFile;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyMapOf;
|
import static org.mockito.Matchers.anyMapOf;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
|
@ -48,11 +48,10 @@ public class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
|
||||||
@Before
|
@Before
|
||||||
public void init() throws Exception {
|
public void init() throws Exception {
|
||||||
command.setConnection(connection);
|
command.setConnection(connection);
|
||||||
premiumTermsPath = writeToNamedTmpFile(
|
premiumTermsPath =
|
||||||
"example_premium_terms.csv",
|
writeToNamedTmpFile(
|
||||||
readResourceUtf8(
|
"example_premium_terms.csv",
|
||||||
CreatePremiumListCommandTest.class,
|
loadFile(CreatePremiumListCommandTest.class, "example_premium_terms.csv"));
|
||||||
"testdata/example_premium_terms.csv"));
|
|
||||||
servletPath = "/_dr/admin/createPremiumList";
|
servletPath = "/_dr/admin/createPremiumList";
|
||||||
when(connection.send(
|
when(connection.send(
|
||||||
eq(CreatePremiumListAction.PATH),
|
eq(CreatePremiumListAction.PATH),
|
||||||
|
@ -108,10 +107,10 @@ public class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_invalidInputData() throws Exception {
|
public void testRun_invalidInputData() throws Exception {
|
||||||
premiumTermsPath = writeToNamedTmpFile(
|
premiumTermsPath =
|
||||||
"tmp_file2",
|
writeToNamedTmpFile(
|
||||||
readResourceUtf8(
|
"tmp_file2",
|
||||||
CreatePremiumListCommandTest.class, "testdata/example_invalid_premium_terms.csv"));
|
loadFile(CreatePremiumListCommandTest.class, "example_invalid_premium_terms.csv"));
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
package google.registry.tools;
|
package google.registry.tools;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static google.registry.util.ResourceUtils.readResourceBytes;
|
import static google.registry.testing.TestDataHelper.loadBytes;
|
||||||
|
|
||||||
import com.google.common.io.ByteSource;
|
import com.google.common.io.ByteSource;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
|
@ -39,8 +39,7 @@ public class EncryptEscrowDepositCommandTest
|
||||||
@Rule
|
@Rule
|
||||||
public final BouncyCastleProviderRule bouncy = new BouncyCastleProviderRule();
|
public final BouncyCastleProviderRule bouncy = new BouncyCastleProviderRule();
|
||||||
|
|
||||||
private final ByteSource depositXml =
|
private final ByteSource depositXml = loadBytes(RdeTestData.class, "deposit_full.xml");
|
||||||
readResourceBytes(RdeTestData.class, "testdata/deposit_full.xml");
|
|
||||||
|
|
||||||
static EscrowDepositEncryptor createEncryptor() {
|
static EscrowDepositEncryptor createEncryptor() {
|
||||||
EscrowDepositEncryptor res = new EscrowDepositEncryptor();
|
EscrowDepositEncryptor res = new EscrowDepositEncryptor();
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
package google.registry.tools;
|
package google.registry.tools;
|
||||||
|
|
||||||
import static google.registry.request.JsonResponse.JSON_SAFETY_PREFIX;
|
import static google.registry.request.JsonResponse.JSON_SAFETY_PREFIX;
|
||||||
import static google.registry.util.ResourceUtils.readResourceUtf8;
|
import static google.registry.testing.TestDataHelper.loadFile;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyMapOf;
|
import static org.mockito.Matchers.anyMapOf;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
|
@ -44,11 +44,10 @@ public class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
|
||||||
public void init() throws Exception {
|
public void init() throws Exception {
|
||||||
command.setConnection(connection);
|
command.setConnection(connection);
|
||||||
servletPath = "/_dr/admin/updatePremiumList";
|
servletPath = "/_dr/admin/updatePremiumList";
|
||||||
premiumTermsPath = writeToNamedTmpFile(
|
premiumTermsPath =
|
||||||
"example_premium_terms.csv",
|
writeToNamedTmpFile(
|
||||||
readResourceUtf8(
|
"example_premium_terms.csv",
|
||||||
UpdatePremiumListCommandTest.class,
|
loadFile(UpdatePremiumListCommandTest.class, "example_premium_terms.csv"));
|
||||||
"testdata/example_premium_terms.csv"));
|
|
||||||
when(connection.send(
|
when(connection.send(
|
||||||
eq(UpdatePremiumListAction.PATH),
|
eq(UpdatePremiumListAction.PATH),
|
||||||
anyMapOf(String.class, String.class),
|
anyMapOf(String.class, String.class),
|
||||||
|
|
|
@ -23,7 +23,7 @@ import static google.registry.testing.DatastoreHelper.newDomainApplication;
|
||||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||||
import static google.registry.testing.DomainApplicationSubject.assertAboutApplications;
|
import static google.registry.testing.DomainApplicationSubject.assertAboutApplications;
|
||||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||||
import static google.registry.util.ResourceUtils.readResourceUtf8;
|
import static google.registry.testing.TestDataHelper.loadFile;
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
@ -56,15 +56,13 @@ public class UpdateSmdCommandTest extends CommandTestCase<UpdateSmdCommand> {
|
||||||
DomainApplication domainApplication;
|
DomainApplication domainApplication;
|
||||||
|
|
||||||
private static final String ACTIVE_SMD =
|
private static final String ACTIVE_SMD =
|
||||||
readResourceUtf8(UpdateSmdCommandTest.class, "testdata/Court-Agent-English-Active.smd");
|
loadFile(UpdateSmdCommandTest.class, "Court-Agent-English-Active.smd");
|
||||||
private static final String DIFFERENT_LABEL_SMD =
|
private static final String DIFFERENT_LABEL_SMD =
|
||||||
readResourceUtf8(UpdateSmdCommandTest.class, "testdata/Court-Agent-Chinese-Active.smd");
|
loadFile(UpdateSmdCommandTest.class, "Court-Agent-Chinese-Active.smd");
|
||||||
private static final String INVALID_SMD =
|
private static final String INVALID_SMD =
|
||||||
readResourceUtf8(UpdateSmdCommandTest.class,
|
loadFile(UpdateSmdCommandTest.class, "InvalidSignature-Trademark-Agent-English-Active.smd");
|
||||||
"testdata/InvalidSignature-Trademark-Agent-English-Active.smd");
|
|
||||||
private static final String REVOKED_TMV_SMD =
|
private static final String REVOKED_TMV_SMD =
|
||||||
readResourceUtf8(UpdateSmdCommandTest.class,
|
loadFile(UpdateSmdCommandTest.class, "TMVRevoked-Trademark-Agent-English-Active.smd");
|
||||||
"testdata/TMVRevoked-Trademark-Agent-English-Active.smd");
|
|
||||||
|
|
||||||
// The test data was created by ICANN on 2013. It includes SMDs that expire sometime during 2017.
|
// The test data was created by ICANN on 2013. It includes SMDs that expire sometime during 2017.
|
||||||
// We want the "current date" to be sometime between 2013 and 2017.
|
// We want the "current date" to be sometime between 2013 and 2017.
|
||||||
|
|
|
@ -25,7 +25,7 @@ import static google.registry.testing.DatastoreHelper.persistActiveDomainApplica
|
||||||
import static google.registry.testing.DatastoreHelper.persistActiveHost;
|
import static google.registry.testing.DatastoreHelper.persistActiveHost;
|
||||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||||
import static google.registry.testing.GcsTestingUtils.readGcsFile;
|
import static google.registry.testing.GcsTestingUtils.readGcsFile;
|
||||||
import static google.registry.util.ResourceUtils.readResourceUtf8;
|
import static google.registry.testing.TestDataHelper.loadFile;
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
import static org.joda.time.Duration.standardDays;
|
import static org.joda.time.Duration.standardDays;
|
||||||
|
|
||||||
|
@ -144,8 +144,7 @@ public class GenerateZoneFilesActionTest extends MapreduceTestCase<GenerateZoneF
|
||||||
// files with literal tabs irritate our build tools.
|
// files with literal tabs irritate our build tools.
|
||||||
Splitter splitter = Splitter.on('\n').omitEmptyStrings();
|
Splitter splitter = Splitter.on('\n').omitEmptyStrings();
|
||||||
Iterable<String> generatedFileLines = splitter.split(generatedFile.replaceAll("\t", " "));
|
Iterable<String> generatedFileLines = splitter.split(generatedFile.replaceAll("\t", " "));
|
||||||
Iterable<String> goldenFileLines =
|
Iterable<String> goldenFileLines = splitter.split(loadFile(getClass(), "tld.zone"));
|
||||||
splitter.split(readResourceUtf8(getClass(), "testdata/tld.zone"));
|
|
||||||
// The first line needs to be the same as the golden file.
|
// The first line needs to be the same as the golden file.
|
||||||
assertThat(generatedFileLines.iterator().next()).isEqualTo(goldenFileLines.iterator().next());
|
assertThat(generatedFileLines.iterator().next()).isEqualTo(goldenFileLines.iterator().next());
|
||||||
// The remaining lines can be in any order.
|
// The remaining lines can be in any order.
|
||||||
|
|
|
@ -21,7 +21,7 @@ import static google.registry.security.JsonHttpTestUtils.createJsonPayload;
|
||||||
import static google.registry.testing.DatastoreHelper.loadRegistrar;
|
import static google.registry.testing.DatastoreHelper.loadRegistrar;
|
||||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||||
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
|
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
|
||||||
import static google.registry.util.ResourceUtils.readResourceUtf8;
|
import static google.registry.testing.TestDataHelper.loadFile;
|
||||||
import static org.mockito.Matchers.anyInt;
|
import static org.mockito.Matchers.anyInt;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
|
@ -133,7 +133,7 @@ public class RegistrarPremiumPriceAckActionTest {
|
||||||
assertThat(loadRegistrar(CLIENT_ID).getPremiumPriceAckRequired()).isTrue();
|
assertThat(loadRegistrar(CLIENT_ID).getPremiumPriceAckRequired()).isTrue();
|
||||||
|
|
||||||
// Verify that we sent notification emails.
|
// Verify that we sent notification emails.
|
||||||
String expectedEmailBody = readResourceUtf8(getClass(), "testdata/update_ppa_email.txt");
|
String expectedEmailBody = loadFile(getClass(), "update_ppa_email.txt");
|
||||||
verify(rsp, never()).setStatus(anyInt());
|
verify(rsp, never()).setStatus(anyInt());
|
||||||
verify(emailService).createMessage();
|
verify(emailService).createMessage();
|
||||||
verify(emailService).sendMessage(message);
|
verify(emailService).sendMessage(message);
|
||||||
|
|
|
@ -20,7 +20,7 @@ import static google.registry.testing.DatastoreHelper.persistResource;
|
||||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||||
import static google.registry.testing.TaskQueueHelper.assertNoTasksEnqueued;
|
import static google.registry.testing.TaskQueueHelper.assertNoTasksEnqueued;
|
||||||
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
|
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
|
||||||
import static google.registry.util.ResourceUtils.readResourceUtf8;
|
import static google.registry.testing.TestDataHelper.loadFile;
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyInt;
|
import static org.mockito.Matchers.anyInt;
|
||||||
|
@ -46,8 +46,8 @@ public class RegistrarSettingsActionTest extends RegistrarSettingsActionTestCase
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_updateRegistrarInfo_andSendsNotificationEmail() throws Exception {
|
public void testSuccess_updateRegistrarInfo_andSendsNotificationEmail() throws Exception {
|
||||||
String expectedEmailBody = readResourceUtf8(getClass(), "testdata/update_registrar_email.txt");
|
String expectedEmailBody = loadFile(getClass(), "update_registrar_email.txt");
|
||||||
action.handleJsonRequest(readJsonFromFile("testdata/update_registrar.json"));
|
action.handleJsonRequest(readJsonFromFile("update_registrar.json"));
|
||||||
verify(rsp, never()).setStatus(anyInt());
|
verify(rsp, never()).setStatus(anyInt());
|
||||||
verify(emailService).createMessage();
|
verify(emailService).createMessage();
|
||||||
verify(emailService).sendMessage(message);
|
verify(emailService).sendMessage(message);
|
||||||
|
@ -63,8 +63,8 @@ public class RegistrarSettingsActionTest extends RegistrarSettingsActionTestCase
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_updateRegistrarInfo_duplicateContacts() throws Exception {
|
public void testFailure_updateRegistrarInfo_duplicateContacts() throws Exception {
|
||||||
Map<String, Object> response = action.handleJsonRequest(
|
Map<String, Object> response =
|
||||||
readJsonFromFile("testdata/update_registrar_duplicate_contacts.json"));
|
action.handleJsonRequest(readJsonFromFile("update_registrar_duplicate_contacts.json"));
|
||||||
assertThat(response).containsEntry("status", "ERROR");
|
assertThat(response).containsEntry("status", "ERROR");
|
||||||
assertThat((String) response.get("message")).startsWith("One email address");
|
assertThat((String) response.get("message")).startsWith("One email address");
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ import static google.registry.config.RegistryConfig.getGSuiteOutgoingEmailDispla
|
||||||
import static google.registry.security.JsonHttpTestUtils.createJsonPayload;
|
import static google.registry.security.JsonHttpTestUtils.createJsonPayload;
|
||||||
import static google.registry.security.JsonHttpTestUtils.createJsonResponseSupplier;
|
import static google.registry.security.JsonHttpTestUtils.createJsonResponseSupplier;
|
||||||
import static google.registry.testing.DatastoreHelper.loadRegistrar;
|
import static google.registry.testing.DatastoreHelper.loadRegistrar;
|
||||||
import static google.registry.util.ResourceUtils.readResourceUtf8;
|
import static google.registry.testing.TestDataHelper.loadFile;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ public class RegistrarSettingsActionTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
static Map<String, Object> readJsonFromFile(String filename) {
|
static Map<String, Object> readJsonFromFile(String filename) {
|
||||||
String contents = readResourceUtf8(RegistrarSettingsActionTestCase.class, filename);
|
String contents = loadFile(RegistrarSettingsActionTestCase.class, filename);
|
||||||
try {
|
try {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, Object> json = (Map<String, Object>) JSONValue.parseWithException(contents);
|
Map<String, Object> json = (Map<String, Object>) JSONValue.parseWithException(contents);
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
package google.registry.xjc;
|
package google.registry.xjc;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static google.registry.util.ResourceUtils.readResourceUtf8;
|
import static google.registry.testing.TestDataHelper.loadFile;
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
|
||||||
import google.registry.xjc.rdehost.XjcRdeHostElement;
|
import google.registry.xjc.rdehost.XjcRdeHostElement;
|
||||||
|
@ -31,8 +31,7 @@ import org.junit.runners.JUnit4;
|
||||||
@RunWith(JUnit4.class)
|
@RunWith(JUnit4.class)
|
||||||
public class JaxbFragmentTest {
|
public class JaxbFragmentTest {
|
||||||
|
|
||||||
private static final String HOST_FRAGMENT =
|
private static final String HOST_FRAGMENT = loadFile(XjcObjectTest.class, "host_fragment.xml");
|
||||||
readResourceUtf8(XjcObjectTest.class, "testdata/host_fragment.xml");
|
|
||||||
|
|
||||||
/** Verifies that a {@link JaxbFragment} can be serialized and deserialized successfully. */
|
/** Verifies that a {@link JaxbFragment} can be serialized and deserialized successfully. */
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
|
|
@ -17,7 +17,8 @@ package google.registry.xjc;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static com.google.common.truth.Truth.assertWithMessage;
|
import static com.google.common.truth.Truth.assertWithMessage;
|
||||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||||
import static google.registry.util.ResourceUtils.readResourceUtf8;
|
import static google.registry.testing.TestDataHelper.loadBytes;
|
||||||
|
import static google.registry.testing.TestDataHelper.loadFile;
|
||||||
import static google.registry.xjc.XjcXmlTransformer.unmarshal;
|
import static google.registry.xjc.XjcXmlTransformer.unmarshal;
|
||||||
import static java.nio.charset.StandardCharsets.UTF_16;
|
import static java.nio.charset.StandardCharsets.UTF_16;
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
@ -36,7 +37,7 @@ import org.junit.runners.JUnit4;
|
||||||
@RunWith(JUnit4.class)
|
@RunWith(JUnit4.class)
|
||||||
public class XjcObjectTest {
|
public class XjcObjectTest {
|
||||||
private static final String RDE_DEPOSIT_FULL =
|
private static final String RDE_DEPOSIT_FULL =
|
||||||
readResourceUtf8(XjcObjectTest.class, "testdata/rde_deposit_full.xml");
|
loadFile(XjcObjectTest.class, "rde_deposit_full.xml");
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMarshalUtf8() throws Exception {
|
public void testMarshalUtf8() throws Exception {
|
||||||
|
@ -116,8 +117,9 @@ public class XjcObjectTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNamespaceEpp() throws Exception {
|
public void testNamespaceEpp() throws Exception {
|
||||||
String xml = unmarshal(XjcObject.class, new ByteArrayInputStream(readResourceUtf8(
|
String xml =
|
||||||
XjcObjectTest.class, "testdata/greeting.xml").getBytes(UTF_8))).toString();
|
unmarshal(XjcObject.class, loadBytes(XjcObjectTest.class, "greeting.xml").openStream())
|
||||||
|
.toString();
|
||||||
assertWithMessage(xml).that(xml).startsWith("<epp:epp ");
|
assertWithMessage(xml).that(xml).startsWith("<epp:epp ");
|
||||||
assertWithMessage(xml).that(xml).contains("\"urn:ietf:params:xml:ns:epp-1.0\"");
|
assertWithMessage(xml).that(xml).contains("\"urn:ietf:params:xml:ns:epp-1.0\"");
|
||||||
assertWithMessage(xml).that(xml).contains("<epp:greeting>");
|
assertWithMessage(xml).that(xml).contains("<epp:greeting>");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue