Import code from internal repository to git

This commit is contained in:
Justine Tunney 2016-03-01 17:18:14 -05:00
commit 0ef0c933d2
2490 changed files with 281594 additions and 0 deletions

View file

@ -0,0 +1,31 @@
package(default_visibility = ["//java/com/google/domain/registry:registry_project"])
java_library(
name = "sheet",
srcs = glob(["*.java"]),
deps = [
"//java/com/google/common/base",
"//java/com/google/common/collect",
"//java/com/google/common/net",
"//java/com/google/domain/registry/config",
"//java/com/google/domain/registry/export/sheet",
"//java/com/google/domain/registry/model",
"//java/com/google/gdata:spreadsheet",
"//javatests/com/google/domain/registry/testing",
"//third_party/java/joda_time",
"//third_party/java/jsr305_annotations",
"//third_party/java/junit",
"//third_party/java/mockito",
"//third_party/java/servlet/servlet_api",
"//third_party/java/truth",
],
)
load("//java/com/google/testing/builddefs:GenTestRules.bzl", "GenTestRules")
GenTestRules(
name = "GeneratedTestRules",
test_files = glob(["*Test.java"]),
deps = [":sheet"],
)

View file

@ -0,0 +1,148 @@
// Copyright 2016 Google Inc. 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 com.google.domain.registry.export.sheet;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.gdata.client.spreadsheet.SpreadsheetService;
import com.google.gdata.data.spreadsheet.CustomElementCollection;
import com.google.gdata.data.spreadsheet.ListEntry;
import com.google.gdata.data.spreadsheet.ListFeed;
import com.google.gdata.data.spreadsheet.SpreadsheetEntry;
import com.google.gdata.data.spreadsheet.WorksheetEntry;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import java.net.URL;
/** Unit tests for {@link SheetSynchronizer}. */
@RunWith(JUnit4.class)
public class SheetSynchronizerTest {
private final SpreadsheetService spreadsheetService = mock(SpreadsheetService.class);
private final SpreadsheetEntry spreadsheet = mock(SpreadsheetEntry.class);
private final WorksheetEntry worksheet = mock(WorksheetEntry.class);
private final ListFeed listFeed = mock(ListFeed.class);
private final SheetSynchronizer sheetSynchronizer = new SheetSynchronizer();
@Before
public void before() throws Exception {
sheetSynchronizer.spreadsheetService = spreadsheetService;
when(spreadsheetService.getEntry(any(URL.class), eq(SpreadsheetEntry.class)))
.thenReturn(spreadsheet);
when(spreadsheet.getWorksheets())
.thenReturn(ImmutableList.of(worksheet));
when(worksheet.getListFeedUrl())
.thenReturn(new URL("http://example.com/spreadsheet"));
when(spreadsheetService.getFeed(any(URL.class), eq(ListFeed.class)))
.thenReturn(listFeed);
when(worksheet.update())
.thenReturn(worksheet);
}
@After
public void after() throws Exception {
verify(spreadsheetService).getEntry(
new URL("https://spreadsheets.google.com/feeds/spreadsheets/foobar"),
SpreadsheetEntry.class);
verify(spreadsheet).getWorksheets();
verify(worksheet).getListFeedUrl();
verify(spreadsheetService).getFeed(new URL("http://example.com/spreadsheet"), ListFeed.class);
verify(listFeed).getEntries();
verifyNoMoreInteractions(spreadsheetService, spreadsheet, worksheet, listFeed);
}
@Test
public void testSynchronize_bothEmpty_doNothing() throws Exception {
when(listFeed.getEntries()).thenReturn(ImmutableList.<ListEntry>of());
sheetSynchronizer.synchronize("foobar", ImmutableList.<ImmutableMap<String, String>>of());
verify(worksheet).setRowCount(0);
verify(worksheet).update();
}
@Test
public void testSynchronize_bothContainSameRow_doNothing() throws Exception {
ListEntry entry = makeListEntry(ImmutableMap.of("key", "value"));
when(listFeed.getEntries()).thenReturn(ImmutableList.of(entry));
sheetSynchronizer.synchronize("foobar", ImmutableList.of(
ImmutableMap.of("key", "value")));
verify(worksheet).setRowCount(1);
verify(worksheet).update();
verify(entry, atLeastOnce()).getCustomElements();
verifyNoMoreInteractions(entry);
}
@Test
public void testSynchronize_cellIsDifferent_updateRow() throws Exception {
ListEntry entry = makeListEntry(ImmutableMap.of("key", "value"));
when(listFeed.getEntries()).thenReturn(ImmutableList.of(entry));
sheetSynchronizer.synchronize("foobar", ImmutableList.of(
ImmutableMap.of("key", "new value")));
verify(entry.getCustomElements()).setValueLocal("key", "new value");
verify(entry).update();
verify(worksheet).setRowCount(1);
verify(worksheet).update();
verify(entry, atLeastOnce()).getCustomElements();
verifyNoMoreInteractions(entry);
}
@Test
public void testSynchronize_spreadsheetMissingRow_insertRow() throws Exception {
ListEntry entry = makeListEntry(ImmutableMap.<String, String>of());
when(listFeed.getEntries()).thenReturn(ImmutableList.<ListEntry>of());
when(listFeed.createEntry()).thenReturn(entry);
sheetSynchronizer.synchronize("foobar", ImmutableList.of(
ImmutableMap.of("key", "value")));
verify(entry.getCustomElements()).setValueLocal("key", "value");
verify(listFeed).insert(entry);
verify(worksheet).setRowCount(1);
verify(worksheet).update();
verify(listFeed).createEntry();
verify(entry, atLeastOnce()).getCustomElements();
verifyNoMoreInteractions(entry);
}
@Test
public void testSynchronize_spreadsheetRowNoLongerInData_deleteRow() throws Exception {
ListEntry entry = makeListEntry(ImmutableMap.of("key", "value"));
when(listFeed.getEntries()).thenReturn(ImmutableList.of(entry));
sheetSynchronizer.synchronize("foobar", ImmutableList.<ImmutableMap<String, String>>of());
verify(worksheet).setRowCount(0);
verify(worksheet).update();
verifyNoMoreInteractions(entry);
}
private static ListEntry makeListEntry(ImmutableMap<String, String> values) {
CustomElementCollection collection = mock(CustomElementCollection.class);
for (ImmutableMap.Entry<String, String> entry : values.entrySet()) {
when(collection.getValue(eq(entry.getKey()))).thenReturn(entry.getValue());
}
ListEntry listEntry = mock(ListEntry.class);
when(listEntry.getCustomElements()).thenReturn(collection);
return listEntry;
}
}

View file

@ -0,0 +1,115 @@
// Copyright 2016 Google Inc. 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 com.google.domain.registry.export.sheet;
import static com.google.common.net.MediaType.PLAIN_TEXT_UTF_8;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import com.google.common.base.Optional;
import com.google.domain.registry.model.server.Lock;
import com.google.domain.registry.testing.AppEngineRule;
import com.google.domain.registry.testing.FakeResponse;
import org.joda.time.Duration;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import java.util.concurrent.Callable;
import javax.annotation.Nullable;
/** Unit tests for {@link SyncRegistrarsSheetTask}. */
@RunWith(JUnit4.class)
public class SyncRegistrarsSheetTaskTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.withTaskQueue()
.build();
private final FakeResponse response = new FakeResponse();
private final SyncRegistrarsSheet syncRegistrarsSheet = mock(SyncRegistrarsSheet.class);
private void runTask(@Nullable String idConfig, @Nullable String idParam) {
SyncRegistrarsSheetTask task = new SyncRegistrarsSheetTask();
task.response = response;
task.syncRegistrarsSheet = syncRegistrarsSheet;
task.idConfig = Optional.fromNullable(idConfig);
task.idParam = Optional.fromNullable(idParam);
task.interval = Duration.standardHours(1);
task.timeout = Duration.standardHours(1);
task.run();
}
@Test
public void testPost_withoutParamsOrSystemProperty_dropsTask() throws Exception {
runTask(null, null);
assertThat(response.getPayload()).startsWith("MISSINGNO");
verifyZeroInteractions(syncRegistrarsSheet);
}
@Test
public void testPost_withoutParams_runsSyncWithDefaultIdAndChecksIfModified() throws Exception {
when(syncRegistrarsSheet.wasRegistrarsModifiedInLast(any(Duration.class))).thenReturn(true);
runTask("jazz", null);
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContentType()).isEqualTo(PLAIN_TEXT_UTF_8);
assertThat(response.getPayload()).startsWith("OK");
verify(syncRegistrarsSheet).wasRegistrarsModifiedInLast(any(Duration.class));
verify(syncRegistrarsSheet).run(eq("jazz"));
verifyNoMoreInteractions(syncRegistrarsSheet);
}
@Test
public void testPost_noModificationsToRegistrarEntities_doesNothing() throws Exception {
when(syncRegistrarsSheet.wasRegistrarsModifiedInLast(any(Duration.class))).thenReturn(false);
runTask("NewRegistrar", null);
assertThat(response.getPayload()).startsWith("NOTMODIFIED");
verify(syncRegistrarsSheet).wasRegistrarsModifiedInLast(any(Duration.class));
verifyNoMoreInteractions(syncRegistrarsSheet);
}
@Test
public void testPost_overrideId_runsSyncWithCustomIdAndDoesNotCheckModified() throws Exception {
runTask(null, "foobar");
assertThat(response.getPayload()).startsWith("OK");
verify(syncRegistrarsSheet).run(eq("foobar"));
verifyNoMoreInteractions(syncRegistrarsSheet);
}
@Test
public void testPost_failToAquireLock_servletDoesNothingAndReturns() throws Exception {
String lockName = "Synchronize registrars sheet: foobar";
Lock.executeWithLocks(new Callable<Void>() {
@Override
public Void call() throws Exception {
runTask(null, "foobar");
return null;
}
}, SyncRegistrarsSheetTask.class, "", Duration.standardHours(1), lockName);
assertThat(response.getPayload()).startsWith("LOCKED");
verifyZeroInteractions(syncRegistrarsSheet);
}
}

View file

@ -0,0 +1,349 @@
// Copyright 2016 Google Inc. 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 com.google.domain.registry.export.sheet;
import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.common.truth.Truth.assertThat;
import static com.google.domain.registry.testing.DatastoreHelper.createTld;
import static com.google.domain.registry.testing.DatastoreHelper.deleteResource;
import static com.google.domain.registry.testing.DatastoreHelper.persistResource;
import static com.google.domain.registry.testing.DatastoreHelper.persistSimpleGlobalResources;
import static org.joda.time.DateTimeZone.UTC;
import static org.joda.time.Duration.standardHours;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.domain.registry.config.RegistryEnvironment;
import com.google.domain.registry.model.ofy.Ofy;
import com.google.domain.registry.model.registrar.Registrar;
import com.google.domain.registry.model.registrar.RegistrarAddress;
import com.google.domain.registry.model.registrar.RegistrarContact;
import com.google.domain.registry.testing.AppEngineRule;
import com.google.domain.registry.testing.FakeClock;
import com.google.domain.registry.testing.InjectRule;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
/** Unit tests for {@link SyncRegistrarsSheet}. */
@RunWith(MockitoJUnitRunner.class)
public class SyncRegistrarsSheetTest {
private static final RegistryEnvironment ENVIRONMENT = RegistryEnvironment.get();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
@Rule
public final InjectRule inject = new InjectRule();
@Captor
private ArgumentCaptor<ImmutableList<ImmutableMap<String, String>>> rowsCaptor;
@Mock
private SheetSynchronizer sheetSynchronizer;
private final FakeClock clock = new FakeClock(DateTime.now(UTC));
private SyncRegistrarsSheet newSyncRegistrarsSheet() {
SyncRegistrarsSheet result = new SyncRegistrarsSheet();
result.clock = clock;
result.sheetSynchronizer = sheetSynchronizer;
return result;
}
@Before
public void before() throws Exception {
inject.setStaticField(Ofy.class, "clock", clock);
createTld("example");
// Remove Registrar entities created by AppEngineRule.
for (Registrar registrar : Registrar.loadAll()) {
deleteResource(registrar);
}
}
@Test
public void testWasRegistrarsModifiedInLast_noRegistrars_returnsFalse() throws Exception {
SyncRegistrarsSheet sync = newSyncRegistrarsSheet();
assertThat(sync.wasRegistrarsModifiedInLast(Duration.standardHours(1))).isFalse();
}
@Test
public void testWasRegistrarsModifiedInLastInterval() throws Exception {
Duration interval = standardHours(1);
persistResource(new Registrar.Builder()
.setClientIdentifier("SomeRegistrar")
.setRegistrarName("Some Registrar Inc.")
.setType(Registrar.Type.REAL)
.setIanaIdentifier(8L)
.setState(Registrar.State.ACTIVE)
.build());
clock.advanceBy(interval);
assertThat(newSyncRegistrarsSheet().wasRegistrarsModifiedInLast(interval)).isTrue();
clock.advanceOneMilli();
assertThat(newSyncRegistrarsSheet().wasRegistrarsModifiedInLast(interval)).isFalse();
}
@Test
public void testRun() throws Exception {
persistResource(new Registrar.Builder()
.setClientIdentifier("anotherregistrar")
.setRegistrarName("Another Registrar LLC")
.setType(Registrar.Type.REAL)
.setIanaIdentifier(1L)
.setState(Registrar.State.ACTIVE)
.setInternationalizedAddress(new RegistrarAddress.Builder()
.setStreet(ImmutableList.of("I will get ignored :'("))
.setCity("Williamsburg")
.setState("NY")
.setZip("11211")
.setCountryCode("US")
.build())
.setLocalizedAddress(new RegistrarAddress.Builder()
.setStreet(ImmutableList.of(
"123 Main St",
"Suite 100"))
.setCity("Smalltown")
.setState("NY")
.setZip("11211")
.setCountryCode("US")
.build())
.setPhoneNumber("+1.2125551212")
.setFaxNumber("+1.2125551213")
.setEmailAddress("contact-us@example.com")
.setWhoisServer("whois.example.com")
.setUrl("http://www.example.org/another_registrar")
.setIcannReferralEmail("jim@example.net")
.build());
Registrar registrar = new Registrar.Builder()
.setClientIdentifier("aaaregistrar")
.setRegistrarName("AAA Registrar Inc.")
.setType(Registrar.Type.REAL)
.setIanaIdentifier(8L)
.setState(Registrar.State.SUSPENDED)
.setPassword("pa$$word")
.setEmailAddress("nowhere@example.org")
.setInternationalizedAddress(new RegistrarAddress.Builder()
.setStreet(ImmutableList.of("I get fallen back upon since there's no l10n addr"))
.setCity("Williamsburg")
.setState("NY")
.setZip("11211")
.setCountryCode("US")
.build())
.setAllowedTlds(ImmutableSet.of("example"))
.setPhoneNumber("+1.2223334444")
.setUrl("http://www.example.org/aaa_registrar")
.build();
ImmutableList<RegistrarContact> contacts = ImmutableList.of(
new RegistrarContact.Builder()
.setParent(registrar)
.setName("Jane Doe")
.setEmailAddress("contact@example.com")
.setPhoneNumber("+1.1234567890")
.setTypes(ImmutableSet.of(RegistrarContact.Type.ADMIN, RegistrarContact.Type.BILLING))
.build(),
new RegistrarContact.Builder()
.setParent(registrar)
.setName("John Doe")
.setEmailAddress("john.doe@example.tld")
.setPhoneNumber("+1.1234567890")
.setFaxNumber("+1.1234567891")
.setTypes(ImmutableSet.of(RegistrarContact.Type.ADMIN))
// Purposely flip the internal/external admin/tech
// distinction to make sure we're not relying on it. Sigh.
.setVisibleInWhoisAsAdmin(false)
.setVisibleInWhoisAsTech(true)
.setGaeUserId("light")
.build(),
new RegistrarContact.Builder()
.setParent(registrar)
.setName("Jane Smith")
.setEmailAddress("pride@example.net")
.setTypes(ImmutableSet.of(RegistrarContact.Type.TECH))
.build());
// Use registrar ref for contacts' parent.
persistSimpleGlobalResources(contacts);
persistResource(registrar);
newSyncRegistrarsSheet().run("foobar");
verify(sheetSynchronizer).synchronize(eq("foobar"), rowsCaptor.capture());
ImmutableList<ImmutableMap<String, String>> rows = getOnlyElement(rowsCaptor.getAllValues());
assertThat(rows).hasSize(2);
ImmutableMap<String, String> row = rows.get(0);
assertThat(row).containsEntry("clientIdentifier", "aaaregistrar");
assertThat(row).containsEntry("registrarName", "AAA Registrar Inc.");
assertThat(row).containsEntry("state", "SUSPENDED");
assertThat(row).containsEntry("ianaIdentifier", "8");
assertThat(row).containsEntry("billingIdentifier", "");
assertThat(row).containsEntry("primaryContacts", ""
+ "Jane Doe\n"
+ "contact@example.com\n"
+ "Tel: +1.1234567890\n"
+ "Types: [ADMIN, BILLING]\n"
+ "Visible in WHOIS as Admin contact: No\n"
+ "Visible in WHOIS as Technical contact: No\n"
+ "\n"
+ "John Doe\n"
+ "john.doe@example.tld\n"
+ "Tel: +1.1234567890\n"
+ "Fax: +1.1234567891\n"
+ "Types: [ADMIN]\n"
+ "Visible in WHOIS as Admin contact: No\n"
+ "Visible in WHOIS as Technical contact: Yes\n"
+ "GAE-UserID: light\n");
assertThat(row).containsEntry("techContacts", ""
+ "Jane Smith\n"
+ "pride@example.net\n"
+ "Types: [TECH]\n"
+ "Visible in WHOIS as Admin contact: No\n"
+ "Visible in WHOIS as Technical contact: No\n");
assertThat(row).containsEntry("marketingContacts", "");
assertThat(row).containsEntry("abuseContacts", "");
assertThat(row).containsEntry("whoisInquiryContacts", "");
assertThat(row).containsEntry("legalContacts", "");
assertThat(row).containsEntry("billingContacts", ""
+ "Jane Doe\n"
+ "contact@example.com\n"
+ "Tel: +1.1234567890\n"
+ "Types: [ADMIN, BILLING]\n"
+ "Visible in WHOIS as Admin contact: No\n"
+ "Visible in WHOIS as Technical contact: No\n");
assertThat(row).containsEntry("contactsMarkedAsWhoisAdmin", "");
assertThat(row).containsEntry("contactsMarkedAsWhoisTech", ""
+ "John Doe\n"
+ "john.doe@example.tld\n"
+ "Tel: +1.1234567890\n"
+ "Fax: +1.1234567891\n"
+ "Types: [ADMIN]\n"
+ "Visible in WHOIS as Admin contact: No\n"
+ "Visible in WHOIS as Technical contact: Yes\n"
+ "GAE-UserID: light\n");
assertThat(row).containsEntry("emailAddress", "nowhere@example.org");
assertThat(row).containsEntry(
"address.street", "I get fallen back upon since there's no l10n addr");
assertThat(row).containsEntry("address.city", "Williamsburg");
assertThat(row).containsEntry("address.state", "NY");
assertThat(row).containsEntry("address.zip", "11211");
assertThat(row).containsEntry("address.countryCode", "US");
assertThat(row).containsEntry("phoneNumber", "+1.2223334444");
assertThat(row).containsEntry("faxNumber", "");
assertThat(row.get("creationTime")).isEqualTo(clock.nowUtc().toString());
assertThat(row.get("lastUpdateTime")).isEqualTo(clock.nowUtc().toString());
assertThat(row).containsEntry("allowedTlds", "example");
assertThat(row).containsEntry("blockPremiumNames", "false");
assertThat(row).containsEntry("ipAddressWhitelist", "");
assertThat(row).containsEntry("url", "http://www.example.org/aaa_registrar");
assertThat(row).containsEntry("icannReferralEmail", "");
assertThat(row).containsEntry("whoisServer",
ENVIRONMENT.config().getRegistrarDefaultWhoisServer());
assertThat(row).containsEntry("referralUrl",
ENVIRONMENT.config().getRegistrarDefaultReferralUrl().toString());
row = rows.get(1);
assertThat(row).containsEntry("clientIdentifier", "anotherregistrar");
assertThat(row).containsEntry("registrarName", "Another Registrar LLC");
assertThat(row).containsEntry("state", "ACTIVE");
assertThat(row).containsEntry("ianaIdentifier", "1");
assertThat(row).containsEntry("billingIdentifier", "");
assertThat(row).containsEntry("primaryContacts", "");
assertThat(row).containsEntry("techContacts", "");
assertThat(row).containsEntry("marketingContacts", "");
assertThat(row).containsEntry("abuseContacts", "");
assertThat(row).containsEntry("whoisInquiryContacts", "");
assertThat(row).containsEntry("legalContacts", "");
assertThat(row).containsEntry("billingContacts", "");
assertThat(row).containsEntry("contactsMarkedAsWhoisAdmin", "");
assertThat(row).containsEntry("contactsMarkedAsWhoisTech", "");
assertThat(row).containsEntry("emailAddress", "contact-us@example.com");
assertThat(row).containsEntry("address.street", "123 Main St\nSuite 100");
assertThat(row).containsEntry("address.city", "Smalltown");
assertThat(row).containsEntry("address.state", "NY");
assertThat(row).containsEntry("address.zip", "11211");
assertThat(row).containsEntry("address.countryCode", "US");
assertThat(row).containsEntry("phoneNumber", "+1.2125551212");
assertThat(row).containsEntry("faxNumber", "+1.2125551213");
assertThat(row.get("creationTime")).isEqualTo(clock.nowUtc().toString());
assertThat(row.get("lastUpdateTime")).isEqualTo(clock.nowUtc().toString());
assertThat(row).containsEntry("allowedTlds", "");
assertThat(row).containsEntry("whoisServer", "whois.example.com");
assertThat(row).containsEntry("blockPremiumNames", "false");
assertThat(row).containsEntry("ipAddressWhitelist", "");
assertThat(row).containsEntry("url", "http://www.example.org/another_registrar");
assertThat(row).containsEntry("referralUrl",
ENVIRONMENT.config().getRegistrarDefaultReferralUrl().toString());
assertThat(row).containsEntry("icannReferralEmail", "jim@example.net");
}
@Test
public void testRun_missingValues_stillWorks() throws Exception {
persistResource(new Registrar.Builder()
.setClientIdentifier("SomeRegistrar")
.setType(Registrar.Type.REAL)
.setIanaIdentifier(8L)
.build());
newSyncRegistrarsSheet().run("foobar");
verify(sheetSynchronizer).synchronize(eq("foobar"), rowsCaptor.capture());
ImmutableMap<String, String> row = getOnlyElement(getOnlyElement(rowsCaptor.getAllValues()));
assertThat(row).containsEntry("clientIdentifier", "SomeRegistrar");
assertThat(row).containsEntry("registrarName", "");
assertThat(row).containsEntry("state", "");
assertThat(row).containsEntry("ianaIdentifier", "8");
assertThat(row).containsEntry("billingIdentifier", "");
assertThat(row).containsEntry("primaryContacts", "");
assertThat(row).containsEntry("techContacts", "");
assertThat(row).containsEntry("marketingContacts", "");
assertThat(row).containsEntry("abuseContacts", "");
assertThat(row).containsEntry("whoisInquiryContacts", "");
assertThat(row).containsEntry("legalContacts", "");
assertThat(row).containsEntry("billingContacts", "");
assertThat(row).containsEntry("contactsMarkedAsWhoisAdmin", "");
assertThat(row).containsEntry("contactsMarkedAsWhoisTech", "");
assertThat(row).containsEntry("emailAddress", "");
assertThat(row).containsEntry("address.street", "UNKNOWN");
assertThat(row).containsEntry("address.city", "UNKNOWN");
assertThat(row).containsEntry("address.state", "");
assertThat(row).containsEntry("address.zip", "");
assertThat(row).containsEntry("address.countryCode", "US");
assertThat(row).containsEntry("phoneNumber", "");
assertThat(row).containsEntry("faxNumber", "");
assertThat(row).containsEntry("allowedTlds", "");
assertThat(row).containsEntry("whoisServer",
ENVIRONMENT.config().getRegistrarDefaultWhoisServer());
assertThat(row).containsEntry("blockPremiumNames", "false");
assertThat(row).containsEntry("ipAddressWhitelist", "");
assertThat(row).containsEntry("url", "");
assertThat(row).containsEntry("referralUrl",
ENVIRONMENT.config().getRegistrarDefaultReferralUrl().toString());
assertThat(row).containsEntry("icannReferralEmail", "");
}
}