@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 testRouterDeleteWithBoundExteriorPort() throws Exception {
      // Add a router
      DtoRouter resRouter = topology.getRouter("router1");
      // Add an exterior port.
      DtoRouterPort port = new DtoRouterPort();
      port.setNetworkAddress("10.0.0.0");
      port.setNetworkLength(24);
      port.setPortAddress("10.0.0.1");
      DtoRouterPort resPort =
          dtoResource.postAndVerifyCreated(
              resRouter.getPorts(), APPLICATION_PORT_V2_JSON(), port, DtoRouterPort.class);

      // Get the host DTO.
      DtoHost[] hosts =
          dtoResource.getAndVerifyOk(
              topology.getApplication().getHosts(),
              APPLICATION_HOST_COLLECTION_JSON_V3(),
              DtoHost[].class);
      Assert.assertEquals(1, hosts.length);
      DtoHost resHost = hosts[0];
      bindHostToTunnelZone(resHost.getId());

      // Bind the exterior port to an interface on the host.
      DtoHostInterfacePort hostBinding = new DtoHostInterfacePort();
      hostBinding.setHostId(resHost.getId());
      hostBinding.setInterfaceName("eth0");
      hostBinding.setPortId(resPort.getId());
      dtoResource.postAndVerifyCreated(
          resHost.getPorts(),
          APPLICATION_HOST_INTERFACE_PORT_JSON(),
          hostBinding,
          DtoHostInterfacePort.class);
      dtoResource.deleteAndVerifyNoContent(resRouter.getUri(), APPLICATION_ROUTER_JSON_V3());
    }
    @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);
    }
示例#4
0
    @Test
    public void testCrud() throws Exception {

      DtoApplication app = topology.getApplication();
      URI tunnelZonesUri = app.getTunnelZones();

      // Get tunnel zones and verify there is none
      DtoTunnelZone tunnelZone = new DtoTunnelZone();
      tunnelZone.setName("tz1-name");
      tunnelZone =
          dtoResource.postAndVerifyCreated(
              tunnelZonesUri, APPLICATION_TUNNEL_ZONE_JSON(), tunnelZone, DtoTunnelZone.class);
      Assert.assertNotNull(tunnelZone.getId());
      Assert.assertEquals("tz1-name", tunnelZone.getName());

      // Do not allow duplicates
      DtoTunnelZone tunnelZone2 = new DtoTunnelZone();
      tunnelZone2.setName("tz1-name");
      DtoError error =
          dtoResource.postAndVerifyError(
              tunnelZonesUri, APPLICATION_TUNNEL_ZONE_JSON(), tunnelZone2, CONFLICT);
      assertErrorMatches(error, UNIQUE_TUNNEL_ZONE_NAME_TYPE);

      // There should only be one
      DtoTunnelZone[] tunnelZones =
          dtoResource.getAndVerifyOk(
              tunnelZonesUri, APPLICATION_TUNNEL_ZONE_COLLECTION_JSON(), DtoTunnelZone[].class);
      Assert.assertEquals(1, tunnelZones.length);

      // Update tunnel zone name
      tunnelZone.setName("tz1-name-updated");
      tunnelZone =
          dtoResource.putAndVerifyNoContent(
              tunnelZone.getUri(), APPLICATION_TUNNEL_ZONE_JSON(), tunnelZone, DtoTunnelZone.class);
      Assert.assertEquals("tz1-name-updated", tunnelZone.getName());

      // List and make sure that there is one
      tunnelZones =
          dtoResource.getAndVerifyOk(
              tunnelZonesUri, APPLICATION_TUNNEL_ZONE_COLLECTION_JSON(), DtoTunnelZone[].class);
      Assert.assertEquals(1, tunnelZones.length);

      // Get the tunnel zone building the URI by hand.
      DtoTunnelZone tZone =
          dtoResource.getAndVerifyOk(
              UriBuilder.fromUri(tunnelZonesUri).path(tunnelZone.getId().toString()).build(),
              APPLICATION_TUNNEL_ZONE_JSON(),
              DtoTunnelZone.class);
      Assert.assertEquals(tunnelZone.getType(), tZone.getType());
      Assert.assertEquals(tunnelZone.getName(), tZone.getName());

      // Getting a non-existent zone returns a 404.
      dtoResource.getAndVerifyNotFound(
          UriBuilder.fromUri(tunnelZonesUri).path(UUID.randomUUID().toString()).build(),
          APPLICATION_TUNNEL_ZONE_JSON());

      // Delete it
      dtoResource.deleteAndVerifyNoContent(tunnelZone.getUri(), APPLICATION_TUNNEL_ZONE_JSON());

      // list and make sure it's gone
      tunnelZones =
          dtoResource.getAndVerifyOk(
              tunnelZonesUri, APPLICATION_TUNNEL_ZONE_COLLECTION_JSON(), DtoTunnelZone[].class);
      Assert.assertEquals(0, tunnelZones.length);
    }