From 6699915132a2501f1a7d0f6c3791663e37b21ddb Mon Sep 17 00:00:00 2001 From: guyben Date: Thu, 5 Apr 2018 13:01:59 -0700 Subject: [PATCH] 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 --- .../registry/flows/EppXmlTransformerTest.java | 8 +++----- .../registry/model/eppinput/EppInputTest.java | 14 ++++---------- .../registry/rde/RdeStagingActionTest.java | 13 ++++++------- .../registry/testing/FakeKeyringModule.java | 14 ++++++-------- .../registry/testing/TestDataHelper.java | 8 ++++++++ ...teOrUpdateReservedListCommandTestCase.java | 6 +++--- .../tools/CreatePremiumListCommandTest.java | 19 +++++++++---------- .../EncryptEscrowDepositCommandTest.java | 5 ++--- .../tools/UpdatePremiumListCommandTest.java | 11 +++++------ .../registry/tools/UpdateSmdCommandTest.java | 12 +++++------- .../server/GenerateZoneFilesActionTest.java | 5 ++--- .../RegistrarPremiumPriceAckActionTest.java | 4 ++-- .../RegistrarSettingsActionTest.java | 10 +++++----- .../RegistrarSettingsActionTestCase.java | 4 ++-- .../google/registry/xjc/JaxbFragmentTest.java | 5 ++--- .../google/registry/xjc/XjcObjectTest.java | 10 ++++++---- 16 files changed, 70 insertions(+), 78 deletions(-) diff --git a/javatests/google/registry/flows/EppXmlTransformerTest.java b/javatests/google/registry/flows/EppXmlTransformerTest.java index d9de68152..e754ce098 100644 --- a/javatests/google/registry/flows/EppXmlTransformerTest.java +++ b/javatests/google/registry/flows/EppXmlTransformerTest.java @@ -18,7 +18,7 @@ package google.registry.flows; import static com.google.common.truth.Truth.assertThat; import static google.registry.flows.EppXmlTransformer.unmarshal; 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.eppoutput.EppOutput; @@ -33,8 +33,7 @@ public class EppXmlTransformerTest extends ShardableTestCase { @Test public void testUnmarshalingEppInput() throws Exception { - EppInput input = unmarshal( - EppInput.class, readResourceBytes(getClass(), "testdata/contact_info.xml").read()); + EppInput input = unmarshal(EppInput.class, loadBytes(getClass(), "contact_info.xml").read()); assertThat(input.getCommandType()).isEqualTo("info"); } @@ -44,7 +43,6 @@ public class EppXmlTransformerTest extends ShardableTestCase { ClassCastException.class, () -> EppXmlTransformer.unmarshal( - EppOutput.class, - readResourceBytes(getClass(), "testdata/contact_info.xml").read())); + EppOutput.class, loadBytes(getClass(), "contact_info.xml").read())); } } diff --git a/javatests/google/registry/model/eppinput/EppInputTest.java b/javatests/google/registry/model/eppinput/EppInputTest.java index 6d1bac6ab..f7bc46b3e 100644 --- a/javatests/google/registry/model/eppinput/EppInputTest.java +++ b/javatests/google/registry/model/eppinput/EppInputTest.java @@ -17,7 +17,7 @@ package google.registry.model.eppinput; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth8.assertThat; 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.domain.DomainResourceTest; @@ -34,9 +34,7 @@ public class EppInputTest { @Test public void testUnmarshalling_contactInfo() throws Exception { EppInput input = - unmarshal( - EppInput.class, - readResourceBytes(ContactResourceTest.class, "testdata/contact_info.xml").read()); + unmarshal(EppInput.class, loadBytes(ContactResourceTest.class, "contact_info.xml").read()); assertThat(input.getCommandWrapper().getClTrid()).isEqualTo("ABC-12345"); assertThat(input.getCommandType()).isEqualTo("info"); assertThat(input.getResourceType()).hasValue("contact"); @@ -47,9 +45,7 @@ public class EppInputTest { @Test public void testUnmarshalling_domainCheck() throws Exception { EppInput input = - unmarshal( - EppInput.class, - readResourceBytes(DomainResourceTest.class, "testdata/domain_check.xml").read()); + unmarshal(EppInput.class, loadBytes(DomainResourceTest.class, "domain_check.xml").read()); assertThat(input.getCommandWrapper().getClTrid()).isEqualTo("ABC-12345"); assertThat(input.getCommandType()).isEqualTo("check"); assertThat(input.getResourceType()).hasValue("domain"); @@ -59,8 +55,7 @@ public class EppInputTest { @Test public void testUnmarshalling_login() throws Exception { - EppInput input = - unmarshal(EppInput.class, readResourceBytes(getClass(), "testdata/login_valid.xml").read()); + EppInput input = unmarshal(EppInput.class, loadBytes(getClass(), "login_valid.xml").read()); assertThat(input.getCommandWrapper().getClTrid()).isEqualTo("ABC-12345"); assertThat(input.getCommandType()).isEqualTo("login"); 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"); } } - diff --git a/javatests/google/registry/rde/RdeStagingActionTest.java b/javatests/google/registry/rde/RdeStagingActionTest.java index 2221fc045..b947eaf18 100644 --- a/javatests/google/registry/rde/RdeStagingActionTest.java +++ b/javatests/google/registry/rde/RdeStagingActionTest.java @@ -30,8 +30,8 @@ import static google.registry.testing.JUnitBackports.assertThrows; import static google.registry.testing.TaskQueueHelper.assertAtLeastOneTaskIsEnqueued; import static google.registry.testing.TaskQueueHelper.assertNoTasksEnqueued; 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.util.ResourceUtils.readResourceUtf8; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Arrays.asList; @@ -550,7 +550,7 @@ public class RdeStagingActionTest extends MapreduceTestCase { executeTasksUntilEmpty("mapreduce", clock); 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"), "deposit.contents.registrar.crDate", "deposit.contents.registrar.upDate"); @@ -582,7 +582,7 @@ public class RdeStagingActionTest extends MapreduceTestCase { executeTasksUntilEmpty("mapreduce", clock); 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"), "deposit.contents.registrar.crDate", "deposit.contents.registrar.upDate"); @@ -799,14 +799,13 @@ public class RdeStagingActionTest extends MapreduceTestCase { throws Exception { doManualModeMapReduceTest(0, ImmutableSet.of("lol")); 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"), "deposit.contents.registrar.crDate", "deposit.contents.registrar.upDate"); XmlTestUtils.assertXmlEquals( - readResourceUtf8(getClass(), "testdata/testMapReduce_withDomain_producesReportXml.xml"), - readXml( - "manual/test/lol_2000-01-01_full_S1_R0-report.xml.ghostryde"), + loadFile(getClass(), "testMapReduce_withDomain_producesReportXml.xml"), + readXml("manual/test/lol_2000-01-01_full_S1_R0-report.xml.ghostryde"), "deposit.contents.registrar.crDate", "deposit.contents.registrar.upDate"); } diff --git a/javatests/google/registry/testing/FakeKeyringModule.java b/javatests/google/registry/testing/FakeKeyringModule.java index 0a56d0cff..ba90ca2f2 100644 --- a/javatests/google/registry/testing/FakeKeyringModule.java +++ b/javatests/google/registry/testing/FakeKeyringModule.java @@ -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.SIGN; -import static google.registry.util.ResourceUtils.readResourceBytes; -import static google.registry.util.ResourceUtils.readResourceUtf8; +import static google.registry.testing.TestDataHelper.loadBytes; +import static google.registry.testing.TestDataHelper.loadFile; import com.google.common.io.ByteSource; 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 RECEIVER_KEY_EMAIL = "rde-unittest@escrow.test"; 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 = - 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 MARKSDB_DNL_LOGIN = "dnl: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); final PGPPublicKey rdeReceiverKey = PgpHelper.lookupPublicKey(publics, RECEIVER_KEY_EMAIL, ENCRYPT); - final String sshPublic = - readResourceUtf8(FakeKeyringModule.class, "testdata/registry-unittest.id_rsa.pub"); - final String sshPrivate = - readResourceUtf8(FakeKeyringModule.class, "testdata/registry-unittest.id_rsa"); + final String sshPublic = loadFile(FakeKeyringModule.class, "registry-unittest.id_rsa.pub"); + final String sshPrivate = loadFile(FakeKeyringModule.class, "registry-unittest.id_rsa"); return new Keyring() { @Override diff --git a/javatests/google/registry/testing/TestDataHelper.java b/javatests/google/registry/testing/TestDataHelper.java index c7730bdc8..04e1bfecb 100644 --- a/javatests/google/registry/testing/TestDataHelper.java +++ b/javatests/google/registry/testing/TestDataHelper.java @@ -74,4 +74,12 @@ public final class TestDataHelper { FileKey.create(context, 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); + } } diff --git a/javatests/google/registry/tools/CreateOrUpdateReservedListCommandTestCase.java b/javatests/google/registry/tools/CreateOrUpdateReservedListCommandTestCase.java index f1298cb2f..fa477441e 100644 --- a/javatests/google/registry/tools/CreateOrUpdateReservedListCommandTestCase.java +++ b/javatests/google/registry/tools/CreateOrUpdateReservedListCommandTestCase.java @@ -15,7 +15,7 @@ package google.registry.tools; 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 com.beust.jcommander.ParameterException; @@ -40,8 +40,8 @@ public abstract class CreateOrUpdateReservedListCommandTestCase public void init() throws IOException { File reservedTermsFile = tmpDir.newFile("xn--q9jyb4c_common-reserved.txt"); File invalidReservedTermsFile = tmpDir.newFile("reserved-terms-wontparse.csv"); - String reservedTermsCsv = readResourceUtf8( - CreateOrUpdateReservedListCommandTestCase.class, "testdata/example_reserved_terms.csv"); + String reservedTermsCsv = + loadFile(CreateOrUpdateReservedListCommandTestCase.class, "example_reserved_terms.csv"); Files.asCharSink(reservedTermsFile, UTF_8).write(reservedTermsCsv); Files.asCharSink(invalidReservedTermsFile, UTF_8) .write("sdfgagmsdgs,sdfgsd\nasdf234tafgs,asdfaw\n\n"); diff --git a/javatests/google/registry/tools/CreatePremiumListCommandTest.java b/javatests/google/registry/tools/CreatePremiumListCommandTest.java index 0cbf1df07..89c1ed758 100644 --- a/javatests/google/registry/tools/CreatePremiumListCommandTest.java +++ b/javatests/google/registry/tools/CreatePremiumListCommandTest.java @@ -17,7 +17,7 @@ package google.registry.tools; import static com.google.common.truth.Truth.assertThat; import static google.registry.request.JsonResponse.JSON_SAFETY_PREFIX; 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.anyMapOf; import static org.mockito.Matchers.eq; @@ -48,11 +48,10 @@ public class CreatePremiumListCommandTest @Before public void init() throws Exception { command.setConnection(connection); - premiumTermsPath = writeToNamedTmpFile( - "example_premium_terms.csv", - readResourceUtf8( - CreatePremiumListCommandTest.class, - "testdata/example_premium_terms.csv")); + premiumTermsPath = + writeToNamedTmpFile( + "example_premium_terms.csv", + loadFile(CreatePremiumListCommandTest.class, "example_premium_terms.csv")); servletPath = "/_dr/admin/createPremiumList"; when(connection.send( eq(CreatePremiumListAction.PATH), @@ -108,10 +107,10 @@ public class CreatePremiumListCommandTest @Test public void testRun_invalidInputData() throws Exception { - premiumTermsPath = writeToNamedTmpFile( - "tmp_file2", - readResourceUtf8( - CreatePremiumListCommandTest.class, "testdata/example_invalid_premium_terms.csv")); + premiumTermsPath = + writeToNamedTmpFile( + "tmp_file2", + loadFile(CreatePremiumListCommandTest.class, "example_invalid_premium_terms.csv")); IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, diff --git a/javatests/google/registry/tools/EncryptEscrowDepositCommandTest.java b/javatests/google/registry/tools/EncryptEscrowDepositCommandTest.java index 78f92bddb..51bc9239f 100644 --- a/javatests/google/registry/tools/EncryptEscrowDepositCommandTest.java +++ b/javatests/google/registry/tools/EncryptEscrowDepositCommandTest.java @@ -15,7 +15,7 @@ package google.registry.tools; 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.Files; @@ -39,8 +39,7 @@ public class EncryptEscrowDepositCommandTest @Rule public final BouncyCastleProviderRule bouncy = new BouncyCastleProviderRule(); - private final ByteSource depositXml = - readResourceBytes(RdeTestData.class, "testdata/deposit_full.xml"); + private final ByteSource depositXml = loadBytes(RdeTestData.class, "deposit_full.xml"); static EscrowDepositEncryptor createEncryptor() { EscrowDepositEncryptor res = new EscrowDepositEncryptor(); diff --git a/javatests/google/registry/tools/UpdatePremiumListCommandTest.java b/javatests/google/registry/tools/UpdatePremiumListCommandTest.java index de4eca826..bc85f0ab7 100644 --- a/javatests/google/registry/tools/UpdatePremiumListCommandTest.java +++ b/javatests/google/registry/tools/UpdatePremiumListCommandTest.java @@ -15,7 +15,7 @@ package google.registry.tools; 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.anyMapOf; import static org.mockito.Matchers.eq; @@ -44,11 +44,10 @@ public class UpdatePremiumListCommandTest public void init() throws Exception { command.setConnection(connection); servletPath = "/_dr/admin/updatePremiumList"; - premiumTermsPath = writeToNamedTmpFile( - "example_premium_terms.csv", - readResourceUtf8( - UpdatePremiumListCommandTest.class, - "testdata/example_premium_terms.csv")); + premiumTermsPath = + writeToNamedTmpFile( + "example_premium_terms.csv", + loadFile(UpdatePremiumListCommandTest.class, "example_premium_terms.csv")); when(connection.send( eq(UpdatePremiumListAction.PATH), anyMapOf(String.class, String.class), diff --git a/javatests/google/registry/tools/UpdateSmdCommandTest.java b/javatests/google/registry/tools/UpdateSmdCommandTest.java index 014a9dff0..9900b4bc6 100644 --- a/javatests/google/registry/tools/UpdateSmdCommandTest.java +++ b/javatests/google/registry/tools/UpdateSmdCommandTest.java @@ -23,7 +23,7 @@ import static google.registry.testing.DatastoreHelper.newDomainApplication; import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DomainApplicationSubject.assertAboutApplications; 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 com.google.common.collect.ImmutableList; @@ -56,15 +56,13 @@ public class UpdateSmdCommandTest extends CommandTestCase { DomainApplication domainApplication; 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 = - readResourceUtf8(UpdateSmdCommandTest.class, "testdata/Court-Agent-Chinese-Active.smd"); + loadFile(UpdateSmdCommandTest.class, "Court-Agent-Chinese-Active.smd"); private static final String INVALID_SMD = - readResourceUtf8(UpdateSmdCommandTest.class, - "testdata/InvalidSignature-Trademark-Agent-English-Active.smd"); + loadFile(UpdateSmdCommandTest.class, "InvalidSignature-Trademark-Agent-English-Active.smd"); private static final String REVOKED_TMV_SMD = - readResourceUtf8(UpdateSmdCommandTest.class, - "testdata/TMVRevoked-Trademark-Agent-English-Active.smd"); + loadFile(UpdateSmdCommandTest.class, "TMVRevoked-Trademark-Agent-English-Active.smd"); // 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. diff --git a/javatests/google/registry/tools/server/GenerateZoneFilesActionTest.java b/javatests/google/registry/tools/server/GenerateZoneFilesActionTest.java index 1cb4f6361..6a4f1ad29 100644 --- a/javatests/google/registry/tools/server/GenerateZoneFilesActionTest.java +++ b/javatests/google/registry/tools/server/GenerateZoneFilesActionTest.java @@ -25,7 +25,7 @@ import static google.registry.testing.DatastoreHelper.persistActiveDomainApplica import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistResource; 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 org.joda.time.Duration.standardDays; @@ -144,8 +144,7 @@ public class GenerateZoneFilesActionTest extends MapreduceTestCase generatedFileLines = splitter.split(generatedFile.replaceAll("\t", " ")); - Iterable goldenFileLines = - splitter.split(readResourceUtf8(getClass(), "testdata/tld.zone")); + Iterable goldenFileLines = splitter.split(loadFile(getClass(), "tld.zone")); // The first line needs to be the same as the golden file. assertThat(generatedFileLines.iterator().next()).isEqualTo(goldenFileLines.iterator().next()); // The remaining lines can be in any order. diff --git a/javatests/google/registry/ui/server/registrar/RegistrarPremiumPriceAckActionTest.java b/javatests/google/registry/ui/server/registrar/RegistrarPremiumPriceAckActionTest.java index 04748393c..bd08a09ca 100644 --- a/javatests/google/registry/ui/server/registrar/RegistrarPremiumPriceAckActionTest.java +++ b/javatests/google/registry/ui/server/registrar/RegistrarPremiumPriceAckActionTest.java @@ -21,7 +21,7 @@ import static google.registry.security.JsonHttpTestUtils.createJsonPayload; import static google.registry.testing.DatastoreHelper.loadRegistrar; import static google.registry.testing.DatastoreHelper.persistResource; 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.Mockito.mock; import static org.mockito.Mockito.never; @@ -133,7 +133,7 @@ public class RegistrarPremiumPriceAckActionTest { assertThat(loadRegistrar(CLIENT_ID).getPremiumPriceAckRequired()).isTrue(); // 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(emailService).createMessage(); verify(emailService).sendMessage(message); diff --git a/javatests/google/registry/ui/server/registrar/RegistrarSettingsActionTest.java b/javatests/google/registry/ui/server/registrar/RegistrarSettingsActionTest.java index 650158cdc..48f453804 100644 --- a/javatests/google/registry/ui/server/registrar/RegistrarSettingsActionTest.java +++ b/javatests/google/registry/ui/server/registrar/RegistrarSettingsActionTest.java @@ -20,7 +20,7 @@ import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.JUnitBackports.assertThrows; import static google.registry.testing.TaskQueueHelper.assertNoTasksEnqueued; 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 org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; @@ -46,8 +46,8 @@ public class RegistrarSettingsActionTest extends RegistrarSettingsActionTestCase @Test public void testSuccess_updateRegistrarInfo_andSendsNotificationEmail() throws Exception { - String expectedEmailBody = readResourceUtf8(getClass(), "testdata/update_registrar_email.txt"); - action.handleJsonRequest(readJsonFromFile("testdata/update_registrar.json")); + String expectedEmailBody = loadFile(getClass(), "update_registrar_email.txt"); + action.handleJsonRequest(readJsonFromFile("update_registrar.json")); verify(rsp, never()).setStatus(anyInt()); verify(emailService).createMessage(); verify(emailService).sendMessage(message); @@ -63,8 +63,8 @@ public class RegistrarSettingsActionTest extends RegistrarSettingsActionTestCase @Test public void testFailure_updateRegistrarInfo_duplicateContacts() throws Exception { - Map response = action.handleJsonRequest( - readJsonFromFile("testdata/update_registrar_duplicate_contacts.json")); + Map response = + action.handleJsonRequest(readJsonFromFile("update_registrar_duplicate_contacts.json")); assertThat(response).containsEntry("status", "ERROR"); assertThat((String) response.get("message")).startsWith("One email address"); } diff --git a/javatests/google/registry/ui/server/registrar/RegistrarSettingsActionTestCase.java b/javatests/google/registry/ui/server/registrar/RegistrarSettingsActionTestCase.java index b10c325d0..9fb60d424 100644 --- a/javatests/google/registry/ui/server/registrar/RegistrarSettingsActionTestCase.java +++ b/javatests/google/registry/ui/server/registrar/RegistrarSettingsActionTestCase.java @@ -19,7 +19,7 @@ import static google.registry.config.RegistryConfig.getGSuiteOutgoingEmailDispla import static google.registry.security.JsonHttpTestUtils.createJsonPayload; import static google.registry.security.JsonHttpTestUtils.createJsonResponseSupplier; 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.when; @@ -116,7 +116,7 @@ public class RegistrarSettingsActionTestCase { } static Map readJsonFromFile(String filename) { - String contents = readResourceUtf8(RegistrarSettingsActionTestCase.class, filename); + String contents = loadFile(RegistrarSettingsActionTestCase.class, filename); try { @SuppressWarnings("unchecked") Map json = (Map) JSONValue.parseWithException(contents); diff --git a/javatests/google/registry/xjc/JaxbFragmentTest.java b/javatests/google/registry/xjc/JaxbFragmentTest.java index 780598e51..009eb0a4a 100644 --- a/javatests/google/registry/xjc/JaxbFragmentTest.java +++ b/javatests/google/registry/xjc/JaxbFragmentTest.java @@ -15,7 +15,7 @@ package google.registry.xjc; 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 google.registry.xjc.rdehost.XjcRdeHostElement; @@ -31,8 +31,7 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public class JaxbFragmentTest { - private static final String HOST_FRAGMENT = - readResourceUtf8(XjcObjectTest.class, "testdata/host_fragment.xml"); + private static final String HOST_FRAGMENT = loadFile(XjcObjectTest.class, "host_fragment.xml"); /** Verifies that a {@link JaxbFragment} can be serialized and deserialized successfully. */ @SuppressWarnings("unchecked") diff --git a/javatests/google/registry/xjc/XjcObjectTest.java b/javatests/google/registry/xjc/XjcObjectTest.java index ffd34eae0..aa66f5f41 100644 --- a/javatests/google/registry/xjc/XjcObjectTest.java +++ b/javatests/google/registry/xjc/XjcObjectTest.java @@ -17,7 +17,8 @@ package google.registry.xjc; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; 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 java.nio.charset.StandardCharsets.UTF_16; import static java.nio.charset.StandardCharsets.UTF_8; @@ -36,7 +37,7 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public class XjcObjectTest { private static final String RDE_DEPOSIT_FULL = - readResourceUtf8(XjcObjectTest.class, "testdata/rde_deposit_full.xml"); + loadFile(XjcObjectTest.class, "rde_deposit_full.xml"); @Test public void testMarshalUtf8() throws Exception { @@ -116,8 +117,9 @@ public class XjcObjectTest { @Test public void testNamespaceEpp() throws Exception { - String xml = unmarshal(XjcObject.class, new ByteArrayInputStream(readResourceUtf8( - XjcObjectTest.class, "testdata/greeting.xml").getBytes(UTF_8))).toString(); + String xml = + unmarshal(XjcObject.class, loadBytes(XjcObjectTest.class, "greeting.xml").openStream()) + .toString(); assertWithMessage(xml).that(xml).startsWith("");