@Test public void testGetJobXml() throws Exception { String jobName = "pr"; String xmlString = "<xml>some xml goes here</xml>"; Mockito.when(client.get(Mockito.anyString())).thenReturn(xmlString); String xmlReturn = server.getJobXml(jobName); Mockito.verify(client).get("/job/pr/config.xml"); assertEquals(xmlString, xmlReturn); }
@Test public void testCreateJob() throws Exception { String jobName = "test-job-" + UUID.randomUUID().toString(); String xmlString = "<xml>some xml goes here</xml>"; server.createJob(jobName, xmlString); ArgumentCaptor<String> captureString = ArgumentCaptor.forClass(String.class); Mockito.verify(client) .post_xml(Mockito.eq("/createItem?name=" + jobName), captureString.capture()); String xmlReturn = captureString.getValue(); assertEquals(xmlReturn, xmlString); }
@Test public void testUpdateJobXml() throws Exception { String jobName = "pr"; String xmlString = "<xml>some xml goes here</xml>"; Mockito.when(client.post_xml(Mockito.anyString(), Mockito.eq(xmlString))).thenReturn(xmlString); server.updateJob(jobName, xmlString); ArgumentCaptor<String> captureString = ArgumentCaptor.forClass(String.class); Mockito.verify(client).post_xml(Mockito.eq("/job/pr/config.xml"), captureString.capture()); assertEquals(xmlString, captureString.getValue()); }
@Test public void testJenkinsConnectivityBroken() throws IOException { Mockito.when(client.get("/")).thenThrow(IOException.class); assertEquals(server.isRunning(), false); }
@Test public void testJenkinsConnectivity() throws IOException { Mockito.when(client.get("/")).thenReturn("<xml>not a real response</xml>"); assertEquals(server.isRunning(), true); }
@Test public void shouldReturnListOfJobs() throws Exception { assertTrue(server.getJobs().containsKey("hello")); }