[ONOS-4409] Merge getApp REST methods into one, revise unit test
Change-Id: I47e5dd1d795404d3ba2c73487858a3d389790ac9
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/ApplicationsWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/ApplicationsWebResource.java
index 5c63035..e7dad7e 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/ApplicationsWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/ApplicationsWebResource.java
@@ -166,34 +166,25 @@
}
/**
- * Gets application Id entry by short id.
+ * Gets applicationId entry by either id or name.
*
- * @param shortId numerical id of application
- * @return 200 OK; 404; 401
- * @onos.rsModel ApplicationId
- */
- @GET
- @Produces(MediaType.APPLICATION_JSON)
- @Path("ids/short")
- public Response getAppIdByShortId(@QueryParam("id") int shortId) {
- CoreService service = get(CoreService.class);
- ApplicationId appId = service.getAppId((short) shortId);
- return response(appId);
- }
-
- /**
- * Gets application Id entry by name.
- *
+ * @param id id of application
* @param name name of application
* @return 200 OK; 404; 401
* @onos.rsModel ApplicationId
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
- @Path("ids/name")
- public Response getAppIdByName(@QueryParam("name") String name) {
+ @Path("ids/entry")
+ public Response getAppIdByName(@QueryParam("id") Short id,
+ @QueryParam("name") String name) {
CoreService service = get(CoreService.class);
- ApplicationId appId = service.getAppId(name);
+ ApplicationId appId = null;
+ if (id != null) {
+ appId = service.getAppId(id);
+ } else if (name != null) {
+ appId = service.getAppId(name);
+ }
return response(appId);
}
diff --git a/web/api/src/test/java/org/onosproject/rest/resources/ApplicationsResourceTest.java b/web/api/src/test/java/org/onosproject/rest/resources/ApplicationsResourceTest.java
index e2a6bb1..f1796dc 100644
--- a/web/api/src/test/java/org/onosproject/rest/resources/ApplicationsResourceTest.java
+++ b/web/api/src/test/java/org/onosproject/rest/resources/ApplicationsResourceTest.java
@@ -22,6 +22,7 @@
import com.google.common.collect.ImmutableSet;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.onlab.osgi.ServiceDirectory;
@@ -42,6 +43,7 @@
import org.onosproject.core.DefaultApplicationId;
import org.onosproject.core.Version;
+import javax.ws.rs.NotFoundException;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
@@ -487,8 +489,8 @@
replay(coreService);
WebTarget wt = target();
- String response = wt.path("applications/ids/short")
- .queryParam("id", 1).request().get(String.class);
+ String response = wt.path("applications/ids/entry")
+ .queryParam("id", 1).request().get(String.class);
JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
@@ -507,7 +509,7 @@
replay(coreService);
WebTarget wt = target();
- String response = wt.path("applications/ids/name")
+ String response = wt.path("applications/ids/entry")
.queryParam("name", "app2").request().get(String.class);
JsonObject result = Json.parse(response).asObject();
@@ -517,4 +519,19 @@
verify(coreService);
}
+
+ /**
+ * Tests a GET of an applicationId without specifying any parameters.
+ */
+ @Test
+ public void getAppWithNoParam() {
+ WebTarget wt = target();
+
+ try {
+ wt.path("applications/ids/entry").request().get();
+ } catch (NotFoundException ex) {
+ Assert.assertThat(ex.getMessage(),
+ containsString("HTTP 404 Not Found"));
+ }
+ }
}