2222import static google .registry .model .billing .BillingBase .Flag .ANCHOR_TENANT ;
2323import static google .registry .model .billing .BillingBase .Flag .RESERVED ;
2424import static google .registry .model .billing .BillingBase .Flag .SUNRISE ;
25- import static google .registry .model .billing .BillingBase .RenewalPriceBehavior .DEFAULT ;
2625import static google .registry .model .billing .BillingBase .RenewalPriceBehavior .NONPREMIUM ;
2726import static google .registry .model .billing .BillingBase .RenewalPriceBehavior .SPECIFIED ;
2827import static google .registry .model .common .FeatureFlag .FeatureName .MINIMUM_DATASET_CONTACTS_OPTIONAL ;
8786import google .registry .flows .domain .DomainCreateFlow .MustHaveSignedMarksInCurrentPhaseException ;
8887import google .registry .flows .domain .DomainCreateFlow .NoGeneralRegistrationsInCurrentPhaseException ;
8988import google .registry .flows .domain .DomainCreateFlow .NoTrademarkedRegistrationsBeforeSunriseException ;
90- import google .registry .flows .domain .DomainCreateFlow .RenewalPriceInfo ;
9189import google .registry .flows .domain .DomainCreateFlow .SignedMarksOnlyDuringSunriseException ;
9290import google .registry .flows .domain .DomainFlowTmchUtils .FoundMarkExpiredException ;
9391import google .registry .flows .domain .DomainFlowTmchUtils .FoundMarkNotYetValidException ;
@@ -303,10 +301,8 @@ private void assertSuccessfulCreate(
303301
304302 boolean isAnchorTenant = expectedBillingFlags .contains (ANCHOR_TENANT );
305303 // Set up the creation cost.
306- BigDecimal createCost =
307- isDomainPremium (getUniqueIdFromCommand (), clock .nowUtc ())
308- ? BigDecimal .valueOf (200 )
309- : BigDecimal .valueOf (24 );
304+ boolean isDomainPremium = isDomainPremium (getUniqueIdFromCommand (), clock .nowUtc ());
305+ BigDecimal createCost = isDomainPremium ? BigDecimal .valueOf (200 ) : BigDecimal .valueOf (24 );
310306 if (isAnchorTenant ) {
311307 createCost = BigDecimal .ZERO ;
312308 }
@@ -315,6 +311,26 @@ private void assertSuccessfulCreate(
315311 createCost .multiply (
316312 BigDecimal .valueOf (1 - RegistryConfig .getSunriseDomainCreateDiscount ()));
317313 }
314+ if (allocationToken != null ) {
315+ if (allocationToken
316+ .getRegistrationBehavior ()
317+ .equals (RegistrationBehavior .NONPREMIUM_CREATE )) {
318+ createCost =
319+ createCost .subtract (
320+ BigDecimal .valueOf (isDomainPremium ? 87 : 0 )); // premium is 100, standard 13
321+ }
322+ if (allocationToken .getRenewalPriceBehavior ().equals (NONPREMIUM )) {
323+ createCost =
324+ createCost .subtract (
325+ BigDecimal .valueOf (isDomainPremium ? 89 : 0 )); // premium is 100, standard 11
326+ }
327+ if (allocationToken .getRenewalPriceBehavior ().equals (SPECIFIED )) {
328+ createCost =
329+ createCost
330+ .subtract (BigDecimal .valueOf (isDomainPremium ? 100 : 11 ))
331+ .add (allocationToken .getRenewalPrice ().get ().getAmount ());
332+ }
333+ }
318334 FeesAndCredits feesAndCredits =
319335 new FeesAndCredits .Builder ()
320336 .setCurrency (USD )
@@ -343,8 +359,12 @@ private void assertSuccessfulCreate(
343359 .hasType (HistoryEntry .Type .DOMAIN_CREATE )
344360 .and ()
345361 .hasPeriodYears (2 );
346- RenewalPriceInfo renewalPriceInfo =
347- DomainCreateFlow .getRenewalPriceInfo (isAnchorTenant , Optional .ofNullable (allocationToken ));
362+ RenewalPriceBehavior expectedRenewalPriceBehavior =
363+ isAnchorTenant
364+ ? RenewalPriceBehavior .NONPREMIUM
365+ : Optional .ofNullable (allocationToken )
366+ .map (AllocationToken ::getRenewalPriceBehavior )
367+ .orElse (RenewalPriceBehavior .DEFAULT );
348368 // There should be one bill for the create and one for the recurrence autorenew event.
349369 BillingEvent createBillingEvent =
350370 new BillingEvent .Builder ()
@@ -369,8 +389,11 @@ private void assertSuccessfulCreate(
369389 .setEventTime (domain .getRegistrationExpirationTime ())
370390 .setRecurrenceEndTime (END_OF_TIME )
371391 .setDomainHistory (historyEntry )
372- .setRenewalPriceBehavior (renewalPriceInfo .renewalPriceBehavior ())
373- .setRenewalPrice (renewalPriceInfo .renewalPrice ())
392+ .setRenewalPriceBehavior (expectedRenewalPriceBehavior )
393+ .setRenewalPrice (
394+ Optional .ofNullable (allocationToken )
395+ .flatMap (AllocationToken ::getRenewalPrice )
396+ .orElse (null ))
374397 .build ();
375398
376399 ImmutableSet .Builder <BillingBase > expectedBillingEvents =
@@ -3187,85 +3210,62 @@ void testEppMetric_isSuccessfullyCreated() throws Exception {
31873210 }
31883211
31893212 @ Test
3190- void testGetRenewalPriceInfo_isAnchorTenantWithoutToken_returnsNonPremiumAndNullPrice () {
3191- assertThat ( DomainCreateFlow . getRenewalPriceInfo ( true , Optional . empty ()))
3192- . isEqualTo ( RenewalPriceInfo . create ( NONPREMIUM , null ));
3193- }
3194-
3195- @ Test
3196- void testGetRenewalPriceInfo_isAnchorTenantWithDefaultToken_returnsNonPremiumAndNullPrice () {
3197- assertThat ( DomainCreateFlow . getRenewalPriceInfo ( true , Optional . of ( allocationToken )) )
3198- . isEqualTo ( RenewalPriceInfo . create ( NONPREMIUM , null ));
3199- }
3200-
3201- @ Test
3202- void testGetRenewalPriceInfo_isNotAnchorTenantWithDefaultToken_returnsDefaultAndNullPrice () {
3203- assertThat ( DomainCreateFlow . getRenewalPriceInfo ( false , Optional . of ( allocationToken )))
3204- . isEqualTo ( RenewalPriceInfo . create ( DEFAULT , null ) );
3213+ void testSuccess_anchorTenant_nonPremiumRenewal () throws Exception {
3214+ AllocationToken token =
3215+ persistResource (
3216+ new AllocationToken . Builder ()
3217+ . setToken ( "abc123" )
3218+ . setTokenType ( SINGLE_USE )
3219+ . setDomainName ( "example.tld" )
3220+ . setRegistrationBehavior ( RegistrationBehavior . ANCHOR_TENANT )
3221+ . build ( ));
3222+ persistContactsAndHosts ();
3223+ setEppInput (
3224+ "domain_create_allocationtoken.xml" ,
3225+ ImmutableMap . of ( "DOMAIN" , "example.tld" , "YEARS" , "2" ));
3226+ runFlow ();
3227+ assertSuccessfulCreate ( "tld" , ImmutableSet . of ( ANCHOR_TENANT ), token );
32053228 }
32063229
32073230 @ Test
3208- void testGetRenewalPriceInfo_isNotAnchorTenantWithoutToken_returnsDefaultAndNullPrice () {
3209- assertThat (DomainCreateFlow .getRenewalPriceInfo (false , Optional .empty ()))
3210- .isEqualTo (RenewalPriceInfo .create (DEFAULT , null ));
3231+ void testSuccess_nonAnchorTenant_nonPremiumRenewal () throws Exception {
3232+ createTld ("example" );
3233+ AllocationToken token =
3234+ persistResource (
3235+ new AllocationToken .Builder ()
3236+ .setToken ("abc123" )
3237+ .setTokenType (SINGLE_USE )
3238+ .setDomainName ("rich.example" )
3239+ .setRenewalPriceBehavior (NONPREMIUM )
3240+ .build ());
3241+ persistContactsAndHosts ();
3242+ // Creation is still $100 but it'll create a NONPREMIUM renewal
3243+ setEppInput (
3244+ "domain_create_premium_allocationtoken.xml" ,
3245+ ImmutableMap .of ("YEARS" , "2" , "FEE" , "111.00" ));
3246+ runFlow ();
3247+ assertSuccessfulCreate ("example" , ImmutableSet .of (), token );
32113248 }
32123249
32133250 @ Test
3214- void
3215- testGetRenewalPriceInfo_isNotAnchorTenantWithSpecifiedInToken_returnsSpecifiedAndCreatePrice () {
3251+ void testSuccess_specifiedRenewalPriceToken_specifiedRecurrencePrice () throws Exception {
3252+ createTld ( "example" );
32163253 AllocationToken token =
32173254 persistResource (
32183255 new AllocationToken .Builder ()
32193256 .setToken ("abc123" )
32203257 .setTokenType (SINGLE_USE )
3258+ .setDomainName ("rich.example" )
32213259 .setRenewalPriceBehavior (SPECIFIED )
3222- .setRenewalPrice (Money .of (USD , 5 ))
3260+ .setRenewalPrice (Money .of (USD , 1 ))
32233261 .build ());
3224- assertThat (DomainCreateFlow .getRenewalPriceInfo (false , Optional .of (token )))
3225- .isEqualTo (RenewalPriceInfo .create (SPECIFIED , Money .of (USD , 5 )));
3226- }
3227-
3228- @ Test
3229- void testGetRenewalPriceInfo_isAnchorTenantWithSpecifiedStateInToken_throwsError () {
3230- IllegalArgumentException thrown =
3231- assertThrows (
3232- IllegalArgumentException .class ,
3233- () ->
3234- DomainCreateFlow .getRenewalPriceInfo (
3235- true ,
3236- Optional .of (
3237- persistResource (
3238- new AllocationToken .Builder ()
3239- .setToken ("abc123" )
3240- .setTokenType (SINGLE_USE )
3241- .setRenewalPriceBehavior (SPECIFIED )
3242- .setRenewalPrice (Money .of (USD , 0 ))
3243- .build ()))));
3244- assertThat (thrown )
3245- .hasMessageThat ()
3246- .isEqualTo ("Renewal price behavior cannot be SPECIFIED for anchor tenant" );
3247- }
3248-
3249- @ Test
3250- void testGetRenewalPriceInfo_withInvalidRenewalPriceBehavior_throwsError () {
3251- IllegalArgumentException thrown =
3252- assertThrows (
3253- IllegalArgumentException .class ,
3254- () ->
3255- DomainCreateFlow .getRenewalPriceInfo (
3256- true ,
3257- Optional .of (
3258- persistResource (
3259- new AllocationToken .Builder ()
3260- .setToken ("abc123" )
3261- .setTokenType (SINGLE_USE )
3262- .setRenewalPriceBehavior (RenewalPriceBehavior .valueOf ("INVALID" ))
3263- .build ()))));
3264- assertThat (thrown )
3265- .hasMessageThat ()
3266- .isEqualTo (
3267- "No enum constant"
3268- + " google.registry.model.billing.BillingBase.RenewalPriceBehavior.INVALID" );
3262+ persistContactsAndHosts ();
3263+ // Creation is still $100 but it'll create a $1 renewal
3264+ setEppInput (
3265+ "domain_create_premium_allocationtoken.xml" ,
3266+ ImmutableMap .of ("YEARS" , "2" , "FEE" , "101.00" ));
3267+ runFlow ();
3268+ assertSuccessfulCreate ("example" , ImmutableSet .of (), token );
32693269 }
32703270
32713271 @ Test
0 commit comments