// 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.rdap; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.truth.Truth.assertThat; import static google.registry.request.Action.Method.GET; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResources; import static google.registry.testing.DatastoreHelper.persistSimpleResources; import static google.registry.testing.FullFieldsTestEntityHelper.makeAndPersistContactResource; import static google.registry.testing.FullFieldsTestEntityHelper.makeAndPersistDeletedContactResource; import static google.registry.testing.FullFieldsTestEntityHelper.makeContactResource; import static google.registry.testing.FullFieldsTestEntityHelper.makeHistoryEntry; import static google.registry.testing.FullFieldsTestEntityHelper.makeRegistrar; import static google.registry.testing.FullFieldsTestEntityHelper.makeRegistrarContacts; import static google.registry.testing.TestDataHelper.loadFile; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ImmutableMap; import google.registry.model.ImmutableObject; import google.registry.model.contact.ContactResource; import google.registry.model.registrar.Registrar; import google.registry.model.reporting.HistoryEntry; import google.registry.rdap.RdapMetrics.EndpointType; import google.registry.rdap.RdapMetrics.SearchType; import google.registry.rdap.RdapSearchResults.IncompletenessWarningType; import google.registry.testing.FakeResponse; import java.net.URLDecoder; import java.util.List; import java.util.Map; import java.util.Optional; import javax.annotation.Nullable; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.JSONValue; import org.junit.Before; 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 extends RdapSearchActionTestCase { public RdapEntitySearchActionTest() { super(RdapEntitySearchAction.class); } private enum QueryType { FULL_NAME, HANDLE } private Registrar registrarDeleted; private Registrar registrarInactive; private Registrar registrarTest; private Object generateActualJsonWithFullName(String fn) { return generateActualJsonWithFullName(fn, null); } private Object generateActualJsonWithFullName(String fn, String cursor) { metricSearchType = SearchType.BY_FULL_NAME; action.fnParam = Optional.of(fn); if (cursor == null) { action.parameterMap = ImmutableListMultimap.of("fn", fn); action.cursorTokenParam = Optional.empty(); } else { action.parameterMap = ImmutableListMultimap.of("fn", fn, "cursor", cursor); action.cursorTokenParam = Optional.of(cursor); } action.run(); return JSONValue.parse(response.getPayload()); } private Object generateActualJsonWithHandle(String handle) { return generateActualJsonWithHandle(handle, null); } private Object generateActualJsonWithHandle(String handle, String cursor) { metricSearchType = SearchType.BY_HANDLE; action.handleParam = Optional.of(handle); if (cursor == null) { action.parameterMap = ImmutableListMultimap.of("handle", handle); action.cursorTokenParam = Optional.empty(); } else { action.parameterMap = ImmutableListMultimap.of("handle", handle, "cursor", cursor); action.cursorTokenParam = Optional.of(cursor); } action.run(); return JSONValue.parse(response.getPayload()); } @Before public void setUp() { createTld("tld"); // deleted registrarDeleted = persistResource( makeRegistrar("2-Registrar", "Yes Virginia