google-nomulus/javatests/google/registry/batch/ResaveEntityActionTest.java
mcilwain 6f2e663b72 Add asynchronous scheduled actions to re-save entities
This is used in the domain transfer and delete flows, both of which are
asynchronous flows that have implicit default actions that will be taken at some
point in the future. This CL adds scheduled re-saves to take place soon after
those default actions would become effective, so that they can be re-saved
quickly if so.

Unfortunately the redemption grace period on our TLDs is 35 days, which exceeds
the 30 day maximum task ETA in App Engine, so these won't actually fire.  That's
fine though; the deletion is actually effective as of 5 days, and this is just
removing the grace period.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=201345274
2018-06-27 15:28:52 -04:00

83 lines
3.3 KiB
Java

// Copyright 2018 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.batch;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistDomainWithDependentResources;
import static google.registry.testing.DatastoreHelper.persistDomainWithPendingTransfer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import com.googlecode.objectify.Key;
import google.registry.model.ImmutableObject;
import google.registry.model.domain.DomainResource;
import google.registry.request.Response;
import google.registry.testing.AppEngineRule;
import google.registry.testing.FakeClock;
import google.registry.testing.ShardableTestCase;
import google.registry.util.Clock;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link ResaveEntityAction}. */
@RunWith(JUnit4.class)
public class ResaveEntityActionTest extends ShardableTestCase {
@Rule
public final AppEngineRule appEngine =
AppEngineRule.builder().withDatastore().withTaskQueue().build();
private final Clock clock = new FakeClock(DateTime.parse("2016-02-11T10:00:00Z"));
private final Response response = mock(Response.class);
@Before
public void before() {
createTld("tld");
}
private void runAction(Key<ImmutableObject> resourceKey, DateTime requestedTime) {
ResaveEntityAction action = new ResaveEntityAction(resourceKey, requestedTime, clock, response);
action.run();
}
@Test
public void test_domainPendingTransfer_isResavedAndTransferCompleted() {
DomainResource domain =
persistDomainWithPendingTransfer(
persistDomainWithDependentResources(
"domain",
"tld",
persistActiveContact("jd1234"),
DateTime.parse("2016-02-06T10:00:00Z"),
DateTime.parse("2016-02-06T10:00:00Z"),
DateTime.parse("2017-01-02T10:11:00Z")),
DateTime.parse("2016-02-06T10:00:00Z"),
DateTime.parse("2016-02-11T10:00:00Z"),
DateTime.parse("2017-01-02T10:11:00Z"),
DateTime.parse("2016-02-06T10:00:00Z"));
assertThat(domain.getCurrentSponsorClientId()).isEqualTo("TheRegistrar");
runAction(Key.create(domain), DateTime.parse("2016-02-06T10:00:01Z"));
DomainResource resavedDomain = ofy().load().entity(domain).now();
assertThat(resavedDomain.getCurrentSponsorClientId()).isEqualTo("NewRegistrar");
verify(response).setPayload("Entity re-saved.");
}
}