Example #1
0
  @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--------------------------------");
  }
Example #2
0
  // TODO Die Parameter beim Request werden nicht korrekt übergeben. Keine
  // Ahnung woran es liegt.
  @Test(enabled = false)
  public void testPostCompute() {
    // connect to api
    clientResource.setReference(
        OcciConfig.getInstance().config.getString("occi.server.location") + "compute");
    // Tests if client resource is connected to api
    Assert.assertNotNull(clientResource);
    // try to create a compute resource
    String architecture = "x86";
    String cores = "20";
    String hostname = "Ubuntu";
    String speed = "2000000";
    String memory = "1024";
    String category = "compute";
    // create new request and add all attributes
    Form form = new Form();
    form.add("occi.compute.architecture", architecture);
    form.add("occi.compute.cores", cores);
    form.add("occi.compute.hostname", hostname);
    form.add("occi.compute.speed", speed);
    form.add("occi.compute.memory", memory);
    form.add("category", category);
    System.out.println("\n FORM " + form.toString());
    // create new representation
    Representation representation = null;
    try {
      // send post request
      representation = clientResource.post(form.toString(), MediaType.TEXT_PLAIN);
    } catch (Exception ex) {
      System.out.println("Failed to execute POST request " + ex.getMessage());
    }
    Assert.assertNotNull(representation);
    // get request and print it in debugger
    Request request = Request.getCurrent();
    System.out.println(request.toString() + "\n\n" + form.getMatrixString());
    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--------------------------------");
  }