Deprecate more fields in RegistryConfig

This primarily addresses issues with TMCH testing mode and email sending utils.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=143710550
This commit is contained in:
mcilwain 2017-01-05 14:38:38 -08:00 committed by Ben McIlwain
parent c05424b947
commit 25a8bbe890
23 changed files with 203 additions and 265 deletions

View file

@ -14,8 +14,6 @@
package google.registry.config;
import static com.google.common.truth.Truth.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@ -28,14 +26,4 @@ public class RegistryEnvironmentTest {
public void testGet() throws Exception {
RegistryEnvironment.get();
}
@Test
public void testOverride() throws Exception {
RegistryEnvironment.overrideConfigurationForTesting(new TestRegistryConfig() {
@Override
public String getSnapshotsBucket() {
return "black velvet";
}});
assertThat(RegistryEnvironment.get().config().getSnapshotsBucket()).isEqualTo("black velvet");
}
}

View file

@ -19,10 +19,8 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import google.registry.config.TestRegistryConfig;
import google.registry.testing.FakeClock;
import google.registry.testing.InjectRule;
import google.registry.testing.RegistryConfigRule;
import java.io.PrintWriter;
import java.io.StringWriter;
import javax.servlet.ServletConfig;
@ -43,12 +41,6 @@ public class ExportSnapshotServletTest {
@Rule
public final InjectRule inject = new InjectRule();
@Rule
public final RegistryConfigRule configRule = new RegistryConfigRule(new TestRegistryConfig() {
@Override public String getSnapshotsBucket() {
return "Bucket-Id";
}});
@Mock
private HttpServletRequest req;
@ -87,7 +79,7 @@ public class ExportSnapshotServletTest {
verify(backupService).launchNewBackup(
ExportSnapshotServlet.QUEUE,
"auto_snapshot_20140801_010203",
"Bucket-Id",
"domain-registry-snapshots",
ExportConstants.getBackupKinds());
verify(checkSnapshotServlet)
.enqueuePollTask("auto_snapshot_20140801_010203", ExportConstants.getReportingKinds());

View file

@ -117,7 +117,6 @@ import google.registry.model.registry.label.ReservedList;
import google.registry.model.reporting.HistoryEntry;
import google.registry.model.smd.SignedMarkRevocationList;
import google.registry.testing.DatastoreHelper;
import google.registry.testing.RegistryConfigRule;
import google.registry.tmch.TmchCertificateAuthority;
import java.util.Collections;
import java.util.Comparator;
@ -128,7 +127,6 @@ import org.joda.time.DateTime;
import org.joda.time.Interval;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
/** Unit tests for {@link DomainApplicationCreateFlow}. */
@ -137,9 +135,6 @@ public class DomainApplicationCreateFlowTest
private static final String CLAIMS_KEY = "2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001";
@Rule
public final RegistryConfigRule configRule = new RegistryConfigRule();
/** This is the id of the SMD stored in "domain_create_sunrise_encoded_signed_mark.xml". */
public static final String SMD_ID = "0000001761376042759136-65535";

View file

@ -26,7 +26,6 @@ import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.VoidWork;
import com.googlecode.objectify.Work;
import com.googlecode.objectify.annotation.Entity;
import google.registry.config.TestRegistryConfig;
import google.registry.model.common.CrossTldSingleton;
import google.registry.model.ofy.CommitLogManifest;
import google.registry.model.ofy.Ofy;
@ -34,10 +33,8 @@ import google.registry.testing.AppEngineRule;
import google.registry.testing.ExceptionRule;
import google.registry.testing.FakeClock;
import google.registry.testing.InjectRule;
import google.registry.testing.RegistryConfigRule;
import java.util.List;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@ -66,15 +63,6 @@ public class CommitLogRevisionsTranslatorFactoryTest {
@Rule
public final ExceptionRule thrown = new ExceptionRule();
@Rule
public final RegistryConfigRule configRule = new RegistryConfigRule(
new TestRegistryConfig() {
@Override
public Duration getCommitLogDatastoreRetention() {
return Duration.standardDays(30);
}
});
private final FakeClock clock = new FakeClock(START_TIME);
@Before

View file

@ -22,6 +22,7 @@ import google.registry.config.RegistryEnvironment;
import org.junit.rules.ExternalResource;
/** JUnit Rule for overriding Nomulus configuration values. */
@Deprecated // is obsoleted by YAML config; see b/33386530 for details
public final class RegistryConfigRule extends ExternalResource {
private final Optional<RegistryConfig> override;

View file

@ -14,6 +14,8 @@
package google.registry.ui.server.registrar;
import static google.registry.config.ConfigModule.LocalTestConfig.GOOGLE_APPS_ADMIN_EMAIL_DISPLAY_NAME;
import static google.registry.config.ConfigModule.LocalTestConfig.GOOGLE_APPS_SEND_FROM_EMAIL_ADDRESS;
import static google.registry.security.JsonHttpTestUtils.createJsonPayload;
import static google.registry.security.JsonHttpTestUtils.createJsonResponseSupplier;
import static google.registry.security.XsrfTokenManager.generateToken;
@ -100,6 +102,9 @@ public class RegistrarSettingsActionTestCase {
ImmutableMap.<String, Object>of(), new JsonResponse(new ResponseImpl(rsp)));
action.registrarChangesNotificationEmailAddresses = ImmutableList.of(
"notification@test.example", "notification2@test.example");
action.sendEmailUtils =
new SendEmailUtils(
GOOGLE_APPS_SEND_FROM_EMAIL_ADDRESS, GOOGLE_APPS_ADMIN_EMAIL_DISPLAY_NAME);
inject.setStaticField(Ofy.class, "clock", clock);
inject.setStaticField(SendEmailUtils.class, "emailService", emailService);
inject.setStaticField(SyncRegistrarsSheetAction.class, "modulesService", modulesService);

View file

@ -11,6 +11,7 @@ java_library(
name = "util",
srcs = glob(["*.java"]),
deps = [
"//java/google/registry/config",
"//java/google/registry/util",
"//javatests/google/registry/testing",
"@com_google_appengine_api_1_0_sdk",

View file

@ -15,7 +15,6 @@
package google.registry.util;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.util.SendEmailUtils.sendEmail;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.never;
@ -23,6 +22,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableList;
import google.registry.config.ConfigModule.LocalTestConfig;
import google.registry.testing.ExceptionRule;
import google.registry.testing.InjectRule;
import java.util.Properties;
@ -53,20 +53,26 @@ public class SendEmailUtilsTest {
private SendEmailService emailService;
private Message message;
private SendEmailUtils sendEmailUtils;
@Before
public void init() throws Exception {
inject.setStaticField(SendEmailUtils.class, "emailService", emailService);
message = new MimeMessage(Session.getDefaultInstance(new Properties(), null));
when(emailService.createMessage()).thenReturn(message);
sendEmailUtils = new SendEmailUtils(
LocalTestConfig.GOOGLE_APPS_SEND_FROM_EMAIL_ADDRESS,
LocalTestConfig.GOOGLE_APPS_ADMIN_EMAIL_DISPLAY_NAME);
}
@Test
public void testSuccess_sendToOneAddress() throws Exception {
assertThat(sendEmail(
"johnny@fakesite.tld",
"Welcome to the Internet",
"It is a dark and scary place.")).isTrue();
assertThat(
sendEmailUtils.sendEmail(
ImmutableList.of("johnny@fakesite.tld"),
"Welcome to the Internet",
"It is a dark and scary place."))
.isTrue();
verifyMessageSent();
assertThat(message.getRecipients(RecipientType.TO)).asList()
.containsExactly(new InternetAddress("johnny@fakesite.tld"));
@ -76,10 +82,12 @@ public class SendEmailUtilsTest {
@Test
public void testSuccess_sendToMultipleAddresses() throws Exception {
assertThat(sendEmail(
ImmutableList.of("foo@example.com", "bar@example.com"),
"Welcome to the Internet",
"It is a dark and scary place.")).isTrue();
assertThat(
sendEmailUtils.sendEmail(
ImmutableList.of("foo@example.com", "bar@example.com"),
"Welcome to the Internet",
"It is a dark and scary place."))
.isTrue();
verifyMessageSent();
assertThat(message.getAllRecipients()).asList().containsExactly(
new InternetAddress("foo@example.com"),
@ -88,10 +96,12 @@ public class SendEmailUtilsTest {
@Test
public void testSuccess_ignoresMalformedEmailAddress() throws Exception {
assertThat(sendEmail(
ImmutableList.of("foo@example.com", "1iñvalidemail"),
"Welcome to the Internet",
"It is a dark and scary place.")).isTrue();
assertThat(
sendEmailUtils.sendEmail(
ImmutableList.of("foo@example.com", "1iñvalidemail"),
"Welcome to the Internet",
"It is a dark and scary place."))
.isTrue();
verifyMessageSent();
assertThat(message.getAllRecipients()).asList()
.containsExactly(new InternetAddress("foo@example.com"));
@ -99,22 +109,27 @@ public class SendEmailUtilsTest {
@Test
public void testFailure_onlyGivenMalformedAddress() throws Exception {
assertThat(sendEmail(
ImmutableList.of("1iñvalidemail"),
"Welcome to the Internet",
"It is a dark and scary place.")).isFalse();
assertThat(
sendEmailUtils.sendEmail(
ImmutableList.of("1iñvalidemail"),
"Welcome to the Internet",
"It is a dark and scary place."))
.isFalse();
verify(emailService, never()).sendMessage(any(Message.class));
}
@Test
public void testFailure_exceptionThrownDuringSend() throws Exception {
doThrow(new MessagingException()).when(emailService).sendMessage(any(Message.class));
assertThat(sendEmail(
ImmutableList.of("foo@example.com"),
"Welcome to the Internet",
"It is a dark and scary place.")).isFalse();
assertThat(
sendEmailUtils.sendEmail(
ImmutableList.of("foo@example.com"),
"Welcome to the Internet",
"It is a dark and scary place."))
.isFalse();
verifyMessageSent();
assertThat(message.getAllRecipients()).asList()
assertThat(message.getAllRecipients())
.asList()
.containsExactly(new InternetAddress("foo@example.com"));
}