Example #1
0
    /*
     * If there is a VTEP configured with a given tunnel zone, it should
     * not be possible to delete the tunnel zone.
     */
    @Test
    public void testDeleteFailsIfVTEPUsingTunnelZone() {
      DtoApplication app = topology.getApplication();
      URI tunnelZonesUri = app.getTunnelZones();
      DtoTunnelZone tunnelZone = new DtoTunnelZone();
      tunnelZone.setName("tz1");
      tunnelZone.setType(TunnelZoneType.VTEP);
      tunnelZone =
          dtoResource.postAndVerifyCreated(
              tunnelZonesUri,
              MidonetMediaTypes.APPLICATION_TUNNEL_ZONE_JSON(),
              tunnelZone,
              DtoTunnelZone.class);
      DtoVtep vtep = new DtoVtep();
      vtep.setManagementIp("192.168.1.2");
      vtep.setManagementPort(6632);
      vtep.setTunnelZoneId(tunnelZone.getId());
      dtoResource.postAndVerifyCreated(
          app.getVteps(), APPLICATION_VTEP_JSON_V2(), vtep, DtoVtep.class);

      // now try to delete the tunnel zone
      dtoResource.deleteAndVerifyError(
          tunnelZone.getUri(),
          MidonetMediaTypes.APPLICATION_TUNNEL_ZONE_JSON(),
          ClientResponse.Status.CONFLICT.getStatusCode());
    }
Example #2
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);
    }