提交 48b909db 编写于 作者: O Oliver Gondža

[FIXED JENKINS-29300] Display system info even when slave is temporarily offline

上级 38fc3e53
......@@ -44,7 +44,7 @@ THE SOFTWARE.
<l:hasPermission permission="${it.CONNECT}">
<j:choose>
<j:when test="${it.online}">
<j:when test="${it.channel != null}">
<h2>${it.oSDescription} slave, version ${it.slaveVersion}</h2>
<j:forEach var="instance" items="${it.systemInfoExtensions}">
......@@ -59,4 +59,4 @@ THE SOFTWARE.
</l:hasPermission>
</l:main-panel>
</l:layout>
</j:jelly>
\ No newline at end of file
</j:jelly>
......@@ -25,19 +25,27 @@ package hudson.cli;
import static org.junit.Assert.*;
import static hudson.cli.CLICommandInvoker.Matcher.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
import jenkins.model.Jenkins;
import hudson.cli.CLICommandInvoker.Result;
import hudson.model.Computer;
import hudson.model.Slave;
import hudson.model.User;
import hudson.security.ACL;
import hudson.slaves.DumbSlave;
import hudson.slaves.OfflineCause.UserCause;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.JenkinsRule.WebClient;
import com.gargoylesoftware.htmlunit.ElementNotFoundException;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
/**
* @author ogondza
......@@ -115,4 +123,51 @@ public class ComputerStateTest {
assertThat(cause.toString(), endsWith("Custom cause message"));
assertThat(cause.getUser(), equalTo(command.user()));
}
@Test
public void testUiForConnected() throws Exception {
DumbSlave slave = j.createOnlineSlave();
Computer computer = slave.toComputer();
WebClient wc = j.createWebClient();
assertConnected(wc, slave);
computer.setTemporarilyOffline(true, null);
assertTrue(computer.isTemporarilyOffline());
assertConnected(wc, slave);
slave.toComputer().disconnect(null);
HtmlPage page = wc.getPage(slave);
assertLinkDoesNotExist(page, "Disconnect");
assertLinkDoesNotExist(page, "Script Console");
HtmlPage script = wc.getPage(slave, "script");
assertThat(script.getByXPath("//form[@action='script']"), empty());
assertLinkDoesNotExist(page, "System Information");
HtmlPage info = wc.getPage(slave, "systemInfo");
assertThat(info.asText(), not(containsString("Environment Variables")));
}
private void assertConnected(WebClient wc, DumbSlave slave) throws Exception {
HtmlPage main = wc.getPage(slave);
main.getAnchorByText("Disconnect");
main.getAnchorByText("Script Console");
HtmlPage script = wc.getPage(slave, "script");
assertThat(script.getByXPath("//form[@action='script']"), not(empty()));
main.getAnchorByText("System Information");
HtmlPage info = wc.getPage(slave, "systemInfo");
assertThat(info.asText(), containsString("Environment Variables"));
}
private void assertLinkDoesNotExist(HtmlPage page, String text) {
try {
page.getAnchorByText(text);
fail(text + " link should not exist");
} catch (ElementNotFoundException _) { /*expected*/ }
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册