Search in sources :

Example 1 with MatrixProject

use of hudson.matrix.MatrixProject in project blueocean-plugin by jenkinsci.

the class PipelineApiTest method matrixProjectTest.

@Test
public void matrixProjectTest() throws Exception {
    MatrixProject mp = j.jenkins.createProject(MatrixProject.class, "mp1");
    mp.getAxes().add(new Axis("os", "linux", "windows"));
    mp.getAxes().add(new Axis("jdk", "1.7", "1.8"));
    MatrixBuild matrixBuild = mp.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(matrixBuild);
    List<Map> pipelines = get("/search/?q=type:pipeline;excludedFromFlattening:jenkins.branch.MultiBranchProject,hudson.matrix.MatrixProject", List.class);
    Assert.assertEquals(1, pipelines.size());
    Map p = pipelines.get(0);
    Assert.assertEquals("mp1", p.get("name"));
    String href = getHrefFromLinks(p, "self");
    Assert.assertEquals("/job/mp1/", href);
}
Also used : MatrixProject(hudson.matrix.MatrixProject) Map(java.util.Map) Axis(hudson.matrix.Axis) MatrixBuild(hudson.matrix.MatrixBuild) Test(org.junit.Test)

Example 2 with MatrixProject

use of hudson.matrix.MatrixProject in project hudson-2.x by hudson.

the class FreeStyleProjectTest method testOnCopiedFrom.

@Test
public void testOnCopiedFrom() {
    Hudson hudson = createMock(Hudson.class);
    AuthorizationStrategy authorizationStrategy = createMock(ProjectMatrixAuthorizationStrategy.class);
    expect(hudson.getAuthorizationStrategy()).andReturn(authorizationStrategy);
    mockStatic(Hudson.class);
    expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
    User user = createMock(User.class);
    expect(user.getId()).andReturn(USER).times(2);
    mockStatic(User.class);
    expect(User.current()).andReturn(user);
    replayAll();
    MatrixProject matrixProjectProject = new MatrixProject("matrixProject");
    FreeStyleProject freeStyleProject = new FreeStyleProjectMock("testJob");
    freeStyleProject.onCopiedFrom(matrixProjectProject);
    verifyAll();
    assertEquals(freeStyleProject.getNextBuildNumber(), 1);
    assertTrue(freeStyleProject.isHoldOffBuildUntilSave());
    assertNotNull(freeStyleProject.getCreationTime());
    assertEquals(freeStyleProject.getCreatedBy(), USER);
    List properties = freeStyleProject.getAllProperties();
    assertEquals(properties.size(), 1);
    AuthorizationMatrixProperty property = (AuthorizationMatrixProperty) properties.get(0);
    assertEquals(property.getGrantedPermissions().keySet().size(), 7);
    assertNotNull(property.getGrantedPermissions().get(Item.CONFIGURE));
    assertTrue(property.getGrantedPermissions().get(Item.CONFIGURE).contains(USER));
}
Also used : ProjectMatrixAuthorizationStrategy(hudson.security.ProjectMatrixAuthorizationStrategy) GlobalMatrixAuthorizationStrategy(hudson.security.GlobalMatrixAuthorizationStrategy) AuthorizationStrategy(hudson.security.AuthorizationStrategy) List(java.util.List) MatrixProject(hudson.matrix.MatrixProject) AuthorizationMatrixProperty(hudson.security.AuthorizationMatrixProperty) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with MatrixProject

use of hudson.matrix.MatrixProject in project hudson-2.x by hudson.

the class ProjectServiceImpl method findProject.

public AbstractProject<?, ?> findProject(final String projectName) {
    checkProjectName(projectName);
    // Handle matrix-project/configuration projects.
    // First part is matrix-project name, second part is
    // matrix-configuration name
    String[] parts = projectName.split("/", 2);
    if (parts.length == 2) {
        log.debug("Detected matrix name: {}", projectName);
        AbstractProject<?, ?> parent = findProject(parts[0]);
        if (parent instanceof MatrixProject) {
            for (MatrixConfiguration config : ((MatrixProject) parent).getItems()) {
                if (parts[1].equals(config.getName())) {
                    log.debug("Selected matrix configuration: {}", config);
                    // config.checkPermission(Item.READ); // TODO needed?
                    return config;
                }
            }
        }
    }
    if (!getProjectNames().contains(projectName)) {
        log.debug("Project {} not in the list of job names.", projectName);
        return null;
    }
    AbstractProject<?, ?> project = getProjectByFullName(projectName);
    log.debug("Selected project: {}", project);
    return project;
}
Also used : MatrixProject(hudson.matrix.MatrixProject) MatrixConfiguration(hudson.matrix.MatrixConfiguration)

Example 4 with MatrixProject

use of hudson.matrix.MatrixProject in project hudson-2.x by hudson.

the class FreeStyleProjectTest method testOnCopiedFromAnonymousAuthentication.

@Test
public void testOnCopiedFromAnonymousAuthentication() {
    Hudson hudson = createMock(Hudson.class);
    mockStatic(Hudson.class);
    expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
    mockStatic(User.class);
    expect(User.current()).andReturn(null);
    replayAll();
    MatrixProject matrixProjectProject = new MatrixProject("matrixProject");
    FreeStyleProject freeStyleProject = new FreeStyleProjectMock("testJob");
    freeStyleProject.onCopiedFrom(matrixProjectProject);
    verifyAll();
    assertEquals(freeStyleProject.getNextBuildNumber(), 1);
    assertTrue(freeStyleProject.isHoldOffBuildUntilSave());
    assertNotNull(freeStyleProject.getCreationTime());
    assertNull(freeStyleProject.getCreatedBy());
    List properties = freeStyleProject.getAllProperties();
    assertEquals(properties.size(), 0);
}
Also used : List(java.util.List) MatrixProject(hudson.matrix.MatrixProject) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with MatrixProject

use of hudson.matrix.MatrixProject in project hudson-2.x by hudson.

the class FreeStyleProjectTest method testOnCopiedFromGlobalMatrixAuthorizationStrategy.

@Test
public void testOnCopiedFromGlobalMatrixAuthorizationStrategy() {
    Hudson hudson = createMock(Hudson.class);
    AuthorizationStrategy authorizationStrategy = createMock(GlobalMatrixAuthorizationStrategy.class);
    expect(hudson.getAuthorizationStrategy()).andReturn(authorizationStrategy);
    mockStatic(Hudson.class);
    expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
    User user = createMock(User.class);
    expect(user.getId()).andReturn(USER).times(1);
    mockStatic(User.class);
    expect(User.current()).andReturn(user);
    replayAll();
    MatrixProject matrixProjectProject = new MatrixProject("matrixProject");
    FreeStyleProject freeStyleProject = new FreeStyleProjectMock("testJob");
    freeStyleProject.onCopiedFrom(matrixProjectProject);
    verifyAll();
    assertEquals(freeStyleProject.getNextBuildNumber(), 1);
    assertTrue(freeStyleProject.isHoldOffBuildUntilSave());
    assertNotNull(freeStyleProject.getCreationTime());
    assertEquals(freeStyleProject.getCreatedBy(), USER);
    assertEquals(freeStyleProject.getAllProperties().size(), 0);
}
Also used : ProjectMatrixAuthorizationStrategy(hudson.security.ProjectMatrixAuthorizationStrategy) GlobalMatrixAuthorizationStrategy(hudson.security.GlobalMatrixAuthorizationStrategy) AuthorizationStrategy(hudson.security.AuthorizationStrategy) MatrixProject(hudson.matrix.MatrixProject) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

MatrixProject (hudson.matrix.MatrixProject)5 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 AuthorizationStrategy (hudson.security.AuthorizationStrategy)2 GlobalMatrixAuthorizationStrategy (hudson.security.GlobalMatrixAuthorizationStrategy)2 ProjectMatrixAuthorizationStrategy (hudson.security.ProjectMatrixAuthorizationStrategy)2 List (java.util.List)2 Axis (hudson.matrix.Axis)1 MatrixBuild (hudson.matrix.MatrixBuild)1 MatrixConfiguration (hudson.matrix.MatrixConfiguration)1 AuthorizationMatrixProperty (hudson.security.AuthorizationMatrixProperty)1 Map (java.util.Map)1