Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Neo4j tests

Squashed commit of the following:

commit 4b285fe
Merge: 4c1e548 fb6860e
Author: Patrick Bozeman <pbozeman@vmware.com>
Date:   Tue Aug 2 11:49:50 2011 -0700

    Merge remote-tracking branch 'jexp/master'

    Contains manual edits during the merge to bring up-to-date
    with the rest of vcap-tests and vcap-services.

    Conflicts:
    	features/support/env.rb
    	features/support/testconfig.yml

    Change-Id: I1c22050996f37f82825bf382ec75c1ad4325d70c

commit fb6860e
Author: Michael Hunger <github@jexp.de>
Date:   Fri May 27 23:02:19 2011 +0200

    finished simple neo4j cucumber test

commit 87cfa4f
Author: CloudFoundry <cloud@cloudfoundry.hosted.neo4j.org>
Date:   Fri May 27 14:43:40 2011 +0200

    updated neo4j test app

commit dcaf13c
Author: Michael Hunger <github@jexp.de>
Date:   Thu May 26 04:22:03 2011 +0200

    added cucumber test for simple neo4j application

commit e90289a
Author: Michael Hunger <github@jexp.de>
Date:   Fri May 13 15:23:55 2011 +0200

    added neo4j sample app

Change-Id: I8e438f1b2c3284006c1ea41ab81fe138dbdfd44d
  • Loading branch information...
commit 7c28f42a25add3bc583934b309f9c8a9f7e1f13b 1 parent 077f6ec
Michael Hunger jexp authored Patrick Bozeman committed
3  apps/neo4j_app/Gemfile
... ... @@ -0,0 +1,3 @@
  1 +source "http://rubygems.org"
  2 +gem 'neography'
  3 +gem 'sinatra'
22 apps/neo4j_app/Gemfile.lock
... ... @@ -0,0 +1,22 @@
  1 +GEM
  2 + remote: http://rubygems.org/
  3 + specs:
  4 + crack (0.1.8)
  5 + httparty (0.7.7)
  6 + crack (= 0.1.8)
  7 + json (1.5.1)
  8 + neography (0.0.13)
  9 + httparty (~> 0.7.3)
  10 + json
  11 + rack (1.2.2)
  12 + sinatra (1.2.6)
  13 + rack (~> 1.1)
  14 + tilt (>= 1.2.2, < 2.0)
  15 + tilt (1.3)
  16 +
  17 +PLATFORMS
  18 + ruby
  19 +
  20 +DEPENDENCIES
  21 + neography
  22 + sinatra
94 apps/neo4j_app/neo4j.rb
... ... @@ -0,0 +1,94 @@
  1 +require 'rubygems'
  2 +require 'sinatra'
  3 +require 'neography'
  4 +require 'json'
  5 +
  6 +include Neography
  7 +
  8 +configure do
  9 + set :show_exceptions, false
  10 +end
  11 +
  12 +def get_neo
  13 + begin
  14 + if ENV['VCAP_SERVICES']
  15 + services = JSON.parse(ENV['VCAP_SERVICES'])
  16 + neo4j = services['neo4j-1.4'][0]['credentials']
  17 + else
  18 + neo4j = {}
  19 + end
  20 +#$stderr.puts ENV['VCAP_SERVICES']
  21 +
  22 + Neography::Config.server = neo4j['hostname'] || 'localhost'
  23 + Neography::Config.port = (neo4j['port'] || "7474").to_i
  24 + Neography::Config.authentication = 'basic'
  25 + Neography::Config.username = neo4j['username']||"test"
  26 + Neography::Config.password = neo4j['password']||"test"
  27 +
  28 + @neo = Rest.new
  29 +#$stderr.puts @neo.configuration
  30 + @neo
  31 + rescue Exception => e
  32 + $stderr.puts "Neo4j Exception #{e}"
  33 + nil
  34 + end
  35 +end
  36 +
  37 +before do
  38 + get_neo
  39 +end
  40 +
  41 +get '/healthcheck' do
  42 + begin
  43 + Node::load(0)
  44 + "OK"
  45 + rescue Exception => e
  46 + "FAIL: #{ENV['VCAP_SERVICES']} #{e}"
  47 + end
  48 +end
  49 +
  50 +def get_root
  51 + Node::load(0)
  52 +end
  53 +
  54 +def new_node(question,answer)
  55 + nil unless question && answer
  56 + node = Node.create("answer" => answer, "question" => question)
  57 + get_root.outgoing(:ANSWER) << node
  58 + node
  59 +end
  60 +
  61 +
  62 +get '/' do
  63 + "<h2>Add a Q&amp;A!</h2>" +
  64 + "<form method='post' action='/add'>Question: <input name=question/> Answer: <input type=text name=answer/><input type=submit/></form>" +
  65 + "<h1>Answers from Neo4j!</h1>" +
  66 + "<dl>" +
  67 + get_root.outgoing(:ANSWER).collect { |n| "<dt>Question: #{n.question}</dt><dd>Answer: #{n.answer}</dd>"}.join +
  68 + "</dl>"
  69 +end
  70 +
  71 +get '/question', :provides => :json do
  72 + content_type :json
  73 + get_root.outgoing(:ANSWER).collect{ |n| { :question => n.question, :answer => n.answer}}.to_json
  74 +end
  75 +
  76 +get '/question/:id', :provides => :json do |id|
  77 + content_type :json
  78 + node = Node::load(id)
  79 + 404 unless node
  80 + { :question => node.question, :answer => node.answer}.to_json
  81 +end
  82 +
  83 +post '/question' do
  84 + data = JSON.parse request.body.read
  85 + node = new_node(data['question'],data['answer'])
  86 + status 400 unless node
  87 + url("/question/#{node.neo_id}")
  88 +end
  89 +
  90 +post '/add' do
  91 + node = new_node(params[:question],params[:answer])
  92 + halt 400 unless node
  93 + redirect to("/"), 201
  94 +end
BIN  apps/neo4j_app/vendor/cache/crack-0.1.8.gem
Binary file not shown
BIN  apps/neo4j_app/vendor/cache/httparty-0.7.7.gem
Binary file not shown
BIN  apps/neo4j_app/vendor/cache/json-1.5.1.gem
Binary file not shown
BIN  apps/neo4j_app/vendor/cache/neography-0.0.13.gem
Binary file not shown
BIN  apps/neo4j_app/vendor/cache/rack-1.2.2.gem
Binary file not shown
BIN  apps/neo4j_app/vendor/cache/sinatra-1.2.6.gem
Binary file not shown
BIN  apps/neo4j_app/vendor/cache/tilt-1.3.gem
Binary file not shown
13 features/neo4j.feature
... ... @@ -0,0 +1,13 @@
  1 +Feature: Neo4j service binding and app deployment
  2 +
  3 + In order to use Neo4j in AppCloud
  4 + As the VMC user
  5 + I want to deploy my app against a Neo4j service
  6 +
  7 + @creates_neo4j_app @creates_neo4j_service
  8 + Scenario: Deploy Neo4j
  9 + Given I have registered and logged in
  10 + Given I have provisioned a Neo4j service
  11 + Given I have deployed a Neo4j application that is bound to this service
  12 + When I add an answer to my application
  13 + Then I should be able to retrieve it
40 features/step_definitions/neo4j_steps.rb
... ... @@ -0,0 +1,40 @@
  1 +# Simple Neo4j Application that uses the Neo4j graph database service
  2 +
  3 +Given /^I have provisioned a Neo4j service$/ do
  4 + pending unless find_service 'neo4j'
  5 + @neo4j_service = provision_neo4j_service @token
  6 + @neo4j_service.should_not == nil
  7 +end
  8 +
  9 +Given /^I have deployed a Neo4j application that is bound to this service$/ do
  10 + @app = create_app NEO4J_APP, @token
  11 + attach_provisioned_service @app, @neo4j_service, @token
  12 + upload_app @app, @token
  13 + start_app @app, @token
  14 + expected_health = 1.0
  15 + health = poll_until_done @app, expected_health, @token
  16 + health.should == expected_health
  17 +end
  18 +
  19 +When /^I add an answer to my application$/ do
  20 + uri = get_uri(@app, "question")
  21 + r = post_record_no_close(uri, { :question => 'Q1', :answer => 'A1'})
  22 + r.response_code.should == 200
  23 + @question_id = r.body_str.split(/\//).last
  24 + r.close
  25 +end
  26 +
  27 +Then /^I should be able to retrieve it$/ do
  28 + uri = get_uri @app, "question/#{@question_id}"
  29 + response = get_uri_contents uri
  30 + response.should_not == nil
  31 + response.response_code.should == 200
  32 + contents = JSON.parse response.body_str
  33 + contents["question"].should == "Q1"
  34 + contents["answer"].should == "A1"
  35 + response.close
  36 +end
  37 +
  38 +After("@creates_neo4j_service") do |scenario|
  39 + delete_app_services if @neo4j_service
  40 +end
24 features/support/env.rb
@@ -45,6 +45,7 @@
45 45 SIMPLE_LIFT_APP = "simple-lift-app"
46 46 LIFT_DB_APP = "lift-db-app"
47 47 TOMCAT_VERSION_CHECK_APP="tomcat-version-check-app"
  48 +NEO4J_APP = "neo4j_app"
48 49 SIMPLE_PYTHON_APP = "simple_wsgi_app"
49 50 PYTHON_APP_WITH_DEPENDENCIES = "wsgi_app_with_requirements"
50 51 SIMPLE_DJANGO_APP = "simple_django_app"
@@ -121,6 +122,10 @@
121 122 AppCloudHelper.instance.delete_app_internal TOMCAT_VERSION_CHECK_APP
122 123 end
123 124
  125 +After("@creates_neo4j_app") do
  126 + AppCloudHelper.instance.delete_app_internal NEO4J_APP
  127 +end
  128 +
124 129 After("@creates_wsgi_app") do
125 130 AppCloudHelper.instance.delete_app_internal SIMPLE_PYTHON_APP
126 131 end
@@ -207,6 +212,7 @@ def cleanup
207 212 delete_app_internal(SIMPLE_LIFT_APP)
208 213 delete_app_internal(LIFT_DB_APP)
209 214 delete_app_internal(TOMCAT_VERSION_CHECK_APP)
  215 + delete_app_internal(NEO4J_APP)
210 216 delete_app_internal(SIMPLE_PYTHON_APP)
211 217 delete_app_internal(PYTHON_APP_WITH_DEPENDENCIES)
212 218 delete_app_internal(SIMPLE_DJANGO_APP)
@@ -622,6 +628,17 @@ def provision_mongodb_service token
622 628 service_manifest
623 629 end
624 630
  631 + def provision_neo4j_service token
  632 + name = "#{@namespace}#{@app || 'simple_neo4j_app'}neo4j"
  633 + @client.create_service(:neo4j, name)
  634 + service_manifest = {
  635 + :vendor=>"neo4j",
  636 + :tier=>"free",
  637 + :version=>"1.4",
  638 + :name=>name
  639 + }
  640 + end
  641 +
625 642 def provision_postgresql_service
626 643 name = "#{@namespace}#{@app || 'simple_db_app'}postgresql"
627 644 @client.create_service(:postgresql, name)
@@ -779,10 +796,15 @@ def post_uri uri, data
779 796 easy
780 797 end
781 798
782   - def post_record uri, data_hash
  799 + def post_record_no_close uri, data_hash
783 800 easy = Curl::Easy.new
784 801 easy.url = uri
785 802 easy.http_post(data_hash.to_json)
  803 + easy
  804 + end
  805 +
  806 + def post_record uri, data_hash
  807 + easy = post_record_no_close(uri,data_hash)
786 808 easy.close
787 809 end
788 810
6 features/support/testconfig.yml
@@ -62,6 +62,7 @@ roo_app:
62 62 startup: "thin start"
63 63 memory: 256
64 64
  65 +
65 66 mochiweb_test:
66 67 framework: "otp_rebar"
67 68 startup: erlangR14B02
@@ -108,6 +109,11 @@ my_test_app_env_test_app:
108 109 startup: "ruby foo.rb"
109 110 memory: 64
110 111
  112 +neo4j_app:
  113 + framework: "http://b20nine.com/unknown"
  114 + startup: "ruby neo4j.rb"
  115 + memory: 256
  116 +
111 117 simple_wsgi_app:
112 118 framework: "wsgi"
113 119
2  profiles/acdev/cloud_controller.yml.erb
@@ -46,4 +46,6 @@ builtin_services:
46 46 token: "0xdeadbeef"
47 47 mongodb:
48 48 token: "0xdeadbeef"
  49 + neo4j:
  50 + token: "0xdeadbeef"
49 51
14 profiles/acdev/services/neo4j/neo4j_gateway.yml.erb
... ... @@ -0,0 +1,14 @@
  1 +---
  2 +cloud_controller_uri: <%= config.controller_host %>
  3 +service:
  4 + name: neo4j
  5 + version: "1.4"
  6 + description: 'Neo4j NOSQL store'
  7 + plans: ['free']
  8 + tags: ['neo4j', 'neo4j-1.4', 'nosql']
  9 +host: localhost
  10 +token: "0xdeadbeef"
  11 +mbus: <%= config.nats_uri %>
  12 +log_level: DEBUG
  13 +pid: <%= config.working_dir %>/sys/run/neo4j_service.pid
  14 +node_timeout: 10
13 profiles/acdev/services/neo4j/neo4j_node.yml.erb
... ... @@ -0,0 +1,13 @@
  1 +---
  2 +local_db: sqlite3:<%= config.working_dir %>/services/neo4j/neo4j_node.db
  3 +mbus: <%= config.nats_uri %>
  4 +base_dir: <%= config.working_dir %>/services/neo4j/instances
  5 +log_level: DEBUG
  6 +pid: <%= config.working_dir %>/sys/run/neo4j_node.pid
  7 +available_memory: 4096
  8 +max_memory: 128
  9 +node_id: neo4j_node_1
  10 +neo4j_path: <%= config.working_dir %>/services/neo4j
  11 +port_range:
  12 + first: 45000
  13 + last: 55000
3  profiles/mac/cloud_controller.yml.erb
@@ -39,4 +39,5 @@ builtin_services:
39 39 token: "0xdeadbeef"
40 40 mongodb:
41 41 token: "0xdeadbeef"
42   -
  42 + neo4j:
  43 + token: "0xdeadbeef"
14 profiles/mac/services/neo4j/neo4j_gateway.yml.erb
... ... @@ -0,0 +1,14 @@
  1 +---
  2 +cloud_controller_uri: <%= config.controller_host %>
  3 +service:
  4 + name: neo4j
  5 + version: "1.4"
  6 + description: 'Neo4j NOSQL store'
  7 + plans: ['free']
  8 + tags: ['neo4j', 'neo4j-1.4', 'nosql']
  9 +host: localhost
  10 +token: "0xdeadbeef"
  11 +mbus: <%= config.nats_uri %>
  12 +log_level: DEBUG
  13 +pid: <%= config.working_dir %>/sys/run/neo4j_service.pid
  14 +node_timeout: 10
13 profiles/mac/services/neo4j/neo4j_node.yml.erb
... ... @@ -0,0 +1,13 @@
  1 +---
  2 +local_db: sqlite3:<%= config.working_dir %>/services/neo4j/neo4j_node.db
  3 +mbus: <%= config.nats_uri %>
  4 +base_dir: <%= config.working_dir %>/services/neo4j/instances
  5 +log_level: DEBUG
  6 +pid: <%= config.working_dir %>/sys/run/neo4j_node.pid
  7 +available_memory: 4096
  8 +max_memory: 128
  9 +node_id: neo4j_node_1
  10 +neo4j_path: <%= config.working_dir %>/services/neo4j
  11 +port_range:
  12 + first: 45000
  13 + last: 55000
2  rakelib/build_helpers.rake
@@ -137,9 +137,11 @@ export BUNDLE_PATH=#{BuildConfig.bundle_path}
137 137 #{start_command_for 'redis_node'}
138 138 #{start_command_for 'mysql_node'}
139 139 #{start_command_for 'mongodb_node'}
  140 +#{start_command_for 'neo4j_node'}
140 141 #{start_command_for 'redis_gateway'}
141 142 #{start_command_for 'mysql_gateway'}
142 143 #{start_command_for 'mongodb_gateway'}
  144 +#{start_command_for 'neo4j_gateway'}
143 145 START
144 146
145 147 File.open(BuildConfig.service_startup_script, 'w') do |fh|

0 comments on commit 7c28f42

Please sign in to comment.
Something went wrong with that request. Please try again.