blob: 19be886d3e59814ae244b4fdbc2d0d1d70285b46 (
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.application.validation;
import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.vespa.model.application.validation.AbstractBundleValidator.JarContext;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author gjoranv
*/
public class PublicApiBundleValidatorTest {
@TempDir
public File tempDir;
@Test
void non_public_api_usage_is_picked_up_from_manifest() throws IOException {
var outputBuf = new StringBuffer();
var deployState = BundleValidatorTest.createDeployState(outputBuf);
var jarFile = BundleValidatorTest.createTemporaryJarFile(tempDir, "non-public-api");
var validator = new PublicApiBundleValidator();
validator.validateJarFile(new JarContext() {
@Override public void illegal(String error) { fail(); }
@Override public void illegal(String error, Throwable cause) { fail(); }
@Override public DeployState deployState() { return deployState; }
}, jarFile);
String output = outputBuf.toString();
assertThat(output, containsString("uses non-public Vespa APIs: ["));
// List of packages should be sorted
List<String> packages = Arrays.asList(output.substring(output.indexOf("[") + 1, output.indexOf("]")).split(", "));
assertThat(packages, hasSize(2));
assertThat(packages, contains("ai.vespa.lib.non_public", "com.yahoo.lib.non_public"));
}
}
|