google-nomulus/java/google/registry/model/eppcommon/Trid.java
mcilwain ed910455b0 Add more absent clTrid unit tests
In RFC 5730, clTrid is specified as optional. We ran into an error earlier this
year in which a registrar was not passing a client transaction id and we didn't
handle it correctly. So, this CL adds some tests of common EPP operations verify
that they work correctly when the clTrid is not specified.

This also slightly improves some flow logic to make it more obvious at first
glance that clTrid is indeed optional.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=202000845
2018-06-27 15:28:52 -04:00

60 lines
2.3 KiB
Java

// 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.model.eppcommon;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
import com.googlecode.objectify.annotation.Embed;
import google.registry.model.ImmutableObject;
import java.util.Optional;
import javax.annotation.Nullable;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
* "A {@code TRID} (transaction identifier) element containing the transaction identifier assigned
* by the server to the command for which the response is being returned. The transaction identifier
* is formed using the {@code clTRID} associated with the command if supplied by the client and a
* {@code svTRID} (server transaction identifier) that is assigned by and unique to the server."
*/
@Embed
@XmlType(propOrder = {"clientTransactionId", "serverTransactionId"})
public class Trid extends ImmutableObject {
/** The server transaction id. */
@XmlElement(name = "svTRID", namespace = "urn:ietf:params:xml:ns:epp-1.0")
String serverTransactionId;
/** The client transaction id, if provided by the client, otherwise null. */
@XmlElement(name = "clTRID", namespace = "urn:ietf:params:xml:ns:epp-1.0")
@Nullable
String clientTransactionId;
public String getServerTransactionId() {
return serverTransactionId;
}
public Optional<String> getClientTransactionId() {
return Optional.ofNullable(clientTransactionId);
}
public static Trid create(@Nullable String clientTransactionId, String serverTransactionId) {
checkArgumentNotNull(serverTransactionId, "serverTransactionId cannot be null");
Trid instance = new Trid();
instance.clientTransactionId = clientTransactionId;
instance.serverTransactionId = serverTransactionId;
return instance;
}
}