forked from petdance/webservice-solr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequest-delete.t
53 lines (43 loc) · 1.12 KB
/
request-delete.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use strict;
use warnings;
use Test::More tests => 17;
use Test::Mock::LWP;
use XML::Simple;
use HTTP::Headers;
use WebService::Solr;
$Mock_ua->mock(
request => sub {
_test_req( @{ $_[ 1 ]->new_args } );
return HTTP::Response->new;
}
);
$Mock_response->mock( is_error => sub { return 0 } );
my $solr = WebService::Solr->new( undef, { autocommit => 0 } );
isa_ok( $solr, 'WebService::Solr' );
my $expect;
{
$expect = { id => 1234 };
$solr->delete_by_id( 1234 );
}
{
$expect = { query => 'name:DDR' };
$solr->delete_by_query( 'name:DDR' );
}
{
$expect = { query => 'foo', id => 13 };
$solr->delete( $expect );
}
{
$expect = { query => [ qw( foo bar ) ], id => [ 13, 42 ] };
$solr->delete( $expect );
}
sub _test_req {
is( $_[ 2 ]->path, '/solr/update', 'delete() path' );
is_deeply( { $_[ 2 ]->query_form }, { wt => 'json' }, 'delete() params' );
is( $_[ 3 ]->header( 'Content_Type' ),
'text/xml; charset=utf-8',
'delete() headers'
);
my $struct = XMLin( $_[ 4 ], KeepRoot => 1 );
is_deeply( $struct, { delete => $expect }, 'delete() xml' );
}