Java Code Examples for org.apache.brooklyn.api.entity.Application#getChildren()

The following examples show how to use org.apache.brooklyn.api.entity.Application#getChildren() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CliTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testLoadEntityFromClasspath() throws Exception {
    String entityName = ExampleEntity.class.getName();
    Object appSpec = loadApplicationFromClasspathOrParse(entityName);
    assertTrue(appSpec instanceof EntitySpec, "app="+appSpec);
    
    mgmt = LocalManagementContextForTests.newInstance();
    app = (Application) mgmt.getEntityManager().createEntity((EntitySpec<?>)appSpec);

    Collection<Entity> entities = app.getChildren();
    assertEquals(entities.size(), 1, "entities="+entities);
    assertTrue(Iterables.getOnlyElement(entities) instanceof ExampleEntity, "entities="+entities+"; ifs="+Iterables.getOnlyElement(entities).getClass().getInterfaces());
    assertTrue(Iterables.getOnlyElement(entities) instanceof EntityProxy, "entities="+entities);
}
 
Example 2
Source File: CliTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Deprecated // Tests deprecated approach of using impl directly
@Test
public void testLoadEntityImplFromClasspath() throws Exception {
    String entityName = ExampleEntityImpl.class.getName();
    Object appSpec = loadApplicationFromClasspathOrParse(entityName);
    assertTrue(appSpec instanceof EntitySpec, "app="+appSpec);
    
    mgmt = LocalManagementContextForTests.newInstance();
    app = (Application) mgmt.getEntityManager().createEntity((EntitySpec<?>)appSpec);
    
    Collection<Entity> entities = app.getChildren();
    assertEquals(entities.size(), 1, "entities="+entities);
    assertEquals(Iterables.getOnlyElement(entities).getEntityType().getName(), ExampleEntity.class.getCanonicalName(), "entities="+entities);
    assertTrue(Iterables.getOnlyElement(entities) instanceof EntityProxy, "entities="+entities);
}
 
Example 3
Source File: CloudFoundryYamlLiveTest.java    From SeaCloudsPlatform with Apache License 2.0 5 votes vote down vote up
private Entity findChildEntitySpecByPlanId(Application app, String planId) {
    for (Entity child : app.getChildren()) {
        String childPlanId = child.getConfig(BrooklynCampConstants.PLAN_ID);
        if ((childPlanId != null) && (childPlanId.equals(planId))) {
            return child;
        }
    }
    return null;
}
 
Example 4
Source File: SpecParameterUnwrappingTest.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
@Test
public void testParameterDefaultsUsedInConfig() throws Exception {
    addCatalogItems(
            "brooklyn.catalog:",
            "  version: " + TEST_VERSION,
            "  items:",
            "    - id: " + ConfigEntityForTest.class.getSimpleName() + "WithParams",
            "      itemType: entity",
            "      item:",
            "        type: " + ConfigEntityForTest.class.getName(),
            "        brooklyn.parameters:",
            "          - name: num",
            "            type: integer",
            "            default: 1234",
            "        brooklyn.children:",
            "          - type: " + BasicStartable.class.getName(),
            "            name: s",
            "            brooklyn.config:",
            "              test: $brooklyn:parent().config(\"num\")",
            "    - id: " + SYMBOLIC_NAME,
            "      itemType: entity",
            "      item:",
            "        type: " + BasicApplication.class.getName(),
            "        brooklyn.children:",
            "          - type: " + ConfigEntityForTest.class.getSimpleName() + "WithParams",
            "            name: a",
            "          - type: " + ConfigEntityForTest.class.getSimpleName() + "WithParams",
            "            name: b",
            "            brooklyn.config:",
            "              num: 5678",
            "          - type: " + ConfigEntityForTest.class.getSimpleName() + "WithParams",
            "            name: c",
            "            brooklyn.config:",
            "              test: $brooklyn:config(\"num\")");
    final int NUM_CONFIG_KEYS_FROM_WITH_PARAMS_TEST_BLUEPRINT = 1;

    AbstractBrooklynObjectSpec<?,?> spec = peekSpec(ConfigEntityForTest.class.getSimpleName() + "WithParams", TEST_VERSION);
    List<SpecParameter<?>> params = spec.getParameters();
    assertEquals(params.size(), NUM_ENTITY_DEFAULT_CONFIG_KEYS + ConfigEntityForTest.NUM_CONFIG_KEYS_DEFINED_HERE + NUM_CONFIG_KEYS_FROM_WITH_PARAMS_TEST_BLUEPRINT,
        "params="+params);
    assertTrue(Iterables.tryFind(params, nameEqualTo("num")).isPresent());
    
    Application app = (Application) createAndStartApplication(
            "services:",
            "  - type: " + ver(SYMBOLIC_NAME));

    Iterable<Entity> children = app.getChildren();
    Optional<Entity> a = Iterables.tryFind(children, EntityPredicates.displayNameEqualTo("a"));
    assertTrue(a.isPresent());
    assertEquals(a.get().config().get(NUM).intValue(), 1234);
    Optional<Entity> as = Iterables.tryFind(a.get().getChildren(), EntityPredicates.displayNameEqualTo("s"));
    assertTrue(as.isPresent());
    assertEquals(as.get().config().get(ConfigKeys.newIntegerConfigKey("test")).intValue(), 1234);
    Optional<Entity> b = Iterables.tryFind(children, EntityPredicates.displayNameEqualTo("b"));
    assertTrue(b.isPresent());
    assertEquals(b.get().config().get(NUM).intValue(), 5678);
    Optional<Entity> bs = Iterables.tryFind(b.get().getChildren(), EntityPredicates.displayNameEqualTo("s"));
    assertTrue(bs.isPresent());
    assertEquals(bs.get().config().get(ConfigKeys.newIntegerConfigKey("test")).intValue(), 5678);
    Optional<Entity> c = Iterables.tryFind(children, EntityPredicates.displayNameEqualTo("c"));
    assertTrue(c.isPresent());
    assertEquals(c.get().config().get(ConfigKeys.newIntegerConfigKey("test")).intValue(), 1234);
    Optional<Entity> cs = Iterables.tryFind(c.get().getChildren(), EntityPredicates.displayNameEqualTo("s"));
    assertTrue(cs.isPresent());
    assertEquals(cs.get().config().get(ConfigKeys.newIntegerConfigKey("test")).intValue(), 1234);
}