amee 2.6.0 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +18 -0
- data/README +2 -2
- data/Rakefile +31 -0
- data/VERSION +1 -0
- data/amee-ruby.gemspec +147 -0
- data/examples/view_profile_item.rb +32 -0
- data/lib/amee.rb +0 -1
- data/lib/amee/profile_item.rb +27 -6
- data/spec/amee_spec.rb +25 -0
- data/spec/cache_spec.rb +152 -0
- data/spec/connection_spec.rb +295 -0
- data/spec/data_category_spec.rb +259 -0
- data/spec/data_item_spec.rb +224 -0
- data/spec/data_item_value_history_spec.rb +311 -0
- data/spec/data_item_value_spec.rb +231 -0
- data/spec/data_object_spec.rb +9 -0
- data/spec/drill_down_spec.rb +163 -0
- data/spec/fixtures/AD63A83B4D41.json +1 -0
- data/spec/fixtures/AD63A83B4D41.xml +1 -0
- data/spec/fixtures/create_item.json +1 -0
- data/spec/fixtures/create_item.xml +1 -0
- data/spec/fixtures/data.json +1 -0
- data/spec/fixtures/data.xml +1 -0
- data/spec/fixtures/data_home_energy_quantity.xml +146 -0
- data/spec/fixtures/data_home_energy_quantity_biodiesel.xml +177 -0
- data/spec/fixtures/data_transport_car_generic_drill_fuel_diesel.xml +33 -0
- data/spec/fixtures/empty.json +1 -0
- data/spec/fixtures/empty.xml +1 -0
- data/spec/fixtures/parse_test.xml +22 -0
- data/spec/fixtures/v0_data_transport_transport_drill_transportType_Car1.xml +20 -0
- data/spec/item_definition_spec.rb +313 -0
- data/spec/item_value_definition_spec.rb +253 -0
- data/spec/logger_spec.rb +16 -0
- data/spec/object_spec.rb +44 -0
- data/spec/parse_helper_spec.rb +72 -0
- data/spec/profile_category_spec.rb +565 -0
- data/spec/profile_item_spec.rb +451 -0
- data/spec/profile_item_value_spec.rb +196 -0
- data/spec/profile_object_spec.rb +24 -0
- data/spec/profile_spec.rb +88 -0
- data/spec/rails_spec.rb +48 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +56 -0
- data/spec/user_spec.rb +249 -0
- metadata +189 -55
- data/lib/amee/version.rb +0 -10
@@ -0,0 +1,177 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
2
|
+
<Resources xmlns="http://schemas.amee.cc/2.0">
|
3
|
+
<DataItemResource>
|
4
|
+
<DataItem created="2007-07-27 09:49:32.0" modified="2009-09-15 15:06:12.0" uid="878854C275BC">
|
5
|
+
<Name>878854C275BC</Name>
|
6
|
+
<ItemValues>
|
7
|
+
<ItemValue uid="7071F0E96196">
|
8
|
+
<Path>kgCO2PerKg</Path>
|
9
|
+
<Name>kgCO2 Per Kg</Name>
|
10
|
+
<Value/>
|
11
|
+
<Unit/>
|
12
|
+
<PerUnit/>
|
13
|
+
<StartDate>1969-12-31T19:00:00-05:00</StartDate>
|
14
|
+
<ItemValueDefinition uid="B5AC731EF1D5">
|
15
|
+
<Path>kgCO2PerKg</Path>
|
16
|
+
<Name>kgCO2 Per Kg</Name>
|
17
|
+
<ValueDefinition created="2007-07-27 08:30:44.0" modified="2007-07-27 08:30:44.0" uid="F066E097D76D">
|
18
|
+
<Name>kgCO2PerKg</Name>
|
19
|
+
<ValueType>DECIMAL</ValueType>
|
20
|
+
<Description/>
|
21
|
+
<Environment uid="5F5887BCF726"/>
|
22
|
+
</ValueDefinition>
|
23
|
+
<FromProfile>false</FromProfile>
|
24
|
+
<FromData>true</FromData>
|
25
|
+
<DrillDown>false</DrillDown>
|
26
|
+
</ItemValueDefinition>
|
27
|
+
</ItemValue>
|
28
|
+
<ItemValue uid="015D3ACF02BD">
|
29
|
+
<Path>source</Path>
|
30
|
+
<Name>Source</Name>
|
31
|
+
<Value>net CV RME-type Wells to wheels/European Commission/JRC 2006 http://ies.jrc.ec.europa.eu/our-activities/support-to-eu-policies/well-to-wheels-analysis/WTW.html</Value>
|
32
|
+
<Unit/>
|
33
|
+
<PerUnit/>
|
34
|
+
<StartDate>1969-12-31T19:00:00-05:00</StartDate>
|
35
|
+
<ItemValueDefinition uid="75DE0251B056">
|
36
|
+
<Path>source</Path>
|
37
|
+
<Name>Source</Name>
|
38
|
+
<ValueDefinition created="2007-07-27 08:30:44.0" modified="2007-07-27 08:30:44.0" uid="CCEB59CACE1B">
|
39
|
+
<Name>text</Name>
|
40
|
+
<ValueType>TEXT</ValueType>
|
41
|
+
<Description/>
|
42
|
+
<Environment uid="5F5887BCF726"/>
|
43
|
+
</ValueDefinition>
|
44
|
+
<FromProfile>false</FromProfile>
|
45
|
+
<FromData>true</FromData>
|
46
|
+
<DrillDown>false</DrillDown>
|
47
|
+
</ItemValueDefinition>
|
48
|
+
</ItemValue>
|
49
|
+
<ItemValue uid="1DFEF8E6D7E5">
|
50
|
+
<Path>kgCO2PerKWh</Path>
|
51
|
+
<Name>kgCO2 Per KWh</Name>
|
52
|
+
<Value/>
|
53
|
+
<Unit/>
|
54
|
+
<PerUnit/>
|
55
|
+
<StartDate>1969-12-31T19:00:00-05:00</StartDate>
|
56
|
+
<ItemValueDefinition uid="469C1AE4B79A">
|
57
|
+
<Path>kgCO2PerKWh</Path>
|
58
|
+
<Name>kgCO2 Per KWh</Name>
|
59
|
+
<ValueDefinition created="2007-07-27 08:30:44.0" modified="2007-07-27 08:30:44.0" uid="3EA39C552E81">
|
60
|
+
<Name>kgCO2PerKWh</Name>
|
61
|
+
<ValueType>DECIMAL</ValueType>
|
62
|
+
<Description/>
|
63
|
+
<Environment uid="5F5887BCF726"/>
|
64
|
+
</ValueDefinition>
|
65
|
+
<FromProfile>false</FromProfile>
|
66
|
+
<FromData>true</FromData>
|
67
|
+
<DrillDown>false</DrillDown>
|
68
|
+
</ItemValueDefinition>
|
69
|
+
</ItemValue>
|
70
|
+
<ItemValue uid="219EE9D836E0">
|
71
|
+
<Path>kgCO2PerLitre</Path>
|
72
|
+
<Name>kgCO2 Per Litre</Name>
|
73
|
+
<Value>2.5000</Value>
|
74
|
+
<Unit/>
|
75
|
+
<PerUnit/>
|
76
|
+
<StartDate>1969-12-31T19:00:00-05:00</StartDate>
|
77
|
+
<ItemValueDefinition uid="EAFBD1CA93E8">
|
78
|
+
<Path>kgCO2PerLitre</Path>
|
79
|
+
<Name>kgCO2 Per Litre</Name>
|
80
|
+
<ValueDefinition created="2007-07-27 08:30:44.0" modified="2007-07-27 08:30:44.0" uid="C809A0FE1918">
|
81
|
+
<Name>kgCO2PerLitre</Name>
|
82
|
+
<ValueType>DECIMAL</ValueType>
|
83
|
+
<Description/>
|
84
|
+
<Environment uid="5F5887BCF726"/>
|
85
|
+
</ValueDefinition>
|
86
|
+
<FromProfile>false</FromProfile>
|
87
|
+
<FromData>true</FromData>
|
88
|
+
<DrillDown>false</DrillDown>
|
89
|
+
</ItemValueDefinition>
|
90
|
+
</ItemValue>
|
91
|
+
<ItemValue uid="5A46861E475C">
|
92
|
+
<Path>type</Path>
|
93
|
+
<Name>Type</Name>
|
94
|
+
<Value>biodiesel</Value>
|
95
|
+
<Unit/>
|
96
|
+
<PerUnit/>
|
97
|
+
<StartDate>1969-12-31T19:00:00-05:00</StartDate>
|
98
|
+
<ItemValueDefinition uid="5DF1F01B2106">
|
99
|
+
<Path>type</Path>
|
100
|
+
<Name>Type</Name>
|
101
|
+
<ValueDefinition created="2007-07-27 08:30:44.0" modified="2007-07-27 08:30:44.0" uid="CCEB59CACE1B">
|
102
|
+
<Name>text</Name>
|
103
|
+
<ValueType>TEXT</ValueType>
|
104
|
+
<Description/>
|
105
|
+
<Environment uid="5F5887BCF726"/>
|
106
|
+
</ValueDefinition>
|
107
|
+
<FromProfile>false</FromProfile>
|
108
|
+
<FromData>true</FromData>
|
109
|
+
<DrillDown>true</DrillDown>
|
110
|
+
</ItemValueDefinition>
|
111
|
+
</ItemValue>
|
112
|
+
</ItemValues>
|
113
|
+
<Environment uid="5F5887BCF726"/>
|
114
|
+
<ItemDefinition uid="212C818D8F16"/>
|
115
|
+
<DataCategory uid="A92693A99BAD">
|
116
|
+
<Name>Quantity</Name>
|
117
|
+
<Path>quantity</Path>
|
118
|
+
<Deprecated>false</Deprecated>
|
119
|
+
</DataCategory>
|
120
|
+
<Path>878854C275BC</Path>
|
121
|
+
<Label>biodiesel</Label>
|
122
|
+
<StartDate>1969-12-31T19:00:00-05:00</StartDate>
|
123
|
+
<EndDate/>
|
124
|
+
</DataItem>
|
125
|
+
<Path>/home/energy/quantity/878854C275BC</Path>
|
126
|
+
<Choices>
|
127
|
+
<Name>userValueChoices</Name>
|
128
|
+
<Choices>
|
129
|
+
<Choice>
|
130
|
+
<Name>deliveries</Name>
|
131
|
+
<Value/>
|
132
|
+
</Choice>
|
133
|
+
<Choice>
|
134
|
+
<Name>greenTariff</Name>
|
135
|
+
<Value/>
|
136
|
+
</Choice>
|
137
|
+
<Choice>
|
138
|
+
<Name>lastReading</Name>
|
139
|
+
<Value>0</Value>
|
140
|
+
</Choice>
|
141
|
+
<Choice>
|
142
|
+
<Name>currentReading</Name>
|
143
|
+
<Value>0</Value>
|
144
|
+
</Choice>
|
145
|
+
<Choice>
|
146
|
+
<Name>includesHeating</Name>
|
147
|
+
<Value>false</Value>
|
148
|
+
</Choice>
|
149
|
+
<Choice>
|
150
|
+
<Name>massPerTime</Name>
|
151
|
+
<Value>0</Value>
|
152
|
+
</Choice>
|
153
|
+
<Choice>
|
154
|
+
<Name>volumePerTime</Name>
|
155
|
+
<Value>0</Value>
|
156
|
+
</Choice>
|
157
|
+
<Choice>
|
158
|
+
<Name>energyConsumption</Name>
|
159
|
+
<Value>0</Value>
|
160
|
+
</Choice>
|
161
|
+
<Choice>
|
162
|
+
<Name>season</Name>
|
163
|
+
<Value/>
|
164
|
+
</Choice>
|
165
|
+
<Choice>
|
166
|
+
<Name>paymentFrequency</Name>
|
167
|
+
<Value/>
|
168
|
+
</Choice>
|
169
|
+
</Choices>
|
170
|
+
</Choices>
|
171
|
+
<AmountPerMonth>0.0</AmountPerMonth>
|
172
|
+
<Amount unit="kg/year">0.0</Amount>
|
173
|
+
<Amounts>
|
174
|
+
<Amount default="true" perUnit="year" type="CO2" unit="kg">0.0</Amount>
|
175
|
+
</Amounts>
|
176
|
+
</DataItemResource>
|
177
|
+
</Resources>
|
@@ -0,0 +1,33 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<Resources>
|
3
|
+
<DrillDownResource>
|
4
|
+
<DataCategory uid="87E55DA88017">
|
5
|
+
<Name>Generic</Name>
|
6
|
+
<Path>generic</Path>
|
7
|
+
</DataCategory>
|
8
|
+
<ItemDefinition uid="123C4A18B5D6"/>
|
9
|
+
<Selections>
|
10
|
+
<Choice>
|
11
|
+
<Name>fuel</Name>
|
12
|
+
<Value>diesel</Value>
|
13
|
+
</Choice>
|
14
|
+
</Selections>
|
15
|
+
<Choices>
|
16
|
+
<Name>size</Name>
|
17
|
+
<Choices>
|
18
|
+
<Choice>
|
19
|
+
<Name>large</Name>
|
20
|
+
<Value>large</Value>
|
21
|
+
</Choice>
|
22
|
+
<Choice>
|
23
|
+
<Name>medium</Name>
|
24
|
+
<Value>medium</Value>
|
25
|
+
</Choice>
|
26
|
+
<Choice>
|
27
|
+
<Name>small</Name>
|
28
|
+
<Value>small</Value>
|
29
|
+
</Choice>
|
30
|
+
</Choices>
|
31
|
+
</Choices>
|
32
|
+
</DrillDownResource>
|
33
|
+
</Resources>
|
@@ -0,0 +1 @@
|
|
1
|
+
{}
|
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?><Resources></Resources>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<root>
|
3
|
+
<attrib_test attrib='attribute_value' empty_attrib=''/>
|
4
|
+
<content_test>content</content_test>
|
5
|
+
<whitespace_content_test>
|
6
|
+
</whitespace_content_test>
|
7
|
+
<empty_content_test></empty_content_test>
|
8
|
+
<self_closing_content_test/>
|
9
|
+
<multi_attrib_test>
|
10
|
+
<attrib_test attrib='attribute_value'/>
|
11
|
+
<attrib_test attrib='attribute_value_1'/>
|
12
|
+
<attrib_test attrib=''/>
|
13
|
+
<attrib_test/>
|
14
|
+
</multi_attrib_test>
|
15
|
+
<multi_content_test>
|
16
|
+
<content>content</content>
|
17
|
+
<content>
|
18
|
+
</content>
|
19
|
+
<content></content>
|
20
|
+
<content/>
|
21
|
+
</multi_content_test>
|
22
|
+
</root>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<Resources>
|
3
|
+
<DrillDownResource>
|
4
|
+
<DataCategory uid="CD13B9174A6A"/>
|
5
|
+
<ItemDefinition uid="7CD0FC1D3B36"/>
|
6
|
+
<Selections>
|
7
|
+
<Choice>
|
8
|
+
<name>transportType</name>
|
9
|
+
<value>Car1</value>
|
10
|
+
</Choice>
|
11
|
+
</Selections>
|
12
|
+
<Choices>
|
13
|
+
<name>transportStyle</name>
|
14
|
+
<Choice>
|
15
|
+
<name>-</name>
|
16
|
+
<value>-</value>
|
17
|
+
</Choice>
|
18
|
+
</Choices>
|
19
|
+
</DrillDownResource>
|
20
|
+
</Resources>
|
@@ -0,0 +1,313 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe AMEE::Admin::ItemDefinition do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@item_definition = AMEE::Admin::ItemDefinition.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should have common AMEE object properties" do
|
10
|
+
@item_definition.is_a?(AMEE::Object).should be_true
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should have a name" do
|
14
|
+
@item_definition.should respond_to(:name)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should initialize AMEE::Object data on creation" do
|
18
|
+
uid = 'ABCD1234'
|
19
|
+
@item_definition = AMEE::Admin::ItemDefinition.new(:uid => uid)
|
20
|
+
@item_definition.uid.should == uid
|
21
|
+
end
|
22
|
+
|
23
|
+
it "can be created with hash of data" do
|
24
|
+
name = "test"
|
25
|
+
@item_definition = AMEE::Admin::ItemDefinition.new(:name => name)
|
26
|
+
@item_definition.name.should == name
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
describe AMEE::Admin::ItemDefinition, "with an authenticated connection" do
|
32
|
+
|
33
|
+
it "should parse XML correctly" do
|
34
|
+
connection = flexmock "connection"
|
35
|
+
connection.should_receive(:get).with("/definitions/itemDefinitions/BD88D30D1214", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8" standalone="no"?><Resources><ItemDefinitionResource><ItemDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="BD88D30D1214"><Name>Bus Generic</Name><DrillDown>type</DrillDown><Environment uid="5F5887BCF726"/></ItemDefinition></ItemDefinitionResource></Resources>'))
|
36
|
+
@data = AMEE::Admin::ItemDefinition.load(connection,"BD88D30D1214")
|
37
|
+
@data.uid.should == "BD88D30D1214"
|
38
|
+
@data.created.should == DateTime.new(2007,7,27,9,30,44)
|
39
|
+
@data.modified.should == DateTime.new(2007,7,27,9,30,44)
|
40
|
+
@data.name.should == "Bus Generic"
|
41
|
+
@data.drill_downs.should == ["type"]
|
42
|
+
@data.full_path.should == '/definitions/itemDefinitions/BD88D30D1214'
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should parse JSON correctly" do
|
46
|
+
connection = flexmock "connection"
|
47
|
+
connection.should_receive(:get).with("/definitions/itemDefinitions/BD88D30D1214", {}).and_return(flexmock(:body => '{"itemDefinition":{"uid":"BD88D30D1214","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","name":"Bus Generic","drillDown":"type","modified":"2007-07-27 09:30:44.0"}}'))
|
48
|
+
@data = AMEE::Admin::ItemDefinition.load(connection,"BD88D30D1214")
|
49
|
+
@data.uid.should == "BD88D30D1214"
|
50
|
+
@data.created.should == DateTime.new(2007,7,27,9,30,44)
|
51
|
+
@data.modified.should == DateTime.new(2007,7,27,9,30,44)
|
52
|
+
@data.name.should == "Bus Generic"
|
53
|
+
@data.drill_downs.should == ["type"]
|
54
|
+
@data.full_path.should == '/definitions/itemDefinitions/BD88D30D1214'
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should be able to load an item value definition list" do
|
58
|
+
connection = flexmock "connection"
|
59
|
+
connection.should_receive(:get).with("/definitions/itemDefinitions/BD88D30D1214", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8" standalone="no"?><Resources><ItemDefinitionResource><ItemDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="BD88D30D1214"><Name>Bus Generic</Name><DrillDown>type</DrillDown><Environment uid="5F5887BCF726"/></ItemDefinition></ItemDefinitionResource></Resources>'))
|
60
|
+
connection.should_receive(:retries).and_return(0).once
|
61
|
+
connection.should_receive(:get).with("/definitions/itemDefinitions/BD88D30D1214/itemValueDefinitions", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8" standalone="no"?><Resources><ItemValueDefinitionsResource><Environment uid="5F5887BCF726"/><ItemDefinition uid="BD88D30D1214"/><ItemValueDefinitions><ItemValueDefinition uid="A8A212610A57"><Path>distancePerJourney</Path><Name>Distance per journey</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>km</Unit><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="D2AB505D2D91"><Path>type</Path><Name>Type</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>false</FromProfile><FromData>true</FromData><DrillDown>true</DrillDown></ItemValueDefinition><ItemValueDefinition uid="41EC337E5C79"><Path>numberOfJourneys</Path><Name>Number of journeys</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="9BAFC976044B"><Path>source</Path><Name>Source</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>false</FromProfile><FromData>true</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="9813267B616E"><Path>country</Path><Name>Country</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="263DE76AF8AA"><Path>kgCO2PerPassengerKmIE</Path><Name>kgCO2 Per Passenger Km IE</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="996AE5477B3F"><Name>kgCO2PerKm</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>false</FromProfile><FromData>true</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="F5550D71085F"><Path>kgCO2PerKmPassenger</Path><Name>kgCO2 Per Passenger Km</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="996AE5477B3F"><Name>kgCO2PerKm</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>false</FromProfile><FromData>true</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="FE166C7602BB"><Path>typicalJourneyDistance</Path><Name>Typical journey distance</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>false</FromProfile><FromData>true</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="2F76AB4E3C0F"><Path>journeyFrequency</Path><Name>Journey frequency</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="B0F02E544603"><Path>numberOfPassengers</Path><Name>Number of passengers</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="28D0B8C4F52A"><Path>useTypicalDistance</Path><Name>Use typical distance</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="6334117D28A0"><Path>distanceKmPerMonth</Path><Name>Distance Km Per Month</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="B691497F1CF2"><Name>kM</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>km</Unit><PerUnit>month</PerUnit><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="98EA75911467"><Path>distancePerJourney</Path><Name>Distance per journey</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>km</Unit><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="584BEA802996"><Path>isReturn</Path><Name>Is return</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition><ItemValueDefinition uid="6CBF739E12F0"><Path>distance</Path><Name>Distance</Name><ValueDefinition created="2007-07-27 09:30:44.0" modified="2007-07-27 09:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>km</Unit><PerUnit>year</PerUnit><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition></ItemValueDefinitions></ItemValueDefinitionsResource></Resources>')).once
|
62
|
+
@data = AMEE::Admin::ItemDefinition.load(connection,"BD88D30D1214")
|
63
|
+
@data.uid.should == "BD88D30D1214"
|
64
|
+
@list=@data.item_value_definition_list
|
65
|
+
@list.length.should==15
|
66
|
+
@list.first.uid.should=='A8A212610A57'
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should fail gracefully with incorrect data" do
|
70
|
+
connection = flexmock "connection"
|
71
|
+
xml = '<?xml version="1.0" encoding="UTF-8"?><Resources></Resources>'
|
72
|
+
connection.should_receive(:get).with("/admin", {}).and_return(flexmock(:body => xml))
|
73
|
+
lambda{AMEE::Admin::ItemDefinition.get(connection, "/admin")}.should raise_error(AMEE::BadData)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should fail gracefully with incorrect JSON data" do
|
77
|
+
connection = flexmock "connection"
|
78
|
+
json = '{}'
|
79
|
+
connection.should_receive(:get).with("/admin", {}).and_return(flexmock(:body => json))
|
80
|
+
lambda{AMEE::Admin::ItemDefinition.get(connection, "/admin")}.should raise_error(AMEE::BadData)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should fail gracefully on other errors" do
|
84
|
+
connection = flexmock "connection"
|
85
|
+
connection.should_receive(:get).with("/admin", {}).and_raise("unidentified error")
|
86
|
+
lambda{AMEE::Admin::ItemDefinition.get(connection, "/admin")}.should raise_error(AMEE::BadData)
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
DefinitionsListResponse=<<HERE
|
92
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
93
|
+
<Resources>
|
94
|
+
<ItemDefinitionsResource>
|
95
|
+
<ItemDefinitions>
|
96
|
+
<ItemDefinition uid="2169991DE821">
|
97
|
+
<Name>AAA Car Generic</Name>
|
98
|
+
<DrillDown>fuel,size</DrillDown>
|
99
|
+
</ItemDefinition>
|
100
|
+
<ItemDefinition uid="18CB59F9EC2D">
|
101
|
+
<Name>AAA Units test</Name>
|
102
|
+
<DrillDown>type</DrillDown>
|
103
|
+
</ItemDefinition>
|
104
|
+
<ItemDefinition uid="76C56F7DF49A">
|
105
|
+
<Name>AAAA1234Test</Name>
|
106
|
+
<DrillDown/>
|
107
|
+
</ItemDefinition>
|
108
|
+
<ItemDefinition uid="CF344E20E9AC">
|
109
|
+
<Name>AAATipTest</Name>
|
110
|
+
<DrillDown>question</DrillDown>
|
111
|
+
</ItemDefinition>
|
112
|
+
<ItemDefinition uid="70BCD634D0A4">
|
113
|
+
<Name>ActOnCO2 Action</Name>
|
114
|
+
<DrillDown>type</DrillDown></ItemDefinition>
|
115
|
+
<ItemDefinition uid="62058B6FD778">
|
116
|
+
<Name>ActOnCO2 Metadata</Name>
|
117
|
+
<DrillDown>type</DrillDown>
|
118
|
+
</ItemDefinition>
|
119
|
+
<ItemDefinition uid="D3351CDC11C8">
|
120
|
+
<Name>ADigTest</Name>
|
121
|
+
<DrillDown/></ItemDefinition>
|
122
|
+
<ItemDefinition uid="A02807E44CA3">
|
123
|
+
<Name>Adipic Acid N2O emissions</Name>
|
124
|
+
<DrillDown>abatementTechnology</DrillDown>
|
125
|
+
</ItemDefinition>
|
126
|
+
<ItemDefinition uid="B910141B00DB">
|
127
|
+
<Name>AJC ID TEST</Name>
|
128
|
+
<DrillDown>type</DrillDown>
|
129
|
+
</ItemDefinition>
|
130
|
+
<ItemDefinition uid="4660BD4FCF97">
|
131
|
+
<Name>Aluminium Production: Alternative (no anode data)</Name>
|
132
|
+
<DrillDown>type</DrillDown>
|
133
|
+
</ItemDefinition></ItemDefinitions>
|
134
|
+
<Pager>
|
135
|
+
<Start>0</Start>
|
136
|
+
<From>1</From>
|
137
|
+
<To>10</To>
|
138
|
+
<Items>10</Items>
|
139
|
+
<CurrentPage>1</CurrentPage>
|
140
|
+
<RequestedPage>1</RequestedPage>
|
141
|
+
<NextPage>-1</NextPage>
|
142
|
+
<PreviousPage>-1</PreviousPage>
|
143
|
+
<LastPage>1</LastPage>
|
144
|
+
<ItemsPerPage>10</ItemsPerPage>
|
145
|
+
<ItemsFound>10</ItemsFound>
|
146
|
+
</Pager>
|
147
|
+
</ItemDefinitionsResource>
|
148
|
+
</Resources>
|
149
|
+
HERE
|
150
|
+
|
151
|
+
DefinitionsListResponsePage1=<<HERE
|
152
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
153
|
+
<Resources>
|
154
|
+
<ItemDefinitionsResource>
|
155
|
+
<ItemDefinitions>
|
156
|
+
<ItemDefinition uid="2169991DE821">
|
157
|
+
<Name>AAA Car Generic</Name>
|
158
|
+
<DrillDown>fuel,size</DrillDown>
|
159
|
+
</ItemDefinition>
|
160
|
+
<ItemDefinition uid="18CB59F9EC2D">
|
161
|
+
<Name>AAA Units test</Name>
|
162
|
+
<DrillDown>type</DrillDown>
|
163
|
+
</ItemDefinition>
|
164
|
+
<ItemDefinition uid="76C56F7DF49A">
|
165
|
+
<Name>AAAA1234Test</Name>
|
166
|
+
<DrillDown/>
|
167
|
+
</ItemDefinition>
|
168
|
+
<ItemDefinition uid="CF344E20E9AC">
|
169
|
+
<Name>AAATipTest</Name>
|
170
|
+
<DrillDown>question</DrillDown>
|
171
|
+
</ItemDefinition></ItemDefinitions>
|
172
|
+
<Pager>
|
173
|
+
<Start>0</Start>
|
174
|
+
<From>1</From>
|
175
|
+
<To>4</To>
|
176
|
+
<Items>10</Items>
|
177
|
+
<CurrentPage>1</CurrentPage>
|
178
|
+
<RequestedPage>1</RequestedPage>
|
179
|
+
<NextPage>2</NextPage>
|
180
|
+
<PreviousPage>-1</PreviousPage>
|
181
|
+
<LastPage>3</LastPage>
|
182
|
+
<ItemsPerPage>4</ItemsPerPage>
|
183
|
+
<ItemsFound>4</ItemsFound>
|
184
|
+
</Pager>
|
185
|
+
</ItemDefinitionsResource>
|
186
|
+
</Resources>
|
187
|
+
HERE
|
188
|
+
DefinitionsListResponsePage2=<<HERE
|
189
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
190
|
+
<Resources>
|
191
|
+
<ItemDefinitionsResource>
|
192
|
+
<ItemDefinitions>
|
193
|
+
<ItemDefinition uid="70BCD634D0A4">
|
194
|
+
<Name>ActOnCO2 Action</Name>
|
195
|
+
<DrillDown>type</DrillDown></ItemDefinition>
|
196
|
+
<ItemDefinition uid="62058B6FD778">
|
197
|
+
<Name>ActOnCO2 Metadata</Name>
|
198
|
+
<DrillDown>type</DrillDown>
|
199
|
+
</ItemDefinition>
|
200
|
+
<ItemDefinition uid="D3351CDC11C8">
|
201
|
+
<Name>ADigTest</Name>
|
202
|
+
<DrillDown/></ItemDefinition>
|
203
|
+
<ItemDefinition uid="A02807E44CA3">
|
204
|
+
<Name>Adipic Acid N2O emissions</Name>
|
205
|
+
<DrillDown>abatementTechnology</DrillDown>
|
206
|
+
</ItemDefinition></ItemDefinitions>
|
207
|
+
<Pager>
|
208
|
+
<Start>4</Start>
|
209
|
+
<From>5</From>
|
210
|
+
<To>8</To>
|
211
|
+
<Items>10</Items>
|
212
|
+
<CurrentPage>2</CurrentPage>
|
213
|
+
<RequestedPage>2</RequestedPage>
|
214
|
+
<NextPage>3</NextPage>
|
215
|
+
<PreviousPage>1</PreviousPage>
|
216
|
+
<LastPage>3</LastPage>
|
217
|
+
<ItemsPerPage>4</ItemsPerPage>
|
218
|
+
<ItemsFound>4</ItemsFound>
|
219
|
+
</Pager>
|
220
|
+
</ItemDefinitionsResource>
|
221
|
+
</Resources>
|
222
|
+
HERE
|
223
|
+
DefinitionsListResponsePage3=<<HERE
|
224
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
225
|
+
<Resources>
|
226
|
+
<ItemDefinitionsResource>
|
227
|
+
<ItemDefinitions>
|
228
|
+
<ItemDefinition uid="B910141B00DB">
|
229
|
+
<Name>AJC ID TEST</Name>
|
230
|
+
<DrillDown>type</DrillDown>
|
231
|
+
</ItemDefinition>
|
232
|
+
<ItemDefinition uid="4660BD4FCF97">
|
233
|
+
<Name>Aluminium Production: Alternative (no anode data)</Name>
|
234
|
+
<DrillDown>type</DrillDown>
|
235
|
+
</ItemDefinition>
|
236
|
+
</ItemDefinitions>
|
237
|
+
<Pager>
|
238
|
+
<Start>8</Start>
|
239
|
+
<From>9</From>
|
240
|
+
<To>10</To>
|
241
|
+
<Items>10</Items>
|
242
|
+
<CurrentPage>3</CurrentPage>
|
243
|
+
<RequestedPage>3</RequestedPage>
|
244
|
+
<NextPage>-1</NextPage>
|
245
|
+
<PreviousPage>2</PreviousPage>
|
246
|
+
<LastPage>3</LastPage>
|
247
|
+
<ItemsPerPage>4</ItemsPerPage>
|
248
|
+
<ItemsFound>2</ItemsFound>
|
249
|
+
</Pager>
|
250
|
+
</ItemDefinitionsResource>
|
251
|
+
</Resources>
|
252
|
+
HERE
|
253
|
+
|
254
|
+
describe AMEE::Admin::ItemDefinitionList do
|
255
|
+
it "Should parse a single page" do
|
256
|
+
connection = flexmock "connection"
|
257
|
+
connection.should_receive(:retries).and_return(0).once
|
258
|
+
connection.should_receive(:get).with("/definitions/itemDefinitions",{}).once.
|
259
|
+
and_return flexmock(:body =>DefinitionsListResponse)
|
260
|
+
@list=AMEE::Admin::ItemDefinitionList.new(connection)
|
261
|
+
@list.first.should be_a AMEE::Admin::ItemDefinition
|
262
|
+
@list.first.uid.should == "2169991DE821"
|
263
|
+
@list.first.name.should == "AAA Car Generic"
|
264
|
+
@list.size.should==10
|
265
|
+
end
|
266
|
+
|
267
|
+
it "Should retry on parse failures" do
|
268
|
+
connection = flexmock "connection"
|
269
|
+
connection.should_receive(:retries).and_return(2).once
|
270
|
+
connection.should_receive(:get).with("/definitions/itemDefinitions",{}).twice.
|
271
|
+
and_return flexmock(:body =>DefinitionsListResponse.first(12))
|
272
|
+
connection.should_receive(:expire).with("/definitions/itemDefinitions").times(2)
|
273
|
+
connection.should_receive(:get).with("/definitions/itemDefinitions",{}).once.
|
274
|
+
and_return flexmock(:body =>DefinitionsListResponse)
|
275
|
+
@list=AMEE::Admin::ItemDefinitionList.new(connection)
|
276
|
+
@list.first.should be_a AMEE::Admin::ItemDefinition
|
277
|
+
@list.first.uid.should == "2169991DE821"
|
278
|
+
@list.first.name.should == "AAA Car Generic"
|
279
|
+
@list.size.should==10
|
280
|
+
end
|
281
|
+
|
282
|
+
it "Should retry on parse failures and bubble up failure if never successful" do
|
283
|
+
connection = flexmock "connection"
|
284
|
+
connection.should_receive(:retries).and_return(2).once
|
285
|
+
connection.should_receive(:get).with("/definitions/itemDefinitions",{}).times(3).
|
286
|
+
and_return flexmock(:body =>DefinitionsListResponse.first(12))
|
287
|
+
connection.should_receive(:expire).with("/definitions/itemDefinitions").times(3)
|
288
|
+
lambda {
|
289
|
+
AMEE::Admin::ItemDefinitionList.new(connection)
|
290
|
+
}.should raise_error(Nokogiri::XML::SyntaxError)
|
291
|
+
end
|
292
|
+
it "Should parse multiple pages" do
|
293
|
+
connection = flexmock "connection"
|
294
|
+
connection.should_receive(:retries).and_return(0).times(3)
|
295
|
+
connection.should_receive(:get).with("/definitions/itemDefinitions",{}).
|
296
|
+
once.
|
297
|
+
and_return flexmock(:body =>DefinitionsListResponsePage1)
|
298
|
+
connection.should_receive(:get).with("/definitions/itemDefinitions",
|
299
|
+
{:page=>2}).once.
|
300
|
+
and_return flexmock(:body =>DefinitionsListResponsePage2)
|
301
|
+
connection.should_receive(:get).with("/definitions/itemDefinitions",
|
302
|
+
{:page=>3}).once.
|
303
|
+
and_return flexmock(:body =>DefinitionsListResponsePage3)
|
304
|
+
@list=AMEE::Admin::ItemDefinitionList.new(connection)
|
305
|
+
@list.first.should be_a AMEE::Admin::ItemDefinition
|
306
|
+
@list.first.uid.should == "2169991DE821"
|
307
|
+
@list.first.name.should == "AAA Car Generic"
|
308
|
+
@list[4].should be_a AMEE::Admin::ItemDefinition
|
309
|
+
@list[4].uid.should == "70BCD634D0A4"
|
310
|
+
@list[4].name.should == "ActOnCO2 Action"
|
311
|
+
@list.size.should==10
|
312
|
+
end
|
313
|
+
end
|