amee 2.6.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. data/Gemfile +18 -0
  2. data/README +2 -2
  3. data/Rakefile +31 -0
  4. data/VERSION +1 -0
  5. data/amee-ruby.gemspec +147 -0
  6. data/examples/view_profile_item.rb +32 -0
  7. data/lib/amee.rb +0 -1
  8. data/lib/amee/profile_item.rb +27 -6
  9. data/spec/amee_spec.rb +25 -0
  10. data/spec/cache_spec.rb +152 -0
  11. data/spec/connection_spec.rb +295 -0
  12. data/spec/data_category_spec.rb +259 -0
  13. data/spec/data_item_spec.rb +224 -0
  14. data/spec/data_item_value_history_spec.rb +311 -0
  15. data/spec/data_item_value_spec.rb +231 -0
  16. data/spec/data_object_spec.rb +9 -0
  17. data/spec/drill_down_spec.rb +163 -0
  18. data/spec/fixtures/AD63A83B4D41.json +1 -0
  19. data/spec/fixtures/AD63A83B4D41.xml +1 -0
  20. data/spec/fixtures/create_item.json +1 -0
  21. data/spec/fixtures/create_item.xml +1 -0
  22. data/spec/fixtures/data.json +1 -0
  23. data/spec/fixtures/data.xml +1 -0
  24. data/spec/fixtures/data_home_energy_quantity.xml +146 -0
  25. data/spec/fixtures/data_home_energy_quantity_biodiesel.xml +177 -0
  26. data/spec/fixtures/data_transport_car_generic_drill_fuel_diesel.xml +33 -0
  27. data/spec/fixtures/empty.json +1 -0
  28. data/spec/fixtures/empty.xml +1 -0
  29. data/spec/fixtures/parse_test.xml +22 -0
  30. data/spec/fixtures/v0_data_transport_transport_drill_transportType_Car1.xml +20 -0
  31. data/spec/item_definition_spec.rb +313 -0
  32. data/spec/item_value_definition_spec.rb +253 -0
  33. data/spec/logger_spec.rb +16 -0
  34. data/spec/object_spec.rb +44 -0
  35. data/spec/parse_helper_spec.rb +72 -0
  36. data/spec/profile_category_spec.rb +565 -0
  37. data/spec/profile_item_spec.rb +451 -0
  38. data/spec/profile_item_value_spec.rb +196 -0
  39. data/spec/profile_object_spec.rb +24 -0
  40. data/spec/profile_spec.rb +88 -0
  41. data/spec/rails_spec.rb +48 -0
  42. data/spec/spec.opts +2 -0
  43. data/spec/spec_helper.rb +56 -0
  44. data/spec/user_spec.rb +249 -0
  45. metadata +189 -55
  46. data/lib/amee/version.rb +0 -10
@@ -0,0 +1,253 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe AMEE::Admin::ItemValueDefinition do
4
+
5
+ before(:each) do
6
+ @item_definition = AMEE::Admin::ItemValueDefinition.new
7
+ end
8
+
9
+ it "should have common AMEE object properties" do
10
+ @item_definition.is_a?(AMEE::Object).should be_true
11
+ end
12
+
13
+ it "should have a name" do
14
+ @item_definition.should respond_to(:name)
15
+ end
16
+
17
+ it "should initialize AMEE::Object data on creation" do
18
+ uid = 'ABCD1234'
19
+ @item_definition = AMEE::Admin::ItemValueDefinition.new(:uid => uid)
20
+ @item_definition.uid.should == uid
21
+ end
22
+
23
+ it "can be created with hash of data" do
24
+ name = "test"
25
+ @item_definition = AMEE::Admin::ItemValueDefinition.new(:name => name)
26
+ @item_definition.name.should == name
27
+ end
28
+
29
+ end
30
+
31
+ describe AMEE::Admin::ItemValueDefinitionList, "with an authenticated connection" do
32
+ it "should parse XML correctly" do
33
+ connection = flexmock "connection"
34
+ connection.should_receive(:retries).and_return(0).once
35
+ connection.should_receive(:get).with("/definitions/itemDefinitions/BD88D30D1214/itemValueDefinitions", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8" standalone="no"?><Resources><ItemValueDefinitionsResource><Environment uid="5F5887BCF726"/><ItemDefinition uid="BD88D30D1214"/><ItemValueDefinitions><ItemValueDefinition uid="A8A212610A57"><Path>distancePerJourney</Path><Name>Distance per journey</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>km</Unit><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="D2AB505D2D91"><Path>type</Path><Name>Type</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>false</FromProfile><FromData>true</FromData><DrillDown>true</DrillDown></ItemValueDefinition><ItemValueDefinition uid="41EC337E5C79"><Path>numberOfJourneys</Path><Name>Number of journeys</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="9BAFC976044B"><Path>source</Path><Name>Source</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>false</FromProfile><FromData>true</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="9813267B616E"><Path>country</Path><Name>Country</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="263DE76AF8AA"><Path>kgCO2PerPassengerKmIE</Path><Name>kgCO2 Per Passenger Km IE</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="996AE5477B3F"><Name>kgCO2PerKm</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>false</FromProfile><FromData>true</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="F5550D71085F"><Path>kgCO2PerKmPassenger</Path><Name>kgCO2 Per Passenger Km</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="996AE5477B3F"><Name>kgCO2PerKm</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>false</FromProfile><FromData>true</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="FE166C7602BB"><Path>typicalJourneyDistance</Path><Name>Typical journey distance</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>false</FromProfile><FromData>true</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="2F76AB4E3C0F"><Path>journeyFrequency</Path><Name>Journey frequency</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="B0F02E544603"><Path>numberOfPassengers</Path><Name>Number of passengers</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="28D0B8C4F52A"><Path>useTypicalDistance</Path><Name>Use typical distance</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="6334117D28A0"><Path>distanceKmPerMonth</Path><Name>Distance Km Per Month</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="B691497F1CF2"><Name>kM</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>km</Unit><PerUnit>month</PerUnit><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="98EA75911467"><Path>distancePerJourney</Path><Name>Distance per journey</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>km</Unit><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="584BEA802996"><Path>isReturn</Path><Name>Is return</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="6CBF739E12F0"><Path>distance</Path><Name>Distance</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>km</Unit><PerUnit>year</PerUnit><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition></ItemValueDefinitions></ItemValueDefinitionsResource></Resources>'))
36
+ @data = AMEE::Admin::ItemValueDefinitionList.new(connection,"BD88D30D1214")
37
+ @data.length.should==15
38
+ @data.first.uid.should=='A8A212610A57'
39
+ @data.first.name.should == "Distance per journey"
40
+ @data.first.path.should == "distancePerJourney"
41
+ @data.first.unit.should == "km"
42
+ @data.first.perunit.should == nil
43
+ @data.first.profile?.should == true
44
+ @data.first.drill?.should == false
45
+ @data.first.data?.should == false
46
+ end
47
+
48
+ it "should apply block filter correctly" do
49
+ connection = flexmock "connection"
50
+ connection.should_receive(:retries).and_return(0).once
51
+ connection.should_receive(:get).with("/definitions/itemDefinitions/BD88D30D1214/itemValueDefinitions", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8" standalone="no"?><Resources><ItemValueDefinitionsResource><Environment uid="5F5887BCF726"/><ItemDefinition uid="BD88D30D1214"/><ItemValueDefinitions><ItemValueDefinition uid="A8A212610A57"><Path>distancePerJourney</Path><Name>Distance per journey</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>km</Unit><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="D2AB505D2D91"><Path>type</Path><Name>Type</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>false</FromProfile><FromData>true</FromData><DrillDown>true</DrillDown></ItemValueDefinition><ItemValueDefinition uid="41EC337E5C79"><Path>numberOfJourneys</Path><Name>Number of journeys</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="9BAFC976044B"><Path>source</Path><Name>Source</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>false</FromProfile><FromData>true</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="9813267B616E"><Path>country</Path><Name>Country</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="263DE76AF8AA"><Path>kgCO2PerPassengerKmIE</Path><Name>kgCO2 Per Passenger Km IE</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="996AE5477B3F"><Name>kgCO2PerKm</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>false</FromProfile><FromData>true</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="F5550D71085F"><Path>kgCO2PerKmPassenger</Path><Name>kgCO2 Per Passenger Km</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="996AE5477B3F"><Name>kgCO2PerKm</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>false</FromProfile><FromData>true</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="FE166C7602BB"><Path>typicalJourneyDistance</Path><Name>Typical journey distance</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>false</FromProfile><FromData>true</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="2F76AB4E3C0F"><Path>journeyFrequency</Path><Name>Journey frequency</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="B0F02E544603"><Path>numberOfPassengers</Path><Name>Number of passengers</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="28D0B8C4F52A"><Path>useTypicalDistance</Path><Name>Use typical distance</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="6334117D28A0"><Path>distanceKmPerMonth</Path><Name>Distance Km Per Month</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="B691497F1CF2"><Name>kM</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>km</Unit><PerUnit>month</PerUnit><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="98EA75911467"><Path>distancePerJourney</Path><Name>Distance per journey</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>km</Unit><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="584BEA802996"><Path>isReturn</Path><Name>Is return</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="6CBF739E12F0"><Path>distance</Path><Name>Distance</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>km</Unit><PerUnit>year</PerUnit><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition></ItemValueDefinitions></ItemValueDefinitionsResource></Resources>'))
52
+ @data = AMEE::Admin::ItemValueDefinitionList.new(connection,"BD88D30D1214") do |x|
53
+ x.uid == 'A8A212610A57' ? x.uid : nil
54
+ end
55
+ @data.length.should==1
56
+ @data.first.should=='A8A212610A57'
57
+ end
58
+
59
+ it "should parse JSON correctly" do
60
+ connection = flexmock "connection"
61
+ connection.should_receive(:retries).and_return(0).once
62
+ connection.should_receive(:get).with("/definitions/itemDefinitions/BD88D30D1214/itemValueDefinitions", {}).and_return(flexmock(:body => '{"environment":{"uid":"5F5887BCF726"},"itemValueDefinitions":[{"uid":"A8A212610A57","unit":"km","name":"Distance per journey","fromData":false,"path":"distancePerJourney","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 09:30:44.0"},"drillDown":false},{"uid":"D2AB505D2D91","name":"Type","fromData":true,"path":"type","fromProfile":false,"valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 09:30:44.0"},"drillDown":true},{"uid":"41EC337E5C79","name":"Number of journeys","fromData":false,"path":"numberOfJourneys","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 09:30:44.0"},"drillDown":false},{"uid":"9BAFC976044B","name":"Source","fromData":true,"path":"source","fromProfile":false,"valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 09:30:44.0"},"drillDown":false},{"uid":"9813267B616E","name":"Country","fromData":false,"path":"country","fromProfile":true,"valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 09:30:44.0"},"drillDown":false},{"uid":"263DE76AF8AA","name":"kgCO2 Per Passenger Km IE","fromData":true,"path":"kgCO2PerPassengerKmIE","fromProfile":false,"valueDefinition":{"uid":"996AE5477B3F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"kgCO2PerKm","valueType":"DECIMAL","modified":"2007-07-27 09:30:44.0"},"drillDown":false},{"uid":"F5550D71085F","name":"kgCO2 Per Passenger Km","fromData":true,"path":"kgCO2PerKmPassenger","fromProfile":false,"valueDefinition":{"uid":"996AE5477B3F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"kgCO2PerKm","valueType":"DECIMAL","modified":"2007-07-27 09:30:44.0"},"drillDown":false},{"uid":"FE166C7602BB","name":"Typical journey distance","fromData":true,"path":"typicalJourneyDistance","fromProfile":false,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 09:30:44.0"},"drillDown":false},{"uid":"2F76AB4E3C0F","name":"Journey frequency","fromData":false,"path":"journeyFrequency","fromProfile":true,"valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 09:30:44.0"},"drillDown":false},{"uid":"B0F02E544603","name":"Number of passengers","fromData":false,"path":"numberOfPassengers","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 09:30:44.0"},"drillDown":false},{"uid":"28D0B8C4F52A","name":"Use typical distance","fromData":false,"path":"useTypicalDistance","fromProfile":true,"valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 09:30:44.0"},"drillDown":false},{"perUnit":"month","uid":"6334117D28A0","unit":"km","name":"Distance Km Per Month","fromData":false,"path":"distanceKmPerMonth","fromProfile":true,"valueDefinition":{"uid":"B691497F1CF2","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"kM","valueType":"DECIMAL","modified":"2007-07-27 09:30:44.0"},"drillDown":false},{"uid":"98EA75911467","unit":"km","name":"Distance per journey","fromData":false,"path":"distancePerJourney","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 09:30:44.0"},"drillDown":false},{"uid":"584BEA802996","name":"Is return","fromData":false,"path":"isReturn","fromProfile":true,"valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 09:30:44.0"},"drillDown":false},{"perUnit":"year","uid":"6CBF739E12F0","unit":"km","name":"Distance","fromData":false,"path":"distance","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 09:30:44.0"},"drillDown":false}],"itemDefinition":{"uid":"BD88D30D1214"}}'))
63
+ @data = AMEE::Admin::ItemValueDefinitionList.new(connection,"BD88D30D1214")
64
+ @data.length.should==15
65
+ @data.first.uid.should=='A8A212610A57'
66
+ @data.first.name.should == "Distance per journey"
67
+ @data.first.path.should == "distancePerJourney"
68
+ @data.first.unit.should == "km"
69
+ @data.first.perunit.should == nil
70
+ @data.first.profile?.should == true
71
+ @data.first.drill?.should == false
72
+ @data.first.data?.should == false
73
+ end
74
+
75
+ it "should fail gracefully with incorrect XML data" do
76
+ connection = flexmock "connection"
77
+ connection.should_receive(:retries).and_return(0).once
78
+ xml = '<?xml version="1.0" encoding="UTF-8"?><Resources></Resources>'
79
+ connection.should_receive(:get).with("/definitions/itemDefinitions/BD88D30D1214/itemValueDefinitions", {}).and_return(flexmock(:body => xml))
80
+ connection.should_receive(:expire).with("/definitions/itemDefinitions/BD88D30D1214/itemValueDefinitions").once
81
+ lambda{AMEE::Admin::ItemValueDefinitionList.new(connection, "BD88D30D1214")}.should raise_error(AMEE::BadData)
82
+ end
83
+
84
+ it "should fail gracefully with incorrect JSON data" do
85
+ connection = flexmock "connection"
86
+ connection.should_receive(:retries).and_return(0).once
87
+ json = '{}'
88
+ connection.should_receive(:get).with("/definitions/itemDefinitions/BD88D30D1214/itemValueDefinitions", {}).and_return(flexmock(:body => json))
89
+ connection.should_receive(:expire).with("/definitions/itemDefinitions/BD88D30D1214/itemValueDefinitions").once
90
+ lambda{AMEE::Admin::ItemValueDefinitionList.new(connection, "BD88D30D1214")}.should raise_error(AMEE::BadData)
91
+ end
92
+
93
+ it "should fail gracefully on other errors" do
94
+ connection = flexmock "connection"
95
+ connection.should_receive(:retries).and_return(0).once
96
+ connection.should_receive(:get).with("/definitions/itemDefinitions/BD88D30D1214/itemValueDefinitions", {}).and_raise(Timeout::Error)
97
+ lambda{AMEE::Admin::ItemValueDefinitionList.new(connection, "BD88D30D1214")}.should raise_error(Timeout::Error)
98
+ end
99
+ end
100
+
101
+ describe AMEE::Admin::ItemValueDefinition, "with an authenticated connection" do
102
+
103
+ it "should parse profile item XML correctly" do
104
+ connection = flexmock "connection"
105
+ connection.should_receive(:get).with("/definitions/itemDefinitions/BD88D30D1214/itemValueDefinitions/A8A212610A57", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8" standalone="no"?><Resources><ItemValueDefinitionResource><ItemValueDefinition created="2009-03-20 00:00:00.0" modified="2009-03-20 00:00:00.0" uid="A8A212610A57"><Path>distancePerJourney</Path><Name>Distance per journey</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>km</Unit><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown><Value/><Choices/><AllowedRoles/><Environment uid="5F5887BCF726"/><ItemDefinition uid="BD88D30D1214"/><AliasedTo/><APIVersions><APIVersion>2.0</APIVersion></APIVersions></ItemValueDefinition></ItemValueDefinitionResource></Resources>'))
106
+ @data = AMEE::Admin::ItemValueDefinition.load(connection,"BD88D30D1214","A8A212610A57")
107
+ @data.uid.should == "A8A212610A57"
108
+ @data.itemdefuid.should == 'BD88D30D1214'
109
+ @data.created.should == DateTime.new(2009,3,20)
110
+ @data.modified.should == DateTime.new(2009,3,20)
111
+ @data.name.should == "Distance per journey"
112
+ @data.path.should == "distancePerJourney"
113
+ @data.unit.should == "km"
114
+ @data.perunit.should == nil
115
+ @data.profile?.should == true
116
+ @data.drill?.should == false
117
+ @data.data?.should == false
118
+ @data.valuetype.should == 'DECIMAL'
119
+ @data.default.should == nil
120
+ @data.choices.should == []
121
+ @data.versions.should == ['2.0']
122
+ @data.full_path.should == '/definitions/itemDefinitions/BD88D30D1214/itemValueDefinitions/A8A212610A57'
123
+ end
124
+
125
+ it "should parse data item XML correctly" do
126
+ connection = flexmock "connection"
127
+ connection.should_receive(:get).with("/definitions/itemDefinitions/BD88D30D1214/itemValueDefinitions/9BAFC976044B", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8" standalone="no"?><Resources><ItemValueDefinitionResource><ItemValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="9BAFC976044B"><Path>source</Path><Name>Source</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>false</FromProfile><FromData>true</FromData><DrillDown>false</DrillDown><Value>42</Value><Choices>foo,bar</Choices><AllowedRoles/><Environment uid="5F5887BCF726"/><ItemDefinition uid="BD88D30D1214"/><AliasedTo/><APIVersions><APIVersion>1.0</APIVersion><APIVersion>2.0</APIVersion></APIVersions></ItemValueDefinition></ItemValueDefinitionResource></Resources>'))
128
+
129
+ @data = AMEE::Admin::ItemValueDefinition.load(connection,"BD88D30D1214","9BAFC976044B")
130
+ @data.uid.should == "9BAFC976044B"
131
+ @data.itemdefuid.should == 'BD88D30D1214'
132
+ @data.created.should == DateTime.new(2007,7,27,9,30,44)
133
+ @data.modified.should == DateTime.new(2007,7,27,9,30,44)
134
+ @data.name.should == "Source"
135
+ @data.path.should == "source"
136
+ @data.unit.should == nil
137
+ @data.perunit.should == nil
138
+ @data.profile?.should == false
139
+ @data.drill?.should == false
140
+ @data.data?.should == true
141
+ @data.valuetype.should == 'TEXT'
142
+ @data.default.should == "42"
143
+ @data.choices.should == ['foo', 'bar']
144
+ @data.versions.should == ['1.0', '2.0']
145
+ end
146
+
147
+ it "should parse drill item XML correctly" do
148
+ connection = flexmock "connection"
149
+ connection.should_receive(:get).with("/definitions/itemDefinitions/BD88D30D1214/itemValueDefinitions/D2AB505D2D91", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8" standalone="no"?><Resources><ItemValueDefinitionResource><ItemValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="D2AB505D2D91"><Path>type</Path><Name>Type</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>false</FromProfile><FromData>true</FromData><DrillDown>true</DrillDown><Value/><Choices/><AllowedRoles/><Environment uid="5F5887BCF726"/><ItemDefinition uid="BD88D30D1214"/><AliasedTo/><APIVersions><APIVersion>1.0</APIVersion><APIVersion>2.0</APIVersion></APIVersions></ItemValueDefinition></ItemValueDefinitionResource></Resources>'))
150
+ @data = AMEE::Admin::ItemValueDefinition.load(connection,"BD88D30D1214","D2AB505D2D91")
151
+ @data.uid.should == "D2AB505D2D91"
152
+ @data.itemdefuid.should == 'BD88D30D1214'
153
+ @data.created.should == DateTime.new(2007,7,27,9,30,44)
154
+ @data.modified.should == DateTime.new(2007,7,27,9,30,44)
155
+ @data.name.should == "Type"
156
+ @data.path.should == "type"
157
+ @data.unit.should == nil
158
+ @data.perunit.should == nil
159
+ @data.profile?.should == false
160
+ @data.drill?.should == true
161
+ @data.data?.should == false
162
+ @data.valuetype.should == 'TEXT'
163
+ @data.default.should == nil
164
+ @data.choices.should == []
165
+ @data.versions.should == ['1.0', '2.0']
166
+ end
167
+
168
+ it "should parse profile item JSON correctly" do
169
+ connection = flexmock "connection"
170
+ connection.should_receive(:get).with("/definitions/itemDefinitions/BD88D30D1214/itemValueDefinitions/A8A212610A57", {}).and_return(flexmock(:body => '{"itemValueDefinition":{"uid":"A8A212610A57","choices":"","itemDefinition":{"uid":"BD88D30D1214"},"fromProfile":true,"drillDown":false,"modified":"2009-03-20 00:00:00.0","unit":"km","apiVersions":[{"apiVersion":"2.0"}],"environment":{"uid":"5F5887BCF726"},"created":"2009-03-20 00:00:00.0","name":"Distance per journey","path":"distancePerJourney","fromData":false,"value":"","aliasedTo":null,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 09:30:44.0"},"allowedRoles":""}}'))
171
+ @data = AMEE::Admin::ItemValueDefinition.load(connection,"BD88D30D1214","A8A212610A57")
172
+ @data.uid.should == "A8A212610A57"
173
+ @data.itemdefuid.should == 'BD88D30D1214'
174
+ @data.created.should == DateTime.new(2009,3,20)
175
+ @data.modified.should == DateTime.new(2009,3,20)
176
+ @data.name.should == "Distance per journey"
177
+ @data.path.should == "distancePerJourney"
178
+ @data.unit.should == "km"
179
+ @data.perunit.should == nil
180
+ @data.profile?.should == true
181
+ @data.drill?.should == false
182
+ @data.data?.should == false
183
+ @data.valuetype.should == 'DECIMAL'
184
+ @data.default.should == nil
185
+ @data.choices.should == []
186
+ @data.versions.should == ['2.0']
187
+ @data.full_path.should == '/definitions/itemDefinitions/BD88D30D1214/itemValueDefinitions/A8A212610A57'
188
+ end
189
+
190
+ it "should parse data item JSON correctly" do
191
+ connection = flexmock "connection"
192
+ connection.should_receive(:get).with("/definitions/itemDefinitions/BD88D30D1214/itemValueDefinitions/9BAFC976044B", {}).and_return(flexmock(:body => '{"itemValueDefinition":{"uid":"9BAFC976044B","choices":"foo,bar","itemDefinition":{"uid":"BD88D30D1214"},"fromProfile":false,"drillDown":false,"modified":"2007-07-27 09:30:44.0","apiVersions":[{"apiVersion":"1.0"},{"apiVersion":"2.0"}],"environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","name":"Source","path":"source","fromData":true,"value":"42","aliasedTo":null,"valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 09:30:44.0"},"allowedRoles":""}}'))
193
+
194
+ @data = AMEE::Admin::ItemValueDefinition.load(connection,"BD88D30D1214","9BAFC976044B")
195
+ @data.uid.should == "9BAFC976044B"
196
+ @data.itemdefuid.should == 'BD88D30D1214'
197
+ @data.created.should == DateTime.new(2007,7,27,9,30,44)
198
+ @data.modified.should == DateTime.new(2007,7,27,9,30,44)
199
+ @data.name.should == "Source"
200
+ @data.path.should == "source"
201
+ @data.unit.should == nil
202
+ @data.perunit.should == nil
203
+ @data.profile?.should == false
204
+ @data.drill?.should == false
205
+ @data.data?.should == true
206
+ @data.valuetype.should == 'TEXT'
207
+ @data.default.should == "42"
208
+ @data.choices.should == ['foo', 'bar']
209
+ @data.versions.should == ['1.0', '2.0']
210
+ end
211
+
212
+ it "should parse drill item JSON correctly" do
213
+ connection = flexmock "connection"
214
+ connection.should_receive(:get).with("/definitions/itemDefinitions/BD88D30D1214/itemValueDefinitions/D2AB505D2D91", {}).and_return(flexmock(:body => '{"itemValueDefinition":{"uid":"D2AB505D2D91","choices":"","itemDefinition":{"uid":"BD88D30D1214"},"fromProfile":false,"drillDown":true,"modified":"2007-07-27 09:30:44.0","apiVersions":[{"apiVersion":"1.0"},{"apiVersion":"2.0"}],"environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","name":"Type","path":"type","fromData":true,"value":"","aliasedTo":null,"valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 09:30:44.0"},"allowedRoles":""}}'))
215
+ @data = AMEE::Admin::ItemValueDefinition.load(connection,"BD88D30D1214","D2AB505D2D91")
216
+ @data.uid.should == "D2AB505D2D91"
217
+ @data.itemdefuid.should == 'BD88D30D1214'
218
+ @data.created.should == DateTime.new(2007,7,27,9,30,44)
219
+ @data.modified.should == DateTime.new(2007,7,27,9,30,44)
220
+ @data.name.should == "Type"
221
+ @data.path.should == "type"
222
+ @data.unit.should == nil
223
+ @data.perunit.should == nil
224
+ @data.profile?.should == false
225
+ @data.drill?.should == true
226
+ @data.data?.should == false
227
+ @data.valuetype.should == 'TEXT'
228
+ @data.default.should == nil
229
+ @data.choices.should == []
230
+ @data.versions.should == ['1.0', '2.0']
231
+ end
232
+
233
+ it "should fail gracefully with incorrect data" do
234
+ connection = flexmock "connection"
235
+ xml = '<?xml version="1.0" encoding="UTF-8"?><Resources></Resources>'
236
+ connection.should_receive(:get).with("/admin", {}).and_return(flexmock(:body => xml))
237
+ lambda{AMEE::Admin::ItemValueDefinition.get(connection, "/admin")}.should raise_error(AMEE::BadData)
238
+ end
239
+
240
+ it "should fail gracefully with incorrect JSON data" do
241
+ connection = flexmock "connection"
242
+ json = '{}'
243
+ connection.should_receive(:get).with("/admin", {}).and_return(flexmock(:body => json))
244
+ lambda{AMEE::Admin::ItemValueDefinition.get(connection, "/admin")}.should raise_error(AMEE::BadData)
245
+ end
246
+
247
+ it "should fail gracefully on other errors" do
248
+ connection = flexmock "connection"
249
+ connection.should_receive(:get).with("/admin", {}).and_raise("unidentified error")
250
+ lambda{AMEE::Admin::ItemValueDefinition.get(connection, "/admin")}.should raise_error(AMEE::BadData)
251
+ end
252
+
253
+ end
@@ -0,0 +1,16 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
5
+
6
+ describe Logger do
7
+ it "Should create default error log" do
8
+ AMEE::Logger::log.should be_a Log4r::Logger
9
+ AMEE::Logger::log.debug("Test log message")
10
+ end
11
+ it "Can log to a different logger" do
12
+ AMEE::Logger.to Log4r::Logger.new('Mylogger')
13
+ AMEE::Logger::log.debug("Test log message 2")
14
+ end
15
+ end
16
+
@@ -0,0 +1,44 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe AMEE::Object do
4
+
5
+ it "can be created from hash of data" do
6
+ data = {}
7
+ data[:uid] = @uid = 'AB69E4AE213B'
8
+ data[:created] = @creation_time = Time.now - 10000
9
+ data[:modified] = @modification_time = Time.now - 1000
10
+ data[:path] = @path = "/transport/plane/generic/ABCD1234"
11
+ data[:name] = @name = "kgPerPassengerJourney"
12
+ o = AMEE::Object.new(data)
13
+ o.uid.should == @uid
14
+ o.created.should == @creation_time
15
+ o.modified.should == @modification_time
16
+ o.path.should == @path
17
+ o.name.should == @name
18
+ end
19
+
20
+ it "should have a uid" do
21
+ AMEE::Object.new.should respond_to(:uid)
22
+ end
23
+
24
+ it "should have a created time" do
25
+ AMEE::Object.new.should respond_to(:created)
26
+ end
27
+
28
+ it "should have a modified time" do
29
+ AMEE::Object.new.should respond_to(:modified)
30
+ end
31
+
32
+ it "should have a name" do
33
+ AMEE::Object.new.should respond_to(:name)
34
+ end
35
+
36
+ it "can be created without data" do
37
+ o = AMEE::Object.new
38
+ o.uid.should be_nil
39
+ o.created.should == o.modified
40
+ o.path.should be_nil
41
+ o.name.should be_nil
42
+ end
43
+
44
+ end
@@ -0,0 +1,72 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ test_set = {
4
+ 'attrib_test/@attrib' => 'attribute_value',
5
+ 'attrib_test/@non_existent_attrib' => nil,
6
+ 'attrib_test/@empty_attrib' => '',
7
+ 'content_test' => 'content',
8
+ 'whitespace_content_test' => "\n ",
9
+ 'empty_content_test' => nil,
10
+ 'self_closing_content_test' => nil,
11
+ 'multi_attrib_test/attrib_test/@attrib' => [
12
+ 'attribute_value',
13
+ 'attribute_value_1',
14
+ ''
15
+ ],
16
+ 'multi_content_test/content' => [
17
+ 'content',
18
+ "\n ",
19
+ nil,
20
+ nil
21
+ ],
22
+ }
23
+
24
+ class REXMLTestObject
25
+ include ParseHelper
26
+ def xmlpathpreamble
27
+ '/root/'
28
+ end
29
+ def initialize
30
+ @doc = REXML::Document.new(fixture('parse_test.xml'))
31
+ end
32
+ end
33
+
34
+ describe ParseHelper, 'using REXML' do
35
+
36
+ before :all do
37
+ @obj = REXMLTestObject.new
38
+ end
39
+
40
+ test_set.each_pair do |xpath, res|
41
+ it "should parse #{xpath} to #{res}" do
42
+ @obj.send(:x, xpath).should eql res
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+
49
+ class NokogiriTestObject
50
+ include ParseHelper
51
+ def xmlpathpreamble
52
+ '/root/'
53
+ end
54
+ def initialize
55
+ @doc = load_xml_doc(fixture('parse_test.xml'))
56
+ end
57
+ end
58
+
59
+ describe ParseHelper, 'using Nokogiri' do
60
+
61
+ before :all do
62
+ @obj = NokogiriTestObject.new
63
+ end
64
+
65
+ test_set.each_pair do |xpath, res|
66
+ it "should parse #{xpath} to #{res}" do
67
+ @obj.send(:x, xpath).should eql res
68
+ end
69
+ end
70
+
71
+
72
+ end
@@ -0,0 +1,565 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe AMEE::Profile::Category do
4
+
5
+ before(:each) do
6
+ @cat = AMEE::Profile::Category.new
7
+ end
8
+
9
+ it "should have common AMEE object properties" do
10
+ @cat.is_a?(AMEE::Profile::Object).should be_true
11
+ end
12
+
13
+ it "should have a total co2 amount and unit" do
14
+ @cat.should respond_to(:total_amount)
15
+ @cat.should respond_to(:total_amount_unit)
16
+ end
17
+
18
+ it "should have children" do
19
+ @cat.should respond_to(:children)
20
+ end
21
+
22
+ it "should have items" do
23
+ @cat.should respond_to(:items)
24
+ end
25
+
26
+ it "should initialize AMEE::Object data on creation" do
27
+ uid = 'ABCD1234'
28
+ @cat = AMEE::Profile::Category.new(:uid => uid)
29
+ @cat.uid.should == uid
30
+ end
31
+
32
+ it "can be created with hash of data" do
33
+ children = ["one", "two"]
34
+ items = ["three", "four"]
35
+ @cat = AMEE::Profile::Category.new(:children => children, :items => items)
36
+ @cat.children.should == children
37
+ @cat.items.should == items
38
+ end
39
+
40
+ end
41
+
42
+ describe AMEE::Profile::Category, "accessing AMEE V0" do
43
+
44
+ it "should load Profile Category" do
45
+ connection = flexmock "connection"
46
+ connection.should_receive(:version).and_return(1.0)
47
+ connection.should_receive(:get).with("/profiles/D4B9755F671D/home", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileCategoryResource><DataCategory created="2007-04-16 17:50:43.0" modified="2007-04-16 17:50:43.0" uid="248D8617A389"><name>Home</name><path>home</path></DataCategory><Profile uid="D4B9755F671D"/><Children><DataCategories><DataCategory uid="3A72CC3F2AC9"><name>Television</name><path>television</path></DataCategory><DataCategory uid="51FF7A9A1D84"><name>Seasonal Billing</name><path>seasonal_billing</path></DataCategory><DataCategory uid="83B7E4488D34"><name>Heating</name><path>heating</path></DataCategory><DataCategory uid="8B5A3EF67252"><name>Fuel</name><path>fuel</path></DataCategory><DataCategory uid="97888F42B5D6"><name>Lighting</name><path>lighting</path></DataCategory><DataCategory uid="0D260A2B9E56"><name>Fuel Price</name><path>fuel_price</path></DataCategory><DataCategory uid="2A018E464460"><name>Appliances</name><path>appliances</path></DataCategory><DataCategory uid="A937C019FA6F"><name>Cooking</name><path>cooking</path></DataCategory></DataCategories></Children><ProfileDate>200902</ProfileDate></ProfileCategoryResource></Resources>'))
48
+ @cat = AMEE::Profile::Category.get(connection, "/profiles/D4B9755F671D/home")
49
+ @cat.profile_uid.should == "D4B9755F671D"
50
+ @cat.profile_date.should == DateTime.new(2009, 2)
51
+ @cat.name.should == "Home"
52
+ @cat.path.should == "/home"
53
+ @cat.full_path.should == "/profiles/D4B9755F671D/home"
54
+ @cat.children.size.should be(8)
55
+ @cat.children[0][:uid].should == "3A72CC3F2AC9"
56
+ @cat.children[0][:name].should == "Television"
57
+ @cat.children[0][:path].should == "television"
58
+ @cat.pager.should be_nil
59
+ end
60
+
61
+ it "should parse data items" do
62
+ connection = flexmock "connection"
63
+ connection.should_receive(:version).and_return(1.0)
64
+ connection.should_receive(:get).with("/profiles/D4B9755F671D/transport/transport", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileCategoryResource><DataCategory created="2007-04-16 17:50:43.0" modified="2007-04-16 17:50:43.0" uid="CD13B9174A6A"><name>Transport</name><path>transport</path></DataCategory><Profile uid="D4B9755F671D"/><Children><DataCategories/><ProfileItems><ProfileItem created="2009-02-19 16:50:26.0" modified="2009-02-19 16:50:27.0" uid="05BB9D4AF86D"><validFrom>20090201</validFrom><end>false</end><transportAdhereToSpeedLimit>false</transportAdhereToSpeedLimit><transportTyresUnderInflated>false</transportTyresUnderInflated><transportAirConAverage>false</transportAirConAverage><transportKmPerLitre>1</transportKmPerLitre><transportEcoDriving>false</transportEcoDriving><transportDistance>0</transportDistance><amountPerMonth>21.42</amountPerMonth><transportAirConFull>false</transportAirConFull><dataItemUid>25A341E24BCE</dataItemUid><transportNumberOfJourneys>0.0833333333333333</transportNumberOfJourneys><name/><dataItemLabel>Flights, Short haul, Return</dataItemLabel></ProfileItem><ProfileItem created="2009-02-19 16:48:47.0" modified="2009-02-19 16:48:47.0" uid="D6FE02356302"><validFrom>20090201</validFrom><end>false</end><transportAdhereToSpeedLimit>false</transportAdhereToSpeedLimit><transportTyresUnderInflated>false</transportTyresUnderInflated><transportAirConAverage>false</transportAirConAverage><transportKmPerLitre>14.16</transportKmPerLitre><transportEcoDriving>false</transportEcoDriving><transportDistance>1340.83333333333</transportDistance><amountPerMonth>286.39</amountPerMonth><transportAirConFull>false</transportAirConFull><dataItemUid>3CAFBEA600F4</dataItemUid><transportNumberOfJourneys>0</transportNumberOfJourneys><name/><dataItemLabel>Car1, Fuel manufacturer consumption, Diesel</dataItemLabel></ProfileItem></ProfileItems></Children><ProfileDate>200902</ProfileDate><TotalAmountPerMonth>307.81</TotalAmountPerMonth></ProfileCategoryResource></Resources>'))
65
+ @cat = AMEE::Profile::Category.get(connection, "/profiles/D4B9755F671D/transport/transport")
66
+ @cat.total_amount.should be_close(307.81, 1e-9)
67
+ @cat.total_amount_unit.should == "kg/month"
68
+ @cat.items.size.should be(2)
69
+ @cat.items[0][:uid].should == "05BB9D4AF86D"
70
+ @cat.items[0][:name].should be_nil
71
+ @cat.items[0][:path].should == "05BB9D4AF86D"
72
+ @cat.items[0][:dataItemLabel].should == "Flights, Short haul, Return"
73
+ @cat.items[0][:dataItemUid].should == "25A341E24BCE"
74
+ @cat.items[0][:validFrom].should == DateTime.new(2009, 2, 1)
75
+ @cat.items[0][:end].should == false
76
+ @cat.items[0][:amountPerMonth].should be_close(21.42, 1e-9)
77
+ @cat.items[0][:values].size.should be(8)
78
+ @cat.items[0][:values][:transportNumberOfJourneys].should == "0.0833333333333333"
79
+ @cat.items[0][:values][:transportEcoDriving].should == "false"
80
+ @cat.pager.should be_nil
81
+ end
82
+
83
+ end
84
+
85
+ describe AMEE::Profile::Category, "with an authenticated XML connection" do
86
+
87
+ it "should load Profile Category" do
88
+ connection = flexmock "connection"
89
+ connection.should_receive(:version).and_return(1.0)
90
+ connection.should_receive(:get).with("/profiles/E54C5525AA3E/home", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileCategoryResource><Path>/home</Path><ProfileDate>200809</ProfileDate><Profile uid="E54C5525AA3E"/><DataCategory uid="BBA3AC3E795E"><Name>Home</Name><Path>home</Path></DataCategory><Children><ProfileCategories><DataCategory uid="427DFCC65E52"><Name>Appliances</Name><Path>appliances</Path></DataCategory><DataCategory uid="30BA55A0C472"><Name>Energy</Name><Path>energy</Path></DataCategory><DataCategory uid="A46ECFA19333"><Name>Heating</Name><Path>heating</Path></DataCategory><DataCategory uid="150266DD4434"><Name>Lighting</Name><Path>lighting</Path></DataCategory></ProfileCategories></Children></ProfileCategoryResource></Resources>'))
91
+ @cat = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home")
92
+ @cat.profile_uid.should == "E54C5525AA3E"
93
+ @cat.profile_date.should == DateTime.new(2008, 9)
94
+ @cat.name.should == "Home"
95
+ @cat.path.should == "/home"
96
+ @cat.full_path.should == "/profiles/E54C5525AA3E/home"
97
+ @cat.children.size.should be(4)
98
+ @cat.children[0][:uid].should == "427DFCC65E52"
99
+ @cat.children[0][:name].should == "Appliances"
100
+ @cat.children[0][:path].should == "appliances"
101
+ @cat.pager.should be_nil
102
+ end
103
+
104
+ it "should provide access to child objects" do
105
+ connection = flexmock "connection"
106
+ connection.should_receive(:version).and_return(1.0)
107
+ connection.should_receive(:get).with("/profiles/E54C5525AA3E/home", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileCategoryResource><Path>/home</Path><ProfileDate>200809</ProfileDate><Profile uid="E54C5525AA3E"/><DataCategory uid="BBA3AC3E795E"><Name>Home</Name><Path>home</Path></DataCategory><Children><ProfileCategories><DataCategory uid="427DFCC65E52"><Name>Appliances</Name><Path>appliances</Path></DataCategory><DataCategory uid="30BA55A0C472"><Name>Energy</Name><Path>energy</Path></DataCategory><DataCategory uid="A46ECFA19333"><Name>Heating</Name><Path>heating</Path></DataCategory><DataCategory uid="150266DD4434"><Name>Lighting</Name><Path>lighting</Path></DataCategory></ProfileCategories></Children></ProfileCategoryResource></Resources>'))
108
+ connection.should_receive(:get).with("/profiles/E54C5525AA3E/home/appliances", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileCategoryResource><Path>/home/appliances</Path><ProfileDate>200809</ProfileDate><Profile uid="E54C5525AA3E"/><DataCategory uid="427DFCC65E52"><Name>Appliances</Name><Path>appliances</Path></DataCategory><Children><ProfileCategories><DataCategory uid="3FE23FDC8CEA"><Name>Computers</Name><Path>computers</Path></DataCategory><DataCategory uid="54C8A44254AA"><Name>Cooking</Name><Path>cooking</Path></DataCategory><DataCategory uid="75AD9B83B7BF"><Name>Entertainment</Name><Path>entertainment</Path></DataCategory><DataCategory uid="4BD595E1873A"><Name>Kitchen</Name><Path>kitchen</Path></DataCategory><DataCategory uid="700D0771870A"><Name>Televisions</Name><Path>televisions</Path></DataCategory></ProfileCategories></Children></ProfileCategoryResource></Resources>'))
109
+ @cat = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home")
110
+ @child = @cat.child('appliances')
111
+ @child.path.should == "/home/appliances"
112
+ @child.full_path.should == "/profiles/E54C5525AA3E/home/appliances"
113
+ @child.children.size.should be(5)
114
+ @child.pager.should be_nil
115
+ end
116
+
117
+ it "should parse data items" do
118
+ connection = flexmock "connection"
119
+ connection.should_receive(:version).and_return(1.0)
120
+ connection.should_receive(:get).with("/profiles/E54C5525AA3E/home/energy/quantity", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileCategoryResource><Path>/home/energy/quantity</Path><ProfileDate>200809</ProfileDate><Profile uid="E54C5525AA3E"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><Children><ProfileCategories/><ProfileItems><ProfileItem created="2008-09-03 11:37:35.0" modified="2008-09-03 11:38:12.0" uid="FB07247AD937"><validFrom>20080902</validFrom><end>false</end><kWhPerMonth>12</kWhPerMonth><amountPerMonth>2.472</amountPerMonth><dataItemUid>66056991EE23</dataItemUid><kgPerMonth>0</kgPerMonth><path>FB07247AD937</path><litresPerMonth>0</litresPerMonth><name>gas</name><dataItemLabel>gas</dataItemLabel></ProfileItem><ProfileItem created="2008-09-03 11:40:44.0" modified="2008-09-03 11:41:54.0" uid="D9CBCDED44C5"><validFrom>20080901</validFrom><end>false</end><kWhPerMonth>500</kWhPerMonth><amountPerMonth>103.000</amountPerMonth><dataItemUid>66056991EE23</dataItemUid><kgPerMonth>0</kgPerMonth><path>D9CBCDED44C5</path><litresPerMonth>0</litresPerMonth><name>gas2</name><dataItemLabel>gas</dataItemLabel></ProfileItem></ProfileItems><Pager><Start>0</Start><From>1</From><To>2</To><Items>2</Items><CurrentPage>1</CurrentPage><RequestedPage>1</RequestedPage><NextPage>-1</NextPage><PreviousPage>-1</PreviousPage><LastPage>1</LastPage><ItemsPerPage>10</ItemsPerPage><ItemsFound>2</ItemsFound></Pager></Children><TotalAmountPerMonth>105.472</TotalAmountPerMonth></ProfileCategoryResource></Resources>'))
121
+ @cat = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
122
+ @cat.total_amount.should be_close(105.472, 1e-9)
123
+ @cat.total_amount_unit.should == "kg/month"
124
+ @cat.items.size.should be(2)
125
+ @cat.items[0][:uid].should == "FB07247AD937"
126
+ @cat.items[0][:name].should == "gas"
127
+ @cat.items[0][:path].should == "FB07247AD937"
128
+ @cat.items[0][:dataItemLabel].should == "gas"
129
+ @cat.items[0][:dataItemUid].should == "66056991EE23"
130
+ @cat.items[0][:validFrom].should == DateTime.new(2008, 9, 2)
131
+ @cat.items[0][:end].should == false
132
+ @cat.items[0][:amountPerMonth].should be_close(2.472, 1e-9)
133
+ @cat.items[0][:values].size.should be(3)
134
+ @cat.items[0][:values][:kWhPerMonth].should == "12"
135
+ @cat.items[0][:values][:kgPerMonth].should == "0"
136
+ @cat.items[0][:values][:litresPerMonth].should == "0"
137
+ @cat.pager.should_not be_nil
138
+ end
139
+
140
+ it "should fail gracefully with incorrect data" do
141
+ connection = flexmock "connection"
142
+ connection.should_receive(:version).and_return(1.0)
143
+ xml = '<?xml version="1.0" encoding="UTF-8"?><Resources></Resources>'
144
+ connection.should_receive(:get).with("/profiles/E54C5525AA3E", {}).and_return(flexmock(:body => xml))
145
+ lambda{AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E")}.should raise_error(AMEE::BadData)
146
+ end
147
+
148
+ it "parses recursive GET requests" do
149
+ connection = flexmock "connection"
150
+ connection.should_receive(:version).and_return(1.0)
151
+ connection.should_receive(:get).with("/profiles/BE22C1732952/transport/car", {:recurse=>true}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileCategoryResource><Path>/transport/car</Path><ProfileDate>200901</ProfileDate><Profile uid="BE22C1732952"/><DataCategory uid="1D95119FB149"><Name>Car</Name><Path>car</Path></DataCategory><Children><ProfileCategories><ProfileCategory><Path>/transport/car/bands</Path><DataCategory uid="883ADD27228F"><Name>Bands</Name><Path>bands</Path></DataCategory></ProfileCategory><ProfileCategory><Path>/transport/car/generic</Path><DataCategory uid="87E55DA88017"><Name>Generic</Name><Path>generic</Path></DataCategory><Children><ProfileCategories><ProfileCategory><Path>/transport/car/generic/electric</Path><DataCategory uid="417DD367E9AA"><Name>Electric</Name><Path>electric</Path></DataCategory></ProfileCategory></ProfileCategories><ProfileItems><ProfileItem created="2009-01-05 13:58:52.0" modified="2009-01-05 13:59:05.0" uid="8450D6D97D2D"><distanceKmPerMonth>1</distanceKmPerMonth><validFrom>20090101</validFrom><end>false</end><airconTypical>true</airconTypical><ecoDriving>false</ecoDriving><airconFull>false</airconFull><kmPerLitreOwn>0</kmPerLitreOwn><country/><tyresUnderinflated>false</tyresUnderinflated><amountPerMonth>0.265</amountPerMonth><occupants>-1</occupants><kmPerLitre>0</kmPerLitre><dataItemUid>4F6CBCEE95F7</dataItemUid><regularlyServiced>true</regularlyServiced><path>8450D6D97D2D</path><name/><dataItemLabel>diesel, large</dataItemLabel></ProfileItem></ProfileItems></Children><TotalAmountPerMonth>0.265</TotalAmountPerMonth></ProfileCategory><ProfileCategory><Path>/transport/car/specific</Path><DataCategory uid="95E76249584D"><Name>Specific</Name><Path>specific</Path></DataCategory></ProfileCategory></ProfileCategories></Children></ProfileCategoryResource></Resources>'))
152
+ cat = AMEE::Profile::Category.get(connection, "/profiles/BE22C1732952/transport/car", :recurse => true)
153
+ cat.items.size.should == 0
154
+ cat.children.size.should == 3
155
+ cat.children[1][:name].should == "Generic"
156
+ cat.children[1][:path].should == "generic"
157
+ cat.children[1][:uid].should == "87E55DA88017"
158
+ cat.children[1][:totalAmountPerMonth].should == 0.265
159
+ cat.children[1][:children].size.should == 1
160
+ cat.children[1][:children][0][:name].should == "Electric"
161
+ cat.children[1][:children][0][:path].should == "electric"
162
+ cat.children[1][:children][0][:uid].should == "417DD367E9AA"
163
+ cat.children[1][:items].size.should == 1
164
+ cat.children[1][:items][0][:amountPerMonth].should == 0.265
165
+ cat.children[1][:items][0][:dataItemLabel].should == "diesel, large"
166
+ cat.children[1][:items][0][:dataItemUid].should == "4F6CBCEE95F7"
167
+ cat.children[1][:items][0][:values][:airconTypical].should == "true"
168
+ cat.children[1][:items][0][:uid].should == "8450D6D97D2D"
169
+ cat.pager.should be_nil
170
+ end
171
+
172
+ end
173
+
174
+ describe AMEE::Profile::Category, "with an authenticated version 2 XML connection" do
175
+
176
+ it "should load Profile Category" do
177
+ connection = flexmock "connection"
178
+ connection.should_receive(:version).and_return(2.0)
179
+ connection.should_receive(:get).with("/profiles/26532D8EFA9D/home", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?> <Resources xmlns="http://schemas.amee.cc/2.0"><ProfileCategoryResource><Path>/home</Path><Profile uid="26532D8EFA9D"/><Environment created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="5F5887BCF726"><Name>AMEE</Name><Path/><Description/><Owner/><ItemsPerPage>10</ItemsPerPage><ItemsPerFeed>10</ItemsPerFeed></Environment><DataCategory uid="BBA3AC3E795E"><Name>Home</Name><Path>home</Path></DataCategory><ProfileCategories><DataCategory uid="427DFCC65E52"><Name>Appliances</Name><Path>appliances</Path></DataCategory><DataCategory uid="30BA55A0C472"><Name>Energy</Name><Path>energy</Path></DataCategory><DataCategory uid="A46ECFA19333"><Name>Heating</Name><Path>heating</Path></DataCategory><DataCategory uid="150266DD4434"><Name>Lighting</Name><Path>lighting</Path></DataCategory><DataCategory uid="6553150F96CE"><Name>Waste</Name><Path>waste</Path></DataCategory><DataCategory uid="07362DCC9E7B"><Name>Water</Name><Path>water</Path></DataCategory></ProfileCategories></ProfileCategoryResource></Resources>'))
180
+ @cat = AMEE::Profile::Category.get(connection, "/profiles/26532D8EFA9D/home")
181
+ @cat.profile_uid.should == "26532D8EFA9D"
182
+ @cat.name.should == "Home"
183
+ @cat.path.should == "/home"
184
+ @cat.full_path.should == "/profiles/26532D8EFA9D/home"
185
+ @cat.children.size.should be(6)
186
+ @cat.children[0][:uid].should == "427DFCC65E52"
187
+ @cat.children[0][:name].should == "Appliances"
188
+ @cat.children[0][:path].should == "appliances"
189
+ @cat.pager.should be_nil
190
+ end
191
+
192
+ it "should parse data items" do
193
+ connection = flexmock "connection"
194
+ connection.should_receive(:version).and_return(2.0)
195
+ connection.should_receive(:get).with("/profiles/26532D8EFA9D/home/energy/quantity", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?> <Resources xmlns="http://schemas.amee.cc/2.0"><ProfileCategoryResource><Path>/home/energy/quantity</Path><Profile uid="9BFB0C1CD78A"/><Environment created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="5F5887BCF726"><Name>AMEE</Name><Path/><Description/><Owner/><ItemsPerPage>10</ItemsPerPage><ItemsPerFeed>10</ItemsPerFeed></Environment><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><ProfileCategories/><ProfileItems><ProfileItem created="2009-02-11T13:50+0000" modified="2009-02-11T13:50+0000" uid="30C00AD33033"><Name>gas</Name><ItemValues><ItemValue uid="570843C78E93"><Path>paymentFrequency</Path><Name>Payment frequency</Name><Value/><Unit/><PerUnit/><ItemValueDefinition uid="E0EFED6FD7E6"><Path>paymentFrequency</Path><Name>Payment frequency</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData></ItemValueDefinition></ItemValue><ItemValue uid="C71B646F8502"><Path>greenTariff</Path><Name>Green tariff</Name><Value/><Unit/><PerUnit/><ItemValueDefinition uid="63005554AE8A"><Path>greenTariff</Path><Name>Green tariff</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData></ItemValueDefinition></ItemValue><ItemValue uid="8231B25E416F"><Path>season</Path><Name>Season</Name><Value/><Unit/><PerUnit/><ItemValueDefinition uid="527AADFB3B65"><Path>season</Path><Name>Season</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData></ItemValueDefinition></ItemValue><ItemValue uid="AE5413F7A459"><Path>includesHeating</Path><Name>Includes Heating</Name><Value>false</Value><Unit/><PerUnit/><ItemValueDefinition uid="1740E500BDAB"><Path>includesHeating</Path><Name>Includes Heating</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData></ItemValueDefinition></ItemValue><ItemValue uid="20FC928B045A"><Path>massPerTime</Path><Name>Mass Per Time</Name><Value/><Unit>kg</Unit><PerUnit>year</PerUnit><ItemValueDefinition uid="80F561BE56E2"><Path>massPerTime</Path><Name>Mass Per Time</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>kg</Unit><PerUnit>year</PerUnit><FromProfile>true</FromProfile><FromData>false</FromData></ItemValueDefinition></ItemValue><ItemValue uid="3835DF705F9D"><Path>energyConsumption</Path><Name>Energy Consumption</Name><Value>13</Value><Unit>kWh</Unit><PerUnit>month</PerUnit><ItemValueDefinition uid="9801C6552128"><Path>energyConsumption</Path><Name>Energy Consumption</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>kWh</Unit><PerUnit>year</PerUnit><FromProfile>true</FromProfile><FromData>false</FromData></ItemValueDefinition></ItemValue><ItemValue uid="064C0DB99F75"><Path>currentReading</Path><Name>Current Reading</Name><Value/><Unit>kWh</Unit><PerUnit/><ItemValueDefinition uid="6EF1FF3361F0"><Path>currentReading</Path><Name>Current Reading</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>kWh</Unit><FromProfile>true</FromProfile><FromData>false</FromData></ItemValueDefinition></ItemValue><ItemValue uid="06B35B089155"><Path>lastReading</Path><Name>Last Reading</Name><Value/><Unit>kWh</Unit><PerUnit/><ItemValueDefinition uid="7DDB0BB0B6CA"><Path>lastReading</Path><Name>Last Reading</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>kWh</Unit><FromProfile>true</FromProfile><FromData>false</FromData></ItemValueDefinition></ItemValue><ItemValue uid="CEBEA6C086B8"><Path>volumePerTime</Path><Name>Volume Per Time</Name><Value/><Unit>L</Unit><PerUnit>year</PerUnit><ItemValueDefinition uid="CDA01AFCF91B"><Path>volumePerTime</Path><Name>Volume Per Time</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>L</Unit><PerUnit>year</PerUnit><FromProfile>true</FromProfile><FromData>false</FromData></ItemValueDefinition></ItemValue><ItemValue uid="0E77ACB084A5"><Path>deliveries</Path><Name>Number of deliveries</Name><Value/><Unit>year</Unit><PerUnit/><ItemValueDefinition uid="DEB369A7AD4E"><Path>deliveries</Path><Name>Number of deliveries</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>year</Unit><FromProfile>true</FromProfile><FromData>false</FromData></ItemValueDefinition></ItemValue></ItemValues><Amount unit="kg/year">29.664</Amount><Amounts><Amount default="true" perUnit="year" type="CO2" unit="kg">29.664</Amount></Amounts><StartDate>2008-09-02T01:00+0100</StartDate><EndDate/><DataItem uid="66056991EE23"><Label>gas</Label></DataItem></ProfileItem><ProfileItem created="2009-02-11T14:13+0000" modified="2009-02-11T14:13+0000" uid="BC0B730255FB"><Name>BC0B730255FB</Name><ItemValues><ItemValue uid="C3DEE5535925"><Path>paymentFrequency</Path><Name>Payment frequency</Name><Value/><Unit/><PerUnit/><ItemValueDefinition uid="E0EFED6FD7E6"><Path>paymentFrequency</Path><Name>Payment frequency</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData></ItemValueDefinition></ItemValue><ItemValue uid="DFBD9254685A"><Path>greenTariff</Path><Name>Green tariff</Name><Value/><Unit/><PerUnit/><ItemValueDefinition uid="63005554AE8A"><Path>greenTariff</Path><Name>Green tariff</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData></ItemValueDefinition></ItemValue><ItemValue uid="CB8705EB55C5"><Path>season</Path><Name>Season</Name><Value/><Unit/><PerUnit/><ItemValueDefinition uid="527AADFB3B65"><Path>season</Path><Name>Season</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData></ItemValueDefinition></ItemValue><ItemValue uid="A282A7875AEB"><Path>includesHeating</Path><Name>Includes Heating</Name><Value>false</Value><Unit/><PerUnit/><ItemValueDefinition uid="1740E500BDAB"><Path>includesHeating</Path><Name>Includes Heating</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData></ItemValueDefinition></ItemValue><ItemValue uid="2624A9954F17"><Path>massPerTime</Path><Name>Mass Per Time</Name><Value/><Unit>kg</Unit><PerUnit>year</PerUnit><ItemValueDefinition uid="80F561BE56E2"><Path>massPerTime</Path><Name>Mass Per Time</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>kg</Unit><PerUnit>year</PerUnit><FromProfile>true</FromProfile><FromData>false</FromData></ItemValueDefinition></ItemValue><ItemValue uid="44518F8EC8DC"><Path>energyConsumption</Path><Name>Energy Consumption</Name><Value/><Unit>kWh</Unit><PerUnit>year</PerUnit><ItemValueDefinition uid="9801C6552128"><Path>energyConsumption</Path><Name>Energy Consumption</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>kWh</Unit><PerUnit>year</PerUnit><FromProfile>true</FromProfile><FromData>false</FromData></ItemValueDefinition></ItemValue><ItemValue uid="C97FDB7CE8DF"><Path>currentReading</Path><Name>Current Reading</Name><Value/><Unit>kWh</Unit><PerUnit/><ItemValueDefinition uid="6EF1FF3361F0"><Path>currentReading</Path><Name>Current Reading</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>kWh</Unit><FromProfile>true</FromProfile><FromData>false</FromData></ItemValueDefinition></ItemValue><ItemValue uid="B540FB4C05C7"><Path>lastReading</Path><Name>Last Reading</Name><Value/><Unit>kWh</Unit><PerUnit/><ItemValueDefinition uid="7DDB0BB0B6CA"><Path>lastReading</Path><Name>Last Reading</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>kWh</Unit><FromProfile>true</FromProfile><FromData>false</FromData></ItemValueDefinition></ItemValue><ItemValue uid="32A873ED2142"><Path>volumePerTime</Path><Name>Volume Per Time</Name><Value/><Unit>L</Unit><PerUnit>year</PerUnit><ItemValueDefinition uid="CDA01AFCF91B"><Path>volumePerTime</Path><Name>Volume Per Time</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>L</Unit><PerUnit>year</PerUnit><FromProfile>true</FromProfile><FromData>false</FromData></ItemValueDefinition></ItemValue><ItemValue uid="88C0DC759E16"><Path>deliveries</Path><Name>Number of deliveries</Name><Value/><Unit>year</Unit><PerUnit/><ItemValueDefinition uid="DEB369A7AD4E"><Path>deliveries</Path><Name>Number of deliveries</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>year</Unit><FromProfile>true</FromProfile><FromData>false</FromData></ItemValueDefinition></ItemValue></ItemValues><Amount unit="kg/year">0.000</Amount><StartDate>2009-02-11T14:13+0000</StartDate><EndDate/><DataItem uid="A70149AF0F26"><Label>coal</Label></DataItem></ProfileItem></ProfileItems><Pager><Start>0</Start><From>1</From><To>2</To><Items>2</Items><CurrentPage>1</CurrentPage><RequestedPage>1</RequestedPage><NextPage>-1</NextPage><PreviousPage>-1</PreviousPage><LastPage>1</LastPage><ItemsPerPage>10</ItemsPerPage><ItemsFound>2</ItemsFound></Pager><TotalAmount unit="kg/year">1265.664</TotalAmount></ProfileCategoryResource></Resources>'))
196
+ @cat = AMEE::Profile::Category.get(connection, "/profiles/26532D8EFA9D/home/energy/quantity")
197
+ @cat.total_amount.should be_close(1265.664, 1e-9)
198
+ @cat.total_amount_unit.should == "kg/year"
199
+ @cat.items.size.should be(2)
200
+ @cat.items[0][:uid].should == "30C00AD33033"
201
+ @cat.items[0][:name].should == "gas"
202
+ @cat.items[0][:path].should == "30C00AD33033"
203
+ @cat.items[0][:dataItemLabel].should == "gas"
204
+ @cat.items[0][:dataItemUid].should == "66056991EE23"
205
+ @cat.items[0][:startDate].should == DateTime.new(2008, 9, 2)
206
+ @cat.items[0][:endDate].should be_nil
207
+ @cat.items[0][:amount].should be_close(29.664, 1e-9)
208
+ @cat.items[0][:amount_unit].should == "kg/year"
209
+ @cat.items[0][:values].size.should be(10)
210
+ @cat.items[0][:values][:energyConsumption][:value].should == "13"
211
+ @cat.items[0][:values][:energyConsumption][:unit].should == "kWh"
212
+ @cat.items[0][:values][:energyConsumption][:per_unit].should == "month"
213
+ @cat.items[0][:values][:massPerTime][:value].should == "0"
214
+ @cat.items[0][:values][:volumePerTime][:value].should == "0"
215
+ @cat.pager.should_not be_nil
216
+ end
217
+
218
+ it "should parse multiple return values" do
219
+ connection = flexmock "connection"
220
+ connection.should_receive(:version).and_return(2.0)
221
+ connection.should_receive(:get).with("/profiles/F8C2D1052BF7/home/energy/quantity", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8" standalone="no"?><Resources xmlns="http://schemas.amee.cc/2.0"><ProfileCategoryResource><Path>/home/energy/quantity</Path><Profile uid="F8C2D1052BF7"/><Environment created="2007-07-27 08:30:44.0" modified="2007-07-27 08:30:44.0" uid="5F5887BCF726"><Name>AMEE</Name><Path/><Description/><Owner/><ItemsPerPage>10</ItemsPerPage><ItemsPerFeed>10</ItemsPerFeed></Environment><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path><Deprecated>false</Deprecated></DataCategory><ProfileCategories/><ProfileItems><ProfileItem created="2010-07-16T14:44:43Z" modified="2010-07-16T14:45:03Z" uid="3BCDB0BB2B96"><Name>gas</Name><ItemValues><ItemValue uid="06F553CED9F7"><Path>currentReading</Path><Name>Current Reading</Name><Value>0</Value><Unit>kWh</Unit><PerUnit>year</PerUnit><StartDate>2010-07-16T10:44:00-04:00</StartDate><ItemValueDefinition uid="67B7476423C0"><Path>currentReading</Path><Name>Current Reading</Name><ValueDefinition created="2007-07-27 08:30:44.0" modified="2007-07-27 08:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>kWh</Unit><PerUnit>year</PerUnit><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition></ItemValue><ItemValue uid="4CF7691084DB"><Path>energyConsumption</Path><Name>Energy Consumption</Name><Value>13</Value><Unit>kWh</Unit><PerUnit>month</PerUnit><StartDate>2010-07-16T10:44:00-04:00</StartDate><ItemValueDefinition uid="068A0D6D03F7"><Path>energyConsumption</Path><Name>Energy Consumption</Name><ValueDefinition created="2007-07-27 08:30:44.0" modified="2007-07-27 08:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>kWh</Unit><PerUnit>year</PerUnit><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition></ItemValue><ItemValue uid="1CA0D40208F0"><Path>includesHeating</Path><Name>Includes Heating</Name><Value>false</Value><Unit/><PerUnit/><StartDate>2010-07-16T10:44:00-04:00</StartDate><ItemValueDefinition uid="1740E500BDAB"><Path>includesHeating</Path><Name>Includes Heating</Name><ValueDefinition created="2007-07-27 08:30:44.0" modified="2007-07-27 08:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition></ItemValue><ItemValue uid="1ACEB4784A42"><Path>season</Path><Name>Season</Name><Value/><Unit/><PerUnit/><StartDate>2010-07-16T10:44:00-04:00</StartDate><ItemValueDefinition uid="527AADFB3B65"><Path>season</Path><Name>Season</Name><ValueDefinition created="2007-07-27 08:30:44.0" modified="2007-07-27 08:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition></ItemValue><ItemValue uid="036262B5D69D"><Path>greenTariff</Path><Name>Green tariff</Name><Value/><Unit/><PerUnit/><StartDate>2010-07-16T10:44:00-04:00</StartDate><ItemValueDefinition uid="63005554AE8A"><Path>greenTariff</Path><Name>Green tariff</Name><ValueDefinition created="2007-07-27 08:30:44.0" modified="2007-07-27 08:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition></ItemValue><ItemValue uid="A568643CD1D7"><Path>paymentFrequency</Path><Name>Payment frequency</Name><Value/><Unit/><PerUnit/><StartDate>2010-07-16T10:44:00-04:00</StartDate><ItemValueDefinition uid="E0EFED6FD7E6"><Path>paymentFrequency</Path><Name>Payment frequency</Name><ValueDefinition created="2007-07-27 08:30:44.0" modified="2007-07-27 08:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition></ItemValue><ItemValue uid="990F69A6BD48"><Path>massPerTime</Path><Name>Mass Per Time</Name><Value>0</Value><Unit>kg</Unit><PerUnit>year</PerUnit><StartDate>2010-07-16T10:44:00-04:00</StartDate><ItemValueDefinition uid="CF12B3EBAD02"><Path>massPerTime</Path><Name>Mass Per Time</Name><ValueDefinition created="2007-07-27 08:30:44.0" modified="2007-07-27 08:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>kg</Unit><PerUnit>year</PerUnit><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition></ItemValue><ItemValue uid="A5BB73E6CBD2"><Path>lastReading</Path><Name>Last Reading</Name><Value>0</Value><Unit>kWh</Unit><PerUnit>year</PerUnit><StartDate>2010-07-16T10:44:00-04:00</StartDate><ItemValueDefinition uid="40AB7E90980C"><Path>lastReading</Path><Name>Last Reading</Name><ValueDefinition created="2007-07-27 08:30:44.0" modified="2007-07-27 08:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>kWh</Unit><PerUnit>year</PerUnit><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition></ItemValue><ItemValue uid="DA93374B62C2"><Path>volumePerTime</Path><Name>Volume Per Time</Name><Value>0</Value><Unit>L</Unit><PerUnit>year</PerUnit><StartDate>2010-07-16T10:44:00-04:00</StartDate><ItemValueDefinition uid="324EC808AC30"><Path>volumePerTime</Path><Name>Volume Per Time</Name><ValueDefinition created="2007-07-27 08:30:44.0" modified="2007-07-27 08:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>L</Unit><PerUnit>year</PerUnit><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition></ItemValue><ItemValue uid="FA09F1FF043D"><Path>deliveries</Path><Name>Number of deliveries</Name><Value/><Unit/><PerUnit>year</PerUnit><StartDate>2010-07-16T10:44:00-04:00</StartDate><ItemValueDefinition uid="177D4642A07A"><Path>deliveries</Path><Name>Number of deliveries</Name><ValueDefinition created="2007-07-27 08:30:44.0" modified="2007-07-27 08:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><PerUnit>year</PerUnit><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition></ItemValue></ItemValues><Amount unit="kg/year">31.7772</Amount><Amounts><Amount default="true" perUnit="year" type="CO2" unit="kg">31.7772</Amount><Amount type="CH4" unit="kg">4.2</Amount><Note type="comment">This is a text node</Note><Note type="comment">This is another text node</Note></Amounts><StartDate>2010-07-16T10:44:00-04:00</StartDate><EndDate/><DataItem uid="66056991EE23"><Label>gas</Label></DataItem></ProfileItem></ProfileItems><Pager><Start>0</Start><From>1</From><To>1</To><Items>1</Items><CurrentPage>1</CurrentPage><RequestedPage>1</RequestedPage><NextPage>-1</NextPage><PreviousPage>-1</PreviousPage><LastPage>1</LastPage><ItemsPerPage>10</ItemsPerPage><ItemsFound>1</ItemsFound></Pager><TotalAmount unit="kg/year">31.7772</TotalAmount></ProfileCategoryResource></Resources>'))
222
+ @cat = AMEE::Profile::Category.get(connection, "/profiles/F8C2D1052BF7/home/energy/quantity")
223
+ @cat.total_amount.should be_close(31.7772, 1e-4)
224
+ @cat.total_amount_unit.should == 'kg/year'
225
+ item = @cat.items[0]
226
+ item[:amounts].size.should be(2)
227
+ item[:amounts][0][:type].should == "CO2"
228
+ item[:amounts][0][:value].should be_close(31.7772, 1e-4)
229
+ item[:amounts][0][:unit].should == 'kg'
230
+ item[:amounts][0][:per_unit].should == 'year'
231
+ item[:amounts][0][:default].should be_true
232
+ item[:amounts][1][:type].should == "CH4"
233
+ item[:amounts][1][:value].should be_close(4.2, 1e-2)
234
+ item[:amounts][1][:unit].should == 'kg'
235
+ item[:amounts][1][:per_unit].should be_nil
236
+ item[:notes].size.should be(2)
237
+ item[:notes][0][:type].should == 'comment'
238
+ item[:notes][0][:value].should == 'This is a text node'
239
+ item[:notes][1][:type].should == 'comment'
240
+ item[:notes][1][:value].should == 'This is another text node'
241
+ end
242
+
243
+ it "should fail gracefully with incorrect data" do
244
+ connection = flexmock "connection"
245
+ connection.should_receive(:version).and_return(2.0)
246
+ xml = '<?xml version="1.0" encoding="UTF-8"?><Resources xmlns="http://schemas.amee.cc/2.0"></Resources>'
247
+ connection.should_receive(:get).with("/profiles/E54C5525AA3E", {}).and_return(flexmock(:body => xml))
248
+ lambda{AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E")}.should raise_error(AMEE::BadData)
249
+ end
250
+
251
+ # it "parses recursive GET requests" do
252
+ # connection = flexmock "connection"
253
+ # connection.should_receive(:version).and_return(2.0)
254
+ # connection.should_receive(:get).with("/profiles/BE22C1732952/transport/car", {:recurse=>true}).and_return('')
255
+ # cat = AMEE::Profile::Category.get(connection, "/profiles/BE22C1732952/transport/car", :recurse => true)
256
+ # cat.items.size.should == 0
257
+ # cat.children.size.should == 3
258
+ # cat.children[1][:name].should == "Generic"
259
+ # cat.children[1][:path].should == "generic"
260
+ # cat.children[1][:uid].should == "87E55DA88017"
261
+ # cat.children[1][:totalAmountPerMonth].should == 0.265
262
+ # cat.children[1][:children].size.should == 1
263
+ # cat.children[1][:children][0][:name].should == "Electric"
264
+ # cat.children[1][:children][0][:path].should == "electric"
265
+ # cat.children[1][:children][0][:uid].should == "417DD367E9AA"
266
+ # cat.children[1][:items].size.should == 1
267
+ # cat.children[1][:items][0][:amountPerMonth].should == 0.265
268
+ # cat.children[1][:items][0][:dataItemLabel].should == "diesel, large"
269
+ # cat.children[1][:items][0][:dataItemUid].should == "4F6CBCEE95F7"
270
+ # cat.children[1][:items][0][:values][:airconTypical].should == "true"
271
+ # cat.children[1][:items][0][:uid].should == "8450D6D97D2D"
272
+ # end
273
+
274
+ end
275
+
276
+ describe AMEE::Profile::Category, "with an authenticated version 2 Atom connection" do
277
+
278
+ it "should load Profile Category" do
279
+ connection = flexmock "connection"
280
+ connection.should_receive(:version).and_return(2.0)
281
+ connection.should_receive(:get).with("/profiles/FD89B8D07D4F/home", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?> <feed xmlns="http://www.w3.org/2005/Atom" xmlns:amee="http://schemas.amee.cc/2.0" xml:lang="en-US" xml:base="http://dev.amee.com/profiles/FD89B8D07D4F/home"> <title type="text">Profile FD89B8D07D4F, Category Home</title> <id>urn:dataCategory:BBA3AC3E795E</id> <generator version="2.0" uri="http://www.amee.cc">AMEE</generator> <link href="" type="application/atom+xml" rel="edit" /> <link href="" type="application/json" rel="alternate" /> <link href="" type="application/xml" rel="alternate" /> <author> <name>FD89B8D07D4F</name> </author> <amee:name>Home</amee:name> <amee:totalAmount unit="kg/year">0.000000</amee:totalAmount> <updated>1970-01-01T00:00:00.000Z</updated> </feed>'))
282
+ @cat = AMEE::Profile::Category.get(connection, "/profiles/FD89B8D07D4F/home")
283
+ @cat.profile_uid.should == "FD89B8D07D4F"
284
+ @cat.name.should == "Home"
285
+ @cat.path.should == "/home"
286
+ @cat.full_path.should == "/profiles/FD89B8D07D4F/home"
287
+ #@cat.children.size.should be(6)
288
+ #@cat.children[0][:uid].should == "427DFCC65E52"
289
+ #@cat.children[0][:name].should == "Appliances"
290
+ #@cat.children[0][:path].should == "appliances"
291
+ end
292
+
293
+ it "should parse data items" do
294
+ connection = flexmock "connection"
295
+ connection.should_receive(:version).and_return(2.0)
296
+ connection.should_receive(:get).with("/profiles/9BFB0C1CD78A/home/energy/quantity", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:amee="http://schemas.amee.cc/2.0" xml:lang="en-US" xml:base="http://dev.amee.com/profiles/9BFB0C1CD78A/home/energy/quantity"><title type="text">Profile 9BFB0C1CD78A, Category /home/energy/quantity</title><id>urn:dataCategory:A92693A99BAD</id><generator version="2.0" uri="http://www.amee.cc">AMEE</generator><link href="" type="application/atom+xml" rel="edit" /><link href="" type="application/json" rel="alternate" /><link href="" type="application/xml" rel="alternate" /><author><name>9BFB0C1CD78A</name></author><amee:name>Quantity</amee:name><amee:totalAmount unit="kg/year">1265.664</amee:totalAmount><updated>2009-02-11T14:13:28.000Z</updated><entry><title type="text">gas</title><subtitle type="text">Tue, 2 Sep 2008 01:00:00 BST</subtitle><link href="30C00AD33033" type="application/atom+xml" rel="edit" /><link href="30C00AD33033" type="application/json" rel="alternate" /><link href="30C00AD33033" type="application/xml" rel="alternate" /><id>urn:item:30C00AD33033</id><published>2008-09-02T00:00:00.000Z</published><updated>2008-09-02T00:00:00.000Z</updated><amee:startDate>2008-09-02T01:00+0100</amee:startDate><amee:amount unit="kg/year">29.664</amee:amount><amee:itemValue><amee:name>Payment frequency</amee:name><amee:value>N/A</amee:value><link href="30C00AD33033/paymentFrequency" rel="http://schemas.amee.cc/2.0#itemValue" /></amee:itemValue><amee:itemValue><amee:name>Green tariff</amee:name><amee:value>N/A</amee:value><link href="30C00AD33033/greenTariff" rel="http://schemas.amee.cc/2.0#itemValue" /></amee:itemValue><amee:itemValue><amee:name>Season</amee:name><amee:value>N/A</amee:value><link href="30C00AD33033/season" rel="http://schemas.amee.cc/2.0#itemValue" /></amee:itemValue><amee:itemValue><amee:name>Includes Heating</amee:name><amee:value>false</amee:value><link href="30C00AD33033/includesHeating" rel="http://schemas.amee.cc/2.0#itemValue" /></amee:itemValue><amee:itemValue><amee:name>Mass Per Time</amee:name><amee:value>N/A</amee:value><link href="30C00AD33033/massPerTime" rel="http://schemas.amee.cc/2.0#itemValue" /><amee:unit>kg</amee:unit><amee:perUnit>year</amee:perUnit></amee:itemValue><amee:itemValue><amee:name>Energy Consumption</amee:name><amee:value>13</amee:value><link href="30C00AD33033/energyConsumption" rel="http://schemas.amee.cc/2.0#itemValue" /><amee:unit>kWh</amee:unit><amee:perUnit>month</amee:perUnit></amee:itemValue><amee:itemValue><amee:name>Current Reading</amee:name><amee:value>N/A</amee:value><link href="30C00AD33033/currentReading" rel="http://schemas.amee.cc/2.0#itemValue" /><amee:unit>kWh</amee:unit></amee:itemValue><amee:itemValue><amee:name>Last Reading</amee:name><amee:value>N/A</amee:value><link href="30C00AD33033/lastReading" rel="http://schemas.amee.cc/2.0#itemValue" /><amee:unit>kWh</amee:unit></amee:itemValue><amee:itemValue><amee:name>Volume Per Time</amee:name><amee:value>N/A</amee:value><link href="30C00AD33033/volumePerTime" rel="http://schemas.amee.cc/2.0#itemValue" /><amee:unit>L</amee:unit><amee:perUnit>year</amee:perUnit></amee:itemValue><amee:itemValue><amee:name>Number of deliveries</amee:name><amee:value>N/A</amee:value><link href="30C00AD33033/deliveries" rel="http://schemas.amee.cc/2.0#itemValue" /><amee:unit>year</amee:unit></amee:itemValue><amee:name>gas</amee:name><content type="html">&lt;div class="vevent">&lt;div class="summary">0.000 kg/year&lt;/div>&lt;abbr class="dtstart" title="2008-09-02T01:00+0100"> Tue, 2 Sep 2008 01:00:00 BST&lt;/abbr>&lt;/div></content><category scheme="http://schemas.amee.cc/2.0#item" term="66056991EE23" label="Energy Quantity" /></entry><entry><title type="text">BC0B730255FB</title><subtitle type="text">Wed, 11 Feb 2009 14:13:00 GMT</subtitle><link href="BC0B730255FB" type="application/atom+xml" rel="edit" /><link href="BC0B730255FB" type="application/json" rel="alternate" /><link href="BC0B730255FB" type="application/xml" rel="alternate" /><id>urn:item:BC0B730255FB</id><published>2009-02-11T14:13:00.000Z</published><updated>2009-02-11T14:13:00.000Z</updated><amee:startDate>2009-02-11T14:13+0000</amee:startDate><amee:amount unit="kg/year">0.000</amee:amount><amee:itemValue><amee:name>Payment frequency</amee:name><amee:value>N/A</amee:value><link href="BC0B730255FB/paymentFrequency" rel="http://schemas.amee.cc/2.0#itemValue" /></amee:itemValue><amee:itemValue><amee:name>Green tariff</amee:name><amee:value>N/A</amee:value><link href="BC0B730255FB/greenTariff" rel="http://schemas.amee.cc/2.0#itemValue" /></amee:itemValue><amee:itemValue><amee:name>Season</amee:name><amee:value>N/A</amee:value><link href="BC0B730255FB/season" rel="http://schemas.amee.cc/2.0#itemValue" /></amee:itemValue><amee:itemValue><amee:name>Includes Heating</amee:name><amee:value>false</amee:value><link href="BC0B730255FB/includesHeating" rel="http://schemas.amee.cc/2.0#itemValue" /></amee:itemValue><amee:itemValue><amee:name>Mass Per Time</amee:name><amee:value>N/A</amee:value><link href="BC0B730255FB/massPerTime" rel="http://schemas.amee.cc/2.0#itemValue" /><amee:unit>kg</amee:unit><amee:perUnit>year</amee:perUnit></amee:itemValue><amee:itemValue><amee:name>Energy Consumption</amee:name><amee:value>N/A</amee:value><link href="BC0B730255FB/energyConsumption" rel="http://schemas.amee.cc/2.0#itemValue" /><amee:unit>kWh</amee:unit><amee:perUnit>year</amee:perUnit></amee:itemValue><amee:itemValue><amee:name>Current Reading</amee:name><amee:value>N/A</amee:value><link href="BC0B730255FB/currentReading" rel="http://schemas.amee.cc/2.0#itemValue" /><amee:unit>kWh</amee:unit></amee:itemValue><amee:itemValue><amee:name>Last Reading</amee:name><amee:value>N/A</amee:value><link href="BC0B730255FB/lastReading" rel="http://schemas.amee.cc/2.0#itemValue" /><amee:unit>kWh</amee:unit></amee:itemValue><amee:itemValue><amee:name>Volume Per Time</amee:name><amee:value>N/A</amee:value><link href="BC0B730255FB/volumePerTime" rel="http://schemas.amee.cc/2.0#itemValue" /><amee:unit>L</amee:unit><amee:perUnit>year</amee:perUnit></amee:itemValue><amee:itemValue><amee:name>Number of deliveries</amee:name><amee:value>N/A</amee:value><link href="BC0B730255FB/deliveries" rel="http://schemas.amee.cc/2.0#itemValue" /><amee:unit>year</amee:unit></amee:itemValue><amee:name></amee:name><content type="html">&lt;div class="vevent">&lt;div class="summary">0.000 kg/year&lt;/div>&lt;abbr class="dtstart" title="2009-02-11T14:13+0000"> Wed, 11 Feb 2009 14:13:00 GMT&lt;/abbr>&lt;/div></content><category scheme="http://schemas.amee.cc/2.0#item" term="A70149AF0F26" label="Energy Quantity" /></entry></feed>'))
297
+ @cat = AMEE::Profile::Category.get(connection, "/profiles/9BFB0C1CD78A/home/energy/quantity")
298
+ @cat.total_amount.should be_close(1265.664, 1e-9)
299
+ @cat.total_amount_unit.should == "kg/year"
300
+ @cat.items.size.should be(2)
301
+ @cat.items[0][:uid].should == "30C00AD33033"
302
+ @cat.items[0][:name].should == "gas"
303
+ @cat.items[0][:path].should == "30C00AD33033"
304
+ #@cat.items[0][:dataItemLabel].should == "gas"
305
+ #@cat.items[0][:dataItemUid].should == "66056991EE23"
306
+ @cat.items[0][:startDate].should == DateTime.new(2008, 9, 2)
307
+ @cat.items[0][:endDate].should be_nil
308
+ @cat.items[0][:amount].should be_close(29.664, 1e-9)
309
+ @cat.items[0][:amount_unit].should == "kg/year"
310
+ @cat.items[0][:values].size.should be(10)
311
+ @cat.items[0][:values][:energyConsumption][:value].should == "13"
312
+ @cat.items[0][:values][:energyConsumption][:unit].should == "kWh"
313
+ @cat.items[0][:values][:energyConsumption][:per_unit].should == "month"
314
+ @cat.items[0][:values][:massPerTime][:value].should == "0"
315
+ @cat.items[0][:values][:volumePerTime][:value].should == "0"
316
+ end
317
+
318
+ it "should fail gracefully with incorrect data" do
319
+ connection = flexmock "connection"
320
+ connection.should_receive(:version).and_return(2.0)
321
+ atom = '<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:amee="http://schemas.amee.cc/2.0"></feed>'
322
+ connection.should_receive(:get).with("/profiles/E54C5525AA3E", {}).and_return(flexmock(:body => atom))
323
+ lambda{AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E")}.should raise_error(AMEE::BadData)
324
+ end
325
+
326
+ # it "parses recursive GET requests" do
327
+ # connection = flexmock "connection"
328
+ # connection.should_receive(:version).and_return(2.0)
329
+ # connection.should_receive(:get).with("/profiles/BE22C1732952/transport/car", {:recurse=>true}).and_return(flexmock(:body => ''))
330
+ # cat = AMEE::Profile::Category.get(connection, "/profiles/BE22C1732952/transport/car", :recurse => true)
331
+ # cat.items.size.should == 0
332
+ # cat.children.size.should == 3
333
+ # cat.children[1][:name].should == "Generic"
334
+ # cat.children[1][:path].should == "generic"
335
+ # cat.children[1][:uid].should == "87E55DA88017"
336
+ # cat.children[1][:totalAmountPerMonth].should == 0.265
337
+ # cat.children[1][:children].size.should == 1
338
+ # cat.children[1][:children][0][:name].should == "Electric"
339
+ # cat.children[1][:children][0][:path].should == "electric"
340
+ # cat.children[1][:children][0][:uid].should == "417DD367E9AA"
341
+ # cat.children[1][:items].size.should == 1
342
+ # cat.children[1][:items][0][:amountPerMonth].should == 0.265
343
+ # cat.children[1][:items][0][:dataItemLabel].should == "diesel, large"
344
+ # cat.children[1][:items][0][:dataItemUid].should == "4F6CBCEE95F7"
345
+ # cat.children[1][:items][0][:values][:airconTypical].should == "true"
346
+ # cat.children[1][:items][0][:uid].should == "8450D6D97D2D"
347
+ # end
348
+
349
+ end
350
+
351
+ describe AMEE::Profile::Category, "with an authenticated JSON connection" do
352
+
353
+ it "should load Profile Category" do
354
+ connection = flexmock "connection"
355
+ connection.should_receive(:version).and_return(1.0)
356
+ connection.should_receive(:get).with("/profiles/E54C5525AA3E/home", {}).and_return(flexmock(:body => '{"totalAmountPerMonth":"0","dataCategory":{"uid":"BBA3AC3E795E","path":"home","name":"Home"},"profileDate":"200809","path":"/home","profile":{"uid":"E54C5525AA3E"},"children":{"pager":{},"dataCategories":[{"uid":"427DFCC65E52","path":"appliances","name":"Appliances"},{"uid":"30BA55A0C472","path":"energy","name":"Energy"},{"uid":"A46ECFA19333","path":"heating","name":"Heating"},{"uid":"150266DD4434","path":"lighting","name":"Lighting"}],"profileItems":{}}}'))
357
+ @cat = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home")
358
+ @cat.profile_uid.should == "E54C5525AA3E"
359
+ @cat.profile_date.should == DateTime.new(2008, 9)
360
+ @cat.name.should == "Home"
361
+ @cat.path.should == "/home"
362
+ @cat.full_path.should == "/profiles/E54C5525AA3E/home"
363
+ @cat.children.size.should be(4)
364
+ @cat.children[0][:uid].should == "427DFCC65E52"
365
+ @cat.children[0][:name].should == "Appliances"
366
+ @cat.children[0][:path].should == "appliances"
367
+ @cat.pager.should be_nil
368
+ end
369
+
370
+ it "should provide access to child objects" do
371
+ connection = flexmock "connection"
372
+ connection.should_receive(:version).and_return(1.0)
373
+ connection.should_receive(:get).with("/profiles/E54C5525AA3E/home", {}).and_return(flexmock(:body => '{"totalAmountPerMonth":"0","dataCategory":{"uid":"BBA3AC3E795E","path":"home","name":"Home"},"profileDate":"200809","path":"/home","profile":{"uid":"E54C5525AA3E"},"children":{"pager":{},"dataCategories":[{"uid":"427DFCC65E52","path":"appliances","name":"Appliances"},{"uid":"30BA55A0C472","path":"energy","name":"Energy"},{"uid":"A46ECFA19333","path":"heating","name":"Heating"},{"uid":"150266DD4434","path":"lighting","name":"Lighting"}],"profileItems":{}}}'))
374
+ connection.should_receive(:get).with("/profiles/E54C5525AA3E/home/appliances", {}).and_return(flexmock(:body => '{"totalAmountPerMonth":"0","dataCategory":{"uid":"427DFCC65E52","path":"appliances","name":"Appliances"},"profileDate":"200809","path":"/home/appliances","profile":{"uid":"E54C5525AA3E"},"children":{"pager":{},"dataCategories":[{"uid":"3FE23FDC8CEA","path":"computers","name":"Computers"},{"uid":"54C8A44254AA","path":"cooking","name":"Cooking"},{"uid":"75AD9B83B7BF","path":"entertainment","name":"Entertainment"},{"uid":"4BD595E1873A","path":"kitchen","name":"Kitchen"},{"uid":"700D0771870A","path":"televisions","name":"Televisions"}],"profileItems":{}}}'))
375
+ @cat = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home")
376
+ @child = @cat.child('appliances')
377
+ @child.path.should == "/home/appliances"
378
+ @child.full_path.should == "/profiles/E54C5525AA3E/home/appliances"
379
+ @child.children.size.should be(5)
380
+ @child.pager.should be_nil
381
+ end
382
+
383
+ it "should parse data items" do
384
+ connection = flexmock "connection"
385
+ connection.should_receive(:version).and_return(1.0)
386
+ connection.should_receive(:get).with("/profiles/E54C5525AA3E/home/energy/quantity", {}).and_return(flexmock(:body => '{"totalAmountPerMonth":105.472,"dataCategory":{"uid":"A92693A99BAD","path":"quantity","name":"Quantity"},"profileDate":"200809","path":"/home/energy/quantity","profile":{"uid":"E54C5525AA3E"},"children":{"pager":{"to":2,"lastPage":1,"start":0,"nextPage":-1,"items":2,"itemsPerPage":10,"from":1,"previousPage":-1,"requestedPage":1,"currentPage":1,"itemsFound":2},"dataCategories":[],"profileItems":{"rows":[{"created":"2008-09-03 11:37:35.0","kgPerMonth":"0","dataItemLabel":"gas","end":"false","uid":"FB07247AD937","modified":"2008-09-03 11:38:12.0","dataItemUid":"66056991EE23","validFrom":"20080902","amountPerMonth":"2.472","label":"ProfileItem","litresPerMonth":"0","path":"FB07247AD937","kWhPerMonth":"12","name":"gas"},{"created":"2008-09-03 11:40:44.0","kgPerMonth":"0","dataItemLabel":"gas","end":"false","uid":"D9CBCDED44C5","modified":"2008-09-03 11:41:54.0","dataItemUid":"66056991EE23","validFrom":"20080901","amountPerMonth":"103.000","label":"ProfileItem","litresPerMonth":"0","path":"D9CBCDED44C5","kWhPerMonth":"500","name":"gas2"}],"label":"ProfileItems"}}}'))
387
+ @cat = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
388
+ @cat.total_amount.should be_close(105.472, 1e-9)
389
+ @cat.total_amount_unit.should == "kg/month"
390
+ @cat.items.size.should be(2)
391
+ @cat.items[0][:uid].should == "FB07247AD937"
392
+ @cat.items[0][:name].should == "gas"
393
+ @cat.items[0][:path].should == "FB07247AD937"
394
+ @cat.items[0][:dataItemLabel].should == "gas"
395
+ @cat.items[0][:dataItemUid].should == "66056991EE23"
396
+ @cat.items[0][:validFrom].should == DateTime.new(2008, 9, 2)
397
+ @cat.items[0][:end].should == false
398
+ @cat.items[0][:amountPerMonth].should be_close(2.472, 1e-9)
399
+ @cat.items[0][:values].size.should be(3)
400
+ @cat.items[0][:values][:kWhPerMonth].should == "12"
401
+ @cat.items[0][:values][:kgPerMonth].should == "0"
402
+ @cat.items[0][:values][:litresPerMonth].should == "0"
403
+ @cat.pager.should_not be_nil
404
+ end
405
+
406
+ it "should fail gracefully with incorrect data" do
407
+ connection = flexmock "connection"
408
+ json = '{"apiVersion":"2.0"}'
409
+ connection.should_receive(:get).with("/profiles/E54C5525AA3E", {}).and_return(flexmock(:body => json))
410
+ lambda{AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E")}.should raise_error(AMEE::BadData)
411
+ end
412
+
413
+ it "parses recursive GET requests" do
414
+ connection = flexmock "connection"
415
+ connection.should_receive(:version).and_return(1.0)
416
+ connection.should_receive(:get).with("/profiles/BE22C1732952/transport/car", {:recurse => true}).and_return(flexmock(:body => '{"totalAmountPerMonth":"0","dataCategory":{"uid":"1D95119FB149","path":"car","name":"Car"},"profileDate":"200901","path":"/transport/car","profile":{"uid":"BE22C1732952"},"children":{"pager":{},"dataCategories":[{"dataCategory":{"modified":"2008-04-21 16:42:10.0","created":"2008-04-21 16:42:10.0","itemDefinition":{"uid":"C6BC60C55678"},"dataCategory":{"uid":"1D95119FB149","path":"car","name":"Car"},"uid":"883ADD27228F","environment":{"uid":"5F5887BCF726"},"path":"bands","name":"Bands"},"path":"/transport/car/bands"},{"totalAmountPerMonth":0.265,"dataCategory":{"modified":"2007-07-27 09:30:44.0","created":"2007-07-27 09:30:44.0","itemDefinition":{"uid":"123C4A18B5D6"},"dataCategory":{"uid":"1D95119FB149","path":"car","name":"Car"},"uid":"87E55DA88017","environment":{"uid":"5F5887BCF726"},"path":"generic","name":"Generic"},"path":"/transport/car/generic","children":{"dataCategories":[{"dataCategory":{"modified":"2008-09-23 12:18:03.0","created":"2008-09-23 12:18:03.0","itemDefinition":{"uid":"E6D0BB09578A"},"dataCategory":{"uid":"87E55DA88017","path":"generic","name":"Generic"},"uid":"417DD367E9AA","environment":{"uid":"5F5887BCF726"},"path":"electric","name":"Electric"},"path":"/transport/car/generic/electric"}],"profileItems":{"rows":[{"created":"2009-01-05 13:58:52.0","ecoDriving":"false","tyresUnderinflated":"false","dataItemLabel":"diesel, large","kmPerLitre":"0","distanceKmPerMonth":"1","end":"false","uid":"8450D6D97D2D","modified":"2009-01-05 13:59:05.0","airconFull":"false","dataItemUid":"4F6CBCEE95F7","validFrom":"20090101","amountPerMonth":"0.265","kmPerLitreOwn":"0","country":"","label":"ProfileItem","occupants":"-1","airconTypical":"true","path":"8450D6D97D2D","name":"","regularlyServiced":"true"}],"label":"ProfileItems"}}},{"dataCategory":{"modified":"2007-07-27 09:30:44.0","created":"2007-07-27 09:30:44.0","itemDefinition":{"uid":"07EBA32512DF"},"dataCategory":{"uid":"1D95119FB149","path":"car","name":"Car"},"uid":"95E76249584D","environment":{"uid":"5F5887BCF726"},"path":"specific","name":"Specific"},"path":"/transport/car/specific"}],"profileItems":{}}}'))
417
+ cat = AMEE::Profile::Category.get(connection, "/profiles/BE22C1732952/transport/car", :recurse => true)
418
+ cat.items.size.should == 0
419
+ cat.children.size.should == 3
420
+ cat.children[1][:name].should == "Generic"
421
+ cat.children[1][:path].should == "generic"
422
+ cat.children[1][:uid].should == "87E55DA88017"
423
+ cat.children[1][:totalAmountPerMonth].should == 0.265
424
+ cat.children[1][:children].size.should == 1
425
+ cat.children[1][:children][0][:name].should == "Electric"
426
+ cat.children[1][:children][0][:path].should == "electric"
427
+ cat.children[1][:children][0][:uid].should == "417DD367E9AA"
428
+ cat.children[1][:items].size.should == 1
429
+ cat.children[1][:items][0][:amountPerMonth].should == 0.265
430
+ cat.children[1][:items][0][:dataItemLabel].should == "diesel, large"
431
+ cat.children[1][:items][0][:dataItemUid].should == "4F6CBCEE95F7"
432
+ cat.children[1][:items][0][:values][:airconTypical].should == "true"
433
+ cat.children[1][:items][0][:uid].should == "8450D6D97D2D"
434
+ cat.pager.should be_nil
435
+ end
436
+
437
+ end
438
+
439
+ describe AMEE::Profile::Category, "with an authenticated V2 JSON connection" do
440
+
441
+ it "should load Profile Category" do
442
+ connection = flexmock "connection"
443
+ connection.should_receive(:version).and_return(2.0)
444
+ connection.should_receive(:get).with("/profiles/447C40EB29FB/home", {}).and_return(flexmock(:body => '{"apiVersion":"2.0","pager":{},"profileCategories":[{"uid":"427DFCC65E52","name":"Appliances","path":"appliances"},{"uid":"30BA55A0C472","name":"Energy","path":"energy"},{"uid":"A46ECFA19333","name":"Heating","path":"heating"},{"uid":"150266DD4434","name":"Lighting","path":"lighting"},{"uid":"6553150F96CE","name":"Waste","path":"waste"},{"uid":"07362DCC9E7B","name":"Water","path":"water"}],"dataCategory":{"uid":"BBA3AC3E795E","dataCategory":{"uid":"CD310BEBAC52","name":"Root","path":""},"environment":{"uid":"5F5887BCF726","itemsPerFeed":10,"description":"","name":"AMEE","owner":"","path":"","itemsPerPage":10},"created":"2007-07-27 09:30:44.0","name":"Home","path":"home","modified":"2007-07-27 09:30:44.0"},"environment":{"uid":"5F5887BCF726","itemsPerFeed":10,"created":"2007-07-27 09:30:44.0","description":"","name":"AMEE","owner":"","path":"","itemsPerPage":10,"modified":"2007-07-27 09:30:44.0"},"totalAmount":"0","path":"/home","profileItemActions":{"allowCreate":true,"allowView":true,"allowList":true,"allowModify":true,"allowDelete":true},"actions":{"allowCreate":true,"allowView":true,"allowList":true,"allowModify":true,"allowDelete":true},"profileItems":{},"profile":{"uid":"447C40EB29FB"}}'))
445
+ @cat = AMEE::Profile::Category.get(connection, "/profiles/447C40EB29FB/home")
446
+ @cat.profile_uid.should == "447C40EB29FB"
447
+ @cat.name.should == "Home"
448
+ @cat.path.should == "/home"
449
+ @cat.full_path.should == "/profiles/447C40EB29FB/home"
450
+ @cat.children.size.should be(6)
451
+ @cat.children[0][:uid].should == "427DFCC65E52"
452
+ @cat.children[0][:name].should == "Appliances"
453
+ @cat.children[0][:path].should == "appliances"
454
+ @cat.pager.should be_nil
455
+ end
456
+
457
+ it "should provide access to child objects" do
458
+ connection = flexmock "connection"
459
+ connection.should_receive(:version).and_return(2.0)
460
+ connection.should_receive(:get).with("/profiles/447C40EB29FB/home", {}).and_return(flexmock(:body => '{"apiVersion":"2.0","pager":{},"profileCategories":[{"uid":"427DFCC65E52","name":"Appliances","path":"appliances"},{"uid":"30BA55A0C472","name":"Energy","path":"energy"},{"uid":"A46ECFA19333","name":"Heating","path":"heating"},{"uid":"150266DD4434","name":"Lighting","path":"lighting"},{"uid":"6553150F96CE","name":"Waste","path":"waste"},{"uid":"07362DCC9E7B","name":"Water","path":"water"}],"dataCategory":{"uid":"BBA3AC3E795E","dataCategory":{"uid":"CD310BEBAC52","name":"Root","path":""},"environment":{"uid":"5F5887BCF726","itemsPerFeed":10,"description":"","name":"AMEE","owner":"","path":"","itemsPerPage":10},"created":"2007-07-27 09:30:44.0","name":"Home","path":"home","modified":"2007-07-27 09:30:44.0"},"environment":{"uid":"5F5887BCF726","itemsPerFeed":10,"created":"2007-07-27 09:30:44.0","description":"","name":"AMEE","owner":"","path":"","itemsPerPage":10,"modified":"2007-07-27 09:30:44.0"},"totalAmount":"0","path":"/home","profileItemActions":{"allowCreate":true,"allowView":true,"allowList":true,"allowModify":true,"allowDelete":true},"actions":{"allowCreate":true,"allowView":true,"allowList":true,"allowModify":true,"allowDelete":true},"profileItems":{},"profile":{"uid":"447C40EB29FB"}}'))
461
+ connection.should_receive(:get).with("/profiles/447C40EB29FB/home/appliances", {}).and_return(flexmock(:body => '{"apiVersion":"2.0","pager":{},"profileCategories":[{"uid":"3FE23FDC8CEA","name":"Computers","path":"computers"},{"uid":"54C8A44254AA","name":"Cooking","path":"cooking"},{"uid":"75AD9B83B7BF","name":"Entertainment","path":"entertainment"},{"uid":"4BD595E1873A","name":"Kitchen","path":"kitchen"},{"uid":"700D0771870A","name":"Televisions","path":"televisions"}],"dataCategory":{"uid":"427DFCC65E52","dataCategory":{"uid":"BBA3AC3E795E","name":"Home","path":"home"},"environment":{"uid":"5F5887BCF726","itemsPerFeed":10,"description":"","name":"AMEE","owner":"","path":"","itemsPerPage":10},"created":"2007-07-27 09:30:44.0","name":"Appliances","path":"appliances","modified":"2007-07-27 09:30:44.0"},"environment":{"uid":"5F5887BCF726","itemsPerFeed":10,"created":"2007-07-27 09:30:44.0","description":"","name":"AMEE","owner":"","path":"","itemsPerPage":10,"modified":"2007-07-27 09:30:44.0"},"totalAmount":"0","path":"/home/appliances","profileItemActions":{"allowCreate":true,"allowView":true,"allowList":true,"allowModify":true,"allowDelete":true},"actions":{"allowCreate":true,"allowView":true,"allowList":true,"allowModify":true,"allowDelete":true},"profileItems":{},"profile":{"uid":"447C40EB29FB"}}'))
462
+ @cat = AMEE::Profile::Category.get(connection, "/profiles/447C40EB29FB/home")
463
+ @child = @cat.child('appliances')
464
+ @child.path.should == "/home/appliances"
465
+ @child.full_path.should == "/profiles/447C40EB29FB/home/appliances"
466
+ @child.children.size.should be(5)
467
+ @child.pager.should be_nil
468
+ end
469
+
470
+ it "should parse data items" do
471
+ connection = flexmock "connection"
472
+ connection.should_receive(:version).and_return(2.0)
473
+ connection.should_receive(:get).with("/profiles/447C40EB29FB/home/energy/quantity", {}).and_return(flexmock(:body => '{"apiVersion":"2.0","pager":{"to":1,"lastPage":1,"nextPage":-1,"items":1,"start":0,"itemsFound":1,"requestedPage":1,"currentPage":1,"from":1,"itemsPerPage":10,"previousPage":-1},"profileCategories":[],"dataCategory":{"uid":"A92693A99BAD","dataCategory":{"uid":"30BA55A0C472","deprecated":false,"name":"Energy","path":"energy"},"deprecated":false,"environment":{"uid":"5F5887BCF726","itemsPerFeed":10,"description":"","name":"AMEE","owner":"","path":"","itemsPerPage":10},"created":"2007-07-27 08:30:44.0","name":"Quantity","path":"quantity","itemDefinition":{"uid":"212C818D8F16","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","name":"Energy Quantity","drillDown":"type","modified":"2007-07-27 08:30:44.0"},"modified":"2007-07-27 08:30:44.0"},"environment":{"uid":"5F5887BCF726","itemsPerFeed":10,"created":"2007-07-27 08:30:44.0","description":"","name":"AMEE","owner":"","path":"","itemsPerPage":10,"modified":"2007-07-27 08:30:44.0"},"totalAmount":{"unit":"kg/year","value":"31.7772"},"path":"/home/energy/quantity","profileItems":[{"amount":{"unit":"kg/year","value":31.7772},"uid":"B3D15D776EB9","startDate":"2010-06-28T13:14:00-04:00","itemValues":[{"itemValueDefinition":{"perUnit":"year","uid":"67B7476423C0","unit":"kWh","name":"Current Reading","fromData":false,"path":"currentReading","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"year","uid":"048EE4994F5B","startDate":"2010-06-28T13:14:00-04:00","unit":"kWh","name":"Current Reading","value":"0","path":"currentReading","displayPath":"currentReading","displayName":"Current Reading"},{"itemValueDefinition":{"perUnit":"year","uid":"068A0D6D03F7","unit":"kWh","name":"Energy Consumption","fromData":false,"path":"energyConsumption","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"month","uid":"2E52C3842819","startDate":"2010-06-28T13:14:00-04:00","unit":"kWh","name":"Energy Consumption","value":"13","path":"energyConsumption","displayPath":"energyConsumption","displayName":"Energy Consumption"},{"itemValueDefinition":{"uid":"1740E500BDAB","choices":"true=true,false=false","name":"Includes Heating","fromData":false,"path":"includesHeating","fromProfile":true,"valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"","uid":"98D6B86F928E","startDate":"2010-06-28T13:14:00-04:00","unit":"","name":"Includes Heating","value":"false","path":"includesHeating","displayPath":"includesHeating","displayName":"Includes Heating"},{"itemValueDefinition":{"uid":"527AADFB3B65","name":"Season","fromData":false,"path":"season","fromProfile":true,"valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"","uid":"142422F25D4E","startDate":"2010-06-28T13:14:00-04:00","unit":"","name":"Season","value":"","path":"season","displayPath":"season","displayName":"Season"},{"itemValueDefinition":{"uid":"63005554AE8A","name":"Green tariff","fromData":false,"path":"greenTariff","fromProfile":true,"valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"","uid":"3BBD254BA9BA","startDate":"2010-06-28T13:14:00-04:00","unit":"","name":"Green tariff","value":"","path":"greenTariff","displayPath":"greenTariff","displayName":"Green tariff"},{"itemValueDefinition":{"uid":"E0EFED6FD7E6","name":"Payment frequency","fromData":false,"path":"paymentFrequency","fromProfile":true,"valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"","uid":"4E57D4DEFC2A","startDate":"2010-06-28T13:14:00-04:00","unit":"","name":"Payment frequency","value":"","path":"paymentFrequency","displayPath":"paymentFrequency","displayName":"Payment frequency"},{"itemValueDefinition":{"perUnit":"year","uid":"CF12B3EBAD02","unit":"kg","name":"Mass Per Time","fromData":false,"path":"massPerTime","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"year","uid":"F0AE74C87EEE","startDate":"2010-06-28T13:14:00-04:00","unit":"kg","name":"Mass Per Time","value":"0","path":"massPerTime","displayPath":"massPerTime","displayName":"Mass Per Time"},{"itemValueDefinition":{"perUnit":"year","uid":"40AB7E90980C","unit":"kWh","name":"Last Reading","fromData":false,"path":"lastReading","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"year","uid":"99B9FDA5D1A8","startDate":"2010-06-28T13:14:00-04:00","unit":"kWh","name":"Last Reading","value":"0","path":"lastReading","displayPath":"lastReading","displayName":"Last Reading"},{"itemValueDefinition":{"perUnit":"year","uid":"177D4642A07A","name":"Number of deliveries","fromData":false,"path":"deliveries","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"year","uid":"EE0151C2C22C","startDate":"2010-06-28T13:14:00-04:00","unit":"","name":"Number of deliveries","value":"","path":"deliveries","displayPath":"deliveries","displayName":"Number of deliveries"},{"itemValueDefinition":{"perUnit":"year","uid":"324EC808AC30","unit":"L","name":"Volume Per Time","fromData":false,"path":"volumePerTime","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"year","uid":"35B94788B050","startDate":"2010-06-28T13:14:00-04:00","unit":"L","name":"Volume Per Time","value":"0","path":"volumePerTime","displayPath":"volumePerTime","displayName":"Volume Per Time"}],"amounts":{"amount":[{"perUnit":"year","unit":"kg","default":"true","value":31.7772,"type":"CO2"}]},"created":"2010-06-28T17:14:18Z","name":"gas","endDate":"","dataItem":{"uid":"66056991EE23","Label":"gas"},"modified":"2010-06-28T17:40:35Z"}],"profile":{"uid":"B6FB1C01BAA7"}}'))
474
+ @cat = AMEE::Profile::Category.get(connection, "/profiles/447C40EB29FB/home/energy/quantity")
475
+ @cat.total_amount.should be_close(31.7772, 1e-9)
476
+ @cat.total_amount_unit.should == "kg/year"
477
+ @cat.items.size.should be(1)
478
+ @cat.items[0][:uid].should == "B3D15D776EB9"
479
+ @cat.items[0][:name].should == "gas"
480
+ @cat.items[0][:path].should == "B3D15D776EB9"
481
+ @cat.items[0][:dataItemLabel].should == "gas"
482
+ @cat.items[0][:dataItemUid].should == "66056991EE23"
483
+ @cat.items[0][:startDate].should == DateTime.new(2010, 6, 28, 17, 14)
484
+ @cat.items[0][:endDate].should be_nil
485
+ @cat.items[0][:amount].should be_close(31.7772, 1e-9)
486
+ @cat.items[0][:amount_unit].should == "kg/year"
487
+ @cat.items[0][:values].size.should be(10)
488
+ @cat.items[0][:values][:energyConsumption][:value].should == "13"
489
+ @cat.items[0][:values][:energyConsumption][:unit].should == "kWh"
490
+ @cat.items[0][:values][:energyConsumption][:per_unit].should == "month"
491
+ @cat.items[0][:values][:massPerTime][:value].should == "0"
492
+ @cat.items[0][:values][:volumePerTime][:value].should == "0"
493
+ @cat.pager.should_not be_nil
494
+ end
495
+
496
+ it "should parse multiple return values" do
497
+ connection = flexmock "connection"
498
+ connection.should_receive(:version).and_return(2.0)
499
+ connection.should_receive(:get).with("/profiles/F8C2D1052BF7/home/energy/quantity", {}).and_return(flexmock(:body => '{"apiVersion":"2.0","pager":{"to":1,"lastPage":1,"nextPage":-1,"items":1,"start":0,"itemsFound":1,"requestedPage":1,"currentPage":1,"from":1,"itemsPerPage":10,"previousPage":-1},"profileCategories":[],"dataCategory":{"uid":"A92693A99BAD","dataCategory":{"uid":"30BA55A0C472","deprecated":false,"name":"Energy","path":"energy"},"deprecated":false,"environment":{"uid":"5F5887BCF726","itemsPerFeed":10,"description":"","name":"AMEE","owner":"","path":"","itemsPerPage":10},"created":"2007-07-27 08:30:44.0","name":"Quantity","path":"quantity","itemDefinition":{"uid":"212C818D8F16","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","name":"Energy Quantity","drillDown":"type","modified":"2007-07-27 08:30:44.0"},"modified":"2007-07-27 08:30:44.0"},"environment":{"uid":"5F5887BCF726","itemsPerFeed":10,"created":"2007-07-27 08:30:44.0","description":"","name":"AMEE","owner":"","path":"","itemsPerPage":10,"modified":"2007-07-27 08:30:44.0"},"totalAmount":{"unit":"kg/year","value":"31.7772"},"path":"/home/energy/quantity","profileItems":[{"amount":{"unit":"kg/year","value":31.7772},"uid":"3BCDB0BB2B96","startDate":"2010-07-16T10:44:00-04:00","itemValues":[{"itemValueDefinition":{"perUnit":"year","uid":"67B7476423C0","unit":"kWh","name":"Current Reading","fromData":false,"path":"currentReading","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"year","uid":"06F553CED9F7","startDate":"2010-07-16T10:44:00-04:00","unit":"kWh","name":"Current Reading","value":"0","path":"currentReading","displayPath":"currentReading","displayName":"Current Reading"},{"itemValueDefinition":{"perUnit":"year","uid":"068A0D6D03F7","unit":"kWh","name":"Energy Consumption","fromData":false,"path":"energyConsumption","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"month","uid":"4CF7691084DB","startDate":"2010-07-16T10:44:00-04:00","unit":"kWh","name":"Energy Consumption","value":"13","path":"energyConsumption","displayPath":"energyConsumption","displayName":"Energy Consumption"},{"itemValueDefinition":{"uid":"1740E500BDAB","choices":"true=true,false=false","name":"Includes Heating","fromData":false,"path":"includesHeating","fromProfile":true,"valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"","uid":"1CA0D40208F0","startDate":"2010-07-16T10:44:00-04:00","unit":"","name":"Includes Heating","value":"false","path":"includesHeating","displayPath":"includesHeating","displayName":"Includes Heating"},{"itemValueDefinition":{"uid":"527AADFB3B65","name":"Season","fromData":false,"path":"season","fromProfile":true,"valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"","uid":"1ACEB4784A42","startDate":"2010-07-16T10:44:00-04:00","unit":"","name":"Season","value":"","path":"season","displayPath":"season","displayName":"Season"},{"itemValueDefinition":{"uid":"63005554AE8A","name":"Green tariff","fromData":false,"path":"greenTariff","fromProfile":true,"valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"","uid":"036262B5D69D","startDate":"2010-07-16T10:44:00-04:00","unit":"","name":"Green tariff","value":"","path":"greenTariff","displayPath":"greenTariff","displayName":"Green tariff"},{"itemValueDefinition":{"uid":"E0EFED6FD7E6","name":"Payment frequency","fromData":false,"path":"paymentFrequency","fromProfile":true,"valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"","uid":"A568643CD1D7","startDate":"2010-07-16T10:44:00-04:00","unit":"","name":"Payment frequency","value":"","path":"paymentFrequency","displayPath":"paymentFrequency","displayName":"Payment frequency"},{"itemValueDefinition":{"perUnit":"year","uid":"CF12B3EBAD02","unit":"kg","name":"Mass Per Time","fromData":false,"path":"massPerTime","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"year","uid":"990F69A6BD48","startDate":"2010-07-16T10:44:00-04:00","unit":"kg","name":"Mass Per Time","value":"0","path":"massPerTime","displayPath":"massPerTime","displayName":"Mass Per Time"},{"itemValueDefinition":{"perUnit":"year","uid":"40AB7E90980C","unit":"kWh","name":"Last Reading","fromData":false,"path":"lastReading","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"year","uid":"A5BB73E6CBD2","startDate":"2010-07-16T10:44:00-04:00","unit":"kWh","name":"Last Reading","value":"0","path":"lastReading","displayPath":"lastReading","displayName":"Last Reading"},{"itemValueDefinition":{"perUnit":"year","uid":"324EC808AC30","unit":"L","name":"Volume Per Time","fromData":false,"path":"volumePerTime","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"year","uid":"DA93374B62C2","startDate":"2010-07-16T10:44:00-04:00","unit":"L","name":"Volume Per Time","value":"0","path":"volumePerTime","displayPath":"volumePerTime","displayName":"Volume Per Time"},{"itemValueDefinition":{"perUnit":"year","uid":"177D4642A07A","name":"Number of deliveries","fromData":false,"path":"deliveries","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"year","uid":"FA09F1FF043D","startDate":"2010-07-16T10:44:00-04:00","unit":"","name":"Number of deliveries","value":"","path":"deliveries","displayPath":"deliveries","displayName":"Number of deliveries"}],"amounts":{"amount":[{"perUnit":"year","unit":"kg","default":"true","value":31.7772,"type":"CO2"},{"type":"CH4","unit":"kg","value":4.2}],"note":[{"type" : "comment","value" : "This is a text node"},{"type" : "comment","value" : "This is another text node"}]},"created":"2010-07-16T14:44:43Z","name":"gas","endDate":"","dataItem":{"uid":"66056991EE23","Label":"gas"},"modified":"2010-07-16T14:45:03Z"}],"profile":{"uid":"F8C2D1052BF7"}}'))
500
+ @cat = AMEE::Profile::Category.get(connection, "/profiles/F8C2D1052BF7/home/energy/quantity")
501
+ @cat.total_amount.should be_close(31.7772, 1e-4)
502
+ @cat.total_amount_unit.should == 'kg/year'
503
+ item = @cat.items[0]
504
+ item[:amounts].size.should be(2)
505
+ item[:amounts][0][:type].should == "CO2"
506
+ item[:amounts][0][:value].should be_close(31.7772, 1e-4)
507
+ item[:amounts][0][:unit].should == 'kg'
508
+ item[:amounts][0][:per_unit].should == 'year'
509
+ item[:amounts][0][:default].should be_true
510
+ item[:amounts][1][:type].should == "CH4"
511
+ item[:amounts][1][:value].should be_close(4.2, 1e-2)
512
+ item[:amounts][1][:unit].should == 'kg'
513
+ item[:amounts][1][:per_unit].should be_nil
514
+ item[:notes].size.should be(2)
515
+ item[:notes][0][:type].should == 'comment'
516
+ item[:notes][0][:value].should == 'This is a text node'
517
+ item[:notes][1][:type].should == 'comment'
518
+ item[:notes][1][:value].should == 'This is another text node'
519
+ end
520
+
521
+ #
522
+ # it "should fail gracefully with incorrect data" do
523
+ # connection = flexmock "connection"
524
+ # connection.should_receive(:get).with("/profiles/E54C5525AA3E", {}).and_return('{}'))
525
+ # lambda{AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E")}.should raise_error(AMEE::BadData)
526
+ # end
527
+
528
+ # it "parses recursive GET requests" do
529
+ # connection = flexmock "connection"
530
+ # connection.should_receive(:version).and_return(2.0)
531
+ # connection.should_receive(:get).with("/profiles/BE22C1732952/transport/car", {:recurse => true}).and_return('{"totalAmountPerMonth":"0","dataCategory":{"uid":"1D95119FB149","path":"car","name":"Car"},"profileDate":"200901","path":"/transport/car","profile":{"uid":"BE22C1732952"},"children":{"pager":{},"dataCategories":[{"dataCategory":{"modified":"2008-04-21 16:42:10.0","created":"2008-04-21 16:42:10.0","itemDefinition":{"uid":"C6BC60C55678"},"dataCategory":{"uid":"1D95119FB149","path":"car","name":"Car"},"uid":"883ADD27228F","environment":{"uid":"5F5887BCF726"},"path":"bands","name":"Bands"},"path":"/transport/car/bands"},{"totalAmountPerMonth":0.265,"dataCategory":{"modified":"2007-07-27 09:30:44.0","created":"2007-07-27 09:30:44.0","itemDefinition":{"uid":"123C4A18B5D6"},"dataCategory":{"uid":"1D95119FB149","path":"car","name":"Car"},"uid":"87E55DA88017","environment":{"uid":"5F5887BCF726"},"path":"generic","name":"Generic"},"path":"/transport/car/generic","children":{"dataCategories":[{"dataCategory":{"modified":"2008-09-23 12:18:03.0","created":"2008-09-23 12:18:03.0","itemDefinition":{"uid":"E6D0BB09578A"},"dataCategory":{"uid":"87E55DA88017","path":"generic","name":"Generic"},"uid":"417DD367E9AA","environment":{"uid":"5F5887BCF726"},"path":"electric","name":"Electric"},"path":"/transport/car/generic/electric"}],"profileItems":{"rows":[{"created":"2009-01-05 13:58:52.0","ecoDriving":"false","tyresUnderinflated":"false","dataItemLabel":"diesel, large","kmPerLitre":"0","distanceKmPerMonth":"1","end":"false","uid":"8450D6D97D2D","modified":"2009-01-05 13:59:05.0","airconFull":"false","dataItemUid":"4F6CBCEE95F7","validFrom":"20090101","amountPerMonth":"0.265","kmPerLitreOwn":"0","country":"","label":"ProfileItem","occupants":"-1","airconTypical":"true","path":"8450D6D97D2D","name":"","regularlyServiced":"true"}],"label":"ProfileItems"}}},{"dataCategory":{"modified":"2007-07-27 09:30:44.0","created":"2007-07-27 09:30:44.0","itemDefinition":{"uid":"07EBA32512DF"},"dataCategory":{"uid":"1D95119FB149","path":"car","name":"Car"},"uid":"95E76249584D","environment":{"uid":"5F5887BCF726"},"path":"specific","name":"Specific"},"path":"/transport/car/specific"}],"profileItems":{}}}'))
532
+ # cat = AMEE::Profile::Category.get(connection, "/profiles/BE22C1732952/transport/car", :recurse => true)
533
+ # cat.items.size.should == 0
534
+ # cat.children.size.should == 3
535
+ # cat.children[1][:name].should == "Generic"
536
+ # cat.children[1][:path].should == "generic"
537
+ # cat.children[1][:uid].should == "87E55DA88017"
538
+ # cat.children[1][:totalAmountPerMonth].should == 0.265
539
+ # cat.children[1][:children].size.should == 1
540
+ # cat.children[1][:children][0][:name].should == "Electric"
541
+ # cat.children[1][:children][0][:path].should == "electric"
542
+ # cat.children[1][:children][0][:uid].should == "417DD367E9AA"
543
+ # cat.children[1][:items].size.should == 1
544
+ # cat.children[1][:items][0][:amountPerMonth].should == 0.265
545
+ # cat.children[1][:items][0][:dataItemLabel].should == "diesel, large"
546
+ # cat.children[1][:items][0][:dataItemUid].should == "4F6CBCEE95F7"
547
+ # cat.children[1][:items][0][:values][:airconTypical].should == "true"
548
+ # cat.children[1][:items][0][:uid].should == "8450D6D97D2D"
549
+ # end
550
+
551
+ end
552
+
553
+ describe AMEE::Profile::Category, "with an authenticated connection" do
554
+
555
+ it "allows direct access to ProfileItems" do
556
+
557
+ end
558
+
559
+ it "should fail gracefully on other GET errors" do
560
+ connection = flexmock "connection"
561
+ connection.should_receive(:get).with("/profiles/E54C5525AA3E", {}).and_raise("unidentified error")
562
+ lambda{AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E")}.should raise_error(AMEE::BadData)
563
+ end
564
+
565
+ end