Skip to content

Commit

Permalink
Merge branch 'master' into add-oic-auth-e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored Sep 10, 2024
2 parents d007fd0 + 0b6a9cf commit ecfdff1
Show file tree
Hide file tree
Showing 85 changed files with 200 additions and 256 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -107,7 +106,7 @@ private WebDriver createWebDriver(TestCleaner cleaner, TestName testName) throws
setDriverPropertyIfMissing("geckodriver", GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY);
GeckoDriverService.Builder builder = new GeckoDriverService.Builder();
if (display != null) {
builder.withEnvironment(Collections.singletonMap("DISPLAY", display));
builder.withEnvironment(Map.of("DISPLAY", display));
}
GeckoDriverService service = builder.build();
return new FirefoxDriver(service, buildFirefoxOptions(testName));
Expand All @@ -117,7 +116,7 @@ private WebDriver createWebDriver(TestCleaner cleaner, TestName testName) throws
case "chrome-container":
return createContainerWebDriver(cleaner, "selenium/standalone-chrome:4.24.0", new ChromeOptions());
case "chrome":
Map<String, String> prefs = new HashMap<String, String>();
Map<String, String> prefs = new HashMap<>();
prefs.put(LANGUAGE_SELECTOR, "en");
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
Expand Down Expand Up @@ -283,7 +282,7 @@ private Proxy createSeleniumProxy(String testName) throws UnknownHostException {
// if we are running maven locally but the browser elsewhere (e.g. docker) using the "127.0.0.1"
// address will not work for the browser
String name = System.getenv("SELENIUM_PROXY_HOSTNAME");
InetAddress proxyAddr = null;
InetAddress proxyAddr;
if (name != null) {
proxyAddr = InetAddress.getByName(name);
} else {
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/org/jenkinsci/test/acceptance/Matchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static Matcher<WebDriver> hasContent(final String content) {
}

public static Matcher<WebDriver> hasContent(final Pattern pattern) {
return new Matcher<WebDriver>("Text matching %s", pattern) {
return new Matcher<>("Text matching %s", pattern) {
// text captured the time matchesSafely was executed
private String pageText;

Expand All @@ -59,7 +59,7 @@ public void describeMismatchSafely(WebDriver item, Description mismatchDescripti
* Matches that matches {@link WebDriver} when it has an element that matches to the given selector.
*/
public static Matcher<WebDriver> hasElement(final By selector) {
return new Matcher<WebDriver>("contains element that matches %s", selector) {
return new Matcher<>("contains element that matches %s", selector) {
@Override
public boolean matchesSafely(WebDriver item) {
try {
Expand All @@ -78,7 +78,7 @@ public void describeMismatchSafely(WebDriver item, Description d) {
}

public static Matcher<WebDriver> hasURL(final URL url) {
return new Matcher<WebDriver>("URL matching %s", url) {
return new Matcher<>("URL matching %s", url) {
@Override
public boolean matchesSafely(WebDriver item) {
return item.getCurrentUrl().equals(url.toString());
Expand All @@ -95,7 +95,7 @@ public void describeMismatchSafely(WebDriver item, Description mismatchDescripti
* For asserting that a {@link PageObject}'s top page has an action of the given name.
*/
public static Matcher<PageObject> hasAction(final String displayName) {
return new Matcher<PageObject>("contains action titled %s", displayName) {
return new Matcher<>("contains action titled %s", displayName) {
@Override
public boolean matchesSafely(PageObject po) {
try {
Expand Down Expand Up @@ -147,7 +147,7 @@ public static org.hamcrest.Matcher<String> containsString(final String format, f
* Matches if a string contains a portion that matches to the regular expression.
*/
public static Matcher<String> containsRegexp(final Pattern re) {
return new Matcher<String>("Matches regexp %s", re.toString()) {
return new Matcher<>("Matches regexp %s", re.toString()) {
@Override
public boolean matchesSafely(String item) {
return re.matcher(item).find();
Expand All @@ -156,7 +156,7 @@ public boolean matchesSafely(String item) {
}

public static Matcher<PageObject> pageObjectExists() {
return new Matcher<PageObject>("Page object exists") {
return new Matcher<>("Page object exists") {
private @CheckForNull HttpURLConnection conn; // Store for later defect localization

@Override
Expand All @@ -178,7 +178,7 @@ public boolean matchesSafely(PageObject item) {
}

public static Matcher<PageObject> pageObjectDoesNotExist() {
return new Matcher<PageObject>("Page object does not exist") {
return new Matcher<>("Page object does not exist") {
private @CheckForNull HttpURLConnection conn; // Store for later defect localization

@Override
Expand All @@ -199,7 +199,7 @@ public boolean matchesSafely(PageObject item) {
}

public static Matcher<Jenkins> hasLoggedInUser(final String user) {
return new Matcher<Jenkins>("has logged in user %s", user) {
return new Matcher<>("has logged in user %s", user) {
@Override
public boolean matchesSafely(final Jenkins jenkins) {
final User currentUser = jenkins.getCurrentUser();
Expand All @@ -217,7 +217,7 @@ public void describeMismatchSafely(final Jenkins item, final Description desc) {
}

public static Matcher<Login> loggedInAs(final String user) {
return new Matcher<Login>("has logged in user %s", user) {
return new Matcher<>("has logged in user %s", user) {
@Override
public boolean matchesSafely(final Login login) {
final User currentUser = login.getJenkins().getCurrentUser();
Expand All @@ -235,7 +235,7 @@ public void describeMismatchSafely(final Login item, final Description desc) {
}

public static Matcher<Login> hasInvalidLoginInformation() {
return new Matcher<Login>("has invalid login information message") {
return new Matcher<>("has invalid login information message") {
@Override
public boolean matchesSafely(final Login login) {
try {
Expand All @@ -254,7 +254,7 @@ public void describeMismatchSafely(final Login item, final Description desc) {
}

public static Matcher<User> isMemberOf(final String group) {
return new Matcher<User>(" is member of group %s", group) {
return new Matcher<>(" is member of group %s", group) {
@Override
public boolean matchesSafely(final User user) {
user.open();
Expand All @@ -279,7 +279,7 @@ public void describeMismatchSafely(final User item, final Description desc) {
}

public static Matcher<User> fullNameIs(final String fullName) {
return new Matcher<User>(" full name is %s", fullName) {
return new Matcher<>(" full name is %s", fullName) {
@Override
public boolean matchesSafely(final User user) {
if (user.fullName() != null) {
Expand All @@ -296,7 +296,7 @@ public void describeMismatchSafely(final User item, final Description desc) {
}

public static Matcher<User> mailAddressIs(final String mail) {
return new Matcher<User>(" mail address is %s", mail) {
return new Matcher<>(" mail address is %s", mail) {
@Override
public boolean matchesSafely(final User user) {
if (user.mail() != null) {
Expand All @@ -313,7 +313,7 @@ public void describeMismatchSafely(final User item, final Description desc) {
}

public static Matcher<File> existingFile() {
return new Matcher<File>("an existing file") {
return new Matcher<>("an existing file") {
@Override
public boolean matchesSafely(final File item) {
return item.exists() && item.isFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import org.codehaus.plexus.util.FileUtils;
import java.nio.file.Files;
import org.apache.commons.io.FileUtils;
import org.jenkinsci.test.acceptance.utils.IOUtil;
import org.jenkinsci.utils.process.CommandBuilder;
import org.jenkinsci.utils.process.ProcessInputStream;
Expand Down Expand Up @@ -62,8 +63,8 @@ public ProcessInputStream startProcess() throws IOException {
if (context.exists()) {
org.apache.commons.io.FileUtils.forceDelete(context);
}
org.apache.commons.io.FileUtils.write(
context,
Files.writeString(
context.toPath(),
"<Context>\n"
+ " <Parameter name=\"jenkins.formelementpath.FormElementPathPageDecorator.enabled\" value=\"true\"/>\n"
+ "</Context>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Date;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.input.TeeInputStream;
import org.jenkinsci.test.acceptance.log.LogListenable;
import org.jenkinsci.test.acceptance.log.LogListener;
Expand Down Expand Up @@ -110,7 +110,7 @@ private String failedToLoadMessage() {
msg += "\nprocess is " + (reader.isAlive() ? "alive" : "dead");
msg += "\nnow = " + new Date();
try {
msg += "\n" + FileUtils.readFileToString(logFile, StandardCharsets.UTF_8);
msg += "\n" + Files.readString(logFile.toPath(), StandardCharsets.UTF_8);
} catch (IOException ignored) {
// ignore
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.codehaus.plexus.util.Expand;
import org.codehaus.plexus.util.StringUtils;
import org.jenkinsci.test.acceptance.junit.FailureDiagnostics;
import org.jenkinsci.test.acceptance.log.LogListenable;
import org.jenkinsci.test.acceptance.log.LogListener;
Expand Down Expand Up @@ -148,7 +148,7 @@ public void populateJenkinsHome(byte[] _template, boolean clean) throws IOExcept
}
File template = File.createTempFile("template", ".dat");
try {
FileUtils.writeByteArrayToFile(template, _template);
Files.write(template.toPath(), _template);
Expand expand = new Expand();
expand.setSrc(template);
expand.setOverwrite(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import org.apache.commons.io.FileUtils;
import org.jenkinsci.test.acceptance.utils.IOUtil;
import org.jenkinsci.utils.process.CommandBuilder;
Expand Down Expand Up @@ -56,8 +57,8 @@ public ProcessInputStream startProcess() throws IOException {
if (context.exists()) {
FileUtils.forceDelete(context);
}
FileUtils.write(
context,
Files.writeString(
context.toPath(),
"<Context>\n"
+ " <Parameter name=\"jenkins.formelementpath.FormElementPathPageDecorator.enabled\" value=\"true\"/>\n"
+ "</Context>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.logging.Logger;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.jenkinsci.utils.process.CommandBuilder;
import org.jenkinsci.utils.process.ProcessInputStream;
Expand All @@ -37,7 +36,7 @@ protected static List<String> envVarOpts(String jenkins_opts) {
if (getenv == null) {
return Collections.emptyList();
}
return Arrays.asList(getenv.split("\\s+"));
return List.of(getenv.split("\\s+"));
}

public void addJavaOpt(String javaOpt) {
Expand All @@ -61,7 +60,7 @@ public WinstoneController(Injector i, int httpPort) {
@Override
protected void onReady() throws IOException {
if (this.httpPort == 0 && portFile != null) {
String s = FileUtils.readFileToString(portFile, StandardCharsets.UTF_8);
String s = Files.readString(portFile.toPath(), StandardCharsets.UTF_8);
try {
this.httpPort = Integer.parseInt(s);
} catch (NumberFormatException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ public HttpResponse<String> createRepo(String repoName, String token) throws Run
.header("PRIVATE-TOKEN", token)
.POST(HttpRequest.BodyPublishers.ofString("{ \"name\": \"" + repoName + "\" }"))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
return response;
return client.send(request, HttpResponse.BodyHandlers.ofString());
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import javax.xml.rpc.ServiceException;
import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -96,7 +95,7 @@ private void connect() throws IOException, ServiceException {

public List<RemoteComment> getComments(String ticket) throws IOException, ServiceException {
connect();
return Arrays.asList(svc.getComments(token, ticket));
return List.of(svc.getComments(token, ticket));
}

public JiraSoapService getSvc() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.codehaus.plexus.util.FileUtils;
import java.util.stream.Stream;
import org.apache.commons.io.FileUtils;
import org.jenkinsci.test.acceptance.guice.TestName;
import org.jenkinsci.test.acceptance.guice.TestScope;
import org.junit.rules.TestWatcher;
Expand Down Expand Up @@ -103,8 +105,8 @@ protected void succeeded(Description description) {
@Override
public void failed(Throwable e, Description description) {
if (dir.exists()) {
try {
Files.walk(dir.toPath()).forEach(p -> {
try (Stream<Path> stream = Files.walk(dir.toPath())) {
stream.forEach(p -> {
if (Files.isRegularFile(p)) {
// https://wiki.jenkins-ci.org/display/JENKINS/JUnit+Attachments+Plugin#JUnitAttachmentsPlugin-ByprintingoutthefilenameinaformatthatJenkinswillunderstand
System.out.printf((JUNIT_ATTACHMENT) + "%n", p.toAbsolutePath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

import com.google.inject.Inject;
import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.jenkinsci.test.acceptance.guice.World;
import org.junit.Assume;
Expand Down Expand Up @@ -70,17 +70,17 @@ public abstract static class Filter {
public abstract String whySkip(Statement base, Description description);

public static <T extends Annotation> Set<T> getAnnotations(Description description, Class<T> type) {
Set<T> annotations = new HashSet<T>();
Set<T> annotations = new HashSet<>();
annotations.add(description.getAnnotation(type));
annotations.add(description.getTestClass().getAnnotation(type));
annotations.remove(null);
return annotations;
}

public static Set<Annotation> getAnnotations(Description description) {
Set<Annotation> annotations = new HashSet<Annotation>();
Set<Annotation> annotations = new HashSet<>();
annotations.addAll(description.getAnnotations());
annotations.addAll(Arrays.asList(description.getTestClass().getAnnotations()));
annotations.addAll(List.of(description.getTestClass().getAnnotations()));
return annotations;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @author Ullrich Hafner
*/
public class JUnitProgressReporter extends RunListener {
private final Set<String> results = new CopyOnWriteArraySet<String>();
private final Set<String> results = new CopyOnWriteArraySet<>();

@Override
public void testStarted(final Description description) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private Statement decorateWithRules(Statement body) {
collectGlobalRules(rules);

// Make sure Jenkins is started between -1 and 0
rules.computeIfAbsent(0, k -> new LinkedHashSet<TestRule>());
rules.computeIfAbsent(0, k -> new LinkedHashSet<>());
rules.get(0).add(jenkinsBoot(rules));

for (Set<TestRule> rulesGroup : rules.values()) {
Expand Down
Loading

0 comments on commit ecfdff1

Please sign in to comment.