spec/service_spec.rb in ruby_odata-0.1.3 vs spec/service_spec.rb in ruby_odata-0.1.4
- old
+ new
@@ -754,15 +754,159 @@
end
end
end
end
- describe "restful options" do
- it "should allow " do
+ describe "JSON serialization of objects" do
+ before(:each) do
+ # Required for the build_classes method
+ stub_request(:get, "http://blabla:@test.com/test.svc/$metadata").
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
+ to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/ms_system_center/edmx_ms_system_center.xml", __FILE__)), :headers => {})
+ stub_request(:get, "http://blabla:@test.com/test.svc/VirtualMachines").
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
+ to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/ms_system_center/virtual_machines.xml", __FILE__)), :headers => {})
+ svc = OData::Service.new "http://test.com/test.svc/", { :username => "blabla", :password=> "", :verify_ssl => false, :namespace => "VMM" }
+ svc.VirtualMachines
+ results = svc.execute
+ @json = results.first.as_json
+ end
+
+ it "Should quote Edm.Int64 properties" do
+ @json["PerfDiskBytesWrite"].should be_a(String)
end
+
+ it "Should output collections with metadata" do
+ @json["VMNetworkAssignments"].should be_a(Hash)
+ @json["VMNetworkAssignments"].should have_key("__metadata")
+ @json["VMNetworkAssignments"]["__metadata"].should be_a(Hash)
+ @json["VMNetworkAssignments"]["__metadata"].should have_key("type")
+ @json["VMNetworkAssignments"]["__metadata"]["type"].should eq("Collection(VMM.VMNetworkAssignment)")
+ @json["VMNetworkAssignments"].should have_key("results")
+ @json["VMNetworkAssignments"]["results"].should be_a(Array)
+ @json["VMNetworkAssignments"]["results"].should eq([])
+ end
end
+
+ describe "handling of Microsoft System Center 2012" do
+ before(:each) do
+ # Required for the build_classes method
+ stub_request(:get, "http://blabla:@test.com/test.svc/$metadata").
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
+ to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/ms_system_center/edmx_ms_system_center.xml", __FILE__)), :headers => {})
+
+ stub_request(:get, "http://blabla:@test.com/test.svc/VirtualMachines").
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
+ to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/ms_system_center/virtual_machines.xml", __FILE__)), :headers => {})
+
+ stub_request(:get, "http://blabla:@test.com/test.svc/HardwareProfiles?$filter=Memory%20eq%203500").
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
+ to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/ms_system_center/hardware_profiles.xml", __FILE__)), :headers => {})
+
+ stub_request(:get, "http://blabla:@test.com/test.svc/VMTemplates").
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
+ to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/ms_system_center/vm_templates.xml", __FILE__)), :headers => {})
+
+ end
+
+ it "should successfully parse null valued string properties" do
+ svc = OData::Service.new "http://test.com/test.svc/", { :username => "blabla", :password=> "", :verify_ssl => false, :namespace => "VMM" }
+ svc.VirtualMachines
+ results = svc.execute
+ results.first.should be_a_kind_of(VMM::VirtualMachine)
+ results.first.CostCenter.should be_nil
+ end
+
+ it "should successfully return a virtual machine" do
+ svc = OData::Service.new "http://test.com/test.svc/", { :username => "blabla", :password=> "", :verify_ssl => false, :namespace => "VMM" }
+ svc.VirtualMachines
+ results = svc.execute
+ results.first.should be_a_kind_of(VMM::VirtualMachine)
+ end
+
+ it "should successfully return a hardware profile for results that include a collection of complex types" do
+ svc = OData::Service.new "http://test.com/test.svc/", { :username => "blabla", :password=> "", :verify_ssl => false, :namespace => "VMM" }
+ svc.HardwareProfiles.filter("Memory eq 3500")
+ results = svc.execute
+ results.first.should be_a_kind_of(VMM::HardwareProfile)
+ end
+
+ it "should successfully return a collection of complex types" do
+ svc = OData::Service.new "http://test.com/test.svc/", { :username => "blabla", :password=> "", :verify_ssl => false, :namespace => "VMM" }
+ svc.HardwareProfiles.filter("Memory eq 3500")
+ results = svc.execute
+ granted_list = results.first.GrantedToList
+ granted_list.should be_a_kind_of(Array)
+ granted_list.first.should be_a_kind_of(VMM::UserAndRole)
+ granted_list.first.RoleName.should == "Important Tenant"
+ end
+
+
+ it "should successfully return results that include a collection of Edm types" do
+ svc = OData::Service.new "http://test.com/test.svc/", { :username => "blabla", :password=> "", :verify_ssl => false, :namespace => "VMM" }
+ svc.VMTemplates
+ results = svc.execute
+ results.first.should be_a_kind_of(VMM::VMTemplate)
+ end
+
+ it "should successfully return a collection of Edm types" do
+ svc = OData::Service.new "http://test.com/test.svc/", { :username => "blabla", :password=> "", :verify_ssl => false, :namespace => "VMM" }
+ svc.VMTemplates
+ results = svc.execute
+ boot_order = results.first.BootOrder
+ boot_order.should be_a_kind_of(Array)
+ boot_order.first.should be_a_kind_of(String)
+ boot_order.should eq ['CD', 'IdeHardDrive', 'PxeBoot', 'Floppy']
+ end
+ end
+
+ describe "handling of nested expands" do
+ before(:each) do
+ stub_request(:get, "http://test.com/test.svc/$metadata").
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
+ to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/nested_expands/edmx_northwind.xml", __FILE__)), :headers => {})
+
+ stub_request(:get, "http://test.com/test.svc/Products?$expand=Category,Category/Products&$top=2").
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
+ to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/nested_expands/northwind_products_category_expands.xml", __FILE__)), :headers => {})
+ end
+
+ it "should successfully parse the results" do
+ svc = OData::Service.new "http://test.com/test.svc", { :namespace => "NW" }
+ svc.Products.expand('Category').expand('Category/Products').top(2)
+ lambda { svc.execute }.should_not raise_exception
+ end
+
+ it "should successfully parse a Category as a Category" do
+ svc = OData::Service.new "http://test.com/test.svc", { :namespace => "NW" }
+ svc.Products.expand('Category').expand('Category/Products').top(2)
+ products = svc.execute
+ products.first.Category.should be_a_kind_of(NW::Category)
+ end
+
+ it "should successfully parse the Category properties" do
+ svc = OData::Service.new "http://test.com/test.svc", { :namespace => "NW" }
+ svc.Products.expand('Category').expand('Category/Products').top(2)
+ products = svc.execute
+ products.first.Category.CategoryID.should eq 1
+ end
+
+ it "should successfully parse the Category children Products" do
+ svc = OData::Service.new "http://test.com/test.svc", { :namespace => "NW" }
+ svc.Products.expand('Category').expand('Category/Products').top(2)
+ products = svc.execute
+ products.first.Category.Products.length.should eq 12
+ end
+
+ it "should successfully parse the Category's child Product properties" do
+ svc = OData::Service.new "http://test.com/test.svc", { :namespace => "NW" }
+ svc.Products.expand('Category').expand('Category/Products').top(2)
+ products = svc.execute
+ products.first.Category.Products.first.ProductName.should eq "Chai"
+ end
+ end
end
describe_private OData::Service do
describe "parse value" do
before(:each) do
@@ -774,10 +918,10 @@
it "should not error on an 'out of range' date" do
# This date was returned in the Netflix OData service and failed with an ArgumentError: out of range using 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32]
svc = OData::Service.new "http://test.com/test.svc/"
element_to_parse = Nokogiri::XML.parse('<d:AvailableFrom m:type="Edm.DateTime">2100-01-01T00:00:00</d:AvailableFrom>').elements[0]
- lambda { svc.parse_value(element_to_parse) }.should_not raise_exception
+ lambda { svc.parse_value_xml(element_to_parse) }.should_not raise_exception
end
end
end
end