some more bundleimpl tests
diff --git a/winegrower-core/src/test/java/org/apache/winegrower/deployer/BundleImplTest.java b/winegrower-core/src/test/java/org/apache/winegrower/deployer/BundleImplTest.java
index 23b2649..db93eb1 100644
--- a/winegrower-core/src/test/java/org/apache/winegrower/deployer/BundleImplTest.java
+++ b/winegrower-core/src/test/java/org/apache/winegrower/deployer/BundleImplTest.java
@@ -16,6 +16,8 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream;
@@ -23,6 +25,7 @@
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
+import java.util.Dictionary;
import java.util.Enumeration;
import java.util.jar.Manifest;
@@ -32,16 +35,18 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.osgi.framework.Bundle;
+import org.osgi.framework.wiring.BundleWiring;
class BundleImplTest {
private static BundleImpl bundle;
+ private static BundleRegistry registry;
@BeforeAll
static void initBundle() throws IOException {
final Manifest manifest = new Manifest(new ByteArrayInputStream(("Manifest-Version: 1.0\nBundle-Version: 1.0\nBundle-SymbolicName: test\n").getBytes(StandardCharsets.UTF_8)));
final Ripener.Configuration configuration = new Ripener.Configuration();
final OSGiServices services = new OSGiServices(new Ripener.Impl(configuration));
- final BundleRegistry registry = new BundleRegistry(services, configuration);
+ registry = new BundleRegistry(services, configuration);
final BundleContextImpl context = new BundleContextImpl(manifest, services, () -> bundle, registry);
final File file = new File(registry.getFramework().getParentFile(), "test-classes");
bundle = new BundleImpl(manifest, file, context, configuration, 1);
@@ -49,11 +54,63 @@
}
@Test
+ void adaptBundleWiring() {
+ assertNotNull(bundle.adapt(BundleWiring.class));
+ }
+
+ @Test
+ void adaptMissing() {
+ assertNull(bundle.adapt(String.class));
+ }
+
+ @Test
+ void compareToSame() {
+ assertEquals(0, bundle.compareTo(bundle));
+ }
+
+ @Test
+ void compareToOther() {
+ assertEquals(1, bundle.compareTo(registry.getBundles().get(0L).getBundle()));
+ }
+
+ @Test
void hasId() {
assertEquals(1L, bundle.getBundleId());
}
@Test
+ void lastModified() {
+ assertEquals(new File(bundle.getLocation()).lastModified(), bundle.getLastModified());
+ }
+
+ @Test
+ void location() {
+ assertEquals(new File(registry.getFramework().getParentFile(), "test-classes").getAbsolutePath(), bundle.getLocation());
+ }
+
+ @Test
+ void registeredServices() {
+ assertEquals(0, bundle.getRegisteredServices().length);
+ }
+
+ @Test
+ void getResource() {
+ assertNotNull(bundle.getResource("org"));
+ assertNull(bundle.getResource("javax"));
+ }
+
+ @Test
+ void getResources() throws IOException {
+ assertTrue(bundle.getResources("org").hasMoreElements());
+ assertFalse(bundle.getResources("javax").hasMoreElements());
+ }
+
+ @Test
+ void getEntry() {
+ assertNotNull(bundle.getEntry("org"));
+ }
+
+ @Test
void getEntryPaths() {
final Enumeration<String> entries = bundle.getEntryPaths("org/apache/winegrower/test/simpleservice/META-INF");
assertTrue(entries.hasMoreElements());
@@ -110,5 +167,17 @@
@Test
void loadClass() throws ClassNotFoundException {
assertNotNull(bundle.loadClass("org.apache.winegrower.test.simpleservice.MyServiceImpl"));
+ assertThrows(ClassNotFoundException.class, () -> bundle.loadClass(BundleImplTest.class.getName() + "$Missing"));
+ }
+
+ @Test
+ void headers() {
+ final Dictionary<String, String> headers = bundle.getHeaders();
+ assertEquals("test", headers.get("Bundle-SymbolicName"));
+ }
+
+ @Test
+ void headersWithLocale() {
+ assertEquals(bundle.getHeaders(), bundle.getHeaders("en"));
}
}