diff --git a/core/src/main/java/google/registry/export/ExportPremiumTermsAction.java b/core/src/main/java/google/registry/export/ExportPremiumTermsAction.java index 8c8af6eb9ad..03696d27319 100644 --- a/core/src/main/java/google/registry/export/ExportPremiumTermsAction.java +++ b/core/src/main/java/google/registry/export/ExportPremiumTermsAction.java @@ -54,7 +54,8 @@ public class ExportPremiumTermsAction implements Runnable { private static final FluentLogger logger = FluentLogger.forEnclosingClass(); static final MediaType EXPORT_MIME_TYPE = MediaType.PLAIN_TEXT_UTF_8; - static final String PREMIUM_TERMS_FILENAME = "CONFIDENTIAL_premium_terms.txt"; + static final String TLD_IDENTIFIER_FORMAT = "# TLD: %s"; + static final String PREMIUM_TERMS_FILENAME_FORMAT = "CONFIDENTIAL_premium_terms_%s.txt"; @Inject DriveConnection driveConnection; @@ -127,7 +128,7 @@ private String exportPremiumTerms(Tld tld) { try { String fileId = driveConnection.createOrUpdateFile( - PREMIUM_TERMS_FILENAME, + String.format(PREMIUM_TERMS_FILENAME_FORMAT, tldStr), EXPORT_MIME_TYPE, tld.getDriveFolderId(), getFormattedPremiumTerms(tld).getBytes(UTF_8)); @@ -150,11 +151,9 @@ private String getFormattedPremiumTerms(Tld tld) { .map(PremiumEntry::toString) .collect(ImmutableSortedSet.toImmutableSortedSet(String::compareTo)); - return Joiner.on("\n") - .appendTo( - new StringBuilder(), - Iterables.concat(ImmutableList.of(exportDisclaimer.trim()), premiumTerms)) - .append("\n") - .toString(); + String tldIdentifier = String.format(TLD_IDENTIFIER_FORMAT, tldStr); + Iterable commentsAndTerms = + Iterables.concat(ImmutableList.of(exportDisclaimer.trim(), tldIdentifier), premiumTerms); + return Joiner.on("\n").join(commentsAndTerms) + "\n"; } } diff --git a/core/src/test/java/google/registry/export/ExportPremiumTermsActionTest.java b/core/src/test/java/google/registry/export/ExportPremiumTermsActionTest.java index 5a475441433..d064cf6d787 100644 --- a/core/src/test/java/google/registry/export/ExportPremiumTermsActionTest.java +++ b/core/src/test/java/google/registry/export/ExportPremiumTermsActionTest.java @@ -17,7 +17,6 @@ import static com.google.common.net.MediaType.PLAIN_TEXT_UTF_8; import static com.google.common.truth.Truth.assertThat; import static google.registry.export.ExportPremiumTermsAction.EXPORT_MIME_TYPE; -import static google.registry.export.ExportPremiumTermsAction.PREMIUM_TERMS_FILENAME; import static google.registry.testing.DatabaseHelper.createTld; import static google.registry.testing.DatabaseHelper.deleteTld; import static google.registry.testing.DatabaseHelper.persistResource; @@ -52,11 +51,10 @@ /** Unit tests for {@link ExportPremiumTermsAction}. */ public class ExportPremiumTermsActionTest { - private static final String DISCLAIMER_WITH_NEWLINE = "# Premium Terms Export Disclaimer\n"; private static final ImmutableList PREMIUM_NAMES = ImmutableList.of("2048,USD 549", "0,USD 549"); private static final String EXPECTED_FILE_CONTENT = - DISCLAIMER_WITH_NEWLINE + "0, 549.00\n" + "2048, 549.00\n"; + "# Premium Terms Export Disclaimer\n# TLD: tld\n0, 549.00\n" + "2048, 549.00\n"; @RegisterExtension final JpaIntegrationTestExtension jpa = @@ -69,7 +67,7 @@ private void runAction(String tld) { ExportPremiumTermsAction action = new ExportPremiumTermsAction(); action.response = response; action.driveConnection = driveConnection; - action.exportDisclaimer = DISCLAIMER_WITH_NEWLINE; + action.exportDisclaimer = "# Premium Terms Export Disclaimer\n"; action.tldStr = tld; action.run(); } @@ -94,7 +92,7 @@ void test_exportPremiumTerms_success() throws IOException { verify(driveConnection) .createOrUpdateFile( - PREMIUM_TERMS_FILENAME, + "CONFIDENTIAL_premium_terms_tld.txt", EXPORT_MIME_TYPE, "folder_id", EXPECTED_FILE_CONTENT.getBytes(UTF_8)); @@ -157,7 +155,7 @@ void testExportPremiumTerms_failure_driveIdThrowsException() throws IOException verify(driveConnection) .createOrUpdateFile( - PREMIUM_TERMS_FILENAME, + "CONFIDENTIAL_premium_terms_tld.txt", EXPORT_MIME_TYPE, "bad_folder_id", EXPECTED_FILE_CONTENT.getBytes(UTF_8));