### Question:
OsgiBundleFactory implements PluginFactory { public String canCreate(PluginArtifact pluginArtifact) throws PluginParseException { Validate.notNull(pluginArtifact, "The plugin artifact is required"); String pluginKey = null; InputStream manifestStream = null; InputStream descriptorStream = null; try { manifestStream = pluginArtifact.getResourceAsStream("META-INF/MANIFEST.MF"); if (manifestStream != null) { Manifest mf; try { mf = new Manifest(manifestStream); } catch (IOException e) { throw new PluginParseException("Unable to parse manifest", e); } String symName = mf.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME); if (symName != null) { pluginKey = OsgiHeaderUtil.getPluginKey(mf); descriptorStream = pluginArtifact.getResourceAsStream(pluginDescriptorFileName); if (descriptorStream != null) { final DescriptorParser descriptorParser = descriptorParserFactory.getInstance(descriptorStream); if (descriptorParser.getPluginsVersion() == 1) { pluginKey = null; } } } } return pluginKey; } finally { IOUtils.closeQuietly(manifestStream); IOUtils.closeQuietly(descriptorStream); } } OsgiBundleFactory(OsgiContainerManager osgi, PluginEventManager pluginEventManager);  OsgiBundleFactory(String pluginDescriptorFileName, OsgiContainerManager osgi, PluginEventManager pluginEventManager); String canCreate(PluginArtifact pluginArtifact); Plugin create(DeploymentUnit deploymentUnit, ModuleDescriptorFactory moduleDescriptorFactory); Plugin create(PluginArtifact pluginArtifact, ModuleDescriptorFactory moduleDescriptorFactory);  }### Answer:
@Test public void testCanDeploy() throws PluginParseException, IOException { File bundle = new PluginJarBuilder("someplugin") .addResource("META-INF/MANIFEST.MF", "Manifest-Version: 1.0\n" + "Import-Package: javax.swing\n" + "Bundle-SymbolicName: my.foo.symbolicName\n" + "Bundle-Version: 1.0\n") .build(); assertEquals("my.foo.symbolicName-1.0", deployer.canCreate(new JarPluginArtifact(bundle))); }
@Test public void testCanDeployNoBundle() throws IOException, PluginParseException { File plugin = new PluginJarBuilder("someplugin") .addPluginInformation("my.foo.symb", "name", "1.0") .build(); assertNull(deployer.canCreate(new JarPluginArtifact(plugin))); }
@Test public void testCanDeployNonJar() throws IOException, PluginParseException { final File tmp = File.createTempFile("foo", "bar"); assertNull(deployer.canCreate(new PluginArtifact() { public boolean doesResourceExist(String name) { return false; } public InputStream getResourceAsStream(String fileName) throws PluginParseException { return null; } public String getName() { return tmp.getPath(); } public InputStream getInputStream() { try { return new FileInputStream(tmp); } catch (FileNotFoundException e) { e.printStackTrace(); return null; } } public File toFile() { return tmp; } })); }
@Test public void testCanDeployStaticPluginWithManifest() throws PluginParseException, IOException { File bundle = new PluginJarBuilder("someplugin") .addResource("META-INF/MANIFEST.MF", "Manifest-Version: 1.0\n" + "Import-Package: javax.swing\n" + "Bundle-SymbolicName: my.foo.symbolicName\n" + "Bundle-Version: 1.0\n") .addPluginInformation("foo", "Foo", "1.0", 1) .build(); assertEquals(null, deployer.canCreate(new JarPluginArtifact(bundle))); }