Permalink
Browse files

finished simple neo4j cucumber test

  • Loading branch information...
1 parent 87cfa4f commit fb6860e935640e20bb46a6fdf90fa5e0326f51ef @jexp jexp committed May 27, 2011
Showing with 47 additions and 20 deletions.
  1. +1 −3 apps/neo4j_app/neo4j.rb
  2. +5 −2 features/neo4j.feature
  3. +34 −11 features/step_definitions/neo4j_steps.rb
  4. +7 −4 features/support/env.rb
View
4 apps/neo4j_app/neo4j.rb
@@ -84,9 +84,7 @@ def new_node(question,answer)
data = JSON.parse request.body.read
node = new_node(data['question'],data['answer'])
status 400 unless node
-# redirect to("/question/#{node.neo_id}"), 201
- target=url("/question/#{node.neo_id}")
- [200, {"Location" => target}, target]
+ url("/question/#{node.neo_id}")
end
post '/add' do
View
7 features/neo4j.feature
@@ -4,8 +4,11 @@ Feature: Neo4j service binding and app deployment
As the VMC user
I want to deploy my app against a Neo4j service
+ @creates_neo4j_app @creates_neo4j_service
Scenario: Deploy Neo4j
- Given I have deployed a Neo4j application that is backed by a Neo4j Service
+ Given I have registered and logged in
+ Given I have provisioned a Neo4j service
+ Given I have deployed a Neo4j application that is bound to this service
When I add an answer to my application
- Then I should be able see it on the start page
+ Then I should be able to retrieve it
View
45 features/step_definitions/neo4j_steps.rb
@@ -1,26 +1,49 @@
# Simple Neo4j Application that uses the Neo4j graph database service
-Given /^I have deployed a Neo4j application that is backed by a Neo4j Service$/ do
- @neo4j_app = create_app NEO4J_APP, @token
+Given /^I have provisioned a Neo4j service$/ do
@neo4j_service = provision_neo4j_service @token
+ @neo4j_service.should_not == nil
+end
+
+
+Given /^I have deployed a Neo4j application that is bound to this service$/ do
+ @neo4j_app = create_app NEO4J_APP, @token
attach_provisioned_service @neo4j_app, @neo4j_service, @token
upload_app @neo4j_app, @token
start_app @neo4j_app, @token
expected_health = 1.0
health = poll_until_done @neo4j_app, expected_health, @token
+ puts "health #{health}"
health.should == expected_health
end
When /^I add an answer to my application$/ do
- uri = get_uri @app, "add"
- post_record uri, { :question => 'Q1', :answer => 'A1'}
+ uri = get_uri(@neo4j_app, "question")
+ r = post_record_no_close(uri, { :question => 'Q1', :answer => 'A1'})
+ r.response_code.should == 200
+ @question_id = r.body_str.split(/\//).last
+ r.close
+end
+
+Then /^I should be able to retrieve it$/ do
+ uri = get_uri @neo4j_app, "question/#{@question_id}"
+ response = get_uri_contents uri
+ response.should_not == nil
+ response.response_code.should == 200
+ contents = JSON.parse response.body_str
+ contents["question"].should == "Q1"
+ contents["answer"].should == "A1"
+ response.close
+end
+
+def delete_app_services
+ app_info = get_app_status @neo4j_app, @token
+ app_info.should_not == nil
+ services = app_info['services']
+ delete_services services, @token if services.length.to_i > 0
+ @services = nil
end
-Then /^I should be able see it on the start page$/ do
- uri = get_uri @app, ""
- contents = get_uri_contents uri
- contents.should_not == nil
- contents.include?("Q1").should_be true
- contents.include?("A1").should_be true
- contents.close
+After("@creates_neo4j_service") do |scenario|
+ delete_app_services
end
View
11 features/support/env.rb
@@ -454,13 +454,11 @@ def get_services token
def provision_neo4j_service token
service_manifest = {
- :type=>"graphdatabase",
:vendor=>"neo4j",
:tier=>"free",
:version=>"1.4",
:name=>"#{@namespace}neo4j_app"}
@client.add_service_internal @services_uri, service_manifest, auth_hdr(token)
-puts "Provisioned service #{service_manifest}"
service_manifest
end
@@ -551,7 +549,7 @@ def attach_provisioned_service app, service_manifest, token
provisioned_service << svc_name
app_manifest['services'] = provisioned_service
response = @client.update_app_state_internal @droplets_uri, appname, app_manifest, auth_hdr(token)
- raise "Problem attaching service #{svc_name} to application #{appname}." if response.status != 200
+ raise "Problem attaching service #{svc_name} to application #{appname}. #{response.status}" if response.status != 200
end
def delete_services services, token
@@ -582,10 +580,15 @@ def get_uri_contents uri
easy
end
- def post_record uri, data_hash
+ def post_record_no_close uri, data_hash
easy = Curl::Easy.new
easy.url = uri
easy.http_post(data_hash.to_json)
+ easy
+ end
+
+ def post_record uri, data_hash
+ easy = post_record_no_close(uri,data_hash)
easy.close
end

0 comments on commit fb6860e

Please sign in to comment.