blob: 79b48ec5a033cda37038c4e49d7536a973b5e962 (
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
|
package com.yahoo.container.plugin;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.stream.Collectors;
import static com.yahoo.container.plugin.BundleTest.findBundleJar;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests for a USER bundle that imports non-PublicApi packages.
*
* @author gjoranv
*/
public class NonPublicApiDetectionTest {
private static Attributes mainAttributes;
@BeforeAll
public static void setup() {
try {
File componentJar = findBundleJar("non-public-api-usage");
mainAttributes = new JarFile(componentJar).getManifest().getMainAttributes();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Test
void direct_usage_of_non_publicApi_packages_is_detected() {
var nonPublicApiAttribute = mainAttributes.getValue("X-JDisc-Non-PublicApi-Import-Package");
assertNotNull(nonPublicApiAttribute);
var usedNonPublicApi = Arrays.stream(nonPublicApiAttribute.split(",")).collect(Collectors.toSet());
// Package 'ai.vespa.internal' is only used indirectly by the compile scoped dependency, and must not be included.
assertFalse(usedNonPublicApi.contains("ai.vespa.internal"));
assertEquals(2, usedNonPublicApi.size());
assertTrue(usedNonPublicApi.contains("ai.vespa.lib.non_public"));
assertTrue(usedNonPublicApi.contains("com.yahoo.lib.non_public"));
}
@Test
void vespa_version_is_added_to_manifest() {
var vespaVersionAttribute = mainAttributes.getValue("X-JDisc-Vespa-Build-Version");
assertNotNull(vespaVersionAttribute);
assertNotEquals("", vespaVersionAttribute);
}
}
|