Search in sources :

Example 1 with WibbleAnalyzer

use of org.example.tests.utils.WibbleAnalyzer in project bnd by bndtools.

the class TestOSGiServices method testWhiteboardAnalyzer.

// Test whiteboard registration of Resource Analyzers.
public void testWhiteboardAnalyzer() throws Exception {
    ServiceRegistration<ResourceAnalyzer> reg = context.registerService(ResourceAnalyzer.class, new WibbleAnalyzer(), null);
    ServiceReference<ResourceIndexer> ref = context.getServiceReference(ResourceIndexer.class);
    ResourceIndexer indexer = context.getService(ref);
    StringWriter writer = new StringWriter();
    Map<String, String> config = new HashMap<String, String>();
    config.put(ResourceIndexer.ROOT_URL, tempDir.getAbsoluteFile().toURI().toString());
    indexer.indexFragment(Collections.singleton(copyToTempFile(tempDir, "testdata/01-bsn+version.jar")), writer, config);
    assertEquals(readStream(TestOSGiServices.class.getResourceAsStream("/testdata/fragment-wibble.txt")), writer.toString().trim());
    context.ungetService(ref);
    reg.unregister();
}
Also used : WibbleAnalyzer(org.example.tests.utils.WibbleAnalyzer) ResourceAnalyzer(org.osgi.service.indexer.ResourceAnalyzer) StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) ResourceIndexer(org.osgi.service.indexer.ResourceIndexer)

Example 2 with WibbleAnalyzer

use of org.example.tests.utils.WibbleAnalyzer in project bnd by bndtools.

the class TestOSGiServices method testWhiteboardAnalyzerWithFilter.

// Test whiteboard registration of Resource Analyzers, with resource filter
// property.
public void testWhiteboardAnalyzerWithFilter() throws Exception {
    Dictionary<String, Object> analyzerProps = new Hashtable<String, Object>();
    analyzerProps.put(ResourceAnalyzer.FILTER, "(location=*sion.jar)");
    ServiceRegistration<ResourceAnalyzer> reg = context.registerService(ResourceAnalyzer.class, new WibbleAnalyzer(), analyzerProps);
    ServiceReference<ResourceIndexer> ref = context.getServiceReference(ResourceIndexer.class);
    ResourceIndexer indexer = context.getService(ref);
    StringWriter writer = new StringWriter();
    Set<File> files = new LinkedHashSet<File>();
    files.add(copyToTempFile(tempDir, "testdata/01-bsn+version.jar"));
    files.add(copyToTempFile(tempDir, "testdata/02-localization.jar"));
    Map<String, String> config = new HashMap<String, String>();
    config.put(ResourceIndexer.ROOT_URL, tempDir.getAbsoluteFile().toURI().toString());
    indexer.indexFragment(files, writer, config);
    assertEquals(readStream(TestOSGiServices.class.getResourceAsStream("/testdata/fragment-wibble-filtered.txt")), writer.toString().trim());
    context.ungetService(ref);
    reg.unregister();
}
Also used : WibbleAnalyzer(org.example.tests.utils.WibbleAnalyzer) ResourceAnalyzer(org.osgi.service.indexer.ResourceAnalyzer) LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) Hashtable(java.util.Hashtable) Matchers.anyString(org.mockito.Matchers.anyString) ResourceIndexer(org.osgi.service.indexer.ResourceIndexer) StringWriter(java.io.StringWriter) Utils.copyToTempFile(org.example.tests.utils.Utils.copyToTempFile) File(java.io.File)

Aggregations

StringWriter (java.io.StringWriter)2 HashMap (java.util.HashMap)2 WibbleAnalyzer (org.example.tests.utils.WibbleAnalyzer)2 Matchers.anyString (org.mockito.Matchers.anyString)2 ResourceAnalyzer (org.osgi.service.indexer.ResourceAnalyzer)2 ResourceIndexer (org.osgi.service.indexer.ResourceIndexer)2 File (java.io.File)1 Hashtable (java.util.Hashtable)1 LinkedHashSet (java.util.LinkedHashSet)1 Utils.copyToTempFile (org.example.tests.utils.Utils.copyToTempFile)1