mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 07:57:13 +02:00
Ensure that poll messages are created in domain create flow tests
Also ensures that a custom logic hook is called on create. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=143112481
This commit is contained in:
parent
1c927a48e9
commit
393eeabc5e
6 changed files with 142 additions and 4 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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<DomainCreateFlow,
|
|||
expectedBillingEvents.add(eapBillingEvent);
|
||||
}
|
||||
assertBillingEvents(expectedBillingEvents.build());
|
||||
assertPollMessagesForResource(
|
||||
domain,
|
||||
new PollMessage.Autorenew.Builder()
|
||||
.setTargetId(domain.getFullyQualifiedDomainName())
|
||||
.setClientId("TheRegistrar")
|
||||
.setEventTime(domain.getRegistrationExpirationTime())
|
||||
.setMsg("Domain was auto-renewed.")
|
||||
.setParent(historyEntry)
|
||||
.build());
|
||||
|
||||
assertGracePeriods(
|
||||
domain.getGracePeriods(),
|
||||
|
@ -1175,6 +1186,36 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
|||
assertSuccessfulCreate("example", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_customLogicIsCalled_andSavesExtraEntity() throws Exception {
|
||||
// @see TestDomainCreateFlowCustomLogic for what the label "custom-logic-test" triggers.
|
||||
ImmutableMap<String, String> 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");
|
||||
|
|
22
javatests/google/registry/flows/domain/testdata/domain_create_wildcard.xml
vendored
Normal file
22
javatests/google/registry/flows/domain/testdata/domain_create_wildcard.xml
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<command>
|
||||
<create>
|
||||
<domain:create
|
||||
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
||||
<domain:name>%DOMAIN%</domain:name>
|
||||
<domain:period unit="y">2</domain:period>
|
||||
<domain:ns>
|
||||
<domain:hostObj>ns1.example.net</domain:hostObj>
|
||||
<domain:hostObj>ns2.example.net</domain:hostObj>
|
||||
</domain:ns>
|
||||
<domain:registrant>jd1234</domain:registrant>
|
||||
<domain:contact type="admin">sh8013</domain:contact>
|
||||
<domain:contact type="tech">sh8013</domain:contact>
|
||||
<domain:authInfo>
|
||||
<domain:pw>2fooBAR</domain:pw>
|
||||
</domain:authInfo>
|
||||
</domain:create>
|
||||
</create>
|
||||
<clTRID>ABC-12345</clTRID>
|
||||
</command>
|
||||
</epp>
|
|
@ -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<PollMessage, PollMessage> POLL_MESSAGE_ID_STRIPPER =
|
||||
new Function<PollMessage, PollMessage>() {
|
||||
@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<PollMessage> getPollMessages() {
|
||||
return FluentIterable.from(ofy().load().type(PollMessage.class)).toList();
|
||||
}
|
||||
|
@ -667,6 +683,10 @@ public class DatastoreHelper {
|
|||
.toList();
|
||||
}
|
||||
|
||||
public static ImmutableList<PollMessage> getPollMessages(EppResource resource) {
|
||||
return FluentIterable.from(ofy().load().type(PollMessage.class).ancestor(resource)).toList();
|
||||
}
|
||||
|
||||
public static ImmutableList<PollMessage> getPollMessages(String clientId, DateTime now) {
|
||||
return FluentIterable
|
||||
.from(ofy()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue