mirror of
https://github.com/google/nomulus.git
synced 2025-05-15 17:07:15 +02:00
Move more lifecycle test helper methods to base class
This also raises their access level so they can be called by other classes that extend EppTestCase (which I'm writing in a follow-up CL). ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=223512618
This commit is contained in:
parent
54b6770ade
commit
c70a8867c6
2 changed files with 87 additions and 80 deletions
|
@ -14,30 +14,24 @@
|
|||
|
||||
package google.registry.flows;
|
||||
|
||||
import static com.google.common.truth.Truth8.assertThat;
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||
import static google.registry.model.eppoutput.Result.Code.SUCCESS;
|
||||
import static google.registry.model.eppoutput.Result.Code.SUCCESS_AND_CLOSE;
|
||||
import static google.registry.model.eppoutput.Result.Code.SUCCESS_WITH_ACTION_PENDING;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.testing.DatastoreHelper.assertBillingEventsForResource;
|
||||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.createTlds;
|
||||
import static google.registry.testing.DatastoreHelper.getOnlyHistoryEntryOfType;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.DatastoreHelper.stripBillingEventId;
|
||||
import static google.registry.testing.EppMetricSubject.assertThat;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static org.joda.money.CurrencyUnit.USD;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
import com.google.re2j.Matcher;
|
||||
import com.google.re2j.Pattern;
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.model.billing.BillingEvent;
|
||||
import google.registry.model.billing.BillingEvent.Flag;
|
||||
import google.registry.model.billing.BillingEvent.OneTime;
|
||||
import google.registry.model.billing.BillingEvent.Reason;
|
||||
import google.registry.model.domain.DomainResource;
|
||||
|
@ -45,8 +39,6 @@ import google.registry.model.registry.Registry;
|
|||
import google.registry.model.registry.Registry.TldState;
|
||||
import google.registry.model.reporting.HistoryEntry.Type;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Before;
|
||||
|
@ -265,77 +257,6 @@ public class EppLifecycleDomainTest extends EppTestCase {
|
|||
assertThatLogoutSucceeds();
|
||||
}
|
||||
|
||||
/** Makes a one-time billing event corresponding to the given domain's creation. */
|
||||
private static BillingEvent.OneTime makeOneTimeCreateBillingEvent(
|
||||
DomainResource domain, DateTime createTime) {
|
||||
return new BillingEvent.OneTime.Builder()
|
||||
.setReason(Reason.CREATE)
|
||||
.setTargetId(domain.getFullyQualifiedDomainName())
|
||||
.setClientId(domain.getCurrentSponsorClientId())
|
||||
.setCost(Money.parse("USD 26.00"))
|
||||
.setPeriodYears(2)
|
||||
.setEventTime(createTime)
|
||||
.setBillingTime(createTime.plus(Registry.get(domain.getTld()).getRenewGracePeriodLength()))
|
||||
.setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_CREATE))
|
||||
.build();
|
||||
}
|
||||
|
||||
/** Makes a recurring billing event corresponding to the given domain's creation. */
|
||||
private static BillingEvent.Recurring makeRecurringCreateBillingEvent(
|
||||
DomainResource domain, DateTime createTime, DateTime endTime) {
|
||||
return new BillingEvent.Recurring.Builder()
|
||||
.setReason(Reason.RENEW)
|
||||
.setFlags(ImmutableSet.of(Flag.AUTO_RENEW))
|
||||
.setTargetId(domain.getFullyQualifiedDomainName())
|
||||
.setClientId(domain.getCurrentSponsorClientId())
|
||||
.setEventTime(createTime.plusYears(2))
|
||||
.setRecurrenceEndTime(endTime)
|
||||
.setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_CREATE))
|
||||
.build();
|
||||
}
|
||||
|
||||
/** Makes a cancellation billing event cancelling out the given domain create billing event. */
|
||||
private static BillingEvent.Cancellation makeCancellationBillingEventFor(
|
||||
DomainResource domain,
|
||||
OneTime billingEventToCancel,
|
||||
DateTime createTime,
|
||||
DateTime deleteTime) {
|
||||
return new BillingEvent.Cancellation.Builder()
|
||||
.setTargetId(domain.getFullyQualifiedDomainName())
|
||||
.setClientId(domain.getCurrentSponsorClientId())
|
||||
.setEventTime(deleteTime)
|
||||
.setOneTimeEventKey(findKeyToActualOneTimeBillingEvent(billingEventToCancel))
|
||||
.setBillingTime(createTime.plus(Registry.get(domain.getTld()).getRenewGracePeriodLength()))
|
||||
.setReason(Reason.CREATE)
|
||||
.setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_DELETE))
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the Key to the actual one-time create billing event associated with a domain's creation.
|
||||
*
|
||||
* <p>This is used in the situation where we have created an expected billing event associated
|
||||
* with the domain's creation (which is passed as the parameter here), then need to locate the key
|
||||
* to the actual billing event in Datastore that would be seen on a Cancellation billing event.
|
||||
* This is necessary because the ID will be different even though all the rest of the fields are
|
||||
* the same.
|
||||
*/
|
||||
private static Key<OneTime> findKeyToActualOneTimeBillingEvent(OneTime expectedBillingEvent) {
|
||||
Optional<OneTime> actualCreateBillingEvent =
|
||||
ofy()
|
||||
.load()
|
||||
.type(BillingEvent.OneTime.class)
|
||||
.list()
|
||||
.stream()
|
||||
.filter(
|
||||
b ->
|
||||
Objects.equals(
|
||||
stripBillingEventId(b), stripBillingEventId(expectedBillingEvent)))
|
||||
.findFirst();
|
||||
assertThat(actualCreateBillingEvent).isPresent();
|
||||
return Key.create(actualCreateBillingEvent.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDomainDeletionWithSubordinateHost_fails() throws Exception {
|
||||
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue