#!/usr/bin/perl -w -CSAD use Test::More tests => 280; use bytes; use Cwd (); use utf8; $^W = 1; use warnings; use strict; BEGIN { use_ok( 'RayApp' ); } BEGIN { use_ok( 'POSIX' ); } BEGIN { use_ok( 'XML::LibXML' ); } POSIX::setlocale(POSIX::LC_ALL, 'C'); chdir 't' if -d 't'; my $rayapp = new RayApp; isa_ok($rayapp, 'RayApp'); my $dsd; ok($dsd = $rayapp->load_dsd("simple1.xml"), 'Loading correct DSD simple1.xml'); is($rayapp->errstr, undef, 'Checking that there was no error'); ok($dsd->can('isdsd'), 'Checking that we loaded DSD'); like($dsd->uri, '/^file:.*simple1.xml$/', 'Checking URI of the DSD'); is($dsd->md5_hex, 'a9eaba3064593944b9141aee064585cf', 'Checking MD5 of the DSD'); is("@{[ sort keys %{ $dsd->params } ]}", "action id", 'Checking parameters found'); ok($dsd = $rayapp->load_dsd("simple1.xml"), 'Loading for the second time'); is($rayapp->errstr, undef, 'Checking that there was no error'); like($dsd->uri, '/^file:.*simple1.xml$/', 'Checking URI of the DSD'); is($dsd->md5_hex, 'a9eaba3064593944b9141aee064585cf', 'Checking MD5 of the DSD'); is("@{[ sort keys %{ $dsd->params } ]}", "action id", 'Checking parameters found'); my $params = $dsd->params; is("@{[ map { qq!$_:$params->{$_}{type}! } sort keys %$params ]}", "action:string id:int", 'Checking parameter types'); is($dsd->out_content, ' ', 'Checking the current content'); my $txt; is($txt = $dsd->serialize_data({ 'result' => 56, 'name' => 'Amanda' }, { RaiseError => 0 }), ' Amanda 56 ', 'Checking serialization of data'); is($dsd->errstr, undef, 'There should be no errstr'); =comment my $dtd = $dsd->get_dtd; is($dtd, ' ', 'Checking the DTD'); my $parsed_dtd = XML::LibXML::Dtd->parse_string($dtd); my $parser = XML::LibXML->new(); ok($parser, 'Loading XML::LibXML parser'); my $doc = $parser->parse_string($txt); ok($doc, 'Parse the serialized XML back'); is($doc->is_valid($parsed_dtd), 1, 'Check against the DTD'); =cut is($dsd->serialize_data({ 'result' => -56 }, { RaiseError => 0, validate => 1 }), ' -56 ', 'Checking serialization of data with validate'); is($dsd->errstr, undef, 'There should be no errstr'); is($dsd->serialize_data({ }, { RaiseError => 0, validate => 1 }), ' ', 'Checking serialization of data with no data'); is($dsd->errstr, undef, 'There should be no errstr'); is($txt = $dsd->serialize_data({ 'result' => 34, 'name' => 'Peter'}, { RaiseError => 0, doctype => 'simple1.dtd' }), ' Peter 34 ', 'Serialize with doctype'); is($dsd->serialize_data({ 'result' => 34, 'name' => 'Peter'}, { RaiseError => 0, doctype_ext => '.DTD' }), ' Peter 34 ', 'Serialize with doctype_ext'); ok($dsd = $rayapp->load_dsd("simple2.xml"), 'Loading correct DSD t/simple2.xml'); is($rayapp->errstr, undef, 'Checking that there was no error'); like($dsd->uri, '/^file:.*simple2.xml$/', 'Checking URI of the DSD'); is($dsd->md5_hex, '0d3f3778c0d5aeb5d574ef12a790f7e8', 'Checking MD5 of the DSD'); is("@{[ sort keys %{ $dsd->params } ]}", "_param id", 'Checking parameters found'); $params = $dsd->params; is("@{[ map { qq!$_->$params->{$_}{type}! } sort keys %$params ]}", "_param->string id->int", 'Checking parameter types'); is($dsd->out_content, ' <_param/> ', 'Checking the current content'); ok($dsd = $rayapp->load_dsd("../../httpd-tests/t/htdocs/ray/app1.dsd"), 'Loading correct DSD ../../httpd-tests/t/htdocs/ray/app1.dsd'); is($rayapp->errstr, undef, 'No error, please'); like($dsd->uri, '/^file:.*app1.dsd$/', 'Checking URI of the DSD'); is($dsd->md5_hex, '1d0461098a35c558d237003e5d5ca52f', 'Checking MD5 of the DSD'); is("@{[ sort keys %{ $dsd->params } ]}", "id", 'Checking parameters found'); ok($dsd = $rayapp->load_dsd("../../httpd-tests/t/htdocs/ray/app1.dsd"), 'Load it again'); is($rayapp->errstr, undef, 'Again, no error'); ok($dsd = $rayapp->load_dsd_string(<<'EOF'), 'Loading correct DSD from string'); <_param name='mix'> EOF is($rayapp->errstr, undef, 'Checking that there was no error'); is($dsd->uri, 'md5:9411809f5b9cd8bf682360b1243f00c5', 'Checking URI of the DSD'); is($dsd->md5_hex, '9411809f5b9cd8bf682360b1243f00c5', 'Checking MD5 of the DSD'); is("@{[ sort keys %{ $dsd->params } ]}", "mix", 'Checking parameters found'); is($dsd->out_content, ' ', 'Checking the current content'); ### print STDERR $dsd->get_dtd; is($dsd->serialize_data({ 'child' => 'Tom & Jerry' }, { RaiseError => 0, validate => 1 }), ' Tom & Jerry ', 'Checking serialization of data'); is($dsd->errstr, undef, 'No errstr should materialize'); ok($dsd = $rayapp->load_dsd("simple3.xml"), 'Loading correct DSD t/simple3.xml'); is($rayapp->errstr, undef, 'Checking that there was no error'); like($dsd->uri, '/^file:.*simple3.xml$/', 'Checking URI of the DSD'); is($dsd->md5_hex, 'e9ff60dcae73d65bda23145346b580df', 'Checking MD5 of the DSD'); my $out_content = <<'EOF'; EOF is($dsd->out_content, $out_content, 'Checking the current content'); ok($dsd = $rayapp->load_dsd("complex_param1.xml"), 'Loading correct DSD t/complex_param1.xml'); is($rayapp->errstr, undef, 'Checking that there was no error'); like($dsd->uri, '/^file:.*complex_param1.xml$/', 'Checking URI of the DSD'); is($dsd->md5_hex, 'f8cdb7a4e520d3d8bff857d0ee27e804', 'Checking MD5 of the DSD'); is("@{[ sort keys %{ $dsd->params } ]}", 'action id ns', 'Checking parameters found'); $params = $dsd->params; is("@{[ map { qq!$_:$params->{$_}{type}! } sort keys %$params ]}", "action:string id:int ns:struct", 'Checking parameter types'); ok($dsd = $rayapp->load_dsd_string(' '), 'Loading correct DSD from string'); is($rayapp->errstr, undef, 'Checking that there was no error'); is($dsd->uri, 'md5:d8de3b6b5337a4ca0b312133fbb58966', 'Checking URI/MD5 of the DSD'); $out_content = <<'EOF'; EOF is($dsd->out_content, $out_content, 'Checking the current content'); ok($dsd = $rayapp->load_dsd_string(' '), 'Loading correct DSD from string'); is($rayapp->errstr, undef, 'Checking that there was no error'); is($dsd->uri, 'md5:aeed5595d4ab07dce072ce1c65625535', 'Checking URI/MD5 of the DSD'); $out_content = <<'EOF'; EOF is($dsd->out_content, $out_content, 'Checking the current content'); is($dsd->serialize_data({ 'result' => 42, 'person' => { id => 243623, name => 'Amanda Reese', age => 23, car => { type => 'Honda', color => 'white', age => 3.5, }, }, }, { RaiseError => 0, validate => 1 }), ' 243623 Amanda Reese 23 white 3.5 Honda 42 ', 'Checking serializing nonscalar data'); is($dsd->errstr, undef, 'Any errstr means bad'); is($dsd->serialize_data({ 'result' => 42, 'person' => { id => 243623, name => 'Amanda Reese', age => 23, }, }, { RaiseError => 0, validate => 1 }), ' 243623 Amanda Reese 23 42 ', 'Checking serializing nonscalar data'); is($dsd->errstr, undef, 'Null errstr'); is($dsd->serialize_data({ 'result' => 42, 'person' => { id => 243623, name => 'Amanda Reese', age => 23, car => [ 'white', 6, 'Jeep', ], }, }, { RaiseError => 0, validate => 1 }), ' 243623 Amanda Reese 23 white 6 Jeep 42 ', 'Checking serializing nonscalar data'); is($dsd->errstr, undef, 'No errstr'); ok($dsd = $rayapp->load_dsd_string(' '), 'Loading correct DSD from string'); is($rayapp->errstr, undef, 'Checking that there was no error'); is($dsd->uri, 'md5:88303aec4b7b818f8c35f5f9ce8fa512', 'Checking URI/MD5 of the DSD'); $out_content = <<'EOF'; EOF is($dsd->out_content, $out_content, 'Checking the current content'); is($dsd->serialize_data({ 'people' => [ { id => 243623, name => 'Amanda Reese', age => 23, car => { type => 'Honda', color => 'white', age => 3.5, }, }, { id => 2413, name => 'Harry Burns', age => 25, }, { name => 'Sally Allbright', car => [ undef, undef, 'Volvo' ], id => 882413, age => 24, }, ] }, { RaiseError => 0, validate => 1 }), ' 243623 Amanda Reese 23 white 3.5 Honda 2413 Harry Burns 25 882413 Sally Allbright 24 Volvo ', 'Checking serializing nonscalar data'); is($rayapp->errstr, undef, 'Checking that there was no error'); is($dsd->serialize_data({ }), ' ', 'Serialize data with no people'); is($rayapp->errstr, undef, 'No errstr'); is($dsd->serialize_data({ people => [], }), ' ', 'Serialize data with empty people'); is($rayapp->errstr, undef, 'No errstr'); ok($dsd = $rayapp->load_dsd_string(' '), 'Loading correct DSD from string'); is($rayapp->errstr, undef, 'Checking that there was no error'); is($dsd->uri, 'md5:007b01e09a946e8912b667ab38804b78', 'Checking URI/MD5 of the DSD'); $out_content = <<'EOF'; EOF is($dsd->out_content, $out_content, 'Checking the current content'); is($dsd->serialize_data({ 'people' => [ { id => 243623, name => 'Amanda Reese', age => 23, car => { type => 'Honda', color => 'white', age => 3.5, }, }, { id => 2413, name => 'Harry Burns', age => 25, }, { name => 'Sally Allbright', car => [ undef, undef, 'Volvo' ], id => 882413, age => 24, }, ] }, { RaiseError => 0, validate => 1 }), ' 243623 Amanda Reese 23 white 3.5 Honda 2413 Harry Burns 25 882413 Sally Allbright 24 Volvo ', 'Checking serializing nonscalar data'); is($rayapp->errstr, undef, 'Checking that there was no error'); ok($dsd = $rayapp->load_dsd('person.xml'), 'Loading DSD with type personname'); is($rayapp->errstr, undef, 'Should be no errstr'); is($dsd->md5_hex, '5b29696f64657d411d1c13fe40669de3', 'Checking MD5'); is($dsd->out_content, ' <_personname> ', 'Checking content'); ok($dsd = $rayapp->load_dsd_string(' '), 'Loading DSD that uses typehref'); is($rayapp->errstr, undef, 'Should be no errstr'); is($dsd->md5_hex, '93048e118ad6af4ab53457d1fe283a63', 'Checking MD5'); is($dsd->out_content, ' ', 'Checking content'); is($dsd->serialize_data({ person => { id => 1, firstname => 'Amanda', lastname => 'Reese', }, car => { make => 'Jeep', year => 1962 }, }, { RaiseError => 0, validate => 1 }), ' Jeep 1962 1 Amanda Reese ', 'Checking serializing'); is($dsd->errstr, undef, 'No error message'); is($dsd->serialize_data({ person => [ 1, 'Amanda', undef, 'Reese' ], car => [ 'Jeep', 1962 ], }, { RaiseError => 0, validate => 1 }), ' Jeep 1962 1 Amanda Reese ', 'Checking serializing 2'); is($dsd->errstr, undef, 'No error expected'); ok($dsd = $rayapp->load_dsd('person1.xml'), 'Loading DSD that uses typehref, from file'); is($rayapp->errstr, undef, 'Should be no errstr'); is($dsd->md5_hex, '1054f4d6b855e175f823b5f6347979e3', 'Checking MD5'); is($dsd->out_content, ' ', 'Checking content'); is($dsd->serialize_data({ person => { id => 1, firstname => 'Amanda', lastname => 'Reese', }, car => { make => 'Jeep', year => 1962 }, }, { RaiseError => 0, validate => 1 }), ' Jeep 1962 1 Amanda Reese ', 'Checking serializing'); is($dsd->errstr, undef, 'Errstr should not be set'); is($dsd->serialize_data({ person => [ 42, 'Amanda', undef, 'Reese' ], car => [ 'Jeep', 1962 ], }, { RaiseError => 0, validate => 1 }), ' Jeep 1962 42 Amanda Reese ', 'Checking serializing'); is($dsd->errstr, undef, 'No errstr'); ok($dsd = $rayapp->load_dsd_string(' '), 'Load DSD with remote typeref'); is($rayapp->errstr, undef, 'Keep errstr silent'); is($dsd->md5_hex, 'f20cbc941b08b8498dd7906e57cd1192', 'Checking MD5'); is($dsd->out_content, ' ', 'Checking content'); is($dsd->serialize_data({ record => [ [ [ [ 13, 'Amanda', 'X.', 'Reese' ], 23 ], [ [ 'Volvo', 1980 ], [ 'Honda', 1990 ], ], ], undef, { person => { personname => [ 15, 'Sally', undef, 'Albright' ], age => 23, }, cars => [ { make => 'GMC', year => 1952, }, ], }, ], }, { RaiseError => 0, validate => 1 }), ' 13 Amanda X. Reese 23 Volvo 1980 Honda 1990 15 Sally Albright 23 GMC 1952 ', 'Checking serializing, lists and all'); is($dsd->errstr, undef, 'No errstr'); ok($dsd = $rayapp->load_dsd_string(' '), 'Loading DSD with CDATA specifications'); is($rayapp->errstr, undef, 'Should be not error'); is($dsd->md5_hex, '34d45a0fd87b715fb3a34ace820d0597', 'Checking MD5 of the DSD'); is($dsd->serialize_data({ 'text' => "hola\n']]>hoj<", 'text1' => "hola\n']]>hoj<", 'result' => -1 }, { RaiseError => 0, validate => 1 }), q# ']]]>hoj<]]> hola<b> ']]>hoj< -1 #, 'Serializing'); is($dsd->errstr, undef, 'Want no error message'); ok($dsd = $rayapp->load_dsd_string('

'), 'Loading DSD with root typeref leading to another remote typeref'); is($rayapp->errstr, undef, 'Should be not error'); is($dsd->md5_hex, '85f1e21edc3e61422cc157ec7f22612d', 'Checking MD5 of the DSD'); is($dsd->out_content, '

', 'Checking the content'); is($dsd->serialize_data({ 'p' => { num_of_children => 'sixteen', person => { id => '0987654321', firstname => 'Amanda', middlename => 'Carol', lastname => 'Reese', } } }, { RaiseError => 0, validate => 1 }), '

0987654321 Amanda Carol Reese sixteen

', 'Serializing'); is($dsd->errstr, undef, 'Errstr expected undef'); ok($dsd = $rayapp->load_dsd_string(' <_param name="a"/> <_param prefix="xxx:"/> '), 'Loading DSD with prefix parameter'); is($rayapp->errstr, undef, 'Should be not error'); is($dsd->uri, 'md5:c7c3b1f2a38c0ceae4dd8d1950c5a621', 'Checking URI/MD5 of the DSD'); is($dsd->out_content, ' ', 'Checking the structure'); is("@{[ sort keys %{ $dsd->params } ]}", "a", 'Checking parameter found'); is("@{[ sort keys %{ $dsd->param_prefixes } ]}", "xxx:", 'Checking parameter prefix found'); ok($dsd = $rayapp->load_dsd_string(' '), 'Loading correct DSD from string, with list data'); is($rayapp->errstr, undef, 'Checking that there was no error'); is($dsd->uri, 'md5:b417c682d4c94a80e42b97d48827c35b', 'Checking URI/MD5 of the DSD'); is($dsd->serialize_data({ 'output' => [ { person => [ 1234, 'Sally' ], result => 4321 }, [ [ 4567, 'Harry' ], 7654 ], { }, [ ], { person => [ 9876, 'Amanda' ], result => 6789 }, [ { name => 'Marie', id => 7777 } ], [ undef, 3645 ], { result => 3645 }, ] }, { RaiseError => 0, validate => 1 }), ' 1234 Sally 4321 4567 Harry 7654 9876 Amanda 6789 7777 Marie 3645 3645 ', 'Checking with various list data'); is($dsd->errstr, undef, 'Errstr should stay unset'); ok($dsd = $rayapp->load_dsd_string('

'), 'Loading correct DSD from string, with conditions'); is($rayapp->errstr, undef, 'Checking that there was no error'); is($dsd->uri, 'md5:dc455c5cc77fe48d8ab9fa2e896e024c', 'Checking URI/MD5 of the DSD'); is($dsd->serialize_data({ 'result' => 12, }, { RaiseError => 0, validate => 1 }), '

12

', 'Checking serialization with condition matched'); is($dsd->errstr, undef, 'Is errstr still cool?'); is($dsd->serialize_data({ 'result' => 12, 'name' => 16, }, { RaiseError => 0, validate => 1 }), '

12 16

', 'Checking another serialization with condition matched'); is($dsd->errstr, undef, 'Want errstr unset'); is($dsd->serialize_data({ 'name' => 16, }, { RaiseError => 0, validate => 1 }), ' ', 'Checking serialization with condition failed'); is($dsd->errstr, undef, 'No errstr'); ok($dsd = $rayapp->load_dsd_string('

<_data name="_data" /> <_data name="name" />

'), 'Loading correct DSD from string, with conditions and _data'); is($rayapp->errstr, undef, 'Checking that there was no error'); is($dsd->uri, 'md5:b91a94c07931932fb92d6416dc0a23ca', 'Checking URI/MD5 of the DSD'); is($dsd->serialize_data({ 'result' => 12, }, { RaiseError => 0, validate => 1 }), ' ', 'Checking serialization with condition failed'); is($dsd->errstr, undef, 'No errstr set'); is($dsd->serialize_data({ 'result' => 12, 'name' => 16, }, { RaiseError => 0, validate => 1 }), ' ', 'Checking another serialization with condition failed'); is($dsd->errstr, undef, 'Errstr should stay unset'); is($dsd->serialize_data({ '_data' => '_data', 'name' => 16, }, { RaiseError => 0, validate => 1 }), '

<_data>_data 16

', 'Checking serialization with condition matched'); is($dsd->errstr, undef, 'Errstr should stay unset'); ok($dsd = $rayapp->load_dsd_string('

'), 'Loading correct DSD with condition and deep structure'); is($rayapp->errstr, undef, 'Checking that there was no error'); is($dsd->uri, 'md5:73e48b24b6a1a1415c70a60979034eeb', 'Checking URI/MD5 of the DSD'); ok($dsd = $rayapp->load_dsd_string('

'), 'Loading correct DSD with conditions'); is($rayapp->errstr, undef, 'Checking that there was no error'); is($dsd->uri, 'md5:09840ed0c31fb6d6fce9164561cde959', 'Checking URI/MD5 of the DSD'); ok($dsd = $rayapp->load_dsd_string('

'), 'Loading correct DSD with conditions'); is($rayapp->errstr, undef, 'Checking that there was no error'); is($dsd->uri, 'md5:abd0a829b8cd322bc01a8d89becd5d94', 'Checking URI/MD5 of the DSD'); ok($dsd = $rayapp->load_dsd_string(' '), 'Loading correct DSD with simple simple list'); is($rayapp->errstr, undef, 'Checking that there was no error'); is($dsd->uri, 'md5:9d4ab423fe8144b08ed02745250528fc', 'Checking URI/MD5 of the DSD'); is($dsd->serialize_data({ 'a' => [ 1, "45", 45, "Amanda" ], }, { RaiseError => 0, validate => 1 }), ' 1 45 45 Amanda ', 'Checking serialization with simple simple list'); is($rayapp->errstr, undef, 'Checking no error message'); ok($dsd = $rayapp->load_dsd_string('

'), 'Loading correct DSD with condition about list'); is($rayapp->errstr, undef, 'Checking that there was no error'); is($dsd->uri, 'md5:70d800af3565547031ed2725556abdcd', 'Checking URI/MD5 of the DSD'); is($dsd->serialize_data({ 'a' => [ 1, "45", 45, "Amanda" ], }, { RaiseError => 0, validate => 1 }), '

1 45 45 Amanda

', 'Checking serialization with simple list'); is($rayapp->errstr, undef, 'Checking no error message'); is($dsd->serialize_data({ 'a' => [ ], }, { RaiseError => 0, validate => 1 }), ' ', 'Checking serialization with empty list'); is($rayapp->errstr, undef, 'Checking no error message'); is($dsd->serialize_data({ }, { RaiseError => 0, validate => 1 }), ' ', 'Checking serialization with undef list'); is($rayapp->errstr, undef, 'Checking no error message'); ok($dsd = $rayapp->load_dsd_string('

'), 'Loading correct DSD from string, with tst not being a top-level placeholder'); is($rayapp->errstr, undef, 'Checking that there was no error'); is($dsd->uri, 'md5:b8b0a12e2f020098493e04ba7c0bacca', 'Checking URI/MD5 of the DSD'); is($dsd->serialize_data({ 'result' => 12, }, { RaiseError => 0, validate => 1 }), ' ', 'Checking serialization with condition failed'); is($dsd->errstr, undef, 'No error expected'); is($dsd->serialize_data({ 'tst' => 23, }, { RaiseError => 0, validate => 1 }), '

', 'Checking serialization with condition failed'); is($dsd->errstr, undef, 'No error expected'); ok($dsd = $rayapp->load_dsd('example_findpeople.xml'), 'Loading correct DSD with findpeople example'); is($rayapp->errstr, undef, 'Checking that there was no error'); is($dsd->md5_hex, '4a0344ee86916145d7ed1ecc23fa2a93', 'Checking MD5'); like($dsd->uri, '/^file:.*t\/example_findpeople.xml$/', 'Checking URI'); is($dsd->out_content, ' ', 'Checking the content'); is($dsd->serialize_data( { 'people' => [ { 'id' => 25132, 'fullname' => 'Rebeca Milton', }, { 'id' => 63423, 'fullname' => 'Amanda Reese', 'affiliation' => [ [ 1323, 'Department of Medieval History' ], ], }, { 'id' => 1883, 'fullname' => "John O'Reilly", 'affiliation' => [ [ 2534, 'Department of Chemistry' ], [ 15, 'Microbiology Institute' ], ], }, ] }, { RaiseError => 0, validate => 1 } ), qq! 25132 Rebeca Milton 63423 Amanda Reese 1323 Department of Medieval History 1883 John O'Reilly 2534 Department of Chemistry 15 Microbiology Institute !, 'Checking serialization with list data'); is($dsd->errstr, undef, 'No errstr'); is($dsd->serialize_data( { 'id' => 1883, 'fullname' => "John O'Reilly", 'major_affiliation' => { 'id' => 2534, 'deptname' => 'Department of Chemistry', 'function' => 'Head of department', }, }, { RaiseError => 0, validate => 1 }), q! 1883 John O'Reilly 2534 Department of Chemistry Head of department !, 'Checking serialization with one person data'); is($dsd->errstr, undef, 'Check errstr'); is($dsd->serialize_data( {}, { RaiseError => 0, validate => 1 } ), ' ', 'Checking serialization with no data'); is($dsd->errstr, undef, 'Check error message'); ok($dsd = $rayapp->load_dsd_string(' '), 'Load DSD with typeref'); is($rayapp->errstr, undef, 'No errstr expected'); is($dsd->serialize_data({ 'a' => 56 }, { RaiseError => 0, validate => 1 }), ' 56 ', 'Serialize the data'); is($dsd->errstr, undef, 'No errstr expected for serialization'); is($dsd->serialize_data({ 'a' => 'x' }, { RaiseError => 0, validate => 1 }), ' ', 'Now, give it a string (where integer expected)'); is($dsd->errstr, "Value 'x' of {a} is not integer for data element defined at line 4", 'It should complain'); ok($dsd = $rayapp->load_dsd_string(' '), 'Loading DSD with hash and hashelements from string'); is($rayapp->errstr, undef, 'Checking that there was no error'); is($dsd->uri, 'md5:818e3c7acefa4a8a824d813722616669', 'Checking URI/MD5 of the DSD'); $out_content = <<'EOF'; EOF is($dsd->out_content, $out_content, 'Checking the current content'); is($dsd->serialize_data({ 'y' => { 'a' => 'ax', 'b' => 'bx', 'c' => 'cx', }, 'x' => { '46' => 46, '3.4' => 34, '16' => 16, }, 'w' => { -45 => [ 'Peter', 16, ], 'g' => [ 'John', 17 ], '-4.5' => { 'age' => 3, 'name' => 'Kate', }, }, 'v' => { -45 => [ 'Peter', 16, ], 'g' => [ 'John', 17 ], '-4.5' => { 'age' => 3, 'name' => 'Kate', }, }, }, { RaiseError => 0, validate => 1 }), ' Peter 16 Kate 3 John 17 Kate 3 Peter 16 John 17 34 16 46 ax bx cx ', 'Check multiple hash serialization'); is($dsd->errstr, undef, 'Expecting no error'); ok($dsd = $rayapp->load_dsd_string(' '), 'Loading DSD with hashes with natural order from string'); is($rayapp->errstr, undef, 'Checking that there was no error'); is($dsd->uri, 'md5:e457b01b94cecfcdb25b4e0abf3ca63f', 'Checking URI/MD5 of the DSD'); $out_content = <<'EOF'; EOF is($dsd->out_content, $out_content, 'Checking the current content'); like($dsd->serialize_data({ 'v' => { -1 => 1, -2 => 2 } }, { RaiseError => 0, validate => 1 }), '/^(<\?xml version="1.0"\?> \s*1<\\/v>\s*2<\\/v>\s*<\\/root>|<\?xml version="1.0"\?> \s*2<\\/v>\s*1<\\/v>\s*<\\/root>) $/', 'Check result serialization'); is($dsd->errstr, undef, 'Still no error'); ok($dsd = $rayapp->load_dsd_string(' '), 'Loading DSD with hashes with idattr'); is($rayapp->errstr, undef, 'Checking that there was no error'); is($dsd->uri, 'md5:05b830d5221596387afbf1f8a81bc4c7', 'Checking URI/MD5 of the DSD'); $out_content = <<'EOF'; EOF is($dsd->out_content, $out_content, 'Checking the current content'); is($dsd->serialize_data({ 'r' => { -1 => 1, -2 => 2 }, 'v' => { 'a' => 1, 'b' => 2 }, }, { RaiseError => 0, validate => 1 }), ' 2 1 1 2 ', 'Check serialization'); is($rayapp->errstr, undef, 'No error'); ok($dsd = $rayapp->load_dsd_string(' '), 'Loading DSD with hashes with conditions'); is($rayapp->errstr, undef, 'Checking that there was no error'); is($dsd->uri, 'md5:01676d650f6fdcf25fafc775a24446a5', 'Checking URI/MD5 of the DSD'); $out_content = <<'EOF'; EOF is($dsd->out_content, $out_content, 'Checking the current content'); is($dsd->serialize_data({ a => 1, ma => 9, b => 1, mb => 9, c => 1, mc => 9, d => 1, md => 9, }, { RaiseError => 0, validate => 1 }), ' 9 9 ', 'Check serialization with 1'); is($rayapp->errstr, undef, 'Checking that there was no error'); is($dsd->serialize_data({ a => undef, ma => 9, b => undef, mb => 9, c => undef, mc => 9, d => undef, md => 9, }, { RaiseError => 0, validate => 1 }), ' 9 9 ', 'Check serialization with undef'); is($rayapp->errstr, undef, 'Checking that there was no error'); is($dsd->serialize_data({ a => 0, ma => 9, b => 0, mb => 9, c => 0, mc => 9, d => 0, md => 9, }, { RaiseError => 0, validate => 1 }), ' 9 9 ', 'Check serialization with zero'); is($rayapp->errstr, undef, 'Checking that there was no error'); ok($dsd = $rayapp->load_dsd_string(' '), 'Loading DSD with hashes with namespaces'); is($rayapp->errstr, undef, 'Checking that there was no error'); is($dsd->uri, 'md5:170ef84d02264e6c7b0b8169365e31d5', 'Checking URI/MD5 of the DSD'); is($dsd->out_content, ' ', 'Checking the current content'); is($dsd->serialize_data({ 'html:b' => 'X', s => { mb => 34 }, }, { RaiseError => 0, validate => 1 }), ' X 34 ', 'Serialization with data with colons'); is($rayapp->errstr, undef, 'No error still?'); ok($dsd = $rayapp->load_dsd('create_domain.dsd'), 'Loading DSD for CZ-NIC create domain command'); is($rayapp->errstr, undef, 'Check errstr'); is($dsd->serialize_data({ 'dsdDomain:name' => 'asdf.cz', 'dsdDomain:description' => 'The ASDF is core of it all', 'dsdDomain:idadm' => 'ASDF', 'dsdDomain:idtech' => 'ASDF', 'dsdDomain:period' => 2, 'dsdDomain:nserver' => [ [ 'ns.asdf.cz', [ '111.111.111.111', '222.222.222.222' ], 'P' ], [ 'ns.server.cz', undef, 'S' ], ], 'clTRID' => 'Ticket-1', }, { RaiseError => 0, validate => 1 }), ' asdf.cz The ASDF is core of it all ASDF ASDF 2 ns.asdf.cz 111.111.111.111 222.222.222.222 P ns.server.cz S Ticket-1 ', 'Serialization with domain data'); is($rayapp->errstr, undef, 'No error still?'); ok($dsd = $rayapp->load_dsd('create_domain.dsd'), 'Loading DSD for CZ-NIC create domain command'); ok($dsd = $rayapp->load_uri('nonxml.xml'), 'Loading file which is not DSD and should not be processed as one'); is($rayapp->errstr, undef, 'Check errstr'); is($dsd->content, "This file is not XML.\n", 'Test the text content'); is(scalar keys %{ $rayapp->{uris} }, 37, 'Total number of distinct URIs processed'); ok($dsd = $rayapp->load_dsd('script1.dsd'), 'Loading correct DSD from string'); is($rayapp->errstr, undef, 'Checking that there was no error'); is($dsd->md5_hex, '113833fe853620287de9005698e3066a', 'Checking MD5 of the DSD'); like($dsd->application_name, '/t\/script1\.pl/', 'Checking application name'); my $appretval = $rayapp->execute_application_handler($dsd); ok($appretval, 'Executing the application -- checking true return value'); ok(ref $appretval, 'Executing the application -- checking that the return is a reference'); my $outxml = $dsd->serialize_data($appretval, { RaiseError => 0, validate => 1 }); is ($outxml, ' Peter Wolf Brian Fox Leslie Child Barbara Bailey Russell King Michael Johnson Michael Shell Tim Jasmine 1523 8234B Šílené laně ', 'Checking that the output values are correct by serializing'); is($dsd->errstr, undef, 'No errstr'); $outxml = $dsd->serialize_data_dom($appretval, { RaiseError => 0, validate => 1 }); ok($outxml, 'Checking that the serialization to DOM is also OK.'); is(ref $outxml, 'XML::LibXML::Document', 'Checking that the ref is correct.'); is($dsd->errstr, undef, 'No errstr?'); use XML::LibXSLT; my $xslt = new XML::LibXSLT; ok($xslt, 'Checking that the XML::LibXSLT parser was created OK.'); my $style = $xslt->parse_stylesheet_file('script1.xsl'); ok($style, 'Loading the t/script1.xsl stylesheet'); my $results = $style->transform($outxml); ok($results, 'Running transformation'); is($results->toString, ' </head><body><h1>A list of students</h1><p> Study program: <b>Šílené laně</b> (<tt>8234B</tt>) </p><ul> <li>Wolf Peter</li> <li>Fox Brian</li> <li>Child Leslie</li> <li>Bailey Barbara</li> <li>King Russell</li> <li>Johnson Michael</li> <li>Shell Michael</li> <li>Jasmine Tim</li> </ul></body></html> ', 'Checking the output HTML'); TODO: { todo_skip 'No Storable thingies', 5; $appretval = $rayapp->execute_application_process_storable($dsd); ok($appretval, 'Executing the application -- checking true return value'); ok(ref $appretval, 'Executing the application -- checking that the return is a reference'); $outxml = $dsd->serialize_data($appretval, { RaiseError => 0, validate => 1 }); is($outxml, '<?xml version="1.0" standalone="yes"?> <list> <students> <student> <lastname>Peter</lastname> <firstname>Wolf</firstname> </student> <student> <lastname>Brian</lastname> <firstname>Fox</firstname> </student> <student> <lastname>Leslie</lastname> <firstname>Child</firstname> </student> <student> <lastname>Barbara</lastname> <firstname>Bailey</firstname> </student> <student> <lastname>Russell</lastname> <firstname>King</firstname> </student> <student> <lastname>Michael</lastname> <firstname>Johnson</firstname> </student> <student> <lastname>Michael</lastname> <firstname>Shell</firstname> </student> <student> <lastname>Tim</lastname> <firstname>Jasmine</firstname> </student> </students> <program> <id>1523</id> <code>8234B</code> <name>Biology</name> </program> </list> ', 'Checking that the output values are correct by serializing'); is($dsd->errstr, undef, 'Check no error message appeared'); $outxml = $dsd->serialize_data_dom($appretval, { RaiseError => 0, validate => 1 }); ok($outxml, 'Checking that the serialization to DOM is also OK.'); is(ref $outxml, 'XML::LibXML::Document', 'Checking that the ref is correct.'); is($dsd->errstr, undef, 'Look at errstr'); $results = $style->transform($outxml); ok($results, 'Running transformation'); is($results->toString, '<?xml version="1.0" standalone="yes"?> <html><head><title/></head><body><h1>A list of students</h1><p> Study program: <b>Biology</b> (<tt>8234B</tt>) </p><ul> <li>Wolf Peter</li> <li>Fox Brian</li> <li>Child Leslie</li> <li>Bailey Barbara</li> <li>King Russell</li> <li>Johnson Michael</li> <li>Shell Michael</li> <li>Jasmine Tim</li> </ul></body></html> ', 'Checking the output HTML'); } $appretval = $rayapp->execute_application_handler_reuse($dsd); ok($appretval, 'Executing the application -- checking true return value'); ok(ref $appretval, 'Executing the application -- checking that the return is a reference'); $outxml = $dsd->serialize_data_dom($appretval, { RaiseError => 0, validate => 1 }); ok($outxml, 'Checking that the serialization to DOM is also OK.'); is(ref $outxml, 'XML::LibXML::Document', 'Checking that the ref is correct.'); is($dsd->errstr, undef, 'No errstr?'); $results = $style->transform($outxml); ok($results, 'Running transformation'); is(Encode::decode('utf-8', $results->toString), '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <html><head><title/></head><body><h1>A list of students</h1><p> Study program: <b>Šílené laně</b> (<tt>8234B</tt>) </p><ul> <li>Wolf Peter</li> <li>Fox Brian</li> <li>Child Leslie</li> <li>Bailey Barbara</li> <li>King Russell</li> <li>Johnson Michael</li> <li>Shell Michael</li> <li>Jasmine Tim</li> </ul></body></html> ', 'Checking the output HTML'); $appretval = $rayapp->execute_application_handler_reuse($dsd); ok($appretval, 'Executing the application -- checking true return value'); ok(ref $appretval, 'Executing the application -- checking that the return is a reference'); $outxml = $dsd->serialize_data_dom($appretval, { RaiseError => 0, validate => 1 }); ok($outxml, 'Checking that the serialization to DOM is also OK.'); is(ref $outxml, 'XML::LibXML::Document', 'Checking that the ref is correct.'); is($dsd->errstr, undef, 'Expected clear error message'); $results = $style->transform($outxml); ok($results, 'Running transformation'); is(Encode::decode('utf-8', $results->toString), '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <html><head><title/></head><body><h1>A list of students</h1><p> Study program: <b>Šílené laně</b> (<tt>8234B</tt>) </p><ul> <li>Wolf Peter</li> <li>Fox Brian</li> <li>Child Leslie</li> <li>Bailey Barbara</li> <li>King Russell</li> <li>Johnson Michael</li> <li>Shell Michael</li> <li>Jasmine Tim</li> </ul></body></html> ', 'Checking the output HTML'); my $out = $dsd->serialize_style( { program => [ 2534, 'X' ], students => [ [ 'A', 'B' ] ], }, {}, 'script1.xsl'); is($out, '<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>

A list of students

Study program: (X)

  • B A
', 'Serializing and styling'); is($dsd->errstr, undef, 'Check errstr'); =comment TODO: { local $TODO = 'rayapp_cgi_wrapper not ready for prime time yet'; $ENV{RAYAPP_DIRECTORY} = Cwd::getcwd(); if (${^TAINT}) { $^X =~ /^(.+)$/ and $^X = $1; delete @ENV{'PATH', 'ENV'}; } my $extout = `$^X ../../bin/rayapp_cgi_wrapper script2.xml`; is($extout, 'Pragma: no-cache Cache-control: no-cache Status: 200 Content-Type: text/xml; charset=UTF-8 Peter Wolf Brian Fox Leslie Child Barbara Bailey Russell King Michael Johnson Michael Shell Tim Jasmine 1523 8234B Šílené laně ', 'Running rayapp_cgi_wrapper'); $extout = `../../bin/rayapp_cgi_wrapper script2.xml`; is($extout, 'Pragma: no-cache Cache-control: no-cache Status: 200 Content-Type: text/xml Peter Wolf Brian Fox Leslie Child Barbara Bailey Russell King Michael Johnson Michael Shell Tim Jasmine 1523 8234B Šílené laně ', 'Running RayApp::CGI without stylesheets'); $ENV{RAYAPP_HTML_STYLESHEETS} = 'script1.xsl'; $extout = `../../bin/rayapp_cgi_wrapper script1.html`; utf8::encode($extout); is($extout, 'Pragma: no-cache Cache-control: no-cache Status: 200 Content-Type: text/html; charset=UTF-8

A list of students

Study program: Šílené laně (8234B)

  • Wolf Peter
  • Fox Brian
  • Child Leslie
  • Bailey Barbara
  • King Russell
  • Johnson Michael
  • Shell Michael
  • Jasmine Tim
', 'Running RayApp::CGI with implicit stylesheet'); $extout = `../../bin/rayapp_cgi_wrapper script2.html`; is($extout, 'Pragma: no-cache Cache-control: no-cache Status: 200 Content-Type: text/html; charset=UTF-8

A list of students

Study program: Šílené laně (8234B)

  • Wolf Peter
  • Fox Brian
  • Child Leslie
  • Bailey Barbara
  • King Russell
  • Johnson Michael
  • Shell Michael
  • Jasmine Tim
', 'Running RayApp::CGI with a stylesheet'); } =cut