class Ugv::Client

Constants

EMPTY
FIRST_ENTITY
SECOND_ENTITY

Public Class Methods

new(api, adminUser, adminPassword, orgName, appName) click to toggle source
# File lib/ugv/client.rb, line 12
def initialize(api, adminUser, adminPassword, orgName, appName)
  @api = api
  @adminUser = adminUser
  @adminPassword = adminPassword
  @orgName = orgName
  @appName = appName

end

Public Instance Methods

create() click to toggle source
# File lib/ugv/client.rb, line 65
def create

  puts "Writing entity #{FIRST_ENTITY[:name]}"

  @application[:tests][FIRST_ENTITY[:name]].put FIRST_ENTITY

  puts "Writing entity #{SECOND_ENTITY[:name]}"

  @application[:tests][SECOND_ENTITY[:name]].put SECOND_ENTITY

  puts "Creating a connection from #{FIRST_ENTITY[:name]} to #{SECOND_ENTITY[:name]}"

  @application[:tests][FIRST_ENTITY[:name]][:connection][:tests][SECOND_ENTITY[:name]].post EMPTY

end
setup() click to toggle source

Login and /or create the org admin and app

# File lib/ugv/client.rb, line 29
def setup

  puts "Attempting to log in with username #{@adminUser} and password #{@adminPassword}"

  @management = Usergrid::Management.new @api


  @management.login @adminUser, @adminPassword

  response = JSON.parse(@management[:users][@adminUser][:orgs].get)

  puts "Response is #{response}"

  #No org, create it
  if response.nil? || response["data"][@orgName].nil?
    puts "No organization #{@orgName} found.  Creating it"
    @management[:users][@adminUser][:orgs].post({:organization => @orgName})
  end

  #Now check to see if the app exists

  response = JSON.parse(@management[:orgs][@orgName][:applications].get)

  #puts "Found organization #{organization}"

  #We have to account for the orgname/appname format
  if response.nil? || response["data"]["#{@orgName}/#{@appName}"].nil?
    puts "No application #{@appName} found.  Creating it"
    @management[:orgs][@orgName][:applications].post({:name => @appName})
  end

  @application = @management.application @orgName, @appName

end
validate() click to toggle source
# File lib/ugv/client.rb, line 21
def validate
  return !@api.nil? && !@adminUser.nil? && !@adminPassword.nil? && !@orgName.nil? && !@appName.nil?
end
verify() click to toggle source
# File lib/ugv/client.rb, line 82
def verify


  puts "Verifying entity #{FIRST_ENTITY[:name]}"


  entity = @application[:tests][FIRST_ENTITY[:name]].get.entity

  raise "Entity #{FIRST_ENTITY[:name]} not found" if entity.nil?

  raise "Entity index mismatch.  Expected #{FIRST_ENTITY[:index]} but was #{entity['index']}" unless FIRST_ENTITY[:index] == entity['index']

  raise "Entity name mismatch.  Expected #{FIRST_ENTITY[:name]} but was #{entity['name']}" unless  FIRST_ENTITY[:name] == entity['name']



  puts "Verifying entity #{SECOND_ENTITY[:name]}"

  entity = @application[:tests][SECOND_ENTITY[:name]].get.entity

  raise "Entity #{SECOND_ENTITY[:name]} not found" if entity.nil?

  raise "Entity index mismatch.  Expected #{SECOND_ENTITY[:index]} but was #{ entity[:'index']}" unless SECOND_ENTITY[:index] ==  entity['index']

  raise "Entity name mismatch.  Expected #{SECOND_ENTITY[:name]} but was #{entity['name']}" unless  SECOND_ENTITY[:name] == entity['name']




  puts "Verifying a connection from #{FIRST_ENTITY[:name]} to #{SECOND_ENTITY[:name]}"

  #verify the connection
  entity = @application[:tests][FIRST_ENTITY[:name]][:connection][:tests][SECOND_ENTITY[:name]].get.entity


  raise "Entity #{SECOND_ENTITY[:name]} not found on connection #{:connection}" if entity.nil?

  raise "Entity index mismatch.  Expected #{SECOND_ENTITY[:index]} but was #{entity['index']}" unless SECOND_ENTITY[:index] ==  entity['index']

  raise "Entity name mismatch.  Expected #{SECOND_ENTITY[:name]} but was #{entity['name']}" unless  SECOND_ENTITY[:name] == entity['name']


  puts 'Verification complete.  All entities and connections are correct'
end