refactore response tests to create response xml files if
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 28 Oct 2007 11:11:40 +0000 (11:11 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 28 Oct 2007 11:11:40 +0000 (11:11 +0000)
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

t/20-response.t
t/response/GetParameterNames.xml [new file with mode: 0644]
t/response/GetRPCMethods.xml [new file with mode: 0644]
t/response/InformResponse.xml [new file with mode: 0644]
t/response/Reboot.xml [new file with mode: 0644]

index b273606..f3dea36 100755 (executable)
@@ -4,83 +4,40 @@ use warnings;
 
 my $debug = shift @ARGV;
 
 
 my $debug = shift @ARGV;
 
-use Test::More tests => 11;
+use Test::More tests => 12;
 use Data::Dump qw/dump/;
 use Data::Dump qw/dump/;
+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' );
diff --git a/t/response/GetParameterNames.xml b/t/response/GetParameterNames.xml
new file mode 100644 (file)
index 0000000..90cd0eb
--- /dev/null
@@ -0,0 +1,14 @@
+<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
diff --git a/t/response/GetRPCMethods.xml b/t/response/GetRPCMethods.xml
new file mode 100644 (file)
index 0000000..259756b
--- /dev/null
@@ -0,0 +1,11 @@
+<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
diff --git a/t/response/InformResponse.xml b/t/response/InformResponse.xml
new file mode 100644 (file)
index 0000000..8ae94fc
--- /dev/null
@@ -0,0 +1,13 @@
+<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
diff --git a/t/response/Reboot.xml b/t/response/Reboot.xml
new file mode 100644 (file)
index 0000000..fb92986
--- /dev/null
@@ -0,0 +1,11 @@
+<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