blob: 48cbd2d54c7d7f3b1e5bfc8ca94090752c0483e2 [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;
30import org.onlab.rest.BaseResource;
31import org.onosproject.app.ApplicationAdminService;
32import org.onosproject.app.ApplicationService;
33import org.onosproject.app.ApplicationState;
34import org.onosproject.codec.CodecService;
35import org.onosproject.codec.impl.ApplicationCodec;
36import org.onosproject.codec.impl.CodecManager;
37import org.onosproject.codec.impl.MockCodecContext;
38import org.onosproject.core.Application;
39import org.onosproject.core.ApplicationId;
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090040import org.onosproject.core.ApplicationRole;
Jian Lie1c1c8d2016-05-09 16:24:40 -070041import org.onosproject.core.CoreService;
Ray Milkeyf195b022015-02-03 15:13:11 -080042import org.onosproject.core.DefaultApplication;
43import org.onosproject.core.DefaultApplicationId;
44import org.onosproject.core.Version;
45
Jian Li847242b2016-05-11 18:58:53 -070046import javax.ws.rs.NotFoundException;
Jian Li9d616492016-03-09 10:52:49 -080047import javax.ws.rs.client.Entity;
48import javax.ws.rs.client.WebTarget;
49import javax.ws.rs.core.MediaType;
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080050import java.io.InputStream;
51import java.net.URI;
52import java.util.Optional;
Ray Milkeyf195b022015-02-03 15:13:11 -080053
Jian Li9d616492016-03-09 10:52:49 -080054import static org.easymock.EasyMock.createMock;
55import static org.easymock.EasyMock.expect;
56import static org.easymock.EasyMock.expectLastCall;
57import static org.easymock.EasyMock.isA;
58import static org.easymock.EasyMock.replay;
59import static org.easymock.EasyMock.verify;
Ray Milkeyf195b022015-02-03 15:13:11 -080060import static org.hamcrest.MatcherAssert.assertThat;
Yuta HIGUCHI293ede02015-02-05 00:08:41 -080061import static org.hamcrest.Matchers.containsString;
62import static org.hamcrest.Matchers.hasSize;
63import static org.hamcrest.Matchers.is;
64import static org.hamcrest.Matchers.notNullValue;
Ray Milkeyf195b022015-02-03 15:13:11 -080065
66/**
67 * Unit tests for applications REST APIs.
68 */
69
70public class ApplicationsResourceTest extends ResourceTest {
71
Jian Lie1c1c8d2016-05-09 16:24:40 -070072 private static class MockCodecContextWithAppService extends MockCodecContext {
73 private ApplicationAdminService appService;
Ray Milkeyf195b022015-02-03 15:13:11 -080074
Jian Lie1c1c8d2016-05-09 16:24:40 -070075 MockCodecContextWithAppService(ApplicationAdminService appService) {
76 this.appService = appService;
Ray Milkeyf195b022015-02-03 15:13:11 -080077 }
78
79 @Override
80 @SuppressWarnings("unchecked")
Ray Milkey3078fc02015-05-06 16:14:14 -070081 public <T> T getService(Class<T> serviceClass) {
Jian Lie1c1c8d2016-05-09 16:24:40 -070082 return (T) appService;
Ray Milkeyf195b022015-02-03 15:13:11 -080083 }
84 }
85
Jian Lie1c1c8d2016-05-09 16:24:40 -070086 private static class MockCodecContextWithCoreService extends MockCodecContext {
87 private CoreService coreService;
88
89 MockCodecContextWithCoreService(CoreService coreService) {
90 this.coreService = coreService;
91 }
92
93 @Override
94 @SuppressWarnings("unchecked")
95 public <T> T getService(Class<T> serviceClass) {
96 return (T) coreService;
97 }
98 }
99
100 private ApplicationAdminService appService;
101 private CoreService coreService;
Ray Milkeyf195b022015-02-03 15:13:11 -0800102 private ApplicationId id1 = new DefaultApplicationId(1, "app1");
103 private ApplicationId id2 = new DefaultApplicationId(2, "app2");
104 private ApplicationId id3 = new DefaultApplicationId(3, "app3");
105 private ApplicationId id4 = new DefaultApplicationId(4, "app4");
106
107 private static final URI FURL = URI.create("mvn:org.foo-features/1.2a/xml/features");
108 private static final Version VER = Version.version(1, 2, "a", null);
109
Ray Milkey47c95412017-09-15 10:40:48 -0700110 private DefaultApplication.Builder baseBuilder = DefaultApplication.builder()
111 .withVersion(VER)
112 .withIcon(new byte[0])
113 .withRole(ApplicationRole.ADMIN)
114 .withPermissions(ImmutableSet.of())
115 .withFeaturesRepo(Optional.of(FURL))
116 .withFeatures(ImmutableList.of("My Feature"))
117 .withRequiredApps(ImmutableList.of());
118
Ray Milkeyf195b022015-02-03 15:13:11 -0800119 private Application app1 =
Ray Milkey47c95412017-09-15 10:40:48 -0700120 DefaultApplication.builder(baseBuilder)
121 .withAppId(id1)
122 .withTitle("title1")
123 .withDescription("desc1")
124 .withOrigin("origin1")
125 .withCategory("category1")
126 .withUrl("url1")
127 .withReadme("readme1")
128 .build();
Ray Milkeyf195b022015-02-03 15:13:11 -0800129 private Application app2 =
Ray Milkey47c95412017-09-15 10:40:48 -0700130 DefaultApplication.builder(baseBuilder)
131 .withAppId(id2)
132 .withTitle("title2")
133 .withDescription("desc2")
134 .withOrigin("origin2")
135 .withCategory("category2")
136 .withUrl("url2")
137 .withReadme("readme2")
138 .build();
Ray Milkeyf195b022015-02-03 15:13:11 -0800139 private Application app3 =
Ray Milkey47c95412017-09-15 10:40:48 -0700140 DefaultApplication.builder(baseBuilder)
141 .withAppId(id3)
142 .withTitle("title3")
143 .withDescription("desc3")
144 .withOrigin("origin3")
145 .withCategory("category3")
146 .withUrl("url3")
147 .withReadme("readme3")
148 .build();
Ray Milkeyf195b022015-02-03 15:13:11 -0800149 private Application app4 =
Ray Milkey47c95412017-09-15 10:40:48 -0700150 DefaultApplication.builder(baseBuilder)
151 .withAppId(id4)
152 .withTitle("title4")
153 .withDescription("desc4")
154 .withOrigin("origin4")
155 .withCategory("category4")
156 .withUrl("url4")
157 .withReadme("readme4")
158 .build();
Ray Milkeyf195b022015-02-03 15:13:11 -0800159
160 /**
Ray Milkeyed0b1662015-02-05 09:34:29 -0800161 * Hamcrest matcher to check that an application representation in JSON matches
Ray Milkeyf195b022015-02-03 15:13:11 -0800162 * the actual device.
163 */
164 private static class AppJsonMatcher extends TypeSafeMatcher<JsonObject> {
165 private final Application app;
166 private String reason = "";
167
168 public AppJsonMatcher(Application appValue) {
169 app = appValue;
170 }
171
172 @Override
173 public boolean matchesSafely(JsonObject jsonApp) {
174 // check id
175 short jsonId = (short) jsonApp.get("id").asInt();
176 if (jsonId != app.id().id()) {
177 reason = "id " + app.id().id();
178 return false;
179 }
180
181 // check name
182 String jsonName = jsonApp.get("name").asString();
183 if (!jsonName.equals(app.id().name())) {
184 reason = "name " + app.id().name();
185 return false;
186 }
187
188 // check origin
189 String jsonOrigin = jsonApp.get("origin").asString();
190 if (!jsonOrigin.equals(app.origin())) {
191 reason = "manufacturer " + app.origin();
192 return false;
193 }
194
195 return true;
196 }
197
198 @Override
199 public void describeTo(Description description) {
200 description.appendText(reason);
201 }
202 }
203
204 /**
Jian Lie1c1c8d2016-05-09 16:24:40 -0700205 * Hamcrest matcher to check that an application id representation in JSON.
206 */
207 private static final class AppIdJsonMatcher extends TypeSafeMatcher<JsonObject> {
208 private final ApplicationId appId;
209 private String reason = "";
210
211 private AppIdJsonMatcher(ApplicationId appId) {
212 this.appId = appId;
213 }
214
215 @Override
216 protected boolean matchesSafely(JsonObject jsonAppId) {
217 // check id
218 short jsonId = (short) jsonAppId.get("id").asInt();
219 if (jsonId != appId.id()) {
220 reason = "id " + appId.id();
221 return false;
222 }
223
224 // check name
225 String jsonName = jsonAppId.get("name").asString();
226 if (!jsonName.equals(appId.name())) {
227 reason = "name " + appId.name();
228 return false;
229 }
230
231 return true;
232 }
233
234 @Override
235 public void describeTo(Description description) {
236 description.appendText(reason);
237 }
238 }
239
240 /**
Ray Milkeyed0b1662015-02-05 09:34:29 -0800241 * Factory to allocate an application matcher.
Ray Milkeyf195b022015-02-03 15:13:11 -0800242 *
243 * @param app application object we are looking for
244 * @return matcher
245 */
246 private static AppJsonMatcher matchesApp(Application app) {
247 return new AppJsonMatcher(app);
248 }
249
Ray Milkeyed0b1662015-02-05 09:34:29 -0800250 /**
Jian Lie1c1c8d2016-05-09 16:24:40 -0700251 * Factory to allocate an application Id matcher.
252 *
253 * @param appId application Id object we are looking for
254 * @return matcher
255 */
256 private static AppIdJsonMatcher matchesAppId(ApplicationId appId) {
257 return new AppIdJsonMatcher(appId);
258 }
259
260 /**
Ray Milkeyed0b1662015-02-05 09:34:29 -0800261 * Initializes test mocks and environment.
262 */
Ray Milkeyf195b022015-02-03 15:13:11 -0800263 @Before
Ray Milkeyed0b1662015-02-05 09:34:29 -0800264 public void setUpMocks() {
Jian Lie1c1c8d2016-05-09 16:24:40 -0700265 appService = createMock(ApplicationAdminService.class);
266 coreService = createMock(CoreService.class);
Ray Milkeyf195b022015-02-03 15:13:11 -0800267
Jian Lie1c1c8d2016-05-09 16:24:40 -0700268 expect(appService.getId("one"))
Ray Milkeyf195b022015-02-03 15:13:11 -0800269 .andReturn(id1)
270 .anyTimes();
Jian Lie1c1c8d2016-05-09 16:24:40 -0700271 expect(appService.getId("two"))
Ray Milkeyf195b022015-02-03 15:13:11 -0800272 .andReturn(id2)
273 .anyTimes();
Jian Lie1c1c8d2016-05-09 16:24:40 -0700274 expect(appService.getId("three"))
Ray Milkeyf195b022015-02-03 15:13:11 -0800275 .andReturn(id3)
276 .anyTimes();
Jian Lie1c1c8d2016-05-09 16:24:40 -0700277 expect(appService.getId("four"))
Ray Milkeyf195b022015-02-03 15:13:11 -0800278 .andReturn(id4)
279 .anyTimes();
280
Jian Lie1c1c8d2016-05-09 16:24:40 -0700281 expect(appService.getApplication(id3))
Ray Milkeyf195b022015-02-03 15:13:11 -0800282 .andReturn(app3)
283 .anyTimes();
Jian Lie1c1c8d2016-05-09 16:24:40 -0700284 expect(appService.getState(isA(ApplicationId.class)))
Ray Milkeyf195b022015-02-03 15:13:11 -0800285 .andReturn(ApplicationState.ACTIVE)
286 .anyTimes();
287
288 // Register the services needed for the test
289 CodecManager codecService = new CodecManager();
290 codecService.activate();
291 ServiceDirectory testDirectory =
292 new TestServiceDirectory()
Jian Lie1c1c8d2016-05-09 16:24:40 -0700293 .add(ApplicationAdminService.class, appService)
294 .add(ApplicationService.class, appService)
295 .add(CoreService.class, coreService)
Ray Milkeyf195b022015-02-03 15:13:11 -0800296 .add(CodecService.class, codecService);
297
298 BaseResource.setServiceDirectory(testDirectory);
299 }
300
Ray Milkeyed0b1662015-02-05 09:34:29 -0800301 /**
Ray Milkeyf195b022015-02-03 15:13:11 -0800302 * Tests a GET of all applications when no applications are present.
303 */
304 @Test
305 public void getAllApplicationsEmpty() {
Jian Lie1c1c8d2016-05-09 16:24:40 -0700306 expect(appService.getApplications())
Ray Milkeyf195b022015-02-03 15:13:11 -0800307 .andReturn(ImmutableSet.of());
Jian Lie1c1c8d2016-05-09 16:24:40 -0700308 replay(appService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800309
Jian Li9d616492016-03-09 10:52:49 -0800310 WebTarget wt = target();
311 String response = wt.path("applications").request().get(String.class);
Ray Milkeyf195b022015-02-03 15:13:11 -0800312 assertThat(response, is("{\"applications\":[]}"));
Jian Lie1c1c8d2016-05-09 16:24:40 -0700313
314 verify(appService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800315 }
316
317 /**
318 * Tests a GET of all applications with data.
319 */
320 @Test
321 public void getAllApplicationsPopulated() {
Jian Lie1c1c8d2016-05-09 16:24:40 -0700322 expect(appService.getApplications())
Ray Milkeyf195b022015-02-03 15:13:11 -0800323 .andReturn(ImmutableSet.of(app1, app2, app3, app4));
Jian Lie1c1c8d2016-05-09 16:24:40 -0700324 replay(appService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800325
Jian Li9d616492016-03-09 10:52:49 -0800326 WebTarget wt = target();
327 String response = wt.path("applications").request().get(String.class);
Ray Milkeyf195b022015-02-03 15:13:11 -0800328 assertThat(response, containsString("{\"applications\":["));
329
Jian Li80cfe452016-01-14 16:04:58 -0800330 JsonObject result = Json.parse(response).asObject();
Ray Milkeyf195b022015-02-03 15:13:11 -0800331 assertThat(result, notNullValue());
332
333 assertThat(result.names(), hasSize(1));
334 assertThat(result.names().get(0), is("applications"));
335
336 JsonArray jsonApps = result.get("applications").asArray();
337 assertThat(jsonApps, notNullValue());
338 assertThat(jsonApps.size(), is(4));
339
340 assertThat(jsonApps.get(0).asObject(), matchesApp(app1));
341 assertThat(jsonApps.get(1).asObject(), matchesApp(app2));
342 assertThat(jsonApps.get(2).asObject(), matchesApp(app3));
343 assertThat(jsonApps.get(3).asObject(), matchesApp(app4));
Jian Lie1c1c8d2016-05-09 16:24:40 -0700344
345 verify(appService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800346 }
347
348 /**
349 * Tests a GET of a single application.
350 */
351 @Test
352 public void getSingleApplication() {
Jian Lie1c1c8d2016-05-09 16:24:40 -0700353 replay(appService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800354
Jian Li9d616492016-03-09 10:52:49 -0800355 WebTarget wt = target();
356 String response = wt.path("applications/three").request().get(String.class);
Ray Milkeyf195b022015-02-03 15:13:11 -0800357
Jian Li80cfe452016-01-14 16:04:58 -0800358 JsonObject result = Json.parse(response).asObject();
Ray Milkeyf195b022015-02-03 15:13:11 -0800359 assertThat(result, notNullValue());
360
361 assertThat(result, matchesApp(app3));
Jian Lie1c1c8d2016-05-09 16:24:40 -0700362
363 verify(appService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800364 }
365
366 /**
367 * Tests a DELETE of a single application - this should
368 * attempt to uninstall it.
369 */
370 @Test
371 public void deleteApplication() {
Jian Lie1c1c8d2016-05-09 16:24:40 -0700372 appService.uninstall(id3);
Ray Milkeyf195b022015-02-03 15:13:11 -0800373 expectLastCall();
374
Jian Lie1c1c8d2016-05-09 16:24:40 -0700375 replay(appService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800376
Jian Li9d616492016-03-09 10:52:49 -0800377 WebTarget wt = target();
378 wt.path("applications/three").request().delete();
Jian Lie1c1c8d2016-05-09 16:24:40 -0700379
380 verify(appService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800381 }
382
383 /**
384 * Tests a DELETE of a single active application - this should
385 * attempt to uninstall it.
386 */
387 @Test
388 public void deleteActiveApplication() {
Jian Lie1c1c8d2016-05-09 16:24:40 -0700389 appService.deactivate(id3);
Ray Milkeyf195b022015-02-03 15:13:11 -0800390 expectLastCall();
391
Jian Lie1c1c8d2016-05-09 16:24:40 -0700392 replay(appService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800393
Jian Li9d616492016-03-09 10:52:49 -0800394 WebTarget wt = target();
395 wt.path("applications/three/active").request().delete();
Jian Lie1c1c8d2016-05-09 16:24:40 -0700396
397 verify(appService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800398 }
399
400 /**
401 * Tests a POST operation to the "active" URL. This should attempt to
402 * activate the application.
403 */
404 @Test
405 public void postActiveApplication() {
Jian Lie1c1c8d2016-05-09 16:24:40 -0700406 appService.activate(id3);
Ray Milkeyf195b022015-02-03 15:13:11 -0800407 expectLastCall();
408
Jian Lie1c1c8d2016-05-09 16:24:40 -0700409 replay(appService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800410
Jian Li9d616492016-03-09 10:52:49 -0800411 WebTarget wt = target();
412 wt.path("applications/three/active").request().post(null);
Jian Lie1c1c8d2016-05-09 16:24:40 -0700413
414 verify(appService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800415 }
416
417 /**
418 * Tests a POST operation. This should attempt to
419 * install the application.
420 */
421 @Test
422 public void postApplication() {
Jian Lie1c1c8d2016-05-09 16:24:40 -0700423 expect(appService.install(isA(InputStream.class)))
Ray Milkeyf195b022015-02-03 15:13:11 -0800424 .andReturn(app4)
425 .once();
426
Jian Lie1c1c8d2016-05-09 16:24:40 -0700427 replay(appService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800428
429 ApplicationCodec codec = new ApplicationCodec();
430 String app4Json = codec.encode(app4,
Jian Lie1c1c8d2016-05-09 16:24:40 -0700431 new MockCodecContextWithAppService(appService))
Ray Milkeyf195b022015-02-03 15:13:11 -0800432 .asText();
433
Jian Li9d616492016-03-09 10:52:49 -0800434 WebTarget wt = target();
435 String response = wt.path("applications").request().post(
436 Entity.entity(app4Json, MediaType.APPLICATION_OCTET_STREAM), String.class);
Ray Milkeyf195b022015-02-03 15:13:11 -0800437
Jian Li80cfe452016-01-14 16:04:58 -0800438 JsonObject result = Json.parse(response).asObject();
Ray Milkeyf195b022015-02-03 15:13:11 -0800439 assertThat(result, notNullValue());
440
441 assertThat(result, matchesApp(app4));
Jian Lie1c1c8d2016-05-09 16:24:40 -0700442
443 verify(appService);
444 }
445
446 /**
447 * Tests a POST operation. This should attempt to register an on/off platform
448 * application ID.
449 */
450 @Test
451 public void postRegisterAppId() {
452 expect(coreService.registerApplication("app1")).andReturn(id1).anyTimes();
453 replay(coreService);
454
455 WebTarget wt = target();
456 wt.path("applications/app1/register").request().post(null);
457
458 verify(coreService);
459 }
460
461 /**
462 * Tests a GET of all application Ids when no applications are present.
463 */
464 @Test
465 public void getAllApplicationIdsEmpty() {
466 expect(coreService.getAppIds()).andReturn(ImmutableSet.of());
467 replay(coreService);
468
469 WebTarget wt = target();
470 String response = wt.path("applications/ids").request().get(String.class);
471 assertThat(response, is("{\"applicationIds\":[]}"));
472
473 verify(coreService);
474 }
475
476 /**
477 * Tests a GET of all application Ids.
478 */
479 @Test
480 public void getAllApplicationIdsPopulated() {
481 expect(coreService.getAppIds())
482 .andReturn(ImmutableSet.of(id1, id2, id3, id4));
483 replay(coreService);
484
485 WebTarget wt = target();
486 String response = wt.path("applications/ids").request().get(String.class);
487
488 assertThat(response, containsString("{\"applicationIds\":["));
489
490 JsonObject result = Json.parse(response).asObject();
491 assertThat(result, notNullValue());
492
493 assertThat(result.names(), hasSize(1));
494 assertThat(result.names().get(0), is("applicationIds"));
495
496 JsonArray jsonApps = result.get("applicationIds").asArray();
497 assertThat(jsonApps, notNullValue());
498 assertThat(jsonApps.size(), is(4));
499
500 assertThat(jsonApps.get(0).asObject(), matchesAppId(id1));
501 assertThat(jsonApps.get(1).asObject(), matchesAppId(id2));
502 assertThat(jsonApps.get(2).asObject(), matchesAppId(id3));
503 assertThat(jsonApps.get(3).asObject(), matchesAppId(id4));
504
505 verify(coreService);
506 }
507
508 /**
509 * Tests a GET of an applicationId entry with the given numeric id.
510 */
511 @Test
512 public void getAppIdByShortId() {
513 expect(coreService.getAppId((short) 1)).andReturn(id1);
514 replay(coreService);
515
516 WebTarget wt = target();
Jian Li847242b2016-05-11 18:58:53 -0700517 String response = wt.path("applications/ids/entry")
518 .queryParam("id", 1).request().get(String.class);
Jian Lie1c1c8d2016-05-09 16:24:40 -0700519
520 JsonObject result = Json.parse(response).asObject();
521 assertThat(result, notNullValue());
522
523 assertThat(result, matchesAppId(id1));
524
525 verify(coreService);
526 }
527
528 /**
529 * Tests a GET of an applicationId entry with the given application name.
530 */
531 @Test
532 public void getAppIdByName() {
533 expect(coreService.getAppId("app2")).andReturn(id2);
534 replay(coreService);
535
536 WebTarget wt = target();
Jian Li847242b2016-05-11 18:58:53 -0700537 String response = wt.path("applications/ids/entry")
Jian Lie1c1c8d2016-05-09 16:24:40 -0700538 .queryParam("name", "app2").request().get(String.class);
539
540 JsonObject result = Json.parse(response).asObject();
541 assertThat(result, notNullValue());
542
543 assertThat(result, matchesAppId(id2));
544
545 verify(coreService);
Ray Milkeyf195b022015-02-03 15:13:11 -0800546 }
Jian Li847242b2016-05-11 18:58:53 -0700547
548 /**
549 * Tests a GET of an applicationId without specifying any parameters.
550 */
551 @Test
552 public void getAppWithNoParam() {
553 WebTarget wt = target();
554
555 try {
556 wt.path("applications/ids/entry").request().get();
557 } catch (NotFoundException ex) {
558 Assert.assertThat(ex.getMessage(),
559 containsString("HTTP 404 Not Found"));
560 }
561 }
Ray Milkeyf195b022015-02-03 15:13:11 -0800562}