amee 2.6.0 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
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,451 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe AMEE::Profile::Item do
4
+
5
+ before(:each) do
6
+ @item = AMEE::Profile::Item.new
7
+ end
8
+
9
+ it "should have common AMEE object properties" do
10
+ @item.is_a?(AMEE::Profile::Object).should be_true
11
+ end
12
+
13
+ it "should have values" do
14
+ @item.should respond_to(:values)
15
+ end
16
+
17
+ it "should initialize AMEE::Object data on creation" do
18
+ uid = 'ABCD1234'
19
+ @item = AMEE::Profile::Item.new(:uid => uid)
20
+ @item.uid.should == uid
21
+ end
22
+
23
+ it "can be created with hash of data" do
24
+ values = ["one", "two"]
25
+ @item = AMEE::Profile::Item.new(:values => values)
26
+ @item.values.should == values
27
+ end
28
+
29
+ it "should be able to create new profile items (XML)" do
30
+ connection = flexmock "connection"
31
+ connection.should_receive(:version).and_return(1.0)
32
+ 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>200901</ProfileDate><Profile uid="E54C5525AA3E"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><Children><ProfileCategories/><ProfileItems/><Pager><Start>0</Start><From>0</From><To>0</To><Items>0</Items><CurrentPage>1</CurrentPage><RequestedPage>1</RequestedPage><NextPage>-1</NextPage><PreviousPage>-1</PreviousPage><LastPage>1</LastPage><ItemsPerPage>10</ItemsPerPage><ItemsFound>0</ItemsFound></Pager></Children><TotalAmountPerMonth>0.000</TotalAmountPerMonth></ProfileCategoryResource></Resources>'))
33
+ connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :kWhPerMonth => "10").and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileCategoryResource><Path>/home/energy/quantity</Path><ProfileDate>200901</ProfileDate><Profile uid="E54C5525AA3E"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><ProfileItem uid="62BCC8C84D0C"><Name>62BCC8C84D0C</Name><ItemValues><ItemValue uid="D281CE71180D"><Path>kgPerMonth</Path><Name>kg Per Month</Name><Value>0</Value><ItemValueDefinition uid="51D072825D41"><Path>kgPerMonth</Path><Name>kg Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="36A771FC1D1A"><Name>kg</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="67DD1D3A00C4"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><Value>10</Value><ItemValueDefinition uid="4DF458FD0E4D"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="26A5C97D3728"><Name>kWh</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="2BEEF89EFCAB"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><Value>0</Value><ItemValueDefinition uid="C9B7E19269A5"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="06B8CFC5A521"><Name>litre</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="7C8968300299"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><Value>0</Value><ItemValueDefinition uid="8A468E75C8E8"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="F68E3F8F988B"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><Value>0</Value><ItemValueDefinition uid="2328DC7F23AE"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="1932882328F0"><Path>paymentFrequency</Path><Name>Payment frequency</Name><Value/><ItemValueDefinition uid="E0EFED6FD7E6"><Path>paymentFrequency</Path><Name>Payment frequency</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="826512435B43"><Path>greenTariff</Path><Name>Green tariff</Name><Value/><ItemValueDefinition uid="63005554AE8A"><Path>greenTariff</Path><Name>Green tariff</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="4D2D471F2F04"><Path>season</Path><Name>Season</Name><Value/><ItemValueDefinition uid="527AADFB3B65"><Path>season</Path><Name>Season</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="583D56F63CD5"><Path>includesHeating</Path><Name>Includes Heating</Name><Value>false</Value><ItemValueDefinition uid="1740E500BDAB"><Path>includesHeating</Path><Name>Includes Heating</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="95DF5F127142"><Path>numberOfDeliveries</Path><Name>Number of deliveries</Name><Value/><ItemValueDefinition uid="AA1D1C349119"><Path>numberOfDeliveries</Path><Name>Number of deliveries</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue></ItemValues><AmountPerMonth>2.060</AmountPerMonth><ValidFrom>20090101</ValidFrom><End>false</End><DataItem uid="66056991EE23"/></ProfileItem></ProfileCategoryResource></Resources>', :'[]' => nil))
34
+ connection.should_receive(:get).with("/profiles/E54C5525AA3E/home/energy/quantity/62BCC8C84D0C", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileItemResource><ProfileItem created="2009-01-28 23:35:00.0" modified="2009-01-28 23:35:00.0" uid="62BCC8C84D0C"><Name>62BCC8C84D0C</Name><ItemValues><ItemValue uid="95DF5F127142"><Path>numberOfDeliveries</Path><Name>Number of deliveries</Name><Value/><ItemValueDefinition uid="AA1D1C349119"><Path>numberOfDeliveries</Path><Name>Number of deliveries</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="4D2D471F2F04"><Path>season</Path><Name>Season</Name><Value/><ItemValueDefinition uid="527AADFB3B65"><Path>season</Path><Name>Season</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="583D56F63CD5"><Path>includesHeating</Path><Name>Includes Heating</Name><Value>false</Value><ItemValueDefinition uid="1740E500BDAB"><Path>includesHeating</Path><Name>Includes Heating</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="826512435B43"><Path>greenTariff</Path><Name>Green tariff</Name><Value/><ItemValueDefinition uid="63005554AE8A"><Path>greenTariff</Path><Name>Green tariff</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="1932882328F0"><Path>paymentFrequency</Path><Name>Payment frequency</Name><Value/><ItemValueDefinition uid="E0EFED6FD7E6"><Path>paymentFrequency</Path><Name>Payment frequency</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="F68E3F8F988B"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><Value>0</Value><ItemValueDefinition uid="2328DC7F23AE"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="7C8968300299"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><Value>0</Value><ItemValueDefinition uid="8A468E75C8E8"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="D281CE71180D"><Path>kgPerMonth</Path><Name>kg Per Month</Name><Value>0</Value><ItemValueDefinition uid="51D072825D41"><Path>kgPerMonth</Path><Name>kg Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="36A771FC1D1A"><Name>kg</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="67DD1D3A00C4"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><Value>10</Value><ItemValueDefinition uid="4DF458FD0E4D"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="26A5C97D3728"><Name>kWh</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="2BEEF89EFCAB"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><Value>0</Value><ItemValueDefinition uid="C9B7E19269A5"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="06B8CFC5A521"><Name>litre</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue></ItemValues><Environment uid="5F5887BCF726"/><ItemDefinition uid="212C818D8F16"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><AmountPerMonth>2.060</AmountPerMonth><ValidFrom>20090101</ValidFrom><End>false</End><DataItem uid="66056991EE23"/><Profile uid="E54C5525AA3E"/></ProfileItem><Path>/home/energy/quantity/62BCC8C84D0C</Path><Profile uid="E54C5525AA3E"/></ProfileItemResource></Resources>'))
35
+ category = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
36
+ item = AMEE::Profile::Item.create(category, '66056991EE23', :kWhPerMonth => "10")
37
+ item.value("kWhPerMonth").should eql "10"
38
+ item.total_amount.should be_close(2.06, 1e-9)
39
+ item.total_amount_unit.should == "kg/month"
40
+ end
41
+
42
+ it "should be able to create new profile items (JSON)" do
43
+ connection = flexmock "connection"
44
+ connection.should_receive(:version).and_return(1.0)
45
+ connection.should_receive(:get).with("/profiles/E54C5525AA3E/home/energy/quantity", {}).and_return(flexmock(:body => '{"totalAmountPerMonth":0,"dataCategory":{"uid":"A92693A99BAD","path":"quantity","name":"Quantity"},"profileDate":"200901","path":"/home/energy/quantity","profile":{"uid":"E54C5525AA3E"},"children":{"pager":{"to":0,"lastPage":1,"start":0,"nextPage":-1,"items":0,"itemsPerPage":10,"from":0,"previousPage":-1,"requestedPage":1,"currentPage":1,"itemsFound":0},"dataCategories":[],"profileItems":{"rows":[],"label":"ProfileItems"}}}'))
46
+ connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :kWhPerMonth => "10").and_return(flexmock(:body => '{"dataCategory":{"uid":"A92693A99BAD","path":"quantity","name":"Quantity"},"profileDate":"200901","path":"/home/energy/quantity","profile":{"uid":"E54C5525AA3E"},"profileItem":{"validFrom":"20090101","amountPerMonth":2.06,"itemValues":[{"value":"0","uid":"01591644B296","path":"kgPerMonth","name":"kg Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"36A771FC1D1A","name":"kg"},"uid":"51D072825D41","path":"kgPerMonth","name":"kg Per Month"}},{"value":"10","uid":"94B617C13137","path":"kWhPerMonth","name":"kWh Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"26A5C97D3728","name":"kWh"},"uid":"4DF458FD0E4D","path":"kWhPerMonth","name":"kWh Per Month"}},{"value":"0","uid":"1F5AF1A6BD65","path":"litresPerMonth","name":"Litres Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"06B8CFC5A521","name":"litre"},"uid":"C9B7E19269A5","path":"litresPerMonth","name":"Litres Per Month"}},{"value":"0","uid":"B2FBB1BFF60F","path":"kWhReadingCurrent","name":"kWh reading current","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"8A468E75C8E8","path":"kWhReadingCurrent","name":"kWh reading current"}},{"value":"0","uid":"A97ADD0FCB82","path":"kWhReadingLast","name":"kWh reading last","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"2328DC7F23AE","path":"kWhReadingLast","name":"kWh reading last"}},{"value":"","uid":"1D96093AD6D7","path":"paymentFrequency","name":"Payment frequency","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"E0EFED6FD7E6","path":"paymentFrequency","name":"Payment frequency"}},{"value":"","uid":"ED12DF35A1C3","path":"greenTariff","name":"Green tariff","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"63005554AE8A","path":"greenTariff","name":"Green tariff"}},{"value":"","uid":"9494FB0F7DE8","path":"season","name":"Season","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"527AADFB3B65","path":"season","name":"Season"}},{"value":"false","uid":"ECB936330FEF","path":"includesHeating","name":"Includes Heating","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"1740E500BDAB","path":"includesHeating","name":"Includes Heating"}},{"value":"","uid":"C85E51E8D26C","path":"numberOfDeliveries","name":"Number of deliveries","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"AA1D1C349119","path":"numberOfDeliveries","name":"Number of deliveries"}}],"end":"false","uid":"8C7BD1AB69D3","dataItem":{"uid":"66056991EE23"},"name":"8C7BD1AB69D3"}}', :'[]' => nil))
47
+ connection.should_receive(:get).with("/profiles/E54C5525AA3E/home/energy/quantity/8C7BD1AB69D3", {}).and_return(flexmock(:body => '{"path":"/home/energy/quantity/8C7BD1AB69D3","profile":{"uid":"E54C5525AA3E"},"profileItem":{"created":"2009-01-29 00:11:33.0","itemValues":[{"value":"","uid":"9494FB0F7DE8","path":"season","name":"Season","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"527AADFB3B65","path":"season","name":"Season"}},{"value":"false","uid":"ECB936330FEF","path":"includesHeating","name":"Includes Heating","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"1740E500BDAB","path":"includesHeating","name":"Includes Heating"}},{"value":"","uid":"C85E51E8D26C","path":"numberOfDeliveries","name":"Number of deliveries","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"AA1D1C349119","path":"numberOfDeliveries","name":"Number of deliveries"}},{"value":"","uid":"ED12DF35A1C3","path":"greenTariff","name":"Green tariff","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"63005554AE8A","path":"greenTariff","name":"Green tariff"}},{"value":"","uid":"1D96093AD6D7","path":"paymentFrequency","name":"Payment frequency","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"E0EFED6FD7E6","path":"paymentFrequency","name":"Payment frequency"}},{"value":"0","uid":"A97ADD0FCB82","path":"kWhReadingLast","name":"kWh reading last","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"2328DC7F23AE","path":"kWhReadingLast","name":"kWh reading last"}},{"value":"0","uid":"B2FBB1BFF60F","path":"kWhReadingCurrent","name":"kWh reading current","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"8A468E75C8E8","path":"kWhReadingCurrent","name":"kWh reading current"}},{"value":"0","uid":"01591644B296","path":"kgPerMonth","name":"kg Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"36A771FC1D1A","name":"kg"},"uid":"51D072825D41","path":"kgPerMonth","name":"kg Per Month"}},{"value":"0","uid":"1F5AF1A6BD65","path":"litresPerMonth","name":"Litres Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"06B8CFC5A521","name":"litre"},"uid":"C9B7E19269A5","path":"litresPerMonth","name":"Litres Per Month"}},{"value":"10","uid":"94B617C13137","path":"kWhPerMonth","name":"kWh Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"26A5C97D3728","name":"kWh"},"uid":"4DF458FD0E4D","path":"kWhPerMonth","name":"kWh Per Month"}}],"dataCategory":{"uid":"A92693A99BAD","path":"quantity","name":"Quantity"},"end":"false","uid":"8C7BD1AB69D3","environment":{"uid":"5F5887BCF726"},"profile":{"uid":"E54C5525AA3E"},"modified":"2009-01-29 00:11:33.0","validFrom":"20090101","amountPerMonth":2.06,"itemDefinition":{"uid":"212C818D8F16"},"dataItem":{"uid":"66056991EE23"},"name":"8C7BD1AB69D3"}}'))
48
+ category = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
49
+ item = AMEE::Profile::Item.create(category, '66056991EE23', :kWhPerMonth => "10")
50
+ item.value("kWhPerMonth").should eql "10"
51
+ item.total_amount.should be_close(2.06, 1e-9)
52
+ item.total_amount_unit.should == "kg/month"
53
+ end
54
+
55
+ it "should be able to create new profile items (V2 XML)" do
56
+ connection = flexmock "connection"
57
+ connection.should_receive(:version).and_return(2.0)
58
+ connection.should_receive(:get).with("/profiles/7V1FQMSWX64O/home/energy/quantity", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileCategoryResource><Path>/home/energy/quantity</Path><ProfileDate>200901</ProfileDate><Profile uid="7V1FQMSWX64O"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><Children><ProfileCategories/><ProfileItems/><Pager><Start>0</Start><From>0</From><To>0</To><Items>0</Items><CurrentPage>1</CurrentPage><RequestedPage>1</RequestedPage><NextPage>-1</NextPage><PreviousPage>-1</PreviousPage><LastPage>1</LastPage><ItemsPerPage>10</ItemsPerPage><ItemsFound>0</ItemsFound></Pager></Children><TotalAmountPerMonth>0.000</TotalAmountPerMonth></ProfileCategoryResource></Resources>'))
59
+ connection.should_receive(:post).with("/profiles/7V1FQMSWX64O/home/energy/quantity", :dataItemUid => '66056991EE23', :energyConsumption => "10", :representation => "full").and_return(flexmock(:body => fixture('create_item.xml'), :'[]' => 'http://example.server.com/profiles/7V1FQMSWX64O/home/energy/quantity/62BCC8C84D0C'))
60
+ category = AMEE::Profile::Category.get(connection, "/profiles/7V1FQMSWX64O/home/energy/quantity")
61
+ item = AMEE::Profile::Item.create(category, '66056991EE23', :energyConsumption => "10")
62
+ item.value("energyConsumption").should eql "10"
63
+ item.total_amount.should be_close(2.037, 1e-9)
64
+ item.total_amount_unit.should == "kg/year"
65
+ end
66
+
67
+ it "should be able to create new profile items (V2 JSON)" do
68
+ connection = flexmock "connection"
69
+ connection.should_receive(:version).and_return(2.0)
70
+ connection.should_receive(:get).with("/profiles/7V1FQMSWX64O/home/energy/quantity", {}).and_return(flexmock(:body => '{"totalAmountPerMonth":0,"dataCategory":{"uid":"A92693A99BAD","path":"quantity","name":"Quantity"},"profileDate":"200901","path":"/home/energy/quantity","profile":{"uid":"7V1FQMSWX64O"},"children":{"pager":{"to":0,"lastPage":1,"start":0,"nextPage":-1,"items":0,"itemsPerPage":10,"from":0,"previousPage":-1,"requestedPage":1,"currentPage":1,"itemsFound":0},"dataCategories":[],"profileItems":{"rows":[],"label":"ProfileItems"}}}'))
71
+ connection.should_receive(:post).with("/profiles/7V1FQMSWX64O/home/energy/quantity", :dataItemUid => '66056991EE23', :energyConsumption => "10", :representation => "full").and_return(flexmock(:body => fixture('create_item.json'), :'[]' => 'http://example.server.com/profiles/7V1FQMSWX64O/home/energy/quantity/8C7BD1AB69D3'))
72
+ category = AMEE::Profile::Category.get(connection, "/profiles/7V1FQMSWX64O/home/energy/quantity")
73
+ item = AMEE::Profile::Item.create(category, '66056991EE23', :energyConsumption => "10")
74
+ item.value("energyConsumption").should eql "10"
75
+ item.total_amount.should be_close(2.037, 1e-9)
76
+ item.total_amount_unit.should == "kg/year"
77
+ end
78
+
79
+ it "should be able to create new profile items and just get location of new resource (XML)" do
80
+ connection = flexmock "connection"
81
+ connection.should_receive(:version).and_return(1.0)
82
+ 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>200901</ProfileDate><Profile uid="E54C5525AA3E"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><Children><ProfileCategories/><ProfileItems/><Pager><Start>0</Start><From>0</From><To>0</To><Items>0</Items><CurrentPage>1</CurrentPage><RequestedPage>1</RequestedPage><NextPage>-1</NextPage><PreviousPage>-1</PreviousPage><LastPage>1</LastPage><ItemsPerPage>10</ItemsPerPage><ItemsFound>0</ItemsFound></Pager></Children><TotalAmountPerMonth>0.000</TotalAmountPerMonth></ProfileCategoryResource></Resources>'))
83
+ connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :kWhPerMonth => "10").and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileCategoryResource><Path>/home/energy/quantity</Path><ProfileDate>200901</ProfileDate><Profile uid="E54C5525AA3E"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><ProfileItem uid="62BCC8C84D0C"><Name>62BCC8C84D0C</Name><ItemValues><ItemValue uid="D281CE71180D"><Path>kgPerMonth</Path><Name>kg Per Month</Name><Value>0</Value><ItemValueDefinition uid="51D072825D41"><Path>kgPerMonth</Path><Name>kg Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="36A771FC1D1A"><Name>kg</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="67DD1D3A00C4"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><Value>10</Value><ItemValueDefinition uid="4DF458FD0E4D"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="26A5C97D3728"><Name>kWh</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="2BEEF89EFCAB"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><Value>0</Value><ItemValueDefinition uid="C9B7E19269A5"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="06B8CFC5A521"><Name>litre</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="7C8968300299"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><Value>0</Value><ItemValueDefinition uid="8A468E75C8E8"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="F68E3F8F988B"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><Value>0</Value><ItemValueDefinition uid="2328DC7F23AE"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="1932882328F0"><Path>paymentFrequency</Path><Name>Payment frequency</Name><Value/><ItemValueDefinition uid="E0EFED6FD7E6"><Path>paymentFrequency</Path><Name>Payment frequency</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="826512435B43"><Path>greenTariff</Path><Name>Green tariff</Name><Value/><ItemValueDefinition uid="63005554AE8A"><Path>greenTariff</Path><Name>Green tariff</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="4D2D471F2F04"><Path>season</Path><Name>Season</Name><Value/><ItemValueDefinition uid="527AADFB3B65"><Path>season</Path><Name>Season</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="583D56F63CD5"><Path>includesHeating</Path><Name>Includes Heating</Name><Value>false</Value><ItemValueDefinition uid="1740E500BDAB"><Path>includesHeating</Path><Name>Includes Heating</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="95DF5F127142"><Path>numberOfDeliveries</Path><Name>Number of deliveries</Name><Value/><ItemValueDefinition uid="AA1D1C349119"><Path>numberOfDeliveries</Path><Name>Number of deliveries</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue></ItemValues><AmountPerMonth>2.060</AmountPerMonth><ValidFrom>20090101</ValidFrom><End>false</End><DataItem uid="66056991EE23"/></ProfileItem></ProfileCategoryResource></Resources>', :'[]' => nil))
84
+ category = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
85
+ location = AMEE::Profile::Item.create(category, '66056991EE23', :kWhPerMonth => "10", :get_item => false)
86
+ location.should == "/profiles/E54C5525AA3E/home/energy/quantity/62BCC8C84D0C"
87
+ end
88
+
89
+ it "should be able to create new profile items and just get location of new resource (JSON)" do
90
+ connection = flexmock "connection"
91
+ connection.should_receive(:version).and_return(1.0)
92
+ connection.should_receive(:get).with("/profiles/E54C5525AA3E/home/energy/quantity", {}).and_return(flexmock(:body => '{"totalAmountPerMonth":0,"dataCategory":{"uid":"A92693A99BAD","path":"quantity","name":"Quantity"},"profileDate":"200901","path":"/home/energy/quantity","profile":{"uid":"E54C5525AA3E"},"children":{"pager":{"to":0,"lastPage":1,"start":0,"nextPage":-1,"items":0,"itemsPerPage":10,"from":0,"previousPage":-1,"requestedPage":1,"currentPage":1,"itemsFound":0},"dataCategories":[],"profileItems":{"rows":[],"label":"ProfileItems"}}}'))
93
+ connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :kWhPerMonth => "10").and_return(flexmock(:body => '{"dataCategory":{"uid":"A92693A99BAD","path":"quantity","name":"Quantity"},"profileDate":"200901","path":"/home/energy/quantity","profile":{"uid":"E54C5525AA3E"},"profileItem":{"validFrom":"20090101","amountPerMonth":2.06,"itemValues":[{"value":"0","uid":"01591644B296","path":"kgPerMonth","name":"kg Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"36A771FC1D1A","name":"kg"},"uid":"51D072825D41","path":"kgPerMonth","name":"kg Per Month"}},{"value":"10","uid":"94B617C13137","path":"kWhPerMonth","name":"kWh Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"26A5C97D3728","name":"kWh"},"uid":"4DF458FD0E4D","path":"kWhPerMonth","name":"kWh Per Month"}},{"value":"0","uid":"1F5AF1A6BD65","path":"litresPerMonth","name":"Litres Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"06B8CFC5A521","name":"litre"},"uid":"C9B7E19269A5","path":"litresPerMonth","name":"Litres Per Month"}},{"value":"0","uid":"B2FBB1BFF60F","path":"kWhReadingCurrent","name":"kWh reading current","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"8A468E75C8E8","path":"kWhReadingCurrent","name":"kWh reading current"}},{"value":"0","uid":"A97ADD0FCB82","path":"kWhReadingLast","name":"kWh reading last","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"2328DC7F23AE","path":"kWhReadingLast","name":"kWh reading last"}},{"value":"","uid":"1D96093AD6D7","path":"paymentFrequency","name":"Payment frequency","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"E0EFED6FD7E6","path":"paymentFrequency","name":"Payment frequency"}},{"value":"","uid":"ED12DF35A1C3","path":"greenTariff","name":"Green tariff","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"63005554AE8A","path":"greenTariff","name":"Green tariff"}},{"value":"","uid":"9494FB0F7DE8","path":"season","name":"Season","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"527AADFB3B65","path":"season","name":"Season"}},{"value":"false","uid":"ECB936330FEF","path":"includesHeating","name":"Includes Heating","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"1740E500BDAB","path":"includesHeating","name":"Includes Heating"}},{"value":"","uid":"C85E51E8D26C","path":"numberOfDeliveries","name":"Number of deliveries","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"AA1D1C349119","path":"numberOfDeliveries","name":"Number of deliveries"}}],"end":"false","uid":"8C7BD1AB69D3","dataItem":{"uid":"66056991EE23"},"name":"8C7BD1AB69D3"}}', :'[]' => nil))
94
+ category = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
95
+ location = AMEE::Profile::Item.create(category, '66056991EE23', :kWhPerMonth => "10", :get_item => false)
96
+ location.should == "/profiles/E54C5525AA3E/home/energy/quantity/8C7BD1AB69D3"
97
+ end
98
+
99
+ it "should be able to create new profile items and just get location of new resource (V2 XML)" do
100
+ connection = flexmock "connection"
101
+ connection.should_receive(:version).and_return(2.0)
102
+ 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>200901</ProfileDate><Profile uid="E54C5525AA3E"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><Children><ProfileCategories/><ProfileItems/><Pager><Start>0</Start><From>0</From><To>0</To><Items>0</Items><CurrentPage>1</CurrentPage><RequestedPage>1</RequestedPage><NextPage>-1</NextPage><PreviousPage>-1</PreviousPage><LastPage>1</LastPage><ItemsPerPage>10</ItemsPerPage><ItemsFound>0</ItemsFound></Pager></Children><TotalAmountPerMonth>0.000</TotalAmountPerMonth></ProfileCategoryResource></Resources>'))
103
+ connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :energyConsumption => "10").and_return(flexmock(:body => '', :'[]' => 'http://example.server.com/profiles/E54C5525AA3E/home/energy/quantity/62BCC8C84D0C'))
104
+ category = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
105
+ location = AMEE::Profile::Item.create(category, '66056991EE23', :energyConsumption => "10", :get_item => false)
106
+ location.should == "/profiles/E54C5525AA3E/home/energy/quantity/62BCC8C84D0C"
107
+ end
108
+
109
+ it "should be able to create new profile items and just get location of new resource (V2 JSON)" do
110
+ connection = flexmock "connection"
111
+ connection.should_receive(:version).and_return(2.0)
112
+ connection.should_receive(:get).with("/profiles/E54C5525AA3E/home/energy/quantity", {}).and_return(flexmock(:body => '{"totalAmountPerMonth":0,"dataCategory":{"uid":"A92693A99BAD","path":"quantity","name":"Quantity"},"profileDate":"200901","path":"/home/energy/quantity","profile":{"uid":"E54C5525AA3E"},"children":{"pager":{"to":0,"lastPage":1,"start":0,"nextPage":-1,"items":0,"itemsPerPage":10,"from":0,"previousPage":-1,"requestedPage":1,"currentPage":1,"itemsFound":0},"dataCategories":[],"profileItems":{"rows":[],"label":"ProfileItems"}}}'))
113
+ connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :energyConsumption => "10").and_return(flexmock(:body => '', :'[]' => 'http://example.server.com/profiles/E54C5525AA3E/home/energy/quantity/8C7BD1AB69D3'))
114
+ category = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
115
+ location = AMEE::Profile::Item.create(category, '66056991EE23', :energyConsumption => "10", :get_item => false)
116
+ location.should == "/profiles/E54C5525AA3E/home/energy/quantity/8C7BD1AB69D3"
117
+ end
118
+
119
+ it "should be able to create new profile items and just get location of new resource (V2 XML SSL)" do
120
+ connection = flexmock "connection"
121
+ connection.should_receive(:version).and_return(2.0)
122
+ 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>200901</ProfileDate><Profile uid="E54C5525AA3E"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><Children><ProfileCategories/><ProfileItems/><Pager><Start>0</Start><From>0</From><To>0</To><Items>0</Items><CurrentPage>1</CurrentPage><RequestedPage>1</RequestedPage><NextPage>-1</NextPage><PreviousPage>-1</PreviousPage><LastPage>1</LastPage><ItemsPerPage>10</ItemsPerPage><ItemsFound>0</ItemsFound></Pager></Children><TotalAmountPerMonth>0.000</TotalAmountPerMonth></ProfileCategoryResource></Resources>'))
123
+ connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :energyConsumption => "10").and_return(flexmock(:body => '', :'[]' => 'https://example.server.com/profiles/E54C5525AA3E/home/energy/quantity/62BCC8C84D0C'))
124
+ category = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
125
+ location = AMEE::Profile::Item.create(category, '66056991EE23', :energyConsumption => "10", :get_item => false)
126
+ location.should == "/profiles/E54C5525AA3E/home/energy/quantity/62BCC8C84D0C"
127
+ end
128
+
129
+ it "should be able to create new profile items and just get location of new resource (V2 JSON SSL)" do
130
+ connection = flexmock "connection"
131
+ connection.should_receive(:version).and_return(2.0)
132
+ connection.should_receive(:get).with("/profiles/E54C5525AA3E/home/energy/quantity", {}).and_return(flexmock(:body => '{"totalAmountPerMonth":0,"dataCategory":{"uid":"A92693A99BAD","path":"quantity","name":"Quantity"},"profileDate":"200901","path":"/home/energy/quantity","profile":{"uid":"E54C5525AA3E"},"children":{"pager":{"to":0,"lastPage":1,"start":0,"nextPage":-1,"items":0,"itemsPerPage":10,"from":0,"previousPage":-1,"requestedPage":1,"currentPage":1,"itemsFound":0},"dataCategories":[],"profileItems":{"rows":[],"label":"ProfileItems"}}}'))
133
+ connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :energyConsumption => "10").and_return(flexmock(:body => '', :'[]' => 'https://example.server.com/profiles/E54C5525AA3E/home/energy/quantity/8C7BD1AB69D3'))
134
+ category = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
135
+ location = AMEE::Profile::Item.create(category, '66056991EE23', :energyConsumption => "10", :get_item => false)
136
+ location.should == "/profiles/E54C5525AA3E/home/energy/quantity/8C7BD1AB69D3"
137
+ end
138
+
139
+ end
140
+
141
+ describe AMEE::Profile::Item, "with an authenticated XML connection" do
142
+
143
+ it "should load Profile Item" do
144
+ connection = flexmock "connection"
145
+ connection.should_receive(:version).and_return(1.0)
146
+ connection.should_receive(:get).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileItemResource><ProfileItem created="2008-09-12 17:20:32.0" modified="2008-09-12 17:20:32.0" uid="6E9B1517D753"><Name>6E9B1517D753</Name><ItemValues><ItemValue uid="0A671BF3D593"><Path>kgPerMonth</Path><Name>kg Per Month</Name><Value>10</Value><ItemValueDefinition uid="51D072825D41"><Path>kgPerMonth</Path><Name>kg Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="36A771FC1D1A"><Name>kg</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="0E4CF565A5AB"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><Value>0</Value><ItemValueDefinition uid="4DF458FD0E4D"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="26A5C97D3728"><Name>kWh</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="D58700708731"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><Value>0</Value><ItemValueDefinition uid="C9B7E19269A5"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="06B8CFC5A521"><Name>litre</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="BD1267F2D001"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><Value>0</Value><ItemValueDefinition uid="8A468E75C8E8"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="B199A908A259"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><Value>0</Value><ItemValueDefinition uid="2328DC7F23AE"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue></ItemValues><Environment uid="5F5887BCF726"/><ItemDefinition uid="212C818D8F16"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><AmountPerMonth>25.200</AmountPerMonth><ValidFrom>20080901</ValidFrom><End>false</End><DataItem uid="A70149AF0F26"/><Profile uid="92C8DB30F46B"/></ProfileItem><Path>/home/energy/quantity/6E9B1517D753</Path><Profile uid="92C8DB30F46B"/></ProfileItemResource></Resources>'))
147
+ @item = AMEE::Profile::Item.get(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")
148
+ @item.profile_uid.should == "92C8DB30F46B"
149
+ @item.uid.should == "6E9B1517D753"
150
+ @item.name.should == "6E9B1517D753"
151
+ @item.path.should == "/home/energy/quantity/6E9B1517D753"
152
+ @item.total_amount.should be_close(25.2, 1e-9)
153
+ @item.total_amount_unit.should == "kg/month"
154
+ @item.valid_from.should == DateTime.new(2008, 9, 1)
155
+ @item.end.should be_false
156
+ @item.full_path.should == "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753"
157
+ end
158
+
159
+ it "should parse values" do
160
+ connection = flexmock "connection"
161
+ connection.should_receive(:version).and_return(1.0)
162
+ connection.should_receive(:get).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileItemResource><ProfileItem created="2008-09-12 17:20:32.0" modified="2008-09-12 17:20:32.0" uid="6E9B1517D753"><Name>6E9B1517D753</Name><ItemValues><ItemValue uid="0A671BF3D593"><Path>kgPerMonth</Path><Name>kg Per Month</Name><Value>10</Value><ItemValueDefinition uid="51D072825D41"><Path>kgPerMonth</Path><Name>kg Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="36A771FC1D1A"><Name>kg</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="0E4CF565A5AB"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><Value>0</Value><ItemValueDefinition uid="4DF458FD0E4D"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="26A5C97D3728"><Name>kWh</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="D58700708731"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><Value>0</Value><ItemValueDefinition uid="C9B7E19269A5"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="06B8CFC5A521"><Name>litre</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="BD1267F2D001"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><Value>0</Value><ItemValueDefinition uid="8A468E75C8E8"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="B199A908A259"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><Value>0</Value><ItemValueDefinition uid="2328DC7F23AE"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue></ItemValues><Environment uid="5F5887BCF726"/><ItemDefinition uid="212C818D8F16"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><AmountPerMonth>25.200</AmountPerMonth><ValidFrom>20080901</ValidFrom><End>false</End><DataItem uid="A70149AF0F26"/><Profile uid="92C8DB30F46B"/></ProfileItem><Path>/home/energy/quantity/6E9B1517D753</Path><Profile uid="92C8DB30F46B"/></ProfileItemResource></Resources>'))
163
+ @item = AMEE::Profile::Item.get(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")
164
+ @item.values.size.should be(5)
165
+ @item.values[0][:uid].should == "0A671BF3D593"
166
+ @item.values[0][:name].should == "kg Per Month"
167
+ @item.values[0][:path].should == "kgPerMonth"
168
+ @item.values[0][:value].should == "10"
169
+ @item.values[1][:uid].should == "0E4CF565A5AB"
170
+ @item.values[1][:name].should == "kWh Per Month"
171
+ @item.values[1][:path].should == "kWhPerMonth"
172
+ @item.values[1][:value].should == "0"
173
+ end
174
+
175
+ it "should fail gracefully with incorrect data" do
176
+ connection = flexmock "connection"
177
+ connection.should_receive(:version).and_return(1.0)
178
+ xml = '<?xml version="1.0" encoding="UTF-8"?><Resources></Resources>'
179
+ connection.should_receive(:get).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => xml))
180
+ lambda{AMEE::Profile::Item.get(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")}.should raise_error(AMEE::BadData)
181
+ end
182
+
183
+ end
184
+
185
+ describe AMEE::Profile::Item, "with an authenticated V2 XML connection" do
186
+
187
+ it "should load Profile Item" do
188
+ connection = flexmock "connection"
189
+ connection.should_receive(:version).and_return(2.0)
190
+ connection.should_receive(:get).with("/profiles/9BFB0C1CD78A/home/energy/quantity/30C00AD33033", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?> <Resources xmlns="http://schemas.amee.cc/2.0"><ProfileItemResource><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>12</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><Environment uid="5F5887BCF726"/><ItemDefinition uid="212C818D8F16"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><Amount unit="kg/year">302.4</Amount><StartDate>2008-09-02T01:00+0100</StartDate><EndDate/><DataItem uid="66056991EE23"><Label>gas</Label></DataItem><Profile uid="9BFB0C1CD78A"/></ProfileItem><Path>/home/energy/quantity/30C00AD33033</Path><Profile uid="9BFB0C1CD78A"/></ProfileItemResource></Resources>'))
191
+ @item = AMEE::Profile::Item.get(connection, "/profiles/9BFB0C1CD78A/home/energy/quantity/30C00AD33033")
192
+ @item.profile_uid.should == "9BFB0C1CD78A"
193
+ @item.uid.should == "30C00AD33033"
194
+ @item.name.should == "gas"
195
+ @item.path.should == "/home/energy/quantity/30C00AD33033"
196
+ @item.total_amount.should be_close(302.4, 1e-9)
197
+ @item.total_amount_unit.should == "kg/year"
198
+ @item.start_date.should == DateTime.new(2008, 9, 2)
199
+ @item.full_path.should == "/profiles/9BFB0C1CD78A/home/energy/quantity/30C00AD33033"
200
+ end
201
+
202
+ it "should parse values" do
203
+ connection = flexmock "connection"
204
+ connection.should_receive(:version).and_return(2.0)
205
+ connection.should_receive(:get).with("/profiles/9BFB0C1CD78A/home/energy/quantity/30C00AD33033", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?> <Resources xmlns="http://schemas.amee.cc/2.0"><ProfileItemResource><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>12</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><Environment uid="5F5887BCF726"/><ItemDefinition uid="212C818D8F16"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><Amount unit="kg/year">302.4</Amount><StartDate>2008-09-02T01:00+0100</StartDate><EndDate/><DataItem uid="66056991EE23"><Label>gas</Label></DataItem><Profile uid="9BFB0C1CD78A"/></ProfileItem><Path>/home/energy/quantity/30C00AD33033</Path><Profile uid="9BFB0C1CD78A"/></ProfileItemResource></Resources>'))
206
+ @item = AMEE::Profile::Item.get(connection, "/profiles/9BFB0C1CD78A/home/energy/quantity/30C00AD33033")
207
+ @item.values.size.should be(10)
208
+ @item.values[4][:uid].should == "20FC928B045A"
209
+ @item.values[4][:name].should == "Mass Per Time"
210
+ @item.values[4][:path].should == "massPerTime"
211
+ @item.values[4][:value].should be_nil
212
+ @item.values[5][:uid].should == "3835DF705F9D"
213
+ @item.values[5][:name].should == "Energy Consumption"
214
+ @item.values[5][:path].should == "energyConsumption"
215
+ @item.values[5][:value].should == "12"
216
+ @item.values[5][:unit].should == "kWh"
217
+ @item.values[5][:per_unit].should == "month"
218
+ end
219
+
220
+ it "should parse multiple return values" do
221
+ connection = flexmock "connection"
222
+ connection.should_receive(:version).and_return(2.0)
223
+ connection.should_receive(:get).with("/profiles/F8C2D1052BF7/home/energy/quantity/3BCDB0BB2B96", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8" standalone="no"?><Resources xmlns="http://schemas.amee.cc/2.0"><ProfileItemResource><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><Environment uid="5F5887BCF726"/><ItemDefinition uid="212C818D8F16"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path><Deprecated>false</Deprecated></DataCategory><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><Profile uid="F8C2D1052BF7"/></ProfileItem><Path>/home/energy/quantity/3BCDB0BB2B96</Path><Profile uid="F8C2D1052BF7"/></ProfileItemResource></Resources>'))
224
+ @item = AMEE::Profile::Item.get(connection, "/profiles/F8C2D1052BF7/home/energy/quantity/3BCDB0BB2B96")
225
+ @item.total_amount.should be_close(31.7772, 1e-4)
226
+ @item.total_amount_unit.should == 'kg/year'
227
+ @item.amounts.size.should be(2)
228
+ @item.amounts[0][:type].should == "CO2"
229
+ @item.amounts[0][:value].should be_close(31.7772, 1e-4)
230
+ @item.amounts[0][:unit].should == 'kg'
231
+ @item.amounts[0][:per_unit].should == 'year'
232
+ @item.amounts[0][:default].should be_true
233
+ @item.amounts[1][:type].should == "CH4"
234
+ @item.amounts[1][:value].should be_close(4.2, 1e-2)
235
+ @item.amounts[1][:unit].should == 'kg'
236
+ @item.amounts[1][:per_unit].should be_nil
237
+ @item.notes.size.should be(2)
238
+ @item.notes[0][:type].should == 'comment'
239
+ @item.notes[0][:value].should == 'This is a text node'
240
+ @item.notes[1][:type].should == 'comment'
241
+ @item.notes[1][:value].should == 'This is another text node'
242
+ end
243
+
244
+ it "should fail gracefully with incorrect data" do
245
+ connection = flexmock "connection"
246
+ connection.should_receive(:version).and_return(2.0)
247
+ xml = '<?xml version="1.0" encoding="UTF-8"?> <Resources xmlns="http://schemas.amee.cc/2.0"></Resources>'
248
+ connection.should_receive(:get).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => xml))
249
+ lambda{AMEE::Profile::Item.get(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")}.should raise_error(AMEE::BadData)
250
+ end
251
+
252
+ end
253
+
254
+ describe AMEE::Profile::Item, "with an authenticated V2 ATOM connection" do
255
+
256
+ it "should load Profile Item" do
257
+ connection = flexmock "connection"
258
+ connection.should_receive(:version).and_return(2.0)
259
+ connection.should_receive(:get).with("/profiles/9BFB0C1CD78A/home/energy/quantity/30C00AD33033", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><entry 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/30C00AD33033"><title type="text">gas</title><subtitle type="text">Tue, 2 Sep 2008 01:00:00 BST</subtitle><link href="" type="application/atom+xml" rel="edit" /><link href="" type="application/json" rel="alternate" /><link href="" 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><content type="html">&lt;div class="vevent">&lt;div class="summary">302.4 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><amee:startDate>2008-09-02T01:00+0100</amee:startDate><amee:amount unit="kg/year">302.4</amee:amount><amee:itemValue><amee:name>Payment frequency</amee:name><amee:value>N/A</amee:value><link href="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="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="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="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="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="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="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="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="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="deliveries" rel="http://schemas.amee.cc/2.0#itemValue" /><amee:unit>year</amee:unit></amee:itemValue><category scheme="http://schemas.amee.cc/2.0#item" term="66056991EE23" label="Energy Quantity" /></entry>'))
260
+ @item = AMEE::Profile::Item.get(connection, "/profiles/9BFB0C1CD78A/home/energy/quantity/30C00AD33033")
261
+ @item.profile_uid.should == "9BFB0C1CD78A"
262
+ @item.uid.should == "30C00AD33033"
263
+ @item.name.should == "gas"
264
+ @item.path.should == "/home/energy/quantity/30C00AD33033"
265
+ @item.total_amount.should be_close(302.4, 1e-9)
266
+ @item.total_amount_unit.should == "kg/year"
267
+ @item.start_date.should == DateTime.new(2008, 9, 2)
268
+ @item.full_path.should == "/profiles/9BFB0C1CD78A/home/energy/quantity/30C00AD33033"
269
+ end
270
+
271
+ it "should parse values" do
272
+ connection = flexmock "connection"
273
+ connection.should_receive(:version).and_return(2.0)
274
+ connection.should_receive(:get).with("/profiles/9BFB0C1CD78A/home/energy/quantity/30C00AD33033", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><entry 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/30C00AD33033"><title type="text">gas</title><subtitle type="text">Tue, 2 Sep 2008 01:00:00 BST</subtitle><link href="" type="application/atom+xml" rel="edit" /><link href="" type="application/json" rel="alternate" /><link href="" 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><content type="html">&lt;div class="vevent">&lt;div class="summary">302.4 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><amee:startDate>2008-09-02T01:00+0100</amee:startDate><amee:amount unit="kg/year">302.4</amee:amount><amee:itemValue><amee:name>Payment frequency</amee:name><amee:value>N/A</amee:value><link href="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="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="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="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="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="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="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="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="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="deliveries" rel="http://schemas.amee.cc/2.0#itemValue" /><amee:unit>year</amee:unit></amee:itemValue><category scheme="http://schemas.amee.cc/2.0#item" term="66056991EE23" label="Energy Quantity" /></entry>'))
275
+ @item = AMEE::Profile::Item.get(connection, "/profiles/9BFB0C1CD78A/home/energy/quantity/30C00AD33033")
276
+ @item.values.size.should be(10)
277
+ #@item.values[4][:uid].should == "20FC928B045A"
278
+ @item.values[4][:name].should == "Mass Per Time"
279
+ @item.values[4][:path].should == "massPerTime"
280
+ @item.values[4][:value].should be_nil
281
+ #@item.values[5][:uid].should == "3835DF705F9D"
282
+ @item.values[5][:name].should == "Energy Consumption"
283
+ @item.values[5][:path].should == "energyConsumption"
284
+ @item.values[5][:value].should == "13"
285
+ @item.values[5][:unit].should == "kWh"
286
+ @item.values[5][:per_unit].should == "month"
287
+ end
288
+
289
+ it "should fail gracefully with incorrect data" do
290
+ connection = flexmock "connection"
291
+ connection.should_receive(:version).and_return(2.0)
292
+ atom = '<?xml version="1.0" encoding="UTF-8"?><entry xmlns="http://www.w3.org/2005/Atom" xmlns:amee="http://schemas.amee.cc/2.0"></entry>'
293
+ connection.should_receive(:get).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => atom))
294
+ lambda{AMEE::Profile::Item.get(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")}.should raise_error(AMEE::BadData)
295
+ end
296
+
297
+ end
298
+
299
+ describe AMEE::Profile::Item, "with an authenticated JSON connection" do
300
+
301
+ it "should load Profile Item" do
302
+ connection = flexmock "connection"
303
+ connection.should_receive(:version).and_return(1.0)
304
+ connection.should_receive(:get).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => '{"path":"/home/energy/quantity/6E9B1517D753","profile":{"uid":"92C8DB30F46B"},"profileItem":{"created":"2008-09-12 17:20:32.0","itemValues":[{"value":"10","uid":"0A671BF3D593","path":"kgPerMonth","name":"kg Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"36A771FC1D1A","name":"kg"},"uid":"51D072825D41","path":"kgPerMonth","name":"kg Per Month"}},{"value":"0","uid":"0E4CF565A5AB","path":"kWhPerMonth","name":"kWh Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"26A5C97D3728","name":"kWh"},"uid":"4DF458FD0E4D","path":"kWhPerMonth","name":"kWh Per Month"}},{"value":"0","uid":"D58700708731","path":"litresPerMonth","name":"Litres Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"06B8CFC5A521","name":"litre"},"uid":"C9B7E19269A5","path":"litresPerMonth","name":"Litres Per Month"}},{"value":"0","uid":"BD1267F2D001","path":"kWhReadingCurrent","name":"kWh reading current","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"8A468E75C8E8","path":"kWhReadingCurrent","name":"kWh reading current"}},{"value":"0","uid":"B199A908A259","path":"kWhReadingLast","name":"kWh reading last","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"2328DC7F23AE","path":"kWhReadingLast","name":"kWh reading last"}}],"dataCategory":{"uid":"A92693A99BAD","path":"quantity","name":"Quantity"},"end":"false","uid":"6E9B1517D753","environment":{"uid":"5F5887BCF726"},"profile":{"uid":"92C8DB30F46B"},"modified":"2008-09-12 17:20:32.0","validFrom":"20080901","amountPerMonth":25.2,"itemDefinition":{"uid":"212C818D8F16"},"dataItem":{"uid":"A70149AF0F26"},"name":"6E9B1517D753"}}'))
305
+ @item = AMEE::Profile::Item.get(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")
306
+ @item.profile_uid.should == "92C8DB30F46B"
307
+ @item.uid.should == "6E9B1517D753"
308
+ @item.name.should == "6E9B1517D753"
309
+ @item.path.should == "/home/energy/quantity/6E9B1517D753"
310
+ @item.total_amount.should be_close(25.2, 1e-9)
311
+ @item.total_amount_unit.should == "kg/month"
312
+ @item.valid_from.should == DateTime.new(2008, 9, 1)
313
+ @item.end.should be_false
314
+ @item.full_path.should == "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753"
315
+ end
316
+
317
+ it "should parse values" do
318
+ connection = flexmock "connection"
319
+ connection.should_receive(:get).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => '{"path":"/home/energy/quantity/6E9B1517D753","profile":{"uid":"92C8DB30F46B"},"profileItem":{"created":"2008-09-12 17:20:32.0","itemValues":[{"value":"10","uid":"0A671BF3D593","path":"kgPerMonth","name":"kg Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"36A771FC1D1A","name":"kg"},"uid":"51D072825D41","path":"kgPerMonth","name":"kg Per Month"}},{"value":"0","uid":"0E4CF565A5AB","path":"kWhPerMonth","name":"kWh Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"26A5C97D3728","name":"kWh"},"uid":"4DF458FD0E4D","path":"kWhPerMonth","name":"kWh Per Month"}},{"value":"0","uid":"D58700708731","path":"litresPerMonth","name":"Litres Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"06B8CFC5A521","name":"litre"},"uid":"C9B7E19269A5","path":"litresPerMonth","name":"Litres Per Month"}},{"value":"0","uid":"BD1267F2D001","path":"kWhReadingCurrent","name":"kWh reading current","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"8A468E75C8E8","path":"kWhReadingCurrent","name":"kWh reading current"}},{"value":"0","uid":"B199A908A259","path":"kWhReadingLast","name":"kWh reading last","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"2328DC7F23AE","path":"kWhReadingLast","name":"kWh reading last"}}],"dataCategory":{"uid":"A92693A99BAD","path":"quantity","name":"Quantity"},"end":"false","uid":"6E9B1517D753","environment":{"uid":"5F5887BCF726"},"profile":{"uid":"92C8DB30F46B"},"modified":"2008-09-12 17:20:32.0","validFrom":"20080901","amountPerMonth":25.2,"itemDefinition":{"uid":"212C818D8F16"},"dataItem":{"uid":"A70149AF0F26"},"name":"6E9B1517D753"}}'))
320
+ @item = AMEE::Profile::Item.get(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")
321
+ @item.values.size.should be(5)
322
+ @item.values[0][:uid].should == "0A671BF3D593"
323
+ @item.values[0][:name].should == "kg Per Month"
324
+ @item.values[0][:path].should == "kgPerMonth"
325
+ @item.values[0][:value].should == "10"
326
+ @item.values[1][:uid].should == "0E4CF565A5AB"
327
+ @item.values[1][:name].should == "kWh Per Month"
328
+ @item.values[1][:path].should == "kWhPerMonth"
329
+ @item.values[1][:value].should == "0"
330
+ end
331
+
332
+ it "should fail gracefully with incorrect data" do
333
+ connection = flexmock "connection"
334
+ connection.should_receive(:version).and_return(1.0)
335
+ json = '{}'
336
+ connection.should_receive(:get).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => json))
337
+ lambda{AMEE::Profile::Item.get(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")}.should raise_error(AMEE::BadData)
338
+ end
339
+
340
+ end
341
+
342
+ describe AMEE::Profile::Item, "with an authenticated V2 JSON connection" do
343
+
344
+ it "should load Profile Item" do
345
+ connection = flexmock "connection"
346
+ connection.should_receive(:version).and_return(2.0)
347
+ connection.should_receive(:get).with("/profiles/447C40EB29FB/home/energy/quantity/4A69B256D62D", {}).and_return(flexmock(:body => '{"apiVersion":"2.0","profileItem":{"uid":"4A69B256D62D","itemValues":[{"itemValueDefinition":{"uid":"E0EFED6FD7E6","name":"Payment frequency","path":"paymentFrequency","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"}},"perUnit":"","uid":"B732461AB225","unit":"","name":"Payment frequency","value":"","path":"paymentFrequency","displayPath":"paymentFrequency","displayName":"Payment frequency"},{"itemValueDefinition":{"uid":"63005554AE8A","name":"Green tariff","path":"greenTariff","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"}},"perUnit":"","uid":"1B5F54675626","unit":"","name":"Green tariff","value":"","path":"greenTariff","displayPath":"greenTariff","displayName":"Green tariff"},{"itemValueDefinition":{"uid":"527AADFB3B65","name":"Season","path":"season","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"}},"perUnit":"","uid":"EBCDC97E8866","unit":"","name":"Season","value":"","path":"season","displayPath":"season","displayName":"Season"},{"itemValueDefinition":{"uid":"1740E500BDAB","choices":"true=true,false=false","name":"Includes Heating","path":"includesHeating","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"}},"perUnit":"","uid":"F3400F402132","unit":"","name":"Includes Heating","value":"false","path":"includesHeating","displayPath":"includesHeating","displayName":"Includes Heating"},{"itemValueDefinition":{"perUnit":"year","uid":"9337F5526A61","unit":"kg","choices":"0","name":"Mass Per Time","path":"massPerTime","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"16BEF21E6ADD","unit":"kg","name":"Mass Per Time","value":"0","path":"massPerTime","displayPath":"massPerTime","displayName":"Mass Per Time"},{"itemValueDefinition":{"perUnit":"year","uid":"9B455839C862","unit":"kWh","choices":"0","name":"Energy Consumption","path":"energyConsumption","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"month","uid":"8BB3F49E2BB3","unit":"kWh","name":"Energy Consumption","value":"13","path":"energyConsumption","displayPath":"energyConsumption","displayName":"Energy Consumption"},{"itemValueDefinition":{"perUnit":"year","uid":"DAEC096CF138","unit":"kWh","choices":"0","name":"Current Reading","path":"currentReading","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"8CDC8101111C","unit":"kWh","name":"Current Reading","value":"0","path":"currentReading","displayPath":"currentReading","displayName":"Current Reading"},{"itemValueDefinition":{"perUnit":"year","uid":"F08A18BEE5E8","unit":"kWh","choices":"0","name":"Last Reading","path":"lastReading","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"3D9E46FBFDBF","unit":"kWh","name":"Last Reading","value":"0","path":"lastReading","displayPath":"lastReading","displayName":"Last Reading"},{"itemValueDefinition":{"perUnit":"year","uid":"87E2DB9BE8BD","unit":"L","choices":"0","name":"Volume Per Time","path":"volumePerTime","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"5D354D0A1E9B","unit":"L","name":"Volume Per Time","value":"0","path":"volumePerTime","displayPath":"volumePerTime","displayName":"Volume Per Time"},{"itemValueDefinition":{"perUnit":"year","uid":"F0DE162CA7E7","choices":"0","name":"Number of deliveries","path":"deliveries","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"7071D7893AD4","unit":"","name":"Number of deliveries","value":"0","path":"deliveries","displayPath":"deliveries","displayName":"Number of deliveries"}],"dataCategory":{"uid":"A92693A99BAD","name":"Quantity","path":"quantity"},"startDate":"2008-09-02T01:00+0100","itemDefinition":{"uid":"212C818D8F16","name":"Energy Quantity","drillDown":"type"},"endDate":"","dataItem":{"uid":"66056991EE23","Label":"gas"},"modified":"2009-02-19T12:16+0000","amount":{"unit":"kg/year","value":32.058},"environment":{"uid":"5F5887BCF726","itemsPerFeed":10,"description":"","name":"AMEE","owner":"","path":"","itemsPerPage":10},"created":"2009-02-19T12:15+0000","name":"gas","profile":{"uid":"447C40EB29FB"}},"path":"/home/energy/quantity/4A69B256D62D","actions":{"allowCreate":true,"allowView":true,"allowList":true,"allowModify":true,"allowDelete":true},"profile":{"uid":"447C40EB29FB"}}'))
348
+ @item = AMEE::Profile::Item.get(connection, "/profiles/447C40EB29FB/home/energy/quantity/4A69B256D62D")
349
+ @item.profile_uid.should == "447C40EB29FB"
350
+ @item.uid.should == "4A69B256D62D"
351
+ @item.name.should == "gas"
352
+ @item.path.should == "/home/energy/quantity/4A69B256D62D"
353
+ @item.total_amount.should be_close(32.058, 1e-9)
354
+ @item.total_amount_unit.should == "kg/year"
355
+ @item.start_date.should == DateTime.new(2008, 9, 2)
356
+ @item.full_path.should == "/profiles/447C40EB29FB/home/energy/quantity/4A69B256D62D"
357
+ end
358
+
359
+ it "should parse values" do
360
+ connection = flexmock "connection"
361
+ connection.should_receive(:version).and_return(2.0)
362
+ connection.should_receive(:get).with("/profiles/447C40EB29FB/home/energy/quantity/4A69B256D62D", {}).and_return(flexmock(:body => '{"apiVersion":"2.0","profileItem":{"uid":"4A69B256D62D","itemValues":[{"itemValueDefinition":{"uid":"E0EFED6FD7E6","name":"Payment frequency","path":"paymentFrequency","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"}},"perUnit":"","uid":"B732461AB225","unit":"","name":"Payment frequency","value":"","path":"paymentFrequency","displayPath":"paymentFrequency","displayName":"Payment frequency"},{"itemValueDefinition":{"uid":"63005554AE8A","name":"Green tariff","path":"greenTariff","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"}},"perUnit":"","uid":"1B5F54675626","unit":"","name":"Green tariff","value":"","path":"greenTariff","displayPath":"greenTariff","displayName":"Green tariff"},{"itemValueDefinition":{"uid":"527AADFB3B65","name":"Season","path":"season","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"}},"perUnit":"","uid":"EBCDC97E8866","unit":"","name":"Season","value":"","path":"season","displayPath":"season","displayName":"Season"},{"itemValueDefinition":{"uid":"1740E500BDAB","choices":"true=true,false=false","name":"Includes Heating","path":"includesHeating","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"}},"perUnit":"","uid":"F3400F402132","unit":"","name":"Includes Heating","value":"false","path":"includesHeating","displayPath":"includesHeating","displayName":"Includes Heating"},{"itemValueDefinition":{"perUnit":"year","uid":"9337F5526A61","unit":"kg","choices":"0","name":"Mass Per Time","path":"massPerTime","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"16BEF21E6ADD","unit":"kg","name":"Mass Per Time","value":"0","path":"massPerTime","displayPath":"massPerTime","displayName":"Mass Per Time"},{"itemValueDefinition":{"perUnit":"year","uid":"9B455839C862","unit":"kWh","choices":"0","name":"Energy Consumption","path":"energyConsumption","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"month","uid":"8BB3F49E2BB3","unit":"kWh","name":"Energy Consumption","value":"13","path":"energyConsumption","displayPath":"energyConsumption","displayName":"Energy Consumption"},{"itemValueDefinition":{"perUnit":"year","uid":"DAEC096CF138","unit":"kWh","choices":"0","name":"Current Reading","path":"currentReading","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"8CDC8101111C","unit":"kWh","name":"Current Reading","value":"0","path":"currentReading","displayPath":"currentReading","displayName":"Current Reading"},{"itemValueDefinition":{"perUnit":"year","uid":"F08A18BEE5E8","unit":"kWh","choices":"0","name":"Last Reading","path":"lastReading","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"3D9E46FBFDBF","unit":"kWh","name":"Last Reading","value":"0","path":"lastReading","displayPath":"lastReading","displayName":"Last Reading"},{"itemValueDefinition":{"perUnit":"year","uid":"87E2DB9BE8BD","unit":"L","choices":"0","name":"Volume Per Time","path":"volumePerTime","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"5D354D0A1E9B","unit":"L","name":"Volume Per Time","value":"0","path":"volumePerTime","displayPath":"volumePerTime","displayName":"Volume Per Time"},{"itemValueDefinition":{"perUnit":"year","uid":"F0DE162CA7E7","choices":"0","name":"Number of deliveries","path":"deliveries","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"7071D7893AD4","unit":"","name":"Number of deliveries","value":"0","path":"deliveries","displayPath":"deliveries","displayName":"Number of deliveries"}],"dataCategory":{"uid":"A92693A99BAD","name":"Quantity","path":"quantity"},"startDate":"2008-09-02T01:00+0100","itemDefinition":{"uid":"212C818D8F16","name":"Energy Quantity","drillDown":"type"},"endDate":"","dataItem":{"uid":"66056991EE23","Label":"gas"},"modified":"2009-02-19T12:16+0000","amount":{"unit":"kg/year","value":32.058},"environment":{"uid":"5F5887BCF726","itemsPerFeed":10,"description":"","name":"AMEE","owner":"","path":"","itemsPerPage":10},"created":"2009-02-19T12:15+0000","name":"gas","profile":{"uid":"447C40EB29FB"}},"path":"/home/energy/quantity/4A69B256D62D","actions":{"allowCreate":true,"allowView":true,"allowList":true,"allowModify":true,"allowDelete":true},"profile":{"uid":"447C40EB29FB"}}'))
363
+ @item = AMEE::Profile::Item.get(connection, "/profiles/447C40EB29FB/home/energy/quantity/4A69B256D62D")
364
+ @item.values.size.should be(10)
365
+ @item.values[4][:uid].should == "16BEF21E6ADD"
366
+ @item.values[4][:name].should == "Mass Per Time"
367
+ @item.values[4][:path].should == "massPerTime"
368
+ @item.values[4][:value].should == "0"
369
+ @item.values[5][:uid].should == "8BB3F49E2BB3"
370
+ @item.values[5][:name].should == "Energy Consumption"
371
+ @item.values[5][:path].should == "energyConsumption"
372
+ @item.values[5][:value].should == "13"
373
+ @item.values[5][:unit].should == "kWh"
374
+ @item.values[5][:per_unit].should == "month"
375
+ end
376
+
377
+ it "should parse multiple return values" do
378
+ connection = flexmock "connection"
379
+ connection.should_receive(:version).and_return(2.0)
380
+ connection.should_receive(:get).with("/profiles/F8C2D1052BF7/home/energy/quantity/3BCDB0BB2B96", {}).and_return(flexmock(:body => '{"apiVersion":"2.0","profileItem":{"uid":"3BCDB0BB2B96","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"}],"dataCategory":{"uid":"A92693A99BAD","deprecated":false,"name":"Quantity","path":"quantity"},"startDate":"2010-07-16T10:44:00-04:00","itemDefinition":{"uid":"212C818D8F16","name":"Energy Quantity","drillDown":"type"},"endDate":"","dataItem":{"uid":"66056991EE23","Label":"gas"},"modified":"2010-07-16T14:45:03Z","amount":{"unit":"kg/year","value":31.7772},"environment":{"uid":"5F5887BCF726","itemsPerFeed":10,"description":"","name":"AMEE","owner":"","path":"","itemsPerPage":10},"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","profile":{"uid":"F8C2D1052BF7"}},"path":"/home/energy/quantity/3BCDB0BB2B96","profile":{"uid":"F8C2D1052BF7"}}'))
381
+ @item = AMEE::Profile::Item.get(connection, "/profiles/F8C2D1052BF7/home/energy/quantity/3BCDB0BB2B96")
382
+ @item.total_amount.should be_close(31.7772, 1e-4)
383
+ @item.total_amount_unit.should == 'kg/year'
384
+ @item.amounts.size.should be(2)
385
+ @item.amounts[0][:type].should == "CO2"
386
+ @item.amounts[0][:value].should be_close(31.7772, 1e-4)
387
+ @item.amounts[0][:unit].should == 'kg'
388
+ @item.amounts[0][:per_unit].should == 'year'
389
+ @item.amounts[0][:default].should be_true
390
+ @item.amounts[1][:type].should == "CH4"
391
+ @item.amounts[1][:value].should be_close(4.2, 1e-2)
392
+ @item.amounts[1][:unit].should == 'kg'
393
+ @item.amounts[1][:per_unit].should be_nil
394
+ @item.notes.size.should be(2)
395
+ @item.notes[0][:type].should == 'comment'
396
+ @item.notes[0][:value].should == 'This is a text node'
397
+ @item.notes[1][:type].should == 'comment'
398
+ @item.notes[1][:value].should == 'This is another text node'
399
+ end
400
+
401
+ it "should fail gracefully with incorrect data" do
402
+ connection = flexmock "connection"
403
+ connection.should_receive(:version).and_return(2.0)
404
+ json = '{"apiVersion":"2.0"}'
405
+ connection.should_receive(:get).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => json))
406
+ lambda{AMEE::Profile::Item.get(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")}.should raise_error(AMEE::BadData)
407
+ end
408
+
409
+ end
410
+
411
+ describe AMEE::Profile::Item, "should be able to update profile items" do
412
+
413
+ it " given an existing item" do
414
+ connection = flexmock "connection"
415
+ connection.should_receive(:version).and_return(1.0)
416
+ connection.should_receive(:get).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileItemResource><ProfileItem created="2008-09-12 17:20:32.0" modified="2008-09-12 17:20:32.0" uid="6E9B1517D753"><Name>6E9B1517D753</Name><ItemValues><ItemValue uid="0A671BF3D593"><Path>kgPerMonth</Path><Name>kg Per Month</Name><Value>10</Value><ItemValueDefinition uid="51D072825D41"><Path>kgPerMonth</Path><Name>kg Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="36A771FC1D1A"><Name>kg</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="0E4CF565A5AB"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><Value>0</Value><ItemValueDefinition uid="4DF458FD0E4D"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="26A5C97D3728"><Name>kWh</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="D58700708731"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><Value>0</Value><ItemValueDefinition uid="C9B7E19269A5"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="06B8CFC5A521"><Name>litre</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="BD1267F2D001"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><Value>0</Value><ItemValueDefinition uid="8A468E75C8E8"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="B199A908A259"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><Value>0</Value><ItemValueDefinition uid="2328DC7F23AE"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue></ItemValues><Environment uid="5F5887BCF726"/><ItemDefinition uid="212C818D8F16"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><AmountPerMonth>25.200</AmountPerMonth><ValidFrom>20080901</ValidFrom><End>false</End><DataItem uid="A70149AF0F26"/><Profile uid="92C8DB30F46B"/></ProfileItem><Path>/home/energy/quantity/6E9B1517D753</Path><Profile uid="92C8DB30F46B"/></ProfileItemResource></Resources>'))
417
+ connection.should_receive(:put).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileItemResource><ProfileItem created="2008-09-12 17:20:32.0" modified="2008-09-12 17:20:32.0" uid="6E9B1517D753"><Name>6E9B1517D753</Name><ItemValues><ItemValue uid="0A671BF3D593"><Path>kgPerMonth</Path><Name>kg Per Month</Name><Value>10</Value><ItemValueDefinition uid="51D072825D41"><Path>kgPerMonth</Path><Name>kg Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="36A771FC1D1A"><Name>kg</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="0E4CF565A5AB"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><Value>0</Value><ItemValueDefinition uid="4DF458FD0E4D"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="26A5C97D3728"><Name>kWh</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="D58700708731"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><Value>0</Value><ItemValueDefinition uid="C9B7E19269A5"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="06B8CFC5A521"><Name>litre</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="BD1267F2D001"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><Value>0</Value><ItemValueDefinition uid="8A468E75C8E8"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="B199A908A259"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><Value>0</Value><ItemValueDefinition uid="2328DC7F23AE"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue></ItemValues><Environment uid="5F5887BCF726"/><ItemDefinition uid="212C818D8F16"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><AmountPerMonth>25.200</AmountPerMonth><ValidFrom>20080901</ValidFrom><End>false</End><DataItem uid="A70149AF0F26"/><Profile uid="92C8DB30F46B"/></ProfileItem><Path>/home/energy/quantity/6E9B1517D753</Path><Profile uid="92C8DB30F46B"/></ProfileItemResource></Resources>'))
418
+ item = AMEE::Profile::Item.get(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")
419
+ item.update()
420
+ end
421
+
422
+ it "without having an existing item" do
423
+ connection = flexmock "connection"
424
+ connection.should_receive(:version).and_return(1.0)
425
+ connection.should_receive(:put).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileItemResource><ProfileItem created="2008-09-12 17:20:32.0" modified="2008-09-12 17:20:32.0" uid="6E9B1517D753"><Name>6E9B1517D753</Name><ItemValues><ItemValue uid="0A671BF3D593"><Path>kgPerMonth</Path><Name>kg Per Month</Name><Value>10</Value><ItemValueDefinition uid="51D072825D41"><Path>kgPerMonth</Path><Name>kg Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="36A771FC1D1A"><Name>kg</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="0E4CF565A5AB"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><Value>0</Value><ItemValueDefinition uid="4DF458FD0E4D"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="26A5C97D3728"><Name>kWh</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="D58700708731"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><Value>0</Value><ItemValueDefinition uid="C9B7E19269A5"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="06B8CFC5A521"><Name>litre</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="BD1267F2D001"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><Value>0</Value><ItemValueDefinition uid="8A468E75C8E8"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="B199A908A259"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><Value>0</Value><ItemValueDefinition uid="2328DC7F23AE"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue></ItemValues><Environment uid="5F5887BCF726"/><ItemDefinition uid="212C818D8F16"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><AmountPerMonth>25.200</AmountPerMonth><ValidFrom>20080901</ValidFrom><End>false</End><DataItem uid="A70149AF0F26"/><Profile uid="92C8DB30F46B"/></ProfileItem><Path>/home/energy/quantity/6E9B1517D753</Path><Profile uid="92C8DB30F46B"/></ProfileItemResource></Resources>'))
426
+ AMEE::Profile::Item.update(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")
427
+ end
428
+
429
+ end
430
+
431
+ describe AMEE::Profile::Item, "should be able to update profile items (v2 behaviour)" do
432
+
433
+ it " given an existing item" do
434
+ connection = flexmock "connection"
435
+ connection.should_receive(:version).and_return(2.0)
436
+ connection.should_receive(:get).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileItemResource><ProfileItem created="2008-09-12 17:20:32.0" modified="2008-09-12 17:20:32.0" uid="6E9B1517D753"><Name>6E9B1517D753</Name><ItemValues><ItemValue uid="0A671BF3D593"><Path>kgPerMonth</Path><Name>kg Per Month</Name><Value>10</Value><ItemValueDefinition uid="51D072825D41"><Path>kgPerMonth</Path><Name>kg Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="36A771FC1D1A"><Name>kg</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="0E4CF565A5AB"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><Value>0</Value><ItemValueDefinition uid="4DF458FD0E4D"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="26A5C97D3728"><Name>kWh</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="D58700708731"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><Value>0</Value><ItemValueDefinition uid="C9B7E19269A5"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="06B8CFC5A521"><Name>litre</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="BD1267F2D001"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><Value>0</Value><ItemValueDefinition uid="8A468E75C8E8"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="B199A908A259"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><Value>0</Value><ItemValueDefinition uid="2328DC7F23AE"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue></ItemValues><Environment uid="5F5887BCF726"/><ItemDefinition uid="212C818D8F16"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><AmountPerMonth>25.200</AmountPerMonth><ValidFrom>20080901</ValidFrom><End>false</End><DataItem uid="A70149AF0F26"/><Profile uid="92C8DB30F46B"/></ProfileItem><Path>/home/energy/quantity/6E9B1517D753</Path><Profile uid="92C8DB30F46B"/></ProfileItemResource></Resources>'))
437
+ connection.should_receive(:put).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => ''))
438
+ connection.should_receive(:get).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileItemResource><ProfileItem created="2008-09-12 17:20:32.0" modified="2008-09-12 17:20:32.0" uid="6E9B1517D753"><Name>6E9B1517D753</Name><ItemValues><ItemValue uid="0A671BF3D593"><Path>kgPerMonth</Path><Name>kg Per Month</Name><Value>10</Value><ItemValueDefinition uid="51D072825D41"><Path>kgPerMonth</Path><Name>kg Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="36A771FC1D1A"><Name>kg</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="0E4CF565A5AB"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><Value>0</Value><ItemValueDefinition uid="4DF458FD0E4D"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="26A5C97D3728"><Name>kWh</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="D58700708731"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><Value>0</Value><ItemValueDefinition uid="C9B7E19269A5"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="06B8CFC5A521"><Name>litre</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="BD1267F2D001"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><Value>0</Value><ItemValueDefinition uid="8A468E75C8E8"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="B199A908A259"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><Value>0</Value><ItemValueDefinition uid="2328DC7F23AE"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue></ItemValues><Environment uid="5F5887BCF726"/><ItemDefinition uid="212C818D8F16"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><AmountPerMonth>25.200</AmountPerMonth><ValidFrom>20080901</ValidFrom><End>false</End><DataItem uid="A70149AF0F26"/><Profile uid="92C8DB30F46B"/></ProfileItem><Path>/home/energy/quantity/6E9B1517D753</Path><Profile uid="92C8DB30F46B"/></ProfileItemResource></Resources>'))
439
+ item = AMEE::Profile::Item.get(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")
440
+ item.update()
441
+ end
442
+
443
+ it "without having an existing item" do
444
+ connection = flexmock "connection"
445
+ connection.should_receive(:version).and_return(2.0)
446
+ connection.should_receive(:put).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => ''))
447
+ connection.should_receive(:get).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileItemResource><ProfileItem created="2008-09-12 17:20:32.0" modified="2008-09-12 17:20:32.0" uid="6E9B1517D753"><Name>6E9B1517D753</Name><ItemValues><ItemValue uid="0A671BF3D593"><Path>kgPerMonth</Path><Name>kg Per Month</Name><Value>10</Value><ItemValueDefinition uid="51D072825D41"><Path>kgPerMonth</Path><Name>kg Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="36A771FC1D1A"><Name>kg</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="0E4CF565A5AB"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><Value>0</Value><ItemValueDefinition uid="4DF458FD0E4D"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="26A5C97D3728"><Name>kWh</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="D58700708731"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><Value>0</Value><ItemValueDefinition uid="C9B7E19269A5"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="06B8CFC5A521"><Name>litre</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="BD1267F2D001"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><Value>0</Value><ItemValueDefinition uid="8A468E75C8E8"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="B199A908A259"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><Value>0</Value><ItemValueDefinition uid="2328DC7F23AE"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue></ItemValues><Environment uid="5F5887BCF726"/><ItemDefinition uid="212C818D8F16"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><AmountPerMonth>25.200</AmountPerMonth><ValidFrom>20080901</ValidFrom><End>false</End><DataItem uid="A70149AF0F26"/><Profile uid="92C8DB30F46B"/></ProfileItem><Path>/home/energy/quantity/6E9B1517D753</Path><Profile uid="92C8DB30F46B"/></ProfileItemResource></Resources>'))
448
+ AMEE::Profile::Item.update(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")
449
+ end
450
+
451
+ end
@@ -0,0 +1,196 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe AMEE::Profile::ItemValue do
4
+
5
+ before(:each) do
6
+ @value = AMEE::Profile::ItemValue.new
7
+ end
8
+
9
+ it "should have common AMEE object properties" do
10
+ @value.is_a?(AMEE::Profile::Object).should be_true
11
+ end
12
+
13
+ it "should have a value" do
14
+ @value.should respond_to(:value)
15
+ end
16
+
17
+ it "should have a type" do
18
+ @value.should respond_to(:type)
19
+ end
20
+
21
+ it "should have units" do
22
+ @value.should respond_to(:unit)
23
+ @value.should respond_to(:per_unit)
24
+ end
25
+
26
+ it "should initialize AMEE::Object data on creation" do
27
+ uid = 'ABCD1234'
28
+ @value = AMEE::Profile::ItemValue.new(:uid => uid)
29
+ @value.uid.should == uid
30
+ end
31
+
32
+ it "can be created with hash of data" do
33
+ value = "test"
34
+ type = "STRING"
35
+ unit = "none"
36
+ per_unit = "nothing"
37
+ @value = AMEE::Profile::ItemValue.new(:value => value, :type => type, :unit => unit, :per_unit => per_unit)
38
+ @value.value.should == value
39
+ @value.type.should == type
40
+ @value.unit.should == unit
41
+ @value.per_unit.should == per_unit
42
+ end
43
+
44
+ it "should support DOUBLE data type" do
45
+ @value = AMEE::Profile::ItemValue.new(:value => "1.5", :type => "DOUBLE")
46
+ @value.value.should == 1.5
47
+ end
48
+
49
+ it "should support TEXT data type" do
50
+ @value = AMEE::Profile::ItemValue.new(:value => "1.5", :type => "TEXT")
51
+ @value.value.should == "1.5"
52
+ end
53
+
54
+ it "allows value to be changed after creation" do
55
+ value = "test"
56
+ type = "TEXT"
57
+ @value = AMEE::Profile::ItemValue.new(:value => value, :type => type)
58
+ @value.value.should == value
59
+ value = "hello"
60
+ @value.value = value
61
+ @value.value.should == value
62
+ end
63
+
64
+ end
65
+
66
+ describe AMEE::Profile::ItemValue, "with an authenticated connection" do
67
+
68
+ it "should parse XML correctly" do
69
+ connection = flexmock "connection"
70
+ connection.should_receive(:get).with("/profiles/AEC30FB9BCB9/home/energy/quantity/B099A221106E/kWhPerMonth").and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileItemValueResource><ItemValue Created="2009-03-24 11:15:13.0" Modified="2009-03-24 11:15:20.0" uid="BA4428721987"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><Value>10</Value><ItemValueDefinition uid="4DF458FD0E4D"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="26A5C97D3728"><Name>kWh</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition><ProfileItem uid="B099A221106E"/></ItemValue><Path>/home/energy/quantity/B099A221106E/kWhPerMonth</Path><Profile uid="AEC30FB9BCB9"/></ProfileItemValueResource></Resources>'))
71
+ @value = AMEE::Profile::ItemValue.get(connection, "/profiles/AEC30FB9BCB9/home/energy/quantity/B099A221106E/kWhPerMonth")
72
+ @value.uid.should == "BA4428721987"
73
+ @value.name.should == "kWh Per Month"
74
+ @value.path.should == "/AEC30FB9BCB9/home/energy/quantity/B099A221106E/kWhPerMonth"
75
+ @value.full_path.should == "/profiles/AEC30FB9BCB9/home/energy/quantity/B099A221106E/kWhPerMonth"
76
+ @value.created.should == DateTime.new(2009,3,24,11,15,13)
77
+ @value.modified.should == DateTime.new(2009,3,24,11,15,20)
78
+ @value.value.should == 10
79
+ @value.unit.should be_nil
80
+ @value.per_unit.should be_nil
81
+ @value.type.should == "DOUBLE"
82
+ @value.from_profile?.should be_true
83
+ @value.from_data?.should be_false
84
+ end
85
+
86
+ it "should parse V2 XML correctly" do
87
+ connection = flexmock "connection"
88
+ connection.should_receive(:get).with("/profiles/459AB34FD0FC/home/energy/quantity/AF8A07038B63/energyConsumption").and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8" standalone="no"?><Resources xmlns="http://schemas.amee.cc/2.0"><ProfileItemValueResource><ItemValue Created="2009-03-24 11:50:32.0" Modified="2009-03-24 11:50:51.0" uid="D19B538D7D84"><Path>energyConsumption</Path><Name>Energy Consumption</Name><Value>10</Value><Unit>kWh</Unit><PerUnit>year</PerUnit><ItemValueDefinition uid="BFD215C4CAB1"><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><ProfileItem uid="AF8A07038B63"/></ItemValue><Path>/home/energy/quantity/AF8A07038B63/energyConsumption</Path><Profile uid="459AB34FD0FC"/></ProfileItemValueResource></Resources>'))
89
+ @value = AMEE::Profile::ItemValue.get(connection, "/profiles/459AB34FD0FC/home/energy/quantity/AF8A07038B63/energyConsumption")
90
+ @value.uid.should == "D19B538D7D84"
91
+ @value.name.should == "Energy Consumption"
92
+ @value.path.should == "/459AB34FD0FC/home/energy/quantity/AF8A07038B63/energyConsumption"
93
+ @value.full_path.should == "/profiles/459AB34FD0FC/home/energy/quantity/AF8A07038B63/energyConsumption"
94
+ @value.created.should == DateTime.new(2009,3,24,11,50,32)
95
+ @value.modified.should == DateTime.new(2009,3,24,11,50,51)
96
+ @value.value.should == 10
97
+ @value.unit.should == "kWh"
98
+ @value.per_unit.should == "year"
99
+ @value.type.should == "DOUBLE"
100
+ @value.from_profile?.should be_true
101
+ @value.from_data?.should be_false
102
+ end
103
+
104
+ it "should parse JSON correctly" do
105
+ connection = flexmock "connection"
106
+ connection.should_receive(:get).with("/profiles/AEC30FB9BCB9/home/energy/quantity/B099A221106E/kWhPerMonth").and_return(flexmock(:body => '{"path":"/home/energy/quantity/B099A221106E/kWhPerMonth","profile":{"uid":"AEC30FB9BCB9"},"itemValue":{"item":{"uid":"B099A221106E"},"modified":"2009-03-24 11:15:20.0","created":"2009-03-24 11:15:13.0","value":"10","uid":"BA4428721987","path":"kWhPerMonth","name":"kWh Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"26A5C97D3728","name":"kWh"},"uid":"4DF458FD0E4D","path":"kWhPerMonth","name":"kWh Per Month"}}}'))
107
+ @value = AMEE::Profile::ItemValue.get(connection, "/profiles/AEC30FB9BCB9/home/energy/quantity/B099A221106E/kWhPerMonth")
108
+ @value.uid.should == "BA4428721987"
109
+ @value.name.should == "kWh Per Month"
110
+ @value.path.should == "/AEC30FB9BCB9/home/energy/quantity/B099A221106E/kWhPerMonth"
111
+ @value.full_path.should == "/profiles/AEC30FB9BCB9/home/energy/quantity/B099A221106E/kWhPerMonth"
112
+ @value.created.should == DateTime.new(2009,3,24,11,15,13)
113
+ @value.modified.should == DateTime.new(2009,3,24,11,15,20)
114
+ @value.value.should == 10
115
+ @value.unit.should be_nil
116
+ @value.per_unit.should be_nil
117
+ @value.type.should == "DOUBLE"
118
+ #@value.from_profile?.should be_false # NOT SET IN JSON
119
+ #@value.from_data?.should be_true # NOT SET IN JSON
120
+ end
121
+
122
+ it "should parse V2 JSON correctly" do
123
+ connection = flexmock "connection"
124
+ connection.should_receive(:get).with("/profiles/459AB34FD0FC/home/energy/quantity/AF8A07038B63/energyConsumption").and_return(flexmock(:body => '{"apiVersion":"2.0","itemValue":{"itemValueDefinition":{"perUnit":"year","uid":"BFD215C4CAB1","unit":"kWh","name":"Energy Consumption","path":"energyConsumption","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"D19B538D7D84","unit":"kWh","created":"2009-03-24 11:50:32.0","item":{"uid":"AF8A07038B63","itemValues":[{"itemValueDefinition":{"uid":"E0EFED6FD7E6","name":"Payment frequency","path":"paymentFrequency","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"}},"perUnit":"","uid":"1640B887FBF1","unit":"","name":"Payment frequency","value":"","path":"paymentFrequency","displayPath":"paymentFrequency","displayName":"Payment frequency"},{"itemValueDefinition":{"uid":"63005554AE8A","name":"Green tariff","path":"greenTariff","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"}},"perUnit":"","uid":"3D6FBA971997","unit":"","name":"Green tariff","value":"","path":"greenTariff","displayPath":"greenTariff","displayName":"Green tariff"},{"itemValueDefinition":{"uid":"527AADFB3B65","name":"Season","path":"season","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"}},"perUnit":"","uid":"DCCFE001A1A3","unit":"","name":"Season","value":"","path":"season","displayPath":"season","displayName":"Season"},{"itemValueDefinition":{"uid":"1740E500BDAB","choices":"true=true,false=false","name":"Includes Heating","path":"includesHeating","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"}},"perUnit":"","uid":"F678696C2BC8","unit":"","name":"Includes Heating","value":"false","path":"includesHeating","displayPath":"includesHeating","displayName":"Includes Heating"},{"itemValueDefinition":{"perUnit":"year","uid":"666C77B224B3","unit":"kg","name":"Mass Per Time","path":"massPerTime","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"6F62EB737262","unit":"kg","name":"Mass Per Time","value":"0","path":"massPerTime","displayPath":"massPerTime","displayName":"Mass Per Time"},{"itemValueDefinition":{"perUnit":"year","uid":"BFD215C4CAB1","unit":"kWh","name":"Energy Consumption","path":"energyConsumption","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"D19B538D7D84","unit":"kWh","name":"Energy Consumption","value":"10","path":"energyConsumption","displayPath":"energyConsumption","displayName":"Energy Consumption"},{"itemValueDefinition":{"perUnit":"year","uid":"A9B493A4A1A6","unit":"kWh","name":"Current Reading","path":"currentReading","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"CBF14AC62D7B","unit":"kWh","name":"Current Reading","value":"0","path":"currentReading","displayPath":"currentReading","displayName":"Current Reading"},{"itemValueDefinition":{"perUnit":"year","uid":"4C689DEF0A41","unit":"kWh","name":"Last Reading","path":"lastReading","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"57F5EF09B890","unit":"kWh","name":"Last Reading","value":"0","path":"lastReading","displayPath":"lastReading","displayName":"Last Reading"},{"itemValueDefinition":{"perUnit":"year","uid":"7BBABF4C2E9E","unit":"L","name":"Volume Per Time","path":"volumePerTime","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"993652F098D6","unit":"L","name":"Volume Per Time","value":"0","path":"volumePerTime","displayPath":"volumePerTime","displayName":"Volume Per Time"},{"itemValueDefinition":{"perUnit":"year","uid":"F0ED40C7EF8F","name":"Number of deliveries","path":"deliveries","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"3BA01E3607B3","unit":"","name":"Number of deliveries","value":"","path":"deliveries","displayPath":"deliveries","displayName":"Number of deliveries"}],"dataCategory":{"uid":"A92693A99BAD","name":"Quantity","path":"quantity"},"startDate":"2009-03-24T11:50:00Z","itemDefinition":{"uid":"212C818D8F16","name":"Energy Quantity","drillDown":"type"},"endDate":"","dataItem":{"uid":"66056991EE23","Label":"gas"},"modified":"2009-03-24T11:50:51Z","amount":{"unit":"kg/year","value":2.055},"environment":{"uid":"5F5887BCF726","itemsPerFeed":10,"description":"","name":"AMEE","owner":"","path":"","itemsPerPage":10},"created":"2009-03-24T11:50:32Z","name":null,"profile":{"uid":"459AB34FD0FC"}},"name":"Energy Consumption","value":"10","path":"energyConsumption","displayPath":"energyConsumption","displayName":"Energy Consumption","modified":"2009-03-24 11:50:51.0"},"path":"/home/energy/quantity/AF8A07038B63/energyConsumption","actions":{"allowCreate":true,"allowView":true,"allowList":true,"allowModify":true,"allowDelete":true},"profile":{"uid":"459AB34FD0FC"}}'))
125
+ @value = AMEE::Profile::ItemValue.get(connection, "/profiles/459AB34FD0FC/home/energy/quantity/AF8A07038B63/energyConsumption")
126
+ @value.uid.should == "D19B538D7D84"
127
+ @value.name.should == "Energy Consumption"
128
+ @value.path.should == "/459AB34FD0FC/home/energy/quantity/AF8A07038B63/energyConsumption"
129
+ @value.full_path.should == "/profiles/459AB34FD0FC/home/energy/quantity/AF8A07038B63/energyConsumption"
130
+ @value.created.should == DateTime.new(2009,3,24,11,50,32)
131
+ @value.modified.should == DateTime.new(2009,3,24,11,50,51)
132
+ @value.value.should == 10
133
+ @value.unit.should == "kWh"
134
+ @value.per_unit.should == "year"
135
+ @value.type.should == "DOUBLE"
136
+ end
137
+
138
+ it "should fail gracefully with incorrect XML data" do
139
+ connection = flexmock "connection"
140
+ xml = '<?xml version="1.0" encoding="UTF-8"?><Resources></Resources>'
141
+ connection.should_receive(:get).with("/profiles/AEC30FB9BCB9/home/energy/quantity/B099A221106E/kWhPerMonth").and_return(flexmock(:body => xml))
142
+ lambda{AMEE::Profile::ItemValue.get(connection, "/profiles/AEC30FB9BCB9/home/energy/quantity/B099A221106E/kWhPerMonth")}.should raise_error(AMEE::BadData)
143
+ end
144
+
145
+ it "should fail gracefully with incorrect JSON data" do
146
+ connection = flexmock "connection"
147
+ json = '{}'
148
+ connection.should_receive(:get).with("/profiles/AEC30FB9BCB9/home/energy/quantity/B099A221106E/kWhPerMonth").and_return(flexmock(:body => json))
149
+ lambda{AMEE::Profile::ItemValue.get(connection, "/profiles/AEC30FB9BCB9/home/energy/quantity/B099A221106E/kWhPerMonth")}.should raise_error(AMEE::BadData)
150
+ end
151
+
152
+ it "should fail gracefully on other errors" do
153
+ connection = flexmock "connection"
154
+ connection.should_receive(:get).with("/profiles/AEC30FB9BCB9/home/energy/quantity/B099A221106E/kWhPerMonth").and_raise("unidentified error")
155
+ lambda{AMEE::Profile::ItemValue.get(connection, "/profiles/AEC30FB9BCB9/home/energy/quantity/B099A221106E/kWhPerMonth")}.should raise_error(AMEE::BadData)
156
+ end
157
+
158
+ end
159
+
160
+ describe AMEE::Profile::ItemValue, "after loading v1" do
161
+
162
+ before(:each) do
163
+ @connection = flexmock "connection"
164
+ @connection.should_receive(:get).with("/profiles/AEC30FB9BCB9/home/energy/quantity/B099A221106E/kWhPerMonth").and_return(flexmock(:body => '{"path":"/home/energy/quantity/B099A221106E/kWhPerMonth","profile":{"uid":"AEC30FB9BCB9"},"itemValue":{"item":{"uid":"B099A221106E"},"modified":"2009-03-24 11:15:20.0","created":"2009-03-24 11:15:13.0","value":"10","uid":"BA4428721987","path":"kWhPerMonth","name":"kWh Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"26A5C97D3728","name":"kWh"},"uid":"4DF458FD0E4D","path":"kWhPerMonth","name":"kWh Per Month"}}}'))
165
+ @val = AMEE::Profile::ItemValue.get(@connection, "/profiles/AEC30FB9BCB9/home/energy/quantity/B099A221106E/kWhPerMonth")
166
+ end
167
+
168
+ it "can have value changed and saved back to server" do
169
+ @connection.should_receive(:put).with("/profiles/AEC30FB9BCB9/home/energy/quantity/B099A221106E/kWhPerMonth", {:value => 42}).and_return(flexmock(:body => ''))
170
+ lambda {
171
+ @val.value = 42
172
+ @val.save!
173
+ }.should_not raise_error
174
+ end
175
+
176
+ end
177
+
178
+ describe AMEE::Profile::ItemValue, "after loading v2" do
179
+
180
+ before(:each) do
181
+ @connection = flexmock "connection"
182
+ @connection.should_receive(:get).with("/profiles/459AB34FD0FC/home/energy/quantity/AF8A07038B63/energyConsumption").and_return(flexmock(:body => '{"apiVersion":"2.0","itemValue":{"itemValueDefinition":{"perUnit":"year","uid":"BFD215C4CAB1","unit":"kWh","name":"Energy Consumption","path":"energyConsumption","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"D19B538D7D84","unit":"kWh","created":"2009-03-24 11:50:32.0","item":{"uid":"AF8A07038B63","itemValues":[{"itemValueDefinition":{"uid":"E0EFED6FD7E6","name":"Payment frequency","path":"paymentFrequency","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"}},"perUnit":"","uid":"1640B887FBF1","unit":"","name":"Payment frequency","value":"","path":"paymentFrequency","displayPath":"paymentFrequency","displayName":"Payment frequency"},{"itemValueDefinition":{"uid":"63005554AE8A","name":"Green tariff","path":"greenTariff","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"}},"perUnit":"","uid":"3D6FBA971997","unit":"","name":"Green tariff","value":"","path":"greenTariff","displayPath":"greenTariff","displayName":"Green tariff"},{"itemValueDefinition":{"uid":"527AADFB3B65","name":"Season","path":"season","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"}},"perUnit":"","uid":"DCCFE001A1A3","unit":"","name":"Season","value":"","path":"season","displayPath":"season","displayName":"Season"},{"itemValueDefinition":{"uid":"1740E500BDAB","choices":"true=true,false=false","name":"Includes Heating","path":"includesHeating","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"}},"perUnit":"","uid":"F678696C2BC8","unit":"","name":"Includes Heating","value":"false","path":"includesHeating","displayPath":"includesHeating","displayName":"Includes Heating"},{"itemValueDefinition":{"perUnit":"year","uid":"666C77B224B3","unit":"kg","name":"Mass Per Time","path":"massPerTime","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"6F62EB737262","unit":"kg","name":"Mass Per Time","value":"0","path":"massPerTime","displayPath":"massPerTime","displayName":"Mass Per Time"},{"itemValueDefinition":{"perUnit":"year","uid":"BFD215C4CAB1","unit":"kWh","name":"Energy Consumption","path":"energyConsumption","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"D19B538D7D84","unit":"kWh","name":"Energy Consumption","value":"10","path":"energyConsumption","displayPath":"energyConsumption","displayName":"Energy Consumption"},{"itemValueDefinition":{"perUnit":"year","uid":"A9B493A4A1A6","unit":"kWh","name":"Current Reading","path":"currentReading","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"CBF14AC62D7B","unit":"kWh","name":"Current Reading","value":"0","path":"currentReading","displayPath":"currentReading","displayName":"Current Reading"},{"itemValueDefinition":{"perUnit":"year","uid":"4C689DEF0A41","unit":"kWh","name":"Last Reading","path":"lastReading","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"57F5EF09B890","unit":"kWh","name":"Last Reading","value":"0","path":"lastReading","displayPath":"lastReading","displayName":"Last Reading"},{"itemValueDefinition":{"perUnit":"year","uid":"7BBABF4C2E9E","unit":"L","name":"Volume Per Time","path":"volumePerTime","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"993652F098D6","unit":"L","name":"Volume Per Time","value":"0","path":"volumePerTime","displayPath":"volumePerTime","displayName":"Volume Per Time"},{"itemValueDefinition":{"perUnit":"year","uid":"F0ED40C7EF8F","name":"Number of deliveries","path":"deliveries","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"3BA01E3607B3","unit":"","name":"Number of deliveries","value":"","path":"deliveries","displayPath":"deliveries","displayName":"Number of deliveries"}],"dataCategory":{"uid":"A92693A99BAD","name":"Quantity","path":"quantity"},"startDate":"2009-03-24T11:50:00Z","itemDefinition":{"uid":"212C818D8F16","name":"Energy Quantity","drillDown":"type"},"endDate":"","dataItem":{"uid":"66056991EE23","Label":"gas"},"modified":"2009-03-24T11:50:51Z","amount":{"unit":"kg/year","value":2.055},"environment":{"uid":"5F5887BCF726","itemsPerFeed":10,"description":"","name":"AMEE","owner":"","path":"","itemsPerPage":10},"created":"2009-03-24T11:50:32Z","name":null,"profile":{"uid":"459AB34FD0FC"}},"name":"Energy Consumption","value":"10","path":"energyConsumption","displayPath":"energyConsumption","displayName":"Energy Consumption","modified":"2009-03-24 11:50:51.0"},"path":"/home/energy/quantity/AF8A07038B63/energyConsumption","actions":{"allowCreate":true,"allowView":true,"allowList":true,"allowModify":true,"allowDelete":true},"profile":{"uid":"459AB34FD0FC"}}'))
183
+ @val = AMEE::Profile::ItemValue.get(@connection, "/profiles/459AB34FD0FC/home/energy/quantity/AF8A07038B63/energyConsumption")
184
+ end
185
+
186
+ it "can have value changed and saved back to server" do
187
+ @connection.should_receive(:put).with("/profiles/459AB34FD0FC/home/energy/quantity/AF8A07038B63/energyConsumption", {:value => 42, :unit => "kWh", :perUnit => "year"}).and_return(flexmock(:body => ''))
188
+ lambda {
189
+ @val.value = 42
190
+ @val.unit = "kWh"
191
+ @val.per_unit = "year"
192
+ @val.save!
193
+ }.should_not raise_error
194
+ end
195
+
196
+ end