/
ResourceFind_test.java
191 lines (146 loc) · 6.77 KB
/
ResourceFind_test.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
*
* NOTE: This copyright does *not* cover user programs that use HQ
* program services by normal system calls through the application
* program interfaces provided as part of the Hyperic Plug-in Development
* Kit or the Hyperic Client Development Kit - this is merely considered
* normal use of the program, and does *not* fall under the heading of
* "derived work".
*
* Copyright (C) [2008, 2009], Hyperic, Inc.
* This file is part of HQ.
*
* HQ is free software; you can redistribute it and/or modify
* it under the terms version 2 of the GNU General Public License as
* published by the Free Software Foundation. This program is distributed
* in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
*/
package org.hyperic.hq.hqapi1.test;
import org.hyperic.hq.hqapi1.ResourceApi;
import org.hyperic.hq.hqapi1.types.Agent;
import org.hyperic.hq.hqapi1.types.Resource;
import org.hyperic.hq.hqapi1.types.ResourcePrototype;
import org.hyperic.hq.hqapi1.types.ResourcePrototypeResponse;
import org.hyperic.hq.hqapi1.types.ResourceResponse;
import org.hyperic.hq.hqapi1.types.ResourcesResponse;
import org.hyperic.hq.hqapi1.types.User;
import java.util.List;
public class ResourceFind_test extends ResourceTestBase {
public ResourceFind_test(String name) {
super(name);
}
public void testFindByAgent() throws Exception {
Agent a = getRunningAgent();
ResourceApi api = getApi().getResourceApi();
ResourcesResponse resp = api.getResources(a, false, false);
hqAssertSuccess(resp);
// This test assumes if you have a local agent that is pingable that
// there will be at least one platform servicing it.
assertTrue("Found 0 platform resources for agent " + a.getId(),
resp.getResource().size() > 0);
for (Resource r : resp.getResource()) {
validateResource(r);
}
}
public void testFindByInvalidAgent() throws Exception {
Agent a = new Agent();
a.setId(Integer.MAX_VALUE);
a.setAddress("1.2.3.4");
a.setPort(80);
a.setVersion("4.0");
ResourceApi api = getApi().getResourceApi();
ResourcesResponse resp = api.getResources(a, false, false);
hqAssertFailureObjectNotFound(resp);
}
public void testFindByPrototype() throws Exception {
final String TYPE = "CPU";
ResourceApi api = getApi().getResourceApi();
ResourcePrototypeResponse protoResponse =
api.getResourcePrototype(TYPE);
hqAssertSuccess(protoResponse);
ResourcePrototype pt = protoResponse.getResourcePrototype();
ResourcesResponse resp = api.getResources(pt, false, false);
hqAssertSuccess(resp);
// We assume we're running against a server with valid resources
if (resp.getResource().size() == 0) {
getLog().warn("Warning, no resources of type " + TYPE + " found!");
}
for (Resource r : resp.getResource()) {
validateResource(r);
}
}
public void testFindByInvalidPrototype() throws Exception {
final String INVALID_TYPE = "Non-existant type";
ResourceApi api = getApi().getResourceApi();
ResourcePrototypeResponse protoResponse =
api.getResourcePrototype(INVALID_TYPE);
hqAssertFailureObjectNotFound(protoResponse);
}
public void testFindByDescription() throws Exception {
final String DESC = "Hyperic HQ monitor Agent";
ResourceApi api = getApi().getResourceApi();
ResourcesResponse response = api.getResources(DESC, false, false);
hqAssertSuccess(response);
assertTrue("Found no matches for '" + DESC + "'", response.getResource().size() > 0);
}
public void testFindByDescriptionPartialMatch() throws Exception {
final String DESC = "HQ monitor";
ResourceApi api = getApi().getResourceApi();
ResourcesResponse response = api.getResources(DESC, false, false);
hqAssertSuccess(response);
assertTrue("Found no matches for '" + DESC + "'", response.getResource().size() > 0);
}
public void testFindByDescriptionNoMatches() throws Exception {
final String DESC = "ASDFASDFASDF";
ResourceApi api = getApi().getResourceApi();
ResourcesResponse response = api.getResources(DESC, false, false);
hqAssertSuccess(response);
assertTrue("Found matches for '" + DESC + "'", response.getResource().size() == 0);
}
public void testFindResourceByAgentUnauthorized() throws Exception {
List<User> users = createTestUsers(1);
User user = users.get(0);
ResourceApi api = getApi(user.getName(), TESTUSER_PASSWORD).getResourceApi();
// Use admin user to get local agent..
Agent agent = getRunningAgent();
// Test find by agent
ResourcesResponse response = api.getResources(agent, false, false);
hqAssertSuccess(response);
assertTrue("Found resources with unauthorized user", response.getResource().size() == 0);
deleteTestUsers(users);
}
public void testFindResourceByPrototypeUnauthorized() throws Exception {
List<User> users = createTestUsers(1);
User user = users.get(0);
ResourceApi api = getApi(user.getName(), TESTUSER_PASSWORD).getResourceApi();
// Use admin user to get local platform..
Resource localPlatform = getLocalPlatformResource(false, false);
// Test find by prototype
ResourcesResponse response = api.getResources(localPlatform.getResourcePrototype(), false, false);
hqAssertSuccess(response);
assertTrue("Found resources with unauthorized user", response.getResource().size() == 0);
deleteTestUsers(users);
}
public void testFindResourceByDescriptionUnauthorized() throws Exception {
final String DESC = "Hyperic HQ monitor Agent";
List<User> users = createTestUsers(1);
User user = users.get(0);
ResourceApi api = getApi(user.getName(), TESTUSER_PASSWORD).getResourceApi();
// Use admin user to get local platform..
Resource localPlatform = getLocalPlatformResource(false, false);
// Test find by prototype
ResourcesResponse response = api.getResources(DESC, false, false);
hqAssertSuccess(response);
assertTrue("Found resources with unauthorized user", response.getResource().size() == 0);
deleteTestUsers(users);
}
}