mirror of
https://github.com/google/nomulus.git
synced 2025-08-04 17:01:51 +02:00
Run automatic Java 8 conversion over codebase
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=171174380
This commit is contained in:
parent
44df5da771
commit
5edb7935ed
190 changed files with 2312 additions and 3096 deletions
|
@ -178,19 +178,6 @@ public abstract class FlowTestCase<F extends Flow> extends ShardableTestCase {
|
|||
}
|
||||
|
||||
/** Helper to remove the grace period's billing event key to facilitate comparison. */
|
||||
private static final Function<GracePeriod, GracePeriod> GRACE_PERIOD_KEY_STRIPPER =
|
||||
new Function<GracePeriod, GracePeriod>() {
|
||||
@Override
|
||||
public GracePeriod apply(GracePeriod gracePeriod) {
|
||||
return GracePeriod.create(
|
||||
gracePeriod.isSunrushAddGracePeriod()
|
||||
? GracePeriodStatus.SUNRUSH_ADD
|
||||
: gracePeriod.getType(),
|
||||
gracePeriod.getExpirationTime(),
|
||||
gracePeriod.getClientId(),
|
||||
null);
|
||||
}};
|
||||
|
||||
/** A helper class that sets the billing event parent history entry to facilitate comparison. */
|
||||
public static class BillingEventParentSetter implements Function<BillingEvent, BillingEvent> {
|
||||
private HistoryEntry historyEntry;
|
||||
|
@ -220,7 +207,16 @@ public abstract class FlowTestCase<F extends Flow> extends ShardableTestCase {
|
|||
ImmutableMap.Builder<GracePeriod, BillingEvent> builder = new ImmutableMap.Builder<>();
|
||||
for (Map.Entry<GracePeriod, ? extends BillingEvent> entry : gracePeriods.entrySet()) {
|
||||
builder.put(
|
||||
GRACE_PERIOD_KEY_STRIPPER.apply(entry.getKey()),
|
||||
((Function<GracePeriod, GracePeriod>)
|
||||
gracePeriod ->
|
||||
GracePeriod.create(
|
||||
gracePeriod.isSunrushAddGracePeriod()
|
||||
? GracePeriodStatus.SUNRUSH_ADD
|
||||
: gracePeriod.getType(),
|
||||
gracePeriod.getExpirationTime(),
|
||||
gracePeriod.getClientId(),
|
||||
null))
|
||||
.apply(entry.getKey()),
|
||||
BILLING_EVENT_ID_STRIPPER.apply(entry.getValue()));
|
||||
}
|
||||
return builder.build();
|
||||
|
@ -235,18 +231,17 @@ public abstract class FlowTestCase<F extends Flow> extends ShardableTestCase {
|
|||
Iterable<GracePeriod> actual,
|
||||
ImmutableMap<GracePeriod, ? extends BillingEvent> expected) {
|
||||
Function<GracePeriod, BillingEvent> gracePeriodExpander =
|
||||
new Function<GracePeriod, BillingEvent>() {
|
||||
@Override
|
||||
public BillingEvent apply(GracePeriod gracePeriod) {
|
||||
assertThat(gracePeriod.hasBillingEvent())
|
||||
.named("Billing event is present for grace period: " + gracePeriod)
|
||||
.isTrue();
|
||||
return ofy().load()
|
||||
.key(firstNonNull(
|
||||
gracePeriod.getOneTimeBillingEvent(),
|
||||
gracePeriod.getRecurringBillingEvent()))
|
||||
.now();
|
||||
}};
|
||||
gracePeriod -> {
|
||||
assertThat(gracePeriod.hasBillingEvent())
|
||||
.named("Billing event is present for grace period: " + gracePeriod)
|
||||
.isTrue();
|
||||
return ofy()
|
||||
.load()
|
||||
.key(
|
||||
firstNonNull(
|
||||
gracePeriod.getOneTimeBillingEvent(), gracePeriod.getRecurringBillingEvent()))
|
||||
.now();
|
||||
};
|
||||
assertThat(canonicalizeGracePeriods(Maps.toMap(actual, gracePeriodExpander)))
|
||||
.isEqualTo(canonicalizeGracePeriods(expected));
|
||||
}
|
||||
|
@ -273,11 +268,7 @@ public abstract class FlowTestCase<F extends Flow> extends ShardableTestCase {
|
|||
throws Exception {
|
||||
// To facilitate comparison, remove the ids.
|
||||
Function<PollMessage, PollMessage> idStripper =
|
||||
new Function<PollMessage, PollMessage>() {
|
||||
@Override
|
||||
public PollMessage apply(PollMessage pollMessage) {
|
||||
return pollMessage.asBuilder().setId(1L).build();
|
||||
}};
|
||||
pollMessage -> pollMessage.asBuilder().setId(1L).build();
|
||||
// Ordering is irrelevant but duplicates should be considered independently.
|
||||
assertThat(FluentIterable.from(pollMessages).transform(idStripper))
|
||||
.containsExactlyElementsIn(FluentIterable.from(expected).transform(idStripper));
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
package google.registry.flows;
|
||||
|
||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
|
@ -21,10 +22,9 @@ import static google.registry.model.tmch.ClaimsListShardTest.createTestClaimsLis
|
|||
import static google.registry.testing.LogsSubject.assertAboutLogs;
|
||||
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Streams;
|
||||
import com.google.common.testing.TestLogHandler;
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.flows.FlowUtils.NotLoggedInException;
|
||||
|
@ -139,17 +139,17 @@ public abstract class ResourceFlowTestCase<F extends Flow, R extends EppResource
|
|||
* Confirms that an EppResourceIndex entity exists in Datastore for a given resource.
|
||||
*/
|
||||
protected static <T extends EppResource> void assertEppResourceIndexEntityFor(final T resource) {
|
||||
ImmutableList<EppResourceIndex> indices = FluentIterable
|
||||
.from(ofy().load()
|
||||
.type(EppResourceIndex.class)
|
||||
.filter("kind", Key.getKind(resource.getClass())))
|
||||
.filter(new Predicate<EppResourceIndex>() {
|
||||
@Override
|
||||
public boolean apply(EppResourceIndex index) {
|
||||
return Key.create(resource).equals(index.getKey())
|
||||
&& ofy().load().key(index.getKey()).now().equals(resource);
|
||||
}})
|
||||
.toList();
|
||||
ImmutableList<EppResourceIndex> indices =
|
||||
Streams.stream(
|
||||
ofy()
|
||||
.load()
|
||||
.type(EppResourceIndex.class)
|
||||
.filter("kind", Key.getKind(resource.getClass())))
|
||||
.filter(
|
||||
index ->
|
||||
Key.create(resource).equals(index.getKey())
|
||||
&& ofy().load().key(index.getKey()).now().equals(resource))
|
||||
.collect(toImmutableList());
|
||||
assertThat(indices).hasSize(1);
|
||||
assertThat(indices.get(0).getBucket())
|
||||
.isEqualTo(EppResourceIndexBucket.getBucketKey(Key.create(resource)));
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
package google.registry.flows.contact;
|
||||
|
||||
import static com.google.common.collect.MoreCollectors.onlyElement;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.ContactResourceSubject.assertAboutContacts;
|
||||
import static google.registry.testing.DatastoreHelper.assertNoBillingEvents;
|
||||
|
@ -23,8 +24,6 @@ import static google.registry.testing.DatastoreHelper.getOnlyPollMessage;
|
|||
import static google.registry.testing.DatastoreHelper.getPollMessages;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.Iterables;
|
||||
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
|
||||
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
|
||||
import google.registry.flows.ResourceFlowUtils.ResourceNotOwnedException;
|
||||
|
@ -92,14 +91,21 @@ public class ContactTransferApproveFlowTest
|
|||
PollMessage gainingPollMessage = getOnlyPollMessage("NewRegistrar");
|
||||
assertThat(gainingPollMessage.getEventTime()).isEqualTo(clock.nowUtc());
|
||||
assertThat(
|
||||
Iterables.getOnlyElement(FluentIterable
|
||||
.from(gainingPollMessage.getResponseData())
|
||||
.filter(TransferResponse.class))
|
||||
gainingPollMessage
|
||||
.getResponseData()
|
||||
.stream()
|
||||
.filter(TransferResponse.class::isInstance)
|
||||
.map(TransferResponse.class::cast)
|
||||
.collect(onlyElement())
|
||||
.getTransferStatus())
|
||||
.isEqualTo(TransferStatus.CLIENT_APPROVED);
|
||||
PendingActionNotificationResponse panData = Iterables.getOnlyElement(FluentIterable
|
||||
.from(gainingPollMessage.getResponseData())
|
||||
.filter(PendingActionNotificationResponse.class));
|
||||
.isEqualTo(TransferStatus.CLIENT_APPROVED);
|
||||
PendingActionNotificationResponse panData =
|
||||
gainingPollMessage
|
||||
.getResponseData()
|
||||
.stream()
|
||||
.filter(PendingActionNotificationResponse.class::isInstance)
|
||||
.map(PendingActionNotificationResponse.class::cast)
|
||||
.collect(onlyElement());
|
||||
assertThat(panData.getTrid())
|
||||
.isEqualTo(Trid.create("transferClient-trid", "transferServer-trid"));
|
||||
assertThat(panData.getActionResult()).isTrue();
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
package google.registry.flows.contact;
|
||||
|
||||
import static com.google.common.collect.MoreCollectors.onlyElement;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.ContactResourceSubject.assertAboutContacts;
|
||||
import static google.registry.testing.DatastoreHelper.assertNoBillingEvents;
|
||||
|
@ -22,8 +23,6 @@ import static google.registry.testing.DatastoreHelper.getOnlyPollMessage;
|
|||
import static google.registry.testing.DatastoreHelper.getPollMessages;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.Iterables;
|
||||
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
|
||||
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
|
||||
import google.registry.flows.exceptions.NotPendingTransferException;
|
||||
|
@ -86,11 +85,14 @@ public class ContactTransferCancelFlowTest
|
|||
PollMessage losingPollMessage = getOnlyPollMessage("TheRegistrar");
|
||||
assertThat(losingPollMessage.getEventTime()).isEqualTo(clock.nowUtc());
|
||||
assertThat(
|
||||
Iterables.getOnlyElement(FluentIterable
|
||||
.from(losingPollMessage.getResponseData())
|
||||
.filter(TransferResponse.class))
|
||||
losingPollMessage
|
||||
.getResponseData()
|
||||
.stream()
|
||||
.filter(TransferResponse.class::isInstance)
|
||||
.map(TransferResponse.class::cast)
|
||||
.collect(onlyElement())
|
||||
.getTransferStatus())
|
||||
.isEqualTo(TransferStatus.CLIENT_CANCELLED);
|
||||
.isEqualTo(TransferStatus.CLIENT_CANCELLED);
|
||||
}
|
||||
|
||||
private void doFailingTest(String commandFilename) throws Exception {
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
package google.registry.flows.contact;
|
||||
|
||||
import static com.google.common.collect.MoreCollectors.onlyElement;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.ContactResourceSubject.assertAboutContacts;
|
||||
import static google.registry.testing.DatastoreHelper.assertNoBillingEvents;
|
||||
|
@ -22,8 +23,6 @@ import static google.registry.testing.DatastoreHelper.getOnlyPollMessage;
|
|||
import static google.registry.testing.DatastoreHelper.getPollMessages;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.Iterables;
|
||||
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
|
||||
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
|
||||
import google.registry.flows.ResourceFlowUtils.ResourceNotOwnedException;
|
||||
|
@ -90,14 +89,21 @@ public class ContactTransferRejectFlowTest
|
|||
PollMessage gainingPollMessage = getOnlyPollMessage("NewRegistrar");
|
||||
assertThat(gainingPollMessage.getEventTime()).isEqualTo(clock.nowUtc());
|
||||
assertThat(
|
||||
Iterables.getOnlyElement(FluentIterable
|
||||
.from(gainingPollMessage.getResponseData())
|
||||
.filter(TransferResponse.class))
|
||||
gainingPollMessage
|
||||
.getResponseData()
|
||||
.stream()
|
||||
.filter(TransferResponse.class::isInstance)
|
||||
.map(TransferResponse.class::cast)
|
||||
.collect(onlyElement())
|
||||
.getTransferStatus())
|
||||
.isEqualTo(TransferStatus.CLIENT_REJECTED);
|
||||
PendingActionNotificationResponse panData = Iterables.getOnlyElement(FluentIterable
|
||||
.from(gainingPollMessage.getResponseData())
|
||||
.filter(PendingActionNotificationResponse.class));
|
||||
.isEqualTo(TransferStatus.CLIENT_REJECTED);
|
||||
PendingActionNotificationResponse panData =
|
||||
gainingPollMessage
|
||||
.getResponseData()
|
||||
.stream()
|
||||
.filter(PendingActionNotificationResponse.class::isInstance)
|
||||
.map(PendingActionNotificationResponse.class::cast)
|
||||
.collect(onlyElement());
|
||||
assertThat(panData.getTrid())
|
||||
.isEqualTo(Trid.create("transferClient-trid", "transferServer-trid"));
|
||||
assertThat(panData.getActionResult()).isFalse();
|
||||
|
|
|
@ -17,6 +17,7 @@ package google.registry.flows.contact;
|
|||
import static com.google.common.base.Predicates.equalTo;
|
||||
import static com.google.common.base.Predicates.not;
|
||||
import static com.google.common.collect.Iterables.getOnlyElement;
|
||||
import static com.google.common.collect.MoreCollectors.onlyElement;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.config.RegistryConfig.getContactAutomaticTransferLength;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
|
@ -116,10 +117,10 @@ public class ContactTransferRequestFlowTest
|
|||
PollMessage gainingApproveMessage =
|
||||
getOnlyElement(getPollMessages("NewRegistrar", afterTransfer));
|
||||
PollMessage losingApproveMessage =
|
||||
getOnlyElement(
|
||||
Iterables.filter(
|
||||
getPollMessages("TheRegistrar", afterTransfer),
|
||||
not(equalTo(losingRequestMessage))));
|
||||
getPollMessages("TheRegistrar", afterTransfer)
|
||||
.stream()
|
||||
.filter(not(equalTo(losingRequestMessage)))
|
||||
.collect(onlyElement());
|
||||
|
||||
// Check for TransferData server-approve entities containing what we expect: only
|
||||
// poll messages, the approval notice ones for gaining and losing registrars.
|
||||
|
|
|
@ -34,6 +34,7 @@ import static google.registry.testing.DatastoreHelper.persistResource;
|
|||
import static google.registry.testing.DomainApplicationSubject.assertAboutApplications;
|
||||
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static java.util.Comparator.comparing;
|
||||
import static org.joda.money.CurrencyUnit.EUR;
|
||||
import static org.joda.money.CurrencyUnit.USD;
|
||||
|
||||
|
@ -124,7 +125,6 @@ import google.registry.tmch.TmchCertificateAuthority;
|
|||
import google.registry.tmch.TmchXmlSignature;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import org.joda.money.CurrencyUnit;
|
||||
import org.joda.money.Money;
|
||||
|
@ -205,11 +205,7 @@ public class DomainApplicationCreateFlowTest
|
|||
// Check that the domain application was created and persisted with a history entry.
|
||||
// We want the one with the newest creation time, but lacking an index we need this code.
|
||||
List<DomainApplication> applications = ofy().load().type(DomainApplication.class).list();
|
||||
Collections.sort(applications, new Comparator<DomainApplication>() {
|
||||
@Override
|
||||
public int compare(DomainApplication a, DomainApplication b) {
|
||||
return a.getCreationTime().compareTo(b.getCreationTime());
|
||||
}});
|
||||
Collections.sort(applications, comparing(DomainApplication::getCreationTime));
|
||||
assertAboutApplications().that(getLast(applications))
|
||||
.hasFullyQualifiedDomainName(getUniqueIdFromCommand()).and()
|
||||
.hasNumEncodedSignedMarks(sunriseApplication ? 1 : 0).and()
|
||||
|
|
|
@ -26,9 +26,7 @@ import static google.registry.testing.DatastoreHelper.persistResource;
|
|||
import static google.registry.testing.TestDataHelper.loadFileWithSubstitutions;
|
||||
import static google.registry.util.DatastoreServiceUtils.KEY_TO_KIND_FUNCTION;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
@ -56,7 +54,6 @@ import google.registry.model.registry.Registry.TldState;
|
|||
import google.registry.model.smd.EncodedSignedMark;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import google.registry.testing.EppLoader;
|
||||
import java.util.List;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -336,20 +333,20 @@ public class DomainApplicationInfoFlowTest
|
|||
int numPreviousReads = RequestCapturingAsyncDatastoreService.getReads().size();
|
||||
doSuccessfulTest("domain_info_sunrise_response.xml", HostsState.HOSTS_EXIST);
|
||||
// Get all of the keys loaded in the flow, with each distinct load() call as a list of keys.
|
||||
int numReadsWithContactsOrHosts = FluentIterable
|
||||
.from(RequestCapturingAsyncDatastoreService.getReads())
|
||||
.skip(numPreviousReads)
|
||||
.filter(
|
||||
new Predicate<List<com.google.appengine.api.datastore.Key>>() {
|
||||
@Override
|
||||
public boolean apply(List<com.google.appengine.api.datastore.Key> keys) {
|
||||
return FluentIterable.from(keys)
|
||||
.transform(KEY_TO_KIND_FUNCTION)
|
||||
.anyMatch(Predicates.or(
|
||||
equalTo(Key.getKind(ContactResource.class)),
|
||||
equalTo(Key.getKind(HostResource.class))));
|
||||
}})
|
||||
.size();
|
||||
int numReadsWithContactsOrHosts =
|
||||
(int)
|
||||
RequestCapturingAsyncDatastoreService.getReads()
|
||||
.stream()
|
||||
.skip(numPreviousReads)
|
||||
.filter(
|
||||
keys ->
|
||||
keys.stream()
|
||||
.map(KEY_TO_KIND_FUNCTION)
|
||||
.anyMatch(
|
||||
Predicates.or(
|
||||
equalTo(Key.getKind(ContactResource.class)),
|
||||
equalTo(Key.getKind(HostResource.class)))))
|
||||
.count();
|
||||
assertThat(numReadsWithContactsOrHosts).isEqualTo(1);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
package google.registry.flows.domain;
|
||||
|
||||
import static com.google.common.collect.MoreCollectors.onlyElement;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.flows.domain.DomainTransferFlowTestCase.persistWithPendingTransfer;
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||
|
@ -46,11 +47,9 @@ import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
|||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static org.joda.money.CurrencyUnit.USD;
|
||||
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.flows.EppRequestSource;
|
||||
import google.registry.flows.ResourceFlowTestCase;
|
||||
|
@ -543,14 +542,21 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
|
|||
PollMessage gainingPollMessage = getOnlyPollMessage("NewRegistrar");
|
||||
assertThat(gainingPollMessage.getEventTime()).isEqualTo(clock.nowUtc());
|
||||
assertThat(
|
||||
Iterables.getOnlyElement(FluentIterable
|
||||
.from(gainingPollMessage.getResponseData())
|
||||
.filter(TransferResponse.class))
|
||||
gainingPollMessage
|
||||
.getResponseData()
|
||||
.stream()
|
||||
.filter(TransferResponse.class::isInstance)
|
||||
.map(TransferResponse.class::cast)
|
||||
.collect(onlyElement())
|
||||
.getTransferStatus())
|
||||
.isEqualTo(TransferStatus.SERVER_CANCELLED);
|
||||
PendingActionNotificationResponse panData = Iterables.getOnlyElement(FluentIterable
|
||||
.from(gainingPollMessage.getResponseData())
|
||||
.filter(PendingActionNotificationResponse.class));
|
||||
.isEqualTo(TransferStatus.SERVER_CANCELLED);
|
||||
PendingActionNotificationResponse panData =
|
||||
gainingPollMessage
|
||||
.getResponseData()
|
||||
.stream()
|
||||
.filter(PendingActionNotificationResponse.class::isInstance)
|
||||
.map(PendingActionNotificationResponse.class::cast)
|
||||
.collect(onlyElement());
|
||||
assertThat(panData.getTrid())
|
||||
.isEqualTo(Trid.create("transferClient-trid", "transferServer-trid"));
|
||||
assertThat(panData.getActionResult()).isFalse();
|
||||
|
|
|
@ -27,9 +27,7 @@ import static google.registry.testing.DatastoreHelper.persistResource;
|
|||
import static google.registry.testing.TestDataHelper.loadFileWithSubstitutions;
|
||||
import static google.registry.util.DatastoreServiceUtils.KEY_TO_KIND_FUNCTION;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.googlecode.objectify.Key;
|
||||
|
@ -56,7 +54,6 @@ import google.registry.model.eppcommon.StatusValue;
|
|||
import google.registry.model.host.HostResource;
|
||||
import google.registry.model.ofy.RequestCapturingAsyncDatastoreService;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import java.util.List;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -641,20 +638,20 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
|
|||
int numPreviousReads = RequestCapturingAsyncDatastoreService.getReads().size();
|
||||
doSuccessfulTest("domain_info_response.xml", false);
|
||||
// Get all of the keys loaded in the flow, with each distinct load() call as a list of keys.
|
||||
int numReadsWithContactsOrHosts = FluentIterable
|
||||
.from(RequestCapturingAsyncDatastoreService.getReads())
|
||||
.skip(numPreviousReads)
|
||||
.filter(
|
||||
new Predicate<List<com.google.appengine.api.datastore.Key>>() {
|
||||
@Override
|
||||
public boolean apply(List<com.google.appengine.api.datastore.Key> keys) {
|
||||
return FluentIterable.from(keys)
|
||||
.transform(KEY_TO_KIND_FUNCTION)
|
||||
.anyMatch(Predicates.or(
|
||||
equalTo(Key.getKind(ContactResource.class)),
|
||||
equalTo(Key.getKind(HostResource.class))));
|
||||
}})
|
||||
.size();
|
||||
int numReadsWithContactsOrHosts =
|
||||
(int)
|
||||
RequestCapturingAsyncDatastoreService.getReads()
|
||||
.stream()
|
||||
.skip(numPreviousReads)
|
||||
.filter(
|
||||
keys ->
|
||||
keys.stream()
|
||||
.map(KEY_TO_KIND_FUNCTION)
|
||||
.anyMatch(
|
||||
Predicates.or(
|
||||
equalTo(Key.getKind(ContactResource.class)),
|
||||
equalTo(Key.getKind(HostResource.class)))))
|
||||
.count();
|
||||
assertThat(numReadsWithContactsOrHosts).isEqualTo(1);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
package google.registry.flows.domain;
|
||||
|
||||
import static com.google.common.collect.Iterables.getOnlyElement;
|
||||
import static com.google.common.collect.MoreCollectors.onlyElement;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.reporting.DomainTransactionRecord.TransactionReportField.NET_ADDS_4_YR;
|
||||
|
@ -40,7 +40,6 @@ import com.google.common.collect.FluentIterable;
|
|||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
|
||||
|
@ -49,8 +48,6 @@ import google.registry.flows.ResourceFlowUtils.ResourceNotOwnedException;
|
|||
import google.registry.flows.domain.DomainFlowUtils.NotAuthorizedForTldException;
|
||||
import google.registry.flows.exceptions.NotPendingTransferException;
|
||||
import google.registry.model.billing.BillingEvent;
|
||||
import google.registry.model.billing.BillingEvent.Cancellation;
|
||||
import google.registry.model.billing.BillingEvent.Cancellation.Builder;
|
||||
import google.registry.model.billing.BillingEvent.OneTime;
|
||||
import google.registry.model.billing.BillingEvent.Reason;
|
||||
import google.registry.model.billing.BillingEvent.Recurring;
|
||||
|
@ -205,15 +202,23 @@ public class DomainTransferApproveFlowTest
|
|||
assertThat(gainingTransferPollMessage.getEventTime()).isEqualTo(clock.nowUtc());
|
||||
assertThat(gainingAutorenewPollMessage.getEventTime())
|
||||
.isEqualTo(domain.getRegistrationExpirationTime());
|
||||
DomainTransferResponse transferResponse = getOnlyElement(FluentIterable
|
||||
.from(gainingTransferPollMessage.getResponseData())
|
||||
.filter(DomainTransferResponse.class));
|
||||
DomainTransferResponse transferResponse =
|
||||
gainingTransferPollMessage
|
||||
.getResponseData()
|
||||
.stream()
|
||||
.filter(DomainTransferResponse.class::isInstance)
|
||||
.map(DomainTransferResponse.class::cast)
|
||||
.collect(onlyElement());
|
||||
assertThat(transferResponse.getTransferStatus()).isEqualTo(TransferStatus.CLIENT_APPROVED);
|
||||
assertThat(transferResponse.getExtendedRegistrationExpirationTime())
|
||||
.isEqualTo(domain.getRegistrationExpirationTime());
|
||||
PendingActionNotificationResponse panData = Iterables.getOnlyElement(FluentIterable
|
||||
.from(gainingTransferPollMessage.getResponseData())
|
||||
.filter(PendingActionNotificationResponse.class));
|
||||
PendingActionNotificationResponse panData =
|
||||
gainingTransferPollMessage
|
||||
.getResponseData()
|
||||
.stream()
|
||||
.filter(PendingActionNotificationResponse.class::isInstance)
|
||||
.map(PendingActionNotificationResponse.class::cast)
|
||||
.collect(onlyElement());
|
||||
assertThat(panData.getTrid())
|
||||
.isEqualTo(Trid.create("transferClient-trid", "transferServer-trid"));
|
||||
assertThat(panData.getActionResult()).isTrue();
|
||||
|
@ -250,12 +255,8 @@ public class DomainTransferApproveFlowTest
|
|||
domain,
|
||||
FluentIterable.from(expectedCancellationBillingEvents)
|
||||
.transform(
|
||||
new Function<BillingEvent.Cancellation.Builder, BillingEvent>() {
|
||||
@Override
|
||||
public Cancellation apply(Builder builder) {
|
||||
return builder.setParent(historyEntryTransferApproved).build();
|
||||
}
|
||||
})
|
||||
(Function<BillingEvent.Cancellation.Builder, BillingEvent>)
|
||||
builder -> builder.setParent(historyEntryTransferApproved).build())
|
||||
.append(
|
||||
transferBillingEvent,
|
||||
getLosingClientAutorenewEvent()
|
||||
|
@ -292,12 +293,8 @@ public class DomainTransferApproveFlowTest
|
|||
domain,
|
||||
FluentIterable.from(expectedCancellationBillingEvents)
|
||||
.transform(
|
||||
new Function<BillingEvent.Cancellation.Builder, BillingEvent>() {
|
||||
@Override
|
||||
public Cancellation apply(Builder builder) {
|
||||
return builder.setParent(historyEntryTransferApproved).build();
|
||||
}
|
||||
})
|
||||
(Function<BillingEvent.Cancellation.Builder, BillingEvent>)
|
||||
builder -> builder.setParent(historyEntryTransferApproved).build())
|
||||
.append(
|
||||
getLosingClientAutorenewEvent()
|
||||
.asBuilder()
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
package google.registry.flows.domain;
|
||||
|
||||
import static com.google.common.collect.MoreCollectors.onlyElement;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.reporting.DomainTransactionRecord.TransactionReportField.NET_RENEWS_3_YR;
|
||||
import static google.registry.model.reporting.DomainTransactionRecord.TransactionReportField.TRANSFER_NACKED;
|
||||
|
@ -32,9 +33,7 @@ import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
|
|||
import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries;
|
||||
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
||||
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
|
||||
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
|
||||
import google.registry.flows.ResourceFlowUtils.ResourceNotOwnedException;
|
||||
|
@ -116,14 +115,21 @@ public class DomainTransferRejectFlowTest
|
|||
PollMessage gainingPollMessage = getOnlyPollMessage("NewRegistrar");
|
||||
assertThat(gainingPollMessage.getEventTime()).isEqualTo(clock.nowUtc());
|
||||
assertThat(
|
||||
Iterables.getOnlyElement(FluentIterable
|
||||
.from(gainingPollMessage.getResponseData())
|
||||
.filter(TransferResponse.class))
|
||||
gainingPollMessage
|
||||
.getResponseData()
|
||||
.stream()
|
||||
.filter(TransferResponse.class::isInstance)
|
||||
.map(TransferResponse.class::cast)
|
||||
.collect(onlyElement())
|
||||
.getTransferStatus())
|
||||
.isEqualTo(TransferStatus.CLIENT_REJECTED);
|
||||
PendingActionNotificationResponse panData = Iterables.getOnlyElement(FluentIterable
|
||||
.from(gainingPollMessage.getResponseData())
|
||||
.filter(PendingActionNotificationResponse.class));
|
||||
.isEqualTo(TransferStatus.CLIENT_REJECTED);
|
||||
PendingActionNotificationResponse panData =
|
||||
gainingPollMessage
|
||||
.getResponseData()
|
||||
.stream()
|
||||
.filter(PendingActionNotificationResponse.class::isInstance)
|
||||
.map(PendingActionNotificationResponse.class::cast)
|
||||
.collect(onlyElement());
|
||||
assertThat(panData.getTrid())
|
||||
.isEqualTo(Trid.create("transferClient-trid", "transferServer-trid"));
|
||||
assertThat(panData.getActionResult()).isFalse();
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
|
||||
package google.registry.flows.domain;
|
||||
|
||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
import static com.google.common.collect.MoreCollectors.onlyElement;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.reporting.DomainTransactionRecord.TransactionReportField.TRANSFER_SUCCESSFUL;
|
||||
|
@ -38,7 +40,6 @@ import static org.joda.money.CurrencyUnit.USD;
|
|||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
@ -66,7 +67,6 @@ import google.registry.flows.exceptions.ResourceStatusProhibitsOperationExceptio
|
|||
import google.registry.flows.exceptions.TransferPeriodMustBeOneYearException;
|
||||
import google.registry.flows.exceptions.TransferPeriodZeroAndFeeTransferExtensionException;
|
||||
import google.registry.model.billing.BillingEvent;
|
||||
import google.registry.model.billing.BillingEvent.Cancellation.Builder;
|
||||
import google.registry.model.billing.BillingEvent.Reason;
|
||||
import google.registry.model.contact.ContactAuthInfo;
|
||||
import google.registry.model.domain.DomainAuthInfo;
|
||||
|
@ -87,6 +87,7 @@ import google.registry.model.transfer.TransferData;
|
|||
import google.registry.model.transfer.TransferResponse;
|
||||
import google.registry.model.transfer.TransferStatus;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Duration;
|
||||
|
@ -285,14 +286,11 @@ public class DomainTransferRequestFlowTest
|
|||
.build();
|
||||
// Construct extra billing events expected by the specific test.
|
||||
ImmutableList<BillingEvent> extraBillingEvents =
|
||||
FluentIterable.from(extraExpectedBillingEvents)
|
||||
.transform(
|
||||
new Function<BillingEvent.Cancellation.Builder, BillingEvent>() {
|
||||
@Override
|
||||
public BillingEvent apply(Builder builder) {
|
||||
return builder.setParent(historyEntryTransferRequest).build();
|
||||
}})
|
||||
.toList();
|
||||
Stream.of(extraExpectedBillingEvents)
|
||||
.map(
|
||||
(Function<BillingEvent.Cancellation.Builder, BillingEvent>)
|
||||
builder -> builder.setParent(historyEntryTransferRequest).build())
|
||||
.collect(toImmutableList());
|
||||
// Assert that the billing events we constructed above actually exist in datastore.
|
||||
assertBillingEvents(FluentIterable.from(extraBillingEvents)
|
||||
.append(optionalTransferBillingEvent.asSet())
|
||||
|
@ -367,46 +365,57 @@ public class DomainTransferRequestFlowTest
|
|||
assertThat(transferApprovedPollMessage.getEventTime()).isEqualTo(implicitTransferTime);
|
||||
assertThat(autorenewPollMessage.getEventTime()).isEqualTo(expectedExpirationTime);
|
||||
assertThat(
|
||||
Iterables.getOnlyElement(FluentIterable
|
||||
.from(transferApprovedPollMessage.getResponseData())
|
||||
.filter(TransferResponse.class))
|
||||
transferApprovedPollMessage
|
||||
.getResponseData()
|
||||
.stream()
|
||||
.filter(TransferResponse.class::isInstance)
|
||||
.map(TransferResponse.class::cast)
|
||||
.collect(onlyElement())
|
||||
.getTransferStatus())
|
||||
.isEqualTo(TransferStatus.SERVER_APPROVED);
|
||||
PendingActionNotificationResponse panData = Iterables.getOnlyElement(FluentIterable
|
||||
.from(transferApprovedPollMessage.getResponseData())
|
||||
.filter(PendingActionNotificationResponse.class));
|
||||
.isEqualTo(TransferStatus.SERVER_APPROVED);
|
||||
PendingActionNotificationResponse panData =
|
||||
transferApprovedPollMessage
|
||||
.getResponseData()
|
||||
.stream()
|
||||
.filter(PendingActionNotificationResponse.class::isInstance)
|
||||
.map(PendingActionNotificationResponse.class::cast)
|
||||
.collect(onlyElement());
|
||||
assertThat(panData.getTrid().getClientTransactionId()).isEqualTo("ABC-12345");
|
||||
assertThat(panData.getActionResult()).isTrue();
|
||||
|
||||
// Two poll messages on the losing registrar's side at the implicit transfer time: a
|
||||
// transfer pending message, and a transfer approved message (both OneTime messages).
|
||||
assertThat(getPollMessages("TheRegistrar", implicitTransferTime)).hasSize(2);
|
||||
PollMessage losingTransferPendingPollMessage = Iterables.getOnlyElement(
|
||||
FluentIterable.from(getPollMessages("TheRegistrar", clock.nowUtc()))
|
||||
.filter(
|
||||
new Predicate<PollMessage>() {
|
||||
@Override
|
||||
public boolean apply(PollMessage pollMessage) {
|
||||
return TransferStatus.PENDING.getMessage().equals(pollMessage.getMsg());
|
||||
}
|
||||
}));
|
||||
PollMessage losingTransferApprovedPollMessage = Iterables.getOnlyElement(FluentIterable
|
||||
.from(getPollMessages("TheRegistrar", implicitTransferTime))
|
||||
.filter(Predicates.not(Predicates.equalTo(losingTransferPendingPollMessage))));
|
||||
PollMessage losingTransferPendingPollMessage =
|
||||
getPollMessages("TheRegistrar", clock.nowUtc())
|
||||
.stream()
|
||||
.filter(pollMessage -> TransferStatus.PENDING.getMessage().equals(pollMessage.getMsg()))
|
||||
.collect(onlyElement());
|
||||
PollMessage losingTransferApprovedPollMessage =
|
||||
getPollMessages("TheRegistrar", implicitTransferTime)
|
||||
.stream()
|
||||
.filter(Predicates.not(Predicates.equalTo(losingTransferPendingPollMessage)))
|
||||
.collect(onlyElement());
|
||||
assertThat(losingTransferPendingPollMessage.getEventTime()).isEqualTo(clock.nowUtc());
|
||||
assertThat(losingTransferApprovedPollMessage.getEventTime()).isEqualTo(implicitTransferTime);
|
||||
assertThat(
|
||||
Iterables.getOnlyElement(FluentIterable
|
||||
.from(losingTransferPendingPollMessage.getResponseData())
|
||||
.filter(TransferResponse.class))
|
||||
losingTransferPendingPollMessage
|
||||
.getResponseData()
|
||||
.stream()
|
||||
.filter(TransferResponse.class::isInstance)
|
||||
.map(TransferResponse.class::cast)
|
||||
.collect(onlyElement())
|
||||
.getTransferStatus())
|
||||
.isEqualTo(TransferStatus.PENDING);
|
||||
.isEqualTo(TransferStatus.PENDING);
|
||||
assertThat(
|
||||
Iterables.getOnlyElement(FluentIterable
|
||||
.from(losingTransferApprovedPollMessage.getResponseData())
|
||||
.filter(TransferResponse.class))
|
||||
losingTransferApprovedPollMessage
|
||||
.getResponseData()
|
||||
.stream()
|
||||
.filter(TransferResponse.class::isInstance)
|
||||
.map(TransferResponse.class::cast)
|
||||
.collect(onlyElement())
|
||||
.getTransferStatus())
|
||||
.isEqualTo(TransferStatus.SERVER_APPROVED);
|
||||
.isEqualTo(TransferStatus.SERVER_APPROVED);
|
||||
|
||||
// Assert that the poll messages show up in the TransferData server approve entities.
|
||||
assertPollMessagesEqual(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue