diff --git a/java/google/registry/model/poll/PollMessage.java b/java/google/registry/model/poll/PollMessage.java index 5360190ea..28fccd3bb 100644 --- a/java/google/registry/model/poll/PollMessage.java +++ b/java/google/registry/model/poll/PollMessage.java @@ -14,11 +14,11 @@ package google.registry.model.poll; -import static com.google.common.base.Preconditions.checkNotNull; import static google.registry.util.CollectionUtils.forceEmptyToNull; import static google.registry.util.CollectionUtils.isNullOrEmpty; import static google.registry.util.CollectionUtils.nullToEmpty; import static google.registry.util.DateTimeUtils.END_OF_TIME; +import static google.registry.util.PreconditionsUtils.checkArgumentNotNull; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Converter; @@ -172,9 +172,9 @@ public abstract class PollMessage extends ImmutableObject @Override public T build() { T instance = getInstance(); - checkNotNull(instance.clientId); - checkNotNull(instance.eventTime); - checkNotNull(instance.parent); + checkArgumentNotNull(instance.clientId, "clientId must be specified"); + checkArgumentNotNull(instance.eventTime, "eventTime must be specified"); + checkArgumentNotNull(instance.parent, "parent must be specified"); return super.build(); } } diff --git a/javatests/google/registry/flows/custom/TestCustomLogicFactory.java b/javatests/google/registry/flows/custom/TestCustomLogicFactory.java index 7e608aacc..f2fc55dd0 100644 --- a/javatests/google/registry/flows/custom/TestCustomLogicFactory.java +++ b/javatests/google/registry/flows/custom/TestCustomLogicFactory.java @@ -20,6 +20,12 @@ import google.registry.model.eppinput.EppInput; /** A custom logic factory for testing. */ public class TestCustomLogicFactory extends CustomLogicFactory { + @Override + public DomainCreateFlowCustomLogic forDomainCreateFlow( + EppInput eppInput, SessionMetadata sessionMetadata) { + return new TestDomainCreateFlowCustomLogic(eppInput, sessionMetadata); + } + @Override public DomainPricingCustomLogic forDomainPricing( EppInput eppInput, SessionMetadata sessionMetadata) { diff --git a/javatests/google/registry/flows/custom/TestDomainCreateFlowCustomLogic.java b/javatests/google/registry/flows/custom/TestDomainCreateFlowCustomLogic.java new file mode 100644 index 000000000..00cf5cf82 --- /dev/null +++ b/javatests/google/registry/flows/custom/TestDomainCreateFlowCustomLogic.java @@ -0,0 +1,49 @@ +// Copyright 2016 The Nomulus Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package google.registry.flows.custom; + +import static google.registry.model.ofy.ObjectifyService.ofy; + +import google.registry.flows.EppException; +import google.registry.flows.SessionMetadata; +import google.registry.model.eppinput.EppInput; +import google.registry.model.poll.PollMessage; + +/** A class to customize {@link DomainCreateFlowCustomLogic} for testing. */ +public class TestDomainCreateFlowCustomLogic extends DomainCreateFlowCustomLogic { + + protected TestDomainCreateFlowCustomLogic(EppInput eppInput, SessionMetadata sessionMetadata) { + super(eppInput, sessionMetadata); + } + + @Override + public EntityChanges beforeSave(BeforeSaveParameters parameters) throws EppException { + if (parameters.newDomain().getFullyQualifiedDomainName().startsWith("custom-logic-test")) { + PollMessage extraPollMessage = + new PollMessage.OneTime.Builder() + .setParent(parameters.historyEntry()) + .setEventTime(ofy().getTransactionTime()) + .setClientId(getSessionMetadata().getClientId()) + .setMsg("Custom logic was triggered") + .build(); + return EntityChanges.newBuilder() + .setSaves(parameters.entityChanges().getSaves()) + .addSave(extraPollMessage) + .setDeletes(parameters.entityChanges().getDeletes()) + .build(); + } + return parameters.entityChanges(); + } +} diff --git a/javatests/google/registry/flows/domain/DomainCreateFlowTest.java b/javatests/google/registry/flows/domain/DomainCreateFlowTest.java index a93b71c51..fa60e3436 100644 --- a/javatests/google/registry/flows/domain/DomainCreateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainCreateFlowTest.java @@ -20,6 +20,7 @@ import static google.registry.model.domain.fee.Fee.FEE_EXTENSION_URIS; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.pricing.PricingEngineProxy.isDomainPremium; import static google.registry.testing.DatastoreHelper.assertBillingEvents; +import static google.registry.testing.DatastoreHelper.assertPollMessagesForResource; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.deleteTld; import static google.registry.testing.DatastoreHelper.getHistoryEntries; @@ -112,6 +113,7 @@ import google.registry.model.domain.launch.LaunchNotice; import google.registry.model.domain.rgp.GracePeriodStatus; import google.registry.model.domain.secdns.DelegationSignerData; import google.registry.model.eppcommon.StatusValue; +import google.registry.model.poll.PollMessage; import google.registry.model.registrar.Registrar; import google.registry.model.registry.Registry; import google.registry.model.registry.Registry.TldState; @@ -234,6 +236,15 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase substitutions = ImmutableMap.of("DOMAIN", "custom-logic-test.tld"); + setEppInput("domain_create_wildcard.xml", substitutions); + persistContactsAndHosts(); + runFlowAssertResponse( + CommitMode.LIVE, + UserPrivileges.NORMAL, + readFile("domain_create_response_wildcard.xml", substitutions)); + DomainResource domain = reloadResourceByForeignKey(); + HistoryEntry historyEntry = getHistoryEntries(domain).get(0); + assertPollMessagesForResource( + domain, + new PollMessage.Autorenew.Builder() + .setTargetId(domain.getFullyQualifiedDomainName()) + .setClientId("TheRegistrar") + .setEventTime(domain.getRegistrationExpirationTime()) + .setMsg("Domain was auto-renewed.") + .setParent(historyEntry) + .build(), + new PollMessage.OneTime.Builder() + .setParent(historyEntry) + .setEventTime(domain.getCreationTime()) + .setClientId("TheRegistrar") + .setMsg("Custom logic was triggered") + .setId(1L) + .build()); + } + @Test public void testFailure_duplicateContact() throws Exception { setEppInput("domain_create_duplicate_contact.xml"); diff --git a/javatests/google/registry/flows/domain/testdata/domain_create_wildcard.xml b/javatests/google/registry/flows/domain/testdata/domain_create_wildcard.xml new file mode 100644 index 000000000..f5bc7c25a --- /dev/null +++ b/javatests/google/registry/flows/domain/testdata/domain_create_wildcard.xml @@ -0,0 +1,22 @@ + + + + + %DOMAIN% + 2 + + ns1.example.net + ns2.example.net + + jd1234 + sh8013 + sh8013 + + 2fooBAR + + + + ABC-12345 + + diff --git a/javatests/google/registry/testing/DatastoreHelper.java b/javatests/google/registry/testing/DatastoreHelper.java index c1bea28df..3851b31e5 100644 --- a/javatests/google/registry/testing/DatastoreHelper.java +++ b/javatests/google/registry/testing/DatastoreHelper.java @@ -657,6 +657,22 @@ public class DatastoreHelper { return billingEvent.asBuilder().setId(1L).build(); }}; + public static void assertPollMessagesForResource(EppResource resource, PollMessage... expected) + throws Exception { + assertThat(FluentIterable.from(getPollMessages(resource)).transform(POLL_MESSAGE_ID_STRIPPER)) + .containsExactlyElementsIn( + FluentIterable.from(asList(expected)).transform(POLL_MESSAGE_ID_STRIPPER)); + } + + /** Helper to effectively erase the poll message ID to facilitate comparison. */ + public static final Function POLL_MESSAGE_ID_STRIPPER = + new Function() { + @Override + public PollMessage apply(PollMessage pollMessage) { + // Can't use id=0 because that causes the builder to generate a new id. + return pollMessage.asBuilder().setId(1L).build(); + }}; + public static ImmutableList getPollMessages() { return FluentIterable.from(ofy().load().type(PollMessage.class)).toList(); } @@ -667,6 +683,10 @@ public class DatastoreHelper { .toList(); } + public static ImmutableList getPollMessages(EppResource resource) { + return FluentIterable.from(ofy().load().type(PollMessage.class).ancestor(resource)).toList(); + } + public static ImmutableList getPollMessages(String clientId, DateTime now) { return FluentIterable .from(ofy()