Ejemplo n.º 1
0
  // @Test
  public void testBadRequests() {
    // Test some bad network lengths
    DtoDhcpSubnet subnet1 = new DtoDhcpSubnet();
    subnet1.setSubnetPrefix("172.31.0.0");
    subnet1.setSubnetLength(-3);
    subnet1.setDefaultGateway("172.31.0.1");
    subnet1.setServerAddr("172.31.0.118");
    ClientResponse response =
        resource()
            .uri(bridge.getDhcpSubnets())
            .type(APPLICATION_DHCP_SUBNET_JSON)
            .post(ClientResponse.class, subnet1);
    assertEquals(400, response.getStatus());
    subnet1.setSubnetLength(33);
    response =
        resource()
            .uri(bridge.getDhcpSubnets())
            .type(APPLICATION_DHCP_SUBNET_JSON)
            .post(ClientResponse.class, subnet1);
    assertEquals(400, response.getStatus());

    // Test some bad network addresses
    subnet1.setSubnetLength(24);
    subnet1.setSubnetPrefix("10.0.0");
    response =
        resource()
            .uri(bridge.getDhcpSubnets())
            .type(APPLICATION_DHCP_SUBNET_JSON)
            .post(ClientResponse.class, subnet1);
    assertEquals(400, response.getStatus());
    subnet1.setSubnetPrefix("321.4.5.6");
    response =
        resource()
            .uri(bridge.getDhcpSubnets())
            .type(APPLICATION_DHCP_SUBNET_JSON)
            .post(ClientResponse.class, subnet1);
    assertEquals(400, response.getStatus());

    // Test some bad default gateways.
    subnet1.setSubnetPrefix("172.31.0.0");
    subnet1.setDefaultGateway("nonsense");
    response =
        resource()
            .uri(bridge.getDhcpSubnets())
            .type(APPLICATION_DHCP_SUBNET_JSON)
            .post(ClientResponse.class, subnet1);
    assertEquals(400, response.getStatus());
    subnet1.setDefaultGateway("1.2.3.4.5");
    response =
        resource()
            .uri(bridge.getDhcpSubnets())
            .type(APPLICATION_DHCP_SUBNET_JSON)
            .post(ClientResponse.class, subnet1);
    assertEquals(400, response.getStatus());
  }
Ejemplo n.º 2
0
  // @Test
  public void testGatewaySetting() throws Exception {
    ClientResponse response;

    DtoDhcpSubnet subnet1 = new DtoDhcpSubnet();
    subnet1.setSubnetPrefix("172.31.0.0");
    subnet1.setSubnetLength(24);
    subnet1.setDefaultGateway("172.31.0.1");
    subnet1.setServerAddr("172.31.0.118");
    response =
        resource()
            .uri(bridge.getDhcpSubnets())
            .type(APPLICATION_DHCP_SUBNET_JSON)
            .post(ClientResponse.class, subnet1);

    assertEquals(201, response.getStatus());

    DtoDhcpSubnet[] subnets =
        resource()
            .uri(bridge.getDhcpSubnets())
            .type(APPLICATION_DHCP_SUBNET_COLLECTION_JSON)
            .get(DtoDhcpSubnet[].class);
    Assert.assertNotNull(subnets);
  }
Ejemplo n.º 3
0
  @Test
  public void testDhcpRoutes() {
    ClientResponse response;

    DtoDhcpSubnet subnet1 = new DtoDhcpSubnet();
    subnet1.setSubnetPrefix("172.0.0.0");
    subnet1.setSubnetLength(24);
    subnet1.setDefaultGateway("172.0.0.254");
    subnet1.setServerAddr("172.0.0.118");
    subnet1.getOpt121Routes().add(new DtoDhcpOption121("172.31.1.0", 24, "172.0.0.253"));
    subnet1.getOpt121Routes().add(new DtoDhcpOption121("172.31.2.0", 24, "172.0.0.253"));
    response =
        resource()
            .uri(bridge.getDhcpSubnets())
            .type(APPLICATION_DHCP_SUBNET_JSON)
            .post(ClientResponse.class, subnet1);
    assertEquals(201, response.getStatus());
    DtoDhcpSubnet subnet2 =
        resource()
            .uri(response.getLocation())
            .accept(APPLICATION_DHCP_SUBNET_JSON)
            .get(DtoDhcpSubnet.class);

    // Copy the URIs from the GET to the DTO we used for create.
    subnet1.setHosts(subnet2.getHosts());
    subnet1.setUri(subnet2.getUri());
    // Now the DTOs should be identical.

    assertEquals(
        "The DhcpSubnet client dto from GET should be " + "identical to the one passed to create",
        subnet1,
        subnet2);

    // Now modify the routes and do an update.
    subnet1.getOpt121Routes().remove(0);
    subnet1.getOpt121Routes().add(new DtoDhcpOption121("172.31.3.0", 24, "172.0.0.252"));
    subnet1.getOpt121Routes().add(new DtoDhcpOption121("172.31.4.0", 24, "172.0.0.253"));
    subnet1.setDefaultGateway("172.0.0.1");
    response =
        resource()
            .uri(subnet1.getUri())
            .type(APPLICATION_DHCP_SUBNET_JSON)
            .put(ClientResponse.class, subnet1);
    assertEquals(204, response.getStatus());
    subnet2 =
        resource()
            .uri(subnet1.getUri())
            .accept(APPLICATION_DHCP_SUBNET_JSON)
            .get(DtoDhcpSubnet.class);
    // The URIs should not have changed, so the DTOs should be identical.
    assertEquals(
        "The DhcpSubnet client dto from GET should be " + "identical to the one passed to create",
        subnet1,
        subnet2);

    // Now try removing all routes.
    subnet1.getOpt121Routes().clear();
    subnet1.setDefaultGateway(null);
    response =
        resource()
            .uri(subnet1.getUri())
            .type(APPLICATION_DHCP_SUBNET_JSON)
            .put(ClientResponse.class, subnet1);
    assertEquals(204, response.getStatus());
    subnet2 =
        resource()
            .uri(subnet1.getUri())
            .accept(APPLICATION_DHCP_SUBNET_JSON)
            .get(DtoDhcpSubnet.class);
    // The URIs should not have changed, so the DTOs should be identical.
    assertEquals(
        "The DhcpSubnet client dto from GET should be " + "identical to the one passed to create",
        subnet1,
        subnet2);
  }