Skip to content

Commit

Permalink
RPE-937 Support UIN with renew unspec extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernie Schelberg committed Sep 22, 2017
1 parent 161db77 commit 35078f0
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 13 deletions.
Expand Up @@ -12,13 +12,20 @@
* <p>Use this to command to restore a domain name in Redemption. The response expected from a
* server should be handled by a Domain Renew Response.</p>
*
* <p>This extension is also used to specify the UIN for renew in the .travel zone.</p>
*
* @see com.ausregistry.jtoolkit2.se.DomainRenewCommand
*/
public class DomainRenewCommandUnspecExtension implements CommandExtension {
private final RestoreReasonCode restoreReasonCode;
private final String restoreComment;
private final boolean trueData;
private final boolean validUse;
private RestoreReasonCode restoreReasonCode;
private String restoreComment;
private boolean trueData;
private boolean validUse;
private String uin;

public DomainRenewCommandUnspecExtension(String uin) {
this.uin = uin;
}

public DomainRenewCommandUnspecExtension(RestoreReasonCode restoreReasonCode, String restoreComment,
boolean trueData, boolean validUse) {
Expand All @@ -30,15 +37,23 @@ public DomainRenewCommandUnspecExtension(RestoreReasonCode restoreReasonCode, St

@Override
public void addToCommand(Command command) {
final XMLWriter xmlWriter = command.getXmlWriter();
final Element extensionElement = command.getExtensionElement();
final Element renewElement = xmlWriter.appendChild(extensionElement, "extension",
ExtendedObjectType.UNSPEC.getURI());
if (restoreReasonCode != null) {
addUnspecWithContent(command, "RestoreReasonCode=" + restoreReasonCode.getValue()
+ " RestoreComment=" + restoreComment
+ " TrueData=" + (trueData ? "Y" : "N")
+ " ValidUse=" + (validUse ? "Y" : "N"));
} else if (uin != null) {
addUnspecWithContent(command, "UIN=" + uin);
}
}

private void addUnspecWithContent(Command command, String content) {
final XMLWriter xmlWriter = command.getXmlWriter();
final Element extensionElement = command.getExtensionElement();
final Element renewElement = xmlWriter.appendChild(extensionElement, "extension",
ExtendedObjectType.UNSPEC.getURI());

xmlWriter.appendChild(renewElement, "unspec", ExtendedObjectType.UNSPEC.getURI()).setTextContent(
"RestoreReasonCode=" + restoreReasonCode.getValue()
+ " RestoreComment=" + restoreComment
+ " TrueData=" + (trueData ? "Y" : "N")
+ " ValidUse=" + (validUse ? "Y" : "N"));
xmlWriter.appendChild(renewElement, "unspec", ExtendedObjectType.UNSPEC.getURI()).setTextContent(
content);
}
}
Expand Up @@ -98,5 +98,40 @@ public void shouldGenerateForFalseBooleanValuesXML() {
fail(saxe.getMessage());
}
}

@Test
public void shouldGenerateWithUin() {
String domainName = "jtkutest.com.au";
String currentExpiry = "2006-12-25";
final Command cmd = new DomainRenewCommand(domainName, EPPDateFormatter.fromXSDateTime(currentExpiry));
DomainRenewCommandUnspecExtension ext = new DomainRenewCommandUnspecExtension("0000");
try {
cmd.appendExtension(ext);
String xml = cmd.toXML();
String expectedXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<epp xmlns=\"urn:ietf:params:xml:ns:epp-1.0\""
+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
+ " xsi:schemaLocation=\"urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd\">"
+ "<command>"
+ "<renew>"
+ "<renew xmlns=\"urn:ietf:params:xml:ns:domain-1.0\""
+ " xsi:schemaLocation=\"urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd\">"
+ "<name>" + domainName + "</name>"
+ "<curExpDate>" + currentExpiry + "</curExpDate>"
+ "</renew>"
+ "</renew>"
+ "<extension>"
+ "<extension xmlns=\"urn:ietf:params:xml:ns:neulevel-1.0\">"
+ "<unspec>UIN=0000</unspec>"
+ "</extension>"
+ "</extension>"
+ "<clTRID>JTKUTEST.20070101.010101.0</clTRID>"
+ "</command>"
+ "</epp>";
assertEquals(expectedXml, xml);
} catch (SAXException saxe) {
fail(saxe.getMessage());
}
}
}

0 comments on commit 35078f0

Please sign in to comment.