blob: 97c2bf02d9b717eba97fbbb85b6230553ed5719f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.plugin.bundle;
import com.yahoo.container.plugin.osgi.ExportPackages;
import com.yahoo.container.plugin.osgi.ExportPackages.Export;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author Tony Vaagenes
* @author ollivir
*/
public class AnalyzeBundleTest {
private final List<Export> exports;
private final Map<String, Export> exportsByPackageName;
File jarDir = new File("src/test/resources/jar");
public AnalyzeBundleTest() {
File notOsgi = new File(jarDir, "notAOsgiBundle.jar");
File simple = new File(jarDir, "simple1.jar");
exports = AnalyzeBundle.exportedPackagesAggregated(List.of(notOsgi, simple));
exportsByPackageName = ExportPackages.exportsByPackageName(this.exports);
}
private File jarFile(String name) {
return new File(jarDir, name);
}
@Test
void require_that_non_osgi_bundles_are_ignored() {
assertFalse(exportsByPackageName.containsKey("com.yahoo.sample.exported.package.ignored"));
}
@Test
void require_that_exports_are_retrieved_from_manifest_in_jars() {
assertEquals(1, exportsByPackageName.keySet().size());
assertTrue(exportsByPackageName.containsKey("com.yahoo.sample.exported.package"));
}
@Test
void exported_class_names_can_be_retrieved() {
assertEquals(ExportPackages.packageNames(exports), exports.get(0).getPackageNames().stream().collect(Collectors.toSet()));
}
@Test
void require_that_invalid_exports_throws_exception() {
try {
AnalyzeBundle.exportedPackages(jarFile("errorExport.jar"));
fail();
} catch (RuntimeException e) {
assertTrue(e.getMessage().contains("Invalid manifest in bundle 'src/test/resources/jar/errorExport.jar'"));
assertTrue(e.getCause().getMessage().startsWith("Failed parsing Export-Package"), e.getCause().getMessage());
}
}
}
|