Java Code Examples for org.apache.brooklyn.core.test.entity.TestApplication#getManagementContext()

The following examples show how to use org.apache.brooklyn.core.test.entity.TestApplication#getManagementContext() . 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: XmlMementoSerializerTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testCatalogItem() throws Exception {
    final TestApplication app = TestApplication.Factory.newManagedInstanceForTests();
    ManagementContext managementContext = app.getManagementContext();
    try {
        CatalogItem<?, ?> catalogItem = CatalogItemBuilder.newEntity("symbolicName", "0.0.1")
                .displayName("test catalog item")
                .description("description")
                .plan("yaml plan")
                .iconUrl("iconUrl")
                .libraries(CatalogItemDtoAbstract.parseLibraries(ImmutableList.of("library-url")))
                .build();
        serializer.setLookupContext(newEmptyLookupManagementContext(managementContext, true).add(catalogItem));
        assertSerializeAndDeserialize(catalogItem);
    } finally {
        Entities.destroyAll(managementContext);
    }
}
 
Example 2
Source File: XmlMementoSerializerTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testImmutableCollectionsWithDanglingEntityRef() throws Exception {
    // If there's a dangling entity in an ImmutableList etc, then discard it entirely.
    // If we try to insert null then it fails, breaking the deserialization of that entire file.
    
    final TestApplication app = TestApplication.Factory.newManagedInstanceForTests();
    final TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
    ManagementContext managementContext = app.getManagementContext();
    try {
        serializer.setLookupContext(newEmptyLookupManagementContext(managementContext, false).add(app));
        
        List<?> resultList = serializeAndDeserialize(ImmutableList.of(app, entity));
        assertEquals(resultList, ImmutableList.of(app));
        
        Set<?> resultSet = serializeAndDeserialize(ImmutableSet.of(app, entity));
        assertEquals(resultSet, ImmutableSet.of(app));
        
        Map<?, ?> resultMap = serializeAndDeserialize(ImmutableMap.of(app, "appval", "appkey", app, entity, "entityval", "entityKey", entity));
        assertEquals(resultMap, ImmutableMap.of(app, "appval", "appkey", app));

    } finally {
        Entities.destroyAll(managementContext);
    }
}
 
Example 3
Source File: XmlMementoSerializerTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testTask() throws Exception {
    final TestApplication app = TestApplication.Factory.newManagedInstanceForTests();
    mgmt = app.getManagementContext();
    Task<String> completedTask = app.getExecutionContext().submit("return myval", Callables.returning("myval"));
    completedTask.get();
    
    String loggerName = UnwantedStateLoggingMapper.class.getName();
    ch.qos.logback.classic.Level logLevel = ch.qos.logback.classic.Level.WARN;
    Predicate<ILoggingEvent> filter = EventPredicates.containsMessage("Task object serialization is not supported or recommended"); 
    String serializedForm;
    try (LogWatcher watcher = new LogWatcher(loggerName, logLevel, filter)) {
        serializedForm = serializer.toString(completedTask);
        watcher.assertHasEvent();
    }

    assertEquals(serializedForm.trim(), "<"+BasicTask.class.getName()+">myval</"+BasicTask.class.getName()+">");
    Object deserialized = serializer.fromString(serializedForm);
    assertEquals(deserialized, null, "serializedForm="+serializedForm+"; deserialized="+deserialized);
}
 
Example 4
Source File: XmlMementoSerializerTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testEntity() throws Exception {
    final TestApplication app = TestApplication.Factory.newManagedInstanceForTests();
    ManagementContext managementContext = app.getManagementContext();
    try {
        serializer.setLookupContext(newEmptyLookupManagementContext(managementContext, true).add(app));
        assertSerializeAndDeserialize(app);
    } finally {
        Entities.destroyAll(managementContext);
    }
}
 
Example 5
Source File: XmlMementoSerializerTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testLocation() throws Exception {
    final TestApplication app = TestApplication.Factory.newManagedInstanceForTests();
    ManagementContext managementContext = app.getManagementContext();
    try {
        final Location loc = managementContext.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
        serializer.setLookupContext(newEmptyLookupManagementContext(managementContext, true).add(loc));
        assertSerializeAndDeserialize(loc);
    } finally {
        Entities.destroyAll(managementContext);
    }
}
 
Example 6
Source File: XmlMementoSerializerTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testFieldReffingEntity() throws Exception {
    final TestApplication app = TestApplication.Factory.newManagedInstanceForTests();
    ReffingEntity reffer = new ReffingEntity(app);
    ManagementContext managementContext = app.getManagementContext();
    try {
        serializer.setLookupContext(newEmptyLookupManagementContext(managementContext, true).add(app));
        ReffingEntity reffer2 = assertSerializeAndDeserialize(reffer);
        assertEquals(reffer2.entity, app);
    } finally {
        Entities.destroyAll(managementContext);
    }
}
 
Example 7
Source File: XmlMementoSerializerTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testUntypedFieldReffingEntity() throws Exception {
    final TestApplication app = TestApplication.Factory.newManagedInstanceForTests();
    ReffingEntity reffer = new ReffingEntity((Object)app);
    ManagementContext managementContext = app.getManagementContext();
    try {
        serializer.setLookupContext(newEmptyLookupManagementContext(managementContext, true).add(app));
        ReffingEntity reffer2 = assertSerializeAndDeserialize(reffer);
        assertEquals(reffer2.obj, app);
    } finally {
        Entities.destroyAll(managementContext);
    }
}