Skip to content

Commit

Permalink
Merge pull request #24 from alecharp/features/jenkins-connectivity-st…
Browse files Browse the repository at this point in the history
…atus

Create method to know end-point connectivity
  • Loading branch information
cosmin committed Jul 29, 2014
2 parents 6551617 + 887cbfd commit 56d2773
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/com/offbytwo/jenkins/JenkinsServer.java
Expand Up @@ -55,6 +55,20 @@ public JenkinsServer(JenkinsHttpClient client) {
this.client = client;
}

/**
* Get the current status of the Jenkins end-point by pinging it.
*
* @return true if Jenkins is up and running, false otherwise
*/
public boolean isRunning() {
try {
client.get("/");
return true;
} catch (IOException e) {
return false;
}
}

/**
* Get a list of all the defined jobs on the server (at the summary level)
*
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/com/offbytwo/jenkins/JenkinsServerTest.java
Expand Up @@ -11,6 +11,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.io.IOException;
import java.util.UUID;

import org.junit.Before;
Expand Down Expand Up @@ -80,4 +81,16 @@ public void testCreateJob() throws Exception {
String xmlReturn = captureString.getValue();
assertEquals(xmlReturn, xmlString);
}

@Test
public void testJenkinsConnectivity() throws IOException {
Mockito.when(client.get("/")).thenReturn("<xml>not a real response</xml>");
assertEquals(server.isRunning(), true);
}

@Test
public void testJenkinsConnectivityBroken() throws IOException {
Mockito.when(client.get("/")).thenThrow(IOException.class);
assertEquals(server.isRunning(), false);
}
}

0 comments on commit 56d2773

Please sign in to comment.