mirror of
https://github.com/google/nomulus.git
synced 2025-05-06 15:07:55 +02:00
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:
parent
3ad0d091f5
commit
1346f7ab70
2 changed files with 35 additions and 14 deletions
|
@ -15,8 +15,11 @@
|
|||
package google.registry.rde;
|
||||
|
||||
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.State;
|
||||
import google.registry.model.registrar.RegistrarAddress;
|
||||
import google.registry.xjc.contact.XjcContactE164Type;
|
||||
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_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}. */
|
||||
static XjcRdeRegistrarElement convert(Registrar registrar) {
|
||||
return new XjcRdeRegistrarElement(convertRegistrar(registrar));
|
||||
|
@ -63,17 +75,11 @@ final class RegistrarToXjcConverter {
|
|||
|
||||
// o A <status> element that contains the operational status of the
|
||||
// registrar. Possible values are: ok, readonly and terminated.
|
||||
switch (model.getState()) {
|
||||
case ACTIVE:
|
||||
bean.setStatus(XjcRdeRegistrarStatusType.OK);
|
||||
break;
|
||||
case PENDING:
|
||||
case SUSPENDED:
|
||||
bean.setStatus(XjcRdeRegistrarStatusType.READONLY);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException(String.format("Bad state: %s", model.getState()));
|
||||
}
|
||||
checkState(
|
||||
REGISTRAR_STATUS_CONVERSIONS.containsKey(model.getState()),
|
||||
"Unknown registrar state: %s",
|
||||
model.getState());
|
||||
bean.setStatus(REGISTRAR_STATUS_CONVERSIONS.get(model.getState()));
|
||||
|
||||
// o One or two <postalInfo> elements that contain postal- address
|
||||
// information. Two elements are provided so that address
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
package google.registry.rde;
|
||||
|
||||
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.xjc.XjcXmlTransformer.marshalStrict;
|
||||
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 google.registry.model.ofy.Ofy;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.model.registrar.Registrar.State;
|
||||
import google.registry.model.registrar.RegistrarAddress;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import google.registry.testing.FakeClock;
|
||||
|
@ -95,8 +97,8 @@ public class RegistrarToXjcConverterTest extends ShardableTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testConvert() {
|
||||
XjcRdeRegistrar bean = RegistrarToXjcConverter.convertRegistrar(registrar);
|
||||
public void test_convertRegistrar() {
|
||||
XjcRdeRegistrar bean = convertRegistrar(registrar);
|
||||
|
||||
assertThat(bean.getId()).isEqualTo("GoblinMarket");
|
||||
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");
|
||||
|
||||
// This is just hard-coded for now I guess.
|
||||
assertThat(bean.getStatus()).isEqualTo(XjcRdeRegistrarStatusType.OK);
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
@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
|
||||
public void testMarshal() throws Exception {
|
||||
marshalStrict(RegistrarToXjcConverter.convert(registrar), new ByteArrayOutputStream(), UTF_8);
|
||||
|
|
Loading…
Add table
Reference in a new issue