Committed by
Gerrit Code Review
Fixing device key REST API bugs and adding json definitions.
Change-Id: I41a98702e781544fe6e0bebe3e281ff2bcd9a6fa
Showing
5 changed files
with
170 additions
and
55 deletions
... | @@ -41,21 +41,20 @@ public class DeviceKeyCodec extends AnnotatedCodec<DeviceKey> { | ... | @@ -41,21 +41,20 @@ public class DeviceKeyCodec extends AnnotatedCodec<DeviceKey> { |
41 | private static final String USERNAME = "username"; | 41 | private static final String USERNAME = "username"; |
42 | private static final String PASSWORD = "password"; | 42 | private static final String PASSWORD = "password"; |
43 | 43 | ||
44 | - | ||
45 | @Override | 44 | @Override |
46 | public ObjectNode encode(DeviceKey deviceKey, CodecContext context) { | 45 | public ObjectNode encode(DeviceKey deviceKey, CodecContext context) { |
47 | checkNotNull(deviceKey, "Device key cannot be null"); | 46 | checkNotNull(deviceKey, "Device key cannot be null"); |
48 | DeviceKeyService service = context.getService(DeviceKeyService.class); | 47 | DeviceKeyService service = context.getService(DeviceKeyService.class); |
49 | ObjectNode result = context.mapper().createObjectNode() | 48 | ObjectNode result = context.mapper().createObjectNode() |
50 | - .put(ID, deviceKey.deviceKeyId().id().toString()) | 49 | + .put(ID, deviceKey.deviceKeyId().id()) |
51 | .put(TYPE, deviceKey.type().toString()) | 50 | .put(TYPE, deviceKey.type().toString()) |
52 | - .put(LABEL, deviceKey.label().toString()); | 51 | + .put(LABEL, deviceKey.label()); |
53 | 52 | ||
54 | if (deviceKey.type().equals(DeviceKey.Type.COMMUNITY_NAME)) { | 53 | if (deviceKey.type().equals(DeviceKey.Type.COMMUNITY_NAME)) { |
55 | result.put(COMMUNITY_NAME, deviceKey.asCommunityName().name()); | 54 | result.put(COMMUNITY_NAME, deviceKey.asCommunityName().name()); |
56 | } else if (deviceKey.type().equals(DeviceKey.Type.USERNAME_PASSWORD)) { | 55 | } else if (deviceKey.type().equals(DeviceKey.Type.USERNAME_PASSWORD)) { |
57 | - result.put(USERNAME, deviceKey.asUsernamePassword().username().toString()); | 56 | + result.put(USERNAME, deviceKey.asUsernamePassword().username()); |
58 | - result.put(PASSWORD, deviceKey.asUsernamePassword().password().toString()); | 57 | + result.put(PASSWORD, deviceKey.asUsernamePassword().password()); |
59 | } | 58 | } |
60 | 59 | ||
61 | return annotate(result, deviceKey, context); | 60 | return annotate(result, deviceKey, context); |
... | @@ -70,18 +69,29 @@ public class DeviceKeyCodec extends AnnotatedCodec<DeviceKey> { | ... | @@ -70,18 +69,29 @@ public class DeviceKeyCodec extends AnnotatedCodec<DeviceKey> { |
70 | DeviceKeyId id = DeviceKeyId.deviceKeyId(json.get(ID).asText()); | 69 | DeviceKeyId id = DeviceKeyId.deviceKeyId(json.get(ID).asText()); |
71 | 70 | ||
72 | DeviceKey.Type type = DeviceKey.Type.valueOf(json.get(TYPE).asText()); | 71 | DeviceKey.Type type = DeviceKey.Type.valueOf(json.get(TYPE).asText()); |
73 | - String label = json.get(LABEL).asText(); | 72 | + String label = extract(json, LABEL); |
74 | 73 | ||
75 | if (type.equals(DeviceKey.Type.COMMUNITY_NAME)) { | 74 | if (type.equals(DeviceKey.Type.COMMUNITY_NAME)) { |
76 | - String communityName = json.get(COMMUNITY_NAME).asText(); | 75 | + String communityName = extract(json, COMMUNITY_NAME); |
77 | return DeviceKey.createDeviceKeyUsingCommunityName(id, label, communityName); | 76 | return DeviceKey.createDeviceKeyUsingCommunityName(id, label, communityName); |
78 | } else if (type.equals(DeviceKey.Type.USERNAME_PASSWORD)) { | 77 | } else if (type.equals(DeviceKey.Type.USERNAME_PASSWORD)) { |
79 | - String username = json.get(USERNAME).asText(); | 78 | + String username = extract(json, USERNAME); |
80 | - String password = json.get(PASSWORD).asText(); | 79 | + String password = extract(json, PASSWORD); |
81 | return DeviceKey.createDeviceKeyUsingUsernamePassword(id, label, username, password); | 80 | return DeviceKey.createDeviceKeyUsingUsernamePassword(id, label, username, password); |
82 | } else { | 81 | } else { |
83 | log.error("Unknown device key type: ", type); | 82 | log.error("Unknown device key type: ", type); |
84 | return null; | 83 | return null; |
85 | } | 84 | } |
86 | } | 85 | } |
86 | + | ||
87 | + /** | ||
88 | + * Extract the key from the json node. | ||
89 | + * | ||
90 | + * @param json json object | ||
91 | + * @param key key to use extract the value from the json object | ||
92 | + * @return extracted value from the json object | ||
93 | + */ | ||
94 | + private String extract(ObjectNode json, String key) { | ||
95 | + return json.get(key) == null ? null : json.get(key).asText(); | ||
96 | + } | ||
87 | } | 97 | } | ... | ... |
... | @@ -56,9 +56,8 @@ public class DeviceKeyWebResource extends AbstractWebResource { | ... | @@ -56,9 +56,8 @@ public class DeviceKeyWebResource extends AbstractWebResource { |
56 | * Returns array of all device keys. | 56 | * Returns array of all device keys. |
57 | * | 57 | * |
58 | * @return 200 OK | 58 | * @return 200 OK |
59 | + * @onos.rsModel Devicekeys | ||
59 | */ | 60 | */ |
60 | -// FIXME DeviceKeysGet.json not found | ||
61 | -// * @onos.rsModel DeviceKeysGet | ||
62 | @GET | 61 | @GET |
63 | public Response getDeviceKeys() { | 62 | public Response getDeviceKeys() { |
64 | Iterable<DeviceKey> deviceKeys = get(DeviceKeyService.class).getDeviceKeys(); | 63 | Iterable<DeviceKey> deviceKeys = get(DeviceKeyService.class).getDeviceKeys(); |
... | @@ -69,11 +68,10 @@ public class DeviceKeyWebResource extends AbstractWebResource { | ... | @@ -69,11 +68,10 @@ public class DeviceKeyWebResource extends AbstractWebResource { |
69 | * Get a single device key by device key unique identifier. | 68 | * Get a single device key by device key unique identifier. |
70 | * Returns the specified device key. | 69 | * Returns the specified device key. |
71 | * | 70 | * |
72 | - * @param id device identifier | 71 | + * @param id device key identifier |
73 | - * @return 200 OK | 72 | + * @return 200 OK, 404 not found |
73 | + * @onos.rsModel Devicekey | ||
74 | */ | 74 | */ |
75 | -// FIXME DeviceKeyGet.json not found | ||
76 | -// * @onos.rsModel DeviceKeyGet | ||
77 | @GET | 75 | @GET |
78 | @Path("{id}") | 76 | @Path("{id}") |
79 | public Response getDeviceKey(@PathParam("id") String id) { | 77 | public Response getDeviceKey(@PathParam("id") String id) { |
... | @@ -83,14 +81,13 @@ public class DeviceKeyWebResource extends AbstractWebResource { | ... | @@ -83,14 +81,13 @@ public class DeviceKeyWebResource extends AbstractWebResource { |
83 | } | 81 | } |
84 | 82 | ||
85 | /** | 83 | /** |
86 | - * Adds a new device key from the JSON request. | 84 | + * Adds a new device key from the JSON input stream. |
87 | * | 85 | * |
88 | - * @param stream input JSON | 86 | + * @param stream device key JSON stream |
89 | * @return status of the request - CREATED if the JSON is correct, | 87 | * @return status of the request - CREATED if the JSON is correct, |
90 | * BAD_REQUEST if the JSON is invalid | 88 | * BAD_REQUEST if the JSON is invalid |
89 | + * @onos.rsModel Devicekey | ||
91 | */ | 90 | */ |
92 | -// FIXME wrong schema definition? | ||
93 | -// * @onos.rsModel IntentHost | ||
94 | @POST | 91 | @POST |
95 | @Consumes(MediaType.APPLICATION_JSON) | 92 | @Consumes(MediaType.APPLICATION_JSON) |
96 | @Produces(MediaType.APPLICATION_JSON) | 93 | @Produces(MediaType.APPLICATION_JSON) |
... | @@ -117,8 +114,8 @@ public class DeviceKeyWebResource extends AbstractWebResource { | ... | @@ -117,8 +114,8 @@ public class DeviceKeyWebResource extends AbstractWebResource { |
117 | /** | 114 | /** |
118 | * Removes a device key by device key identifier. | 115 | * Removes a device key by device key identifier. |
119 | * | 116 | * |
120 | - * @param id device identifier | 117 | + * @param id device key identifier |
121 | - * @return 200 OK | 118 | + * @return 200 OK, 404 not found |
122 | */ | 119 | */ |
123 | @DELETE | 120 | @DELETE |
124 | @Path("{id}") | 121 | @Path("{id}") | ... | ... |
1 | +{ | ||
2 | + "type": "object", | ||
3 | + "title": "Devicekey", | ||
4 | + "required": [ | ||
5 | + "id", | ||
6 | + "type", | ||
7 | + "label" | ||
8 | + ], | ||
9 | + "properties": { | ||
10 | + "id": { | ||
11 | + "type": "String", | ||
12 | + "example": "Device key unique identifier" | ||
13 | + }, | ||
14 | + "type": { | ||
15 | + "type": "String", | ||
16 | + "example": "COMMUNITY_NAME, OR USERNAME_PASSWORD" | ||
17 | + }, | ||
18 | + "label": { | ||
19 | + "type": "String", | ||
20 | + "example": "Device key user label" | ||
21 | + }, | ||
22 | + "community_name": { | ||
23 | + "type": "String", | ||
24 | + "example": "Device key community name" | ||
25 | + }, | ||
26 | + "username": { | ||
27 | + "type": "String", | ||
28 | + "example": "Device key username" | ||
29 | + }, | ||
30 | + "password": { | ||
31 | + "type": "String", | ||
32 | + "example": "Device key password" | ||
33 | + } | ||
34 | + } | ||
35 | +} |
1 | +{ | ||
2 | + "type": "object", | ||
3 | + "title": "Devicekeys", | ||
4 | + "required": [ | ||
5 | + "keys" | ||
6 | + ], | ||
7 | + "properties": { | ||
8 | + "keys": { | ||
9 | + "type": "array", | ||
10 | + "xml": { | ||
11 | + "name": "keys", | ||
12 | + "wrapped": true | ||
13 | + }, | ||
14 | + "items": { | ||
15 | + "type": "object", | ||
16 | + "title": "key", | ||
17 | + "required": [ | ||
18 | + "id", | ||
19 | + "type", | ||
20 | + "label" | ||
21 | + ], | ||
22 | + "properties": { | ||
23 | + "id": { | ||
24 | + "type": "String", | ||
25 | + "example": "Device key unique identifier" | ||
26 | + }, | ||
27 | + "type": { | ||
28 | + "type": "String", | ||
29 | + "example": "COMMUNITY_NAME, OR USERNAME_PASSWORD" | ||
30 | + }, | ||
31 | + "label": { | ||
32 | + "type": "String", | ||
33 | + "example": "Device key user label" | ||
34 | + }, | ||
35 | + "community_name": { | ||
36 | + "type": "String", | ||
37 | + "example": "Device key community name" | ||
38 | + }, | ||
39 | + "username": { | ||
40 | + "type": "String", | ||
41 | + "example": "Device key username" | ||
42 | + }, | ||
43 | + "password": { | ||
44 | + "type": "String", | ||
45 | + "example": "Device key password" | ||
46 | + } | ||
47 | + } | ||
48 | + } | ||
49 | + } | ||
50 | + } | ||
51 | +} |
... | @@ -25,7 +25,6 @@ import com.sun.jersey.api.client.WebResource; | ... | @@ -25,7 +25,6 @@ import com.sun.jersey.api.client.WebResource; |
25 | import org.hamcrest.Description; | 25 | import org.hamcrest.Description; |
26 | import org.hamcrest.Matchers; | 26 | import org.hamcrest.Matchers; |
27 | import org.hamcrest.TypeSafeMatcher; | 27 | import org.hamcrest.TypeSafeMatcher; |
28 | -import org.junit.After; | ||
29 | import org.junit.Before; | 28 | import org.junit.Before; |
30 | import org.junit.Test; | 29 | import org.junit.Test; |
31 | import org.onlab.osgi.ServiceDirectory; | 30 | import org.onlab.osgi.ServiceDirectory; |
... | @@ -67,6 +66,7 @@ public class DeviceKeyWebResourceTest extends ResourceTest { | ... | @@ -67,6 +66,7 @@ public class DeviceKeyWebResourceTest extends ResourceTest { |
67 | private final String deviceKeyId1 = "DeviceKeyId1"; | 66 | private final String deviceKeyId1 = "DeviceKeyId1"; |
68 | private final String deviceKeyId2 = "DeviceKeyId2"; | 67 | private final String deviceKeyId2 = "DeviceKeyId2"; |
69 | private final String deviceKeyId3 = "DeviceKeyId3"; | 68 | private final String deviceKeyId3 = "DeviceKeyId3"; |
69 | + private final String deviceKeyId4 = "DeviceKeyId4"; | ||
70 | private final String deviceKeyLabel = "DeviceKeyLabel"; | 70 | private final String deviceKeyLabel = "DeviceKeyLabel"; |
71 | private final String deviceKeyCommunityName = "DeviceKeyCommunityName"; | 71 | private final String deviceKeyCommunityName = "DeviceKeyCommunityName"; |
72 | private final String deviceKeyUsername = "DeviceKeyUsername"; | 72 | private final String deviceKeyUsername = "DeviceKeyUsername"; |
... | @@ -75,7 +75,11 @@ public class DeviceKeyWebResourceTest extends ResourceTest { | ... | @@ -75,7 +75,11 @@ public class DeviceKeyWebResourceTest extends ResourceTest { |
75 | private final DeviceKey deviceKey1 = DeviceKey.createDeviceKeyUsingCommunityName( | 75 | private final DeviceKey deviceKey1 = DeviceKey.createDeviceKeyUsingCommunityName( |
76 | DeviceKeyId.deviceKeyId(deviceKeyId1), deviceKeyLabel, deviceKeyCommunityName); | 76 | DeviceKeyId.deviceKeyId(deviceKeyId1), deviceKeyLabel, deviceKeyCommunityName); |
77 | private final DeviceKey deviceKey2 = DeviceKey.createDeviceKeyUsingUsernamePassword( | 77 | private final DeviceKey deviceKey2 = DeviceKey.createDeviceKeyUsingUsernamePassword( |
78 | - DeviceKeyId.deviceKeyId(deviceKeyId2), deviceKeyLabel, deviceKeyUsername, deviceKeyPassword); | 78 | + DeviceKeyId.deviceKeyId(deviceKeyId2), null, deviceKeyUsername, deviceKeyPassword); |
79 | + private final DeviceKey deviceKey3 = DeviceKey.createDeviceKeyUsingUsernamePassword( | ||
80 | + DeviceKeyId.deviceKeyId(deviceKeyId3), null, null, null); | ||
81 | + private final DeviceKey deviceKey4 = DeviceKey.createDeviceKeyUsingCommunityName( | ||
82 | + DeviceKeyId.deviceKeyId(deviceKeyId4), null, null); | ||
79 | 83 | ||
80 | /** | 84 | /** |
81 | * Initializes test mocks and environment. | 85 | * Initializes test mocks and environment. |
... | @@ -97,15 +101,6 @@ public class DeviceKeyWebResourceTest extends ResourceTest { | ... | @@ -97,15 +101,6 @@ public class DeviceKeyWebResourceTest extends ResourceTest { |
97 | } | 101 | } |
98 | 102 | ||
99 | /** | 103 | /** |
100 | - * Verifies test mocks. | ||
101 | - */ | ||
102 | - @After | ||
103 | - public void tearDownMocks() { | ||
104 | - verify(mockDeviceKeyService); | ||
105 | - verify(mockDeviceKeyAdminService); | ||
106 | - } | ||
107 | - | ||
108 | - /** | ||
109 | * Hamcrest matcher to check that a device key representation in JSON matches | 104 | * Hamcrest matcher to check that a device key representation in JSON matches |
110 | * the actual device key. | 105 | * the actual device key. |
111 | */ | 106 | */ |
... | @@ -127,10 +122,12 @@ public class DeviceKeyWebResourceTest extends ResourceTest { | ... | @@ -127,10 +122,12 @@ public class DeviceKeyWebResourceTest extends ResourceTest { |
127 | } | 122 | } |
128 | 123 | ||
129 | // Check the device key label | 124 | // Check the device key label |
130 | - final String jsonLabel = jsonHost.get(LABEL).asString(); | 125 | + final String jsonLabel = (jsonHost.get(LABEL).isNull()) ? null : jsonHost.get(LABEL).asString(); |
131 | - if (!jsonLabel.equals(deviceKey.label().toString())) { | 126 | + if (deviceKey.label() != null) { |
132 | - reason = LABEL + " " + deviceKey.label().toString(); | 127 | + if ((jsonLabel == null) || !jsonLabel.equals(deviceKey.label())) { |
133 | - return false; | 128 | + reason = LABEL + " " + deviceKey.label(); |
129 | + return false; | ||
130 | + } | ||
134 | } | 131 | } |
135 | 132 | ||
136 | // Check the device key type | 133 | // Check the device key type |
... | @@ -142,24 +139,33 @@ public class DeviceKeyWebResourceTest extends ResourceTest { | ... | @@ -142,24 +139,33 @@ public class DeviceKeyWebResourceTest extends ResourceTest { |
142 | 139 | ||
143 | if (jsonType.equals(DeviceKey.Type.COMMUNITY_NAME.toString())) { | 140 | if (jsonType.equals(DeviceKey.Type.COMMUNITY_NAME.toString())) { |
144 | // Check the device key community name | 141 | // Check the device key community name |
145 | - final String jsonCommunityName = jsonHost.get(COMMUNITY_NAME).asString(); | 142 | + final String jsonCommunityName = jsonHost.get(COMMUNITY_NAME).isNull() ? |
146 | - if (!jsonCommunityName.equals(deviceKey.asCommunityName().name().toString())) { | 143 | + null : jsonHost.get(COMMUNITY_NAME).asString(); |
147 | - reason = COMMUNITY_NAME + " " + deviceKey.asCommunityName().name().toString(); | 144 | + if (deviceKey.asCommunityName().name() != null) { |
148 | - return false; | 145 | + if (!jsonCommunityName.equals(deviceKey.asCommunityName().name().toString())) { |
146 | + reason = COMMUNITY_NAME + " " + deviceKey.asCommunityName().name().toString(); | ||
147 | + return false; | ||
148 | + } | ||
149 | } | 149 | } |
150 | } else if (jsonType.equals(DeviceKey.Type.USERNAME_PASSWORD.toString())) { | 150 | } else if (jsonType.equals(DeviceKey.Type.USERNAME_PASSWORD.toString())) { |
151 | // Check the device key username | 151 | // Check the device key username |
152 | - final String jsonUsername = jsonHost.get(USERNAME).asString(); | 152 | + final String jsonUsername = jsonHost.get(USERNAME).isNull() ? |
153 | - if (!jsonUsername.equals(deviceKey.asUsernamePassword().username().toString())) { | 153 | + null : jsonHost.get(USERNAME).asString(); |
154 | - reason = USERNAME + " " + deviceKey.asUsernamePassword().username().toString(); | 154 | + if (deviceKey.asUsernamePassword().username() != null) { |
155 | - return false; | 155 | + if (!jsonUsername.equals(deviceKey.asUsernamePassword().username().toString())) { |
156 | + reason = USERNAME + " " + deviceKey.asUsernamePassword().username().toString(); | ||
157 | + return false; | ||
158 | + } | ||
156 | } | 159 | } |
157 | 160 | ||
158 | // Check the device key password | 161 | // Check the device key password |
159 | - final String jsonPassword = jsonHost.get(PASSWORD).asString(); | 162 | + final String jsonPassword = jsonHost.get(PASSWORD).isNull() ? |
160 | - if (!jsonPassword.equals(deviceKey.asUsernamePassword().password().toString())) { | 163 | + null : jsonHost.get(PASSWORD).asString(); |
161 | - reason = PASSWORD + " " + deviceKey.asUsernamePassword().password().toString(); | 164 | + if (deviceKey.asUsernamePassword().password() != null) { |
162 | - return false; | 165 | + if (!jsonPassword.equals(deviceKey.asUsernamePassword().password().toString())) { |
166 | + reason = PASSWORD + " " + deviceKey.asUsernamePassword().password().toString(); | ||
167 | + return false; | ||
168 | + } | ||
163 | } | 169 | } |
164 | } else { | 170 | } else { |
165 | reason = "Unknown " + TYPE + " " + deviceKey.type().toString(); | 171 | reason = "Unknown " + TYPE + " " + deviceKey.type().toString(); |
... | @@ -251,11 +257,12 @@ public class DeviceKeyWebResourceTest extends ResourceTest { | ... | @@ -251,11 +257,12 @@ public class DeviceKeyWebResourceTest extends ResourceTest { |
251 | @Test | 257 | @Test |
252 | public void testGetDeviceKeysEmptyArray() { | 258 | public void testGetDeviceKeysEmptyArray() { |
253 | replay(mockDeviceKeyService); | 259 | replay(mockDeviceKeyService); |
254 | - replay(mockDeviceKeyAdminService); | ||
255 | 260 | ||
256 | WebResource rs = resource(); | 261 | WebResource rs = resource(); |
257 | String response = rs.path("keys").get(String.class); | 262 | String response = rs.path("keys").get(String.class); |
258 | assertThat(response, is("{\"keys\":[]}")); | 263 | assertThat(response, is("{\"keys\":[]}")); |
264 | + | ||
265 | + verify(mockDeviceKeyService); | ||
259 | } | 266 | } |
260 | 267 | ||
261 | /** | 268 | /** |
... | @@ -264,9 +271,10 @@ public class DeviceKeyWebResourceTest extends ResourceTest { | ... | @@ -264,9 +271,10 @@ public class DeviceKeyWebResourceTest extends ResourceTest { |
264 | @Test | 271 | @Test |
265 | public void testGetDeviceKeysArray() { | 272 | public void testGetDeviceKeysArray() { |
266 | replay(mockDeviceKeyService); | 273 | replay(mockDeviceKeyService); |
267 | - replay(mockDeviceKeyAdminService); | ||
268 | deviceKeySet.add(deviceKey1); | 274 | deviceKeySet.add(deviceKey1); |
269 | deviceKeySet.add(deviceKey2); | 275 | deviceKeySet.add(deviceKey2); |
276 | + deviceKeySet.add(deviceKey3); | ||
277 | + deviceKeySet.add(deviceKey4); | ||
270 | 278 | ||
271 | WebResource rs = resource(); | 279 | WebResource rs = resource(); |
272 | String response = rs.path("keys").get(String.class); | 280 | String response = rs.path("keys").get(String.class); |
... | @@ -280,10 +288,14 @@ public class DeviceKeyWebResourceTest extends ResourceTest { | ... | @@ -280,10 +288,14 @@ public class DeviceKeyWebResourceTest extends ResourceTest { |
280 | 288 | ||
281 | final JsonArray deviceKeys = result.get("keys").asArray(); | 289 | final JsonArray deviceKeys = result.get("keys").asArray(); |
282 | assertThat(deviceKeys, notNullValue()); | 290 | assertThat(deviceKeys, notNullValue()); |
283 | - assertEquals("Device keys array is not the correct size.", 2, deviceKeys.size()); | 291 | + assertEquals("Device keys array is not the correct size.", 4, deviceKeys.size()); |
284 | 292 | ||
285 | assertThat(deviceKeys, hasDeviceKey(deviceKey1)); | 293 | assertThat(deviceKeys, hasDeviceKey(deviceKey1)); |
286 | assertThat(deviceKeys, hasDeviceKey(deviceKey2)); | 294 | assertThat(deviceKeys, hasDeviceKey(deviceKey2)); |
295 | + assertThat(deviceKeys, hasDeviceKey(deviceKey3)); | ||
296 | + assertThat(deviceKeys, hasDeviceKey(deviceKey4)); | ||
297 | + | ||
298 | + verify(mockDeviceKeyService); | ||
287 | } | 299 | } |
288 | 300 | ||
289 | /** | 301 | /** |
... | @@ -297,7 +309,6 @@ public class DeviceKeyWebResourceTest extends ResourceTest { | ... | @@ -297,7 +309,6 @@ public class DeviceKeyWebResourceTest extends ResourceTest { |
297 | .andReturn(deviceKey1) | 309 | .andReturn(deviceKey1) |
298 | .anyTimes(); | 310 | .anyTimes(); |
299 | replay(mockDeviceKeyService); | 311 | replay(mockDeviceKeyService); |
300 | - replay(mockDeviceKeyAdminService); | ||
301 | 312 | ||
302 | WebResource rs = resource(); | 313 | WebResource rs = resource(); |
303 | String response = rs.path("keys/" + deviceKeyId1).get(String.class); | 314 | String response = rs.path("keys/" + deviceKeyId1).get(String.class); |
... | @@ -305,6 +316,8 @@ public class DeviceKeyWebResourceTest extends ResourceTest { | ... | @@ -305,6 +316,8 @@ public class DeviceKeyWebResourceTest extends ResourceTest { |
305 | assertThat(result, notNullValue()); | 316 | assertThat(result, notNullValue()); |
306 | 317 | ||
307 | assertThat(result, matchesDeviceKey(deviceKey1)); | 318 | assertThat(result, matchesDeviceKey(deviceKey1)); |
319 | + | ||
320 | + verify(mockDeviceKeyService); | ||
308 | } | 321 | } |
309 | 322 | ||
310 | /** | 323 | /** |
... | @@ -317,7 +330,6 @@ public class DeviceKeyWebResourceTest extends ResourceTest { | ... | @@ -317,7 +330,6 @@ public class DeviceKeyWebResourceTest extends ResourceTest { |
317 | .andReturn(null) | 330 | .andReturn(null) |
318 | .anyTimes(); | 331 | .anyTimes(); |
319 | replay(mockDeviceKeyService); | 332 | replay(mockDeviceKeyService); |
320 | - replay(mockDeviceKeyAdminService); | ||
321 | 333 | ||
322 | WebResource rs = resource(); | 334 | WebResource rs = resource(); |
323 | try { | 335 | try { |
... | @@ -327,6 +339,8 @@ public class DeviceKeyWebResourceTest extends ResourceTest { | ... | @@ -327,6 +339,8 @@ public class DeviceKeyWebResourceTest extends ResourceTest { |
327 | assertThat(ex.getMessage(), | 339 | assertThat(ex.getMessage(), |
328 | containsString("returned a response status of")); | 340 | containsString("returned a response status of")); |
329 | } | 341 | } |
342 | + | ||
343 | + verify(mockDeviceKeyService); | ||
330 | } | 344 | } |
331 | 345 | ||
332 | /** | 346 | /** |
... | @@ -338,7 +352,6 @@ public class DeviceKeyWebResourceTest extends ResourceTest { | ... | @@ -338,7 +352,6 @@ public class DeviceKeyWebResourceTest extends ResourceTest { |
338 | mockDeviceKeyAdminService.addKey(anyObject()); | 352 | mockDeviceKeyAdminService.addKey(anyObject()); |
339 | expectLastCall(); | 353 | expectLastCall(); |
340 | 354 | ||
341 | - replay(mockDeviceKeyService); | ||
342 | replay(mockDeviceKeyAdminService); | 355 | replay(mockDeviceKeyAdminService); |
343 | 356 | ||
344 | WebResource rs = resource(); | 357 | WebResource rs = resource(); |
... | @@ -352,6 +365,8 @@ public class DeviceKeyWebResourceTest extends ResourceTest { | ... | @@ -352,6 +365,8 @@ public class DeviceKeyWebResourceTest extends ResourceTest { |
352 | 365 | ||
353 | String location = response.getLocation().getPath(); | 366 | String location = response.getLocation().getPath(); |
354 | assertThat(location, Matchers.startsWith("/keys/" + deviceKeyId3)); | 367 | assertThat(location, Matchers.startsWith("/keys/" + deviceKeyId3)); |
368 | + | ||
369 | + verify(mockDeviceKeyAdminService); | ||
355 | } | 370 | } |
356 | 371 | ||
357 | /** | 372 | /** |
... | @@ -360,7 +375,6 @@ public class DeviceKeyWebResourceTest extends ResourceTest { | ... | @@ -360,7 +375,6 @@ public class DeviceKeyWebResourceTest extends ResourceTest { |
360 | @Test | 375 | @Test |
361 | public void testPostNullDeviceKey() { | 376 | public void testPostNullDeviceKey() { |
362 | 377 | ||
363 | - replay(mockDeviceKeyService); | ||
364 | replay(mockDeviceKeyAdminService); | 378 | replay(mockDeviceKeyAdminService); |
365 | 379 | ||
366 | WebResource rs = resource(); | 380 | WebResource rs = resource(); |
... | @@ -373,6 +387,8 @@ public class DeviceKeyWebResourceTest extends ResourceTest { | ... | @@ -373,6 +387,8 @@ public class DeviceKeyWebResourceTest extends ResourceTest { |
373 | assertThat(ex.getMessage(), | 387 | assertThat(ex.getMessage(), |
374 | containsString("returned a response status of")); | 388 | containsString("returned a response status of")); |
375 | } | 389 | } |
390 | + | ||
391 | + verify(mockDeviceKeyAdminService); | ||
376 | } | 392 | } |
377 | 393 | ||
378 | /** | 394 | /** |
... | @@ -395,6 +411,9 @@ public class DeviceKeyWebResourceTest extends ResourceTest { | ... | @@ -395,6 +411,9 @@ public class DeviceKeyWebResourceTest extends ResourceTest { |
395 | .type(MediaType.APPLICATION_JSON_TYPE) | 411 | .type(MediaType.APPLICATION_JSON_TYPE) |
396 | .delete(ClientResponse.class); | 412 | .delete(ClientResponse.class); |
397 | assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK)); | 413 | assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK)); |
414 | + | ||
415 | + verify(mockDeviceKeyService); | ||
416 | + verify(mockDeviceKeyAdminService); | ||
398 | } | 417 | } |
399 | 418 | ||
400 | /** | 419 | /** |
... | @@ -421,5 +440,8 @@ public class DeviceKeyWebResourceTest extends ResourceTest { | ... | @@ -421,5 +440,8 @@ public class DeviceKeyWebResourceTest extends ResourceTest { |
421 | assertThat(ex.getMessage(), | 440 | assertThat(ex.getMessage(), |
422 | containsString("returned a response status of")); | 441 | containsString("returned a response status of")); |
423 | } | 442 | } |
443 | + | ||
444 | + verify(mockDeviceKeyService); | ||
445 | + verify(mockDeviceKeyAdminService); | ||
424 | } | 446 | } |
425 | } | 447 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment