diff --git a/pom.xml b/pom.xml index a3ef0afe9..1526f3a6c 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.jenkins-ci.plugins plugin - 4.79 + 4.81 @@ -28,11 +28,6 @@ - - basil - Basil Crow - me@basilcrow.com - TobiX Tobias Gruetzmacher @@ -59,7 +54,7 @@ 999999-SNAPSHOT - 2.387.3 + 2.426.3 jenkinsci/${project.artifactId}-plugin Max Low @@ -70,8 +65,8 @@ io.jenkins.tools.bom - bom-2.387.x - 2543.vfb_1a_5fb_9496d + bom-2.426.x + 2982.vdce2153031a_0 pom import diff --git a/src/main/resources/org/jenkins/plugins/lockableresources/actions/LockableResourcesRootAction/tableLabels/table.jelly b/src/main/resources/org/jenkins/plugins/lockableresources/actions/LockableResourcesRootAction/tableLabels/table.jelly index 63f44ff37..92107d2cd 100644 --- a/src/main/resources/org/jenkins/plugins/lockableresources/actions/LockableResourcesRootAction/tableLabels/table.jelly +++ b/src/main/resources/org/jenkins/plugins/lockableresources/actions/LockableResourcesRootAction/tableLabels/table.jelly @@ -32,7 +32,7 @@ THE SOFTWARE.
- + diff --git a/src/main/resources/org/jenkins/plugins/lockableresources/actions/LockableResourcesRootAction/tableQueue/table.jelly b/src/main/resources/org/jenkins/plugins/lockableresources/actions/LockableResourcesRootAction/tableQueue/table.jelly index aac07c82b..751d32cd2 100644 --- a/src/main/resources/org/jenkins/plugins/lockableresources/actions/LockableResourcesRootAction/tableQueue/table.jelly +++ b/src/main/resources/org/jenkins/plugins/lockableresources/actions/LockableResourcesRootAction/tableQueue/table.jelly @@ -51,7 +51,7 @@ THE SOFTWARE.
${%labels.table.column.labels}${%labels.table.column.labels} ${%labels.table.column.assigned} ${%labels.table.column.free} ${%labels.table.column.percentage}
${%queue.table.column.index} - + diff --git a/src/main/resources/org/jenkins/plugins/lockableresources/actions/LockableResourcesRootAction/tableResources/table.jelly b/src/main/resources/org/jenkins/plugins/lockableresources/actions/LockableResourcesRootAction/tableResources/table.jelly index 3ae5ddfba..6b741f072 100644 --- a/src/main/resources/org/jenkins/plugins/lockableresources/actions/LockableResourcesRootAction/tableResources/table.jelly +++ b/src/main/resources/org/jenkins/plugins/lockableresources/actions/LockableResourcesRootAction/tableResources/table.jelly @@ -35,7 +35,7 @@ THE SOFTWARE.
${%queue.table.column.request.type} ${%queue.table.column.request.info}${%queue.table.column.reason}${%queue.table.column.reason} ${%queue.table.column.requested.by} ${%queue.table.column.requested.at}
- - - - - - - - - - - - - - - - - + - + diff --git a/src/test/java/org/jenkins/plugins/lockableresources/LockStepTest.java b/src/test/java/org/jenkins/plugins/lockableresources/LockStepTest.java index 3235bc9e0..ac0ff25cf 100644 --- a/src/test/java/org/jenkins/plugins/lockableresources/LockStepTest.java +++ b/src/test/java/org/jenkins/plugins/lockableresources/LockStepTest.java @@ -430,18 +430,14 @@ public void unlockButtonWithWaitingRuns() throws Exception { WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition("lock('resource1') { semaphore('wait-inside') }", true)); - JenkinsRule.WebClient wc = j.createWebClient(); - WorkflowRun prevBuild = null; + TestHelpers testHelpers = new TestHelpers(); for (int i = 0; i < 3; i++) { WorkflowRun rNext = p.scheduleBuild2(0).waitForStart(); if (prevBuild != null) { j.waitForMessage("[resource1] is locked by build " + prevBuild.getFullDisplayName(), rNext); isPaused(rNext, 1, 1); - // List resources = new ArrayList<>(); - // resources.add(LockableResourcesManager.get().fromName("resource1")); - // LockableResourcesManager.get().unlock(resources, null); - TestHelpers.clickButton(wc, "unlock"); + testHelpers.clickButton("unlock", "resource1"); } j.waitForMessage("Lock acquired on [resource1]", rNext); diff --git a/src/test/java/org/jenkins/plugins/lockableresources/LockStepTest_manualUnreserveUnblocksJob.java b/src/test/java/org/jenkins/plugins/lockableresources/LockStepTest_manualUnreserveUnblocksJob.java index c44f06abb..d90e26e45 100644 --- a/src/test/java/org/jenkins/plugins/lockableresources/LockStepTest_manualUnreserveUnblocksJob.java +++ b/src/test/java/org/jenkins/plugins/lockableresources/LockStepTest_manualUnreserveUnblocksJob.java @@ -25,9 +25,9 @@ public class LockStepTest_manualUnreserveUnblocksJob extends LockStepTestBase { @Test public void manualUnreserveUnblocksJob() throws Exception { LockableResourcesManager.get().createResource("resource1"); - JenkinsRule.WebClient wc = j.createWebClient(); - TestHelpers.clickButton(wc, "reserve"); + TestHelpers testHelpers = new TestHelpers(); + testHelpers.clickButton("reserve", "resource1"); LockableResource resource1 = LockableResourcesManager.get().fromName("resource1"); assertNotNull(resource1); resource1.setReservedBy("someone"); @@ -45,7 +45,7 @@ public void manualUnreserveUnblocksJob() throws Exception { WorkflowRun r = p.scheduleBuild2(0).waitForStart(); j.waitForMessage("[resource1] is not free, waiting for execution ...", r); j.assertLogNotContains("I am inside", r); - TestHelpers.clickButton(wc, "unreserve"); + testHelpers.clickButton("unreserve", "resource1"); j.waitForMessage("I am inside", r); j.assertLogContains("I am inside", r); j.assertBuildStatusSuccess(j.waitForCompletion(r)); diff --git a/src/test/java/org/jenkins/plugins/lockableresources/LockStepWithRestartTest.java b/src/test/java/org/jenkins/plugins/lockableresources/LockStepWithRestartTest.java index a04fbe506..520c4a6fe 100644 --- a/src/test/java/org/jenkins/plugins/lockableresources/LockStepWithRestartTest.java +++ b/src/test/java/org/jenkins/plugins/lockableresources/LockStepWithRestartTest.java @@ -180,7 +180,9 @@ public void checkQueueAfterRestart() throws Throwable { JenkinsRule.WebClient wc = j.createWebClient(); wc.login("user"); - TestHelpers.clickButton(wc, "unreserve"); + + TestHelpers testHelpers = new TestHelpers(); + testHelpers.clickButton("unreserve", "resource1"); lrm.unreserve(Collections.singletonList(lrm.fromName("resource1"))); diff --git a/src/test/java/org/jenkins/plugins/lockableresources/LockableResourceApiTest.java b/src/test/java/org/jenkins/plugins/lockableresources/LockableResourceApiTest.java index 3a7a12666..bb547f8f0 100644 --- a/src/test/java/org/jenkins/plugins/lockableresources/LockableResourceApiTest.java +++ b/src/test/java/org/jenkins/plugins/lockableresources/LockableResourceApiTest.java @@ -37,9 +37,10 @@ public void reserveUnreserveApi() throws Exception { JenkinsRule.WebClient wc = j.createWebClient(); wc.login("user"); - TestHelpers.clickButton(wc, "reserve"); + TestHelpers testHelpers = new TestHelpers(); + testHelpers.clickButton("reserve", "a1"); assertThat(LockableResourcesManager.get().fromName("a1").isReserved(), is(true)); - TestHelpers.clickButton(wc, "unreserve"); + testHelpers.clickButton("unreserve", "a1"); assertThat(LockableResourcesManager.get().fromName("a1").isReserved(), is(false)); } diff --git a/src/test/java/org/jenkins/plugins/lockableresources/TestHelpers.java b/src/test/java/org/jenkins/plugins/lockableresources/TestHelpers.java index e14cb8fd5..4df135a10 100644 --- a/src/test/java/org/jenkins/plugins/lockableresources/TestHelpers.java +++ b/src/test/java/org/jenkins/plugins/lockableresources/TestHelpers.java @@ -8,19 +8,21 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.nullValue; +import static org.mockito.Mockito.when; import hudson.model.FreeStyleProject; import hudson.model.Queue; import java.io.IOException; -import java.util.List; import java.util.logging.Logger; import jenkins.model.Jenkins; import net.sf.json.JSONArray; import net.sf.json.JSONObject; -import org.htmlunit.html.HtmlElement; -import org.htmlunit.html.HtmlElementUtil; -import org.htmlunit.html.HtmlPage; +import org.jenkins.plugins.lockableresources.actions.LockableResourcesRootAction; import org.jvnet.hudson.test.JenkinsRule; +import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerResponse; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; public final class TestHelpers { @@ -29,8 +31,18 @@ public final class TestHelpers { private static final int SLEEP_TIME = 100; private static final int MAX_WAIT = 5000; + @Mock + private StaplerRequest req; + + @Mock + private StaplerResponse rsp; + + private AutoCloseable mocks; + // Utility class - private TestHelpers() {} + public TestHelpers() { + this.mocks = MockitoAnnotations.openMocks(this); + } public static void waitForQueue(Jenkins jenkins, FreeStyleProject job) throws InterruptedException { waitForQueue(jenkins, job, Queue.Item.class); @@ -71,20 +83,31 @@ public static JSONObject getApiData(JenkinsRule rule) throws IOException { return rule.getJSON("plugin/lockable-resources/api/json").getJSONObject(); } - // Currently assumes one resource or only clicks the button for the first resource - public static void clickButton(JenkinsRule.WebClient wc, String action) throws Exception { - // disable exceptions, otherwise it will not parse jQuery scripts (used ba DataTable plugin) - wc.getOptions().setThrowExceptionOnScriptError(false); - HtmlPage htmlPage = wc.goTo("lockable-resources"); - List allButtons = htmlPage.getDocumentElement().getElementsByTagName("button"); + /** SImulate the click on the button in the LRM page + * note: Currently does not click on the button. Just simulate the doAction (stapler request) + * on the given resource. + * We shall provide some better solution like selenium tests. But for now it is fine. + */ + public void clickButton(String action, String resourceName) throws Exception { + LOGGER.info(action + " on " + resourceName); + LockableResourcesRootAction doAction = new LockableResourcesRootAction(); + when(req.getMethod()).thenReturn("POST"); + when(req.getParameter("resource")).thenReturn(resourceName); - HtmlElement reserveButton = null; - for (HtmlElement b : allButtons) { - String onClick = b.getAttribute("onClick"); - if (onClick != null && onClick.contains(action)) { - reserveButton = b; + switch (action) { + case "reserve": { + doAction.doReserve(req, rsp); + break; + } + case "unreserve": { + doAction.doUnreserve(req, rsp); + break; + } + case "unlock": { + LOGGER.info("doUnlock"); + doAction.doUnlock(req, rsp); + break; } } - HtmlElementUtil.click(reserveButton); } }
${%resources.table.column.index}${%resources.table.column.resource}${%resources.table.column.resource} ${%resources.table.column.status} ${%resources.table.column.timestamp}${%resources.table.column.labels}${%resources.table.column.labels} ${%resources.table.column.properties} ${%resources.table.column.action}