Make Registrar load methods return Optionals instead of Nullables

This makes the code more understandable from callsites, and also forces
users of this function to deal with the situation where the registrar
with a given client ID might not be present (it was previously silently
NPEing from some of the callsites).

This also adds a test helper method loadRegistrar(clientId) that retains
the old functionality for terseness in tests. It also fixes some instances
of using the load method with the wrong cachedness -- some uses in high-
traffic situations (WHOIS) that should have caching, but also low-traffic
reporting that don't benefit from caching so might as well always be
current.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=162990468
This commit is contained in:
mcilwain 2017-07-24 14:43:20 -07:00 committed by Ben McIlwain
parent 84fdeebc2f
commit d536cef20f
81 changed files with 707 additions and 602 deletions

View file

@ -18,6 +18,7 @@ import static com.google.common.collect.Iterables.getOnlyElement;
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.loadRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource;
import static org.joda.money.CurrencyUnit.USD;
import static org.joda.time.DateTimeZone.UTC;
@ -44,7 +45,7 @@ public class CreateCreditBalanceCommandTest extends CommandTestCase<CreateCredit
@Before
public void setUp() {
registrar = Registrar.loadByClientId("TheRegistrar");
registrar = loadRegistrar("TheRegistrar");
createTld("tld");
assertThat(Registry.get("tld").getCurrency()).isEqualTo(USD);
credit = persistResource(
@ -79,7 +80,7 @@ public class CreateCreditBalanceCommandTest extends CommandTestCase<CreateCredit
@Test
public void testFailure_nonexistentParentRegistrar() throws Exception {
thrown.expect(NullPointerException.class, "FakeRegistrar");
thrown.expect(IllegalArgumentException.class, "Registrar FakeRegistrar not found");
runCommandForced(
"--registrar=FakeRegistrar",
"--credit_id=" + creditId,

View file

@ -18,6 +18,7 @@ import static com.google.common.collect.Iterables.getOnlyElement;
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.loadRegistrar;
import static org.joda.money.CurrencyUnit.USD;
import static org.joda.time.DateTimeZone.UTC;
@ -41,7 +42,7 @@ public class CreateCreditCommandTest extends CommandTestCase<CreateCreditCommand
@Before
public void setUp() {
createTld("tld");
registrar = Registrar.loadByClientId("TheRegistrar");
registrar = loadRegistrar("TheRegistrar");
assertThat(Registry.get("tld").getCurrency()).isEqualTo(USD);
}
@ -92,7 +93,7 @@ public class CreateCreditCommandTest extends CommandTestCase<CreateCreditCommand
@Test
public void testFailure_nonexistentParentRegistrar() throws Exception {
thrown.expect(NullPointerException.class, "FakeRegistrar");
thrown.expect(IllegalArgumentException.class, "Registrar FakeRegistrar not found");
runCommandForced(
"--registrar=FakeRegistrar",
"--type=PROMOTION",

View file

@ -27,6 +27,7 @@ import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import com.beust.jcommander.ParameterException;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Range;
import com.google.common.net.MediaType;
@ -73,8 +74,9 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
// Clear the cache so that the CreateAutoTimestamp field gets reloaded.
ofy().clearSessionCache();
Registrar registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isNotNull();
Optional<Registrar> registrarOptional = Registrar.loadByClientId("clientz");
assertThat(registrarOptional).isPresent();
Registrar registrar = registrarOptional.get();
assertThat(registrar.testPassword("some_password")).isTrue();
assertThat(registrar.getType()).isEqualTo(Registrar.Type.REAL);
assertThat(registrar.getIanaIdentifier()).isEqualTo(8);
@ -110,9 +112,9 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"clientz");
Registrar registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isNotNull();
assertThat(registrar.testPassword("some_password")).isTrue();
Optional<Registrar> registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isPresent();
assertThat(registrar.get().testPassword("some_password")).isTrue();
}
@Test
@ -130,9 +132,9 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"clientz");
Registrar registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isNotNull();
assertThat(registrar.getType()).isEqualTo(Registrar.Type.TEST);
Optional<Registrar> registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isPresent();
assertThat(registrar.get().getType()).isEqualTo(Registrar.Type.TEST);
}
@Test
@ -152,9 +154,9 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"clientz");
Registrar registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isNotNull();
assertThat(registrar.getState()).isEqualTo(Registrar.State.SUSPENDED);
Optional<Registrar> registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isPresent();
assertThat(registrar.get().getState()).isEqualTo(Registrar.State.SUSPENDED);
}
@Test
@ -177,9 +179,9 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"clientz");
Registrar registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isNotNull();
assertThat(registrar.getAllowedTlds()).containsExactly("xn--q9jyb4c", "foobar");
Optional<Registrar> registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isPresent();
assertThat(registrar.get().getAllowedTlds()).containsExactly("xn--q9jyb4c", "foobar");
}
@Test
@ -224,8 +226,8 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"clientz");
Registrar registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isNotNull();
Optional<Registrar> registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isPresent();
assertInStdout("Registrar created, but groups creation failed with error");
assertInStdout("BAD ROBOT NO COOKIE");
}
@ -267,10 +269,11 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"clientz");
Registrar registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isNotNull();
assertThat(registrar.getIpAddressWhitelist())
.containsExactlyElementsIn(registrar.getIpAddressWhitelist()).inOrder();
Optional<Registrar> registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isPresent();
assertThat(registrar.get().getIpAddressWhitelist())
.containsExactlyElementsIn(registrar.get().getIpAddressWhitelist())
.inOrder();
}
@Test
@ -290,9 +293,9 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"clientz");
Registrar registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isNotNull();
assertThat(registrar.getIpAddressWhitelist()).isEmpty();
Optional<Registrar> registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isPresent();
assertThat(registrar.get().getIpAddressWhitelist()).isEmpty();
}
@Test
@ -312,9 +315,9 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"clientz");
Registrar registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isNotNull();
assertThat(registrar.getClientCertificateHash())
Optional<Registrar> registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isPresent();
assertThat(registrar.get().getClientCertificateHash())
.isEqualTo(CertificateSamples.SAMPLE_CERT_HASH);
}
@ -335,10 +338,10 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"clientz");
Registrar registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isNotNull();
assertThat(registrar.getClientCertificate()).isNull();
assertThat(registrar.getClientCertificateHash()).isEqualTo(SAMPLE_CERT_HASH);
Optional<Registrar> registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isPresent();
assertThat(registrar.get().getClientCertificate()).isNull();
assertThat(registrar.get().getClientCertificateHash()).isEqualTo(SAMPLE_CERT_HASH);
}
@Test
@ -358,8 +361,9 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"clientz");
Registrar registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isNotNull();
Optional<Registrar> registrarOptional = Registrar.loadByClientId("clientz");
assertThat(registrarOptional).isPresent();
Registrar registrar = registrarOptional.get();
assertThat(registrar.getClientCertificate()).isNull();
assertThat(registrar.getClientCertificateHash()).isNull();
assertThat(registrar.getFailoverClientCertificate()).isEqualTo(SAMPLE_CERT);
@ -382,9 +386,9 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"clientz");
Registrar registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isNotNull();
assertThat(registrar.getIanaIdentifier()).isEqualTo(12345);
Optional<Registrar> registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isPresent();
assertThat(registrar.get().getIanaIdentifier()).isEqualTo(12345);
}
@Test
@ -404,9 +408,9 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"clientz");
Registrar registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isNotNull();
assertThat(registrar.getBillingIdentifier()).isEqualTo(12345);
Optional<Registrar> registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isPresent();
assertThat(registrar.get().getBillingIdentifier()).isEqualTo(12345);
}
@Test
@ -426,9 +430,9 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"clientz");
Registrar registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isNotNull();
assertThat(registrar.getBillingAccountMap())
Optional<Registrar> registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isPresent();
assertThat(registrar.get().getBillingAccountMap())
.containsExactly(CurrencyUnit.USD, "abc123", CurrencyUnit.JPY, "789xyz");
}
@ -473,10 +477,9 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"clientz");
Registrar registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isNotNull();
assertThat(registrar.getBillingAccountMap())
.containsExactly(CurrencyUnit.JPY, "789xyz");
Optional<Registrar> registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isPresent();
assertThat(registrar.get().getBillingAccountMap()).containsExactly(CurrencyUnit.JPY, "789xyz");
}
@Test
@ -497,8 +500,9 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--icann_referral_email=foo@bar.test",
"clientz");
Registrar registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isNotNull();
Optional<Registrar> registrarOptional = Registrar.loadByClientId("clientz");
assertThat(registrarOptional).isPresent();
Registrar registrar = registrarOptional.get();
assertThat(registrar.getLocalizedAddress()).isNotNull();
assertThat(registrar.getLocalizedAddress().getStreet()).hasSize(3);
assertThat(registrar.getLocalizedAddress().getStreet().get(0)).isEqualTo("1234 Main St");
@ -527,9 +531,9 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"clientz");
Registrar registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isNotNull();
assertThat(registrar.getEmailAddress()).isEqualTo("foo@foo.foo");
Optional<Registrar> registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isPresent();
assertThat(registrar.get().getEmailAddress()).isEqualTo("foo@foo.foo");
}
@Test
@ -549,9 +553,9 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"clientz");
Registrar registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isNotNull();
assertThat(registrar.getUrl()).isEqualTo("http://foo.foo");
Optional<Registrar> registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isPresent();
assertThat(registrar.get().getUrl()).isEqualTo("http://foo.foo");
}
@Test
@ -571,9 +575,9 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"clientz");
Registrar registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isNotNull();
assertThat(registrar.getPhoneNumber()).isEqualTo("+1.2125556342");
Optional<Registrar> registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isPresent();
assertThat(registrar.get().getPhoneNumber()).isEqualTo("+1.2125556342");
}
@Test
@ -597,8 +601,9 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"clientz");
Registrar registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isNotNull();
Optional<Registrar> registrarOptional = Registrar.loadByClientId("clientz");
assertThat(registrarOptional).isPresent();
Registrar registrar = registrarOptional.get();
assertThat(registrar.getIanaIdentifier()).isNull();
assertThat(registrar.getBillingIdentifier()).isNull();
assertThat(registrar.getPhoneNumber()).isNull();
@ -630,8 +635,9 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"clientz");
Registrar registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isNotNull();
Optional<Registrar> registrarOptional = Registrar.loadByClientId("clientz");
assertThat(registrarOptional).isPresent();
Registrar registrar = registrarOptional.get();
assertThat(registrar.getIanaIdentifier()).isNull();
assertThat(registrar.getBillingIdentifier()).isNull();
assertThat(registrar.getPhoneNumber()).isNull();
@ -658,9 +664,9 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"clientz");
Registrar registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isNotNull();
assertThat(registrar.getBlockPremiumNames()).isTrue();
Optional<Registrar> registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isPresent();
assertThat(registrar.get().getBlockPremiumNames()).isTrue();
}
@Test
@ -680,9 +686,9 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"clientz");
Registrar registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isNotNull();
assertThat(registrar.getBlockPremiumNames()).isFalse();
Optional<Registrar> registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isPresent();
assertThat(registrar.get().getBlockPremiumNames()).isFalse();
}
@Test
@ -740,9 +746,9 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"clientz");
Registrar registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isNotNull();
assertThat(registrar.getFaxNumber()).isEqualTo("+1.2125556342");
Optional<Registrar> registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isPresent();
assertThat(registrar.get().getFaxNumber()).isEqualTo("+1.2125556342");
}
@Test

View file

@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource;
import static org.joda.money.CurrencyUnit.USD;
@ -47,7 +48,7 @@ public class DeleteCreditCommandTest extends CommandTestCase<DeleteCreditCommand
@Before
public void setUp() {
registrar = Registrar.loadByClientId("TheRegistrar");
registrar = loadRegistrar("TheRegistrar");
createTld("tld");
assertThat(Registry.get("tld").getCurrency()).isEqualTo(USD);
DateTime creditCreationTime = Registry.get("tld").getCreationTime().plusMillis(1);
@ -110,7 +111,7 @@ public class DeleteCreditCommandTest extends CommandTestCase<DeleteCreditCommand
@Test
public void testFailure_nonexistentParentRegistrar() throws Exception {
thrown.expect(NullPointerException.class, "FakeRegistrar");
thrown.expect(IllegalArgumentException.class, "Registrar FakeRegistrar not found");
runCommandForced("--registrar=FakeRegistrar", "--credit_id=" + creditAId);
}

View file

@ -34,7 +34,7 @@ public class GetRegistrarCommandTest extends CommandTestCase<GetRegistrarCommand
@Test
public void testFailure_registrarDoesNotExist() throws Exception {
thrown.expect(IllegalStateException.class);
thrown.expect(IllegalArgumentException.class, "Registrar with id ClientZ does not exist");
runCommand("ClientZ");
}
@ -46,7 +46,7 @@ public class GetRegistrarCommandTest extends CommandTestCase<GetRegistrarCommand
@Test
public void testFailure_oneRegistrarDoesNotExist() throws Exception {
thrown.expect(IllegalStateException.class);
thrown.expect(IllegalArgumentException.class, "Registrar with id ClientZ does not exist");
runCommand("NewRegistrar", "ClientZ");
}
}

View file

@ -19,6 +19,7 @@ import static google.registry.model.registrar.RegistrarContact.Type.ABUSE;
import static google.registry.model.registrar.RegistrarContact.Type.ADMIN;
import static google.registry.model.registrar.RegistrarContact.Type.TECH;
import static google.registry.model.registrar.RegistrarContact.Type.WHOIS;
import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DatastoreHelper.persistSimpleResource;
import static google.registry.testing.DatastoreHelper.persistSimpleResources;
@ -45,7 +46,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
@Test
public void testList() throws Exception {
Registrar registrar = Registrar.loadByClientId("NewRegistrar");
Registrar registrar = loadRegistrar("NewRegistrar");
RegistrarContact.updateContacts(
registrar,
ImmutableSet.of(
@ -70,7 +71,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
@Test
public void testUpdate() throws Exception {
Registrar registrar = Registrar.loadByClientId("NewRegistrar");
Registrar registrar = loadRegistrar("NewRegistrar");
ImmutableList<RegistrarContact> contacts = ImmutableList.of(
new RegistrarContact.Builder()
.setParent(registrar)
@ -93,8 +94,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
"--visible_in_whois_as_tech=false",
"--visible_in_domain_whois_as_abuse=false",
"NewRegistrar");
RegistrarContact registrarContact =
Registrar.loadByClientId("NewRegistrar").getContacts().asList().get(1);
RegistrarContact registrarContact = loadRegistrar("NewRegistrar").getContacts().asList().get(1);
assertThat(registrarContact).isEqualTo(
new RegistrarContact.Builder()
.setParent(registrar)
@ -111,7 +111,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
@Test
public void testUpdate_enableConsoleAccess() throws Exception {
Registrar registrar = Registrar.loadByClientId("NewRegistrar");
Registrar registrar = loadRegistrar("NewRegistrar");
persistSimpleResource(
new RegistrarContact.Builder()
.setParent(registrar)
@ -123,14 +123,13 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
"--email=jane.doe@example.com",
"--allow_console_access=true",
"NewRegistrar");
RegistrarContact registrarContact =
Registrar.loadByClientId("NewRegistrar").getContacts().asList().get(1);
RegistrarContact registrarContact = loadRegistrar("NewRegistrar").getContacts().asList().get(1);
assertThat(registrarContact.getGaeUserId()).matches("-?[0-9]+");
}
@Test
public void testUpdate_disableConsoleAccess() throws Exception {
Registrar registrar = Registrar.loadByClientId("NewRegistrar");
Registrar registrar = loadRegistrar("NewRegistrar");
persistSimpleResource(
new RegistrarContact.Builder()
.setParent(registrar)
@ -143,14 +142,13 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
"--email=judith.doe@example.com",
"--allow_console_access=false",
"NewRegistrar");
RegistrarContact registrarContact =
Registrar.loadByClientId("NewRegistrar").getContacts().asList().get(1);
RegistrarContact registrarContact = loadRegistrar("NewRegistrar").getContacts().asList().get(1);
assertThat(registrarContact.getGaeUserId()).isNull();
}
@Test
public void testUpdate_unsetOtherWhoisAbuseFlags() throws Exception {
Registrar registrar = Registrar.loadByClientId("NewRegistrar");
Registrar registrar = loadRegistrar("NewRegistrar");
persistSimpleResource(
new RegistrarContact.Builder()
.setParent(registrar)
@ -172,7 +170,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
"--visible_in_domain_whois_as_abuse=true",
"NewRegistrar");
ImmutableList<RegistrarContact> registrarContacts =
Registrar.loadByClientId("NewRegistrar").getContacts().asList();
loadRegistrar("NewRegistrar").getContacts().asList();
for (RegistrarContact registrarContact : registrarContacts) {
if (registrarContact.getName().equals("John Doe")) {
assertThat(registrarContact.getVisibleInDomainWhoisAsAbuse()).isTrue();
@ -184,7 +182,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
@Test
public void testUpdate_cannotUnsetOnlyWhoisAbuseContact() throws Exception {
Registrar registrar = Registrar.loadByClientId("NewRegistrar");
Registrar registrar = loadRegistrar("NewRegistrar");
persistSimpleResource(
new RegistrarContact.Builder()
.setParent(registrar)
@ -204,14 +202,13 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
} catch (IllegalArgumentException e) {
assertThat(e).hasMessageThat().contains("Cannot clear visible_in_domain_whois_as_abuse flag");
}
RegistrarContact registrarContact =
Registrar.loadByClientId("NewRegistrar").getContacts().asList().get(1);
RegistrarContact registrarContact = loadRegistrar("NewRegistrar").getContacts().asList().get(1);
assertThat(registrarContact.getVisibleInDomainWhoisAsAbuse()).isTrue();
}
@Test
public void testUpdate_emptyCommandModifiesNothing() throws Exception {
Registrar registrar = Registrar.loadByClientId("NewRegistrar");
Registrar registrar = loadRegistrar("NewRegistrar");
RegistrarContact existingContact = persistSimpleResource(
new RegistrarContact.Builder()
.setParent(registrar)
@ -226,8 +223,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
.setVisibleInDomainWhoisAsAbuse(true)
.build());
runCommandForced("--mode=UPDATE", "--email=john.doe@example.com", "NewRegistrar");
RegistrarContact registrarContact =
Registrar.loadByClientId("NewRegistrar").getContacts().asList().get(1);
RegistrarContact registrarContact = loadRegistrar("NewRegistrar").getContacts().asList().get(1);
assertThat(registrarContact.getEmailAddress()).isEqualTo(existingContact.getEmailAddress());
assertThat(registrarContact.getName()).isEqualTo(existingContact.getName());
assertThat(registrarContact.getGaeUserId()).isEqualTo(existingContact.getGaeUserId());
@ -244,7 +240,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
@Test
public void testUpdate_listOfTypesWorks() throws Exception {
Registrar registrar = Registrar.loadByClientId("NewRegistrar");
Registrar registrar = loadRegistrar("NewRegistrar");
persistSimpleResource(
new RegistrarContact.Builder()
.setParent(registrar)
@ -263,14 +259,13 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
"--email=john.doe@example.com",
"--contact_type=ADMIN,TECH",
"NewRegistrar");
RegistrarContact registrarContact =
Registrar.loadByClientId("NewRegistrar").getContacts().asList().get(1);
RegistrarContact registrarContact = loadRegistrar("NewRegistrar").getContacts().asList().get(1);
assertThat(registrarContact.getTypes()).containsExactly(ADMIN, TECH);
}
@Test
public void testUpdate_clearAllTypes() throws Exception {
Registrar registrar = Registrar.loadByClientId("NewRegistrar");
Registrar registrar = loadRegistrar("NewRegistrar");
persistSimpleResource(
new RegistrarContact.Builder()
.setParent(registrar)
@ -283,14 +278,13 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
"--email=john.doe@example.com",
"--contact_type=",
"NewRegistrar");
RegistrarContact registrarContact =
Registrar.loadByClientId("NewRegistrar").getContacts().asList().get(1);
RegistrarContact registrarContact = loadRegistrar("NewRegistrar").getContacts().asList().get(1);
assertThat(registrarContact.getTypes()).isEmpty();
}
@Test
public void testCreate_withAdminType() throws Exception {
Registrar registrar = Registrar.loadByClientId("NewRegistrar");
Registrar registrar = loadRegistrar("NewRegistrar");
runCommandForced(
"--mode=CREATE",
"--name=Jim Doe",
@ -300,8 +294,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
"--visible_in_whois_as_tech=false",
"--visible_in_domain_whois_as_abuse=true",
"NewRegistrar");
RegistrarContact registrarContact =
Registrar.loadByClientId("NewRegistrar").getContacts().asList().get(1);
RegistrarContact registrarContact = loadRegistrar("NewRegistrar").getContacts().asList().get(1);
assertThat(registrarContact).isEqualTo(
new RegistrarContact.Builder()
.setParent(registrar)
@ -317,18 +310,17 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
@Test
public void testDelete() throws Exception {
assertThat(Registrar.loadByClientId("NewRegistrar").getContacts()).isNotEmpty();
assertThat(loadRegistrar("NewRegistrar").getContacts()).isNotEmpty();
runCommandForced(
"--mode=DELETE",
"--email=janedoe@theregistrar.com",
"NewRegistrar");
assertThat(Registrar.loadByClientId("NewRegistrar").getContacts()).isEmpty();
assertThat(loadRegistrar("NewRegistrar").getContacts()).isEmpty();
}
@Test
public void testDelete_failsOnDomainWhoisAbuseContact() throws Exception {
RegistrarContact registrarContact =
Registrar.loadByClientId("NewRegistrar").getContacts().asList().get(0);
RegistrarContact registrarContact = loadRegistrar("NewRegistrar").getContacts().asList().get(0);
persistSimpleResource(
registrarContact.asBuilder().setVisibleInDomainWhoisAsAbuse(true).build());
try {
@ -341,7 +333,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
} catch (IllegalArgumentException e) {
assertThat(e).hasMessageThat().contains("Cannot delete the domain WHOIS abuse contact");
}
assertThat(Registrar.loadByClientId("NewRegistrar").getContacts()).isNotEmpty();
assertThat(loadRegistrar("NewRegistrar").getContacts()).isNotEmpty();
}
@Test
@ -353,37 +345,26 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
"--allow_console_access=true",
"--contact_type=ADMIN,ABUSE",
"NewRegistrar");
RegistrarContact registrarContact =
Registrar.loadByClientId("NewRegistrar").getContacts().asList().get(1);
RegistrarContact registrarContact = loadRegistrar("NewRegistrar").getContacts().asList().get(1);
assertThat(registrarContact.getGaeUserId()).matches("-?[0-9]+");
}
@Test
public void testCreate_withNoContactTypes() throws Exception {
runCommandForced(
"--mode=CREATE",
"--name=Jim Doe",
"--email=jim.doe@example.com",
"NewRegistrar");
RegistrarContact registrarContact =
Registrar.loadByClientId("NewRegistrar").getContacts().asList().get(1);
"--mode=CREATE", "--name=Jim Doe", "--email=jim.doe@example.com", "NewRegistrar");
RegistrarContact registrarContact = loadRegistrar("NewRegistrar").getContacts().asList().get(1);
assertThat(registrarContact.getTypes()).isEmpty();
}
@Test
public void testCreate_syncingRequiredSetToTrue() throws Exception {
persistResource(
Registrar.loadByClientId("NewRegistrar")
.asBuilder()
.setContactsRequireSyncing(false)
.build());
loadRegistrar("NewRegistrar").asBuilder().setContactsRequireSyncing(false).build());
assertThat(Registrar.loadByClientId("NewRegistrar").getContactsRequireSyncing()).isFalse();
assertThat(loadRegistrar("NewRegistrar").getContactsRequireSyncing()).isFalse();
runCommandForced(
"--mode=CREATE",
"--name=Jim Doe",
"--email=jim.doe@example.com",
"NewRegistrar");
assertThat(Registrar.loadByClientId("NewRegistrar").getContactsRequireSyncing()).isTrue();
"--mode=CREATE", "--name=Jim Doe", "--email=jim.doe@example.com", "NewRegistrar");
assertThat(loadRegistrar("NewRegistrar").getContactsRequireSyncing()).isTrue();
}
}

View file

@ -19,6 +19,7 @@ import static com.google.common.collect.Iterables.transform;
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.loadRegistrar;
import com.google.common.base.Function;
import google.registry.model.ImmutableObject;
@ -70,11 +71,11 @@ public class ResaveEnvironmentEntitiesCommandTest
assertThat(savedEntities)
.containsExactly(
// The Registrars and RegistrarContacts are created by AppEngineRule.
Registrar.loadByClientId("TheRegistrar"),
Registrar.loadByClientId("NewRegistrar"),
loadRegistrar("TheRegistrar"),
loadRegistrar("NewRegistrar"),
Registry.get("tld"),
getOnlyElement(Registrar.loadByClientId("TheRegistrar").getContacts()),
getOnlyElement(Registrar.loadByClientId("NewRegistrar").getContacts()));
getOnlyElement(loadRegistrar("TheRegistrar").getContacts()),
getOnlyElement(loadRegistrar("NewRegistrar").getContacts()));
}
@SafeVarargs

View file

@ -19,6 +19,7 @@ import static google.registry.model.registrar.Registrar.State.ACTIVE;
import static google.registry.testing.CertificateSamples.SAMPLE_CERT;
import static google.registry.testing.CertificateSamples.SAMPLE_CERT_HASH;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.persistPremiumList;
import static google.registry.testing.DatastoreHelper.persistResource;
import static org.joda.time.DateTimeZone.UTC;
@ -94,7 +95,7 @@ public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
String allowedTld,
String password,
ImmutableList<CidrAddressBlock> ipWhitelist) {
Registrar registrar = Registrar.loadByClientId(registrarName);
Registrar registrar = loadRegistrar(registrarName);
assertThat(registrar).isNotNull();
assertThat(registrar.getAllowedTlds()).containsExactlyElementsIn(ImmutableSet.of(allowedTld));
assertThat(registrar.getRegistrarName()).isEqualTo(registrarName);
@ -321,7 +322,7 @@ public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
@Test
public void testFailure_registrarExists() throws Exception {
Registrar registrar = Registrar.loadByClientId("TheRegistrar").asBuilder()
Registrar registrar = loadRegistrar("TheRegistrar").asBuilder()
.setClientId("blobio-1")
.setRegistrarName("blobio-1")
.build();

View file

@ -14,6 +14,7 @@
package google.registry.tools;
import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.newDomainResource;
import static google.registry.testing.DatastoreHelper.persistActiveDomain;
import static google.registry.testing.DatastoreHelper.persistActiveHost;
@ -25,7 +26,6 @@ import com.googlecode.objectify.Key;
import google.registry.model.domain.secdns.DelegationSignerData;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.HostResource;
import google.registry.model.registrar.Registrar;
import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
import org.junit.Before;
import org.junit.Test;
@ -42,9 +42,8 @@ public class UniformRapidSuspensionCommandTest
@Before
public void initResources() {
// Since the command's history client ID must be CharlestonRoad, resave TheRegistrar that way.
persistResource(Registrar.loadByClientId("TheRegistrar").asBuilder()
.setClientId("CharlestonRoad")
.build());
persistResource(
loadRegistrar("TheRegistrar").asBuilder().setClientId("CharlestonRoad").build());
ns1 = persistActiveHost("ns1.example.com");
ns2 = persistActiveHost("ns2.example.com");
urs1 = persistActiveHost("urs1.example.com");

View file

@ -21,6 +21,7 @@ import static google.registry.model.domain.launch.ApplicationStatus.PENDING_ALLO
import static google.registry.model.domain.launch.ApplicationStatus.REJECTED;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.newContactResourceWithRoid;
import static google.registry.testing.DatastoreHelper.newDomainApplication;
import static google.registry.testing.DatastoreHelper.persistResource;
@ -35,7 +36,6 @@ import google.registry.model.eppcommon.StatusValue;
import google.registry.model.eppcommon.Trid;
import google.registry.model.poll.PendingActionNotificationResponse.DomainPendingActionNotificationResponse;
import google.registry.model.poll.PollMessage;
import google.registry.model.registrar.Registrar;
import google.registry.model.reporting.HistoryEntry;
import org.joda.time.DateTime;
import org.junit.Before;
@ -52,9 +52,8 @@ public class UpdateApplicationStatusCommandTest
public void init() {
// Since the command's history client ID defaults to CharlestonRoad, resave TheRegistrar as
// CharlestonRoad so we don't have to pass in --history_client_id everywhere below.
persistResource(Registrar.loadByClientId("TheRegistrar").asBuilder()
.setClientId("CharlestonRoad")
.build());
persistResource(
loadRegistrar("TheRegistrar").asBuilder().setClientId("CharlestonRoad").build());
createTld("xn--q9jyb4c");
domainApplication = persistResource(newDomainApplication(

View file

@ -14,13 +14,12 @@
package google.registry.tools;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.isNullOrEmpty;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.registrar.Registrar.loadByClientId;
import static google.registry.testing.CertificateSamples.SAMPLE_CERT;
import static google.registry.testing.CertificateSamples.SAMPLE_CERT_HASH;
import static google.registry.testing.DatastoreHelper.createTlds;
import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource;
import static org.joda.time.DateTimeZone.UTC;
@ -44,28 +43,28 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
@Test
public void testSuccess_password() throws Exception {
assertThat(loadByClientId("NewRegistrar").testPassword("some_password")).isFalse();
assertThat(loadRegistrar("NewRegistrar").testPassword("some_password")).isFalse();
runCommand("--password=some_password", "--force", "NewRegistrar");
assertThat(loadByClientId("NewRegistrar").testPassword("some_password")).isTrue();
assertThat(loadRegistrar("NewRegistrar").testPassword("some_password")).isTrue();
}
@Test
public void testSuccess_registrarType() throws Exception {
persistResource(
loadByClientId("NewRegistrar")
loadRegistrar("NewRegistrar")
.asBuilder()
.setType(Registrar.Type.OTE)
.setIanaIdentifier(null)
.build());
assertThat(loadByClientId("NewRegistrar").getType()).isEqualTo(Type.OTE);
assertThat(loadRegistrar("NewRegistrar").getType()).isEqualTo(Type.OTE);
runCommand("--registrar_type=TEST", "--force", "NewRegistrar");
assertThat(loadByClientId("NewRegistrar").getType()).isEqualTo(Type.TEST);
assertThat(loadRegistrar("NewRegistrar").getType()).isEqualTo(Type.TEST);
}
@Test
public void testFailure_noPasscodeOnChangeToReal() throws Exception {
persistResource(
loadByClientId("NewRegistrar")
loadRegistrar("NewRegistrar")
.asBuilder()
.setType(Registrar.Type.OTE)
.setIanaIdentifier(null)
@ -77,21 +76,21 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
@Test
public void testSuccess_registrarState() throws Exception {
assertThat(loadByClientId("NewRegistrar").getState()).isEqualTo(State.ACTIVE);
assertThat(loadRegistrar("NewRegistrar").getState()).isEqualTo(State.ACTIVE);
runCommand("--registrar_state=SUSPENDED", "--force", "NewRegistrar");
assertThat(loadByClientId("NewRegistrar").getState()).isEqualTo(State.SUSPENDED);
assertThat(loadRegistrar("NewRegistrar").getState()).isEqualTo(State.SUSPENDED);
}
@Test
public void testSuccess_allowedTlds() throws Exception {
createTlds("xn--q9jyb4c", "foobar");
persistResource(
loadByClientId("NewRegistrar")
loadRegistrar("NewRegistrar")
.asBuilder()
.setAllowedTlds(ImmutableSet.of("xn--q9jyb4c"))
.build());
runCommand("--allowed_tlds=xn--q9jyb4c,foobar", "--force", "NewRegistrar");
assertThat(loadByClientId("NewRegistrar").getAllowedTlds())
assertThat(loadRegistrar("NewRegistrar").getAllowedTlds())
.containsExactly("xn--q9jyb4c", "foobar");
}
@ -99,12 +98,12 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
public void testSuccess_addAllowedTlds() throws Exception {
createTlds("xn--q9jyb4c", "foo", "bar");
persistResource(
loadByClientId("NewRegistrar")
loadRegistrar("NewRegistrar")
.asBuilder()
.setAllowedTlds(ImmutableSet.of("xn--q9jyb4c"))
.build());
runCommand("--add_allowed_tlds=foo,bar", "--force", "NewRegistrar");
assertThat(loadByClientId("NewRegistrar").getAllowedTlds())
assertThat(loadRegistrar("NewRegistrar").getAllowedTlds())
.containsExactly("xn--q9jyb4c", "foo", "bar");
}
@ -112,20 +111,20 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
public void testSuccess_addAllowedTldsWithDupes() throws Exception {
createTlds("xn--q9jyb4c", "foo", "bar");
persistResource(
loadByClientId("NewRegistrar")
loadRegistrar("NewRegistrar")
.asBuilder()
.setAllowedTlds(ImmutableSet.of("xn--q9jyb4c"))
.build());
runCommand("--add_allowed_tlds=xn--q9jyb4c,foo,bar", "--force", "NewRegistrar");
assertThat(loadByClientId("NewRegistrar").getAllowedTlds())
assertThat(loadRegistrar("NewRegistrar").getAllowedTlds())
.isEqualTo(ImmutableSet.of("xn--q9jyb4c", "foo", "bar"));
}
@Test
public void testSuccess_ipWhitelist() throws Exception {
assertThat(loadByClientId("NewRegistrar").getIpAddressWhitelist()).isEmpty();
assertThat(loadRegistrar("NewRegistrar").getIpAddressWhitelist()).isEmpty();
runCommand("--ip_whitelist=192.168.1.1,192.168.0.2/16", "--force", "NewRegistrar");
assertThat(loadByClientId("NewRegistrar").getIpAddressWhitelist())
assertThat(loadRegistrar("NewRegistrar").getIpAddressWhitelist())
.containsExactly(
CidrAddressBlock.create("192.168.1.1"), CidrAddressBlock.create("192.168.0.2/16"))
.inOrder();
@ -134,25 +133,25 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
@Test
public void testSuccess_clearIpWhitelist() throws Exception {
persistResource(
loadByClientId("NewRegistrar")
loadRegistrar("NewRegistrar")
.asBuilder()
.setIpAddressWhitelist(
ImmutableList.of(
CidrAddressBlock.create("192.168.1.1"),
CidrAddressBlock.create("192.168.0.2/16")))
.build());
assertThat(loadByClientId("NewRegistrar").getIpAddressWhitelist()).isNotEmpty();
assertThat(loadRegistrar("NewRegistrar").getIpAddressWhitelist()).isNotEmpty();
runCommand("--ip_whitelist=null", "--force", "NewRegistrar");
assertThat(loadByClientId("NewRegistrar").getIpAddressWhitelist()).isEmpty();
assertThat(loadRegistrar("NewRegistrar").getIpAddressWhitelist()).isEmpty();
}
@Test
public void testSuccess_certFile() throws Exception {
Registrar registrar = checkNotNull(loadByClientId("NewRegistrar"));
Registrar registrar = loadRegistrar("NewRegistrar");
assertThat(registrar.getClientCertificate()).isNull();
assertThat(registrar.getClientCertificateHash()).isNull();
runCommand("--cert_file=" + getCertFilename(), "--force", "NewRegistrar");
registrar = checkNotNull(loadByClientId("NewRegistrar"));
registrar = loadRegistrar("NewRegistrar");
// NB: Hash was computed manually using 'openssl x509 -fingerprint -sha256 -in ...' and then
// converting the result from a hex string to non-padded base64 encoded string.
assertThat(registrar.getClientCertificate()).isEqualTo(SAMPLE_CERT);
@ -161,62 +160,62 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
@Test
public void testSuccess_certHash() throws Exception {
assertThat(loadByClientId("NewRegistrar").getClientCertificateHash()).isNull();
assertThat(loadRegistrar("NewRegistrar").getClientCertificateHash()).isNull();
runCommand("--cert_hash=" + SAMPLE_CERT_HASH, "--force", "NewRegistrar");
assertThat(loadByClientId("NewRegistrar").getClientCertificateHash())
assertThat(loadRegistrar("NewRegistrar").getClientCertificateHash())
.isEqualTo(SAMPLE_CERT_HASH);
}
@Test
public void testSuccess_clearCert() throws Exception {
persistResource(
loadByClientId("NewRegistrar")
loadRegistrar("NewRegistrar")
.asBuilder()
.setClientCertificate(SAMPLE_CERT, DateTime.now(UTC))
.build());
assertThat(isNullOrEmpty(loadByClientId("NewRegistrar").getClientCertificate())).isFalse();
assertThat(isNullOrEmpty(loadRegistrar("NewRegistrar").getClientCertificate())).isFalse();
runCommand("--cert_file=/dev/null", "--force", "NewRegistrar");
assertThat(loadByClientId("NewRegistrar").getClientCertificate()).isNull();
assertThat(loadRegistrar("NewRegistrar").getClientCertificate()).isNull();
}
@Test
public void testSuccess_clearCertHash() throws Exception {
persistResource(
loadByClientId("NewRegistrar")
loadRegistrar("NewRegistrar")
.asBuilder()
.setClientCertificateHash(SAMPLE_CERT_HASH)
.build());
assertThat(isNullOrEmpty(loadByClientId("NewRegistrar").getClientCertificateHash())).isFalse();
assertThat(isNullOrEmpty(loadRegistrar("NewRegistrar").getClientCertificateHash())).isFalse();
runCommand("--cert_hash=null", "--force", "NewRegistrar");
assertThat(loadByClientId("NewRegistrar").getClientCertificateHash()).isNull();
assertThat(loadRegistrar("NewRegistrar").getClientCertificateHash()).isNull();
}
@Test
public void testSuccess_ianaId() throws Exception {
assertThat(loadByClientId("NewRegistrar").getIanaIdentifier()).isEqualTo(8);
assertThat(loadRegistrar("NewRegistrar").getIanaIdentifier()).isEqualTo(8);
runCommand("--iana_id=12345", "--force", "NewRegistrar");
assertThat(loadByClientId("NewRegistrar").getIanaIdentifier()).isEqualTo(12345);
assertThat(loadRegistrar("NewRegistrar").getIanaIdentifier()).isEqualTo(12345);
}
@Test
public void testSuccess_billingId() throws Exception {
assertThat(loadByClientId("NewRegistrar").getBillingIdentifier()).isNull();
assertThat(loadRegistrar("NewRegistrar").getBillingIdentifier()).isNull();
runCommand("--billing_id=12345", "--force", "NewRegistrar");
assertThat(loadByClientId("NewRegistrar").getBillingIdentifier()).isEqualTo(12345);
assertThat(loadRegistrar("NewRegistrar").getBillingIdentifier()).isEqualTo(12345);
}
@Test
public void testSuccess_billingAccountMap() throws Exception {
assertThat(loadByClientId("NewRegistrar").getBillingAccountMap()).isEmpty();
assertThat(loadRegistrar("NewRegistrar").getBillingAccountMap()).isEmpty();
runCommand("--billing_account_map=USD=abc123,JPY=789xyz", "--force", "NewRegistrar");
assertThat(loadByClientId("NewRegistrar").getBillingAccountMap())
assertThat(loadRegistrar("NewRegistrar").getBillingAccountMap())
.containsExactly(CurrencyUnit.USD, "abc123", CurrencyUnit.JPY, "789xyz");
}
@Test
public void testFailure_billingAccountMap_doesNotContainEntryForTldAllowed() throws Exception {
createTlds("foo");
assertThat(loadByClientId("NewRegistrar").getBillingAccountMap()).isEmpty();
assertThat(loadRegistrar("NewRegistrar").getBillingAccountMap()).isEmpty();
thrown.expect(IllegalArgumentException.class, "USD");
runCommand(
"--billing_account_map=JPY=789xyz",
@ -229,13 +228,13 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
@Test
public void testSuccess_billingAccountMap_onlyAppliesToRealRegistrar() throws Exception {
createTlds("foo");
assertThat(loadByClientId("NewRegistrar").getBillingAccountMap()).isEmpty();
assertThat(loadRegistrar("NewRegistrar").getBillingAccountMap()).isEmpty();
runCommand(
"--billing_account_map=JPY=789xyz",
"--allowed_tlds=foo",
"--force",
"NewRegistrar");
assertThat(loadByClientId("NewRegistrar").getBillingAccountMap())
assertThat(loadRegistrar("NewRegistrar").getBillingAccountMap())
.containsExactly(CurrencyUnit.JPY, "789xyz");
}
@ -243,29 +242,29 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
public void testSuccess_billingAccountMap_partialUpdate() throws Exception {
createTlds("foo");
persistResource(
loadByClientId("NewRegistrar")
loadRegistrar("NewRegistrar")
.asBuilder()
.setBillingAccountMap(
ImmutableMap.of(CurrencyUnit.USD, "abc123", CurrencyUnit.JPY, "789xyz"))
.build());
runCommand("--billing_account_map=JPY=123xyz", "--allowed_tlds=foo", "--force", "NewRegistrar");
assertThat(loadByClientId("NewRegistrar").getBillingAccountMap())
assertThat(loadRegistrar("NewRegistrar").getBillingAccountMap())
.containsExactly(CurrencyUnit.JPY, "123xyz", CurrencyUnit.USD, "abc123");
}
@Test
public void testSuccess_changeBillingMethodToBraintreeWhenBalanceIsZero() throws Exception {
createTlds("xn--q9jyb4c");
assertThat(loadByClientId("NewRegistrar").getBillingMethod()).isEqualTo(BillingMethod.EXTERNAL);
assertThat(loadRegistrar("NewRegistrar").getBillingMethod()).isEqualTo(BillingMethod.EXTERNAL);
runCommand("--billing_method=braintree", "--force", "NewRegistrar");
assertThat(loadByClientId("NewRegistrar").getBillingMethod())
assertThat(loadRegistrar("NewRegistrar").getBillingMethod())
.isEqualTo(BillingMethod.BRAINTREE);
}
@Test
public void testFailure_changeBillingMethodWhenBalanceIsNonZero() throws Exception {
createTlds("xn--q9jyb4c");
Registrar registrar = checkNotNull(loadByClientId("NewRegistrar"));
Registrar registrar = loadRegistrar("NewRegistrar");
persistResource(
new RegistrarBillingEntry.Builder()
.setPrevious(null)
@ -286,7 +285,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
runCommand("--street=\"1234 Main St\"", "--street \"4th Floor\"", "--street \"Suite 1\"",
"--city Brooklyn", "--state NY", "--zip 11223", "--cc US", "--force", "NewRegistrar");
Registrar registrar = checkNotNull(loadByClientId("NewRegistrar"));
Registrar registrar = loadRegistrar("NewRegistrar");
assertThat(registrar.getLocalizedAddress() != null).isTrue();
assertThat(registrar.getLocalizedAddress().getStreet()).hasSize(3);
assertThat(registrar.getLocalizedAddress().getStreet().get(0)).isEqualTo("1234 Main St");
@ -300,39 +299,39 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
@Test
public void testSuccess_blockPremiumNames() throws Exception {
assertThat(loadByClientId("NewRegistrar").getBlockPremiumNames()).isFalse();
assertThat(loadRegistrar("NewRegistrar").getBlockPremiumNames()).isFalse();
runCommand("--block_premium=true", "--force", "NewRegistrar");
assertThat(loadByClientId("NewRegistrar").getBlockPremiumNames()).isTrue();
assertThat(loadRegistrar("NewRegistrar").getBlockPremiumNames()).isTrue();
}
@Test
public void testSuccess_resetBlockPremiumNames() throws Exception {
persistResource(loadByClientId("NewRegistrar").asBuilder().setBlockPremiumNames(true).build());
persistResource(loadRegistrar("NewRegistrar").asBuilder().setBlockPremiumNames(true).build());
runCommand("--block_premium=false", "--force", "NewRegistrar");
assertThat(loadByClientId("NewRegistrar").getBlockPremiumNames()).isFalse();
assertThat(loadRegistrar("NewRegistrar").getBlockPremiumNames()).isFalse();
}
@Test
public void testSuccess_blockPremiumNamesUnspecified() throws Exception {
persistResource(loadByClientId("NewRegistrar").asBuilder().setBlockPremiumNames(true).build());
persistResource(loadRegistrar("NewRegistrar").asBuilder().setBlockPremiumNames(true).build());
// Make some unrelated change where we don't specify "--block_premium".
runCommand("--billing_id=12345", "--force", "NewRegistrar");
// Make sure the field didn't get reset back to false.
assertThat(loadByClientId("NewRegistrar").getBlockPremiumNames()).isTrue();
assertThat(loadRegistrar("NewRegistrar").getBlockPremiumNames()).isTrue();
}
@Test
public void testSuccess_updateMultiple() throws Exception {
assertThat(loadByClientId("TheRegistrar").getState()).isEqualTo(State.ACTIVE);
assertThat(loadByClientId("NewRegistrar").getState()).isEqualTo(State.ACTIVE);
assertThat(loadRegistrar("TheRegistrar").getState()).isEqualTo(State.ACTIVE);
assertThat(loadRegistrar("NewRegistrar").getState()).isEqualTo(State.ACTIVE);
runCommand("--registrar_state=SUSPENDED", "--force", "TheRegistrar", "NewRegistrar");
assertThat(loadByClientId("TheRegistrar").getState()).isEqualTo(State.SUSPENDED);
assertThat(loadByClientId("NewRegistrar").getState()).isEqualTo(State.SUSPENDED);
assertThat(loadRegistrar("TheRegistrar").getState()).isEqualTo(State.SUSPENDED);
assertThat(loadRegistrar("NewRegistrar").getState()).isEqualTo(State.SUSPENDED);
}
@Test
public void testSuccess_resetOptionalParamsNullString() throws Exception {
Registrar registrar = checkNotNull(loadByClientId("NewRegistrar"));
Registrar registrar = loadRegistrar("NewRegistrar");
registrar = persistResource(registrar.asBuilder()
.setType(Type.PDT) // for non-null IANA ID
.setIanaIdentifier(9995L)
@ -364,7 +363,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
"--force",
"NewRegistrar");
registrar = checkNotNull(loadByClientId("NewRegistrar"));
registrar = loadRegistrar("NewRegistrar");
assertThat(registrar.getIanaIdentifier()).isNull();
assertThat(registrar.getBillingIdentifier()).isNull();
assertThat(registrar.getPhoneNumber()).isNull();
@ -376,7 +375,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
@Test
public void testSuccess_resetOptionalParamsEmptyString() throws Exception {
Registrar registrar = checkNotNull(loadByClientId("NewRegistrar"));
Registrar registrar = loadRegistrar("NewRegistrar");
registrar = persistResource(registrar.asBuilder()
.setType(Type.PDT) // for non-null IANA ID
.setIanaIdentifier(9995L)
@ -408,7 +407,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
"--force",
"NewRegistrar");
registrar = checkNotNull(loadByClientId("NewRegistrar"));
registrar = loadRegistrar("NewRegistrar");
assertThat(registrar.getIanaIdentifier()).isNull();
assertThat(registrar.getBillingIdentifier()).isNull();
assertThat(registrar.getPhoneNumber()).isNull();
@ -421,16 +420,16 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
@Test
public void testSuccess_setWhoisServer_works() throws Exception {
runCommand("--whois=whois.goth.black", "--force", "NewRegistrar");
assertThat(loadByClientId("NewRegistrar").getWhoisServer()).isEqualTo("whois.goth.black");
assertThat(loadRegistrar("NewRegistrar").getWhoisServer()).isEqualTo("whois.goth.black");
}
@Test
public void testSuccess_triggerGroupSyncing_works() throws Exception {
persistResource(
loadByClientId("NewRegistrar").asBuilder().setContactsRequireSyncing(false).build());
assertThat(loadByClientId("NewRegistrar").getContactsRequireSyncing()).isFalse();
loadRegistrar("NewRegistrar").asBuilder().setContactsRequireSyncing(false).build());
assertThat(loadRegistrar("NewRegistrar").getContactsRequireSyncing()).isFalse();
runCommand("--sync_groups=true", "--force", "NewRegistrar");
assertThat(loadByClientId("NewRegistrar").getContactsRequireSyncing()).isTrue();
assertThat(loadRegistrar("NewRegistrar").getContactsRequireSyncing()).isTrue();
}
@Test
@ -594,7 +593,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
@Test
public void testFailure_doesNotExist() throws Exception {
thrown.expect(NullPointerException.class);
thrown.expect(IllegalArgumentException.class, "Registrar ClientZ not found");
runCommand("--force", "ClientZ");
}

View file

@ -16,6 +16,7 @@ package google.registry.tools;
import static google.registry.model.registrar.Registrar.State.ACTIVE;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource;
import com.beust.jcommander.ParameterException;
@ -23,7 +24,6 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import google.registry.flows.EppException;
import google.registry.flows.TransportCredentials.BadRegistrarPasswordException;
import google.registry.model.registrar.Registrar;
import google.registry.testing.CertificateSamples;
import google.registry.util.CidrAddressBlock;
import org.junit.Before;
@ -40,13 +40,15 @@ public class ValidateLoginCredentialsCommandTest
@Before
public void init() {
createTld("tld");
persistResource(Registrar.loadByClientId("NewRegistrar").asBuilder()
.setPassword(PASSWORD)
.setClientCertificateHash(CERT_HASH)
.setIpAddressWhitelist(ImmutableList.of(new CidrAddressBlock(CLIENT_IP)))
.setState(ACTIVE)
.setAllowedTlds(ImmutableSet.of("tld"))
.build());
persistResource(
loadRegistrar("NewRegistrar")
.asBuilder()
.setPassword(PASSWORD)
.setClientCertificateHash(CERT_HASH)
.setIpAddressWhitelist(ImmutableList.of(new CidrAddressBlock(CLIENT_IP)))
.setState(ACTIVE)
.setAllowedTlds(ImmutableSet.of("tld"))
.build());
}
@Test

View file

@ -14,6 +14,7 @@
package google.registry.tools;
import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource;
import static org.mockito.Matchers.anyMapOf;
import static org.mockito.Matchers.anyString;
@ -21,7 +22,6 @@ import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.google.common.base.VerifyException;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import google.registry.model.registrar.Registrar;
@ -48,7 +48,7 @@ public class VerifyOteCommandTest extends CommandTestCase<VerifyOteCommand> {
@Test
public void testSuccess_pass() throws Exception {
Registrar registrar =
Registrar.loadByClientId("TheRegistrar")
loadRegistrar("TheRegistrar")
.asBuilder()
.setClientId("blobio-1")
.setRegistrarName("blobio-1")
@ -66,7 +66,7 @@ public class VerifyOteCommandTest extends CommandTestCase<VerifyOteCommand> {
@Test
public void testFailure_registrarDoesntExist() throws Exception {
thrown.expect(VerifyException.class, "Registrar blobio does not exist.");
thrown.expect(IllegalArgumentException.class, "Registrar blobio does not exist.");
runCommand("blobio");
}

View file

@ -15,11 +15,11 @@
package google.registry.tools.server;
import static google.registry.testing.DatastoreHelper.createTlds;
import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSet;
import google.registry.model.registrar.Registrar;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -40,12 +40,12 @@ public class ListRegistrarsActionTest extends ListActionTestCase {
// Ensure that NewRegistrar only has access to xn--q9jyb4c and that TheRegistrar only has access
// to example.
persistResource(
Registrar.loadByClientId("NewRegistrar")
loadRegistrar("NewRegistrar")
.asBuilder()
.setAllowedTlds(ImmutableSet.of("xn--q9jyb4c"))
.build());
persistResource(
Registrar.loadByClientId("TheRegistrar")
loadRegistrar("TheRegistrar")
.asBuilder()
.setAllowedTlds(ImmutableSet.of("example"))
.build());