Make RDE report generation correctly handle DISABLED registrars

This is a follow-up to [] We can't set registrars as DISABLED until
this is deployed.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=241767990
This commit is contained in:
mcilwain 2019-04-03 11:13:27 -07:00 committed by jianglai
parent 3ad0d091f5
commit 1346f7ab70
2 changed files with 35 additions and 14 deletions

View file

@ -15,8 +15,11 @@
package google.registry.rde; package google.registry.rde;
import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkState;
import com.google.common.collect.ImmutableMap;
import google.registry.model.registrar.Registrar; import google.registry.model.registrar.Registrar;
import google.registry.model.registrar.Registrar.State;
import google.registry.model.registrar.RegistrarAddress; import google.registry.model.registrar.RegistrarAddress;
import google.registry.xjc.contact.XjcContactE164Type; import google.registry.xjc.contact.XjcContactE164Type;
import google.registry.xjc.rderegistrar.XjcRdeRegistrar; import google.registry.xjc.rderegistrar.XjcRdeRegistrar;
@ -36,6 +39,15 @@ final class RegistrarToXjcConverter {
private static final String UNKNOWN_ZIP = "00000"; private static final String UNKNOWN_ZIP = "00000";
private static final String UNKNOWN_CC = "US"; private static final String UNKNOWN_CC = "US";
/** A conversion map between internal Registrar states and external RDE states. */
private static final ImmutableMap<Registrar.State, XjcRdeRegistrarStatusType>
REGISTRAR_STATUS_CONVERSIONS =
ImmutableMap.of(
State.ACTIVE, XjcRdeRegistrarStatusType.OK,
State.PENDING, XjcRdeRegistrarStatusType.READONLY,
State.SUSPENDED, XjcRdeRegistrarStatusType.READONLY,
State.DISABLED, XjcRdeRegistrarStatusType.TERMINATED);
/** Converts {@link Registrar} to {@link XjcRdeRegistrarElement}. */ /** Converts {@link Registrar} to {@link XjcRdeRegistrarElement}. */
static XjcRdeRegistrarElement convert(Registrar registrar) { static XjcRdeRegistrarElement convert(Registrar registrar) {
return new XjcRdeRegistrarElement(convertRegistrar(registrar)); return new XjcRdeRegistrarElement(convertRegistrar(registrar));
@ -63,17 +75,11 @@ final class RegistrarToXjcConverter {
// o A <status> element that contains the operational status of the // o A <status> element that contains the operational status of the
// registrar. Possible values are: ok, readonly and terminated. // registrar. Possible values are: ok, readonly and terminated.
switch (model.getState()) { checkState(
case ACTIVE: REGISTRAR_STATUS_CONVERSIONS.containsKey(model.getState()),
bean.setStatus(XjcRdeRegistrarStatusType.OK); "Unknown registrar state: %s",
break; model.getState());
case PENDING: bean.setStatus(REGISTRAR_STATUS_CONVERSIONS.get(model.getState()));
case SUSPENDED:
bean.setStatus(XjcRdeRegistrarStatusType.READONLY);
break;
default:
throw new IllegalStateException(String.format("Bad state: %s", model.getState()));
}
// o One or two <postalInfo> elements that contain postal- address // o One or two <postalInfo> elements that contain postal- address
// information. Two elements are provided so that address // information. Two elements are provided so that address

View file

@ -15,6 +15,7 @@
package google.registry.rde; package google.registry.rde;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.rde.RegistrarToXjcConverter.convertRegistrar;
import static google.registry.testing.DatastoreHelper.cloneAndSetAutoTimestamps; import static google.registry.testing.DatastoreHelper.cloneAndSetAutoTimestamps;
import static google.registry.xjc.XjcXmlTransformer.marshalStrict; import static google.registry.xjc.XjcXmlTransformer.marshalStrict;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
@ -22,6 +23,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import google.registry.model.ofy.Ofy; import google.registry.model.ofy.Ofy;
import google.registry.model.registrar.Registrar; import google.registry.model.registrar.Registrar;
import google.registry.model.registrar.Registrar.State;
import google.registry.model.registrar.RegistrarAddress; import google.registry.model.registrar.RegistrarAddress;
import google.registry.testing.AppEngineRule; import google.registry.testing.AppEngineRule;
import google.registry.testing.FakeClock; import google.registry.testing.FakeClock;
@ -95,8 +97,8 @@ public class RegistrarToXjcConverterTest extends ShardableTestCase {
} }
@Test @Test
public void testConvert() { public void test_convertRegistrar() {
XjcRdeRegistrar bean = RegistrarToXjcConverter.convertRegistrar(registrar); XjcRdeRegistrar bean = convertRegistrar(registrar);
assertThat(bean.getId()).isEqualTo("GoblinMarket"); assertThat(bean.getId()).isEqualTo("GoblinMarket");
assertThat(bean.getName()).isEqualTo("Maids heard the goblins cry: Come buy, come buy:"); assertThat(bean.getName()).isEqualTo("Maids heard the goblins cry: Come buy, come buy:");
@ -131,7 +133,6 @@ public class RegistrarToXjcConverterTest extends ShardableTestCase {
assertThat(bean.getUrl()).isEqualTo("http://www.goblinmen.example"); assertThat(bean.getUrl()).isEqualTo("http://www.goblinmen.example");
// This is just hard-coded for now I guess.
assertThat(bean.getStatus()).isEqualTo(XjcRdeRegistrarStatusType.OK); assertThat(bean.getStatus()).isEqualTo(XjcRdeRegistrarStatusType.OK);
assertThat(bean.getCrDate()).isEqualTo(DateTime.parse("2013-01-01T00:00:00Z")); assertThat(bean.getCrDate()).isEqualTo(DateTime.parse("2013-01-01T00:00:00Z"));
@ -141,6 +142,20 @@ public class RegistrarToXjcConverterTest extends ShardableTestCase {
assertThat(bean.getWhoisInfo().getName()).isEqualTo("whois.goblinmen.example"); assertThat(bean.getWhoisInfo().getName()).isEqualTo("whois.goblinmen.example");
} }
@Test
public void test_convertRegistrar_disabledStateMeansTerminated() {
XjcRdeRegistrar bean = convertRegistrar(registrar.asBuilder().setState(State.DISABLED).build());
assertThat(bean.getStatus()).isEqualTo(XjcRdeRegistrarStatusType.TERMINATED);
}
@Test
public void test_convertRegistrar_handlesAllRegistrarStates() {
for (State state : Registrar.State.values()) {
// This will throw an exception if it can't handle the chosen state.
convertRegistrar(registrar.asBuilder().setState(state).build());
}
}
@Test @Test
public void testMarshal() throws Exception { public void testMarshal() throws Exception {
marshalStrict(RegistrarToXjcConverter.convert(registrar), new ByteArrayOutputStream(), UTF_8); marshalStrict(RegistrarToXjcConverter.convert(registrar), new ByteArrayOutputStream(), UTF_8);