|
27 | 27 | */
|
28 | 28 | package com.github.farmgeek4life.jenkins.negotiatesso;
|
29 | 29 |
|
30 |
| -import org.htmlunit.FailingHttpStatusCodeException; |
31 | 30 | import org.htmlunit.html.HtmlElement;
|
32 | 31 | import org.htmlunit.html.HtmlForm;
|
33 | 32 | import org.htmlunit.html.HtmlPage;
|
34 |
| -import org.junit.Rule; |
35 |
| -import org.junit.Test; |
36 |
| -import org.junit.runners.model.Statement; |
37 |
| -import org.jvnet.hudson.test.RestartableJenkinsRule; |
38 |
| -import org.jvnet.hudson.test.RestartableJenkinsRule.Step; |
| 33 | +import org.junit.jupiter.api.Test; |
| 34 | +import org.jvnet.hudson.test.JenkinsRule; |
| 35 | +import org.jvnet.hudson.test.junit.jupiter.WithJenkins; |
39 | 36 |
|
40 |
| -import static org.junit.Assert.assertFalse; |
41 |
| -import static org.junit.Assert.assertNotNull; |
42 |
| -import static org.junit.Assert.assertTrue; |
| 37 | +import static hudson.Functions.isWindows; |
| 38 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 39 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 40 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
43 | 41 |
|
44 | 42 | /**
|
45 | 43 | * UI tests for the global configuration page of the plugin.
|
46 | 44 | * @author Bryson Gibbons
|
47 | 45 | */
|
48 |
| -public class NegotiateConfigTests { |
49 |
| - /** |
50 |
| - * Time limit in seconds for timed tests. |
51 |
| - */ |
52 |
| - public static final int TIME_LIMIT = 10; |
53 |
| - |
54 |
| - /** |
55 |
| - * Jenkins rule instance. |
56 |
| - */ |
57 |
| - // CS IGNORE VisibilityModifier FOR NEXT 3 LINES. REASON: Mocks tests. |
58 |
| - @Rule |
59 |
| - public RestartableJenkinsRule rule = new RestartableJenkinsRule(); |
60 |
| - |
61 |
| - /** |
62 |
| - * |
63 |
| - */ |
64 |
| - private boolean IsWindowsOS() { |
65 |
| - return System.getProperty("os.name").toLowerCase().contains("win"); |
66 |
| - } |
| 46 | +@WithJenkins |
| 47 | +class NegotiateConfigTests { |
67 | 48 |
|
68 | 49 | /**
|
69 | 50 | * Tests if Negotiate SSO plugin has a section on the global config page.
|
70 | 51 | */
|
71 | 52 | @Test
|
72 |
| - public void testNegotiateHasConfigPage() { |
73 |
| - rule.then(r -> { |
74 |
| - HtmlPage currentPage = rule.j.createWebClient().goTo("configureSecurity"); |
75 |
| - HtmlElement enabled = currentPage.getElementByName("_.enabled"); |
76 |
| - assertNotNull("Negotiate configuration page missing.", enabled); |
77 |
| - }); |
78 |
| - |
| 53 | + void testNegotiateHasConfigPage(JenkinsRule rule) throws Exception { |
| 54 | + HtmlPage currentPage = rule.createWebClient().goTo("configureSecurity"); |
| 55 | + HtmlElement enabled = currentPage.getElementByName("_.enabled"); |
| 56 | + assertNotNull(enabled, "Negotiate configuration page missing."); |
79 | 57 | }
|
80 | 58 |
|
81 | 59 | /**
|
82 | 60 | * Tests if Negotiate SSO plugin block can be expanded.
|
83 | 61 | */
|
84 | 62 | @Test
|
85 |
| - public void testEnableNegotiate() { |
86 |
| - rule.then(r -> { |
87 |
| - HtmlPage currentPage = rule.j.createWebClient().goTo("configureSecurity"); |
88 |
| - HtmlElement enabled = currentPage.getElementByName("_.enabled"); |
89 |
| - enabled.fireEvent("click"); |
90 |
| - assertNotNull("Optional block wasn't expanded.", currentPage.getElementByName("_.redirectEnabled")); |
91 |
| - }); |
| 63 | + void testEnableNegotiate(JenkinsRule rule) throws Exception { |
| 64 | + HtmlPage currentPage = rule.createWebClient().goTo("configureSecurity"); |
| 65 | + HtmlElement enabled = currentPage.getElementByName("_.enabled"); |
| 66 | + enabled.fireEvent("click"); |
| 67 | + assertNotNull(currentPage.getElementByName("_.redirectEnabled"), "Optional block wasn't expanded."); |
92 | 68 | }
|
93 | 69 |
|
94 | 70 | /**
|
95 | 71 | * Tests if the NegotiateSSO class changes attributes if a new config is submitted.
|
96 | 72 | * @throws Exception if something goes wrong
|
97 | 73 | */
|
98 | 74 | @Test
|
99 |
| - public void testIfConfigCanBeUpdated() throws Exception { |
100 |
| - rule.then(r -> { |
101 |
| - assertFalse("Plugin already enabled", NegotiateSSO.getInstance().getEnabled()); |
| 75 | + void testIfConfigCanBeUpdated(JenkinsRule rule) throws Exception { |
| 76 | + assertFalse(NegotiateSSO.getInstance().getEnabled(), "Plugin already enabled"); |
102 | 77 |
|
103 |
| - HtmlPage currentPage = rule.j.createWebClient().goTo("configureSecurity"); |
104 |
| - HtmlForm form = currentPage.getFormByName("config"); |
105 |
| - assertNotNull(form); |
| 78 | + HtmlPage currentPage = rule.createWebClient().goTo("configureSecurity"); |
| 79 | + HtmlForm form = currentPage.getFormByName("config"); |
| 80 | + assertNotNull(form); |
106 | 81 |
|
107 |
| - form.getInputByName("_.enabled").click(); |
108 |
| - form.getSelectByName("_.principalFormat").setSelectedAttribute("both", true); |
109 |
| - form.getSelectByName("_.roleFormat").setSelectedAttribute("sid", true); |
| 82 | + form.getInputByName("_.enabled").click(); |
| 83 | + form.getSelectByName("_.principalFormat").setSelectedAttribute("both", true); |
| 84 | + form.getSelectByName("_.roleFormat").setSelectedAttribute("sid", true); |
110 | 85 |
|
111 |
| - try { |
112 |
| - rule.j.submit(form); |
113 |
| - // CS IGNORE EmptyBlock FOR NEXT 3 LINES. REASON: Mocks Tests. |
114 |
| - } catch (FailingHttpStatusCodeException e) { |
115 |
| - // Expected since filter cannot be added to Jenkins rule. |
116 |
| - } |
| 86 | + rule.submit(form); |
117 | 87 |
|
118 |
| - boolean wasEnabled = NegotiateSSO.getInstance().getEnabled(); |
119 |
| - if (IsWindowsOS()) { |
120 |
| - assertTrue("Plugin wasn't enabled after saving the new config", wasEnabled); |
121 |
| - } |
122 |
| - else { |
123 |
| - assertFalse("Plugin was enabled on a non-Windows OS", wasEnabled); |
124 |
| - } |
125 |
| - }); |
| 88 | + boolean wasEnabled = NegotiateSSO.getInstance().getEnabled(); |
| 89 | + if (isWindows()) { |
| 90 | + assertTrue(wasEnabled, "Plugin wasn't enabled after saving the new config"); |
| 91 | + } |
| 92 | + else { |
| 93 | + assertFalse(wasEnabled, "Plugin was enabled on a non-Windows OS"); |
| 94 | + } |
126 | 95 | }
|
127 | 96 | }
|
0 commit comments