mirror of
https://github.com/google/nomulus.git
synced 2025-05-15 17:07:15 +02:00
Add flow-level EPP metric tests
This also adds an assertion helper for EPP metrics. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=154458134
This commit is contained in:
parent
f1129ea2b1
commit
8025c7547b
4 changed files with 167 additions and 32 deletions
|
@ -14,8 +14,12 @@
|
||||||
|
|
||||||
package google.registry.flows;
|
package google.registry.flows;
|
||||||
|
|
||||||
|
import static google.registry.model.eppoutput.Result.Code.SUCCESS;
|
||||||
|
import static google.registry.model.eppoutput.Result.Code.SUCCESS_AND_CLOSE;
|
||||||
|
import static google.registry.model.eppoutput.Result.Code.SUCCESS_WITH_ACTION_PENDING;
|
||||||
import static google.registry.testing.DatastoreHelper.createTld;
|
import static google.registry.testing.DatastoreHelper.createTld;
|
||||||
import static google.registry.testing.DatastoreHelper.createTlds;
|
import static google.registry.testing.DatastoreHelper.createTlds;
|
||||||
|
import static google.registry.testing.EppMetricSubject.assertThat;
|
||||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
@ -36,10 +40,8 @@ import org.junit.runners.JUnit4;
|
||||||
public class EppLifecycleDomainTest extends EppTestCase {
|
public class EppLifecycleDomainTest extends EppTestCase {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
public final AppEngineRule appEngine =
|
||||||
.withDatastore()
|
AppEngineRule.builder().withDatastore().withTaskQueue().build();
|
||||||
.withTaskQueue()
|
|
||||||
.build();
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void initTld() {
|
public void initTld() {
|
||||||
|
@ -60,13 +62,9 @@ public class EppLifecycleDomainTest extends EppTestCase {
|
||||||
"contact_create_response_jd1234.xml",
|
"contact_create_response_jd1234.xml",
|
||||||
startTime.plusMinutes(1));
|
startTime.plusMinutes(1));
|
||||||
assertCommandAndResponse(
|
assertCommandAndResponse(
|
||||||
"host_create.xml",
|
"host_create.xml", "host_create_response.xml", startTime.plusMinutes(2));
|
||||||
"host_create_response.xml",
|
|
||||||
startTime.plusMinutes(2));
|
|
||||||
assertCommandAndResponse(
|
assertCommandAndResponse(
|
||||||
"host_create2.xml",
|
"host_create2.xml", "host_create2_response.xml", startTime.plusMinutes(3));
|
||||||
"host_create2_response.xml",
|
|
||||||
startTime.plusMinutes(3));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates the domain fakesite.example with two nameservers on it. */
|
/** Creates the domain fakesite.example with two nameservers on it. */
|
||||||
|
@ -175,7 +173,7 @@ public class EppLifecycleDomainTest extends EppTestCase {
|
||||||
assertCommandAndResponse(
|
assertCommandAndResponse(
|
||||||
"domain_info.xml",
|
"domain_info.xml",
|
||||||
"domain_info_response_pendingdelete.xml",
|
"domain_info_response_pendingdelete.xml",
|
||||||
DateTime.parse("2000-08-01T00:02:00Z")); // 1 day out.
|
DateTime.parse("2000-08-01T00:02:00Z")); // 1 day out.
|
||||||
|
|
||||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||||
}
|
}
|
||||||
|
@ -195,6 +193,12 @@ public class EppLifecycleDomainTest extends EppTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testDeletionOfDomain_afterRenameOfSubordinateHost_succeeds() throws Exception {
|
public void testDeletionOfDomain_afterRenameOfSubordinateHost_succeeds() throws Exception {
|
||||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||||
|
assertThat(getRecordedEppMetric())
|
||||||
|
.hasClientId("NewRegistrar")
|
||||||
|
.and()
|
||||||
|
.hasCommandName("Login")
|
||||||
|
.and()
|
||||||
|
.hasStatus(SUCCESS);
|
||||||
createFakesite();
|
createFakesite();
|
||||||
createSubordinateHost();
|
createSubordinateHost();
|
||||||
// Update the ns3 host to no longer be on fakesite.example domain.
|
// Update the ns3 host to no longer be on fakesite.example domain.
|
||||||
|
@ -202,17 +206,48 @@ public class EppLifecycleDomainTest extends EppTestCase {
|
||||||
"host_update_fakesite.xml",
|
"host_update_fakesite.xml",
|
||||||
"generic_success_response.xml",
|
"generic_success_response.xml",
|
||||||
DateTime.parse("2002-05-30T01:01:00Z"));
|
DateTime.parse("2002-05-30T01:01:00Z"));
|
||||||
|
// Add assert about EppMetric
|
||||||
|
assertThat(getRecordedEppMetric())
|
||||||
|
.hasClientId("NewRegistrar")
|
||||||
|
.and()
|
||||||
|
.hasCommandName("HostUpdate")
|
||||||
|
.and()
|
||||||
|
.hasEppTarget("ns3.fakesite.example")
|
||||||
|
.and()
|
||||||
|
.hasStatus(SUCCESS);
|
||||||
// Delete the fakesite.example domain (which should succeed since it no longer has subords).
|
// Delete the fakesite.example domain (which should succeed since it no longer has subords).
|
||||||
assertCommandAndResponse(
|
assertCommandAndResponse(
|
||||||
"domain_delete_fakesite.xml",
|
"domain_delete_fakesite.xml",
|
||||||
"generic_success_action_pending_response.xml",
|
"generic_success_action_pending_response.xml",
|
||||||
DateTime.parse("2002-05-30T01:02:00Z"));
|
DateTime.parse("2002-05-30T01:02:00Z"));
|
||||||
|
assertThat(getRecordedEppMetric())
|
||||||
|
.hasClientId("NewRegistrar")
|
||||||
|
.and()
|
||||||
|
.hasCommandName("DomainDelete")
|
||||||
|
.and()
|
||||||
|
.hasEppTarget("fakesite.example")
|
||||||
|
.and()
|
||||||
|
.hasStatus(SUCCESS_WITH_ACTION_PENDING);
|
||||||
// Check info on the renamed host and verify that it's still around and wasn't deleted.
|
// Check info on the renamed host and verify that it's still around and wasn't deleted.
|
||||||
assertCommandAndResponse(
|
assertCommandAndResponse(
|
||||||
"host_info_ns9000_example.xml",
|
"host_info_ns9000_example.xml",
|
||||||
"host_info_response_ns9000_example.xml",
|
"host_info_response_ns9000_example.xml",
|
||||||
DateTime.parse("2002-06-30T01:03:00Z"));
|
DateTime.parse("2002-06-30T01:03:00Z"));
|
||||||
|
assertThat(getRecordedEppMetric())
|
||||||
|
.hasClientId("NewRegistrar")
|
||||||
|
.and()
|
||||||
|
.hasCommandName("HostInfo")
|
||||||
|
.and()
|
||||||
|
.hasEppTarget("ns9000.example.external")
|
||||||
|
.and()
|
||||||
|
.hasStatus(SUCCESS);
|
||||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||||
|
assertThat(getRecordedEppMetric())
|
||||||
|
.hasClientId("NewRegistrar")
|
||||||
|
.and()
|
||||||
|
.hasCommandName("Logout")
|
||||||
|
.and()
|
||||||
|
.hasStatus(SUCCESS_AND_CLOSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -259,10 +294,15 @@ public class EppLifecycleDomainTest extends EppTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testDomainCreation_failsBeforeSunrise() throws Exception {
|
public void testDomainCreation_failsBeforeSunrise() throws Exception {
|
||||||
DateTime sunriseDate = DateTime.parse("2000-05-30T00:00:00Z");
|
DateTime sunriseDate = DateTime.parse("2000-05-30T00:00:00Z");
|
||||||
createTld("example", ImmutableSortedMap.of(
|
createTld(
|
||||||
START_OF_TIME, TldState.PREDELEGATION,
|
"example",
|
||||||
sunriseDate, TldState.SUNRISE,
|
ImmutableSortedMap.of(
|
||||||
sunriseDate.plusMonths(2), TldState.GENERAL_AVAILABILITY));
|
START_OF_TIME,
|
||||||
|
TldState.PREDELEGATION,
|
||||||
|
sunriseDate,
|
||||||
|
TldState.SUNRISE,
|
||||||
|
sunriseDate.plusMonths(2),
|
||||||
|
TldState.GENERAL_AVAILABILITY));
|
||||||
|
|
||||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||||
|
|
||||||
|
@ -284,9 +324,11 @@ public class EppLifecycleDomainTest extends EppTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testDomainCheckFee_succeeds() throws Exception {
|
public void testDomainCheckFee_succeeds() throws Exception {
|
||||||
DateTime gaDate = DateTime.parse("2000-05-30T00:00:00Z");
|
DateTime gaDate = DateTime.parse("2000-05-30T00:00:00Z");
|
||||||
createTld("example", ImmutableSortedMap.of(
|
createTld(
|
||||||
START_OF_TIME, TldState.PREDELEGATION,
|
"example",
|
||||||
gaDate, TldState.GENERAL_AVAILABILITY));
|
ImmutableSortedMap.of(
|
||||||
|
START_OF_TIME, TldState.PREDELEGATION,
|
||||||
|
gaDate, TldState.GENERAL_AVAILABILITY));
|
||||||
|
|
||||||
assertCommandAndResponse("login_valid_fee_extension.xml", "login_response.xml");
|
assertCommandAndResponse("login_valid_fee_extension.xml", "login_response.xml");
|
||||||
|
|
||||||
|
@ -307,10 +349,11 @@ public class EppLifecycleDomainTest extends EppTestCase {
|
||||||
|
|
||||||
// As the winning registrar, request a transfer. Capture the server trid; we'll need it later.
|
// As the winning registrar, request a transfer. Capture the server trid; we'll need it later.
|
||||||
assertCommandAndResponse("login2_valid.xml", "login_response.xml");
|
assertCommandAndResponse("login2_valid.xml", "login_response.xml");
|
||||||
String response = assertCommandAndResponse(
|
String response =
|
||||||
"domain_transfer_request_1_year.xml",
|
assertCommandAndResponse(
|
||||||
"domain_transfer_response_1_year.xml",
|
"domain_transfer_request_1_year.xml",
|
||||||
DateTime.parse("2001-01-01T00:00:00Z"));
|
"domain_transfer_response_1_year.xml",
|
||||||
|
DateTime.parse("2001-01-01T00:00:00Z"));
|
||||||
Matcher matcher = Pattern.compile("<svTRID>(.*)</svTRID>").matcher(response);
|
Matcher matcher = Pattern.compile("<svTRID>(.*)</svTRID>").matcher(response);
|
||||||
matcher.find();
|
matcher.find();
|
||||||
String transferRequestTrid = matcher.group(1);
|
String transferRequestTrid = matcher.group(1);
|
||||||
|
@ -327,7 +370,7 @@ public class EppLifecycleDomainTest extends EppTestCase {
|
||||||
ImmutableMap.of("ID", "1-C-EXAMPLE-17-23"),
|
ImmutableMap.of("ID", "1-C-EXAMPLE-17-23"),
|
||||||
"poll_ack_response_empty.xml",
|
"poll_ack_response_empty.xml",
|
||||||
null,
|
null,
|
||||||
DateTime.parse("2001-01-01T00:01:00Z"));
|
DateTime.parse("2001-01-01T00:01:00Z"));
|
||||||
|
|
||||||
// Five days in the future, expect a server approval poll message to the loser, and ack it.
|
// Five days in the future, expect a server approval poll message to the loser, and ack it.
|
||||||
assertCommandAndResponse(
|
assertCommandAndResponse(
|
||||||
|
@ -376,8 +419,7 @@ public class EppLifecycleDomainTest extends EppTestCase {
|
||||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||||
|
|
||||||
// Log back in as the first registrar and verify things.
|
// Log back in as the first registrar and verify things.
|
||||||
assertCommandAndResponse(
|
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||||
"login_valid.xml", "login_response.xml");
|
|
||||||
assertCommandAndResponse(
|
assertCommandAndResponse(
|
||||||
"domain_info_fakesite.xml",
|
"domain_info_fakesite.xml",
|
||||||
"domain_info_response_fakesite_pending_transfer.xml",
|
"domain_info_response_fakesite_pending_transfer.xml",
|
||||||
|
@ -421,7 +463,8 @@ public class EppLifecycleDomainTest extends EppTestCase {
|
||||||
|
|
||||||
// Log back in as the first registrar and verify domain is pending transfer.
|
// Log back in as the first registrar and verify domain is pending transfer.
|
||||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||||
assertCommandAndResponse("domain_info_fakesite.xml",
|
assertCommandAndResponse(
|
||||||
|
"domain_info_fakesite.xml",
|
||||||
"domain_info_response_fakesite_3_nameservers_pending_transfer.xml",
|
"domain_info_response_fakesite_3_nameservers_pending_transfer.xml",
|
||||||
DateTime.parse("2002-05-30T01:00:00Z"));
|
DateTime.parse("2002-05-30T01:00:00Z"));
|
||||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||||
|
@ -502,7 +545,8 @@ public class EppLifecycleDomainTest extends EppTestCase {
|
||||||
assertCommandAndResponse("login2_valid.xml", "login_response.xml");
|
assertCommandAndResponse("login2_valid.xml", "login_response.xml");
|
||||||
assertCommandAndResponse(
|
assertCommandAndResponse(
|
||||||
"domain_transfer_request_1_year.xml",
|
"domain_transfer_request_1_year.xml",
|
||||||
"domain_transfer_response_1_year.xml", DateTime.parse("2001-01-01T00:00:00Z"));
|
"domain_transfer_response_1_year.xml",
|
||||||
|
DateTime.parse("2001-01-01T00:00:00Z"));
|
||||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||||
|
|
||||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||||
|
@ -587,7 +631,7 @@ public class EppLifecycleDomainTest extends EppTestCase {
|
||||||
assertCommandAndResponse(
|
assertCommandAndResponse(
|
||||||
"domain_transfer_query_fakesite.xml",
|
"domain_transfer_query_fakesite.xml",
|
||||||
"domain_transfer_query_response_no_transfer_history.xml",
|
"domain_transfer_query_response_no_transfer_history.xml",
|
||||||
DateTime.parse("2000-09-02T00:00:00Z"));
|
DateTime.parse("2000-09-02T00:00:00Z"));
|
||||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||||
// Request a transfer of the domain to the second registrar.
|
// Request a transfer of the domain to the second registrar.
|
||||||
assertCommandAndResponse("login2_valid.xml", "login_response.xml");
|
assertCommandAndResponse("login2_valid.xml", "login_response.xml");
|
||||||
|
|
|
@ -14,7 +14,9 @@
|
||||||
|
|
||||||
package google.registry.flows;
|
package google.registry.flows;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static google.registry.model.eppoutput.Result.Code.SUCCESS;
|
||||||
|
import static google.registry.model.eppoutput.Result.Code.SUCCESS_AND_CLOSE;
|
||||||
|
import static google.registry.testing.EppMetricSubject.assertThat;
|
||||||
|
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
|
@ -31,10 +33,20 @@ public class EppLifecycleLoginTest extends EppTestCase {
|
||||||
AppEngineRule.builder().withDatastore().withTaskQueue().build();
|
AppEngineRule.builder().withDatastore().withTaskQueue().build();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoginAndLogout_recordClientIdInEppMetric() throws Exception {
|
public void testLoginAndLogout_recordsEppMetric() throws Exception {
|
||||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||||
assertThat(getRecordedEppMetric().getClientId()).hasValue("NewRegistrar");
|
assertThat(getRecordedEppMetric())
|
||||||
|
.hasClientId("NewRegistrar")
|
||||||
|
.and()
|
||||||
|
.hasCommandName("Login")
|
||||||
|
.and()
|
||||||
|
.hasStatus(SUCCESS);
|
||||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||||
assertThat(getRecordedEppMetric().getClientId()).hasValue("NewRegistrar");
|
assertThat(getRecordedEppMetric())
|
||||||
|
.hasClientId("NewRegistrar")
|
||||||
|
.and()
|
||||||
|
.hasCommandName("Logout")
|
||||||
|
.and()
|
||||||
|
.hasStatus(SUCCESS_AND_CLOSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ java_library(
|
||||||
"//java/google/registry/flows",
|
"//java/google/registry/flows",
|
||||||
"//java/google/registry/keyring/api",
|
"//java/google/registry/keyring/api",
|
||||||
"//java/google/registry/model",
|
"//java/google/registry/model",
|
||||||
|
"//java/google/registry/monitoring/whitebox",
|
||||||
"//java/google/registry/pricing",
|
"//java/google/registry/pricing",
|
||||||
"//java/google/registry/request",
|
"//java/google/registry/request",
|
||||||
"//java/google/registry/tmch",
|
"//java/google/registry/tmch",
|
||||||
|
|
78
javatests/google/registry/testing/EppMetricSubject.java
Normal file
78
javatests/google/registry/testing/EppMetricSubject.java
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package google.registry.testing;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertAbout;
|
||||||
|
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
||||||
|
|
||||||
|
import com.google.common.base.Optional;
|
||||||
|
import com.google.common.truth.FailureStrategy;
|
||||||
|
import com.google.common.truth.Subject;
|
||||||
|
import com.google.common.truth.SubjectFactory;
|
||||||
|
import google.registry.model.eppoutput.Result.Code;
|
||||||
|
import google.registry.monitoring.whitebox.EppMetric;
|
||||||
|
import google.registry.testing.TruthChainer.And;
|
||||||
|
import java.util.Objects;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/** Utility methods for asserting things about {@link EppMetric} instances. */
|
||||||
|
public class EppMetricSubject extends Subject<EppMetricSubject, EppMetric> {
|
||||||
|
|
||||||
|
public EppMetricSubject(FailureStrategy strategy, EppMetric subject) {
|
||||||
|
super(strategy, subject);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EppMetricSubject assertThat(EppMetric subject) {
|
||||||
|
return assertAbout(SUBJECT_FACTORY).that(subject);
|
||||||
|
}
|
||||||
|
|
||||||
|
public And<EppMetricSubject> hasClientId(String clientId) {
|
||||||
|
return hasValue(clientId, actual().getClientId(), "has clientId");
|
||||||
|
}
|
||||||
|
|
||||||
|
public And<EppMetricSubject> hasCommandName(String commandName) {
|
||||||
|
return hasValue(commandName, actual().getCommandName(), "has commandName");
|
||||||
|
}
|
||||||
|
|
||||||
|
public And<EppMetricSubject> hasEppTarget(String eppTarget) {
|
||||||
|
return hasValue(eppTarget, actual().getEppTarget(), "has eppTarget");
|
||||||
|
}
|
||||||
|
|
||||||
|
public And<EppMetricSubject> hasStatus(Code status) {
|
||||||
|
return hasValue(status, actual().getStatus(), "has status");
|
||||||
|
}
|
||||||
|
|
||||||
|
private <E> And<EppMetricSubject> hasValue(E expected, Optional<E> actual, String verb) {
|
||||||
|
checkArgumentNotNull(expected, "Expected value cannot be null");
|
||||||
|
if (actual == null) {
|
||||||
|
fail("is non-null", expected);
|
||||||
|
} else if (!actual.isPresent()) {
|
||||||
|
fail("has value", expected);
|
||||||
|
} else if (!Objects.equals(expected, actual.get())) {
|
||||||
|
failWithBadResults(verb, expected, verb, actual);
|
||||||
|
}
|
||||||
|
return new And<>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** {@link SubjectFactory} for assertions about {@link EppMetric} objects. */
|
||||||
|
private static final SubjectFactory<EppMetricSubject, EppMetric> SUBJECT_FACTORY =
|
||||||
|
new SubjectFactory<EppMetricSubject, EppMetric>() {
|
||||||
|
@Override
|
||||||
|
public EppMetricSubject getSubject(
|
||||||
|
FailureStrategy failureStrategy, @Nullable EppMetric target) {
|
||||||
|
return new EppMetricSubject(failureStrategy, target);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue