use of io.jenkins.blueocean.rest.hal.Link in project blueocean-plugin by jenkinsci.
the class ChangeSetResourceTest method testChangeSet.
@Test
public void testChangeSet() {
Reachable reachable = mock(Reachable.class);
when(reachable.getLink()).thenReturn(new Link("/foo/bar"));
User user = mock(User.class);
when(user.getId()).thenReturn("vivek");
ChangeLogSet.Entry entry = mock(ChangeLogSet.Entry.class);
when(entry.getAuthor()).thenReturn(user);
when(entry.getTimestamp()).thenReturn(System.currentTimeMillis());
when(entry.getCommitId()).thenReturn("12345");
when(entry.getMsg()).thenReturn("test changeset");
when(entry.getAffectedPaths()).thenReturn(Collections.singleton("/foo/bar"));
ChangeSetResource changeSetResource = new ChangeSetResource(new OrganizationImpl("testorg", mock(Folder.class)), entry, reachable);
assertEquals(user.getId(), changeSetResource.getAuthor().getId());
assertEquals(entry.getCommitId(), changeSetResource.getCommitId());
assertEquals(entry.getMsg(), changeSetResource.getMsg());
}
use of io.jenkins.blueocean.rest.hal.Link in project blueocean-plugin by jenkinsci.
the class BlueJUnitTestResultTest method createsTestResult.
@Test
public void createsTestResult() throws Exception {
URL resource = getClass().getResource("BlueJUnitTestResultTest.jenkinsfile");
String jenkinsFile = IOUtils.toString(resource, StandardCharsets.UTF_8);
WorkflowJob p = j.createProject(WorkflowJob.class, "project");
p.setDefinition(new CpsFlowDefinition(jenkinsFile, false));
p.save();
Run r = p.scheduleBuild2(0).waitForStart();
j.waitUntilNoActivity();
BlueRun test = BlueRunFactory.getRun(r, () -> new Link("test"));
Assert.assertEquals(3, IterableUtils.size(test.getTests()));
BluePipelineNode node = mock(BluePipelineNode.class);
when(node.getId()).thenReturn("6");
}
use of io.jenkins.blueocean.rest.hal.Link in project blueocean-plugin by jenkinsci.
the class PipelineApiTest method testArtifactsRunApi.
@Test
public void testArtifactsRunApi() throws Exception {
FreeStyleProject p = j.createFreeStyleProject("pipeline1");
p.getBuildersList().add(new TestBuilder() {
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
FilePath ws = build.getWorkspace();
if (ws == null) {
return false;
}
FilePath dir = ws.child("dir");
dir.mkdirs();
dir.child("fizz").write("contents", null);
dir.child("lodge").symlinkTo("fizz", listener);
return true;
}
});
ArtifactArchiver aa = new ArtifactArchiver("dir/fizz");
aa.setAllowEmptyArchive(true);
p.getPublishersList().add(aa);
FreeStyleBuild b = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
List artifacts = get("/organizations/jenkins/pipelines/pipeline1/runs/" + b.getId() + "/artifacts", List.class);
assertEquals(1, artifacts.size());
assertEquals("fizz", ((Map) artifacts.get(0)).get("name"));
String artifactId = (String) ((Map) artifacts.get(0)).get("id");
ArtifactContainerImpl container = new ArtifactContainerImpl(b, () -> new Link("/blue/rest/organizations/jenkins/pipelines/pipeline1/runs/1/artifacts/"));
BlueArtifact blueArtifact = container.get(artifactId);
assertNotNull(blueArtifact);
}
use of io.jenkins.blueocean.rest.hal.Link in project blueocean-plugin by jenkinsci.
the class QueueContainerImpl method getQueuedItems.
/**
* This function gets gets a list of all queued items if the job is a buildable item.
*
* Note the estimated build number calculation is a guess - job types need not return
* sequential build numbers.
*
* @return List of items newest first
*/
public static List<BlueQueueItem> getQueuedItems(Job job) {
Link pipelineLink = LinkResolver.resolveLink(job);
if (job instanceof BuildableItem) {
BuildableItem task = (BuildableItem) job;
List<Queue.Item> items = Jenkins.getInstance().getQueue().getItems(task);
List<BlueQueueItem> items2 = Lists.newArrayList();
for (int i = 0; i < items.size(); i++) {
Link self = pipelineLink.rel("queue").rel(Long.toString(items.get(i).getId()));
items2.add(0, new QueueItemImpl(items.get(i), job.getName(), (items.size() == 1 ? job.getNextBuildNumber() : job.getNextBuildNumber() + i), self, pipelineLink));
}
return items2;
} else {
throw new ServiceException.UnexpectedErrorException("This pipeline is not buildable and therefore does not have a queue.");
}
}
use of io.jenkins.blueocean.rest.hal.Link in project blueocean-plugin by jenkinsci.
the class GenericResource method getResource.
private Object getResource(String token, Method m) {
final Object v;
try {
v = m.invoke(value);
} catch (IllegalAccessException | InvocationTargetException e) {
LOGGER.error(e.getMessage(), e);
throw new ServiceException.NotFoundException("Path " + token + " is not found");
}
Link subResLink = getLink().rel(token + "/");
if (v instanceof List) {
return Containers.from(subResLink, (List) v);
} else if (v instanceof Map) {
return Containers.from(subResLink, (Map) v);
} else if (v instanceof String) {
return new PrimitiveTypeResource(subResLink, v);
}
return new GenericResource<>(v);
}
Aggregations