// Copyright 2016 The Domain Registry 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.rdap; import static com.google.common.truth.Truth.assertThat; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistSimpleResources; import static google.registry.testing.FullFieldsTestEntityHelper.makeAndPersistContactResource; import static google.registry.testing.FullFieldsTestEntityHelper.makeContactResource; import static google.registry.testing.FullFieldsTestEntityHelper.makeRegistrar; import static google.registry.testing.FullFieldsTestEntityHelper.makeRegistrarContacts; import static google.registry.testing.TestDataHelper.loadFileWithSubstitutions; import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import google.registry.model.contact.ContactResource; import google.registry.model.ofy.Ofy; import google.registry.model.registrar.Registrar; import google.registry.testing.AppEngineRule; import google.registry.testing.FakeClock; import google.registry.testing.FakeResponse; import google.registry.testing.InjectRule; import javax.annotation.Nullable; import org.joda.time.DateTime; import org.json.simple.JSONValue; 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 RdapEntitySearchAction}. */ @RunWith(JUnit4.class) public class RdapEntitySearchActionTest { @Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build(); @Rule public final InjectRule inject = new InjectRule(); private final FakeResponse response = new FakeResponse(); private final FakeClock clock = new FakeClock(DateTime.parse("2000-01-01T00:00:00Z")); private final RdapEntitySearchAction action = new RdapEntitySearchAction(); private ContactResource contact; private Registrar registrar; private Registrar registrarInactive; private Registrar registrarTest; private Object generateActualJsonWithFullName(String fn) { action.fnParam = Optional.of(fn); action.run(); return JSONValue.parse(response.getPayload()); } private Object generateActualJsonWithHandle(String handle) { action.handleParam = Optional.of(handle); action.run(); return JSONValue.parse(response.getPayload()); } @Before public void setUp() throws Exception { inject.setStaticField(Ofy.class, "clock", clock); createTld("tld"); contact = makeAndPersistContactResource( "blinky", "Blinky (赤ベイ)", "blinky@b.tld", ImmutableList.of("123 Blinky St", "Blinkyland"), clock.nowUtc()); makeAndPersistContactResource( "blindly", "Blindly", "blindly@b.tld", ImmutableList.of("123 Blindly St", "Blindlyland"), clock.nowUtc()); // deleted persistResource( makeContactResource("clyde", "Clyde (愚図た)", "clyde@c.tld") .asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); registrar = persistResource( makeRegistrar("2-Registrar", "Yes Virginia