Class: Ugv::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ugv/client.rb

Constant Summary collapse

FIRST_ENTITY =
{:index => 1, :name => 'test1'}
SECOND_ENTITY =
{:index => 2, :name => 'test2'}
EMPTY =
{}

Instance Method Summary collapse

Constructor Details

#initialize(api, adminUser, adminPassword, orgName, appName) ⇒ Client

Returns a new instance of Client.



12
13
14
15
16
17
18
19
# 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

Instance Method Details

#createObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# 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

#setupObject

Login and /or create the org admin and app



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 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. @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

#validateObject



21
22
23
# File 'lib/ugv/client.rb', line 21

def validate
  return !@api.nil? && !@adminUser.nil? && !@adminPassword.nil? && !@orgName.nil? && !@appName.nil?
end

#verifyObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# 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