Exemplo n.º 1
0
  public void testCreateZoneWhenResponseIs2xxAnd404() {
    GlobalZoneApi client =
        requestSendsResponse(
            createZone,
            HttpResponse.builder()
                .statusCode(200)
                .payload(payloadFromResource("/createzoneresponse.json"))
                .build());

    assertEquals(
        client.createZone("test-zone", NetworkType.BASIC, "8.8.8.8", "10.10.10.10"),
        Zone.builder()
            .id("6")
            .name("test-zone")
            .DNS(ImmutableList.of("8.8.8.8"))
            .internalDNS(ImmutableList.of("10.10.10.10"))
            .networkType(NetworkType.BASIC)
            .securityGroupsEnabled(true)
            .allocationState(AllocationState.ENABLED)
            .zoneToken("7b6e27df-30a6-3024-9d8b-7971a3127f64")
            .dhcpProvider("DhcpServer")
            .build());

    client = requestSendsResponse(createZone, HttpResponse.builder().statusCode(404).build());
    assertNull(client.createZone("test-zone", NetworkType.BASIC, "8.8.8.8", "10.10.10.10"));
  }
Exemplo n.º 2
0
  public void testUpdateZoneWhenResponseIs2xxAnd404() {
    HttpRequest request =
        HttpRequest.builder()
            .method("GET")
            .endpoint("http://localhost:8080/client/api")
            .addQueryParam("response", "json")
            .addQueryParam("command", "updateZone")
            .addQueryParam("id", "6")
            .addQueryParam("name", "test-zone")
            .addQueryParam("dns1", "8.8.8.8")
            .addQueryParam("apiKey", "identity")
            .addQueryParam("signature", "v19FdHKHztdT0IRloYFFn0eNbWM=")
            .headers(
                ImmutableMultimap.<String, String>builder()
                    .put("Accept", "application/json")
                    .build())
            .build();

    GlobalZoneApi client =
        requestSendsResponse(
            request,
            HttpResponse.builder()
                .statusCode(200)
                .payload(payloadFromResource("/updatezoneresponse.json"))
                .build());

    assertEquals(
        client.updateZone("6", name("test-zone").externalDns(ImmutableList.of("8.8.8.8"))),
        Zone.builder()
            .id("6")
            .name("test-zone")
            .DNS(ImmutableList.of("8.8.8.8"))
            .internalDNS(ImmutableList.of("10.10.10.10"))
            .networkType(NetworkType.BASIC)
            .securityGroupsEnabled(true)
            .allocationState(AllocationState.ENABLED)
            .zoneToken("7b6e27df-30a6-3024-9d8b-7971a3127f64")
            .dhcpProvider("DhcpServer")
            .build());

    client = requestSendsResponse(request, HttpResponse.builder().statusCode(404).build());
    assertNull(client.updateZone("6", name("test-zone").externalDns(ImmutableList.of("8.8.8.8"))));
  }