google-nomulus/javatests/google/registry/rde/imports/XjcToHostResourceConverterTest.java
cgoldfeder 0b1781b110 Make LINKED into a virtual status value
* Remove LINKED when loading an EppResource
* Enforce that you can't add it to a resource
* Ignore LINKED on xjc import of contacts and hosts

After running ResaveAllEppResourcesAction we will no
longer have persisted LINKED statuses in datastore.

In the process of writing this I discovered that RDAP
treats LINKED like any other status value and returns
the persisted value rather than the derived one. Since
this is an existing bug and is orthogonal to the changes
in this CL, I am addressing it in a separate CL.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=145585227
2017-01-30 15:03:53 -05:00

104 lines
4.1 KiB
Java

// Copyright 2016 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.rde.imports;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.DatastoreHelper.createTld;
import com.google.appengine.repackaged.com.google.common.net.InetAddresses;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.io.ByteSource;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.HostResource;
import google.registry.testing.AppEngineRule;
import google.registry.testing.ShardableTestCase;
import google.registry.xjc.rdehost.XjcRdeHost;
import google.registry.xjc.rdehost.XjcRdeHostElement;
import java.io.InputStream;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
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;
/**
* Unit tests for {@link XjcToHostResourceConverter}
*/
@RunWith(JUnit4.class)
public class XjcToHostResourceConverterTest extends ShardableTestCase {
private static final ByteSource HOST_XML = RdeImportsTestData.get("host_fragment.xml");
//List of packages to initialize JAXBContext
private static final String JAXB_CONTEXT_PACKAGES = Joiner.on(":")
.join(ImmutableList.of(
"google.registry.xjc.contact",
"google.registry.xjc.domain",
"google.registry.xjc.host",
"google.registry.xjc.mark",
"google.registry.xjc.rde",
"google.registry.xjc.rdecontact",
"google.registry.xjc.rdedomain",
"google.registry.xjc.rdeeppparams",
"google.registry.xjc.rdeheader",
"google.registry.xjc.rdeidn",
"google.registry.xjc.rdenndn",
"google.registry.xjc.rderegistrar",
"google.registry.xjc.smd"));
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
private Unmarshaller unmarshaller;
@Before
public void before() throws Exception {
createTld("example");
unmarshaller = JAXBContext.newInstance(JAXB_CONTEXT_PACKAGES)
.createUnmarshaller();
}
@Test
public void testConvertHostResource() throws Exception {
XjcRdeHost xjcHost = getHost();
HostResource host = XjcToHostResourceConverter.convert(xjcHost);
assertThat(host.getFullyQualifiedHostName()).isEqualTo("ns1.example1.test");
assertThat(host.getRepoId()).isEqualTo("Hns1_example1_test-TEST");
// The imported XML also had LINKED status, but that should have been dropped on import.
assertThat(host.getStatusValues()).containsExactly(StatusValue.OK);
assertThat(host.getInetAddresses()).containsExactly(
InetAddresses.forString("192.0.2.2"),
InetAddresses.forString("192.0.2.29"),
InetAddresses.forString("1080:0:0:0:8:800:200C:417A"));
assertThat(host.getCurrentSponsorClientId()).isEqualTo("RegistrarX");
assertThat(host.getCreationClientId()).isEqualTo("RegistrarX");
assertThat(host.getCreationTime()).isEqualTo(DateTime.parse("1999-05-08T12:10:00.0Z"));
assertThat(host.getLastEppUpdateClientId()).isEqualTo("RegistrarX");
assertThat(host.getLastEppUpdateTime()).isEqualTo(DateTime.parse("2009-10-03T09:34:00.0Z"));
assertThat(host.getLastTransferTime()).isEqualTo(DateTime.parse("2008-10-03T09:34:00.0Z"));
}
private XjcRdeHost getHost() throws Exception {
try (InputStream ins = HOST_XML.openStream()) {
return ((XjcRdeHostElement) unmarshaller.unmarshal(ins)).getValue();
}
}
}