Search in sources :

Example 6 with ServiceReference

use of org.osgi.framework.ServiceReference in project opennms by OpenNMS.

the class OperationListShellCommand method doExecute.

@Override
protected Object doExecute() throws Exception {
    final List<Operation> operations = Lists.newArrayList();
    final Map<Operation, Map<String, Object>> properties = new HashMap<>();
    final Collection<ServiceReference<Operation>> services = this.bundleContext.getServiceReferences(Operation.class, null);
    if (services == null)
        return null;
    for (final ServiceReference<Operation> sr : services) {
        final Operation operation = this.bundleContext.getService(sr);
        if (operation == null)
            continue;
        operations.add(operation);
        final Map<String, Object> props = new TreeMap<>();
        for (final String key : sr.getPropertyKeys()) {
            props.put(key, sr.getProperty(key));
        }
        properties.put(operation, props);
    }
    // Output
    for (final Operation operation : operations) {
        final String operationClass = operation.getClass().getName();
        System.out.println("    " + makeLine(operationClass));
        System.out.println("    Class: " + operationClass);
        System.out.println("    ID:    " + operation.getId());
        final Map<String, Object> props = properties.get(operation);
        if (!props.isEmpty()) {
            System.out.println("    Service Properties:");
            for (final String key : props.keySet()) {
                final Object object = props.get(key);
                final String value = (object instanceof Object[]) ? Arrays.toString((Object[]) object) : object.toString();
                System.out.println("        " + key + "=" + value);
            }
        }
    }
    return null;
}
Also used : HashMap(java.util.HashMap) Operation(org.opennms.features.topology.api.Operation) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map) HashMap(java.util.HashMap) ServiceReference(org.osgi.framework.ServiceReference)

Example 7 with ServiceReference

use of org.osgi.framework.ServiceReference in project voltdb by VoltDB.

the class TestVoltCSVFormatter method testBlankError.

@Test
public void testBlankError() throws Exception {
    ServiceReference[] refs = m_bundle.getRegisteredServices();
    ServiceReference<AbstractFormatterFactory> reference = refs[0];
    AbstractFormatterFactory o = m_bundle.getBundleContext().getService(reference);
    Properties prop = new Properties();
    prop.setProperty("separator", ",");
    prop.setProperty("blank", "error");
    FormatterBuilder builder = new FormatterBuilder("csv", prop);
    builder.setFormatterFactory(o);
    Formatter formatter = builder.create();
    try {
        Object[] results = formatter.transform(ByteBuffer.wrap("12,,test".getBytes(StandardCharsets.UTF_8)));
        fail();
    } catch (RuntimeException e) {
    }
}
Also used : Formatter(org.voltdb.importer.formatter.Formatter) Properties(java.util.Properties) FormatterBuilder(org.voltdb.importer.formatter.FormatterBuilder) AbstractFormatterFactory(org.voltdb.importer.formatter.AbstractFormatterFactory) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 8 with ServiceReference

use of org.osgi.framework.ServiceReference in project voltdb by VoltDB.

the class TestVoltCSVFormatter method testQuoteChar.

//char separator, char quotechar, char escape, boolean strictQuotes, boolean ignoreLeadingWhiteSpace
@Test
public void testQuoteChar() throws Exception {
    ServiceReference[] refs = m_bundle.getRegisteredServices();
    ServiceReference<AbstractFormatterFactory> reference = refs[0];
    AbstractFormatterFactory o = m_bundle.getBundleContext().getService(reference);
    Properties prop = new Properties();
    prop.setProperty("quotechar", "'");
    FormatterBuilder builder = new FormatterBuilder("csv", prop);
    builder.setFormatterFactory(o);
    Formatter formatter = builder.create();
    Object[] results = formatter.transform(ByteBuffer.wrap("12,'10.05,test'".getBytes(StandardCharsets.UTF_8)));
    assertEquals(results.length, 2);
    assertEquals(results[0], "12");
    assertEquals(results[1], "10.05,test");
}
Also used : Formatter(org.voltdb.importer.formatter.Formatter) Properties(java.util.Properties) FormatterBuilder(org.voltdb.importer.formatter.FormatterBuilder) AbstractFormatterFactory(org.voltdb.importer.formatter.AbstractFormatterFactory) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 9 with ServiceReference

use of org.osgi.framework.ServiceReference in project voltdb by VoltDB.

the class TestVoltCSVFormatter method testBadFormat.

@Test
public void testBadFormat() throws Exception {
    ServiceReference[] refs = m_bundle.getRegisteredServices();
    ServiceReference<AbstractFormatterFactory> reference = refs[0];
    AbstractFormatterFactory o = m_bundle.getBundleContext().getService(reference);
    Properties prop = new Properties();
    FormatterBuilder builder = new FormatterBuilder("badformat", prop);
    builder.setFormatterFactory(o);
    try {
        builder.create();
        fail();
    } catch (RuntimeException e) {
    }
}
Also used : Properties(java.util.Properties) FormatterBuilder(org.voltdb.importer.formatter.FormatterBuilder) AbstractFormatterFactory(org.voltdb.importer.formatter.AbstractFormatterFactory) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 10 with ServiceReference

use of org.osgi.framework.ServiceReference in project voltdb by VoltDB.

the class TestVoltCSVFormatter method testTrimunquoted.

@Test
public void testTrimunquoted() throws Exception {
    ServiceReference[] refs = m_bundle.getRegisteredServices();
    ServiceReference<AbstractFormatterFactory> reference = refs[0];
    AbstractFormatterFactory o = m_bundle.getBundleContext().getService(reference);
    Properties prop = new Properties();
    prop.setProperty("trimunquoted", "false");
    FormatterBuilder builder = new FormatterBuilder("csv", prop);
    builder.setFormatterFactory(o);
    Formatter formatter = builder.create();
    Object[] results = formatter.transform(ByteBuffer.wrap("12,10.05,  test".getBytes(StandardCharsets.UTF_8)));
    assertEquals(results.length, 3);
    assertEquals(results[0], "12");
    assertEquals(results[1], "10.05");
    assertEquals(results[2], "  test");
}
Also used : Formatter(org.voltdb.importer.formatter.Formatter) Properties(java.util.Properties) FormatterBuilder(org.voltdb.importer.formatter.FormatterBuilder) AbstractFormatterFactory(org.voltdb.importer.formatter.AbstractFormatterFactory) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Aggregations

ServiceReference (org.osgi.framework.ServiceReference)1687 Test (org.junit.Test)926 Properties (java.util.Properties)396 Architecture (org.apache.felix.ipojo.architecture.Architecture)263 CheckService (org.apache.felix.ipojo.runtime.core.test.services.CheckService)233 BundleContext (org.osgi.framework.BundleContext)229 InstanceDescription (org.apache.felix.ipojo.architecture.InstanceDescription)227 ComponentInstance (org.apache.felix.ipojo.ComponentInstance)215 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)182 ArrayList (java.util.ArrayList)167 Bundle (org.osgi.framework.Bundle)144 FooService (org.apache.felix.ipojo.runtime.core.services.FooService)141 Hashtable (java.util.Hashtable)124 IOException (java.io.IOException)107 CheckService (org.apache.felix.ipojo.runtime.core.services.CheckService)92 Dictionary (java.util.Dictionary)82 Configuration (org.osgi.service.cm.Configuration)74 CheckService (org.apache.felix.ipojo.handler.temporal.services.CheckService)70 FooService (org.apache.felix.ipojo.handler.temporal.services.FooService)70 CheckService (org.apache.felix.ipojo.handler.transaction.services.CheckService)65