1616
1717import static com .google .common .truth .Truth .assertThat ;
1818import static google .registry .export .ExportDomainListsAction .REGISTERED_DOMAINS_FILENAME ;
19+ import static google .registry .model .common .FeatureFlag .FeatureName .INCLUDE_PENDING_DELETE_DATE_FOR_DOMAINS ;
20+ import static google .registry .model .common .FeatureFlag .FeatureStatus .ACTIVE ;
21+ import static google .registry .model .common .FeatureFlag .FeatureStatus .INACTIVE ;
1922import static google .registry .testing .DatabaseHelper .createTld ;
2023import static google .registry .testing .DatabaseHelper .persistActiveDomain ;
2124import static google .registry .testing .DatabaseHelper .persistDeletedDomain ;
2225import static google .registry .testing .DatabaseHelper .persistResource ;
26+ import static google .registry .util .DateTimeUtils .START_OF_TIME ;
2327import static java .nio .charset .StandardCharsets .UTF_8 ;
2428import static org .junit .jupiter .api .Assertions .assertThrows ;
2529import static org .mockito .ArgumentMatchers .eq ;
3135import com .google .cloud .storage .StorageException ;
3236import com .google .cloud .storage .contrib .nio .testing .LocalStorageHelper ;
3337import com .google .common .collect .ImmutableList ;
38+ import com .google .common .collect .ImmutableSortedMap ;
3439import com .google .common .net .MediaType ;
3540import google .registry .gcs .GcsUtils ;
41+ import google .registry .model .common .FeatureFlag ;
42+ import google .registry .model .domain .Domain ;
43+ import google .registry .model .domain .GracePeriod ;
44+ import google .registry .model .domain .rgp .GracePeriodStatus ;
45+ import google .registry .model .eppcommon .StatusValue ;
3646import google .registry .model .tld .Tld ;
3747import google .registry .model .tld .Tld .TldType ;
3848import google .registry .persistence .transaction .JpaTestExtensions ;
@@ -56,7 +66,7 @@ class ExportDomainListsActionTest {
5666
5767 @ RegisterExtension
5868 final JpaIntegrationTestExtension jpa =
59- new JpaTestExtensions .Builder ().buildIntegrationTestExtension ();
69+ new JpaTestExtensions .Builder ().withClock ( clock ). buildIntegrationTestExtension ();
6070
6171 @ BeforeEach
6272 void beforeEach () {
@@ -70,6 +80,7 @@ void beforeEach() {
7080 action .gcsUtils = gcsUtils ;
7181 action .clock = clock ;
7282 action .driveConnection = driveConnection ;
83+ persistFeatureFlag (INACTIVE );
7384 }
7485
7586 private void verifyExportedToDrive (String folderId , String domains ) throws Exception {
@@ -83,7 +94,7 @@ private void verifyExportedToDrive(String folderId, String domains) throws Excep
8394 }
8495
8596 @ Test
86- void test_outputsOnlyActiveDomains () throws Exception {
97+ void test_outputsOnlyActiveDomains_txt () throws Exception {
8798 persistActiveDomain ("onetwo.tld" );
8899 persistActiveDomain ("rudnitzky.tld" );
89100 persistDeletedDomain ("mortuary.tld" , DateTime .parse ("2001-03-14T10:11:12Z" ));
@@ -97,7 +108,22 @@ void test_outputsOnlyActiveDomains() throws Exception {
97108 }
98109
99110 @ Test
100- void test_outputsOnlyDomainsOnRealTlds () throws Exception {
111+ void test_outputsOnlyActiveDomains_csv () throws Exception {
112+ persistFeatureFlag (ACTIVE );
113+ persistActiveDomain ("onetwo.tld" );
114+ persistActiveDomain ("rudnitzky.tld" );
115+ persistDeletedDomain ("mortuary.tld" , DateTime .parse ("2001-03-14T10:11:12Z" ));
116+ action .run ();
117+ BlobId existingFile = BlobId .of ("outputbucket" , "tld.txt" );
118+ String tlds = new String (gcsUtils .readBytesFrom (existingFile ), UTF_8 );
119+ // Check that it only contains the active domains, not the dead one.
120+ assertThat (tlds ).isEqualTo ("onetwo.tld,\n rudnitzky.tld," );
121+ verifyExportedToDrive ("brouhaha" , "onetwo.tld,\n rudnitzky.tld," );
122+ verifyNoMoreInteractions (driveConnection );
123+ }
124+
125+ @ Test
126+ void test_outputsOnlyDomainsOnRealTlds_txt () throws Exception {
101127 persistActiveDomain ("onetwo.tld" );
102128 persistActiveDomain ("rudnitzky.tld" );
103129 persistActiveDomain ("wontgo.testtld" );
@@ -116,7 +142,58 @@ void test_outputsOnlyDomainsOnRealTlds() throws Exception {
116142 }
117143
118144 @ Test
119- void test_outputsDomainsFromDifferentTldsToMultipleFiles () throws Exception {
145+ void test_outputsOnlyDomainsOnRealTlds_csv () throws Exception {
146+ persistFeatureFlag (ACTIVE );
147+ persistActiveDomain ("onetwo.tld" );
148+ persistActiveDomain ("rudnitzky.tld" );
149+ persistActiveDomain ("wontgo.testtld" );
150+ action .run ();
151+ BlobId existingFile = BlobId .of ("outputbucket" , "tld.txt" );
152+ String tlds = new String (gcsUtils .readBytesFrom (existingFile ), UTF_8 ).trim ();
153+ // Check that it only contains the domains on the real TLD, and not the test one.
154+ assertThat (tlds ).isEqualTo ("onetwo.tld,\n rudnitzky.tld," );
155+ // Make sure that the test TLD file wasn't written out.
156+ BlobId nonexistentFile = BlobId .of ("outputbucket" , "testtld.txt" );
157+ assertThrows (StorageException .class , () -> gcsUtils .readBytesFrom (nonexistentFile ));
158+ ImmutableList <String > ls = gcsUtils .listFolderObjects ("outputbucket" , "" );
159+ assertThat (ls ).containsExactly ("tld.txt" );
160+ verifyExportedToDrive ("brouhaha" , "onetwo.tld,\n rudnitzky.tld," );
161+ verifyNoMoreInteractions (driveConnection );
162+ }
163+
164+ @ Test
165+ void test_outputIncludesDeletionTimes_forPendingDeletes_notRdemption () throws Exception {
166+ persistFeatureFlag (ACTIVE );
167+ // Domains pending delete (meaning the 5 day period, not counting the 30 day redemption period)
168+ // should include their pending deletion date
169+ persistActiveDomain ("active.tld" );
170+ Domain redemption = persistActiveDomain ("redemption.tld" );
171+ persistResource (
172+ redemption
173+ .asBuilder ()
174+ .addStatusValue (StatusValue .PENDING_DELETE )
175+ .addGracePeriod (
176+ GracePeriod .createWithoutBillingEvent (
177+ GracePeriodStatus .REDEMPTION ,
178+ redemption .getRepoId (),
179+ clock .nowUtc ().plusDays (20 ),
180+ redemption .getCurrentSponsorRegistrarId ()))
181+ .build ());
182+ persistResource (
183+ persistActiveDomain ("pendingdelete.tld" )
184+ .asBuilder ()
185+ .addStatusValue (StatusValue .PENDING_DELETE )
186+ .setDeletionTime (clock .nowUtc ().plusDays (3 ))
187+ .build ());
188+
189+ action .run ();
190+
191+ verifyExportedToDrive (
192+ "brouhaha" , "active.tld,\n pendingdelete.tld,2020-02-05T02:02:02.000Z\n redemption.tld," );
193+ }
194+
195+ @ Test
196+ void test_outputsDomainsFromDifferentTldsToMultipleFiles_txt () throws Exception {
120197 createTld ("tldtwo" );
121198 persistResource (Tld .get ("tldtwo" ).asBuilder ().setDriveFolderId ("hooray" ).build ());
122199
@@ -143,4 +220,43 @@ void test_outputsDomainsFromDifferentTldsToMultipleFiles() throws Exception {
143220 // tldthree does not have a drive id, so no export to drive is performed.
144221 verifyNoMoreInteractions (driveConnection );
145222 }
223+
224+ @ Test
225+ void test_outputsDomainsFromDifferentTldsToMultipleFiles_csv () throws Exception {
226+ persistFeatureFlag (ACTIVE );
227+ createTld ("tldtwo" );
228+ persistResource (Tld .get ("tldtwo" ).asBuilder ().setDriveFolderId ("hooray" ).build ());
229+
230+ createTld ("tldthree" );
231+ // You'd think this test was written around Christmas, but it wasn't.
232+ persistActiveDomain ("dasher.tld" );
233+ persistActiveDomain ("prancer.tld" );
234+ persistActiveDomain ("rudolph.tldtwo" );
235+ persistActiveDomain ("santa.tldtwo" );
236+ persistActiveDomain ("buddy.tldtwo" );
237+ persistActiveDomain ("cupid.tldthree" );
238+ action .run ();
239+ BlobId firstTldFile = BlobId .of ("outputbucket" , "tld.txt" );
240+ String tlds = new String (gcsUtils .readBytesFrom (firstTldFile ), UTF_8 ).trim ();
241+ assertThat (tlds ).isEqualTo ("dasher.tld,\n prancer.tld," );
242+ BlobId secondTldFile = BlobId .of ("outputbucket" , "tldtwo.txt" );
243+ String moreTlds = new String (gcsUtils .readBytesFrom (secondTldFile ), UTF_8 ).trim ();
244+ assertThat (moreTlds ).isEqualTo ("buddy.tldtwo,\n rudolph.tldtwo,\n santa.tldtwo," );
245+ BlobId thirdTldFile = BlobId .of ("outputbucket" , "tldthree.txt" );
246+ String evenMoreTlds = new String (gcsUtils .readBytesFrom (thirdTldFile ), UTF_8 ).trim ();
247+ assertThat (evenMoreTlds ).isEqualTo ("cupid.tldthree," );
248+ verifyExportedToDrive ("brouhaha" , "dasher.tld,\n prancer.tld," );
249+ verifyExportedToDrive ("hooray" , "buddy.tldtwo,\n rudolph.tldtwo,\n santa.tldtwo," );
250+ // tldthree does not have a drive id, so no export to drive is performed.
251+ verifyNoMoreInteractions (driveConnection );
252+ }
253+
254+ private void persistFeatureFlag (FeatureFlag .FeatureStatus status ) {
255+ persistResource (
256+ new FeatureFlag ()
257+ .asBuilder ()
258+ .setFeatureName (INCLUDE_PENDING_DELETE_DATE_FOR_DOMAINS )
259+ .setStatusMap (ImmutableSortedMap .of (START_OF_TIME , status ))
260+ .build ());
261+ }
146262}
0 commit comments