Search in sources :

Example 41 with ProjectEx

use of jetbrains.buildServer.serverSide.impl.ProjectEx in project teamcity-rest by JetBrains.

the class MuteRequestTest method test_unmuteBuildType.

@Test
public void test_unmuteBuildType() {
    final ProjectEx project = createProject("Project", "Project");
    final BuildTypeEx bt1 = project.createBuildType("bt1");
    final BuildTypeEx bt2 = project.createBuildType("bt2");
    // just a child project
    final ProjectEx projectChild = project.createProject("Project2", "Project2");
    final BuildTypeEx bt21 = projectChild.createBuildType("bt21");
    createBuild(bt1, new String[0], new String[] { "test1", "test2", "test3" });
    createBuild(bt2, new String[0], new String[] { "test1", "test2", "test3", "test4" });
    createBuild(bt21, new String[0], new String[] { "test1", "test2", "test3", "test4" });
    final STest test1 = myFixture.getTestManager().createTest(new TestName("test1"), project.getProjectId());
    final STest test2 = myFixture.getTestManager().createTest(new TestName("test2"), project.getProjectId());
    SUser user = createUser("user");
    {
        Mutes mutes = myRequest.getMutes(null, null, null, null);
        // assertEquals(Integer.valueOf(0), mutes.count); //todo: fix
        assertEmpty(mutes.items);
    }
    myMutingService.muteTestsInBuildTypes(user, null, false, null, Arrays.asList(bt1, bt2), Arrays.asList(test1, test2), false);
    {
        Mutes mutes = myRequest.getMutes(null, null, null, null);
        assertEquals(Integer.valueOf(1), mutes.count);
        assertEquals(1, mutes.items.size());
        assertNull(mutes.items.get(0).scope.project);
        assertNotNull(mutes.items.get(0).scope.buildTypes);
        assertEquals(2, mutes.items.get(0).scope.buildTypes.buildTypes.size());
        assertTrue(mutes.items.get(0).scope.buildTypes.buildTypes.stream().anyMatch(buildType -> bt1.getExternalId().equals(buildType.getId())));
        assertTrue(mutes.items.get(0).scope.buildTypes.buildTypes.stream().anyMatch(buildType -> bt2.getExternalId().equals(buildType.getId())));
        assertNull(mutes.items.get(0).target.problems);
        assertEquals(2, mutes.items.get(0).target.tests.items.size());
        assertTrue(mutes.items.get(0).target.tests.items.stream().anyMatch(test -> String.valueOf(test1.getTestNameId()).equals(test.id)));
        assertTrue(mutes.items.get(0).target.tests.items.stream().anyMatch(test -> String.valueOf(test2.getTestNameId()).equals(test.id)));
    }
    myMutingService.unmuteTests(user, null, bt1, Arrays.asList(test1, test2));
    {
        Mutes mutes = myRequest.getMutes(null, null, null, null);
        assertEquals(Integer.valueOf(1), mutes.count);
        assertEquals(1, mutes.items.size());
        assertNull(mutes.items.get(0).scope.project);
        assertNotNull(mutes.items.get(0).scope.buildTypes);
        assertEquals(1, mutes.items.get(0).scope.buildTypes.buildTypes.size());
        assertTrue(mutes.items.get(0).scope.buildTypes.buildTypes.stream().anyMatch(buildType -> bt2.getExternalId().equals(buildType.getId())));
        assertNull(mutes.items.get(0).target.problems);
        assertEquals(2, mutes.items.get(0).target.tests.items.size());
        assertTrue(mutes.items.get(0).target.tests.items.stream().anyMatch(test -> String.valueOf(test1.getTestNameId()).equals(test.id)));
        assertTrue(mutes.items.get(0).target.tests.items.stream().anyMatch(test -> String.valueOf(test2.getTestNameId()).equals(test.id)));
    }
    {
        setInternalProperty(Mutes.REST_MUTES_ACTUAL_STATE, "true");
        Mutes mutes = myRequest.getMutes(null, "$long,mute(target(tests(test(mutes(mute(scope(buildTypes($long))))))))", null, null);
        assertEquals(1, mutes.items.get(0).target.tests.items.get(0).mutes.items.get(0).scope.buildTypes.buildTypes.size());
    }
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) BuildTypeEx(jetbrains.buildServer.serverSide.BuildTypeEx) TestName(jetbrains.buildServer.tests.TestName) SUser(jetbrains.buildServer.users.SUser) STest(jetbrains.buildServer.serverSide.STest) Mutes(jetbrains.buildServer.server.rest.model.problem.Mutes) STest(jetbrains.buildServer.serverSide.STest) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest) Test(org.testng.annotations.Test)

Example 42 with ProjectEx

use of jetbrains.buildServer.serverSide.impl.ProjectEx in project teamcity-rest by JetBrains.

the class ProjectRequest method setBuildTypesOrder.

/**
 * Put empty collection to remove custom ordering
 */
@PUT
@Path("/{projectLocator}/order/buildTypes")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Update custom ordering of build configurations of the matching project.", nickname = "setBuildTypesOrder")
public BuildTypes setBuildTypesOrder(@ApiParam(format = LocatorName.PROJECT) @PathParam("projectLocator") String projectLocator, BuildTypes buildTypes, @QueryParam("field") String fields) {
    SProject project = myProjectFinder.getItem(projectLocator);
    LinkedHashSet<String> ids = new LinkedHashSet<>();
    if (buildTypes.buildTypes != null) {
        for (BuildType buildType : buildTypes.buildTypes) {
            String locatorFromPosted = buildType.getLocatorFromPosted();
            List<SBuildType> items = myBuildTypeFinder.getBuildTypes(project, locatorFromPosted);
            if (items.isEmpty()) {
                throw new BadRequestException("No build types in project found by locator '" + locatorFromPosted + "'");
            }
            for (SBuildType item : items) {
                ids.add(item.getInternalId());
            }
        }
    }
    ((ProjectEx) project).setOwnBuildTypesOrder(new ArrayList<>(ids));
    // see serveBuildTypesInProject()
    return new BuildTypes(BuildTypes.fromBuildTypes(((ProjectEx) project).getOwnBuildTypesOrder()), null, new Fields(fields), myBeanContext);
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) Fields(jetbrains.buildServer.server.rest.model.Fields) BuildTypes(jetbrains.buildServer.server.rest.model.buildType.BuildTypes) BuildType(jetbrains.buildServer.server.rest.model.buildType.BuildType) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) ApiOperation(io.swagger.annotations.ApiOperation)

Example 43 with ProjectEx

use of jetbrains.buildServer.serverSide.impl.ProjectEx in project teamcity-rest by JetBrains.

the class ProjectRequest method setDefaultTemplate.

@PUT
@Path("/{projectLocator}/defaultTemplate")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Update the default template of the matching project.", nickname = "setDefaultTemplate")
public BuildType setDefaultTemplate(@ApiParam(format = LocatorName.PROJECT) @PathParam("projectLocator") String projectLocator, BuildType defaultTemplate, @QueryParam("fields") String fields) {
    ProjectEx project = (ProjectEx) myProjectFinder.getItem(projectLocator, true);
    if (defaultTemplate == null)
        throw new BadRequestException("No payload found while template is expected");
    BuildTypeOrTemplate newDefaultTemplate = defaultTemplate.getBuildTypeFromPosted(myBuildTypeFinder);
    BuildTypeTemplate result = newDefaultTemplate.getTemplate();
    if (result == null) {
        throw new BadRequestException("Found build type when template is expected: " + LogUtil.describe(newDefaultTemplate.getBuildType()));
    }
    Boolean inherited = newDefaultTemplate.isInherited();
    BuildTypeTemplate currentDefaultTemplate = project.getDefaultTemplate();
    if (inherited == null || !inherited || (currentDefaultTemplate != null && !currentDefaultTemplate.getInternalId().equals(newDefaultTemplate.getInternalId()))) {
        try {
            project.setDefaultTemplate(result);
        } catch (CyclicDependencyFoundException e) {
            throw new BadRequestException(e.getMessage());
        }
        project.schedulePersisting("Default template changed");
    }
    BuildType template = Project.getDefaultTemplate(project, new Fields(fields), myBeanContext);
    if (template == null)
        throw new NotFoundException("No default template present");
    return template;
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) CyclicDependencyFoundException(jetbrains.buildServer.serverSide.dependency.CyclicDependencyFoundException) Fields(jetbrains.buildServer.server.rest.model.Fields) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) BuildType(jetbrains.buildServer.server.rest.model.buildType.BuildType) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) ApiOperation(io.swagger.annotations.ApiOperation)

Example 44 with ProjectEx

use of jetbrains.buildServer.serverSide.impl.ProjectEx in project teamcity-rest by JetBrains.

the class BaseTestScopesCollectorTest method buildTree.

protected void buildTree() {
    /* Builds a following tree:

                                 project
                               /        \
                       project1          project2
                      /        \                \
                buildconf1   subproject11    subproject21
                    |               \                    \
                  suite1          buildconf2            buildconf1
                 /      \             \             /        |    \
            packageA    packageB    suite2       suite1  suite2   suite0
             /     \        \          \           |         |         \
         class1   class2    class1   packageA   packageB   packageC    packageZ
         / | \       |         \        \          |         |            \
        b  a  c      a          b     class3    class1       class2      classZ
                                         \         |       / | | | | \      \
                                          c        a      h  g f e d  c      z
     */
    ProjectEx project = myFixture.createProject("project", "project");
    ProjectEx project1 = project.createProject("project1", "project1");
    ProjectEx project2 = project.createProject("project2", "project2");
    ProjectEx subproject11 = project1.createProject("subproject11", "subproject11");
    ProjectEx subproject21 = project2.createProject("subproject21", "subproject21");
    BuildTypeEx buildconf1 = project1.createBuildType("buildconf1");
    BuildTypeEx buildconf2 = subproject11.createBuildType("buildconf2");
    BuildTypeEx buildconf11 = subproject21.createBuildType("buildconf1");
    final SFinishedBuild build1 = build().in(buildconf1).startSuite("suite1").withTest("packageA.class1.b", false).withTest("packageA.class1.a", false).withTest("packageB.class1.b", false).withTest("packageA.class2.a", false).withTest("packageA.class1.c", false).endSuite().finish();
    final SFinishedBuild build2 = build().in(buildconf2).startSuite("suite2").withTest("packageA.class3.c", false).endSuite().finish();
    final SFinishedBuild build3 = build().in(buildconf11).startSuite("suite1").withTest("packageB.class1.a", false).endSuite().startSuite("suite2").withTest("packageC.class2.h", false).withTest("packageC.class2.g", false).withTest("packageC.class2.f", false).withTest("packageC.class2.e", false).withTest("packageC.class2.d", false).withTest("packageC.class2.c", false).endSuite().startSuite("suite0").withTest("packageZ.classZ.z", false).endSuite().finish();
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) BuildTypeEx(jetbrains.buildServer.serverSide.BuildTypeEx) SFinishedBuild(jetbrains.buildServer.serverSide.SFinishedBuild)

Example 45 with ProjectEx

use of jetbrains.buildServer.serverSide.impl.ProjectEx in project teamcity-rest by JetBrains.

the class AbstractAgentPoolResolverTest method basicProjectsConnection.

public void basicProjectsConnection() throws Throwable {
    jetbrains.buildServer.serverSide.agentPools.AgentPool realPool = myFixture.getAgentPoolManager().createNewAgentPool("testAgentPool");
    Set<String> allProjectIds = new HashSet<>();
    Set<String> visibleProjectNames = new HashSet<>();
    MockAuthorityHolder mockUser = new MockAuthorityHolder();
    Permissions viewProjectPermissions = new Permissions(Permission.VIEW_PROJECT);
    for (int i = 0; i < 5; i++) {
        ProjectEx project = createProject("visibleProject" + i);
        mockUser.projectPerms.put(project.getProjectId(), viewProjectPermissions);
        allProjectIds.add(project.getProjectId());
        visibleProjectNames.add(project.getName());
    }
    List<ProjectEx> invisibleProjects = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        ProjectEx project = createProject("invisibleProject" + i);
        allProjectIds.add(project.getProjectId());
        invisibleProjects.add(project);
    }
    myFixture.getAgentPoolManager().associateProjectsWithPool(realPool.getAgentPoolId(), allProjectIds);
    Mock fieldSelectionSetMock = mock(DataFetchingFieldSelectionSet.class);
    fieldSelectionSetMock.stubs().method("contains").with(eq("excludedCount")).will(returnValue(true));
    myDataFetchingEnvironment.setSelectionSet((DataFetchingFieldSelectionSet) fieldSelectionSetMock.proxy());
    AgentPoolProjectsConnection connection = myFixture.getSecurityContext().runAs(mockUser, () -> myResolver.projects(new AgentPool(realPool), new ProjectsFilter(), myDataFetchingEnvironment));
    connection.getEdges().getData().forEach(edge -> {
        String name = edge.getNode().getData().getName();
        assertTrue("Project '" + name + "' is visible, but shouldn't be.", visibleProjectNames.contains(name));
    });
    assertEquals(visibleProjectNames.size(), connection.getCount());
    assertEquals(new Integer(invisibleProjects.size()), connection.getExcludedCount());
}
Also used : ProjectsFilter(jetbrains.buildServer.server.graphql.model.filter.ProjectsFilter) AgentPoolProjectsConnection(jetbrains.buildServer.server.graphql.model.connections.agentPool.AgentPoolProjectsConnection) AgentPool(jetbrains.buildServer.server.graphql.model.agentPool.AgentPool) Mock(org.jmock.Mock) ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) Permissions(jetbrains.buildServer.serverSide.auth.Permissions) jetbrains.buildServer.serverSide.agentPools(jetbrains.buildServer.serverSide.agentPools) MockAuthorityHolder(jetbrains.buildServer.serverSide.impl.MockAuthorityHolder)

Aggregations

ProjectEx (jetbrains.buildServer.serverSide.impl.ProjectEx)52 Test (org.testng.annotations.Test)42 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)16 SUser (jetbrains.buildServer.users.SUser)10 BuildTypeOrTemplate (jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate)8 BuildTypeEx (jetbrains.buildServer.serverSide.BuildTypeEx)7 MockVcsSupport (jetbrains.buildServer.serverSide.impl.MockVcsSupport)7 BuildType (jetbrains.buildServer.server.rest.model.buildType.BuildType)6 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)6 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)5 Fields (jetbrains.buildServer.server.rest.model.Fields)5 TestName (jetbrains.buildServer.tests.TestName)5 ApiOperation (io.swagger.annotations.ApiOperation)4 SUserGroup (jetbrains.buildServer.groups.SUserGroup)4 ProjectRequestTest (jetbrains.buildServer.server.rest.request.ProjectRequestTest)4 Mutes (jetbrains.buildServer.server.rest.model.problem.Mutes)3 SFinishedBuild (jetbrains.buildServer.serverSide.SFinishedBuild)3 SProject (jetbrains.buildServer.serverSide.SProject)3 STest (jetbrains.buildServer.serverSide.STest)3 Permissions (jetbrains.buildServer.serverSide.auth.Permissions)3