Refactor EppToolVerifier to accept chaining verify commands

We're doing this to allow several new tests:
- xml files (that exist today)
- xml files with substitutions
- xml content (maybe? Currently private. Caching the files seems more readable)
- no data at all

Instead of having only one interface

eppToolVerifier.verifySent("file1.xml", "file2.xml");

we're refactoring to allow:
eppToolVerifier
  .verifySent("file1.xml")
  .verifySentAny() // we don't care about this epps
  .verifySent("file2.xml", substitutions)
  .verifyNoMoreSent();

In this case we're checking that "exactly 3 EPPs were sent, where the 1st one has content from file1.xml, and the 3rd one has the content from file2.xml, after the given substitutions were applied"

This also updates EppToolCommandTestCase to have only one EppToolVerifier, and
always finish by checking verifyNoMoreSent, meaning that in every test - all
sent epps must be accounted for (verified or skiped)

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=177353887
This commit is contained in:
guyben 2017-11-29 13:20:55 -08:00 committed by jianglai
parent 0e3d050dae
commit 68768a561f
20 changed files with 285 additions and 190 deletions

View file

@ -22,25 +22,21 @@ import static google.registry.testing.DatastoreHelper.newDomainResource;
import static google.registry.testing.DatastoreHelper.persistActiveDomain;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.tools.server.ToolsTestData.loadUtf8;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
/** Unit tests for {@link UnlockDomainCommand}. */
public class UnlockDomainCommandTest extends EppToolCommandTestCase<UnlockDomainCommand> {
/** Gets an overridden eppVerifier that has superuser set to true on it. */
@Override
EppToolVerifier eppVerifier() {
return new EppToolVerifier()
.withConnection(connection)
.withClientId("NewRegistrar")
.asSuperuser();
@Before
public void before() {
eppVerifier.expectSuperuser();
}
private static void persistLockedDomain(String domainName) {
@ -57,10 +53,7 @@ public class UnlockDomainCommandTest extends EppToolCommandTestCase<UnlockDomain
public void testSuccess_sendsCorrectEppXml() throws Exception {
persistLockedDomain("example.tld");
runCommandForced("--client=NewRegistrar", "example.tld");
eppVerifier()
.verifySentContents(
ImmutableList.of(
loadUtf8("domain_unlock.xml", ImmutableMap.of("DOMAIN", "example.tld"))));
eppVerifier.verifySent("domain_unlock.xml", ImmutableMap.of("DOMAIN", "example.tld"));
}
@Test
@ -71,24 +64,24 @@ public class UnlockDomainCommandTest extends EppToolCommandTestCase<UnlockDomain
.addStatusValues(ImmutableSet.of(SERVER_DELETE_PROHIBITED, SERVER_UPDATE_PROHIBITED))
.build());
runCommandForced("--client=NewRegistrar", "example.tld");
eppVerifier().verifySent("domain_unlock_partial_statuses.xml");
eppVerifier.verifySent("domain_unlock_partial_statuses.xml");
}
@Test
public void testSuccess_manyDomains() throws Exception {
List<String> params = new ArrayList<>();
List<String> expectedXmls = new ArrayList<>();
params.add("--client=NewRegistrar");
// Create 26 domains -- one more than the number of entity groups allowed in a transaction (in
// case that was going to be the failure point).
List<String> domains = new ArrayList<>();
for (int n = 0; n < 26; n++) {
String domain = String.format("domain%d.tld", n);
persistLockedDomain(domain);
params.add(domain);
expectedXmls.add(loadUtf8("domain_unlock.xml", ImmutableMap.of("DOMAIN", domain)));
domains.add(domain);
}
runCommandForced(
ImmutableList.<String>builder().add("--client=NewRegistrar").addAll(domains).build());
for (String domain : domains) {
eppVerifier.verifySent("domain_unlock.xml", ImmutableMap.of("DOMAIN", domain));
}
runCommandForced(params);
eppVerifier().verifySentContents(expectedXmls);
}
@Test
@ -104,7 +97,6 @@ public class UnlockDomainCommandTest extends EppToolCommandTestCase<UnlockDomain
public void testSuccess_alreadyUnlockedDomain_performsNoAction() throws Exception {
persistActiveDomain("example.tld");
runCommandForced("--client=NewRegistrar", "example.tld");
eppVerifier().verifyNothingSent();
}
@Test