Refactor AppEngineConnection

AppEngineConnection can now connect to all services and not just the tools.

The default is still the tools.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=218734983
This commit is contained in:
guyben 2018-10-25 12:57:16 -07:00 committed by jianglai
parent 97aa98eb35
commit b48061b792
31 changed files with 269 additions and 329 deletions

View file

@ -28,7 +28,6 @@ import com.beust.jcommander.ParameterException;
import com.google.common.base.VerifyException;
import com.google.common.collect.ImmutableMap;
import com.google.common.net.MediaType;
import google.registry.tools.CommandWithConnection.Connection;
import google.registry.tools.server.CreatePremiumListAction;
import org.junit.Before;
import org.junit.Test;
@ -38,8 +37,7 @@ import org.mockito.Mock;
public class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
extends CreateOrUpdatePremiumListCommandTestCase<C> {
@Mock
Connection connection;
@Mock AppEngineConnection connection;
String premiumTermsPath;
String premiumTermsCsv;
@ -53,12 +51,12 @@ public class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
"example_premium_terms.csv",
loadFile(CreatePremiumListCommandTest.class, "example_premium_terms.csv"));
servletPath = "/_dr/admin/createPremiumList";
when(connection.send(
eq(CreatePremiumListAction.PATH),
anyMapOf(String.class, String.class),
any(MediaType.class),
any(byte[].class)))
.thenReturn(JSON_SAFETY_PREFIX + "{\"status\":\"success\",\"lines\":[]}");
when(connection.sendPostRequest(
eq(CreatePremiumListAction.PATH),
anyMapOf(String.class, String.class),
any(MediaType.class),
any(byte[].class)))
.thenReturn(JSON_SAFETY_PREFIX + "{\"status\":\"success\",\"lines\":[]}");
}
@Test
@ -86,13 +84,12 @@ public class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
public void testRun_errorResponse() throws Exception {
reset(connection);
command.setConnection(connection);
when(connection.send(
eq(CreatePremiumListAction.PATH),
anyMapOf(String.class, String.class),
any(MediaType.class),
any(byte[].class)))
.thenReturn(
JSON_SAFETY_PREFIX + "{\"status\":\"error\",\"error\":\"foo already exists\"}");
when(connection.sendPostRequest(
eq(CreatePremiumListAction.PATH),
anyMapOf(String.class, String.class),
any(MediaType.class),
any(byte[].class)))
.thenReturn(JSON_SAFETY_PREFIX + "{\"status\":\"error\",\"error\":\"foo already exists\"}");
VerifyException thrown =
assertThrows(
VerifyException.class, () -> runCommandForced("-i=" + premiumTermsPath, "-n=foo"));