Committed by
Gerrit Code Review
[ONOS-4409] Merge getApp REST methods into one, revise unit test
Change-Id: I47e5dd1d795404d3ba2c73487858a3d389790ac9
Showing
2 changed files
with
30 additions
and
22 deletions
| ... | @@ -166,34 +166,25 @@ public class ApplicationsWebResource extends AbstractWebResource { | ... | @@ -166,34 +166,25 @@ public class ApplicationsWebResource extends AbstractWebResource { |
| 166 | } | 166 | } |
| 167 | 167 | ||
| 168 | /** | 168 | /** |
| 169 | - * Gets application Id entry by short id. | 169 | + * Gets applicationId entry by either id or name. |
| 170 | - * | ||
| 171 | - * @param shortId numerical id of application | ||
| 172 | - * @return 200 OK; 404; 401 | ||
| 173 | - * @onos.rsModel ApplicationId | ||
| 174 | - */ | ||
| 175 | - @GET | ||
| 176 | - @Produces(MediaType.APPLICATION_JSON) | ||
| 177 | - @Path("ids/short") | ||
| 178 | - public Response getAppIdByShortId(@QueryParam("id") int shortId) { | ||
| 179 | - CoreService service = get(CoreService.class); | ||
| 180 | - ApplicationId appId = service.getAppId((short) shortId); | ||
| 181 | - return response(appId); | ||
| 182 | - } | ||
| 183 | - | ||
| 184 | - /** | ||
| 185 | - * Gets application Id entry by name. | ||
| 186 | * | 170 | * |
| 171 | + * @param id id of application | ||
| 187 | * @param name name of application | 172 | * @param name name of application |
| 188 | * @return 200 OK; 404; 401 | 173 | * @return 200 OK; 404; 401 |
| 189 | * @onos.rsModel ApplicationId | 174 | * @onos.rsModel ApplicationId |
| 190 | */ | 175 | */ |
| 191 | @GET | 176 | @GET |
| 192 | @Produces(MediaType.APPLICATION_JSON) | 177 | @Produces(MediaType.APPLICATION_JSON) |
| 193 | - @Path("ids/name") | 178 | + @Path("ids/entry") |
| 194 | - public Response getAppIdByName(@QueryParam("name") String name) { | 179 | + public Response getAppIdByName(@QueryParam("id") Short id, |
| 180 | + @QueryParam("name") String name) { | ||
| 195 | CoreService service = get(CoreService.class); | 181 | CoreService service = get(CoreService.class); |
| 196 | - ApplicationId appId = service.getAppId(name); | 182 | + ApplicationId appId = null; |
| 183 | + if (id != null) { | ||
| 184 | + appId = service.getAppId(id); | ||
| 185 | + } else if (name != null) { | ||
| 186 | + appId = service.getAppId(name); | ||
| 187 | + } | ||
| 197 | return response(appId); | 188 | return response(appId); |
| 198 | } | 189 | } |
| 199 | 190 | ... | ... |
| ... | @@ -22,6 +22,7 @@ import com.google.common.collect.ImmutableList; | ... | @@ -22,6 +22,7 @@ import com.google.common.collect.ImmutableList; |
| 22 | import com.google.common.collect.ImmutableSet; | 22 | import com.google.common.collect.ImmutableSet; |
| 23 | import org.hamcrest.Description; | 23 | import org.hamcrest.Description; |
| 24 | import org.hamcrest.TypeSafeMatcher; | 24 | import org.hamcrest.TypeSafeMatcher; |
| 25 | +import org.junit.Assert; | ||
| 25 | import org.junit.Before; | 26 | import org.junit.Before; |
| 26 | import org.junit.Test; | 27 | import org.junit.Test; |
| 27 | import org.onlab.osgi.ServiceDirectory; | 28 | import org.onlab.osgi.ServiceDirectory; |
| ... | @@ -42,6 +43,7 @@ import org.onosproject.core.DefaultApplication; | ... | @@ -42,6 +43,7 @@ import org.onosproject.core.DefaultApplication; |
| 42 | import org.onosproject.core.DefaultApplicationId; | 43 | import org.onosproject.core.DefaultApplicationId; |
| 43 | import org.onosproject.core.Version; | 44 | import org.onosproject.core.Version; |
| 44 | 45 | ||
| 46 | +import javax.ws.rs.NotFoundException; | ||
| 45 | import javax.ws.rs.client.Entity; | 47 | import javax.ws.rs.client.Entity; |
| 46 | import javax.ws.rs.client.WebTarget; | 48 | import javax.ws.rs.client.WebTarget; |
| 47 | import javax.ws.rs.core.MediaType; | 49 | import javax.ws.rs.core.MediaType; |
| ... | @@ -487,7 +489,7 @@ public class ApplicationsResourceTest extends ResourceTest { | ... | @@ -487,7 +489,7 @@ public class ApplicationsResourceTest extends ResourceTest { |
| 487 | replay(coreService); | 489 | replay(coreService); |
| 488 | 490 | ||
| 489 | WebTarget wt = target(); | 491 | WebTarget wt = target(); |
| 490 | - String response = wt.path("applications/ids/short") | 492 | + String response = wt.path("applications/ids/entry") |
| 491 | .queryParam("id", 1).request().get(String.class); | 493 | .queryParam("id", 1).request().get(String.class); |
| 492 | 494 | ||
| 493 | JsonObject result = Json.parse(response).asObject(); | 495 | JsonObject result = Json.parse(response).asObject(); |
| ... | @@ -507,7 +509,7 @@ public class ApplicationsResourceTest extends ResourceTest { | ... | @@ -507,7 +509,7 @@ public class ApplicationsResourceTest extends ResourceTest { |
| 507 | replay(coreService); | 509 | replay(coreService); |
| 508 | 510 | ||
| 509 | WebTarget wt = target(); | 511 | WebTarget wt = target(); |
| 510 | - String response = wt.path("applications/ids/name") | 512 | + String response = wt.path("applications/ids/entry") |
| 511 | .queryParam("name", "app2").request().get(String.class); | 513 | .queryParam("name", "app2").request().get(String.class); |
| 512 | 514 | ||
| 513 | JsonObject result = Json.parse(response).asObject(); | 515 | JsonObject result = Json.parse(response).asObject(); |
| ... | @@ -517,4 +519,19 @@ public class ApplicationsResourceTest extends ResourceTest { | ... | @@ -517,4 +519,19 @@ public class ApplicationsResourceTest extends ResourceTest { |
| 517 | 519 | ||
| 518 | verify(coreService); | 520 | verify(coreService); |
| 519 | } | 521 | } |
| 522 | + | ||
| 523 | + /** | ||
| 524 | + * Tests a GET of an applicationId without specifying any parameters. | ||
| 525 | + */ | ||
| 526 | + @Test | ||
| 527 | + public void getAppWithNoParam() { | ||
| 528 | + WebTarget wt = target(); | ||
| 529 | + | ||
| 530 | + try { | ||
| 531 | + wt.path("applications/ids/entry").request().get(); | ||
| 532 | + } catch (NotFoundException ex) { | ||
| 533 | + Assert.assertThat(ex.getMessage(), | ||
| 534 | + containsString("HTTP 404 Not Found")); | ||
| 535 | + } | ||
| 536 | + } | ||
| 520 | } | 537 | } | ... | ... |
-
Please register or login to post a comment