mirror of
https://github.com/google/nomulus.git
synced 2025-07-21 02:06:00 +02:00
The dark lord Gosling designed the Java package naming system so that ownership flows from the DNS system. Since we own the domain name registry.google, it seems only appropriate that we should use google.registry as our package name.
152 lines
6.1 KiB
Java
152 lines
6.1 KiB
Java
// Copyright 2016 The Domain Registry 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.rde;
|
|
|
|
import static com.google.common.truth.Truth.assertThat;
|
|
import static google.registry.testing.DatastoreHelper.cloneAndSetAutoTimestamps;
|
|
import static google.registry.xjc.XjcXmlTransformer.marshalStrict;
|
|
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.RegistrarAddress;
|
|
import google.registry.testing.AppEngineRule;
|
|
import google.registry.testing.FakeClock;
|
|
import google.registry.testing.InjectRule;
|
|
import google.registry.xjc.rderegistrar.XjcRdeRegistrar;
|
|
import google.registry.xjc.rderegistrar.XjcRdeRegistrarAddrType;
|
|
import google.registry.xjc.rderegistrar.XjcRdeRegistrarPostalInfoEnumType;
|
|
import google.registry.xjc.rderegistrar.XjcRdeRegistrarPostalInfoType;
|
|
import google.registry.xjc.rderegistrar.XjcRdeRegistrarStatusType;
|
|
|
|
import org.joda.time.DateTime;
|
|
import org.junit.Before;
|
|
import org.junit.Rule;
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
import org.junit.runners.JUnit4;
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
/**
|
|
* Unit tests for {@link RegistrarToXjcConverter}.
|
|
*
|
|
* <p>This tests the mapping between {@link Registrar} and {@link XjcRdeRegistrar} as well as
|
|
* some exceptional conditions.
|
|
*/
|
|
@RunWith(JUnit4.class)
|
|
public class RegistrarToXjcConverterTest {
|
|
|
|
@Rule
|
|
public final AppEngineRule appEngine = AppEngineRule.builder()
|
|
.withDatastore()
|
|
.build();
|
|
|
|
@Rule
|
|
public final InjectRule inject = new InjectRule();
|
|
|
|
Registrar registrar;
|
|
|
|
@Before
|
|
public void init() {
|
|
registrar = new Registrar.Builder()
|
|
.setClientIdentifier("GoblinMarket")
|
|
.setRegistrarName("Maids heard the goblins cry: Come buy, come buy:")
|
|
.setType(Registrar.Type.REAL)
|
|
.setIanaIdentifier(8L)
|
|
.setState(Registrar.State.ACTIVE)
|
|
.setInternationalizedAddress(new RegistrarAddress.Builder()
|
|
.setStreet(ImmutableList.of("123 Detonation Boulevard"))
|
|
.setCity("Williamsburg")
|
|
.setState("NY")
|
|
.setZip("11211")
|
|
.setCountryCode("US")
|
|
.build())
|
|
.setLocalizedAddress(new RegistrarAddress.Builder()
|
|
.setStreet(ImmutableList.of("123 Example Boulevard."))
|
|
.setCity("Hipsterville")
|
|
.setState("NY")
|
|
.setZip("11211")
|
|
.setCountryCode("US")
|
|
.build())
|
|
.setPhoneNumber("+1.2125551212")
|
|
.setFaxNumber("+1.2125551213")
|
|
.setEmailAddress("contact-us@goblinmen.example")
|
|
.setWhoisServer("whois.goblinmen.example")
|
|
.setUrl("http://www.goblinmen.example")
|
|
.build();
|
|
FakeClock clock = new FakeClock(DateTime.parse("2013-01-01T00:00:00Z"));
|
|
inject.setStaticField(Ofy.class, "clock", clock);
|
|
registrar = cloneAndSetAutoTimestamps(registrar); // Set the creation time in 2013.
|
|
clock.setTo(DateTime.parse("2014-01-01T00:00:00Z"));
|
|
registrar = cloneAndSetAutoTimestamps(registrar); // Set the update time in 2014.
|
|
}
|
|
|
|
@Test
|
|
public void testConvert() throws Exception {
|
|
XjcRdeRegistrar bean = RegistrarToXjcConverter.convertRegistrar(registrar);
|
|
|
|
assertThat(bean.getId()).isEqualTo("GoblinMarket");
|
|
assertThat(bean.getName()).isEqualTo("Maids heard the goblins cry: Come buy, come buy:");
|
|
|
|
assertThat(bean.getPostalInfos()).hasSize(2);
|
|
// I hard-coded the localized unicode happy address to come first just cuz.
|
|
XjcRdeRegistrarPostalInfoType postalInfo0 = bean.getPostalInfos().get(0);
|
|
assertThat(postalInfo0.getType()).isEqualTo(XjcRdeRegistrarPostalInfoEnumType.LOC);
|
|
XjcRdeRegistrarAddrType address0 = postalInfo0.getAddr();
|
|
assertThat(address0.getStreets()).containsExactly("123 Example Boulevard.");
|
|
assertThat(address0.getCity()).isEqualTo("Hipsterville");
|
|
assertThat(address0.getSp()).isEqualTo("NY");
|
|
assertThat(address0.getPc()).isEqualTo("11211");
|
|
assertThat(address0.getCc()).isEqualTo("US");
|
|
// Now for the non-unicode form.
|
|
XjcRdeRegistrarPostalInfoType postalInfo1 = bean.getPostalInfos().get(1);
|
|
assertThat(postalInfo1.getType()).isEqualTo(XjcRdeRegistrarPostalInfoEnumType.INT);
|
|
XjcRdeRegistrarAddrType address1 = postalInfo1.getAddr();
|
|
assertThat(address1.getStreets()).containsExactly("123 Detonation Boulevard");
|
|
assertThat(address1.getCity()).isEqualTo("Williamsburg");
|
|
assertThat(address1.getSp()).isEqualTo("NY");
|
|
assertThat(address1.getPc()).isEqualTo("11211");
|
|
assertThat(address1.getCc()).isEqualTo("US");
|
|
|
|
assertThat(bean.getVoice().getValue()).isEqualTo("+1.2125551212");
|
|
assertThat(bean.getVoice().getX()).isNull();
|
|
|
|
assertThat(bean.getFax().getValue()).isEqualTo("+1.2125551213");
|
|
assertThat(bean.getFax().getX()).isNull();
|
|
|
|
assertThat(bean.getEmail()).isEqualTo("contact-us@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.getCrDate()).isEqualTo(DateTime.parse("2013-01-01T00:00:00Z"));
|
|
|
|
assertThat(bean.getUpDate()).isEqualTo(DateTime.parse("2014-01-01T00:00:00Z"));
|
|
|
|
assertThat(bean.getWhoisInfo().getName()).isEqualTo("whois.goblinmen.example");
|
|
}
|
|
|
|
@Test
|
|
public void testMarshal() throws Exception {
|
|
marshalStrict(RegistrarToXjcConverter.convert(registrar), new ByteArrayOutputStream(), UTF_8);
|
|
}
|
|
|
|
@Test public void makeShardingWork1() {}
|
|
}
|