11
11
import java .nio .file .StandardOpenOption ;
12
12
import java .util .Map ;
13
13
import org .junit .After ;
14
- import org .junit .AfterClass ;
15
- import org .junit .BeforeClass ;
14
+ import org .junit .Before ;
16
15
import org .junit .Rule ;
17
16
import org .junit .Test ;
18
- import org .jvnet .hudson .test .JenkinsRule ;
17
+ import org .jvnet .hudson .test .JenkinsSessionRule ;
19
18
20
19
/**
21
20
* Tests for the {@link NodeRemoteDirectoryComponent}
22
21
*/
23
22
public class NodeRemoteDirectoryComponentTest {
24
23
25
24
@ Rule
26
- public JenkinsRule j = new JenkinsRule ();
25
+ public JenkinsSessionRule r = new JenkinsSessionRule ();
27
26
28
- @ BeforeClass
29
- public static void clearLog () throws Exception {
27
+ @ Before
28
+ public void clearLog () throws Throwable {
30
29
try (var os =
31
30
Files .newOutputStream (SafeLog .file , StandardOpenOption .CREATE , StandardOpenOption .TRUNCATE_EXISTING )) {}
32
31
System .err .println ("Cleared " + SafeLog .file );
33
32
}
34
33
35
34
@ After
36
- public void showLog () throws Exception {
37
- System .err .println ("---%<--- " + SafeLog .file );
38
- Files .copy (SafeLog .file , System .err );
39
- System .err .println ("--->%--- " );
40
- }
41
-
42
- @ AfterClass
43
- public static void showFinalLog () throws Exception {
35
+ public void showLog () throws Throwable {
44
36
System .err .println ("---%<--- " + SafeLog .file );
45
37
Files .copy (SafeLog .file , System .err );
46
38
System .err .println ("--->%--- " );
@@ -50,61 +42,69 @@ public static void showFinalLog() throws Exception {
50
42
* Test adding agent remote directory content with the defaults.
51
43
*/
52
44
@ Test
53
- public void addContents () throws Exception {
54
- DumbSlave agent = j .createOnlineSlave (Label .parseExpression ("test" ), null );
45
+ public void addContents () throws Throwable {
46
+ r .then (j -> {
47
+ DumbSlave agent = j .createOnlineSlave (Label .parseExpression ("test" ), null );
55
48
56
- Map <String , String > output =
57
- SupportTestUtils .invokeComponentToMap (new NodeRemoteDirectoryComponent (), agent .toComputer ());
49
+ Map <String , String > output =
50
+ SupportTestUtils .invokeComponentToMap (new NodeRemoteDirectoryComponent (), agent .toComputer ());
58
51
59
- String prefix = "nodes/slave/" + agent .getNodeName () + "/remote" ;
60
- assertTrue (output .keySet ().stream ().anyMatch (key -> key .matches (prefix + "/support/.*.log" )));
52
+ String prefix = "nodes/slave/" + agent .getNodeName () + "/remote" ;
53
+ assertTrue (output .keySet ().stream ().anyMatch (key -> key .matches (prefix + "/support/.*.log" )));
54
+ });
61
55
}
62
56
63
57
/*
64
58
* Test adding agent remote directory content with excludes pattern(s).
65
59
*/
66
60
@ Test
67
- public void addContentsWithExcludes () throws Exception {
68
- DumbSlave agent = j .createSlave ("agent1" , "test" , null );
69
- agent .getComputer ().connect (false ).get ();
70
- j .waitOnline (agent );
71
-
72
- Map <String , String > output = SupportTestUtils .invokeComponentToMap (
73
- new NodeRemoteDirectoryComponent ("" , "**/*.log" , true , 10 ), agent .toComputer ());
74
-
75
- String prefix = "nodes/slave/" + agent .getNodeName () + "/remote" ;
76
- assertFalse (output .keySet ().stream ().anyMatch (key -> key .matches (prefix + ".*/.*.log" )));
61
+ public void addContentsWithExcludes () throws Throwable {
62
+ r .then (j -> {
63
+ DumbSlave agent = j .createSlave ("agent1" , "test" , null );
64
+ agent .getComputer ().connect (false ).get ();
65
+ j .waitOnline (agent );
66
+
67
+ Map <String , String > output = SupportTestUtils .invokeComponentToMap (
68
+ new NodeRemoteDirectoryComponent ("" , "**/*.log" , true , 10 ), agent .toComputer ());
69
+
70
+ String prefix = "nodes/slave/" + agent .getNodeName () + "/remote" ;
71
+ assertFalse (output .keySet ().stream ().anyMatch (key -> key .matches (prefix + ".*/.*.log" )));
72
+ });
77
73
}
78
74
79
75
/*
80
76
* Test adding agent remote directory content with includes pattern(s).
81
77
*/
82
78
@ Test
83
- public void addContentsWithIncludes () throws Exception {
84
- DumbSlave agent = j .createSlave ("agent1" , "test" , null );
85
- agent .getComputer ().connect (false ).get ();
86
- j .waitOnline (agent );
87
-
88
- Map <String , String > output = SupportTestUtils .invokeComponentToMap (
89
- new NodeRemoteDirectoryComponent ("support/*.log" , "" , true , 10 ), agent .toComputer ());
90
-
91
- String prefix = "nodes/slave/" + agent .getNodeName () + "/remote" ;
92
- assertTrue (output .keySet ().stream ().anyMatch (key -> key .matches (prefix + "/support/.*.log" )));
79
+ public void addContentsWithIncludes () throws Throwable {
80
+ r .then (j -> {
81
+ DumbSlave agent = j .createSlave ("agent1" , "test" , null );
82
+ agent .getComputer ().connect (false ).get ();
83
+ j .waitOnline (agent );
84
+
85
+ Map <String , String > output = SupportTestUtils .invokeComponentToMap (
86
+ new NodeRemoteDirectoryComponent ("support/*.log" , "" , true , 10 ), agent .toComputer ());
87
+
88
+ String prefix = "nodes/slave/" + agent .getNodeName () + "/remote" ;
89
+ assertTrue (output .keySet ().stream ().anyMatch (key -> key .matches (prefix + "/support/.*.log" )));
90
+ });
93
91
}
94
92
95
93
/*
96
94
* Test adding agent remote directory content with includes pattern(s).
97
95
*/
98
96
@ Test
99
- public void addContentsWithMaxDepth () throws Exception {
100
- DumbSlave agent = j .createSlave ("agent1" , "test" , null );
101
- agent .getComputer ().connect (false ).get ();
102
- j .waitOnline (agent );
103
-
104
- Map <String , String > output = SupportTestUtils .invokeComponentToMap (
105
- new NodeRemoteDirectoryComponent ("" , "" , true , 1 ), agent .toComputer ());
106
-
107
- String prefix = "nodes/slave/" + agent .getNodeName () + "/remote" ;
108
- assertFalse (output .keySet ().stream ().anyMatch (key -> key .matches (prefix + "/support/.*.log" )));
97
+ public void addContentsWithMaxDepth () throws Throwable {
98
+ r .then (j -> {
99
+ DumbSlave agent = j .createSlave ("agent1" , "test" , null );
100
+ agent .getComputer ().connect (false ).get ();
101
+ j .waitOnline (agent );
102
+
103
+ Map <String , String > output = SupportTestUtils .invokeComponentToMap (
104
+ new NodeRemoteDirectoryComponent ("" , "" , true , 1 ), agent .toComputer ());
105
+
106
+ String prefix = "nodes/slave/" + agent .getNodeName () + "/remote" ;
107
+ assertFalse (output .keySet ().stream ().anyMatch (key -> key .matches (prefix + "/support/.*.log" )));
108
+ });
109
109
}
110
110
}
0 commit comments