blob: 3de04ba20ecd139d36a436e8a7aa28fc0e1cf691 [file] [log] [blame]
Ray Milkeyf195b022015-02-03 15:13:11 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Ray Milkeyf195b022015-02-03 15:13:11 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Jian Li8ae91202016-03-24 14:36:16 -070016package org.onosproject.rest.resources;
Ray Milkeyf195b022015-02-03 15:13:11 -080017
Jian Li80cfe452016-01-14 16:04:58 -080018import com.eclipsesource.json.Json;
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080019import com.eclipsesource.json.JsonArray;
20import com.eclipsesource.json.JsonObject;
21import com.google.common.collect.ImmutableList;
22import com.google.common.collect.ImmutableSet;
Ray Milkeyf195b022015-02-03 15:13:11 -080023import org.hamcrest.Description;
24import org.hamcrest.TypeSafeMatcher;
Jian Li847242b2016-05-11 18:58:53 -070025import org.junit.Assert;
Ray Milkeyf195b022015-02-03 15:13:11 -080026import org.junit.Before;
27import org.junit.Test;
28import org.onlab.osgi.ServiceDirectory;
29import org.onlab.osgi.TestServiceDirectory;
Ray Milkeyf195b022015-02-03 15:13:11 -080030import org.onosproject.app.ApplicationAdminService;
31import org.onosproject.app.ApplicationService;
32import org.onosproject.app.ApplicationState;
33import org.onosproject.codec.CodecService;
34import org.onosproject.codec.impl.ApplicationCodec;
35import org.onosproject.codec.impl.CodecManager;
36import org.onosproject.codec.impl.MockCodecContext;
37import org.onosproject.core.Application;
38import org.onosproject.core.ApplicationId;
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090039import org.onosproject.core.ApplicationRole;
Jian Lie1c1c8d2016-05-09 16:24:40 -070040import org.onosproject.core.CoreService;
Ray Milkeyf195b022015-02-03 15:13:11 -080041import org.onosproject.core.DefaultApplication;
42import org.onosproject.core.DefaultApplicationId;
43import org.onosproject.core.Version;
44
Jian Li847242b2016-05-11 18:58:53 -070045import javax.ws.rs.NotFoundException;
Jian Li9d616492016-03-09 10:52:49 -080046import javax.ws.rs.client.Entity;
47import javax.ws.rs.client.WebTarget;
48import javax.ws.rs.core.MediaType;
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080049import java.io.InputStream;
50import java.net.URI;
51import java.util.Optional;
Ray Milkeyf195b022015-02-03 15:13:11 -080052
Jian Li9d616492016-03-09 10:52:49 -080053import static org.easymock.EasyMock.createMock;
54import static org.easymock.EasyMock.expect;
55import static org.easymock.EasyMock.expectLastCall;
56import static org.easymock.EasyMock.isA;
57import static org.easymock.EasyMock.replay;
58import static org.easymock.EasyMock.verify;
Ray Milkeyf195b022015-02-03 15:13:11 -080059import static org.hamcrest.MatcherAssert.assertThat;
Yuta HIGUCHI293ede02015-02-05 00:08:41 -080060import static org.hamcrest.Matchers.containsString;
61import static org.hamcrest.Matchers.hasSize;
62import static org.hamcrest.Matchers.is;
63import static org.hamcrest.Matchers.notNullValue;
Ray Milkeyf195b022015-02-03 15:13:11 -080064
65/**
66 * Unit tests for applications REST APIs.
67 */
68
69public class ApplicationsResourceTest extends ResourceTest {
70
Jian Lie1c1c8d2016-05-09 16:24:40 -070071 private static class MockCodecContextWithAppService extends MockCodecContext {
72 private ApplicationAdminService appService;
Ray Milkeyf195b022015-02-03 15:13:11 -080073
Jian Lie1c1c8d2016-05-09 16:24:40 -070074 MockCodecContextWithAppService(ApplicationAdminService appService) {
75 this.appService = appService;
Ray Milkeyf195b022015-02-03 15:13:11 -080076 }
77
78 @Override
79 @SuppressWarnings("unchecked")
Ray Milkey3078fc02015-05-06 16:14:14 -070080 public <T> T getService(Class<T> serviceClass) {
Jian Lie1c1c8d2016-05-09 16:24:40 -070081 return (T) appService;
Ray Milkeyf195b022015-02-03 15:13:11 -080082 }
83 }
84
Jian Lie1c1c8d2016-05-09 16:24:40 -070085 private static class MockCodecContextWithCoreService extends MockCodecContext {
86 private CoreService coreService;
87
88 MockCodecContextWithCoreService(CoreService coreService) {
89 this.coreService = coreService;
90 }
91
92 @Override
93 @SuppressWarnings("unchecked")
94 public <T> T getService(Class<T> serviceClass) {
95 return (T) coreService;
96 }
97 }
98
99 private ApplicationAdminService appService;
100 private CoreService coreService;
Ray Milkeyf195b022015-02-03 15:13:11 -0800101 private ApplicationId id1 = new DefaultApplicationId(1, "app1");
102 private ApplicationId id2 = new DefaultApplicationId(2, "app2");
103 private ApplicationId id3 = new DefaultApplicationId(3, "app3");
104 private ApplicationId id4 = new DefaultApplicationId(4, "app4");
105
106 private static final URI FURL = URI.create("mvn:org.foo-features/1.2a/xml/features");
107 private static final Version VER = Version.version(1, 2, "a", null);
108
Ray Milkey47c95412017-09-15 10:40:48 -0700109 private DefaultApplication.Builder baseBuilder = DefaultApplication.builder()
110 .withVersion(VER)
111 .withIcon(new byte[0])
112 .withRole(ApplicationRole.ADMIN)
113 .withPermissions(ImmutableSet.of())
114 .withFeaturesRepo(Optional.of(FURL))
115 .withFeatures(ImmutableList.of("My Feature"))
116 .withRequiredApps(ImmutableList.of());
117
Ray Milkeyf195b022015-02-03 15:13:11 -0800118 private Application app1 =
Ray Milkey47c95412017-09-15 10:40:48 -0700119 DefaultApplication.builder(baseBuilder)
120 .withAppId(id1)
121 .withTitle("title1")
122 .withDescription("desc1")
123 .withOrigin("origin1")
124 .withCategory("category1")
125 .withUrl("url1")
126 .withReadme("readme1")
127 .build();
Ray Milkeyf195b022015-02-03 15:13:11 -0800128 private Application app2 =
Ray Milkey47c95412017-09-15 10:40:48 -0700129 DefaultApplication.builder(baseBuilder)
130 .withAppId(id2)
131 .withTitle("title2")
132 .withDescription("desc2")
133 .withOrigin("origin2")
134 .withCategory("category2")
135 .withUrl("url2")
136 .withReadme("readme2")
137 .build();
Ray Milkeyf195b022015-02-03 15:13:11 -0800138 private Application app3 =
Ray Milkey47c95412017-09-15 10:40:48 -0700139 DefaultApplication.builder(baseBuilder)
140 .withAppId(id3)
141 .withTitle("title3")
142 .withDescription("desc3")
143 .withOrigin("origin3")
144 .withCategory("category3")
145 .withUrl("url3")
146 .withReadme("readme3")
147 .build();
Ray Milkeyf195b022015-02-03 15:13:11 -0800148 private Application app4 =
Ray Milkey47c95412017-09-15 10:40:48 -0700149 DefaultApplication.builder(baseBuilder)
150 .withAppId(id4)
151 .withTitle("title4")
152 .withDescription("desc4")
153 .withOrigin("origin4")
154 .withCategory("category4")
155 .withUrl("url4")
156 .withReadme("readme4")
157 .build();
Ray Milkeyf195b022015-02-03 15:13:11 -0800158
159 /**
Ray Milkeyed0b1662015-02-05 09:34:29 -0800160 * Hamcrest matcher to check that an application representation in JSON matches
Ray Milkeyf195b022015-02-03 15:13:11 -0800161 * the actual device.
162 */
163 private static class AppJsonMatcher extends TypeSafeMatcher<JsonObject> {
164 private final Application app;
165 private String reason = "";
166
167 public AppJsonMatcher(Application appValue) {
168 app = appValue;
169 }
170
171 @Override
172 public boolean matchesSafely(JsonObject jsonApp) {
173 // check id
174 short jsonId = (short) jsonApp.get("id").asInt();
175 if (jsonId != app.id().id()) {
176 reason = "id " + app.id().id();
177 return false;
178 }
179
180 // check name
181 String jsonName = jsonApp.get("name").asString();
182 if (!jsonName.equals(app.id().name())) {
183 reason = "name " + app.id().name();
184 return false;
185 }
186
187 // check origin
188 String jsonOrigin = jsonApp.get("origin").asString();
189 if (!jsonOrigin.equals(app.origin())) {
190 reason = "manufacturer " + app.origin();
191 return false;
192 }
193
194 return true;
195 }
196
197 @Override
198 public void describeTo(Description description) {
199 description.appendText(reason);
200 }
201 }
202
203 /**
Jian Lie1c1c8d2016-05-09 16:24:40 -0700204 * Hamcrest matcher to check that an application id representation in JSON.
205 */
206 private static final class AppIdJsonMatcher extends TypeSafeMatcher<JsonObject> {
207 private final ApplicationId appId;
208 private String reason = "";
209
210 private AppIdJsonMatcher(ApplicationId appId) {
211 this.appId = appId;
212 }
213
214 @Override
215 protected boolean matchesSafely(JsonObject jsonAppId) {
216 // check id
217 short jsonId = (short) jsonAppId.get("id").asInt();
218 if (jsonId != appId.id()) {
219 reason = "id " + appId.id();
220 return false;
221 }
222
223 // check name
224 String jsonName = jsonAppId.get("name").asString();
225 if (!jsonName.equals(appId.name())) {
226 reason = "name " + appId.name();
227 return false;
228 }
229
230 return true;
231 }
232
233 @Override
234 public void describeTo(Description description) {
235 description.appendText(reason);
236 }
237 }
238
239 /**
Ray Milkeyed0b1662015-02-05 09:34:29 -0800240 * Factory to allocate an application matcher.
Ray Milkeyf195b022015-02-03 15:13:11 -0800241 *
242 * @param app application object we are looking for
243 * @return matcher
244 */
245 private static AppJsonMatcher matchesApp(Application app) {
246 return new AppJsonMatcher(app);
247 }
248
Ray Milkeyed0b1662015-02-05 09:34:29 -0800249 /**
Jian Lie1c1c8d2016-05-09 16:24:40 -0700250 * Factory to allocate an application Id matcher.
251 *
252 * @param appId application Id object we are looking for
253 * @return matcher
254 */
255 private static AppIdJsonMatcher matchesAppId(ApplicationId appId) {
256 return new AppIdJsonMatcher(appId);
257 }
258
259 /**
Ray Milkeyed0b1662015-02-05 09:34:29 -0800260 * Initializes test mocks and environment.
261 */
Ray Milkeyf195b022015-02-03 15:13:11 -0800262 @Before
Ray Milkeyed0b1662015-02-05 09:34:29 -0800263 public void setUpMocks() {
Jian Lie1c1c8d2016-05-09 16:24:40 -0700264 appService = createMock(ApplicationAdminService.class);
265 coreService = createMock(CoreService.class);
Ray Milkeyf195b022015-02-03 15:13:11 -0800266
Jian Lie1c1c8d2016-05-09 16:24:40 -0700267 expect(appService.getId("one"))
Ray Milkeyf195b022015-02-03 15:13:11 -0800268 .andReturn(id1)
269 .anyTimes();
Jian Lie1c1c8d2016-05-09 16:24:40 -0700270 expect(appService.getId("two"))
Ray Milkeyf195b022015-02-03 15:13:11 -0800271 .andReturn(id2)
272 .anyTimes();
Jian Lie1c1c8d2016-05-09 16:24:40 -0700273 expect(appService.getId("three"))
Ray Milkeyf195b022015-02-03 15:13:11 -0800274 .andReturn(id3)
275 .anyTimes();
Jian Lie1c1c8d2016-05-09 16:24:40 -0700276 expect(appService.getId("four"))
Ray Milkeyf195b022015-02-03 15:13:11 -0800277 .andReturn(id4)
278 .anyTimes();
279
Jian Lie1c1c8d2016-05-09 16:24:40 -0700280 expect(appService.getApplication(id3))
Ray Milkeyf195b022015-02-03 15:13:11 -0800281 .andReturn(app3)
282 .anyTimes();
Jian Lie1c1c8d2016-05-09 16:24:40 -0700283 expect(appService.getState(isA(ApplicationId.class)))
Ray Milkeyf195b022015-02-03 15:13:11 -0800284 .andReturn(ApplicationState.ACTIVE)
285 .anyTimes();
286
287 // Register the services needed for the test
288 CodecManager codecService = new CodecManager();
289 codecService.activate();
290 ServiceDirectory testDirectory =
291 new TestServiceDirectory()
Jian Lie1c1c8d2016-05-09 16:24:40 -0700292 .add(ApplicationAdminService.class, appService)
293 .add(ApplicationService.class, appService)
294 .add(CoreService.class, coreService)
Ray Milkeyf195b022015-02-03 15:13:11 -0800295 .add(CodecService.class, codecService);
296
Ray Milkey094a1352018-01-22 14:03:54 -0800297 setServiceDirectory(testDirectory);
Ray Milkeyf195b022015-02-03 15:13:11 -0800298 }
299
Ray Milkeyed0b1662015-02-05 09:34:29 -0800300 /**
Ray Milkeyf195b022015-02-03 15:13:11 -0800301 * Tests a GET of all applications when no applications are present.
302 */
303 @Test
304 public void getAllApplicationsEmpty() {
Jian Lie1c1c8d2016-05-09 16:24:40 -0700305 expect(appService.getApplications())
Ray Milkeyf195b022015-02-03 15:13:11 -0800306 .andReturn(ImmutableSet.of());
Jian Lie1c1c8d2016-05-09 16:24:40 -0700307 replay(appService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800308
Jian Li9d616492016-03-09 10:52:49 -0800309 WebTarget wt = target();
310 String response = wt.path("applications").request().get(String.class);
Ray Milkeyf195b022015-02-03 15:13:11 -0800311 assertThat(response, is("{\"applications\":[]}"));
Jian Lie1c1c8d2016-05-09 16:24:40 -0700312
313 verify(appService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800314 }
315
316 /**
317 * Tests a GET of all applications with data.
318 */
319 @Test
320 public void getAllApplicationsPopulated() {
Jian Lie1c1c8d2016-05-09 16:24:40 -0700321 expect(appService.getApplications())
Ray Milkeyf195b022015-02-03 15:13:11 -0800322 .andReturn(ImmutableSet.of(app1, app2, app3, app4));
Jian Lie1c1c8d2016-05-09 16:24:40 -0700323 replay(appService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800324
Jian Li9d616492016-03-09 10:52:49 -0800325 WebTarget wt = target();
326 String response = wt.path("applications").request().get(String.class);
Ray Milkeyf195b022015-02-03 15:13:11 -0800327 assertThat(response, containsString("{\"applications\":["));
328
Jian Li80cfe452016-01-14 16:04:58 -0800329 JsonObject result = Json.parse(response).asObject();
Ray Milkeyf195b022015-02-03 15:13:11 -0800330 assertThat(result, notNullValue());
331
332 assertThat(result.names(), hasSize(1));
333 assertThat(result.names().get(0), is("applications"));
334
335 JsonArray jsonApps = result.get("applications").asArray();
336 assertThat(jsonApps, notNullValue());
337 assertThat(jsonApps.size(), is(4));
338
339 assertThat(jsonApps.get(0).asObject(), matchesApp(app1));
340 assertThat(jsonApps.get(1).asObject(), matchesApp(app2));
341 assertThat(jsonApps.get(2).asObject(), matchesApp(app3));
342 assertThat(jsonApps.get(3).asObject(), matchesApp(app4));
Jian Lie1c1c8d2016-05-09 16:24:40 -0700343
344 verify(appService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800345 }
346
347 /**
348 * Tests a GET of a single application.
349 */
350 @Test
351 public void getSingleApplication() {
Jian Lie1c1c8d2016-05-09 16:24:40 -0700352 replay(appService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800353
Jian Li9d616492016-03-09 10:52:49 -0800354 WebTarget wt = target();
355 String response = wt.path("applications/three").request().get(String.class);
Ray Milkeyf195b022015-02-03 15:13:11 -0800356
Jian Li80cfe452016-01-14 16:04:58 -0800357 JsonObject result = Json.parse(response).asObject();
Ray Milkeyf195b022015-02-03 15:13:11 -0800358 assertThat(result, notNullValue());
359
360 assertThat(result, matchesApp(app3));
Jian Lie1c1c8d2016-05-09 16:24:40 -0700361
362 verify(appService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800363 }
364
365 /**
366 * Tests a DELETE of a single application - this should
367 * attempt to uninstall it.
368 */
369 @Test
370 public void deleteApplication() {
Jian Lie1c1c8d2016-05-09 16:24:40 -0700371 appService.uninstall(id3);
Ray Milkeyf195b022015-02-03 15:13:11 -0800372 expectLastCall();
373
Jian Lie1c1c8d2016-05-09 16:24:40 -0700374 replay(appService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800375
Jian Li9d616492016-03-09 10:52:49 -0800376 WebTarget wt = target();
377 wt.path("applications/three").request().delete();
Jian Lie1c1c8d2016-05-09 16:24:40 -0700378
379 verify(appService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800380 }
381
382 /**
383 * Tests a DELETE of a single active application - this should
384 * attempt to uninstall it.
385 */
386 @Test
387 public void deleteActiveApplication() {
Jian Lie1c1c8d2016-05-09 16:24:40 -0700388 appService.deactivate(id3);
Ray Milkeyf195b022015-02-03 15:13:11 -0800389 expectLastCall();
390
Jian Lie1c1c8d2016-05-09 16:24:40 -0700391 replay(appService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800392
Jian Li9d616492016-03-09 10:52:49 -0800393 WebTarget wt = target();
394 wt.path("applications/three/active").request().delete();
Jian Lie1c1c8d2016-05-09 16:24:40 -0700395
396 verify(appService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800397 }
398
399 /**
400 * Tests a POST operation to the "active" URL. This should attempt to
401 * activate the application.
402 */
403 @Test
404 public void postActiveApplication() {
Jian Lie1c1c8d2016-05-09 16:24:40 -0700405 appService.activate(id3);
Ray Milkeyf195b022015-02-03 15:13:11 -0800406 expectLastCall();
407
Jian Lie1c1c8d2016-05-09 16:24:40 -0700408 replay(appService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800409
Jian Li9d616492016-03-09 10:52:49 -0800410 WebTarget wt = target();
411 wt.path("applications/three/active").request().post(null);
Jian Lie1c1c8d2016-05-09 16:24:40 -0700412
413 verify(appService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800414 }
415
416 /**
417 * Tests a POST operation. This should attempt to
418 * install the application.
419 */
420 @Test
421 public void postApplication() {
Jian Lie1c1c8d2016-05-09 16:24:40 -0700422 expect(appService.install(isA(InputStream.class)))
Ray Milkeyf195b022015-02-03 15:13:11 -0800423 .andReturn(app4)
424 .once();
425
Jian Lie1c1c8d2016-05-09 16:24:40 -0700426 replay(appService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800427
428 ApplicationCodec codec = new ApplicationCodec();
429 String app4Json = codec.encode(app4,
Jian Lie1c1c8d2016-05-09 16:24:40 -0700430 new MockCodecContextWithAppService(appService))
Ray Milkeyf195b022015-02-03 15:13:11 -0800431 .asText();
432
Jian Li9d616492016-03-09 10:52:49 -0800433 WebTarget wt = target();
434 String response = wt.path("applications").request().post(
435 Entity.entity(app4Json, MediaType.APPLICATION_OCTET_STREAM), String.class);
Ray Milkeyf195b022015-02-03 15:13:11 -0800436
Jian Li80cfe452016-01-14 16:04:58 -0800437 JsonObject result = Json.parse(response).asObject();
Ray Milkeyf195b022015-02-03 15:13:11 -0800438 assertThat(result, notNullValue());
439
440 assertThat(result, matchesApp(app4));
Jian Lie1c1c8d2016-05-09 16:24:40 -0700441
442 verify(appService);
443 }
444
445 /**
446 * Tests a POST operation. This should attempt to register an on/off platform
447 * application ID.
448 */
449 @Test
450 public void postRegisterAppId() {
451 expect(coreService.registerApplication("app1")).andReturn(id1).anyTimes();
452 replay(coreService);
453
454 WebTarget wt = target();
455 wt.path("applications/app1/register").request().post(null);
456
457 verify(coreService);
458 }
459
460 /**
461 * Tests a GET of all application Ids when no applications are present.
462 */
463 @Test
464 public void getAllApplicationIdsEmpty() {
465 expect(coreService.getAppIds()).andReturn(ImmutableSet.of());
466 replay(coreService);
467
468 WebTarget wt = target();
469 String response = wt.path("applications/ids").request().get(String.class);
470 assertThat(response, is("{\"applicationIds\":[]}"));
471
472 verify(coreService);
473 }
474
475 /**
476 * Tests a GET of all application Ids.
477 */
478 @Test
479 public void getAllApplicationIdsPopulated() {
480 expect(coreService.getAppIds())
481 .andReturn(ImmutableSet.of(id1, id2, id3, id4));
482 replay(coreService);
483
484 WebTarget wt = target();
485 String response = wt.path("applications/ids").request().get(String.class);
486
487 assertThat(response, containsString("{\"applicationIds\":["));
488
489 JsonObject result = Json.parse(response).asObject();
490 assertThat(result, notNullValue());
491
492 assertThat(result.names(), hasSize(1));
493 assertThat(result.names().get(0), is("applicationIds"));
494
495 JsonArray jsonApps = result.get("applicationIds").asArray();
496 assertThat(jsonApps, notNullValue());
497 assertThat(jsonApps.size(), is(4));
498
499 assertThat(jsonApps.get(0).asObject(), matchesAppId(id1));
500 assertThat(jsonApps.get(1).asObject(), matchesAppId(id2));
501 assertThat(jsonApps.get(2).asObject(), matchesAppId(id3));
502 assertThat(jsonApps.get(3).asObject(), matchesAppId(id4));
503
504 verify(coreService);
505 }
506
507 /**
508 * Tests a GET of an applicationId entry with the given numeric id.
509 */
510 @Test
511 public void getAppIdByShortId() {
512 expect(coreService.getAppId((short) 1)).andReturn(id1);
513 replay(coreService);
514
515 WebTarget wt = target();
Jian Li847242b2016-05-11 18:58:53 -0700516 String response = wt.path("applications/ids/entry")
517 .queryParam("id", 1).request().get(String.class);
Jian Lie1c1c8d2016-05-09 16:24:40 -0700518
519 JsonObject result = Json.parse(response).asObject();
520 assertThat(result, notNullValue());
521
522 assertThat(result, matchesAppId(id1));
523
524 verify(coreService);
525 }
526
527 /**
528 * Tests a GET of an applicationId entry with the given application name.
529 */
530 @Test
531 public void getAppIdByName() {
532 expect(coreService.getAppId("app2")).andReturn(id2);
533 replay(coreService);
534
535 WebTarget wt = target();
Jian Li847242b2016-05-11 18:58:53 -0700536 String response = wt.path("applications/ids/entry")
Jian Lie1c1c8d2016-05-09 16:24:40 -0700537 .queryParam("name", "app2").request().get(String.class);
538
539 JsonObject result = Json.parse(response).asObject();
540 assertThat(result, notNullValue());
541
542 assertThat(result, matchesAppId(id2));
543
544 verify(coreService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800545 }
Jian Li847242b2016-05-11 18:58:53 -0700546
547 /**
548 * Tests a GET of an applicationId without specifying any parameters.
549 */
550 @Test
551 public void getAppWithNoParam() {
552 WebTarget wt = target();
553
554 try {
555 wt.path("applications/ids/entry").request().get();
556 } catch (NotFoundException ex) {
557 Assert.assertThat(ex.getMessage(),
558 containsString("HTTP 404 Not Found"));
559 }
560 }
Ray Milkeyf195b022015-02-03 15:13:11 -0800561}