Search in sources :

Example 11 with Link

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());
}
Also used : User(hudson.model.User) ChangeLogSet(hudson.scm.ChangeLogSet) Reachable(io.jenkins.blueocean.rest.Reachable) ChangeSetResource(io.jenkins.blueocean.service.embedded.rest.ChangeSetResource) Link(io.jenkins.blueocean.rest.hal.Link) OrganizationImpl(io.jenkins.blueocean.service.embedded.rest.OrganizationImpl) Test(org.junit.Test)

Example 12 with Link

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");
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) BlueRun(io.jenkins.blueocean.rest.model.BlueRun) BlueRun(io.jenkins.blueocean.rest.model.BlueRun) Run(hudson.model.Run) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) BluePipelineNode(io.jenkins.blueocean.rest.model.BluePipelineNode) URL(java.net.URL) Link(io.jenkins.blueocean.rest.hal.Link) Test(org.junit.Test)

Example 13 with Link

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);
}
Also used : FilePath(hudson.FilePath) ArtifactArchiver(hudson.tasks.ArtifactArchiver) IOException(java.io.IOException) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) TestBuilder(org.jvnet.hudson.test.TestBuilder) BuildListener(hudson.model.BuildListener) BlueArtifact(io.jenkins.blueocean.rest.model.BlueArtifact) Launcher(hudson.Launcher) List(java.util.List) ArtifactContainerImpl(io.jenkins.blueocean.service.embedded.rest.ArtifactContainerImpl) Link(io.jenkins.blueocean.rest.hal.Link) Test(org.junit.Test)

Example 14 with Link

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.");
    }
}
Also used : BlueQueueItem(io.jenkins.blueocean.rest.model.BlueQueueItem) BuildableItem(hudson.model.BuildableItem) BuildableItem(hudson.model.BuildableItem) BlueQueueItem(io.jenkins.blueocean.rest.model.BlueQueueItem) Link(io.jenkins.blueocean.rest.hal.Link)

Example 15 with Link

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);
}
Also used : ServiceException(io.jenkins.blueocean.commons.ServiceException) List(java.util.List) Map(java.util.Map) InvocationTargetException(java.lang.reflect.InvocationTargetException) Link(io.jenkins.blueocean.rest.hal.Link)

Aggregations

Link (io.jenkins.blueocean.rest.hal.Link)30 Test (org.junit.Test)12 BlueRun (io.jenkins.blueocean.rest.model.BlueRun)8 Run (hudson.model.Run)7 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)7 Reachable (io.jenkins.blueocean.rest.Reachable)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 BlueOrganization (io.jenkins.blueocean.rest.model.BlueOrganization)5 BluePipelineNode (io.jenkins.blueocean.rest.model.BluePipelineNode)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)4 Job (hudson.model.Job)3 ServiceException (io.jenkins.blueocean.commons.ServiceException)3 BluePipelineStep (io.jenkins.blueocean.rest.model.BluePipelineStep)3 BlueQueueItem (io.jenkins.blueocean.rest.model.BlueQueueItem)3