From: Michal Fojtik <[email protected]>
Signed-off-by: Michal fojtik <[email protected]> --- server/tests/cimi/features/machines.feature | 37 +++++++----- .../features/step_definitions/machines_steps.rb | 59 ++++++++++++++++---- server/tests/cimi/features/support/env.rb | 8 +++ 3 files changed, 77 insertions(+), 27 deletions(-) diff --git a/server/tests/cimi/features/machines.feature b/server/tests/cimi/features/machines.feature index badf427..08934ad 100644 --- a/server/tests/cimi/features/machines.feature +++ b/server/tests/cimi/features/machines.feature @@ -2,7 +2,7 @@ Feature: Managing Machines In order to interact with the provider We must first be provided a URL to the main entry point (CEP). - Scenario: Create a New Machine + Scenario: Create a New Machine entity Given Cloud Entry Point URL is provided And client retrieve the Cloud Entry Point When client specifies a Machine Image @@ -14,28 +14,33 @@ Feature: Managing Machines | description | sampleMachine1Description | Then client should be able to create this Machine - Scenario: Querying created Machine + Scenario: Querying created Machine entity Given Cloud Entry Point URL is provided And client retrieve the Cloud Entry Point - When client query for 'sampleMachine1' Machine entity - Then client should verify that this machine exists - And client should verify that this Machine has set - | name | sampleMachine1 || - | description | sampleMachine1Description || - | cpu | 1 || - | memory | quantity | 1740 | - | state | RUNNING || + When client query for created Machine entity + Then client should verify that this Machine exists + And client should verify that this Machine has been created properly + | cpu | 1 | + | memory | 1740.8 | + | state | STARTED | - Scenario: Stopping Machine + Scenario: Stopping created Machine entity Given Cloud Entry Point URL is provided And client retrieve the Cloud Entry Point - When client executes stop operation on Machine 'sampleMachine1' - Then client should be able to query for 'sampleMachine1' Machine entity + When client executes stop operation on created Machine + Then client query for created Machine entity And client should verify that this machine is stopped - Scenario: Starting Machine + Scenario: Starting created Machine entity Given Cloud Entry Point URL is provided And client retrieve the Cloud Entry Point - When client executes start operation on Machine 'sampleMachine1' - Then client should be able to query for 'sampleMachine1' Machine entity + When client executes start operation on created Machine + Then client query for created Machine entity And client should verify that this machine is started + + Scenario: Deleting created Machine entity + Given Cloud Entry Point URL is provided + And client retrieve the Cloud Entry Point + When client executes delete operation on created Machine + Then client query for created Machine entity + And client should verify that this machine is deleted diff --git a/server/tests/cimi/features/step_definitions/machines_steps.rb b/server/tests/cimi/features/step_definitions/machines_steps.rb index d8a6b87..a8b63d0 100644 --- a/server/tests/cimi/features/step_definitions/machines_steps.rb +++ b/server/tests/cimi/features/step_definitions/machines_steps.rb @@ -21,9 +21,10 @@ end When /^client specifies a new Machine using$/ do |machine| @machine_image.should_not be_nil @machine_configuration.should_not be_nil + @new_machine_name = machine.raw[0][1] @builder = Nokogiri::XML::Builder.new do |xml| xml.Machine(:xmlns => CMWG_NAMESPACE) { - xml.name machine.raw[0][1] + xml.name @new_machine_name xml.description machine.raw[1][1] xml.MachineTemplate { xml.MachineConfig( :href => @machine_configuration.uri ) @@ -34,23 +35,59 @@ When /^client specifies a new Machine using$/ do |machine| end Then /^client should be able to create this Machine$/ do - pending "\nNOTE: There is an inconsistency between Primer and CIMI spec\n" + - "The Primer says that client should send just pointners MachineConf and MachineImg\n"+ - "The CIMI says that full XML need to be provided in order to create a Machine\n\n" - @machine = CIMI::Model::Machine.from_xml(@builder.to_xml) authorize 'mockuser', 'mockpassword' - post '/cimi/machines', @machine + header 'Content-Type', 'application/xml' + post '/cimi/machines', @builder.to_xml last_response.status.should == 201 + set_new_machine(CIMI::Model::Machine.from_xml(last_response.body)) end -Then /^client should be able to query this Machine$/ do - get "/cimi/machines/%s" % (@new_machine/'') +Then /^client query for created Machine entity$/ do + authorize 'mockuser', 'mockpassword' + header 'Content-Type', 'application/xml' + get "/cimi/machines/%s" % new_machine.name + if @delete_operation + last_response.status.should == 404 + else + last_response.status.should == 200 + @machine = CIMI::Model::Machine.from_xml(last_response.body) + @machine.name.should == new_machine.name + end + end -When /^client executes (\w+) operation on Machine '(\w+)'$/ do |operation, machine_id| - pending # express the regexp above with the code you wish you had +Then /^client should verify that this Machine has been created properly$/ do |attrs| + attrs.rows_hash.each do |key, value| + if key == 'memory' + @machine.memory['quantity'].to_s.should == value + else + @machine.send(key.intern).to_s.should == value + end + end +end + +When /^client executes (\w+) operation on created Machine$/ do |operation| + builder = Nokogiri::XML::Builder.new do |xml| + xml.Action(:xmlns => CMWG_NAMESPACE) { + xml.action "http://www.dmtf.org/cimi/action/#{operation}" + } + end + authorize 'mockuser', 'mockpassword' + header 'Content-Type', 'application/xml' + if operation == 'delete' + delete "/cimi/machines/%s/delete" % new_machine.name + last_response.status.should == 200 + last_response.body.should be_empty + @delete_operation = true + else + post "/cimi/machines/%s/%s" % [new_machine.name, operation], builder.to_xml + last_response.status.should == 202 + last_response.body.should be_empty + end end Then /^client should verify that this machine is (\w+)$/ do |status| - pending # express the regexp above with the code you wish you had + unless @delete_operation + @machine.state.should == status.upcase + end end diff --git a/server/tests/cimi/features/support/env.rb b/server/tests/cimi/features/support/env.rb index f55e811..06ff3d6 100644 --- a/server/tests/cimi/features/support/env.rb +++ b/server/tests/cimi/features/support/env.rb @@ -16,6 +16,14 @@ def last_xml_response Nokogiri::XML(last_response.body) end +def new_machine + @@new_machine +end + +def set_new_machine(machine) + @@new_machine = machine +end + class String def to_class_name -- 1.7.4.4
