org.jvnet.hudson.test.MockFolder Java Examples

The following examples show how to use org.jvnet.hudson.test.MockFolder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LinkResolverTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void nestedFolderJobLinkResolveTest() throws IOException {
    Project f = j.createFreeStyleProject("fstyle1");
    MockFolder folder1 = j.createFolder("folder1");
    Project p1 = folder1.createProject(FreeStyleProject.class, "test1");
    MockFolder folder2 = folder1.createProject(MockFolder.class, "folder2");
    MockFolder folder3 = folder2.createProject(MockFolder.class, "folder3");
    Project p2 = folder2.createProject(FreeStyleProject.class, "test2");
    Project p3 = folder3.createProject(FreeStyleProject.class, "test3");

    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/fstyle1/",LinkResolver.resolveLink(f).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/",LinkResolver.resolveLink(folder1).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/test1/",LinkResolver.resolveLink(p1).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/",LinkResolver.resolveLink(folder2).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/test2/",LinkResolver.resolveLink(p2).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/folder3/",LinkResolver.resolveLink(folder3).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/folder3/pipelines/test3/",LinkResolver.resolveLink(p3).getHref());
}
 
Example #2
Source File: PipelineSearchTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void testOrganizationSearch() throws IOException {
    j.createFreeStyleProject("aa");
    j.createFreeStyleProject("bb");
    MockFolder folder = j.createFolder("Cool");
    folder.createProject(FreeStyleProject.class, "aa");
    folder.createProject(FreeStyleProject.class, "yy");
    folder.createProject(FreeStyleProject.class, "zz");

    // user types "a"
    List req = request()
        .get("/search/?q=type:pipeline;pipeline:*a*;organization:jenkins")
        .build(List.class);

    Assert.assertEquals(2, req.size());
    Assert.assertEquals("aa", ((Map) req.get(0)).get("fullName"));
    Assert.assertEquals("Cool/aa", ((Map) req.get(1)).get("fullName"));
}
 
Example #3
Source File: PipelineSearchTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void testOrganizationSearchWithKnownPrefix() throws IOException {
    j.createFreeStyleProject("aa");
    j.createFreeStyleProject("bb");
    MockFolder folder = j.createFolder("Cool");
    folder.createProject(FreeStyleProject.class, "yy");
    folder.createProject(FreeStyleProject.class, "zz");

    // user types "cool/"
    List req = request()
        .get("/search/?q=type:pipeline;pipeline:Cool/*;organization:jenkins")
        .build(List.class);

    Assert.assertEquals(2, req.size());
    Assert.assertEquals("Cool/yy", ((Map) req.get(0)).get("fullName"));
    Assert.assertEquals("Cool/zz", ((Map) req.get(1)).get("fullName"));
}
 
Example #4
Source File: PipelineSearchTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void testOrganizationSearchWithPartialPath() throws IOException {
    j.createFreeStyleProject("aa");
    j.createFreeStyleProject("bb");
    MockFolder folder = j.createFolder("Cool");
    folder.createProject(FreeStyleProject.class, "yy");
    folder.createProject(FreeStyleProject.class, "zz");

    // user types "c/z"
    List req = request()
        .get("/search/?q=type:pipeline;pipeline:*c*/*z*;organization:jenkins")
        .build(List.class);

    Assert.assertEquals(1, req.size());
    Assert.assertEquals("Cool/zz", ((Map) req.get(0)).get("fullName"));
}
 
Example #5
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void getMultiBranchPipelineInsideFolder() throws IOException, ExecutionException, InterruptedException {
    MockFolder folder1 = j.createFolder("folder1");
    WorkflowMultiBranchProject mp = folder1.createProject(WorkflowMultiBranchProject.class, "p");
    mp.setDisplayName("My MBP");

    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }

    mp.scheduleBuild2(0).getFuture().get();

    Map r = get("/organizations/jenkins/pipelines/folder1/pipelines/p/");

    validateMultiBranchPipeline(mp, r, 3);
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/p/",
        ((Map)((Map)r.get("_links")).get("self")).get("href"));
    Assert.assertEquals("folder1/My%20MBP", r.get("fullDisplayName"));
    r = get("/organizations/jenkins/pipelines/folder1/pipelines/p/master/");
    Assert.assertEquals("folder1/My%20MBP/master", r.get("fullDisplayName"));
}
 
Example #6
Source File: PipelineApiTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void findAllPipelineTest() throws IOException, ExecutionException, InterruptedException {
    MockFolder folder1 = j.createFolder("folder1");
    j.createFolder("afolder");
    Project p1 = folder1.createProject(FreeStyleProject.class, "test1");
    MockFolder folder2 = folder1.createProject(MockFolder.class, "folder2");
    folder1.createProject(MockFolder.class, "folder3");
    folder2.createProject(FreeStyleProject.class, "test2");

    FreeStyleBuild b1 = (FreeStyleBuild) p1.scheduleBuild2(0).get();


    List<Map> resp = get("/search?q=type:pipeline", List.class);

    assertEquals(6, resp.size());
}
 
Example #7
Source File: PipelineApiTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void findAllPipelineByGlob() throws IOException, ExecutionException, InterruptedException {
    MockFolder folder1 = j.createFolder("folder1");
    j.createFolder("afolder");
    Project p1 = folder1.createProject(FreeStyleProject.class, "test1");
    MockFolder folder2 = folder1.createProject(MockFolder.class, "folder2");
    folder1.createProject(MockFolder.class, "folder3");
    folder2.createProject(FreeStyleProject.class, "test2");
    folder2.createProject(FreeStyleProject.class, "coolPipeline");
    List<Map> resp = get("/search?q=type:pipeline;pipeline:*TEST*", List.class);
    assertEquals(2, resp.size());

    resp = get("/search?q=type:pipeline;pipeline:*cool*", List.class);
    assertEquals(1, resp.size());

    resp = get("/search?q=type:pipeline;pipeline:*nothing*", List.class);
    assertEquals(0, resp.size());

    resp = get("/search?q=type:pipeline;pipeline:*f*", List.class);
    assertEquals(7, resp.size());
}
 
Example #8
Source File: PipelineApiTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void PipelineSecureWithAnonymousUserPermissionTest() throws IOException {
    j.jenkins.setSecurityRealm(new HudsonPrivateSecurityRealm(false));
    j.jenkins.setAuthorizationStrategy(new LegacyAuthorizationStrategy());

    MockFolder folder = j.createFolder("folder1");

    Project p = folder.createProject(FreeStyleProject.class, "test1");

    Map response = get("/organizations/jenkins/pipelines/folder1/pipelines/test1");
    validatePipeline(p, response);

    Map<String,Boolean> permissions = (Map<String, Boolean>) response.get("permissions");
    Assert.assertFalse(permissions.get("create"));
    Assert.assertFalse(permissions.get("start"));
    Assert.assertFalse(permissions.get("stop"));
    assertTrue(permissions.get("read"));

    response = get("/organizations/jenkins/pipelines/folder1/");

    permissions = (Map<String, Boolean>) response.get("permissions");
    Assert.assertFalse(permissions.get("create"));
    Assert.assertFalse(permissions.get("start"));
    Assert.assertFalse(permissions.get("stop"));
    assertTrue(permissions.get("read"));
}
 
Example #9
Source File: PipelineApiTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void PipelineSecureWithLoggedInUserPermissionTest() throws IOException, UnirestException {
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());

    hudson.model.User user = User.get("alice");
    user.setFullName("Alice Cooper");


    MockFolder folder = j.createFolder("folder1");

    Project p = folder.createProject(FreeStyleProject.class, "test1");
    String token = getJwtToken(j.jenkins, "alice", "alice");
    assertNotNull(token);
    Map response = new RequestBuilder(baseUrl)
        .get("/organizations/jenkins/pipelines/folder1/pipelines/test1")
        .jwtToken(token)
        .build(Map.class);

    validatePipeline(p, response);

    Map<String,Boolean> permissions = (Map<String, Boolean>) response.get("permissions");
    assertTrue(permissions.get("create"));
    assertTrue(permissions.get("start"));
    assertTrue(permissions.get("stop"));
    assertTrue(permissions.get("read"));
}
 
Example #10
Source File: BlueOceanWebURLBuilderTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Test
public void getMultiBranchPipelineInsideFolder() throws Exception {
    MockFolder folder1 = jenkinsRule.createFolder("folder1");
    MockFolder folder2 = folder1.createProject(MockFolder.class, "folder two with spaces");
    WorkflowMultiBranchProject mp = folder2.createProject(WorkflowMultiBranchProject.class, "p");

    String blueOceanURL;

    blueOceanURL = urlMapper.getUrl(mp);
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/branches/", blueOceanURL);

    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false), new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }

    mp.scheduleBuild2(0).getFuture().get();
    jenkinsRule.waitUntilNoActivity();

    // All branch jobs should just resolve back to the same top level branches
    // page for the multibranch job in Blue Ocean.
    WorkflowJob masterJob = findBranchProject(mp, "master");
    blueOceanURL = urlMapper.getUrl(masterJob);
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/branches/", blueOceanURL);
    WorkflowJob featureUx1Job = findBranchProject(mp, "feature/ux-1");
    blueOceanURL = urlMapper.getUrl(featureUx1Job);
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/branches/", blueOceanURL);
    WorkflowJob feature2Job = findBranchProject(mp, "feature2");
    blueOceanURL = urlMapper.getUrl(feature2Job);
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/branches/", blueOceanURL);

    // Runs on the jobs
    blueOceanURL = urlMapper.getUrl(masterJob.getFirstBuild());
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/detail/master/1/", blueOceanURL);
    blueOceanURL = urlMapper.getUrl(featureUx1Job.getFirstBuild());
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/detail/feature%2Fux-1/1/", blueOceanURL);
}
 
Example #11
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Test
public void testMultiBranchPipelineBranchSecurePermissions() throws IOException, ExecutionException, InterruptedException {
    j.jenkins.setSecurityRealm(new HudsonPrivateSecurityRealm(false));
    j.jenkins.setAuthorizationStrategy(new LegacyAuthorizationStrategy());

    MockFolder folder1 = j.createFolder("folder1");
    WorkflowMultiBranchProject mp = folder1.createProject(WorkflowMultiBranchProject.class, "p");

    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }

    mp.scheduleBuild2(0).getFuture().get();


    Map r = get("/organizations/jenkins/pipelines/folder1/pipelines/p/");


    Map<String,Boolean> permissions = (Map<String, Boolean>) r.get("permissions");
    Assert.assertFalse(permissions.get("create"));
    Assert.assertTrue(permissions.get("read"));
    Assert.assertFalse(permissions.get("start"));
    Assert.assertFalse(permissions.get("stop"));



    r = get("/organizations/jenkins/pipelines/folder1/pipelines/p/branches/master/");

    permissions = (Map<String, Boolean>) r.get("permissions");
    Assert.assertFalse(permissions.get("create"));
    Assert.assertFalse(permissions.get("start"));
    Assert.assertFalse(permissions.get("stop"));
    Assert.assertTrue(permissions.get("read"));
}
 
Example #12
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Test
public void testMultiBranchPipelineBranchUnsecurePermissions() throws IOException, ExecutionException, InterruptedException {
    MockFolder folder1 = j.createFolder("folder1");
    WorkflowMultiBranchProject mp = folder1.createProject(WorkflowMultiBranchProject.class, "p");

    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }

    mp.scheduleBuild2(0).getFuture().get();


    Map r = get("/organizations/jenkins/pipelines/folder1/pipelines/p/");


    Map<String,Boolean> permissions = (Map<String, Boolean>) r.get("permissions");
    Assert.assertTrue(permissions.get("create"));
    Assert.assertTrue(permissions.get("read"));
    Assert.assertTrue(permissions.get("start"));
    Assert.assertTrue(permissions.get("stop"));



    r = get("/organizations/jenkins/pipelines/folder1/pipelines/p/branches/master/");

    permissions = (Map<String, Boolean>) r.get("permissions");
    Assert.assertTrue(permissions.get("create"));
    Assert.assertTrue(permissions.get("start"));
    Assert.assertTrue(permissions.get("stop"));
    Assert.assertTrue(permissions.get("read"));
}
 
Example #13
Source File: LinkResolverTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Test
public void nestedFolderJobLinkResolveTest() throws IOException {
    Project f = j.createFreeStyleProject("fstyle1");
    MockFolder folder1 = j.createFolder("folder1");
    Project p1 = folder1.createProject(FreeStyleProject.class, "test1");
    MockFolder folder2 = folder1.createProject(MockFolder.class, "folder2");
    MockFolder folder3 = folder2.createProject(MockFolder.class, "folder3");
    Project p2 = folder2.createProject(FreeStyleProject.class, "test2");
    Project p3 = folder3.createProject(FreeStyleProject.class, "test3");

    WorkflowJob pipelineJob1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    pipelineJob1.setDefinition(new CpsFlowDefinition("stage \"Build\"\n" +
        "    node {\n" +
        "       sh \"echo here\"\n" +
        "    }\n" +
        "\n"));

    WorkflowJob pipelineJob2 = folder2.createProject(WorkflowJob.class, "pipeline2");
    pipelineJob2.setDefinition(new CpsFlowDefinition("stage \"Build\"\n" +
        "    node {\n" +
        "       sh \"echo here\"\n" +
        "    }\n" +
        "\n"));


    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/pipeline1/",LinkResolver.resolveLink(pipelineJob1).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/pipeline2/",LinkResolver.resolveLink(pipelineJob2).getHref());

    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/fstyle1/",LinkResolver.resolveLink(f).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/",LinkResolver.resolveLink(folder1).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/test1/",LinkResolver.resolveLink(p1).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/",LinkResolver.resolveLink(folder2).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/test2/",LinkResolver.resolveLink(p2).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/folder3/",LinkResolver.resolveLink(folder3).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/folder3/pipelines/test3/",LinkResolver.resolveLink(p3).getHref());
}
 
Example #14
Source File: BaseTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
protected void validateFolder(MockFolder folder, Map resp){
    Assert.assertEquals("jenkins", resp.get("organization"));
    Assert.assertEquals(folder.getName(), resp.get("name"));
    Assert.assertEquals(folder.getDisplayName(), resp.get("displayName"));
    Assert.assertEquals(folder.getFullName(), resp.get("fullName"));
    Assert.assertEquals(folder.getAllJobs().size(), resp.get("numberOfPipelines"));
    Assert.assertEquals(folder.getAllJobs().size(), resp.get("numberOfPipelines"));
}
 
Example #15
Source File: BlueOceanWebURLBuilderTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Test
public void test_freestyle() throws IOException, ExecutionException, InterruptedException {
    MockFolder folder1 = jenkinsRule.createFolder("folder1");
    MockFolder folder2 = folder1.createProject(MockFolder.class, "folder two with spaces");
    FreeStyleProject freestyleProject = folder2.createProject(FreeStyleProject.class, "freestyle with spaces");
    String blueOceanURL;

    blueOceanURL = urlMapper.getUrl(freestyleProject);
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Ffreestyle%20with%20spaces/", blueOceanURL);

    FreeStyleBuild run = freestyleProject.scheduleBuild2(0).get();
    blueOceanURL = urlMapper.getUrl(run);
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Ffreestyle%20with%20spaces/detail/freestyle%20with%20spaces/1/", blueOceanURL);
}
 
Example #16
Source File: AbortRunningJobRunnerCauseTest.java    From github-integration-plugin with MIT License 5 votes vote down vote up
@Test
@RandomlyFails(value = "No idea why it doesn't work normally")
public void testAbortRunningFreestyleProject() throws Exception {

    MockFolder folder = j.createFolder("freestyle_folder");

    FreeStyleProject job1 = folder.createProject(FreeStyleProject.class, "project1");
    job1.setDisplayName("project1 display name");
    job1.setConcurrentBuild(true);
    job1.getBuildersList().add(new SleepBuilder());
    configRoundTripUnsecure(job1);
    job1.save();

    FreeStyleProject job2 = folder.createProject(FreeStyleProject.class, "project2");
    job2.setDisplayName("project1 display name");
    job2.setConcurrentBuild(true);
    job2.getBuildersList().add(new SleepBuilder());
    configRoundTripUnsecure(job2);
    job2.save();

    FreeStyleProject job3 = folder.createProject(FreeStyleProject.class, "project3");
    job3.setDisplayName("project1 display name");
    job3.setConcurrentBuild(true);
    job3.getBuildersList().add(new SleepBuilder());
    configRoundTripUnsecure(job3);
    job3.save();

    testAbortRunning(job1, job2, job3);
}
 
Example #17
Source File: PipelineApiTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Test
public void PipelineUnsecurePermissionTest() throws IOException {
    MockFolder folder = j.createFolder("folder1");

    Project p = folder.createProject(FreeStyleProject.class, "test1");

    Map response = get("/organizations/jenkins/pipelines/folder1/pipelines/test1");
    validatePipeline(p, response);

    Map<String,Boolean> permissions = (Map<String, Boolean>) response.get("permissions");
    assertTrue(permissions.get("create"));
    assertTrue(permissions.get("start"));
    assertTrue(permissions.get("stop"));
    assertTrue(permissions.get("read"));
}
 
Example #18
Source File: AbortRunningJobRunnerCauseTest.java    From github-integration-plugin with MIT License 5 votes vote down vote up
@Test
@RandomlyFails(value = "No idea why workflow doesn't work normally")
public void testAbortRunningWorkflow() throws Exception {

    MockFolder folder = j.createFolder("workflow_folder");

    WorkflowJob job1 = folder.createProject(WorkflowJob.class, "job1");
    job1.setDisplayName("WorkflowJob 1 display name");
    job1.setConcurrentBuild(true);
    job1.setDefinition(new SleepFlow());
    configRoundTripUnsecure(job1);
    job1.save();

    WorkflowJob job2 = folder.createProject(WorkflowJob.class, "job2");
    job2.setDisplayName("WorkflowJob 2 display name");
    job2.setConcurrentBuild(true);
    job2.setDefinition(new SleepFlow());
    configRoundTripUnsecure(job2);
    job2.save();

    WorkflowJob job3 = folder.createProject(WorkflowJob.class, "job3");
    job3.setDisplayName("WorkflowJob 3 display name");
    job3.setConcurrentBuild(true);
    job3.setDefinition(new SleepFlow());
    configRoundTripUnsecure(job3);
    job3.save();

    Thread.sleep(30 * 1000); // allow get jobs to executors
    testAbortRunning(job1, job2, job3);
}
 
Example #19
Source File: PipelineApiTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Test
public void linkStartLimitTest() throws IOException, UnirestException {
    MockFolder folder = j.createFolder("folder1");
    Project p = folder.createProject(FreeStyleProject.class, "test1");

    HttpResponse<String> response = Unirest.get(getBaseUrl("/organizations/jenkins/pipelines/folder1/pipelines/"))
            .header("Accept-Encoding","")
            .header("Authorization", "Bearer "+jwtToken)
            .asString();

    String link = response.getHeaders().get("Link").get(0);

    assertEquals("</jenkins/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/?start=100&limit=100>; rel=\"next\"", link);

    response = Unirest.get(getBaseUrl("/search/?q=type:pipeline;excludedFromFlattening:jenkins.branch.MultiBranchProject,hudson.matrix.MatrixProject&filter1=no-folders&start=0&limit=26"))
            .header("Accept-Encoding","")
            .header("Authorization", "Bearer "+jwtToken)
            .asString();

    link = response.getHeaders().get("Link").get(0);

    assertEquals("</jenkins/blue/rest/search/?q=type:pipeline;excludedFromFlattening:jenkins.branch.MultiBranchProject,hudson.matrix.MatrixProject&filter1=no-folders&start=26&limit=26>; rel=\"next\"", link);


    response = Unirest.get(getBaseUrl("/organizations/jenkins/pipelines/folder1/pipelines/?start=10&limit=10&foo=bar"))
            .header("Accept-Encoding","")
            .header("Authorization", "Bearer "+jwtToken)
            .asString();

    link = response.getHeaders().get("Link").get(0);

    assertEquals("</jenkins/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/?foo=bar&start=20&limit=10>; rel=\"next\"", link);
}
 
Example #20
Source File: PipelineApiTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Test
public void getFolderPipelineTest() throws IOException {
    MockFolder folder = j.createFolder("folder1");
    Project p = folder.createProject(FreeStyleProject.class, "test1");

    Map response = get("/organizations/jenkins/pipelines/folder1/pipelines/test1");
    validatePipeline(p, response);
}
 
Example #21
Source File: ContainerFilterTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Test
public void customFilter() throws IOException {
    MockFolder folder = j.createFolder("folder1");
    Project p = folder.createProject(FreeStyleProject.class, "test1");
    Collection<Item> items = ContainerFilter.filter(j.getInstance().getAllItems(), "itemgroup-only");
    assertEquals(1, items.size());
    assertEquals(folder.getFullName(), items.iterator().next().getFullName());
}
 
Example #22
Source File: GitScmTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
private void setOrgRoot(String root) {
    if (root != null) {
        try {
            MockFolder itemGroup = Jenkins.getInstance().createProject(MockFolder.class, root);
            instance = new OrganizationImpl(root, itemGroup);
        } catch (IOException e) {
            throw new RuntimeException("Test setup failed!", e);
        }

    }
    else {
        instance = new OrganizationImpl("jenkins", Jenkins.getInstance());
    }
}
 
Example #23
Source File: AbortRunningJobRunnerCauseTest.java    From github-integration-plugin with MIT License 4 votes vote down vote up
@Test
@RandomlyFails(value = "No idea why matrix doesn't work normally")
public void testAbortRunningMatrixProject() throws Exception {

    MockFolder folder = j.createFolder("Matrix_folder");

    MatrixProject job1 = folder.createProject(MatrixProject.class, "project1");
    job1.setDisplayName("project1 display name");
    job1.setConcurrentBuild(true);
    job1.getBuildersList().add(new SleepBuilder());
    job1.setAxes(
            new AxisList(
                    new TextAxis("first_axis", "first_value1"),
                    new TextAxis("second_axis", "sec_value1")
            )
    );
    configRoundTripUnsecure(job1);
    job1.save();

    MatrixProject job2 = folder.createProject(MatrixProject.class, "project2");
    job2.setDisplayName("project1 display name");
    job2.setConcurrentBuild(true);
    job2.getBuildersList().add(new SleepBuilder());
    job2.setAxes(
            new AxisList(
                    new TextAxis("first_axis", "first_value1"),
                    new TextAxis("second_axis", "sec_value1")
            )
    );
    configRoundTripUnsecure(job2);
    job2.save();

    MatrixProject job3 = folder.createProject(MatrixProject.class, "project3");
    job3.setDisplayName("project1 display name");
    job3.setConcurrentBuild(true);
    job3.getBuildersList().add(new SleepBuilder());
    job3.setAxes(
            new AxisList(
                    new TextAxis("first_axis", "first_value1"),
                    new TextAxis("second_axis", "sec_value1")
            )
    );
    configRoundTripUnsecure(job3);
    job3.save();

    testAbortRunning(job1, job2, job3);

    assertThat(job1.getBuilds(), hasSize(3));

    for (MatrixBuild matrixBuild : job1.getBuilds()) {
        assertThat(matrixBuild.getResult(), is(Result.ABORTED));
        assertThat(matrixBuild.getRuns(), not(empty()));
        for (MatrixRun matrixRun : matrixBuild.getRuns()) {
            assertThat(matrixRun.getResult(), is(Result.ABORTED));
        }
    }
}
 
Example #24
Source File: SseEventTest.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Test
public void multiBranchJobEventsWithCustomOrg() throws Exception {
    MockFolder folder = j.createFolder("TestOrgFolderName");
    assertNotNull(folder);

    setupScm();

    final OneShotEvent success = new OneShotEvent();

    final Boolean[] pipelineNameMatched = {null};
    final Boolean[] mbpPipelineNameMatched = {null};

    SSEConnection con = new SSEConnection(j.getURL(), "me", new ChannelSubscriber() {
        @Override
        public void onMessage(@Nonnull Message message) {
            System.out.println(message);
            if("job".equals(message.get(jenkins_channel))) {
                if ("org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject".equals(message.get(jenkins_object_type))) {
                    if("pipeline1".equals(message.get(blueocean_job_pipeline_name))) {
                        mbpPipelineNameMatched[0] = true;
                    }else{
                        mbpPipelineNameMatched[0] = false;
                    }
                } else if ("org.jenkinsci.plugins.workflow.job.WorkflowJob".equals(message.get(jenkins_object_type))) {
                    if("pipeline1".equals(message.get(blueocean_job_pipeline_name))) {
                        pipelineNameMatched[0] = true;
                    }else {
                        pipelineNameMatched[0] = false;
                    }
                }
            }
            if(pipelineNameMatched[0] != null && mbpPipelineNameMatched[0] != null){
                success.signal();
            }
        }
    });
    con.subscribe("pipeline");
    con.subscribe("job");

    final WorkflowMultiBranchProject mp = folder.createProject(WorkflowMultiBranchProject.class, "pipeline1");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false),
            new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }

    mp.scheduleBuild2(0).getFuture().get();

    WorkflowJob p = mp.getItem("master");
    if (p == null) {
        mp.getIndexing().writeWholeLogTo(System.out);
        fail("master project not found");
    }
    j.waitUntilNoActivity();
    WorkflowRun b1 = p.getLastBuild();
    assertEquals(1, b1.getNumber());
    assertEquals(2, mp.getItems().size());

    success.block(5000);
    con.close();
    if(success.isSignaled()) {
        assertTrue(pipelineNameMatched[0]);
        assertTrue(mbpPipelineNameMatched[0]);
    }
}
 
Example #25
Source File: PipelineApiTest.java    From blueocean-plugin with MIT License 4 votes vote down vote up
/**
 * Tests the API when the organization root is a folder instead of the root jenkins. That organization should only
 * see the elements under that folder.
 */
@Test
@Issue({ "JENKINS-44176", "JENKINS-44270" })
public void testOrganizationFolder() throws IOException, ExecutionException, InterruptedException {

    FreeStyleProject jobOutSideOrg = j.createFreeStyleProject("pipelineOutsideOrgName");
    jobOutSideOrg.setDisplayName("pipelineOutsideOrg Display Name");

    MockFolder orgFolder = j.createFolder("TestOrgFolderName");
    orgFolder.setDisplayName("TestOrgFolderName Display Name");

    MockFolder folderOnOrg = orgFolder.createProject(MockFolder.class, "folderOnOrgName");
    folderOnOrg.setDisplayName("folderOnOrg Display Name");

    FreeStyleProject jobOnRootOrg = orgFolder.createProject(FreeStyleProject.class, "jobOnRootOrgName");
    jobOnRootOrg.setDisplayName("jobOnRootOrg Display Name");

    FreeStyleProject jobOnFolder = folderOnOrg.createProject(FreeStyleProject.class, "jobOnFolderName");
    jobOnFolder.setDisplayName("jobOnFolder Display Name");

    List<Map> pipelines = get("/search/?q=type:pipeline;organization:TestOrg;excludedFromFlattening:jenkins.branch.MultiBranchProject,hudson.matrix.MatrixProject", List.class);

    //Only what's inside the org folder should be returned
    Assert.assertEquals(3, pipelines.size());

    //The full name should not contain the organization folder name
    Map links;
    for (Map map : pipelines) {
        Assert.assertEquals("TestOrg", map.get("organization"));
        if (map.get("name").equals("folderOnOrgName")) {
            map.get("fullDisplayName").equals("folderOnOrg%20Display%20Name");
            map.get("fullName").equals("folderOnOrgName");
            checkLinks((Map) map.get("_links"), "/blue/rest/organizations/TestOrg/pipelines/folderOnOrgName/");
        } else if (map.get("name").equals("jobOnRootOrgName")) {
            map.get("fullDisplayName").equals("jobOnRootOrg%20Display%20Name");
            map.get("fullName").equals("jobOnRootOrgName");
            checkLinks((Map) map.get("_links"), "/blue/rest/organizations/TestOrg/pipelines/jobOnRootOrgName/");
        } else if (map.get("name").equals("jobOnFolderName")) {
            map.get("fullDisplayName").equals("folderOnOrg%20Display%20Name/jobOnFolder%20Display%20Name");
            map.get("fullName").equals("folderOnOrgName/jobOnFolderName");
            checkLinks((Map) map.get("_links"), "/blue/rest/organizations/TestOrg/pipelines/folderOnOrgName/pipelines/jobOnFolderName/");
        } else {
            Assert.fail("Item " + map.get("name") + " shouldn't be present");
        }
    }
}
 
Example #26
Source File: PipelineApiTest.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Test
public void getNestedFolderPipelineTest() throws IOException {
    MockFolder folder1 = j.createFolder("folder1");
    Project p1 = folder1.createProject(FreeStyleProject.class, "test1");
    MockFolder folder2 = folder1.createProject(MockFolder.class, "folder2");
    folder2.setDisplayName("My folder2");
    MockFolder folder3 = folder1.createProject(MockFolder.class, "folder3");
    Project p2 = folder2.createProject(FreeStyleProject.class, "test2");

    List<Map> topFolders = get("/organizations/jenkins/pipelines/", List.class);

    assertEquals(1, topFolders.size());

    Map response = get("/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/test2");
    validatePipeline(p2, response);

    List<Map> pipelines = get("/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/", List.class);
    assertEquals(1, pipelines.size());
    validatePipeline(p2, pipelines.get(0));

    pipelines = get("/organizations/jenkins/pipelines/folder1/pipelines/", List.class);
    assertEquals(3, pipelines.size());
    assertEquals("folder2", pipelines.get(0).get("name"));
    assertEquals("folder1/folder2", pipelines.get(0).get("fullName"));
    assertEquals("folder1/My%20folder2", pipelines.get(0).get("fullDisplayName"));

    response = get("/organizations/jenkins/pipelines/folder1");
    assertEquals("folder1", response.get("name"));
    assertEquals("folder1", response.get("displayName"));
    assertEquals(2, response.get("numberOfFolders"));
    assertEquals(1, response.get("numberOfPipelines"));
    assertEquals("folder1", response.get("fullName"));

    String clazz = (String) response.get("_class");

    response = get("/classes/"+clazz+"/");
    assertNotNull(response);

    List<String> classes = (List<String>) response.get("classes");
    assertTrue(!classes.contains("hudson.model.Job")
        && classes.contains("io.jenkins.blueocean.rest.model.BluePipeline")
        && classes.contains("io.jenkins.blueocean.rest.model.BluePipelineFolder")
        && classes.contains("com.cloudbees.hudson.plugins.folder.AbstractFolder"));
}
 
Example #27
Source File: ProfileApiTest.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Test
public void createUserFavouriteFolderTest() throws Exception {
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    hudson.model.User user = User.get("alice");
    user.setFullName("Alice Cooper");

    MockFolder folder1 = j.createFolder("folder1");
    Project p = folder1.createProject(FreeStyleProject.class, "pipeline1");

    //String token = getJwtToken(j.jenkins,"alice", "alice");
    Map map = new RequestBuilder(baseUrl)
        .put("/organizations/jenkins/pipelines/folder1/pipelines/pipeline1/favorite/")
        .authAlice()
        .data(ImmutableMap.of("favorite", true))
        .build(Map.class);

    validatePipeline(p, (Map) map.get("item"));
    List l = new RequestBuilder(baseUrl)
        .get("/users/"+user.getId()+"/favorites/")
        .authAlice()
        .build(List.class);

    assertEquals(1, l.size());
    Map pipeline = (Map)((Map)l.get(0)).get("item");

    validatePipeline(p, pipeline);

    String href = getHrefFromLinks((Map)l.get(0),"self");

    assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/pipeline1/favorite/", href);

    map = new RequestBuilder(baseUrl)
        .put(href.substring("/blue/rest".length()))
        .authAlice()
        .data(ImmutableMap.of("favorite", false))
        .build(Map.class);

    validatePipeline(p, (Map) map.get("item"));

    l = new RequestBuilder(baseUrl)
        .get("/users/"+user.getId()+"/favorites/")
        .authAlice()
        .build(List.class);

    assertEquals(0, l.size());


    new RequestBuilder(baseUrl)
        .put("/organizations/jenkins/pipelines/folder1/favorite/")
        .authAlice()
        .data(ImmutableMap.of("favorite", true))
        .status(405)
        .build(Map.class);

    new RequestBuilder(baseUrl)
        .put("/organizations/jenkins/pipelines/folder1/favorite/")
        .authAlice()
        .data(ImmutableMap.of("favorite", false))
        .status(405)
        .build(Map.class);

    l = new RequestBuilder(baseUrl)
        .get("/users/"+user.getId()+"/favorites/")
        .authAlice()
        .build(List.class);

    assertEquals(0, l.size());

}