Search in sources :

Example 11 with LogService

use of org.osgi.service.log.LogService in project bnd by bndtools.

the class TestIndexer method testRemoveDisallowed.

public void testRemoveDisallowed() throws Exception {
    LogService log = mock(LogService.class);
    RepoIndex indexer = new RepoIndex(log);
    indexer.addAnalyzer(new NaughtyAnalyzer(), null);
    Map<String, String> props = new HashMap<String, String>();
    props.put(ResourceIndexer.ROOT_URL, new File("testdata").getAbsoluteFile().toURI().toURL().toString());
    StringWriter writer = new StringWriter();
    indexer.indexFragment(Collections.singleton(new File("testdata/subdir/01-bsn+version.jar")), writer, props);
    verify(log).log(eq(LogService.LOG_ERROR), anyString(), isA(UnsupportedOperationException.class));
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) File(java.io.File) LogService(org.osgi.service.log.LogService)

Example 12 with LogService

use of org.osgi.service.log.LogService in project bnd by bndtools.

the class TestIndexer method testLogErrorsFromAnalyzer.

public void testLogErrorsFromAnalyzer() throws Exception {
    ResourceAnalyzer badAnalyzer = new ResourceAnalyzer() {

        public void analyzeResource(Resource resource, List<Capability> capabilities, List<Requirement> requirements) throws Exception {
            throw new Exception("Bang!");
        }
    };
    ResourceAnalyzer goodAnalyzer = mock(ResourceAnalyzer.class);
    LogService log = mock(LogService.class);
    RepoIndex indexer = new RepoIndex(log);
    indexer.addAnalyzer(badAnalyzer, null);
    indexer.addAnalyzer(goodAnalyzer, null);
    // Run the indexer
    Map<String, String> props = new HashMap<String, String>();
    props.put(ResourceIndexer.ROOT_URL, new File("testdata").getAbsoluteFile().toURI().toURL().toString());
    StringWriter writer = new StringWriter();
    indexer.indexFragment(Collections.singleton(new File("testdata/subdir/01-bsn+version.jar")), writer, props);
    // The "good" analyzer should have been called
    verify(goodAnalyzer).analyzeResource(any(Resource.class), anyListOf(Capability.class), anyListOf(Requirement.class));
    // The log service should have been notified about the exception
    ArgumentCaptor<Exception> exceptionCaptor = ArgumentCaptor.forClass(Exception.class);
    verify(log).log(eq(LogService.LOG_ERROR), any(String.class), exceptionCaptor.capture());
    assertEquals("Bang!", exceptionCaptor.getValue().getMessage());
}
Also used : ResourceAnalyzer(org.osgi.service.indexer.ResourceAnalyzer) Capability(org.osgi.service.indexer.Capability) HashMap(java.util.HashMap) Resource(org.osgi.service.indexer.Resource) Matchers.anyString(org.mockito.Matchers.anyString) IOException(java.io.IOException) Requirement(org.osgi.service.indexer.Requirement) StringWriter(java.io.StringWriter) List(java.util.List) File(java.io.File) LogService(org.osgi.service.log.LogService)

Example 13 with LogService

use of org.osgi.service.log.LogService in project bnd by bndtools.

the class TestIndexer method testBundleOutsideRootDirectory.

public void testBundleOutsideRootDirectory() throws Exception {
    LogService log = mock(LogService.class);
    RepoIndex indexer = new RepoIndex(log);
    Map<String, String> props = new HashMap<String, String>();
    props.put(ResourceIndexer.ROOT_URL, new File("testdata/subdir").getAbsoluteFile().toURI().toURL().toString());
    StringWriter writer = new StringWriter();
    indexer.indexFragment(Collections.singleton(new File("testdata/01-bsn+version.jar")), writer, props);
    verify(log).log(eq(LogService.LOG_ERROR), anyString(), isA(IllegalArgumentException.class));
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) File(java.io.File) LogService(org.osgi.service.log.LogService)

Example 14 with LogService

use of org.osgi.service.log.LogService in project bnd by bndtools.

the class TestIndexer method testFragmentPlainJar.

public void testFragmentPlainJar() throws Exception {
    LogService mockLog = Mockito.mock(LogService.class);
    RepoIndex indexer = new RepoIndex(mockLog);
    indexer.addAnalyzer(new KnownBundleAnalyzer(), FrameworkUtil.createFilter("(name=*)"));
    assertFragmentMatch(indexer, "testdata/fragment-plainjar.txt", "testdata/jcip-annotations.jar");
    Mockito.verifyZeroInteractions(mockLog);
}
Also used : LogService(org.osgi.service.log.LogService)

Aggregations

LogService (org.osgi.service.log.LogService)14 File (java.io.File)10 StringWriter (java.io.StringWriter)5 HashMap (java.util.HashMap)5 Builder (aQute.bnd.osgi.Builder)4 Jar (aQute.bnd.osgi.Jar)4 Resource (aQute.bnd.osgi.Resource)4 XmlTester (aQute.bnd.test.XmlTester)4 Attributes (java.util.jar.Attributes)4 Matchers.anyString (org.mockito.Matchers.anyString)4 PrintStream (java.io.PrintStream)2 List (java.util.List)2 Utils.copyToTempFile (org.example.tests.utils.Utils.copyToTempFile)2 ServiceReference (org.osgi.framework.ServiceReference)2 Resource (org.osgi.service.indexer.Resource)2 ResourceAnalyzer (org.osgi.service.indexer.ResourceAnalyzer)2 ResourceIndexer (org.osgi.service.indexer.ResourceIndexer)2 Run (aQute.bnd.build.Run)1 Workspace (aQute.bnd.build.Workspace)1 IOException (java.io.IOException)1