Skip to content
This repository has been archived by the owner on Feb 24, 2023. It is now read-only.

Commit

Permalink
Add postgresql test steps.
Browse files Browse the repository at this point in the history
Change-Id: I899f7d2b11fb83502975c7e6987f809654df54db
  • Loading branch information
xinli authored and Andrew Liu committed Jul 15, 2011
1 parent 6259da6 commit d200d48
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 1 deletion.
11 changes: 10 additions & 1 deletion features/autostaging.feature
Expand Up @@ -3,7 +3,7 @@ Feature: Deploy applications that make use of autostaging
As a user of AppCloud
I want to launch apps that expect automatic binding of the services that they use

Background: MySQL autostaging
Background: MySQL and PostgreSQL autostaging
Given I have registered and logged in

@creates_jpa_app @creates_jpa_db_adapter
Expand Down Expand Up @@ -61,3 +61,12 @@ Feature: Deploy applications that make use of autostaging
Given I deploy a broken dbrails application using the MySQL DB service
Then The broken dbrails application should fail

@creates_hibernate_app @creates_hibernate_postgresql_adapter
Scenario: start Spring Web application using Hibernate and add some records
Given I deploy a hibernate application that is backed by the PostgreSQL database service on AppCloud
When I add 3 records to the application
Then I should have the same 3 records on retrieving all records from the application

When I delete my application
And I deploy a Spring Hibernate application using the created PostgreSQL service
Then I should have the same 3 records on retrieving all records from the application
57 changes: 57 additions & 0 deletions features/step_definitions/appcloud_steps.rb
Expand Up @@ -8,6 +8,8 @@

#World(AppCloudHelper)

require 'nokogiri'

World do
AppCloudHelper.instance
end
Expand Down Expand Up @@ -602,3 +604,58 @@
contents.close
end

# Hiberate application that uses PostgreSQL
Given /^I deploy a hibernate application that is backed by the PostgreSQL database service on AppCloud$/ do
# Enumerate system services, if postgresql service is present,
# then create the app, provision the service and bind it to app,
# otherwise put this step pending
services = get_services @token
# flatten
services_list = []

services.each do |service_type, value|
value.each do |k,v|
v.each do |version, s|
services_list << s
end
end
end

# find postgresql service in the list
postgresql_service = services_list.find {|service| service[:vendor].downcase == "postgresql"}

if postgresql_service
@app = create_app HIBERNATE_APP, @token
@service = provision_postgresql_service_named @token, "mydb"
attach_provisioned_service @app, @service, @token
upload_app @app, @token
start_app @app, @token
expected_health = 1.0
health = poll_until_done @app, expected_health, @token
health.should == expected_health
else
pending "Not running Postgresql test because Postgresql service is not available"
end
end

When /^I add one entry in the Guestbook$/ do
uri = get_uri @app, "guest.html"

easy = Curl::Easy.new
easy.url = uri
easy.http_post("name=guest")
easy.close
end

Then /^I should be able to retrieve entries from Guestbook$/ do
uri = get_uri @app

easy = Curl::Easy.new
easy.url = uri
easy.http_get
doc = Nokogiri::HTML(easy.body_str)
number = doc.xpath('//p').count
easy.close

number.should >= 1
end
21 changes: 21 additions & 0 deletions features/step_definitions/autostaging_steps.rb
Expand Up @@ -46,6 +46,12 @@
health.should == expected_health
end

When /^I deploy a Spring Hibernate application using the created PostgreSQL service$/ do
expected_health = 1.0
health = create_and_start_app HIBERNATE_APP, expected_health, @service
health.should == expected_health
end

Given /^I deploy a dbrails application using the MySQL DB service$/ do
expected_health = 1.0
health = create_and_start_app DBRAILS_APP, expected_health
Expand Down Expand Up @@ -155,6 +161,16 @@ def delete_app_services
@services = nil
end

# check application exist before deleting its services.
def delete_app_services_check
if @app.nil?
@services = nil
return
else
delete_app_services
end
end

Given /^I deploy a Spring Grails application using the MySQL DB service$/ do
expected_health = 1.0
health = create_and_start_app GRAILS_APP, expected_health
Expand Down Expand Up @@ -228,6 +244,11 @@ def delete_app_services
delete_app_services
end


After("@creates_hibernate_postgresql_adapter") do |scenario|
delete_app_services_check
end

After("@creates_grails_db_adapter") do |scenario|
delete_app_services
end
Expand Down
17 changes: 17 additions & 0 deletions features/support/env.rb
Expand Up @@ -599,6 +599,23 @@ def provision_redis_service token
}
end

def postgresql_name name
"#{@namespace}postgresql_#{name}"
end

def provision_postgresql_service_named token, name
service_manifest = {
:type=>"database",
:vendor=>"postgresql",
:tier=>"free",
:version=>"8.4",
:name=>postgresql_name(name),
}
@client.create_service(:postgresql, service_manifest[:name])
#puts "Provisioned service #{service_manifest}"
service_manifest
end

def provision_redis_service_named token, name
r_name = redis_name(name)
@client.create_service(:redis, r_name)
Expand Down

0 comments on commit d200d48

Please sign in to comment.