-
-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathBrandingTest.java
More file actions
704 lines (639 loc) · 34.4 KB
/
BrandingTest.java
File metadata and controls
704 lines (639 loc) · 34.4 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
/*
* The MIT License
*
* Copyright (c) 2016 CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package integration;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.model.Action;
import hudson.model.Cause;
import hudson.model.CauseAction;
import hudson.model.FreeStyleProject;
import hudson.model.ListView;
import hudson.model.Result;
import hudson.model.TaskListener;
import hudson.model.TopLevelItem;
import hudson.views.JobColumn;
import hudson.views.StatusColumn;
import hudson.views.WeatherColumn;
import integration.harness.BasicMultiBranchProject;
import integration.harness.BasicMultiBranchProjectFactory;
import jenkins.branch.Branch;
import jenkins.branch.BranchIndexingCause;
import jenkins.branch.BranchSource;
import jenkins.branch.DescriptionColumn;
import jenkins.branch.MultiBranchProject;
import jenkins.branch.OrganizationFolder;
import jenkins.scm.api.SCMEvent;
import jenkins.scm.api.SCMEvents;
import jenkins.scm.api.SCMHeadEvent;
import jenkins.scm.api.SCMRevision;
import jenkins.scm.api.SCMSourceEvent;
import jenkins.scm.api.metadata.ObjectMetadataAction;
import jenkins.scm.impl.mock.MockSCMController;
import jenkins.scm.impl.mock.MockSCMDiscoverBranches;
import jenkins.scm.impl.mock.MockSCMLink;
import jenkins.scm.impl.mock.MockSCMNavigator;
import jenkins.scm.impl.mock.MockSCMSource;
import jenkins.scm.impl.mock.MockSCMSourceEvent;
import org.htmlunit.html.HtmlAnchor;
import org.htmlunit.html.HtmlPage;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
@WithJenkins
class BrandingTest {
/**
* All tests in this class only create items and do not affect other global configuration, thus we trade test
* execution time for the restriction on only touching items.
*/
private static JenkinsRule r;
@BeforeAll
static void setUp(JenkinsRule rule) {
r = rule;
}
@BeforeEach
void setUp() throws Exception {
for (TopLevelItem i : r.getInstance().getItems()) {
i.delete();
}
}
@Test
void given_multibranch_when_noSourcesDefined_then_noSourceBrandingPresent() throws Exception {
try (MockSCMController c = MockSCMController.create()) {
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
assertThat(prj.getAction(MockSCMLink.class), nullValue());
}
}
@Test
void given_multibranch_when_sourceDefined_then_sourceBrandingPresentAfterIndexing()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
prj.getSourcesList().add(new BranchSource(new MockSCMSource(c, "foo", new MockSCMDiscoverBranches())));
assertThat(prj.getAction(MockSCMLink.class), nullValue());
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
assertThat(prj.getAction(MockSCMLink.class), hasProperty("id", is("source")));
}
}
@Test
void given_multibranch_when_sourceDefined_then_sourceBrandingPresentAfterSourceEvent()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
prj.getSourcesList().add(new BranchSource(new MockSCMSource(c, "foo", new MockSCMDiscoverBranches())));
assertThat(prj.getAction(MockSCMLink.class), nullValue());
fire(new MockSCMSourceEvent(null, SCMEvent.Type.UPDATED, c, "foo"));
r.waitUntilNoActivity();
assertThat(prj.getAction(MockSCMLink.class), hasProperty("id", is("source")));
}
}
@Test
void given_multibranch_when_branches_then_branchBrandingPresent()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
prj.getSourcesList().add(new BranchSource(new MockSCMSource(c, "foo", new MockSCMDiscoverBranches())));
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
assertThat(prj.getItem("master").getAction(MockSCMLink.class), hasProperty("id", is("branch")));
}
}
@Test
void given_multibranch_when_branches_then_runBrandingPresent()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
prj.getSourcesList().add(new BranchSource(new MockSCMSource(c, "foo", new MockSCMDiscoverBranches())));
assertThat(prj.getAction(MockSCMLink.class), nullValue());
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
assertThat(prj.getItem("master").getBuildByNumber(1).getAction(MockSCMLink.class),
hasProperty("id", is("revision")));
}
}
@Test
@Issue("JENKINS-48090")
void given_multibranch_when_runBrandingIncludesAdditionalCauses_then_causesMerged() throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
prj.getSourcesList().add(new BranchSource(new BrandedMockSCMSource(c)));
assertThat(prj.getAction(MockSCMLink.class), nullValue());
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
CauseAction causeAction = prj.getItem("master").getBuildByNumber(1).getAction(CauseAction.class);
assertThat(causeAction.getCauses(), containsInAnyOrder(
instanceOf(BranchIndexingCause.class),
instanceOf(Cause.UserIdCause.class),
instanceOf(Cause.RemoteCause.class)
));
}
}
@Test
void given_orgFolder_when_noNavigatorsDefined_then_noNavigatorBrandingPresent() throws Exception {
try (MockSCMController c = MockSCMController.create()) {
OrganizationFolder prj = r.jenkins.createProject(OrganizationFolder.class, "foo");
assertThat(prj.getAction(MockSCMLink.class), nullValue());
}
}
@Test
void given_multibranch_when_sourceHasNonSafeNames_then_branchDisplayNameNotMangled() throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
c.createBranch("foo", ".");
c.createBranch("foo", "..");
c.createBranch("foo", "../..");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
prj.getSourcesList().add(new BranchSource(new MockSCMSource(c, "foo", new MockSCMDiscoverBranches())));
assertThat(prj.getAction(MockSCMLink.class), nullValue());
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
// now for the fun
FreeStyleProject master = null;
FreeStyleProject dot = null;
FreeStyleProject dotdot = null;
FreeStyleProject dotdotslashdotdot = null;
for (FreeStyleProject p : prj.getItems()) {
Branch branch = prj.getProjectFactory().getBranch(p);
String name = branch.getName();
if ("master".equals(name)) {
master = p;
} else if (".".equals(name)) {
dot = p;
} else if ("..".equals(name)) {
dotdot = p;
} else if ("../..".equals(name)) {
dotdotslashdotdot = p;
}
}
assertThat("We have the master branch", master, notNullValue());
assertThat("The master branch was built", master.getLastBuild(), notNullValue());
assertThat("The master branch build was success", master.getLastBuild().getResult(), is(Result.SUCCESS));
assertThat(master.getDisplayName(), is("master"));
assertThat(master.getName(), is("master"));
assertThat("We have the . branch", dot, notNullValue());
assertThat("The . branch was built", dot.getLastBuild(), notNullValue());
assertThat("The . branch build was success", dot.getLastBuild().getResult(), is(Result.SUCCESS));
assertThat(dot.getDisplayName(), is("."));
assertThat(dot.getName(), not(is(".")));
assertThat("We have the .. branch", dotdot, notNullValue());
assertThat("The .. branch was built", dotdot.getLastBuild(), notNullValue());
assertThat("The .. branch build was success", dotdot.getLastBuild().getResult(), is(Result.SUCCESS));
assertThat(dotdot.getDisplayName(), is(".."));
assertThat(dotdot.getName(), not(is("..")));
assertThat("We have the ../.. branch", dotdotslashdotdot, notNullValue());
assertThat("The ../.. branch was built", dotdotslashdotdot.getLastBuild(), notNullValue());
assertThat("The ../.. branch build was success", dotdotslashdotdot.getLastBuild().getResult(), is(Result.SUCCESS));
assertThat(dotdotslashdotdot.getDisplayName(), is("../.."));
assertThat(dotdotslashdotdot.getName(), not(is("../..")));
assertThat(prj.getItems(), containsInAnyOrder(master, dot, dotdot, dotdotslashdotdot));
}
}
@Test
void given_multibranch_when_sourceHasI18nNames_then_branchDisplayNameNotMangled() throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
c.createBranch("foo","特征/新");
c.createBranch("foo","특색/새로운");
c.createBranch("foo","gné/nua");
c.createBranch("foo","característica/nuevo");
c.createBranch("foo","особенность/новый");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
prj.getSourcesList().add(new BranchSource(new MockSCMSource(c, "foo", new MockSCMDiscoverBranches())));
assertThat(prj.getAction(MockSCMLink.class), nullValue());
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
// now for the fun
FreeStyleProject master = null;
FreeStyleProject irish = null;
FreeStyleProject chinese = null;
FreeStyleProject korean = null;
FreeStyleProject spanish = null;
FreeStyleProject russian = null;
for (FreeStyleProject p: prj.getItems()) {
Branch branch = prj.getProjectFactory().getBranch(p);
String name = branch.getName();
if ("master".equals(name)) {
master = p;
} else if ("gné/nua".equals(name)) {
irish = p;
} else if ("特征/新".equals(name)) {
chinese = p;
} else if ("특색/새로운".equals(name)) {
korean = p;
} else if ("característica/nuevo".equals(name)) {
spanish = p;
} else if ("особенность/новый".equals(name)) {
russian = p;
}
}
assertThat("We have the master branch", master, notNullValue());
assertThat("The master branch was built", master.getLastBuild(), notNullValue());
assertThat("The master branch build was success", master.getLastBuild().getResult(), is(Result.SUCCESS));
assertThat(master.getDisplayName(), is("master"));
assertThat(master.getName(), is("master"));
assertThat("We have the Irish branch", irish, notNullValue());
assertThat("The Irish branch was built", irish.getLastBuild(), notNullValue());
assertThat("The Irish branch build was success", irish.getLastBuild().getResult(), is(Result.SUCCESS));
assertThat(irish.getDisplayName(), is("gné/nua"));
assertThat(irish.getName(), not(is("gné/nua")));
assertThat("We have the Chinese branch", chinese, notNullValue());
assertThat("The Chinese branch was built", chinese.getLastBuild(), notNullValue());
assertThat("The Chinese branch build was success", chinese.getLastBuild().getResult(), is(Result.SUCCESS));
assertThat(chinese.getDisplayName(), is("特征/新"));
assertThat(chinese.getName(), not(is("特征/新")));
assertThat("We have the Korean branch", korean, notNullValue());
assertThat("The Korean branch was built", korean.getLastBuild(), notNullValue());
assertThat("The Korean branch build was success", korean.getLastBuild().getResult(), is(Result.SUCCESS));
assertThat(korean.getDisplayName(), is("특색/새로운"));
assertThat(korean.getName(), not(is("특색/새로운")));
assertThat("We have the Spanish branch", spanish, notNullValue());
assertThat("The Spanish branch was built", spanish.getLastBuild(), notNullValue());
assertThat("The Spanish branch build was success", spanish.getLastBuild().getResult(), is(Result.SUCCESS));
assertThat(spanish.getDisplayName(), is("característica/nuevo"));
assertThat(spanish.getName(), not(is("característica/nuevo")));
assertThat("We have the Russian branch", russian, notNullValue());
assertThat("The Russian branch was built", russian.getLastBuild(), notNullValue());
assertThat("The Russian branch build was success", russian.getLastBuild().getResult(), is(Result.SUCCESS));
assertThat(russian.getDisplayName(), is("особенность/новый"));
assertThat(russian.getName(), not(is("особенность/новый")));
assertThat(prj.getItems(), containsInAnyOrder(master, irish, chinese, korean, spanish, russian));
assertThat(prj.getItemByBranchName("master"), is(master));
assertThat(prj.getItemByBranchName("gné/nua"), is(irish));
assertThat(prj.getItemByBranchName("особенность/новый"), is(russian));
assertThat(prj.getItemByBranchName("特征/新"), is(chinese));
assertThat(prj.getItemByBranchName("característica/nuevo"), is(spanish));
assertThat(prj.getItemByBranchName("특색/새로운"), is(korean));
}
}
@Test
void given_orgFolder_when_navigatorDefined_then_navigatorBrandingPresentAfterIndexing()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
OrganizationFolder prj = r.jenkins.createProject(OrganizationFolder.class, "foo");
prj.getSCMNavigators().add(new MockSCMNavigator(c, new MockSCMDiscoverBranches()));
prj.getProjectFactories().replaceBy(Collections.singletonList(new BasicMultiBranchProjectFactory(null)));
assertThat(prj.getAction(MockSCMLink.class), nullValue());
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
assertThat(prj.getAction(MockSCMLink.class), hasProperty("id", is("organization")));
}
}
@Test
void given_orgFolderWithI18nRepos_when_indexing_then_repoNamesEncoded()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("England");
c.createRepository("Éireann");
c.createRepository("Россия");
c.createRepository("中国");
c.createRepository("España");
c.createRepository("대한민국");
OrganizationFolder prj = r.jenkins.createProject(OrganizationFolder.class, "multicultural");
prj.getSCMNavigators().add(new MockSCMNavigator(c, new MockSCMDiscoverBranches()));
prj.getProjectFactories().replaceBy(Collections.singletonList(new BasicMultiBranchProjectFactory(null)));
assertThat(prj.getAction(MockSCMLink.class), nullValue());
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
MultiBranchProject england = null;
MultiBranchProject ireland = null;
MultiBranchProject russia = null;
MultiBranchProject china = null;
MultiBranchProject spain = null;
MultiBranchProject korea = null;
for (MultiBranchProject p : prj.getItems()) {
String name = p.getDisplayName();
if ("England".equals(name)) {
england = p;
} else if ("Éireann".equals(name)) {
ireland = p;
} else if ("Россия".equals(name)) {
russia = p;
} else if ("中国".equals(name)) {
china = p;
} else if ("España".equals(name)) {
spain = p;
} else if ("대한민국".equals(name)) {
korea = p;
}
}
assertThat("England", england, notNullValue());
assertThat("England/master", england.getItem("master"), notNullValue());
assertThat("England/master/lastBuild", england.getItem("master").getLastBuild(), notNullValue());
assertThat("Ireland", ireland, notNullValue());
assertThat("Ireland/master", ireland.getItem("master"), notNullValue());
assertThat("Ireland/master/lastBuild", ireland.getItem("master").getLastBuild(), notNullValue());
assertThat("Russia", russia, notNullValue());
assertThat("Russia/master", russia.getItem("master"), notNullValue());
assertThat("Russia/master/lastBuild", russia.getItem("master").getLastBuild(), notNullValue());
assertThat("China", china, notNullValue());
assertThat("China/master", china.getItem("master"), notNullValue());
assertThat("China/master/lastBuild", china.getItem("master").getLastBuild(), notNullValue());
assertThat("Spain", spain, notNullValue());
assertThat("Spain/master", spain.getItem("master"), notNullValue());
assertThat("Spain/master/lastBuild", spain.getItem("master").getLastBuild(), notNullValue());
assertThat("Korea", korea, notNullValue());
assertThat("Korea/master", korea.getItem("master"), notNullValue());
assertThat("Korea/master/lastBuild", korea.getItem("master").getLastBuild(), notNullValue());
assertThat(prj.getItems(), containsInAnyOrder(england, ireland, spain, china, russia, korea));
assertThat(prj.getItemByProjectName("England"), is(england));
assertThat(prj.getItemByProjectName("Éireann"), is(ireland));
assertThat(prj.getItemByProjectName("Россия"), is(russia));
assertThat(prj.getItemByProjectName("中国"), is(china));
assertThat(prj.getItemByProjectName("España"), is(spain));
assertThat(prj.getItemByProjectName("대한민국"), is(korea));
}
}
@Test
void given_orgFolderWithNonSafeRepos_when_indexing_then_repoNamesEncoded()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("a?");
c.createRepository("a*");
c.createRepository("a/b");
OrganizationFolder prj = r.jenkins.createProject(OrganizationFolder.class, "multicultural");
prj.getSCMNavigators().add(new MockSCMNavigator(c, new MockSCMDiscoverBranches()));
prj.getProjectFactories().replaceBy(Collections.singletonList(new BasicMultiBranchProjectFactory(null)));
assertThat(prj.getAction(MockSCMLink.class), nullValue());
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
MultiBranchProject question = null;
MultiBranchProject star = null;
MultiBranchProject slash = null;
for (MultiBranchProject p : prj.getItems()) {
String name = p.getDisplayName();
System.out.println(name);
if ("a?".equals(name)) {
question = p;
} else if ("a*".equals(name)) {
star = p;
} else if ("a/b".equals(name)) {
slash = p;
}
}
assertThat("a?", question, notNullValue());
assertThat("a?/master", question.getItem("master"), notNullValue());
assertThat("a?/master/lastBuild", question.getItem("master").getLastBuild(), notNullValue());
assertThat("a*", star, notNullValue());
assertThat("a*/master", star.getItem("master"), notNullValue());
assertThat("a*/master/lastBuild", star.getItem("master").getLastBuild(), notNullValue());
assertThat("a/b", slash, notNullValue());
assertThat("a/b/master", slash.getItem("master"), notNullValue());
assertThat("a/b/master/lastBuild", slash.getItem("master").getLastBuild(), notNullValue());
assertThat(prj.getItems(), containsInAnyOrder(question, star, slash));
}
}
@Test
void given_orgFolder_when_navigatorDefined_then_sourceBrandingPresentAfterIndexing()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
OrganizationFolder prj = r.jenkins.createProject(OrganizationFolder.class, "foo");
prj.getSCMNavigators().add(new MockSCMNavigator(c, new MockSCMDiscoverBranches()));
prj.getProjectFactories().replaceBy(Collections.singletonList(new BasicMultiBranchProjectFactory(null)));
assertThat(prj.getAction(MockSCMLink.class), nullValue());
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
assertThat(prj.getItem("foo").getAction(MockSCMLink.class), hasProperty("id", is("source")));
}
}
@Test
void given_orgFolder_when_navigatorDefined_then_branchBrandingPresentAfterIndexing()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
OrganizationFolder prj = r.jenkins.createProject(OrganizationFolder.class, "foo");
prj.getSCMNavigators().add(new MockSCMNavigator(c, new MockSCMDiscoverBranches()));
prj.getProjectFactories().replaceBy(Collections.singletonList(new BasicMultiBranchProjectFactory(null)));
assertThat(prj.getAction(MockSCMLink.class), nullValue());
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
assertThat(prj.getItem("foo").getItem("master").getAction(MockSCMLink.class),
hasProperty("id", is("branch")));
}
}
@Test
void given_orgFolder_when_navigatorDefined_then_revisionBrandingPresentAfterIndexing()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
OrganizationFolder prj = r.jenkins.createProject(OrganizationFolder.class, "foo");
prj.getSCMNavigators().add(new MockSCMNavigator(c, new MockSCMDiscoverBranches()));
prj.getProjectFactories().replaceBy(Collections.singletonList(new BasicMultiBranchProjectFactory(null)));
assertThat(prj.getAction(MockSCMLink.class), nullValue());
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
assertThat(prj.getItem("foo").getItem("master").getBuildByNumber(1).getAction(MockSCMLink.class),
hasProperty("id", is("revision")));
}
}
@Test
void given_multibranch_when_decoratedSourceDefined_then_descriptionPresentAfterIndexing()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
c.setDescription("foo", "The Foo Project of Manchu");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
prj.getSourcesList().add(new BranchSource(new MockSCMSource(c, "foo", new MockSCMDiscoverBranches())));
assertThat(prj.getDescription(), nullValue());
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
assertThat(prj.getDescription(), is("The Foo Project of Manchu"));
}
}
@Test
void given_multibranch_when_decoratedSourceDefined_then_displayNamePresentAfterIndexing()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
c.setDisplayName("foo", "Foo Project");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
prj.getSourcesList().add(new BranchSource(new MockSCMSource(c, "foo", new MockSCMDiscoverBranches())));
assertThat(prj.getDisplayName(), is("foo"));
assertThat(prj.getDisplayNameOrNull(), nullValue());
assertThat(prj.getAction(ObjectMetadataAction.class), nullValue());
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
assertThat(prj.getAction(ObjectMetadataAction.class), notNullValue());
assertThat(prj.getDisplayName(), is("Foo Project"));
}
}
@Test
void given_orgFolder_when_decoratedSourceDefined_then_descriptionLinkPresentAfterIndexing()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
c.setDescription("foo", "The Foo Project of Manchu");
c.setUrl("foo", "http://foo.manchu.example.com/");
OrganizationFolder prj = r.jenkins.createProject(OrganizationFolder.class, "foo");
prj.getSCMNavigators().add(new MockSCMNavigator(c, new MockSCMDiscoverBranches()));
prj.getProjectFactories().replaceBy(Collections.singletonList(new BasicMultiBranchProjectFactory(null)));
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
assertThat(prj.getItem("foo").getAction(ObjectMetadataAction.class), allOf(
hasProperty("objectDescription", is("The Foo Project of Manchu")),
hasProperty("objectUrl", is("http://foo.manchu.example.com/")),
hasProperty("objectDisplayName", nullValue())
));
JenkinsRule.WebClient webClient = r.createWebClient();
HtmlPage page = webClient.getPage(prj);
HtmlAnchor href = page.getAnchorByHref("http://foo.manchu.example.com/");
assertThat(href.getTextContent(), containsString("The Foo Project of Manchu"));
}
}
@Test
void given_multibranch_when_decoratedSourceDefined_then_folderIconPresentAfterIndexing()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
c.setRepoIconClassName("icon-star");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
prj.getSourcesList().add(new BranchSource(new MockSCMSource(c, "foo", new MockSCMDiscoverBranches())));
assertThat(prj.getIcon().getIconClassName(), not(is("icon-star")));
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
assertThat(prj.getIcon().getIconClassName(), is("icon-star"));
}
}
@Test
void given_orgFolder_when_decoratedOrganizationDefined_then_folderIconPresentAfterIndexing()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
c.setOrgIconClassName("icon-star");
OrganizationFolder prj = r.jenkins.createProject(OrganizationFolder.class, "foo");
prj.getSCMNavigators().add(new MockSCMNavigator(c, new MockSCMDiscoverBranches()));
prj.getProjectFactories().replaceBy(Collections.singletonList(new BasicMultiBranchProjectFactory(null)));
assertThat(prj.getIcon().getIconClassName(), not(is("icon-star")));
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
assertThat(prj.getIcon().getIconClassName(), is("icon-star"));
}
}
@Test
void given_orgFolder_when_decoratedOrganizationDefined_then_displayNamePresentAfterIndexing()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
c.setDisplayName("Foo Organization");
OrganizationFolder prj = r.jenkins.createProject(OrganizationFolder.class, "foo");
prj.getSCMNavigators().add(new MockSCMNavigator(c, new MockSCMDiscoverBranches()));
prj.getProjectFactories().replaceBy(Collections.singletonList(new BasicMultiBranchProjectFactory(null)));
assertThat(prj.getDisplayName(), is("foo"));
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
assertThat(prj.getDisplayName(), is("Foo Organization"));
}
}
@Test
void given_orgFolder_when_decoratedOrganizationDefined_then_descriptionLinkPresentAfterIndexing()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
c.setDescription("The Foo of Manchu");
c.setUrl("http://foo.manchu.example.com/");
OrganizationFolder prj = r.jenkins.createProject(OrganizationFolder.class, "foo");
prj.getSCMNavigators().add(new MockSCMNavigator(c, new MockSCMDiscoverBranches()));
prj.getProjectFactories().replaceBy(Collections.singletonList(new BasicMultiBranchProjectFactory(null)));
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
assertThat(prj.getAction(ObjectMetadataAction.class), allOf(
hasProperty("objectDescription", is("The Foo of Manchu")),
hasProperty("objectUrl", is("http://foo.manchu.example.com/")),
hasProperty("objectDisplayName", nullValue())
));
ListView view = new ListView("descript");
view.setIncludeRegex(".*");
view.getColumns().replaceBy(Arrays.asList(
new StatusColumn(),
new WeatherColumn(),
new JobColumn(),
new DescriptionColumn()
));
r.jenkins.addView(view);
JenkinsRule.WebClient webClient = r.createWebClient();
HtmlPage page = webClient.getPage(view);
HtmlAnchor href = page.getAnchorByHref("http://foo.manchu.example.com/");
assertThat(href.getTextContent(), containsString("The Foo of Manchu"));
}
}
private void fire(MockSCMSourceEvent event) throws Exception {
long watermark = SCMEvents.getWatermark();
SCMSourceEvent.fireNow(event);
SCMEvents.awaitAll(watermark);
r.waitUntilNoActivity();
}
public static class BrandedMockSCMSource extends MockSCMSource {
public BrandedMockSCMSource(MockSCMController c) {
super(c, "foo", new MockSCMDiscoverBranches());
}
@NonNull
@Override
protected List<Action> retrieveActions(@NonNull SCMRevision revision, SCMHeadEvent event,
@NonNull TaskListener listener)
throws IOException, InterruptedException {
List<Action> result = new ArrayList<>(super.retrieveActions(revision, event, listener));
result.add(new CauseAction(new Cause.UserIdCause()));
result.add(new CauseAction(new Cause.RemoteCause("test", "data")));
return result;
}
@Extension()
public static class DescriptorImpl extends MockSCMSource.DescriptorImpl {}
}
}