1use strict;
2use warnings;
3use Test::More qw( no_plan );
4use SRU::Utils::XMLTest;
5
6use_ok( 'SRU::Request' );
7use_ok( 'SRU::Response' );
8use_ok( 'SRU::Response::Term' );
9
10MISSING_VERSION: {
11    my $url = 'http://myserver.com/myurl?operation=scan&scanClause=%2fdc.title%3d%22cat%22&responsePosition=3&maximumTerms=50&stylesheet=http://myserver.com/myStyle';
12    my $request = SRU::Request->newFromURI( $url );
13    isa_ok( $request, 'SRU::Request::Scan' );
14
15    my $response = SRU::Response->newFromRequest( $request );
16    isa_ok( $response, 'SRU::Response::Scan' );
17    is( $response->type(), 'scan', 'type()' );
18
19    my $diags = $response->diagnostics();
20    is( @$diags, 1, 'got one diagnostic' );
21
22    is( $diags->[0]->details(), 'version', 'got expected error' );
23}
24
25OK: {
26    my $url = 'http://myserver.com/myurl/?operation=scan&version=1.1&scanClause=%2fdc.title%3d%22cat%22&responsePosition=3&maximumTerms=50&stylesheet=http://myserver.com/myStyle';
27
28    my $request = SRU::Request->newFromURI( $url );
29    isa_ok( $request, 'SRU::Request::Scan' );
30
31    my $response = SRU::Response->newFromRequest( $request );
32    isa_ok( $response, 'SRU::Response::Scan' );
33
34    my $diags = $response->diagnostics();
35    is( @$diags, 0, 'no diagnostic messages' );
36
37    ## add a few terms to the response
38    $response->addTerm( SRU::Response::Term->new( value => 'Apollo Creed' ) );
39    $response->addTerm( SRU::Response::Term->new( value => 'Rocky Balboa' ) );
40
41    ## check the xml
42    my $xml = $response->asXML();
43    ok( wellFormedXML( $xml ), 'asXML() well formed XML' );
44
45    ## rudimentary check for the terms
46    like( $xml, qr{<value>Apollo Creed</value>}, 'found term 1' );
47    like( $xml, qr{<value>Rocky Balboa</value>}, 'found term 2' );
48
49    like( $xml, qr{\Q<?xml-stylesheet type='text/xsl' href="http://myserver.com/myStyle" ?>\E}, 'found stylsheet in XML' );
50}
51