コード例 #1
0
ファイル: TestRestCompute.java プロジェクト: nilupa/occi4java
  @Test
  public void testGetCompute() {
    Compute compute = null;
    try {
      compute = new Compute(Architecture.x64, 2, "TestCase", 200, 20, State.active, null);
    } catch (NumberFormatException e) {
      e.printStackTrace();
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
    } catch (URISyntaxException e) {
      e.printStackTrace();
    } catch (NamingException e) {
      e.printStackTrace();
    }
    // test if compute ist not null
    Assert.assertNotNull(compute);
    // connect to api
    clientResource.setReference(
        OcciConfig.getInstance().config.getString("occi.server.location")
            + "compute/"
            + compute.getId());
    clientResource.setHostRef(
        OcciConfig.getInstance().config.getString("occi.server.location")
            + "compute/"
            + compute.getId());
    // create new representation
    Representation representation = null;
    try {
      // send post request
      representation = clientResource.get();
    } catch (Exception ex) {
      System.out.println("Failed to execute GET request: " + ex.getMessage());
    }
    Assert.assertNotNull(representation);
    // get request and print it in debugger
    Request request = Request.getCurrent();
    System.out.println(request.toString() + "\n\n");
    System.out.println("--------------------------------");
    // get current response
    Response response = Response.getCurrent();
    Assert.assertNotNull(response);
    System.out.println("Response: " + response.toString());

    try {
      representation.write(System.out);
    } catch (IOException e) {
      System.out.println(e.getMessage());
    }
    System.out.println("\n--------------------------------");
  }