1414
1515package google .registry .model ;
1616
17+ import static google .registry .persistence .transaction .TransactionManagerFactory .tm ;
1718import static google .registry .testing .DatabaseHelper .createTld ;
1819import static google .registry .testing .DatabaseHelper .persistActiveDomain ;
1920import static google .registry .testing .DatabaseHelper .persistActiveHost ;
20- import static google .registry .testing .DatabaseHelper .persistDeletedDomain ;
2121import static google .registry .testing .DatabaseHelper .persistDeletedHost ;
22+ import static google .registry .testing .DatabaseHelper .persistDomainAsDeleted ;
2223import static google .registry .testing .DatabaseHelper .persistPremiumList ;
2324import static google .registry .testing .DatabaseHelper .persistResource ;
2425import static google .registry .testing .TestDataHelper .loadBytes ;
2526import static google .registry .util .DateTimeUtils .END_OF_TIME ;
2627import static org .joda .money .CurrencyUnit .USD ;
2728
29+ import google .registry .model .domain .Domain ;
2830import google .registry .model .domain .DomainHistory ;
2931import google .registry .model .eppcommon .Trid ;
3032import google .registry .model .host .HostHistory ;
@@ -49,7 +51,7 @@ public static void setupCompleteOte(String baseClientId) throws IOException {
4951 .build ());
5052 persistResource (
5153 new DomainHistory .Builder ()
52- .setDomain (persistActiveDomain ("example .tld" ))
54+ .setDomain (persistActiveDomain ("restored .tld" ))
5355 .setRegistrarId (oteAccount1 )
5456 .setType (Type .DOMAIN_RESTORE )
5557 .setXmlBytes (getBytes ("domain_restore.xml" ))
@@ -84,79 +86,80 @@ public static void setupIncompleteOte(String baseClientId) throws IOException {
8486 DateTime now = DateTime .now (DateTimeZone .UTC );
8587 persistResource (
8688 new DomainHistory .Builder ()
87- .setDomain (persistActiveDomain ("exampleone.tld" ))
89+ .setDomain (loadOrCreateDomain ("exampleone.tld" ))
8890 .setRegistrarId (oteAccount1 )
8991 .setType (Type .DOMAIN_CREATE )
9092 .setXmlBytes (getBytes ("domain_create_sunrise.xml" ))
9193 .setModificationTime (now )
9294 .build ());
9395 persistResource (
9496 new DomainHistory .Builder ()
95- .setDomain (persistActiveDomain ("example-one.tld" ))
97+ .setDomain (loadOrCreateDomain ("example-one.tld" ))
9698 .setRegistrarId (oteAccount1 )
9799 .setType (Type .DOMAIN_CREATE )
98100 .setXmlBytes (getBytes ("domain_create_claim_notice.xml" ))
99101 .setModificationTime (now )
100102 .build ());
103+ Domain exampleDomain = loadOrCreateDomain ("example.tld" );
101104 persistResource (
102105 new DomainHistory .Builder ()
103- .setDomain (persistActiveDomain ( "example.tld" ) )
106+ .setDomain (exampleDomain )
104107 .setRegistrarId (oteAccount1 )
105108 .setType (Type .DOMAIN_CREATE )
106109 .setXmlBytes (getBytes ("domain_create_anchor_tenant_fee_standard.xml" ))
107110 .setModificationTime (now )
108111 .build ());
109112 persistResource (
110113 new DomainHistory .Builder ()
111- .setDomain (persistActiveDomain ( "example.tld" ) )
114+ .setDomain (exampleDomain )
112115 .setRegistrarId (oteAccount1 )
113116 .setType (Type .DOMAIN_CREATE )
114117 .setXmlBytes (getBytes ("domain_create_dsdata.xml" ))
115118 .setModificationTime (now )
116119 .build ());
117120 persistResource (
118121 new DomainHistory .Builder ()
119- .setDomain (persistDeletedDomain ( "example .tld" , now ))
122+ .setDomain (persistDomainAsDeleted ( loadOrCreateDomain ( "deleted .tld") , now ))
120123 .setRegistrarId (oteAccount1 )
121124 .setType (Type .DOMAIN_DELETE )
122125 .setXmlBytes (getBytes ("domain_delete.xml" ))
123126 .setModificationTime (now )
124127 .build ());
125128 persistResource (
126129 new DomainHistory .Builder ()
127- .setDomain (persistActiveDomain ( "example.tld" ) )
130+ .setDomain (exampleDomain )
128131 .setRegistrarId (oteAccount1 )
129132 .setType (Type .DOMAIN_TRANSFER_APPROVE )
130133 .setXmlBytes (getBytes ("domain_transfer_approve.xml" ))
131134 .setModificationTime (now )
132135 .build ());
133136 persistResource (
134137 new DomainHistory .Builder ()
135- .setDomain (persistActiveDomain ( "example.tld" ) )
138+ .setDomain (exampleDomain )
136139 .setRegistrarId (oteAccount1 )
137140 .setType (Type .DOMAIN_TRANSFER_CANCEL )
138141 .setXmlBytes (getBytes ("domain_transfer_cancel.xml" ))
139142 .setModificationTime (now )
140143 .build ());
141144 persistResource (
142145 new DomainHistory .Builder ()
143- .setDomain (persistActiveDomain ( "example.tld" ) )
146+ .setDomain (exampleDomain )
144147 .setRegistrarId (oteAccount1 )
145148 .setType (Type .DOMAIN_TRANSFER_REJECT )
146149 .setXmlBytes (getBytes ("domain_transfer_reject.xml" ))
147150 .setModificationTime (now )
148151 .build ());
149152 persistResource (
150153 new DomainHistory .Builder ()
151- .setDomain (persistActiveDomain ( "example.tld" ) )
154+ .setDomain (exampleDomain )
152155 .setRegistrarId (oteAccount1 )
153156 .setType (Type .DOMAIN_TRANSFER_REQUEST )
154157 .setXmlBytes (getBytes ("domain_transfer_request.xml" ))
155158 .setModificationTime (now )
156159 .build ());
157160 persistResource (
158161 new DomainHistory .Builder ()
159- .setDomain (persistActiveDomain ( "example.tld" ) )
162+ .setDomain (exampleDomain )
160163 .setRegistrarId (oteAccount1 )
161164 .setType (Type .DOMAIN_UPDATE )
162165 .setXmlBytes (getBytes ("domain_update_with_secdns.xml" ))
@@ -189,4 +192,12 @@ public static void setupIncompleteOte(String baseClientId) throws IOException {
189192 private static byte [] getBytes (String filename ) throws IOException {
190193 return loadBytes (OteStatsTestHelper .class , filename ).read ();
191194 }
195+
196+ private static Domain loadOrCreateDomain (String domainName ) {
197+ return tm ().transact (
198+ () ->
199+ EppResourceUtils .loadByForeignKey (
200+ Domain .class , domainName , tm ().getTransactionTime ()))
201+ .orElseGet (() -> persistActiveDomain (domainName ));
202+ }
192203}
0 commit comments