they doesn't exist (so, implementing new command consists
of adding one line in 20-response.t, re-run test and check if xml is valid
and commit it :-)
git-svn-id: https://perl-cwmp.googlecode.com/svn/trunk@164
836a5e1a-633d-0410-964b-
294494ad4392
-use Test::More tests => 11;
+use Test::More tests => 12;
+use Cwd qw/abs_path/;
+use File::Slurp;
use blib;
BEGIN {
use_ok('CWMP::Response');
}
use blib;
BEGIN {
use_ok('CWMP::Response');
}
-#ok( my $xml = join("",<DATA>), 'xml' );
-#diag $xml if $debug;
+ok(my $abs_path = abs_path($0), "abs_path");
+$abs_path =~ s!/[^/]*$!/!; #!fix-vim
ok( my $response = CWMP::Response->new({ debug => $debug }), 'new' );
isa_ok( $response, 'CWMP::Response' );
ok( my $response = CWMP::Response->new({ debug => $debug }), 'new' );
isa_ok( $response, 'CWMP::Response' );
-sub is_like {
- my ( $command, $template_xml ) = @_;
+sub check_response {
+ my $command = shift || die "no command?";
- ok( my $xml = $response->$command({ ID => 42 }), $command );
- diag $xml if $debug;
- chomp( $xml );
- chomp( $template_xml );
- like( $xml, qr{^\Q$template_xml\E$}, $command . ' xml' );
-}
+ ok( my $xml = $response->$command({ ID => 42 }), "generate response for $command" );
+
+ my $file = "$abs_path/response/$command.xml";
-is_like( 'InformResponse', <<__SOAP__
-<soap:Envelope xmlns:cwmp="urn:dslforum-org:cwmp-1-0" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
- <soap:Header>
- <cwmp:ID mustUnderstand="1">42</cwmp:ID>
- <cwmp:NoMoreRequests>0</cwmp:NoMoreRequests>
- </soap:Header>
- <soap:Body>
- <cwmp:InformResponse>
- <cwmp:MaxEnvelopes>1</cwmp:MaxEnvelopes>
- </cwmp:InformResponse>
- </soap:Body>
-</soap:Envelope>
-__SOAP__
-);
+ if ( ! -e $file ) {
+ diag "creating $file";
+ write_file( $file, $xml );
+ }
-is_like( 'GetRPCMethods', <<__SOAP__
-<soap:Envelope xmlns:cwmp="urn:dslforum-org:cwmp-1-0" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
- <soap:Header>
- <cwmp:ID mustUnderstand="1">42</cwmp:ID>
- <cwmp:NoMoreRequests>0</cwmp:NoMoreRequests>
- </soap:Header>
- <soap:Body>
- <GetRPCMethods />
- </soap:Body>
-</soap:Envelope>
-__SOAP__
-);
+ my $template_xml = read_file( $file ) || die "can't read template xml $file: $!";
-is_like( 'Reboot', <<__SOAP__
-<soap:Envelope xmlns:cwmp="urn:dslforum-org:cwmp-1-0" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
- <soap:Header>
- <cwmp:ID mustUnderstand="1">42</cwmp:ID>
- <cwmp:NoMoreRequests>0</cwmp:NoMoreRequests>
- </soap:Header>
- <soap:Body>
- <Reboot />
- </soap:Body>
-</soap:Envelope>
-__SOAP__
-);
+ is( $xml, $template_xml, "compare $command" );
+}
-is_like( 'GetParameterNames', <<__SOAP__
-<soap:Envelope xmlns:cwmp="urn:dslforum-org:cwmp-1-0" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
- <soap:Header>
- <cwmp:ID mustUnderstand="1">42</cwmp:ID>
- <cwmp:NoMoreRequests>0</cwmp:NoMoreRequests>
- </soap:Header>
- <soap:Body>
- <cwmp:GetParameterNames>
- <cwmp:ParameterPath></cwmp:ParameterPath>
- <cwmp:NextLevel>0</cwmp:NextLevel>
- </cwmp:GetParameterNames>
- </soap:Body>
-</soap:Envelope>
-__SOAP__
-);
+check_response( 'InformResponse' );
+check_response( 'GetRPCMethods' );
+check_response( 'Reboot' );
+check_response( 'GetParameterNames' );
--- /dev/null
+<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
+ xmlns:cwmp="urn:dslforum-org:cwmp-1-0"
+ soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
+ <soap:Header>
+ <cwmp:ID mustUnderstand="1">42</cwmp:ID>
+ <cwmp:NoMoreRequests>0</cwmp:NoMoreRequests>
+ </soap:Header>
+ <soap:Body>
+ <cwmp:GetParameterNames>
+ <cwmp:ParameterPath></cwmp:ParameterPath>
+ <cwmp:NextLevel>0</cwmp:NextLevel>
+ </cwmp:GetParameterNames>
+ </soap:Body>
+</soap:Envelope>
\ No newline at end of file
--- /dev/null
+<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
+ xmlns:cwmp="urn:dslforum-org:cwmp-1-0"
+ soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
+ <soap:Header>
+ <cwmp:ID mustUnderstand="1">42</cwmp:ID>
+ <cwmp:NoMoreRequests>0</cwmp:NoMoreRequests>
+ </soap:Header>
+ <soap:Body>
+ <GetRPCMethods />
+ </soap:Body>
+</soap:Envelope>
\ No newline at end of file
--- /dev/null
+<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
+ xmlns:cwmp="urn:dslforum-org:cwmp-1-0"
+ soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
+ <soap:Header>
+ <cwmp:ID mustUnderstand="1">42</cwmp:ID>
+ <cwmp:NoMoreRequests>0</cwmp:NoMoreRequests>
+ </soap:Header>
+ <soap:Body>
+ <cwmp:InformResponse>
+ <cwmp:MaxEnvelopes>1</cwmp:MaxEnvelopes>
+ </cwmp:InformResponse>
+ </soap:Body>
+</soap:Envelope>
\ No newline at end of file
--- /dev/null
+<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
+ xmlns:cwmp="urn:dslforum-org:cwmp-1-0"
+ soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
+ <soap:Header>
+ <cwmp:ID mustUnderstand="1">42</cwmp:ID>
+ <cwmp:NoMoreRequests>0</cwmp:NoMoreRequests>
+ </soap:Header>
+ <soap:Body>
+ <Reboot />
+ </soap:Body>
+</soap:Envelope>
\ No newline at end of file