Exemplo n.º 1
0
  public void testCreateInstance() {
    URI endpoint = URI.create("http://172.16.0.1:8776/v1/3456/instances");
    InstanceApi api =
        requestsSendResponses(
                keystoneAuthWithUsernameAndPasswordAndTenantName,
                responseWithKeystoneAccess,
                authenticatedGET()
                    .endpoint(
                        endpoint) // bad naming convention, you should not be able to change the
                                  // method to POST
                    .method("POST")
                    .payload(
                        payloadFromResourceWithContentType(
                            "/instance_create_request.json", MediaType.APPLICATION_JSON))
                    .build(),
                HttpResponse.builder()
                    .statusCode(200)
                    .payload(payloadFromResource("/instance_create.json"))
                    .build() // response
                )
            .getInstanceApi("RegionOne");

    Instance instance = api.create("1", 2, "json_rack_instance");
    assertEquals(instance.getSize(), 2);
    assertEquals(instance.getName(), "json_rack_instance");
  }
  /** @return Instance The Instance created in the CreateInstance example. */
  private Instance getInstance() {
    for (Instance instance : instanceApi.list()) {
      if (instance.getName().startsWith(NAME)) {
        return instance;
      }
    }

    throw new RuntimeException(NAME + " not found. Run the CreateInstance example first.");
  }
Exemplo n.º 3
0
  public void testGetInstance() {
    URI endpoint =
        URI.create("http://172.16.0.1:8776/v1/3456/instances/44b277eb-39be-4921-be31-3d61b43651d7");
    InstanceApi api =
        requestsSendResponses(
                keystoneAuthWithUsernameAndPasswordAndTenantName,
                responseWithKeystoneAccess,
                authenticatedGET().endpoint(endpoint).build(),
                HttpResponse.builder()
                    .statusCode(200)
                    .payload(payloadFromResource("/instance_get.json"))
                    .build())
            .getInstanceApi("RegionOne");

    Instance instance = api.get("44b277eb-39be-4921-be31-3d61b43651d7");
    assertEquals(instance.getName(), "json_rack_instance");
    assertEquals(instance.getId(), "44b277eb-39be-4921-be31-3d61b43651d7");
    assertEquals(instance.getLinks().size(), 2);
    assertEquals(
        instance.getHostname(), "e09ad9a3f73309469cf1f43d11e79549caf9acf2.rackspaceclouddb.com");
  }
Exemplo n.º 4
0
 /*
  * The instance needs to be comparable for this test to work
  * */
 @Override
 @Consumes(MediaType.APPLICATION_JSON)
 @SelectJson("instances")
 public Set<Instance> expected() {
   return ImmutableSet.of(
       Instance.builder()
           .id("098653ba-218b-47ce-936a-e0b749101f81")
           .name("xml_rack_instance")
           .size(2)
           .flavor(
               Flavor.builder()
                   .id(1)
                   .links(
                       ImmutableList.of(
                           Link.create(
                               Relation.SELF,
                               Uris.uriBuilder(
                                       "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1")
                                   .build()),
                           Link.create(
                               Relation.BOOKMARK,
                               Uris.uriBuilder(
                                       "https://ord.databases.api.rackspacecloud.com/flavors/1")
                                   .build())))
                   .build())
           .status(Instance.Status.ACTIVE)
           .links(
               ImmutableList.of(
                   Link.create(
                       Relation.SELF,
                       Uris.uriBuilder(
                               "https://ord.databases.api.rackspacecloud.com/v1.0/1234/instances/098653ba-218b-47ce-936a-e0b749101f81")
                           .build()),
                   Link.create(
                       Relation.BOOKMARK,
                       Uris.uriBuilder(
                               "https://ord.databases.api.rackspacecloud.com/instances/098653ba-218b-47ce-936a-e0b749101f81")
                           .build())))
           .build(),
       Instance.builder()
           .id("44b277eb-39be-4921-be31-3d61b43651d7")
           .name("json_rack_instance")
           .size(2)
           .flavor(
               Flavor.builder()
                   .id(1)
                   .links(
                       ImmutableList.of(
                           Link.create(
                               Relation.SELF,
                               Uris.uriBuilder(
                                       "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1")
                                   .build()),
                           Link.create(
                               Relation.BOOKMARK,
                               Uris.uriBuilder(
                                       "https://ord.databases.api.rackspacecloud.com/flavors/1")
                                   .build())))
                   .build())
           .status(Instance.Status.ACTIVE)
           .links(
               ImmutableList.of(
                   Link.create(
                       Relation.SELF,
                       Uris.uriBuilder(
                               "https://ord.databases.api.rackspacecloud.com/v1.0/1234/instances/44b277eb-39be-4921-be31-3d61b43651d7")
                           .build()),
                   Link.create(
                       Relation.BOOKMARK,
                       Uris.uriBuilder(
                               "https://ord.databases.api.rackspacecloud.com/instances/44b277eb-39be-4921-be31-3d61b43651d7")
                           .build())))
           .build());
 }