1#!/usr/bin/perl -w
2
3use Net::DRI;
4use Net::DRI::Data::Raw;
5use DateTime::Duration;
6use Data::Dumper;
7
8use Test::More tests => 3;
9
10eval { no warnings; require Test::LongString; Test::LongString->import(max => 100); $Test::LongString::Context=50; };
11*{'main::is_string'}=\&main::is if $@;
12
13our $E1='<?xml version="1.0" encoding="UTF-8" standalone="no"?><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">';
14our $E2='</epp>';
15our $TRID='<trID><clTRID>ABC-12345</clTRID><svTRID>54322-XYZ</svTRID></trID>';
16
17our $R1;
18sub mysend
19{
20	my ($transport, $count, $msg) = @_;
21	$R1 = $msg->as_string();
22	return 1;
23}
24
25our $R2;
26sub myrecv
27{
28	return Net::DRI::Data::Raw->new_from_string($R2 ? $R2 : $E1 .
29		'<response>' . r() . $TRID . '</response>' . $E2);
30}
31
32my $dri;
33eval {
34	$dri = Net::DRI->new(10);
35};
36print $@->as_string() if $@;
37$dri->{trid_factory} = sub { return 'ABC-12345'; };
38$dri->add_registry('HN');
39eval {
40	$dri->target('HN')->add_current_profile('p1',
41		'test=EPP',
42		{
43			f_send=> \&mysend,
44			f_recv=> \&myrecv
45		}, {extensions=>['Net::DRI::Protocol::EPP::Extensions::Afilias::Restore']});
46};
47print $@->as_string() if $@;
48
49
50my $rc;
51my $s;
52my $d;
53my ($dh,@c);
54
55####################################################################################################
56## Restore a deleted domain
57$R2 = $E1 . '<response>' . r(1001,'Command completed successfully; ' .
58	'action pending') . $TRID . '</response>' . $E2;
59
60eval {
61	$rc = $dri->domain_renew('deleted-by-accident.com.hn', {
62		current_expiration => new DateTime(year => 2008, month => 12,
63			day => 24),
64		rgp => 1});
65};
66print(STDERR $@->as_string()) if ($@);
67isa_ok($rc, 'Net::DRI::Protocol::ResultStatus');
68is($rc->is_success(), 1, 'Domain successfully recovered');
69is($R1, '<?xml version="1.0" encoding="UTF-8" standalone="no"?><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><domain:renew xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd"><domain:name>deleted-by-accident.com.hn</domain:name><domain:curExpDate>2008-12-24</domain:curExpDate></domain:renew></renew><extension><rgp:renew xmlns:rgp="urn:EPP:xml:ns:ext:rgp-1.0" xsi:schemaLocation="urn:EPP:xml:ns:ext:rgp-1.0 rgp-1.0.xsd"><rgp:restore/></rgp:renew></extension><clTRID>ABC-12345</clTRID></command></epp>', 'Recover Domain XML correct');
70
71####################################################################################################
72exit(0);
73
74sub r
75{
76 my ($c,$m)=@_;
77 return '<result code="'.($c || 1000).'"><msg>'.($m || 'Command completed successfully').'</msg></result>';
78}
79