public void testGetServerWithSecurityGroups() {
    URI endpoint =
        URI.create(
            "https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/os-create-server-ext/8d0a6ca5-8849-4b3d-b86e-f24c92490ebb");
    ServerWithSecurityGroupsApi api =
        requestsSendResponses(
                keystoneAuthWithUsernameAndPasswordAndTenantName,
                responseWithKeystoneAccess,
                extensionsOfNovaRequest,
                extensionsOfNovaResponse,
                authenticatedGET().endpoint(endpoint).build(),
                HttpResponse.builder()
                    .statusCode(200)
                    .payload(payloadFromResource("/server_with_security_groups.json"))
                    .build())
            .getServerWithSecurityGroupsExtensionForZone("az-1.region-a.geo-1")
            .get();

    ServerWithSecurityGroups server = api.get("8d0a6ca5-8849-4b3d-b86e-f24c92490ebb");
    assertEquals(server.getId(), "8d0a6ca5-8849-4b3d-b86e-f24c92490ebb");
    assertEquals(server.getSecurityGroupNames(), ImmutableSet.of("default", "group1"));
  }
Esempio n. 2
0
 @Override
 public ServerWithSecurityGroups deserialize(
     JsonElement jsonElement, Type type, JsonDeserializationContext context)
     throws JsonParseException {
   Server server = context.deserialize(jsonElement, Server.class);
   ServerWithSecurityGroups.Builder<?> result =
       ServerWithSecurityGroups.builder().fromServer(server);
   Set<String> names = Sets.newLinkedHashSet();
   if (jsonElement.getAsJsonObject().get("security_groups") != null) {
     JsonArray x = jsonElement.getAsJsonObject().get("security_groups").getAsJsonArray();
     for (JsonElement y : x) {
       names.add(y.getAsJsonObject().get("name").getAsString());
     }
     result.securityGroupNames(names);
   }
   return result.build();
 }