limelight 0.5.0-java → 0.5.1-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,86 +0,0 @@
1
- #- Copyright � 2008-2009 8th Light, Inc. All Rights Reserved.
2
- #- Limelight and all included source files are distributed under terms of the GNU LGPL.
3
-
4
- require 'rexml/document'
5
- require 'uri'
6
- require 'net/http'
7
-
8
- module Limelight
9
- module Client
10
-
11
- class Playbills
12
-
13
- def self.from_xml(xml, uri=nil)
14
- playbills = []
15
- doc = REXML::Document.new(xml)
16
- doc.root.each_element do |playbill_element|
17
- playbills << Playbill.from_element(playbill_element, uri)
18
- end
19
- return playbills
20
- end
21
-
22
- def self.from_url(url)
23
- uri = URI.parse(url)
24
- response = Net::HTTP.get_response(uri)
25
- return from_xml(response.body, uri)
26
- end
27
-
28
- end
29
-
30
- class Playbill
31
-
32
- def self.from_element(element, uri=nil)
33
- playbill = Playbill.new(uri)
34
- playbill.populate_from_element(element)
35
- return playbill
36
- end
37
-
38
- def populate_from_element(element)
39
- element.each_element do |element|
40
- name = element.name.gsub("-", "_")
41
- setter_sym = "#{name}=".to_sym
42
- self.send(setter_sym, coerce_value(element))
43
- end
44
- end
45
-
46
- attr_accessor :author, :created_at, :description, :id, :name, :size, :title, :updated_at, :version, :llp_path, :thumbnail_path
47
- attr_reader :uri
48
-
49
- def initialize(uri=nil)
50
- @uri = uri
51
- end
52
-
53
- def thumbnail
54
- return pull(thumbnail_path)
55
- end
56
-
57
- def llp
58
- return pull(llp_path)
59
- end
60
-
61
- private #############################################
62
-
63
- def coerce_value(element)
64
- value = element.text
65
- type_attribute = element.attribute("type")
66
- return value if type_attribute.nil?
67
- case type_attribute.value
68
- when "datetime"
69
- value = DateTime.parse(value)
70
- when "integer"
71
- value = value.to_i
72
- end
73
- return value
74
- end
75
-
76
- def pull(path)
77
- new_uri = uri.dup
78
- new_uri.path = path
79
- response = Net::HTTP.get_response(new_uri)
80
- return response.body
81
- end
82
-
83
- end
84
-
85
- end
86
- end
@@ -1,79 +0,0 @@
1
- #- Copyright � 2008-2009 8th Light, Inc. All Rights Reserved.
2
- #- Limelight and all included source files are distributed under terms of the GNU LGPL.
3
-
4
- require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
5
- require 'limelight/client/playbills'
6
-
7
- describe Limelight::Client::Playbills do
8
-
9
- before(:each) do
10
- @xml = <<END
11
- <?xml version="1.0" encoding="UTF-8"?>
12
- <playbills type="array">
13
- <playbill>
14
- <author>Jim Weirich and Micah Martin</author>
15
- <created-at type="datetime">2009-01-02T17:07:26Z</created-at>
16
- <description>The classic game of memory.</description>
17
- <id type="integer">1</id>
18
- <name>simon</name>
19
- <size>270418</size>
20
- <title>Limelight Simon</title>
21
- <updated-at type="datetime">2009-01-02T17:07:26Z</updated-at>
22
- <version>1.0</version>
23
- <llp-path>/playbills/1.llp</llp-path>
24
- <thumbnail-path>/playbills/1.thumbnail</thumbnail-path>
25
- </playbill>
26
- </playbills>
27
- END
28
-
29
- @response = mock("response")
30
- end
31
-
32
- it "should translate xml with 1 playbill" do
33
- playbills = Limelight::Client::Playbills.from_xml(@xml)
34
- playbills.length.should == 1
35
-
36
- simon = playbills[0]
37
- simon.name.should == "simon"
38
- simon.title.should == "Limelight Simon"
39
- simon.size.should == "270418"
40
- simon.updated_at.year.should == 2009
41
- simon.created_at.year.should == 2009
42
- simon.thumbnail_path.should == "/playbills/1.thumbnail"
43
- simon.llp_path.should == "/playbills/1.llp"
44
- simon.author.should == "Jim Weirich and Micah Martin"
45
- simon.description.should == "The classic game of memory."
46
- end
47
-
48
- it "should get all the playbills from a URL" do
49
- Net::HTTP.should_receive(:get_response).with(URI.parse("http://localhost:3000/playbills.xml")).and_return(@response)
50
- @response.should_receive(:body).and_return(@xml)
51
-
52
- playbills = Limelight::Client::Playbills.from_url("http://localhost:3000/playbills.xml")
53
-
54
- playbills.length.should == 1
55
- playbills[0].uri.host.should == "localhost"
56
- playbills[0].uri.port.should == 3000
57
- end
58
-
59
- it "should get the thumbnail for a playbill" do
60
- playbill = Limelight::Client::Playbill.new(URI.parse("http://localhost:3000/playbills.xml"))
61
- playbill.thumbnail_path = "/playbills/1.thumbnail"
62
-
63
- Net::HTTP.should_receive(:get_response).with(URI.parse("http://localhost:3000/playbills/1.thumbnail")).and_return(@response)
64
- @response.should_receive(:body).and_return("blah")
65
-
66
- playbill.thumbnail.should == "blah"
67
- end
68
-
69
- it "should get the thumbnail for a playbill" do
70
- playbill = Limelight::Client::Playbill.new(URI.parse("http://localhost:3000/playbills.xml"))
71
- playbill.llp_path = "/playbills/1.llp"
72
-
73
- Net::HTTP.should_receive(:get_response).with(URI.parse("http://localhost:3000/playbills/1.llp")).and_return(@response)
74
- @response.should_receive(:body).and_return("blah")
75
-
76
- playbill.llp.should == "blah"
77
- end
78
-
79
- end
@@ -1,157 +0,0 @@
1
- #- Copyright � 2008-2009 8th Light, Inc. All Rights Reserved.
2
- #- Limelight and all included source files are distributed under terms of the GNU LGPL.
3
-
4
- require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
5
- require 'limelight/studio'
6
-
7
- Studio = Limelight::Studio
8
-
9
- describe Limelight::Studio do
10
-
11
- class TestProduction
12
- attr_accessor :name
13
- end
14
-
15
- before do
16
- Studio.reset
17
- @production = TestProduction.new
18
- end
19
-
20
- it "should install itsself" do
21
- Studio.install
22
-
23
- Limelight::Context.instance.studio.should == Studio.instance
24
- end
25
-
26
- def prepare_for_open()
27
- @producer = mock("producer", :production => @production, :open => nil)
28
- Limelight::Producer.stub!(:new).and_return(@producer)
29
- end
30
-
31
- it "should keep track of productions opened" do
32
- prepare_for_open
33
- @production.name = "Sven"
34
- Studio.productions.length.should == 0
35
-
36
- Studio.open(@production)
37
-
38
- Studio.productions.length.should == 1
39
- Studio["Sven"].should be(@production)
40
- end
41
-
42
- it "should ask all the production if it's okay to close and not shutdown" do
43
- Studio.index(@production)
44
-
45
- @production.should_receive(:allow_close?).and_return(false)
46
- Studio.should_allow_shutdown.should == false
47
- end
48
-
49
- it "should ask all the production if it's okay to close and shutdown" do
50
- Studio.index(@production)
51
-
52
- @production.should_receive(:allow_close?).and_return(true)
53
- Studio.should_allow_shutdown.should == true
54
- end
55
-
56
- it "should removed productions that are closed" do
57
- production1 = TestProduction.new
58
- production2 = TestProduction.new
59
- Studio.index(production1)
60
- Studio.index(production2)
61
-
62
- Studio.production_closed(production1)
63
-
64
- Studio.productions.length.should == 1
65
- Studio.productions[0].should be(production2)
66
- end
67
-
68
- it "should shutdown if all the productions are closed" do
69
- prepare_for_open
70
- Studio.open("blah")
71
- Limelight::Context.instance().should_receive(:shutdown)
72
-
73
- Studio.production_closed(@production)
74
-
75
- sleep(0.1)
76
- end
77
-
78
- it "should add productions to the index" do
79
- @production.name = "Bob"
80
-
81
- Limelight::Studio.index(@production)
82
-
83
- Limelight::Studio["Bob"].should == @production
84
- end
85
-
86
- it "should give a production a name if it doesn't have one" do
87
- Limelight::Studio.index(@production)
88
-
89
- @production.name.should == "1"
90
- Limelight::Studio["1"].should == @production
91
-
92
- production2 = TestProduction.new
93
- Limelight::Studio.index(production2)
94
-
95
- production2.name.should == "2"
96
- Limelight::Studio["2"].should == production2
97
- end
98
-
99
- it "should modify the name of a production until it's unique" do
100
- prod1 = TestProduction.new
101
- prod2 = TestProduction.new
102
- prod3 = TestProduction.new
103
- prod1.name = prod2.name = prod3.name = "Fido"
104
-
105
- Studio.index(prod1)
106
- Studio.index(prod2)
107
- Studio.index(prod3)
108
-
109
- Studio["Fido"].should be(prod1)
110
- Studio["Fido_2"].should be(prod2)
111
- Studio["Fido_3"].should be(prod3)
112
- prod1.name.should == "Fido"
113
- prod2.name.should == "Fido_2"
114
- prod3.name.should == "Fido_3"
115
- end
116
-
117
- it "should shutdown" do
118
- Studio.index(@production)
119
- @production.should_receive(:allow_close?).and_return(true)
120
- @production.should_receive(:close).and_return(true)
121
- Limelight::Context.instance().should_receive(:shutdown)
122
-
123
- Studio.shutdown
124
- sleep(0.1)
125
- end
126
-
127
- it "should publish on drb" do
128
- Studio.publish_on_drb("9876")
129
-
130
- DRb.start_service
131
- proxy = DRbObject.new(nil, "druby://127.0.0.1:9876")
132
- proxy.instance.should_not == nil
133
- end
134
-
135
- it "should provide the utilities production" do
136
- Studio.utilities_production.should_not == nil
137
- Studio.utilities_production.name.should == "utilities_production"
138
- Studio.utilities_production.should be(Studio.utilities_production)
139
- # Studio.utilities_production.close
140
- end
141
-
142
- it "should give the same buildin_styles hash twice" do
143
- Studio.builtin_styles.should be(Studio.builtin_styles)
144
- Studio.builtin_styles["limelight_builtin_players_curtains"].should_not == nil
145
- end
146
-
147
- it "should show alert and shutdown if first production fails to open" do
148
- utilities = mock("utilities")
149
- utilities.should_receive(:alert)
150
- Studio.should_receive(:utilities_production).and_return(utilities)
151
- Limelight::Context.instance().should_receive(:shutdown)
152
-
153
- Studio.open("http://blah.blah:1234/blah.llp") # will fail
154
- sleep(0.1)
155
- end
156
-
157
- end