Varun Sharma

ONOS-4835 fix

Change-Id: Ic384b39e6cfd111b38c72ade01677831831ec3c0
......@@ -43,6 +43,7 @@ import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import org.onlab.util.HexString;
import static org.onlab.util.Tools.nullIsNotFound;
/**
......@@ -110,7 +111,12 @@ public class GroupsWebResource extends AbstractWebResource {
public Response getGroupByDeviceIdAndAppCookie(@PathParam("deviceId") String deviceId,
@PathParam("appCookie") String appCookie) {
final DeviceId deviceIdInstance = DeviceId.deviceId(deviceId);
final GroupKey appCookieInstance = new DefaultGroupKey(appCookie.getBytes());
if (!appCookie.startsWith("0x")) {
throw new IllegalArgumentException("APP_COOKIE must be a hex string starts with 0x");
}
final GroupKey appCookieInstance = new DefaultGroupKey(HexString.fromHexString(
appCookie.split("0x")[1], ""));
Group group = nullIsNotFound(groupService.getGroup(deviceIdInstance, appCookieInstance),
GROUP_NOT_FOUND);
......@@ -172,7 +178,12 @@ public class GroupsWebResource extends AbstractWebResource {
public void deleteGroupByDeviceIdAndAppCookie(@PathParam("deviceId") String deviceId,
@PathParam("appCookie") String appCookie) {
DeviceId deviceIdInstance = DeviceId.deviceId(deviceId);
GroupKey appCookieInstance = new DefaultGroupKey(appCookie.getBytes());
if (!appCookie.startsWith("0x")) {
throw new IllegalArgumentException("APP_COOKIE must be a hex string starts with 0x");
}
GroupKey appCookieInstance = new DefaultGroupKey(HexString.fromHexString(
appCookie.split("0x")[1], ""));
groupService.removeGroup(deviceIdInstance, appCookieInstance, null);
}
......
......@@ -67,6 +67,11 @@
"description": "types of the group",
"example": "ALL"
},
"deviceId": {
"type": "string",
"description": "device identifier",
"example": "of:0000000000000003"
},
"appId": {
"type": "string",
"description": "application identifier",
......
......@@ -3,7 +3,6 @@
"title": "group",
"required": [
"type",
"deviceId",
"appCookie",
"groupId",
"buckets"
......@@ -13,10 +12,6 @@
"type": "string",
"example": "ALL"
},
"deviceId": {
"type": "string",
"example": "of:0000000000000001"
},
"appCookie": {
"type": "string",
"description": "application cookie. Arbitrary length byte array represented in hex string",
......@@ -82,4 +77,4 @@
}
}
}
}
\ No newline at end of file
}
......
......@@ -94,14 +94,14 @@ public class GroupsResourceTest extends ResourceTest {
final Device device2 = new DefaultDevice(null, deviceId2, Device.Type.OTHER,
"", "", "", "", null);
final MockGroup group1 = new MockGroup(deviceId1, 1, "111", 1);
final MockGroup group2 = new MockGroup(deviceId1, 2, "222", 2);
final MockGroup group1 = new MockGroup(deviceId1, 1, "0x111", 1);
final MockGroup group2 = new MockGroup(deviceId1, 2, "0x222", 2);
final MockGroup group3 = new MockGroup(deviceId2, 3, "333", 3);
final MockGroup group4 = new MockGroup(deviceId2, 4, "444", 4);
final MockGroup group3 = new MockGroup(deviceId2, 3, "0x333", 3);
final MockGroup group4 = new MockGroup(deviceId2, 4, "0x444", 4);
final MockGroup group5 = new MockGroup(deviceId3, 5, "555", 5);
final MockGroup group6 = new MockGroup(deviceId3, 6, "666", 6);
final MockGroup group5 = new MockGroup(deviceId3, 5, "0x555", 5);
final MockGroup group6 = new MockGroup(deviceId3, 6, "0x666", 6);
public GroupsResourceTest() {
super(CoreWebApplication.class);
......@@ -460,7 +460,7 @@ public class GroupsResourceTest extends ResourceTest {
.andReturn(group5).anyTimes();
replay(mockGroupService);
final WebResource rs = resource();
final String response = rs.path("groups/" + deviceId3 + "/" + "111").get(String.class);
final String response = rs.path("groups/" + deviceId3 + "/" + "0x111").get(String.class);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
......@@ -481,7 +481,7 @@ public class GroupsResourceTest extends ResourceTest {
.andReturn(null).anyTimes();
replay(mockGroupService);
final WebResource rs = resource();
final ClientResponse response = rs.path("groups/" + deviceId3 + "/" + "222").get(ClientResponse.class);
final ClientResponse response = rs.path("groups/" + deviceId3 + "/" + "0x222").get(ClientResponse.class);
assertEquals(404, response.getStatus());
}
......@@ -517,7 +517,7 @@ public class GroupsResourceTest extends ResourceTest {
WebResource rs = resource();
String location = "/groups/1/111";
String location = "/groups/1/0x111";
ClientResponse deleteResponse = rs.path(location)
.type(MediaType.APPLICATION_JSON_TYPE)
......