use of org.apache.felix.ipojo.extender.InstanceDeclaration in project felix by apache.
the class DefaultConfigurationBuilderTestCase method testPropertyRemoval.
public void testPropertyRemoval() throws Exception {
DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(parent);
builder.property("a", "b");
InstanceDeclaration declaration = (InstanceDeclaration) builder.build();
assertEquals(declaration.getConfiguration().get("a"), "b");
builder.remove("a");
InstanceDeclaration declaration2 = (InstanceDeclaration) builder.build();
assertNull(declaration2.getConfiguration().get("a"));
}
use of org.apache.felix.ipojo.extender.InstanceDeclaration in project felix by apache.
the class DefaultConfigurationBuilderTestCase method testPropertyAdditionReUse.
public void testPropertyAdditionReUse() throws Exception {
DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(parent);
builder.property("a", "b");
// First built instance
InstanceDeclaration declaration = (InstanceDeclaration) builder.build();
assertEquals(declaration.getConfiguration().get("a"), "b");
// Second built instance
builder.property("c", "d");
InstanceDeclaration declaration2 = (InstanceDeclaration) builder.build();
assertEquals(declaration2.getConfiguration().get("a"), "b");
assertEquals(declaration2.getConfiguration().get("c"), "d");
// Verify that first instance is not modified
assertNull(declaration.getConfiguration().get("c"));
}
use of org.apache.felix.ipojo.extender.InstanceDeclaration in project felix by apache.
the class DefaultInstanceBuilderTestCase method testVersionConfiguration.
public void testVersionConfiguration() throws Exception {
InstanceBuilder builder = new DefaultInstanceBuilder(m_bundleContext, "type").name("John").version("1.0");
DeclarationHandle handle = builder.build();
InstanceDeclaration did = (InstanceDeclaration) handle;
assertEquals("type", did.getComponentName());
assertEquals("John", did.getInstanceName());
assertEquals("1.0", did.getComponentVersion());
Dictionary<String, Object> configuration = did.getConfiguration();
assertEquals("John", configuration.get(Factory.INSTANCE_NAME_PROPERTY));
assertEquals("1.0", configuration.get(Factory.FACTORY_VERSION_PROPERTY));
}
use of org.apache.felix.ipojo.extender.InstanceDeclaration in project felix by apache.
the class DefaultInstanceBuilderTestCase method testNameConfiguration.
public void testNameConfiguration() throws Exception {
InstanceBuilder builder = new DefaultInstanceBuilder(m_bundleContext, "type").name("John");
DeclarationHandle handle = builder.build();
InstanceDeclaration did = (InstanceDeclaration) handle;
assertEquals("type", did.getComponentName());
assertEquals("John", did.getInstanceName());
assertNull(did.getComponentVersion());
Dictionary<String, Object> configuration = did.getConfiguration();
assertEquals("John", configuration.get(Factory.INSTANCE_NAME_PROPERTY));
}
use of org.apache.felix.ipojo.extender.InstanceDeclaration in project felix by apache.
the class Arch method instances.
/**
* Displays iPOJO instances.
*/
@Descriptor("Display iPOJO instances")
public void instances() {
StringBuilder buffer = new StringBuilder();
for (Architecture m_arch : m_archs) {
InstanceDescription instance = m_arch.getInstanceDescription();
if (instance.getState() == ComponentInstance.VALID) {
buffer.append(format("Instance %s -> valid%n", instance.getName()));
}
if (instance.getState() == ComponentInstance.INVALID) {
buffer.append(format("Instance %s -> invalid%n", instance.getName()));
}
if (instance.getState() == ComponentInstance.STOPPED) {
buffer.append(format("Instance %s -> stopped%n", instance.getName()));
}
}
for (InstanceDeclaration instance : m_instances) {
// Only print unbound instances (others already printed above)
if (!instance.getStatus().isBound()) {
buffer.append(format("Instance %s of type %s is not bound.%n", name(instance.getConfiguration()), instance.getConfiguration().get("component")));
buffer.append(format(" Reason: %s", instance.getStatus().getMessage()));
buffer.append("\n");
}
}
if (buffer.length() == 0) {
buffer.append("No instances \n");
}
System.out.println(buffer.toString());
}
Aggregations