use of hudson.model.FreeStyleProject in project hudson-2.x by hudson.
the class CascadingUtilTest method testGetAllItems.
@Test
@PrepareForTest(Hudson.class)
public void testGetAllItems() throws Exception {
FreeStyleProject project1 = new FreeStyleProjectMock("p1");
FreeStyleProjectMock project2 = new FreeStyleProjectMock("p2");
FreeStyleProjectMock project3 = new FreeStyleProjectMock("p3");
FreeStyleProjectMock project4 = new FreeStyleProjectMock("p4");
List<Job> jobs = new ArrayList<Job>();
jobs.add(project1);
jobs.add(project2);
jobs.add(project3);
jobs.add(project4);
Hudson hudson = createMock(Hudson.class);
mockStatic(Hudson.class);
expect(hudson.getAllItems(Job.class)).andReturn(jobs).anyTimes();
expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
replay(Hudson.class, hudson);
project2.setCascadingProject(project1);
CascadingUtil.linkCascadingProjectsToChild(project1, "p2");
project3.setCascadingProject(project1);
CascadingUtil.linkCascadingProjectsToChild(project1, "p3");
project4.setCascadingProject(project3);
CascadingUtil.linkCascadingProjectsToChild(project3, "p4");
List<Job> jobs1 = CascadingUtil.getCascadingParents(Job.class, project1);
List<Job> jobs2 = CascadingUtil.getCascadingParents(Job.class, project2);
List<Job> jobs3 = CascadingUtil.getCascadingParents(Job.class, project3);
List<Job> jobs4 = CascadingUtil.getCascadingParents(Job.class, project4);
verify(Hudson.class, hudson);
assertEquals(0, jobs1.size());
assertFalse(jobs1.contains(project1));
assertFalse(jobs1.contains(project2));
assertFalse(jobs1.contains(project3));
assertFalse(jobs1.contains(project4));
assertEquals(3, jobs2.size());
assertTrue(jobs2.contains(project1));
assertFalse(jobs2.contains(project2));
assertTrue(jobs2.contains(project3));
assertTrue(jobs2.contains(project4));
assertEquals(2, jobs3.size());
assertTrue(jobs3.contains(project1));
assertTrue(jobs3.contains(project2));
assertFalse(jobs3.contains(project3));
assertFalse(jobs3.contains(project4));
assertEquals(3, jobs4.size());
assertTrue(jobs4.contains(project1));
assertTrue(jobs4.contains(project2));
assertTrue(jobs4.contains(project3));
assertFalse(jobs4.contains(project4));
}
use of hudson.model.FreeStyleProject in project hudson-2.x by hudson.
the class FunctionsTest method testGetTemplatePresentTemplate.
@Test
public void testGetTemplatePresentTemplate() {
FreeStyleProject parentProject = new FreeStyleProject(null, TEMPLATE_NAME);
List<FreeStyleProject> items = new ArrayList<FreeStyleProject>();
items.add(parentProject);
FreeStyleProject project = Functions.getItemByName(items, TEMPLATE_NAME);
assertNotNull(project);
}
use of hudson.model.FreeStyleProject in project blueocean-plugin by jenkinsci.
the class StatePreloaderTest method test.
@Test
public void test() throws IOException, ExecutionException, InterruptedException, SAXException {
// Create a project and run a build on it.
FreeStyleProject freestyleProject = j.createProject(FreeStyleProject.class, "freestyle");
FreeStyleBuild run = freestyleProject.scheduleBuild2(0).get();
j.waitForCompletion(run);
// Lets request the activity page for that project. The page should
// contain some prefetched javascript for the pipeline
// details + the runs on the page
Assert.assertTrue(BlueOceanUrlMapper.all().size() > 0);
BlueOceanUrlMapper mapper = BlueOceanUrlMapper.all().get(0);
String projectBlueUrl = j.jenkins.getRootUrl() + mapper.getUrl(freestyleProject);
Document doc = Jsoup.connect(projectBlueUrl + "/activity/").get();
String script = doc.select("head script").toString();
Assert.assertTrue(script.contains(String.format("setState('prefetchdata.%s',", PipelineStatePreloader.class.getSimpleName())));
Assert.assertTrue(script.contains(String.format("setState('prefetchdata.%s',", PipelineActivityStatePreloader.class.getSimpleName())));
Assert.assertTrue(script.contains("\"restUrl\":\"/blue/rest/organizations/jenkins/pipelines/freestyle/runs/?start=0&limit=26\""));
}
use of hudson.model.FreeStyleProject in project blueocean-plugin by jenkinsci.
the class PipelineApiTest method getPipelineRunStopTest.
@Test
public void getPipelineRunStopTest() throws Exception {
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition("" + "node {" + " stage ('Build'); " + " semaphore 's' " + " stage ('Test'); " + " echo ('Testing'); " + "}", false));
WorkflowRun b1 = job1.scheduleBuild2(0).waitForStart();
SemaphoreStep.waitForStart("s/1", b1);
Map r = null;
for (int i = 0; i < 10; i++) {
r = request().put("/organizations/jenkins/pipelines/pipeline1/runs/1/stop").build(Map.class);
if (((String) r.get("state")).equals("FINISHED"))
break;
Thread.sleep(1000);
}
Assert.assertEquals(r.get("state"), "FINISHED");
Assert.assertEquals(r.get("result"), "ABORTED");
j.assertBuildStatus(Result.ABORTED, b1);
FreeStyleProject p = j.createFreeStyleProject("pipeline5");
p.getBuildersList().add(new Shell("echo hello!\nsleep 69"));
FreeStyleBuild b2 = p.scheduleBuild2(0).waitForStart();
for (int i = 0; i < 10; i++) {
r = put("/organizations/jenkins/pipelines/pipeline5/runs/1/stop", null);
if (((String) r.get("state")).equals("FINISHED"))
break;
Thread.sleep(1000);
}
Assert.assertEquals(r.get("state"), "FINISHED");
Assert.assertEquals(r.get("result"), "ABORTED");
j.assertBuildStatus(Result.ABORTED, b2);
}
use of hudson.model.FreeStyleProject in project blueocean-plugin by jenkinsci.
the class SseEventTest method jobRunEvents.
@Test
public void jobRunEvents() throws IOException, ExecutionException, InterruptedException {
final OneShotEvent success = new OneShotEvent();
final FreeStyleProject p = j.createFreeStyleProject("test1");
final AssertionHelper assertionHelper = new AssertionHelper();
SSEConnection con = new SSEConnection(j.getURL(), "me", new ChannelSubscriber() {
@Override
public void onMessage(@Nonnull Message message) {
System.out.println(message);
assertionHelper.isEquals("/blue/rest/organizations/jenkins/pipelines/test1/", message.get(blueocean_job_rest_url));
assertionHelper.isEquals(p.getName(), message.get(blueocean_job_pipeline_name));
if (message.get(jenkins_event).equals(Events.JobChannel.job_run_queue_left.name())) {
assertionHelper.isEquals("1", message.get(blueocean_queue_item_expected_build_number));
}
assertionHelper.isEquals(p.getName(), message.get(job_name));
assertionHelper.isEquals("job", message.get(jenkins_channel));
assertionHelper.isEquals("jenkins", message.get(jenkins_org));
assertionHelper.isNull(message.get(job_ismultibranch));
assertionHelper.isNull(message.get(job_multibranch_indexing_result));
assertionHelper.isNull(message.get(job_multibranch_indexing_status));
assertionHelper.isNotNull(message.get(Job.job_run_queueId));
assertionHelper.isNotNull(message.get(Job.job_run_status));
if ("SUCCESS".equals(message.get(Job.job_run_status)) && "job_run_ended".equals(message.get(jenkins_event)))
success.signal();
}
});
con.subscribe("job");
p.scheduleBuild2(0).get();
// make sure we got the event we were looking for
success.block(5000);
con.close();
if (assertionHelper.totalErrors() > 0) {
fail("There were errors: " + assertionHelper.totalErrors());
}
}
Aggregations