Ejemplo n.º 1
0
  @Test
  public void testAddChild() throws Exception {
    try {
      // to test in GUI:
      // services: [ { type: org.apache.brooklyn.entity.stock.BasicEntity }]
      Response response =
          client()
              .path(entityEndpoint + "/children")
              .query("timeout", "10s")
              .post(
                  javax.ws.rs.client.Entity.entity(
                      "services: [ { type: " + TestEntity.class.getName() + " }]",
                      "application/yaml"));

      HttpAsserts.assertHealthyStatusCode(response.getStatus());
      Assert.assertEquals(entity.getChildren().size(), 1);
      Entity child = Iterables.getOnlyElement(entity.getChildren());
      Assert.assertTrue(Entities.isManaged(child));

      TaskSummary task = response.readEntity(TaskSummary.class);
      Assert.assertEquals(task.getResult(), MutableList.of(child.getId()));

    } finally {
      // restore it for other tests
      Collection<Entity> children = entity.getChildren();
      if (!children.isEmpty()) Entities.unmanage(Iterables.getOnlyElement(children));
    }
  }
Ejemplo n.º 2
0
  @Test
  public void testTagsDoNotSerializeTooMuch() throws Exception {
    entity.tags().addTag("foo");
    entity.tags().addTag(entity.getParent());

    Response response =
        client().path(entityEndpoint + "/tags").accept(MediaType.APPLICATION_JSON).get();
    String raw = response.readEntity(String.class);
    log.info("TAGS raw: " + raw);
    HttpAsserts.assertHealthyStatusCode(response.getStatus());

    Assert.assertTrue(
        raw.contains(entity.getParent().getId()),
        "unexpected app tag, does not include ID: " + raw);

    Assert.assertTrue(
        raw.length() < 1000,
        "unexpected app tag, includes too much mgmt info (len " + raw.length() + "): " + raw);

    Assert.assertFalse(
        raw.contains(entity.getManagementContext().getManagementNodeId()),
        "unexpected app tag, includes too much mgmt info: " + raw);
    Assert.assertFalse(
        raw.contains("managementContext"),
        "unexpected app tag, includes too much mgmt info: " + raw);
    Assert.assertFalse(
        raw.contains("localhost"), "unexpected app tag, includes too much mgmt info: " + raw);
    Assert.assertFalse(
        raw.contains("catalog"), "unexpected app tag, includes too much mgmt info: " + raw);

    @SuppressWarnings("unchecked")
    List<Object> tags = mapper().readValue(raw, List.class);
    log.info("TAGS are: " + tags);

    Assert.assertEquals(tags.size(), 2, "tags are: " + tags);

    Assert.assertTrue(tags.contains("foo"));
    Assert.assertFalse(tags.contains("bar"));

    MutableList<Object> appTags = MutableList.copyOf(tags);
    appTags.remove("foo");
    Object appTag = Iterables.getOnlyElement(appTags);

    // it's a map at this point, because there was no way to make it something stronger than Object
    Assert.assertTrue(appTag instanceof Map, "Should have deserialized an entity: " + appTag);
    // let's re-serialize it as an entity
    appTag = mapper().readValue(mapper().writeValueAsString(appTag), Entity.class);

    Assert.assertTrue(appTag instanceof Entity, "Should have deserialized an entity: " + appTag);
    Assert.assertEquals(
        ((Entity) appTag).getId(), entity.getApplicationId(), "Wrong ID: " + appTag);
    Assert.assertTrue(
        appTag instanceof BasicApplication, "Should have deserialized BasicApplication: " + appTag);
  }
Ejemplo n.º 3
0
  @Test
  public void testRename() throws Exception {
    try {
      Response response =
          client().path(entityEndpoint + "/name").query("name", "New Name").post(null);

      HttpAsserts.assertHealthyStatusCode(response.getStatus());
      Assert.assertTrue(entity.getDisplayName().equals("New Name"));
    } finally {
      // restore it for other tests!
      entity.setDisplayName("simple-ent");
    }
  }