Decouple dryRun from SessionMetadata

dryRun is only available via the (sessionless!) tool, and is not
a property of the session.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=125203026
This commit is contained in:
cgoldfeder 2016-06-17 14:31:22 -07:00 committed by Ben McIlwain
parent 3ae646d687
commit e359ab5f52
17 changed files with 31 additions and 54 deletions

View file

@ -55,12 +55,11 @@ public class EppConsoleActionTest extends ShardableTestCase {
ArgumentCaptor.forClass(TransportCredentials.class);
ArgumentCaptor<SessionMetadata> metadataCaptor = ArgumentCaptor.forClass(SessionMetadata.class);
verify(action.eppRequestHandler).executeEpp(
metadataCaptor.capture(), credentialsCaptor.capture(), eq(INPUT_XML_BYTES));
metadataCaptor.capture(), credentialsCaptor.capture(), eq(false), eq(INPUT_XML_BYTES));
assertThat(((GaeUserCredentials) credentialsCaptor.getValue()).gaeUser.getEmail())
.isEqualTo("person@example.com");
SessionMetadata sessionMetadata = metadataCaptor.getValue();
assertThat(sessionMetadata.getClientId()).isEqualTo("ClientIdentifier");
assertThat(sessionMetadata.isDryRun()).isFalse(); // Should always be false for console.
assertThat(sessionMetadata.isSuperuser()).isEqualTo(superuser);
}

View file

@ -118,7 +118,7 @@ public class EppTestCase extends ShardableTestCase {
handler.eppController = new EppController();
handler.eppController.clock = clock;
handler.eppController.metrics = mock(EppMetrics.class);
handler.executeEpp(sessionMetadata, credentials, inputXml.getBytes(UTF_8));
handler.executeEpp(sessionMetadata, credentials, false, inputXml.getBytes(UTF_8));
assertThat(response.getStatus()).isEqualTo(SC_OK);
assertThat(response.getContentType()).isEqualTo(APPLICATION_EPP_XML_UTF8);
String result = response.getPayload();

View file

@ -49,10 +49,9 @@ public class EppTlsActionTest extends ShardableTestCase {
action.run();
ArgumentCaptor<SessionMetadata> captor = ArgumentCaptor.forClass(SessionMetadata.class);
verify(action.eppRequestHandler)
.executeEpp(captor.capture(), same(action.tlsCredentials), eq(INPUT_XML_BYTES));
.executeEpp(captor.capture(), same(action.tlsCredentials), eq(false), eq(INPUT_XML_BYTES));
SessionMetadata sessionMetadata = captor.getValue();
assertThat(sessionMetadata.getClientId()).isEqualTo("ClientIdentifier");
assertThat(sessionMetadata.isDryRun()).isFalse(); // Should always be false for TLS.
assertThat(sessionMetadata.isSuperuser()).isEqualTo(superuser);
}

View file

@ -42,10 +42,10 @@ public class EppToolActionTest {
verify(action.eppRequestHandler).executeEpp(
captor.capture(),
isA(PasswordOnlyTransportCredentials.class),
eq(dryRun),
eq(action.xml.getBytes(UTF_8)));
SessionMetadata sessionMetadata = captor.getValue();
assertThat(sessionMetadata.getClientId()).isEqualTo("ClientIdentifier");
assertThat(sessionMetadata.isDryRun()).isEqualTo(dryRun);
assertThat(sessionMetadata.isSuperuser()).isEqualTo(superuser);
}

View file

@ -87,8 +87,6 @@ public abstract class FlowTestCase<F extends Flow> {
@Rule
public final InjectRule inject = new InjectRule();
private FlowRunner flowRunner;
protected EppLoader eppLoader;
protected Class<? extends Flow> flowClass;
protected TestSessionMetadata sessionMetadata;
@ -97,7 +95,6 @@ public abstract class FlowTestCase<F extends Flow> {
@Before
public void init() throws Exception {
flowRunner = null;
sessionMetadata = new TestSessionMetadata();
sessionMetadata.setClientId("TheRegistrar");
sessionMetadata.setServiceExtensionUris(ProtocolDefinition.getVisibleServiceExtensionUris());
@ -123,16 +120,8 @@ public abstract class FlowTestCase<F extends Flow> {
return readResourceUtf8(getClass(), "testdata/" + filename);
}
/** Lazily load the flow, since it may fail to initialize if the environment isn't set up yet. */
public FlowRunner getFlowRunner() throws Exception {
if (flowRunner == null) {
flowRunner = createFlowRunner();
}
return flowRunner;
}
/** Load a flow from an epp object. */
private FlowRunner createFlowRunner() throws Exception {
private FlowRunner getFlowRunner(CommitMode commitMode) throws Exception {
EppInput eppInput = eppLoader.getEpp();
flowClass = firstNonNull(flowClass, FlowPicker.getFlowClass(eppInput));
Class<?> expectedFlowClass = new TypeInstantiator<F>(getClass()){}.getExactType();
@ -143,6 +132,7 @@ public abstract class FlowTestCase<F extends Flow> {
getTrid(),
sessionMetadata,
credentials,
commitMode.equals(CommitMode.DRY_RUN),
"<xml></xml>".getBytes(),
null,
clock);
@ -163,7 +153,7 @@ public abstract class FlowTestCase<F extends Flow> {
}
public void assertTransactionalFlow(boolean isTransactional) throws Exception {
assertThat(getFlowRunner().isTransactional()).isEqualTo(isTransactional);
assertThat(getFlowRunner(CommitMode.LIVE).isTransactional()).isEqualTo(isTransactional);
}
public void assertNoHistory() throws Exception {
@ -282,8 +272,7 @@ public abstract class FlowTestCase<F extends Flow> {
/** Run a flow, and attempt to marshal the result to EPP or throw if it doesn't validate. */
public EppOutput runFlow(CommitMode commitMode, UserPrivileges userPrivileges) throws Exception {
sessionMetadata.setSuperuser(userPrivileges.equals(UserPrivileges.SUPERUSER));
sessionMetadata.setIsDryRun(commitMode.equals(CommitMode.DRY_RUN));
EppOutput output = getFlowRunner().run();
EppOutput output = getFlowRunner(commitMode).run();
marshal(output, ValidationMode.STRICT);
return output;
}
@ -296,8 +285,7 @@ public abstract class FlowTestCase<F extends Flow> {
CommitMode commitMode, UserPrivileges userPrivileges, String xml, String... ignoredPaths)
throws Exception {
sessionMetadata.setSuperuser(userPrivileges.equals(UserPrivileges.SUPERUSER));
sessionMetadata.setIsDryRun(commitMode.equals(CommitMode.DRY_RUN));
EppOutput eppOutput = getFlowRunner().run();
EppOutput eppOutput = getFlowRunner(commitMode).run();
if (eppOutput.isResponse()) {
assertThat(eppOutput.isSuccess()).isTrue();
}

View file

@ -86,6 +86,7 @@ public class EppResourceUtilsTest {
Trid.create(null, "server-trid"),
sessionMetadata,
new PasswordOnlyTransportCredentials(),
false,
"<xml></xml>".getBytes(),
null,
clock)

View file

@ -25,7 +25,6 @@ public class TestSessionMetadata extends SessionMetadata {
private final Map<String, Object> properties = new HashMap<>();
private boolean isValid = true;
private boolean isDryRun = false;
private SessionSource sessionSource = SessionSource.NONE;
@Override
@ -58,15 +57,6 @@ public class TestSessionMetadata extends SessionMetadata {
sessionSource = source;
}
public void setIsDryRun(boolean isDryRun) {
this.isDryRun = isDryRun;
}
@Override
public boolean isDryRun() {
return isDryRun;
}
public boolean isValid() {
return isValid;
}