Skip to content

Commit

Permalink
Add more tests for the changes made for BBB 0.81
Browse files Browse the repository at this point in the history
The only missing tests now are for BigBlueButton::BigBlueButtonConfigXml.

refs #1129
  • Loading branch information
daronco committed May 11, 2014
1 parent 51e78de commit ca5b47e
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lib/bigbluebutton_config_layout.rb
Expand Up @@ -24,8 +24,13 @@ class BigBlueButtonConfigLayout
# xml (string):: The XML that has the definition of all layouts, usually fetched from
# the web conference server.
def initialize(xml)
@xml = nil
opts = { 'ForceArray' => false, 'KeepRoot' => true }
@xml = XmlSimple.xml_in(xml, opts)
begin
@xml = XmlSimple.xml_in(xml, opts)
rescue Exception => e
raise BigBlueButton::BigBlueButtonException.new("Error parsing the layouts XML. Error: #{e.message}")
end
end

# Returns an array with the name of each layout available in the XML.
Expand All @@ -43,7 +48,7 @@ def get_available_layouts
protected

def xml_has_layouts
@xml["layouts"] and @xml["layouts"]["layout"]
@xml and @xml["layouts"] and @xml["layouts"]["layout"]
end

end
Expand Down
4 changes: 3 additions & 1 deletion lib/bigbluebutton_config_xml.rb
Expand Up @@ -78,7 +78,9 @@ def is_modified?

def find_module(module_name)
if xml_has_modules
@xml["config"]["modules"]["module"].each do |mod|
modules = @xml["config"]["modules"]["module"]
modules = [modules] unless modules.is_a?(Array)
modules.each do |mod|
if mod["name"] == module_name
return mod
end
Expand Down
66 changes: 66 additions & 0 deletions spec/bigbluebutton_api_0.81_spec.rb
Expand Up @@ -85,4 +85,70 @@
end
end

describe "#get_available_layouts" do
let(:config_xml) { # a simplified config.xml file
"<config>
<modules>
<module name=\"LayoutModule\" url=\"http://test-server.org/client/LayoutModule.swf?v=4357\"
uri=\"rtmp://test-server.org/bigbluebutton\"
layoutConfig=\"http://test-server.org/client/conf/layout.xml\"
enableEdit=\"false\"/>
</modules>
</config>"
}
let(:layouts_xml) { # a simplified layouts.xml file
"<layouts>
<layout name=\"Default\" default=\"true\">
<window name=\"NotesWindow\" hidden=\"true\" width=\"0.7\" height=\"1\" x=\"0\" y=\"0\" draggable=\"false\" resizable=\"false\"/>
</layout>
<layout name=\"Video Chat\">
<window name=\"NotesWindow\" hidden=\"true\" width=\"0.7\" height=\"1\" x=\"0\" y=\"0\" draggable=\"false\" resizable=\"false\"/>
</layout>
</layouts>"
}

context "when an XML is passed" do
before {
response = double("Net::HTTPResponse")
response.stub(:body).and_return(layouts_xml)
api.should_receive(:send_request)
.with("http://test-server.org/client/conf/layout.xml")
.and_return(response)
}
subject { api.get_available_layouts(config_xml) }
it { should be_instance_of(Array) }
it { subject.count.should be(2) }
it { should include("Default") }
it { should include("Video Chat") }
end

context "when no XML is passed" do
before {
api.should_receive(:get_default_config_xml)
.and_return(config_xml)
response = double("Net::HTTPResponse")
response.stub(:body).and_return(layouts_xml)
api.should_receive(:send_request)
.with("http://test-server.org/client/conf/layout.xml")
.and_return(response)
}
subject { api.get_available_layouts }
it { should be_instance_of(Array) }
it { subject.count.should be(2) }
it { should include("Default") }
it { should include("Video Chat") }
end
end

describe "#get_default_layouts" do
subject { api.get_default_layouts }
it { should be_instance_of(Array) }
it { should include("Default") }
it { should include("Video Chat") }
it { should include("Meeting") }
it { should include("Webinar") }
it { should include("Lecture assistant") }
it { should include("Lecture") }
end

end
86 changes: 86 additions & 0 deletions spec/bigbluebutton_config_layout_spec.rb
@@ -0,0 +1,86 @@
require 'spec_helper'

describe BigBlueButton::BigBlueButtonConfigLayout do

let(:default_xml) { # a simplified layouts.xml file
"<layouts>
<layout name=\"Default\" default=\"true\">
<window name=\"NotesWindow\" hidden=\"true\" width=\"0.7\" height=\"1\" x=\"0\" y=\"0\" draggable=\"false\" resizable=\"false\"/>
</layout>
<layout name=\"Video Chat\">
<window name=\"NotesWindow\" hidden=\"true\" width=\"0.7\" height=\"1\" x=\"0\" y=\"0\" draggable=\"false\" resizable=\"false\"/>
</layout>
</layouts>"
}

describe "#initialize" do
context "with a valid xml" do
before {
XmlSimple.should_receive(:xml_in)
.with(default_xml, { 'ForceArray' => false, 'KeepRoot' => true })
.and_return("internal_xml")
}
subject { BigBlueButton::BigBlueButtonConfigLayout.new(default_xml) }
it("creates and stores a correct internal xml") { subject.xml.should eql("internal_xml") }
end

context "with an empty string as xml" do
it "throws an exception" do
expect {
BigBlueButton::BigBlueButtonConfigLayout.new("")
}.to raise_error(BigBlueButton::BigBlueButtonException)
end
end

context "throws any exception thrown by XmlSimple" do
before {
XmlSimple.should_receive(:xml_in) { raise Exception }
}
it {
expect {
BigBlueButton::BigBlueButtonConfigLayout.new(default_xml)
}.to raise_error(BigBlueButton::BigBlueButtonException)
}
end
end

describe "#get_available_layouts" do
subject { target.get_available_layouts }

context "returns nil if the xml has no <layouts>" do
let(:target) { BigBlueButton::BigBlueButtonConfigLayout.new("<test></test>") }
it { should be_nil }
end

context "returns nil if the xml has no <layouts><layout>" do
let(:target) { BigBlueButton::BigBlueButtonConfigLayout.new("<layouts></layouts>") }
it { should be_nil }
end

context "returns the correct available layout names" do
let(:target) { BigBlueButton::BigBlueButtonConfigLayout.new(default_xml) }
it { should be_instance_of(Array) }
it { subject.count.should be(2) }
it { should include("Default") }
it { should include("Video Chat") }
end

context "doesn't return duplicated layouts" do
let(:layouts_xml) {
"<layouts>
<layout name=\"Default\" default=\"true\">
<window name=\"NotesWindow\" hidden=\"true\" width=\"0.7\" height=\"1\" x=\"0\" y=\"0\" draggable=\"false\" resizable=\"false\"/>
</layout>
<layout name=\"Default\">
<window name=\"NotesWindow\" hidden=\"true\" width=\"0.7\" height=\"1\" x=\"0\" y=\"0\" draggable=\"false\" resizable=\"false\"/>
</layout>
</layouts>"
}
let(:target) { BigBlueButton::BigBlueButtonConfigLayout.new(layouts_xml) }
it { should be_instance_of(Array) }
it { subject.count.should be(1) }
it { should include("Default") }
end
end

end

0 comments on commit ca5b47e

Please sign in to comment.