### Question:
NarBundleExtractor implements BundleExtractor { @Override public BundleDetails extract(final InputStream inputStream) throws IOException { try (final JarInputStream jarInputStream = new JarInputStream(inputStream)) { final Manifest manifest = jarInputStream.getManifest(); if (manifest == null) { throw new BundleException("NAR bundles must contain a valid MANIFEST"); } final Attributes attributes = manifest.getMainAttributes(); final BundleIdentifier bundleIdentifier = getBundleCoordinate(attributes); final BundleIdentifier dependencyCoordinate = getDependencyBundleCoordinate(attributes); final BuildInfo buildInfo = getBuildInfo(attributes); final BundleDetails.Builder builder = new BundleDetails.Builder() .coordinate(bundleIdentifier) .addDependencyCoordinate(dependencyCoordinate) .buildInfo(buildInfo); parseExtensionDocs(jarInputStream, builder); return builder.build(); } }  @Override BundleDetails extract(final InputStream inputStream); boolean isBlank(String value);  }### Answer:
@Test(expected = BundleException.class) public void testExtractFromNarMissingExtensionDescriptor() throws IOException { try (final InputStream in = new FileInputStream("src/test/resources/nars/nifi-foo-nar-missing-extension-descriptor.nar")) { extractor.extract(in); fail("Should have thrown exception"); } }
@Test public void testExtractFromGoodNarNoDependencies() throws IOException { try (final InputStream in = new FileInputStream("src/test/resources/nars/nifi-framework-nar.nar")) { final BundleDetails bundleDetails = extractor.extract(in); assertNotNull(bundleDetails); assertNotNull(bundleDetails.getBundleIdentifier()); assertNotNull(bundleDetails.getDependencies()); assertEquals(0, bundleDetails.getDependencies().size()); final BundleIdentifier bundleIdentifier = bundleDetails.getBundleIdentifier(); assertEquals("org.apache.nifi", bundleIdentifier.getGroupId()); assertEquals("nifi-framework-nar", bundleIdentifier.getArtifactId()); assertEquals("1.8.0", bundleIdentifier.getVersion()); assertNotNull(bundleDetails.getExtensions()); assertEquals(0, bundleDetails.getExtensions().size()); assertEquals("1.8.0", bundleDetails.getSystemApiVersion()); } }
@Test public void testExtractFromGoodNarWithDependencies() throws IOException { try (final InputStream in = new FileInputStream("src/test/resources/nars/nifi-foo-nar.nar")) { final BundleDetails bundleDetails = extractor.extract(in); assertNotNull(bundleDetails); assertNotNull(bundleDetails.getBundleIdentifier()); assertNotNull(bundleDetails.getDependencies()); assertEquals(1, bundleDetails.getDependencies().size()); final BundleIdentifier bundleIdentifier = bundleDetails.getBundleIdentifier(); assertEquals("org.apache.nifi", bundleIdentifier.getGroupId()); assertEquals("nifi-foo-nar", bundleIdentifier.getArtifactId()); assertEquals("1.8.0", bundleIdentifier.getVersion()); final BundleIdentifier dependencyCoordinate = bundleDetails.getDependencies().stream().findFirst().get(); assertEquals("org.apache.nifi", dependencyCoordinate.getGroupId()); assertEquals("nifi-bar-nar", dependencyCoordinate.getArtifactId()); assertEquals("2.0.0", dependencyCoordinate.getVersion()); final Map<String,String> additionalDetails = bundleDetails.getAdditionalDetails(); assertNotNull(additionalDetails); assertEquals(0, additionalDetails.size()); } }
@Test(expected = BundleException.class) public void testExtractFromNarMissingRequiredManifestEntries() throws IOException { try (final InputStream in = new FileInputStream("src/test/resources/nars/nifi-missing-manifest-entries.nar")) { extractor.extract(in); fail("Should have thrown exception"); } }
@Test(expected = BundleException.class) public void testExtractFromNarMissingManifest() throws IOException { try (final InputStream in = new FileInputStream("src/test/resources/nars/nifi-missing-manifest.nar")) { extractor.extract(in); fail("Should have thrown exception"); } }