@Test
 public void testSubstitutionUsesDriverBean() throws Exception {
   String entityid = entity.getId();
   String pattern = "id=${driver.entity.id}";
   BasicDownloadRequirement req = new BasicDownloadRequirement(driver);
   String result = DownloadSubstituters.substitute(req, pattern);
   assertEquals(result, String.format("id=%s", entityid));
 }
예제 #2
0
 @Test
 public void testCreateAndManageChild() {
   TestEntity result = entity.createAndManageChild(TestEntity.Spec.newInstance());
   assertIsProxy(result);
   assertIsProxy(Iterables.get(entity.getChildren(), 0));
   assertIsProxy(result.getParent());
   assertIsProxy(managementContext.getEntityManager().getEntity(result.getId()));
 }
  @Test
  public void testRestoresEntityHierarchy() throws Exception {
    TestEntity origE = origApp.createAndManageChild(EntitySpec.create(TestEntity.class));
    TestEntity origE2 = origE.createAndManageChild(EntitySpec.create(TestEntity.class));

    newApp = rebind();

    // Assert has expected config/fields
    assertEquals(newApp.getId(), origApp.getId());

    assertEquals(newApp.getChildren().size(), 1);
    TestEntity newE = (TestEntity) Iterables.get(newApp.getChildren(), 0);
    assertEquals(newE.getId(), origE.getId());

    assertEquals(newE.getChildren().size(), 1);
    TestEntity newE2 = (TestEntity) Iterables.get(newE.getChildren(), 0);
    assertEquals(newE2.getId(), origE2.getId());

    assertNotSame(origApp, newApp);
    assertNotSame(origApp.getManagementContext(), newApp.getManagementContext());
    assertNotSame(origE, newE);
    assertNotSame(origE2, newE2);
  }
예제 #4
0
  @Test
  public void testEntityManagerQueriesGiveProxies() {
    EntityManager entityManager = managementContext.getEntityManager();

    Application retrievedApp = (Application) entityManager.getEntity(app.getId());
    TestEntity retrievedEntity = (TestEntity) entityManager.getEntity(entity.getId());

    assertIsProxy(retrievedApp);
    assertIsProxy(retrievedEntity);

    Collection<Entity> entities = entityManager.getEntities();
    for (Entity e : entities) {
      assertIsProxy(e);
    }
    assertEquals(ImmutableSet.copyOf(entities), ImmutableSet.of(app, entity));
  }
  @Test
  public void testEscapesUriForSensorName() throws IOException {
    Sensor<String> sensor = Sensors.newStringSensor("name with space");
    SensorSummary summary = SensorTransformer.sensorSummary(entity, sensor);
    URI selfUri = summary.getLinks().get("self");

    String expectedUri =
        "/v1/applications/"
            + entity.getApplicationId()
            + "/entities/"
            + entity.getId()
            + "/sensors/"
            + "name%20with%20space";

    assertEquals(selfUri, URI.create(expectedUri));
  }