@Test(dependsOnMethods = "testSetDriveData")
  public void testCreateAndStartServer() throws Exception {
    Logger.getAnonymousLogger().info("preparing drive");
    prepareDrive();

    Server serverRequest = Servers.small(prefix, drive.getUuid(), vncPassword).build();

    Logger.getAnonymousLogger().info("starting server");
    server = client.createServer(serverRequest);
    client.startServer(server.getUuid());
    server = client.getServerInfo(server.getUuid());
    checkStartedServer();

    Server newInfo = client.getServerInfo(server.getUuid());
    checkServerMatchesGet(newInfo);
  }
  @Test(dependsOnMethods = "testLifeCycle")
  public void testSetServerConfiguration() throws Exception {
    client.stopServer(server.getUuid());
    assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.STOPPED);

    ServerInfo server2 =
        client.setServerConfiguration(
            server.getUuid(),
            Server.Builder.fromServer(server)
                .name("rediculous")
                .tags(ImmutableSet.of("networking", "security", "gateway"))
                .userMetadata(ImmutableMap.of("foo", "bar"))
                .build());

    assertNotNull(server2.getUuid(), server.getUuid());
    assertEquals(server2.getName(), "rediculous");
    checkTagsAndMetadata(server2);
    server = server2;
  }
  @Test(dependsOnMethods = "testConnectivity")
  public void testLifeCycle() throws Exception {
    client.stopServer(server.getUuid());
    assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.STOPPED);

    client.startServer(server.getUuid());
    assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.ACTIVE);

    client.resetServer(server.getUuid());
    assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.ACTIVE);

    client.shutdownServer(server.getUuid());
    // behavior on shutdown depends on how your server OS is set up to respond to an ACPI power
    // button signal
    assert (client.getServerInfo(server.getUuid()).getStatus() == ServerStatus.ACTIVE
        || client.getServerInfo(server.getUuid()).getStatus() == ServerStatus.STOPPED);
  }
 protected void checkStartedServer() {
   System.out.println(new Gson().toJson(server));
   assertNotNull(server.getUuid());
   assertNotNull(server.getUser());
   assertEquals(server.getName(), prefix);
   assertEquals(server.isPersistent(), true);
   assertEquals(
       server.getDevices(),
       ImmutableMap.of("ide:0:0", new IDEDevice.Builder(0, 0).uuid(drive.getUuid()).build()));
   assertEquals(server.getBootDeviceIds(), ImmutableSet.of("ide:0:0"));
   assertEquals(server.getNics().get(0).getDhcp(), server.getVnc().getIp());
   assertEquals(server.getNics().get(0).getModel(), Model.E1000);
   assertEquals(server.getStatus(), ServerStatus.ACTIVE);
 }
  @AfterGroups(groups = "live")
  @Override
  protected void tearDownContext() {
    try {
      client.destroyServer(server.getUuid());
    } catch (Exception e) {
      // no need to check null or anything as we swallow all
    }
    try {
      client.destroyDrive(drive.getUuid());
    } catch (Exception e) {

    }
    super.tearDownContext();
  }
 @Test(dependsOnMethods = "testSetServerConfiguration")
 public void testDestroyServer() throws Exception {
   client.destroyServer(server.getUuid());
   assertEquals(client.getServerInfo(server.getUuid()), null);
 }
 protected void checkServerMatchesGet(Server newInfo) {
   assertEquals(newInfo.getUuid(), server.getUuid());
 }