forked from jenkinsci/acceptance-test-harness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AbstractJUnitTest.java
72 lines (61 loc) · 2.14 KB
/
AbstractJUnitTest.java
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
66
67
68
69
70
71
72
package org.jenkinsci.test.acceptance.junit;
import jakarta.inject.Inject;
import java.io.IOException;
import java.net.ServerSocket;
import java.util.logging.Logger;
import org.jenkinsci.test.acceptance.po.CapybaraPortingLayerImpl;
import org.jenkinsci.test.acceptance.po.Jenkins;
import org.jenkinsci.test.acceptance.recorder.SupportBundle;
import org.jenkinsci.test.acceptance.utils.SupportBundleRequest;
import org.junit.After;
import org.junit.Rule;
import org.openqa.selenium.WebDriver;
/**
* Convenience base class to derive your plain-old JUnit tests from.
* <p>
* It provides a number of convenience methods, and sets up the correct test runner.
*
* @author Kohsuke Kawaguchi
*/
public class AbstractJUnitTest extends CapybaraPortingLayerImpl {
private static final Logger LOGGER = Logger.getLogger(AbstractJUnitTest.class.getName());
@Rule
public JenkinsAcceptanceTestRule rules = new JenkinsAcceptanceTestRule();
/**
* Jenkins under test.
*/
@Inject
public Jenkins jenkins;
@Inject
private FailureDiagnostics diagnostics;
@Rule(order = 0) // enclosed by JenkinsAcceptanceTestRule so that we have a valid Jenkins + webdriver
public SupportBundle supportBundle = new SupportBundle();
/**
* This field receives a valid web driver object you can use to talk to Jenkins.
*/
@Inject
public WebDriver driver;
public AbstractJUnitTest() {
super(null);
}
/**
* @return finds an unused, available port on the test machine
*/
public int findAvailablePort() {
// use port 65000 as fallback (but maybe there is something running)
int port = 65000;
try (ServerSocket s = new ServerSocket(0)) {
port = s.getLocalPort();
} catch (IOException e) {
e.printStackTrace();
}
return port;
}
protected void interrupt() {
throw new RuntimeException("INTERACTIVE debugging");
}
@After
public void injectSpec() {
supportBundle.addSpec(jenkins, SupportBundleRequest.builder().includeDefaultComponents().setOutputFile(diagnostics.touch("support-bundle.zip")).build());
}
}