mirror of
https://github.com/google/nomulus.git
synced 2025-08-05 17:28:25 +02:00
Wrap ModulesService in new AppEngineServiceUtils
ModulesService does not provide a great API. Specifically, it doesn't have a way to get the hostname for a specific service; you have to get the hostname for a specific version as well. This is very rarely what we want, as we publish new versions every week and don't expect old ones to hang around for very long, so a task should execute against whatever the live version is, not whatever the current version was back when the task was enqueued (especially because that version might be deleted by now). This new and improved wrapper API removes the confusion and plays better with dependency injection to boot. We can also fold in other methods having to do with App Engine services, whereas ModulesService was quite limited in scope. This also has the side effect of fixing ResaveEntityAction, which is currently broken because the tasks it's enqueuing to execute up to 30 days in the future have the version hard-coded into the hostname, and we typically delete old versions sooner than that. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=206173763
This commit is contained in:
parent
c87fde605c
commit
6e74ba0587
27 changed files with 422 additions and 286 deletions
|
@ -17,17 +17,12 @@ package google.registry.ui.server.registrar;
|
|||
import static google.registry.config.RegistryConfig.getGSuiteOutgoingEmailAddress;
|
||||
import static google.registry.config.RegistryConfig.getGSuiteOutgoingEmailDisplayName;
|
||||
import static google.registry.security.JsonHttpTestUtils.createJsonPayload;
|
||||
import static google.registry.security.JsonHttpTestUtils.createJsonResponseSupplier;
|
||||
import static google.registry.testing.DatastoreHelper.loadRegistrar;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.google.appengine.api.modules.ModulesService;
|
||||
import com.google.appengine.api.users.User;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.export.sheet.SyncRegistrarsSheetAction;
|
||||
import google.registry.model.ofy.Ofy;
|
||||
import google.registry.request.JsonActionRunner;
|
||||
import google.registry.request.JsonResponse;
|
||||
|
@ -38,10 +33,11 @@ import google.registry.request.auth.UserAuthInfo;
|
|||
import google.registry.testing.AppEngineRule;
|
||||
import google.registry.testing.FakeClock;
|
||||
import google.registry.testing.InjectRule;
|
||||
import google.registry.testing.MockitoJUnitRule;
|
||||
import google.registry.util.AppEngineServiceUtils;
|
||||
import google.registry.util.SendEmailService;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.Session;
|
||||
|
@ -53,6 +49,7 @@ import org.junit.Before;
|
|||
import org.junit.Rule;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.mockito.Mock;
|
||||
|
||||
/** Base class for tests using {@link RegistrarSettingsAction}. */
|
||||
@RunWith(JUnit4.class)
|
||||
|
@ -61,32 +58,31 @@ public class RegistrarSettingsActionTestCase {
|
|||
static final String CLIENT_ID = "TheRegistrar";
|
||||
|
||||
@Rule
|
||||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
||||
.withDatastore()
|
||||
.withTaskQueue()
|
||||
.build();
|
||||
public final AppEngineRule appEngine =
|
||||
AppEngineRule.builder().withDatastore().withTaskQueue().build();
|
||||
|
||||
@Rule
|
||||
public final InjectRule inject = new InjectRule();
|
||||
@Rule public final InjectRule inject = new InjectRule();
|
||||
@Rule public final MockitoJUnitRule mocks = MockitoJUnitRule.create();
|
||||
|
||||
final HttpServletRequest req = mock(HttpServletRequest.class);
|
||||
final HttpServletResponse rsp = mock(HttpServletResponse.class);
|
||||
final SendEmailService emailService = mock(SendEmailService.class);
|
||||
final ModulesService modulesService = mock(ModulesService.class);
|
||||
final SessionUtils sessionUtils = mock(SessionUtils.class);
|
||||
@Mock AppEngineServiceUtils appEngineServiceUtils;
|
||||
@Mock HttpServletRequest req;
|
||||
@Mock HttpServletResponse rsp;
|
||||
@Mock SendEmailService emailService;
|
||||
@Mock SessionUtils sessionUtils;
|
||||
final User user = new User("user", "gmail.com");
|
||||
|
||||
Message message;
|
||||
|
||||
final RegistrarSettingsAction action = new RegistrarSettingsAction();
|
||||
final StringWriter writer = new StringWriter();
|
||||
final Supplier<Map<String, Object>> json = createJsonResponseSupplier(writer);
|
||||
final FakeClock clock = new FakeClock(DateTime.parse("2014-01-01T00:00:00Z"));
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
action.request = req;
|
||||
action.sessionUtils = sessionUtils;
|
||||
action.appEngineServiceUtils = appEngineServiceUtils;
|
||||
when(appEngineServiceUtils.getCurrentVersionHostname("backend")).thenReturn("backend.hostname");
|
||||
action.authResult = AuthResult.create(AuthLevel.USER, UserAuthInfo.create(user, false));
|
||||
action.jsonActionRunner = new JsonActionRunner(
|
||||
ImmutableMap.of(), new JsonResponse(new ResponseImpl(rsp)));
|
||||
|
@ -96,7 +92,6 @@ public class RegistrarSettingsActionTestCase {
|
|||
new SendEmailUtils(getGSuiteOutgoingEmailAddress(), getGSuiteOutgoingEmailDisplayName());
|
||||
inject.setStaticField(Ofy.class, "clock", clock);
|
||||
inject.setStaticField(SendEmailUtils.class, "emailService", emailService);
|
||||
inject.setStaticField(SyncRegistrarsSheetAction.class, "modulesService", modulesService);
|
||||
message = new MimeMessage(Session.getDefaultInstance(new Properties(), null));
|
||||
when(emailService.createMessage()).thenReturn(message);
|
||||
when(req.getMethod()).thenReturn("POST");
|
||||
|
@ -109,6 +104,5 @@ public class RegistrarSettingsActionTestCase {
|
|||
// would still return the old value)
|
||||
when(sessionUtils.getRegistrarForAuthResult(req, action.authResult))
|
||||
.thenAnswer(x -> loadRegistrar(CLIENT_ID));
|
||||
when(modulesService.getVersionHostname("backend", null)).thenReturn("backend.hostname");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue