google-nomulus/javatests/google/registry/tools/server/ResaveAllHistoryEntriesActionTest.java
mcilwain e2528875b2 Merge DomainResource into DomainBase
This eliminates the use of Objectify polymorphism for EPP resources entirely
(yay!), which makes the Registry 3.0 database migration easier.

It is unfortunate that the naming parallelism of EppResources is lost between
ContactResource, HostResource, and DomainResource, but the actual type as far as
Datastore was concerned was DomainBase all along, and it would be a much more
substantial data migration to allow us to continue using the class name
DomainResource now that we're no longer using Objectify polymorphism. This
simply isn't worth it.

This also removes the polymorphic Datastore indexes (which will no longer
function as of this change). The non-polymorphic replacement indexes were added
in []

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=230930546
2019-01-28 15:57:10 -05:00

83 lines
3.5 KiB
Java

// Copyright 2017 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.tools.server;
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.persistActiveDomain;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import google.registry.model.contact.ContactResource;
import google.registry.model.domain.DomainBase;
import google.registry.model.reporting.HistoryEntry;
import google.registry.testing.FakeResponse;
import google.registry.testing.mapreduce.MapreduceTestCase;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link ResaveAllHistoryEntriesAction}. */
@RunWith(JUnit4.class)
public class ResaveAllHistoryEntriesActionTest
extends MapreduceTestCase<ResaveAllHistoryEntriesAction> {
private static final DatastoreService datastoreService =
DatastoreServiceFactory.getDatastoreService();
@Before
public void init() {
action = new ResaveAllHistoryEntriesAction();
action.mrRunner = makeDefaultRunner();
action.response = new FakeResponse();
}
private void runMapreduce() throws Exception {
action.run();
executeTasksUntilEmpty("mapreduce");
}
@Test
public void test_mapreduceSuccessfullyResavesEntity() throws Exception {
createTld("tld");
DomainBase domain = persistActiveDomain("test.tld");
ContactResource contact = persistActiveContact("humanBeing");
Entity domainEntry =
ofy().save().toEntity(new HistoryEntry.Builder().setParent(domain).build());
Entity contactEntry =
ofy().save().toEntity(new HistoryEntry.Builder().setParent(contact).build());
// Set raw properties outside the Objectify schema, which will be deleted upon re-save.
domainEntry.setProperty("clientId", "validId");
contactEntry.setProperty("otherClientId", "anotherId");
domainEntry.setProperty("propertyToBeDeleted", "123blah");
contactEntry.setProperty("alsoShouldBeDeleted", "456nah");
datastoreService.put(domainEntry);
datastoreService.put(contactEntry);
ofy().clearSessionCache();
runMapreduce();
Entity updatedDomainEntry = datastoreService.get(domainEntry.getKey());
Entity updatedContactEntry = datastoreService.get(contactEntry.getKey());
assertThat(updatedDomainEntry.getProperty("clientId")).isEqualTo("validId");
assertThat(updatedDomainEntry.getProperty("propertyToBeDeleted")).isNull();
assertThat(updatedContactEntry.getProperty("otherClientId")).isEqualTo("anotherId");
assertThat(updatedContactEntry.getProperty("alsoShouldBeDeleted")).isNull();
}
}