diff --git a/java/google/registry/model/reporting/HistoryEntry.java b/java/google/registry/model/reporting/HistoryEntry.java index 2ee7a998f..ea67690fc 100644 --- a/java/google/registry/model/reporting/HistoryEntry.java +++ b/java/google/registry/model/reporting/HistoryEntry.java @@ -31,6 +31,7 @@ import google.registry.model.annotations.ReportedOn; import google.registry.model.domain.Period; import google.registry.model.eppcommon.Trid; import java.util.Set; +import javax.annotation.Nullable; import org.joda.time.DateTime; /** A record of an EPP command that mutated a resource. */ @@ -121,8 +122,8 @@ public class HistoryEntry extends ImmutableObject implements Buildable { */ String otherClientId; - /** Transaction id that made this change. */ - Trid trid; + /** Transaction id that made this change, or null if the entry was not created by a flow. */ + @Nullable Trid trid; /** Whether this change was created by a superuser. */ boolean bySuperuser; @@ -170,7 +171,8 @@ public class HistoryEntry extends ImmutableObject implements Buildable { return otherClientId; } - public Trid getTrid() { + /** Returns the TRID, which may be null if the entry was not created by a normal flow. */ + @Nullable public Trid getTrid() { return trid; } diff --git a/java/google/registry/tools/GetHistoryEntriesCommand.java b/java/google/registry/tools/GetHistoryEntriesCommand.java index f09b91b74..9dbcd26e8 100644 --- a/java/google/registry/tools/GetHistoryEntriesCommand.java +++ b/java/google/registry/tools/GetHistoryEntriesCommand.java @@ -77,8 +77,8 @@ final class GetHistoryEntriesCommand implements RemoteApiCommand { "Client: %s\nTime: %s\nClient TRID: %s\nServer TRID: %s\n%s\n", entry.getClientId(), entry.getModificationTime(), - entry.getTrid().getClientTransactionId(), - entry.getTrid().getServerTransactionId(), + (entry.getTrid() == null) ? null : entry.getTrid().getClientTransactionId(), + (entry.getTrid() == null) ? null : entry.getTrid().getServerTransactionId(), entry.getXmlBytes() == null ? String.format("[no XML stored for %s]\n", entry.getType()) : XmlTransformer.prettyPrint(entry.getXmlBytes())); diff --git a/javatests/google/registry/tools/GetHistoryEntriesCommandTest.java b/javatests/google/registry/tools/GetHistoryEntriesCommandTest.java new file mode 100644 index 000000000..4b74dd854 --- /dev/null +++ b/javatests/google/registry/tools/GetHistoryEntriesCommandTest.java @@ -0,0 +1,83 @@ +// 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.tools; + +import static google.registry.testing.DatastoreHelper.createTld; +import static google.registry.testing.DatastoreHelper.persistActiveDomain; +import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.FullFieldsTestEntityHelper.makeHistoryEntry; + +import google.registry.model.domain.DomainResource; +import google.registry.model.domain.Period; +import google.registry.model.reporting.HistoryEntry; +import google.registry.testing.FakeClock; +import org.joda.time.DateTime; +import org.junit.Before; +import org.junit.Test; + +/** Unit tests for {@link GetClaimsListCommand}. */ +public class GetHistoryEntriesCommandTest extends CommandTestCase { + + private final FakeClock clock = new FakeClock(DateTime.parse("2000-01-01T00:00:00Z")); + + private DomainResource domain; + + @Before + public void setup() { + createTld("tld"); + domain = persistActiveDomain("example.tld"); + } + + @Test + public void testSuccess_works() throws Exception { + persistResource( + makeHistoryEntry( + domain, + HistoryEntry.Type.DOMAIN_CREATE, + Period.create(1, Period.Unit.YEARS), + "created", + clock.nowUtc())); + runCommand("--id=example.tld", "--type=DOMAIN"); + assertStdoutIs( + "Client: foo\n" + + "Time: 2000-01-01T00:00:00.000Z\n" + + "Client TRID: ABC-123\n" + + "Server TRID: server-trid\n" + + "\n" + + "\n"); + } + + @Test + public void testSuccess_noTrid() throws Exception { + persistResource( + makeHistoryEntry( + domain, + HistoryEntry.Type.DOMAIN_CREATE, + Period.create(1, Period.Unit.YEARS), + "created", + clock.nowUtc()) + .asBuilder() + .setTrid(null) + .build()); + runCommand("--id=example.tld", "--type=DOMAIN"); + assertStdoutIs( + "Client: foo\n" + + "Time: 2000-01-01T00:00:00.000Z\n" + + "Client TRID: null\n" + + "Server TRID: null\n" + + "\n" + + "\n"); + } +}