@Override public void run() { TestEntity e3 = app.addChild(EntitySpec.create(TestEntity.class) .displayName("e3")); e3ref.set(e3); }});
protected void createTestEntities() throws Exception { e1 = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("test-one")); e2 = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("test-two")); e3 = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("test-three")); }
@Test public void testExplicitDisplayName() { TestEntity entity = app.addChild(EntitySpec.create(TestEntity.class) .displayName("myDisplayName")); assertEquals(entity.getDisplayName(), "myDisplayName"); }
@Test public void testDisplayNameUsesCustom() throws Exception { TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("entityname")); assertEquals(entity.getDisplayName(), "entityname"); }
@Test public void testCreateEntityUsingSpec() { TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)); TestEntity child = entity.addChild(EntitySpec.create(TestEntity.class).displayName("mychildname")); assertTrue(child instanceof EntityProxy, "child="+child); assertFalse(child instanceof TestEntityImpl, "child="+child); assertTrue(entity.getChildren().contains(child), "child="+child+"; children="+entity.getChildren()); assertEquals(child.getDisplayName(), "mychildname"); }
@Test public void testDisplayName() { TestEntity result = entity.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("Boo")); assertIsProxy(result); assertEquals(result.getDisplayName(), "Boo"); }
@Test public void testExplicitDefaultDisplayNameOverriddenByRealName() { TestEntity entity = app.addChild(EntitySpec.create(TestEntity.class) .configure(AbstractEntity.DEFAULT_DISPLAY_NAME, "myDefaultName") .displayName("myDisplayName")); assertEquals(entity.getDisplayName(), "myDisplayName"); }
@Test public void testGenerateNewMachineUniqueNameFromGroupId() { TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class).displayName("TistApp")); TestEntity child = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("TestEnt")); ConfigBag cfg = new ConfigBag() .configure(CloudLocationConfig.CALLER_CONTEXT, child); CloudMachineNamer namer = new BasicCloudMachineNamer(); String groupId = namer.generateNewGroupId(cfg); String result = namer.generateNewMachineUniqueNameFromGroupId(cfg, groupId); Assert.assertTrue(result.startsWith(groupId)); Assert.assertTrue(result.length() == groupId.length() + 5); }
private static MockItemEntity newItem(TestApplication app, MockContainerEntity container, String name) { MockItemEntity item = app.createAndManageChild(EntitySpec.create(MockItemEntity.class) .displayName(name)); item.move(container); return item; } }
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); StaticTypePlanTransformer.forceInstall(); specId = StaticTypePlanTransformer.registerSpec(EntitySpec.create(BasicEntity.class).displayName(DISPLAY_NAME)); }
@Test public void testDisplayNameUsesCustomWhenOverriddenDefault() throws Exception { entity = app.createAndManageChild(EntitySpec.create(TestEntity.class) .impl(TestEntityWithDefaultNameImpl.class) .configure(TestEntityWithDefaultNameImpl.DEFAULT_NAME, "myOverriddenDefaultName") .displayName("myEntityName")); assertEquals(entity.getDisplayName(), "myEntityName"); }
protected static MockItemEntity newLockedItem(TestApplication app, MockContainerEntity container, String name) { MockItemEntity item = app.createAndManageChild(EntitySpec.create(MockItemEntity.class) .displayName(name) .configure(MockItemEntity.IMMOVABLE, true)); LOG.debug("Managed new locked item {}", container); if (container != null) { item.move(container); } return item; }
@Test public void testGroupUsesNewFilter() throws Exception { final Entity e3 = app.addChild(EntitySpec.create(TestEntity.class).displayName("myname")); group.setEntityFilter(EntityPredicates.displayNameEqualTo("myname")); assertEqualsIgnoringOrder(group.getMembers(), ImmutableSet.of(e3)); }
@Test public void testAppUsesDisplayNameOverDefaultName() { EntitySpec<TestApplication> appSpec = EntitySpec.create(TestApplication.class) .displayName("myName") .configure(AbstractApplication.DEFAULT_DISPLAY_NAME, "myDefaultName"); TestApplication app2 = mgmt.getEntityManager().createEntity(EntitySpec.create(appSpec)); assertEquals(app2.getDisplayName(), "myName"); } }
@Test public void testRestoresEntityIdAndDisplayName() throws Exception { MyEntity origE = origApp.createAndManageChild(EntitySpec.create(MyEntity.class) .displayName("mydisplayname") .configure("iconUrl", "file:///tmp/myicon.png")); String eId = origE.getId(); newApp = rebind(); MyEntity newE = (MyEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(MyEntity.class)); assertEquals(newE.getId(), eId); assertEquals(newE.getDisplayName(), "mydisplayname"); }
@Test public void testGroupDetectsNewlyManagedMatchingMember() throws Exception { group.setEntityFilter(EntityPredicates.displayNameEqualTo("myname")); final Entity e3 = app.addChild(EntitySpec.create(TestEntity.class).displayName("myname")); Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertEqualsIgnoringOrder(group.getMembers(), ImmutableSet.of(e3)); }}); }
protected static MockItemEntity newLockedItem(TestApplication app, MockContainerEntity container, String name, double workrate) { MockItemEntity item = app.createAndManageChild(EntitySpec.create(MockItemEntity.class) .displayName(name) .configure(Movable.IMMOVABLE, true)); LOG.debug("Managed new item {} on container {}", item, container); item.move(container); item.sensors().set(TEST_METRIC, (int)workrate); return item; }
@Test public void testRebindsToExistingApp() throws Exception { populatePersistenceDir(persistenceDir, EntitySpec.create(TestApplication.class).displayName("myorig")); // Rebind to the app we just started last time newLauncherDefault(PersistMode.REBIND).start(); assertOnlyApp(lastMgmt(), TestApplication.class); assertNotNull(Iterables.find(lastMgmt().getApplications(), EntityPredicates.displayNameEqualTo("myorig"), null), "apps="+lastMgmt().getApplications()); }
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); entity = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("mydisplayname")); group = app.createAndManageChild(EntitySpec.create(BasicGroup.class)); loc = app.getManagementContext().getLocationRegistry().getLocationManaged("localhost"); }
private TestApplication newClusterApp(int suffix) { TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(EntitySpec.create(TestApplication.class) .displayName("app-"+suffix) .child(EntitySpec.create(DynamicCluster.class) .configure(DynamicCluster.INITIAL_SIZE, 1) .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(BasicStartable.class))))); app.start(ImmutableList.of(app.newLocalhostProvisioningLocation())); return app; }