MountInfoProviderService { @Activate private void activate(BundleContext bundleContext, Map<String, ?> config) { String[] paths = PropertiesUtil.toStringArray(config.get(PROP_MOUNT_PATHS)); String mountName = PropertiesUtil.toString(config.get(PROP_MOUNT_NAME), PROP_MOUNT_NAME_DEFAULT); boolean readOnly = PropertiesUtil.toBoolean(config.get(PROP_MOUNT_READONLY), PROP_MOUNT_READONLY_DEFAULT); String[] pathsSupportingFragments = PropertiesUtil.toStringArray(config.get(PROP_PATHS_SUPPORTING_FRAGMENTS), PROP_PATHS_SUPPORTING_FRAGMENTS_DEFAULT); MountInfoProvider mip = Mounts.defaultMountInfoProvider(); if (paths != null) { mip = Mounts.newBuilder() .mount(mountName.trim(), readOnly, trim(pathsSupportingFragments), trim(paths)) .build(); log.info("Enabling mount for {}", mip); } else { log.info("No mount config provided. Mounting would be disabled"); } reg = bundleContext.registerService(MountInfoProvider.class.getName(), mip, null); }    }
@Test public void mountWithConfig_Paths() throws Exception{ MockOsgi.activate(service, context.bundleContext(), ImmutableMap.<String, Object>of("mountedPaths", new String[] {"/a", "/b"})); MountInfoProvider provider = context.getService(MountInfoProvider.class); assertEquals(1, provider.getNonDefaultMounts().size()); Mount m = provider.getMountByName(MountInfoProviderService.PROP_MOUNT_NAME_DEFAULT); assertNotNull(m); Mount defMount = provider.getDefaultMount(); assertNotNull(defMount); assertFalse(m.isReadOnly()); assertEquals(m, provider.getMountByPath("/a")); assertEquals(defMount, provider.getMountByPath("/x")); }
@Test public void mountWithConfig_Name() throws Exception{ MockOsgi.activate(service, context.bundleContext(), ImmutableMap.<String, Object>of( "mountedPaths", new String[] {"/a", "/b"}, "mountName", "foo", "readOnlyMount", true )); MountInfoProvider provider = context.getService(MountInfoProvider.class); assertEquals(1, provider.getNonDefaultMounts().size()); Mount m = provider.getMountByName(MountInfoProviderService.PROP_MOUNT_NAME_DEFAULT); assertNull(m); Mount defMount = provider.getDefaultMount(); assertNotNull(defMount); m = provider.getMountByName("foo"); assertEquals(m, provider.getMountByPath("/a")); assertEquals(defMount, provider.getMountByPath("/x")); assertTrue(m.isReadOnly()); }