@Test public void testCreateWhenAlreadyBound() { DtoHost host = hostTopology.getHost(host1Id); DtoBridgePort port1 = topology.getBridgePort("bridgePort1"); bindHostToTunnelZone(host1Id); // List mappings. There should be none. DtoHostInterfacePort[] maps = dtoResource.getAndVerifyOk( host.getPorts(), APPLICATION_HOST_INTERFACE_PORT_COLLECTION_JSON(), DtoHostInterfacePort[].class); Assert.assertEquals(0, maps.length); DtoHostInterfacePort mapping = new DtoHostInterfacePort(); mapping.setPortId(port1.getId()); mapping.setInterfaceName("eth0"); dtoResource.postAndVerifyCreated( host.getPorts(), APPLICATION_HOST_INTERFACE_PORT_JSON(), mapping, DtoHostInterfacePort.class); mapping = new DtoHostInterfacePort(); mapping.setPortId(port1.getId()); mapping.setInterfaceName("eth1"); dtoResource.postAndVerifyBadRequest( host.getPorts(), APPLICATION_HOST_INTERFACE_PORT_JSON(), mapping); }
@Test public void testCreateWhenHostIsNotInAnyTunnelZone() { DtoHost host = hostTopology.getHost(host1Id); DtoBridgePort port = topology.getBridgePort("bridgePort1"); // Map a tunnel zone to a host DtoHostInterfacePort mapping = new DtoHostInterfacePort(); mapping.setPortId(port.getId()); mapping.setInterfaceName("eth0"); DtoError error = dtoResource.postAndVerifyBadRequest( host.getPorts(), APPLICATION_HOST_INTERFACE_PORT_JSON(), mapping); assertErrorMatchesLiteral(error, getMessage(HOST_IS_NOT_IN_ANY_TUNNEL_ZONE, host1Id)); }
@Test public void testCrud() throws Exception { DtoHost host = hostTopology.getHost(host1Id); DtoBridgePort port1 = topology.getBridgePort("bridgePort1"); bindHostToTunnelZone(host1Id); // List mappings. There should be none. DtoHostInterfacePort[] maps = dtoResource.getAndVerifyOk( host.getPorts(), APPLICATION_HOST_INTERFACE_PORT_COLLECTION_JSON(), DtoHostInterfacePort[].class); Assert.assertEquals(0, maps.length); // Map a tunnel zone to a host DtoHostInterfacePort mapping1 = new DtoHostInterfacePort(); mapping1.setPortId(port1.getId()); mapping1.setInterfaceName("eth0"); mapping1 = dtoResource.postAndVerifyCreated( host.getPorts(), APPLICATION_HOST_INTERFACE_PORT_JSON(), mapping1, DtoHostInterfacePort.class); // List bridge mapping and verify that there is one maps = dtoResource.getAndVerifyOk( host.getPorts(), APPLICATION_HOST_INTERFACE_PORT_COLLECTION_JSON(), DtoHostInterfacePort[].class); Assert.assertEquals(1, maps.length); // Remove mapping dtoResource.deleteAndVerifyNoContent( mapping1.getUri(), APPLICATION_HOST_INTERFACE_PORT_JSON()); // List mapping and verify that there is none maps = dtoResource.getAndVerifyOk( host.getPorts(), APPLICATION_HOST_INTERFACE_PORT_COLLECTION_JSON(), DtoHostInterfacePort[].class); Assert.assertEquals(0, maps.length); }