casper-client 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/casper-client.gemspec +1 -1
- data/lib/casper-client.rb +14 -1
- data/spec/casper_client_spec.rb +40 -18
- data/spec/spec_helper.rb +1 -1
- metadata +1 -1
data/casper-client.gemspec
CHANGED
data/lib/casper-client.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'rest_client'
|
2
|
+
require 'json'
|
3
|
+
require 'base64'
|
2
4
|
|
3
5
|
module Casper
|
4
6
|
|
@@ -10,13 +12,24 @@ module Casper
|
|
10
12
|
options = {:host => 'http://casper.jrs-labs.com:8080'}.merge!(options)
|
11
13
|
report = Report.new
|
12
14
|
report.instance_eval(&block)
|
13
|
-
RestClient.post options[:host],
|
15
|
+
RestClient.post options[:host], report.to_json, :content_type => :json, :accept => :json
|
14
16
|
end
|
15
17
|
|
16
18
|
end
|
17
19
|
|
18
20
|
class Report
|
19
21
|
attr_accessor :xml, :template, :xpath
|
22
|
+
|
23
|
+
def to_json
|
24
|
+
{:casper =>
|
25
|
+
{
|
26
|
+
:jrxml => Base64.encode64(self.template.read),
|
27
|
+
:data => Base64.encode64((self.xml.kind_of? File) ? self.xml.read : xml),
|
28
|
+
:xpath => self.xpath
|
29
|
+
}
|
30
|
+
}.to_json
|
31
|
+
end
|
32
|
+
|
20
33
|
end
|
21
34
|
|
22
35
|
end
|
data/spec/casper_client_spec.rb
CHANGED
@@ -1,42 +1,64 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
2
|
|
3
3
|
describe Casper::Client do
|
4
|
-
|
5
|
-
TEMPLATE = open(File.join(File.dirname(__FILE__), 'data', 'report.jrxml'))
|
6
|
-
DATASET = open(File.join(File.dirname(__FILE__), 'data','dataset.xml'))
|
7
|
-
|
4
|
+
|
8
5
|
describe 'a basic flow of generation of a report' do
|
9
6
|
|
10
7
|
before(:each) do
|
11
8
|
RestClient.stub!(:post).and_return('report')
|
12
9
|
end
|
13
10
|
|
14
|
-
it 'should build the correct request to a report with a xml datasource' do
|
11
|
+
it 'should build the correct request to a report with a xml file as datasource' do
|
15
12
|
RestClient.should_receive(:post).with(
|
16
13
|
'http://casper.jrs-labs.com:8080',
|
17
|
-
{
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
{:casper =>
|
15
|
+
{
|
16
|
+
:jrxml => Base64.encode64(open(File.join(File.dirname(__FILE__),'data/report.jrxml')).read),
|
17
|
+
:data => Base64.encode64(open(File.join(File.dirname(__FILE__),'data/dataset.xml')).read),
|
18
|
+
:xpath => '//root'
|
19
|
+
}
|
20
|
+
}.to_json, :content_type => :json, :accept => :json
|
21
21
|
)
|
22
22
|
report = Casper::Client.build do |report|
|
23
|
-
report.
|
24
|
-
report.
|
23
|
+
report.template = open(File.join(File.dirname(__FILE__),'data/report.jrxml'))
|
24
|
+
report.xml = open(File.join(File.dirname(__FILE__),'data/dataset.xml'))
|
25
|
+
report.xpath = '//root'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should build the correct request to a report with a xml file as datasource with a optional host' do
|
30
|
+
RestClient.should_receive(:post).with(
|
31
|
+
'http://myserver',
|
32
|
+
{:casper =>
|
33
|
+
{
|
34
|
+
:jrxml => Base64.encode64(open(File.join(File.dirname(__FILE__),'data/report.jrxml')).read),
|
35
|
+
:data => Base64.encode64(open(File.join(File.dirname(__FILE__),'data/dataset.xml')).read),
|
36
|
+
:xpath => '//root'
|
37
|
+
}
|
38
|
+
}.to_json, :content_type => :json, :accept => :json
|
39
|
+
)
|
40
|
+
report = Casper::Client.build :host => 'http://myserver' do |report|
|
41
|
+
report.template = open(File.join(File.dirname(__FILE__),'data/report.jrxml'))
|
42
|
+
report.xml = open(File.join(File.dirname(__FILE__),'data/dataset.xml'))
|
25
43
|
report.xpath = '//root'
|
26
44
|
end
|
27
45
|
end
|
28
46
|
|
29
|
-
|
47
|
+
|
48
|
+
it 'should build the correct request to a report with a xml string as datasource' do
|
30
49
|
RestClient.should_receive(:post).with(
|
31
50
|
'http://mycasperserver.com',
|
32
|
-
{
|
33
|
-
|
34
|
-
|
35
|
-
|
51
|
+
{:casper =>
|
52
|
+
{
|
53
|
+
:jrxml => Base64.encode64(open(File.join(File.dirname(__FILE__),'data/report.jrxml')).read),
|
54
|
+
:data => Base64.encode64('<model/>'),
|
55
|
+
:xpath => '//root'
|
56
|
+
}
|
57
|
+
}.to_json, :content_type => :json, :accept => :json
|
36
58
|
)
|
37
59
|
report = Casper::Client.build :host => 'http://mycasperserver.com' do |report|
|
38
|
-
report.
|
39
|
-
report.
|
60
|
+
report.template = open(File.join(File.dirname(__FILE__),'data/report.jrxml'))
|
61
|
+
report.xml = '<model/>'
|
40
62
|
report.xpath = '//root'
|
41
63
|
end
|
42
64
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..','lib','
|
1
|
+
require File.join(File.dirname(__FILE__), '..','lib','casper-client')
|