Remove duplicated removeVirtualLink and corresponding unit test
Change-Id: I9279bad857a54e47ba7ec72a53d65fede0ad132b
Showing
2 changed files
with
35 additions
and
93 deletions
... | @@ -41,7 +41,6 @@ import javax.ws.rs.Consumes; | ... | @@ -41,7 +41,6 @@ import javax.ws.rs.Consumes; |
41 | import javax.ws.rs.DELETE; | 41 | import javax.ws.rs.DELETE; |
42 | import javax.ws.rs.GET; | 42 | import javax.ws.rs.GET; |
43 | import javax.ws.rs.POST; | 43 | import javax.ws.rs.POST; |
44 | -import javax.ws.rs.PUT; | ||
45 | import javax.ws.rs.Path; | 44 | import javax.ws.rs.Path; |
46 | import javax.ws.rs.PathParam; | 45 | import javax.ws.rs.PathParam; |
47 | import javax.ws.rs.Produces; | 46 | import javax.ws.rs.Produces; |
... | @@ -392,38 +391,6 @@ public class VirtualNetworkWebResource extends AbstractWebResource { | ... | @@ -392,38 +391,6 @@ public class VirtualNetworkWebResource extends AbstractWebResource { |
392 | } | 391 | } |
393 | 392 | ||
394 | /** | 393 | /** |
395 | - * Removes the virtual network link from the JSON input stream. | ||
396 | - * | ||
397 | - * @param networkId network identifier | ||
398 | - * @param stream deviceIds JSON stream | ||
399 | - * @return 200 OK, 404 not found | ||
400 | - * @onos.rsModel VirtualLink | ||
401 | - */ | ||
402 | - | ||
403 | - @PUT | ||
404 | - @Path("{networkId}/links/remove") | ||
405 | - @Consumes(MediaType.APPLICATION_JSON) | ||
406 | - @Produces(MediaType.APPLICATION_JSON) | ||
407 | - public Response removeVirtualLink2(@PathParam("networkId") long networkId, | ||
408 | - InputStream stream) { | ||
409 | - try { | ||
410 | - ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); | ||
411 | - JsonNode specifiedNetworkId = jsonTree.get("networkId"); | ||
412 | - if (specifiedNetworkId != null && | ||
413 | - specifiedNetworkId.asLong() != (networkId)) { | ||
414 | - throw new IllegalArgumentException(INVALID_FIELD + "networkId"); | ||
415 | - } | ||
416 | - final VirtualLink vlinkReq = codec(VirtualLink.class).decode(jsonTree, this); | ||
417 | - vnetAdminService.removeVirtualLink(vlinkReq.networkId(), | ||
418 | - vlinkReq.src(), vlinkReq.dst()); | ||
419 | - } catch (IOException e) { | ||
420 | - throw new IllegalArgumentException(e); | ||
421 | - } | ||
422 | - | ||
423 | - return Response.ok().build(); | ||
424 | - } | ||
425 | - | ||
426 | - /** | ||
427 | * Get the tenant identifier from the JSON stream. | 394 | * Get the tenant identifier from the JSON stream. |
428 | * | 395 | * |
429 | * @param stream TenantId JSON stream | 396 | * @param stream TenantId JSON stream | ... | ... |
... | @@ -70,9 +70,19 @@ import java.util.function.BiFunction; | ... | @@ -70,9 +70,19 @@ import java.util.function.BiFunction; |
70 | import java.util.function.BiPredicate; | 70 | import java.util.function.BiPredicate; |
71 | import java.util.function.Function; | 71 | import java.util.function.Function; |
72 | 72 | ||
73 | -import static org.easymock.EasyMock.*; | 73 | +import static org.easymock.EasyMock.anyObject; |
74 | -import static org.hamcrest.Matchers.*; | 74 | +import static org.easymock.EasyMock.createMock; |
75 | -import static org.junit.Assert.*; | 75 | +import static org.easymock.EasyMock.expect; |
76 | +import static org.easymock.EasyMock.expectLastCall; | ||
77 | +import static org.easymock.EasyMock.replay; | ||
78 | +import static org.easymock.EasyMock.verify; | ||
79 | +import static org.hamcrest.Matchers.containsString; | ||
80 | +import static org.hamcrest.Matchers.hasSize; | ||
81 | +import static org.hamcrest.Matchers.is; | ||
82 | +import static org.hamcrest.Matchers.notNullValue; | ||
83 | +import static org.junit.Assert.assertEquals; | ||
84 | +import static org.junit.Assert.assertThat; | ||
85 | +import static org.junit.Assert.fail; | ||
76 | import static org.onosproject.net.PortNumber.portNumber; | 86 | import static org.onosproject.net.PortNumber.portNumber; |
77 | 87 | ||
78 | /** | 88 | /** |
... | @@ -281,14 +291,11 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { | ... | @@ -281,14 +291,11 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { |
281 | public VnetJsonArrayMatcher(VirtualNetwork vnetIn) { | 291 | public VnetJsonArrayMatcher(VirtualNetwork vnetIn) { |
282 | super(vnetIn, | 292 | super(vnetIn, |
283 | vnet -> "Virtual network " + vnet.id().toString(), | 293 | vnet -> "Virtual network " + vnet.id().toString(), |
284 | - (vnet, jsonObject) -> { | 294 | + (vnet, jsonObject) -> jsonObject.get(ID).asString().equals(vnet.id().toString()), |
285 | - return jsonObject.get(ID).asString().equals(vnet.id().toString()); }, | ||
286 | ImmutableList.of(ID, TENANT_ID), | 295 | ImmutableList.of(ID, TENANT_ID), |
287 | - (vnet, s) -> { | 296 | + (vnet, s) -> s.equals(ID) ? vnet.id().toString() |
288 | - return s.equals(ID) ? vnet.id().toString() | 297 | + : s.equals(TENANT_ID) ? vnet.tenantId().toString() |
289 | - : s.equals(TENANT_ID) ? vnet.tenantId().toString() | 298 | + : null |
290 | - : null; | ||
291 | - } | ||
292 | ); | 299 | ); |
293 | } | 300 | } |
294 | } | 301 | } |
... | @@ -447,7 +454,7 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { | ... | @@ -447,7 +454,7 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { |
447 | 454 | ||
448 | WebTarget wt = target(); | 455 | WebTarget wt = target(); |
449 | try { | 456 | try { |
450 | - String response = wt.path("vnets") | 457 | + wt.path("vnets") |
451 | .request(MediaType.APPLICATION_JSON_TYPE) | 458 | .request(MediaType.APPLICATION_JSON_TYPE) |
452 | .post(Entity.json(null), String.class); | 459 | .post(Entity.json(null), String.class); |
453 | fail("POST of null virtual network did not throw an exception"); | 460 | fail("POST of null virtual network did not throw an exception"); |
... | @@ -564,15 +571,12 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { | ... | @@ -564,15 +571,12 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { |
564 | super(vdevIn, | 571 | super(vdevIn, |
565 | vdev -> "Virtual device " + vdev.networkId().toString() | 572 | vdev -> "Virtual device " + vdev.networkId().toString() |
566 | + " " + vdev.id().toString(), | 573 | + " " + vdev.id().toString(), |
567 | - (vdev, jsonObject) -> { | 574 | + (vdev, jsonObject) -> jsonObject.get(ID).asString().equals(vdev.networkId().toString()) |
568 | - return jsonObject.get(ID).asString().equals(vdev.networkId().toString()) | 575 | + && jsonObject.get(DEVICE_ID).asString().equals(vdev.id().toString()), |
569 | - && jsonObject.get(DEVICE_ID).asString().equals(vdev.id().toString()); }, | ||
570 | ImmutableList.of(ID, DEVICE_ID), | 576 | ImmutableList.of(ID, DEVICE_ID), |
571 | - (vdev, s) -> { | 577 | + (vdev, s) -> s.equals(ID) ? vdev.networkId().toString() |
572 | - return s.equals(ID) ? vdev.networkId().toString() | 578 | + : s.equals(DEVICE_ID) ? vdev.id().toString() |
573 | - : s.equals(DEVICE_ID) ? vdev.id().toString() | 579 | + : null |
574 | - : null; | ||
575 | - } | ||
576 | ); | 580 | ); |
577 | } | 581 | } |
578 | } | 582 | } |
... | @@ -623,7 +627,7 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { | ... | @@ -623,7 +627,7 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { |
623 | WebTarget wt = target(); | 627 | WebTarget wt = target(); |
624 | try { | 628 | try { |
625 | String reqLocation = "vnets/" + networkId.toString() + "/devices"; | 629 | String reqLocation = "vnets/" + networkId.toString() + "/devices"; |
626 | - String response = wt.path(reqLocation) | 630 | + wt.path(reqLocation) |
627 | .request(MediaType.APPLICATION_JSON_TYPE) | 631 | .request(MediaType.APPLICATION_JSON_TYPE) |
628 | .post(Entity.json(null), String.class); | 632 | .post(Entity.json(null), String.class); |
629 | fail("POST of null virtual device did not throw an exception"); | 633 | fail("POST of null virtual device did not throw an exception"); |
... | @@ -722,19 +726,16 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { | ... | @@ -722,19 +726,16 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { |
722 | super(vportIn, | 726 | super(vportIn, |
723 | vport -> "Virtual port " + vport.networkId().toString() + " " | 727 | vport -> "Virtual port " + vport.networkId().toString() + " " |
724 | + vport.element().id().toString() + " " + vport.number().toString(), | 728 | + vport.element().id().toString() + " " + vport.number().toString(), |
725 | - (vport, jsonObject) -> { | 729 | + (vport, jsonObject) -> jsonObject.get(ID).asString().equals(vport.networkId().toString()) |
726 | - return jsonObject.get(ID).asString().equals(vport.networkId().toString()) | 730 | + && jsonObject.get(PORT_NUM).asString().equals(vport.number().toString()) |
727 | - && jsonObject.get(PORT_NUM).asString().equals(vport.number().toString()) | 731 | + && jsonObject.get(DEVICE_ID).asString().equals(vport.element().id().toString()), |
728 | - && jsonObject.get(DEVICE_ID).asString().equals(vport.element().id().toString()); }, | ||
729 | ImmutableList.of(ID, DEVICE_ID, PORT_NUM, PHYS_DEVICE_ID, PHYS_PORT_NUM), | 732 | ImmutableList.of(ID, DEVICE_ID, PORT_NUM, PHYS_DEVICE_ID, PHYS_PORT_NUM), |
730 | - (vport, s) -> { | 733 | + (vport, s) -> s.equals(ID) ? vport.networkId().toString() |
731 | - return s.equals(ID) ? vport.networkId().toString() | 734 | + : s.equals(DEVICE_ID) ? vport.element().id().toString() |
732 | - : s.equals(DEVICE_ID) ? vport.element().id().toString() | 735 | + : s.equals(PORT_NUM) ? vport.number().toString() |
733 | - : s.equals(PORT_NUM) ? vport.number().toString() | 736 | + : s.equals(PHYS_DEVICE_ID) ? vport.realizedBy().element().id().toString() |
734 | - : s.equals(PHYS_DEVICE_ID) ? vport.realizedBy().element().id().toString() | 737 | + : s.equals(PHYS_PORT_NUM) ? vport.realizedBy().number().toString() |
735 | - : s.equals(PHYS_PORT_NUM) ? vport.realizedBy().number().toString() | 738 | + : null |
736 | - : null; | ||
737 | - } | ||
738 | ); | 739 | ); |
739 | } | 740 | } |
740 | } | 741 | } |
... | @@ -790,7 +791,7 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { | ... | @@ -790,7 +791,7 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { |
790 | try { | 791 | try { |
791 | String reqLocation = "vnets/" + networkId.toString() | 792 | String reqLocation = "vnets/" + networkId.toString() |
792 | + "/devices/" + deviceId.toString() + "/ports"; | 793 | + "/devices/" + deviceId.toString() + "/ports"; |
793 | - String response = wt.path(reqLocation) | 794 | + wt.path(reqLocation) |
794 | .request(MediaType.APPLICATION_JSON_TYPE) | 795 | .request(MediaType.APPLICATION_JSON_TYPE) |
795 | .post(Entity.json(null), String.class); | 796 | .post(Entity.json(null), String.class); |
796 | fail("POST of null virtual port did not throw an exception"); | 797 | fail("POST of null virtual port did not throw an exception"); |
... | @@ -1034,35 +1035,9 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { | ... | @@ -1034,35 +1035,9 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { |
1034 | InputStream jsonStream = VirtualNetworkWebResourceTest.class | 1035 | InputStream jsonStream = VirtualNetworkWebResourceTest.class |
1035 | .getResourceAsStream("post-virtual-link.json"); | 1036 | .getResourceAsStream("post-virtual-link.json"); |
1036 | String reqLocation = "vnets/" + networkId.toString() + "/links"; | 1037 | String reqLocation = "vnets/" + networkId.toString() + "/links"; |
1037 | - Response response = wt.path(reqLocation).request().accept(MediaType.APPLICATION_JSON_TYPE) | 1038 | + Response response = wt.path(reqLocation).request().method("DELETE", Entity.json(jsonStream)); |
1038 | - .method("DELETE", Entity.json(jsonStream)); | ||
1039 | -// Response response = wt.path(reqLocation).request().method("DELETE", Entity.json(jsonStream)); | ||
1040 | - | ||
1041 | -// assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK)); | ||
1042 | -// verify(mockVnetAdminService); | ||
1043 | - } | ||
1044 | - | ||
1045 | - /** | ||
1046 | - * Tests removing a virtual link with PUT request. | ||
1047 | - */ | ||
1048 | - @Test | ||
1049 | - public void testDeleteVirtualLink2() { | ||
1050 | - NetworkId networkId = networkId3; | ||
1051 | - mockVnetAdminService.removeVirtualLink(networkId, cp22, cp11); | ||
1052 | - expectLastCall(); | ||
1053 | - replay(mockVnetAdminService); | ||
1054 | - | ||
1055 | - WebTarget wt = target() | ||
1056 | - .property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true); | ||
1057 | - InputStream jsonStream = VirtualNetworkWebResourceTest.class | ||
1058 | - .getResourceAsStream("post-virtual-link.json"); | ||
1059 | - String reqLocation = "vnets/" + networkId.toString() + "/links/remove"; | ||
1060 | - Response response = wt.path(reqLocation).request().accept(MediaType.APPLICATION_JSON_TYPE) | ||
1061 | - .method("PUT", Entity.json(jsonStream)); | ||
1062 | 1039 | ||
1063 | assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK)); | 1040 | assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK)); |
1064 | verify(mockVnetAdminService); | 1041 | verify(mockVnetAdminService); |
1065 | } | 1042 | } |
1066 | - | ||
1067 | - // All Tests done | ||
1068 | } | 1043 | } | ... | ... |
-
Please register or login to post a comment