Search in sources :

Example 1 with TestName

use of jetbrains.buildServer.tests.TestName in project teamcity-rest by JetBrains.

the class MuteRequestTest method test_severalMutes.

@Test
public void test_severalMutes() {
    final ProjectEx project = createProject("Project", "Project");
    final BuildTypeEx bt1 = project.createBuildType("bt1");
    final BuildTypeEx bt2 = project.createBuildType("bt2");
    final ProjectEx project2 = createProject("Project2", "Project2");
    final BuildTypeEx bt22 = project.createBuildType("bt3");
    createBuild(bt1, new String[0], new String[] { "test1", "test2", "test3" });
    createBuild(bt22, 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");
    myMutingService.muteTestsInBuildTypes(user, null, false, null, Arrays.asList(bt1, bt2), Arrays.asList(test1, test2), false);
    myMutingService.muteTestsInProject(user, null, false, null, project2, Arrays.asList(test1));
    int mute1Id, mute2Id;
    {
        Mutes mutes = myRequest.getMutes(null, null, null, null);
        assertEquals(Integer.valueOf(2), mutes.count);
        assertEquals(2, mutes.items.size());
        mute1Id = mutes.items.get(0).id;
        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)));
        mute2Id = mutes.items.get(1).id;
        assertNull(mutes.items.get(1).scope.buildTypes);
        assertNotNull(mutes.items.get(1).scope.project);
        assertEquals(project2.getExternalId(), mutes.items.get(1).scope.project.id);
        assertNull(mutes.items.get(1).target.problems);
        assertEquals(1, mutes.items.get(1).target.tests.items.size());
        assertTrue(mutes.items.get(1).target.tests.items.stream().anyMatch(test -> String.valueOf(test1.getTestNameId()).equals(test.id)));
    }
    {
        setInternalProperty(Mutes.REST_MUTES_ACTUAL_STATE, "true");
        Mutes mutes = myRequest.getMutes("id:" + mute2Id, "$long,mute(target(tests(test(mutes(mute(target(tests(test($long))),scope(buildTypes(buildType($long)))))))))", null, null);
        assertEquals(2, mutes.items.get(0).target.tests.items.get(0).mutes.items.size());
        assertEquals(2, mutes.items.get(0).target.tests.items.get(0).mutes.items.get(0).target.tests.items.size());
        assertEquals(2, 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 2 with TestName

use of jetbrains.buildServer.tests.TestName in project teamcity-rest by JetBrains.

the class MuteRequestTest method test_unmuteTest.

@Test
public void test_unmuteTest() {
    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));
    {
        // this is the current behavior, but actually something should change, see TW-53393
        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, bt2, Arrays.asList(test1));
    {
        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(1, mutes.items.get(0).target.tests.items.size());
        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(target(tests($long))))))))", null, null);
        assertEquals(1, mutes.items.get(0).target.tests.items.get(0).mutes.items.get(0).target.tests.items.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 3 with TestName

use of jetbrains.buildServer.tests.TestName in project teamcity-rest by JetBrains.

the class TestFinder method findSingleItem.

@Override
@Nullable
public STest findSingleItem(@NotNull final Locator locator) {
    if (locator.isSingleValue()) {
        // no dimensions found, assume it's id
        final Long parsedId = locator.getSingleValueAsLong();
        if (parsedId == null) {
            throw new BadRequestException("Expecting id, found empty value.");
        }
        STest item = findTest(parsedId);
        if (item == null) {
            throw new NotFoundException("No test can be found by id '" + parsedId + "' on the entire server.");
        }
        return item;
    }
    // dimension-specific item search
    Long id = locator.getSingleDimensionValueAsLong(DIMENSION_ID);
    if (id != null) {
        STest item = findTest(id);
        if (item == null) {
            throw new NotFoundException("No test" + " can be found by " + DIMENSION_ID + " '" + id + "' on the entire server.");
        }
        return item;
    }
    String nameDimension = locator.getSingleDimensionValue(NAME);
    if (nameDimension != null) {
        ValueCondition nameCondition = ParameterCondition.createValueConditionFromPlainValueOrCondition(nameDimension);
        String constantName = nameCondition.getConstantValueIfSimpleEqualsCondition();
        if (constantName == null) {
            return null;
        }
        final Long testNameId = myTestName2Index.findTestNameId(new TestName(constantName));
        if (testNameId == null) {
            throw new NotFoundException("No test can be found by " + NAME + " '" + constantName + "' on the entire server.");
        }
        STest test = findTest(testNameId);
        if (test == null) {
            throw new NotFoundException("No test can be found by id corresponding to " + NAME + " '" + constantName + "' on the entire server.");
        }
        return test;
    }
    return null;
}
Also used : TestName(jetbrains.buildServer.tests.TestName) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with TestName

use of jetbrains.buildServer.tests.TestName in project teamcity-rest by JetBrains.

the class InvestigationFinderTest method testTestInvestigationModel.

@Test
public void testTestInvestigationModel() throws Exception {
    createFailingBuild();
    final TestName testName = new TestName(FAIL_TEST2_NAME);
    myFixture.getResponsibilityFacadeEx().setTestNameResponsibility(testName, myProject.getProjectId(), createRespEntry(ResponsibilityEntry.State.TAKEN, myUser));
    final PagedSearchResult<InvestigationWrapper> ivestigationWrappers = myInvestigationFinder.getItems((String) null);
    final Investigations investigations = new Investigations(ivestigationWrappers.myEntries, null, Fields.LONG, getBeanContext(myServer));
    assertEquals(1, investigations.count.longValue());
    final Investigation investigation = investigations.items.get(0);
    final TestName2Index testName2Index = myFixture.getSingletonService(TestName2Index.class);
    assertEquals("assignmentProject:(id:" + myProject.getExternalId() + "),test:(id:" + testName2Index.findTestNameId(testName) + ")", investigation.id);
    assertEquals("TAKEN", investigation.state);
    assertEquals((Long) myUser.getId(), investigation.assignee.getId());
    assertEquals("The comment", investigation.assignment.text);
    assertEquals(null, investigation.target.anyProblem);
    assertEquals(null, investigation.target.problems);
    assertEquals(FAIL_TEST2_NAME, investigation.target.tests.items.get(0).name);
    assertEquals(null, investigation.scope.buildTypes);
    assertEquals(myProject.getExternalId(), investigation.scope.project.id);
}
Also used : TestName(jetbrains.buildServer.tests.TestName) InvestigationWrapper(jetbrains.buildServer.server.rest.data.investigations.InvestigationWrapper) Investigation(jetbrains.buildServer.server.rest.model.buildType.Investigation) TestName2Index(jetbrains.buildServer.serverSide.TestName2Index) Investigations(jetbrains.buildServer.server.rest.model.buildType.Investigations) Test(org.testng.annotations.Test)

Example 5 with TestName

use of jetbrains.buildServer.tests.TestName in project teamcity-rest by JetBrains.

the class TestOccurrenceFinderTest method testInvestigationState.

@Test
public void testInvestigationState() throws Exception {
    final BuildTypeImpl buildType = registerBuildType("buildConf1", "project1");
    final SFinishedBuild build = build().in(buildType).withTest("aaa_active", false).withTest("bbb_fixed", false).withTest("ccc_given_up", false).withTest("ddd_none", false).finish();
    long activeNameId = myFixture.getSingletonService(TestName2Index.class).getOrSaveTestNameId("aaa_active");
    long fixedNameId = myFixture.getSingletonService(TestName2Index.class).getOrSaveTestNameId("bbb_fixed");
    long givenUpNameId = myFixture.getSingletonService(TestName2Index.class).getOrSaveTestNameId("ccc_given_up");
    SUser user = createUser("user");
    ProjectEx project = myServer.getProjectManager().getRootProject().findProjectByName("project1");
    TestNameResponsibilityEntryImpl activeEntry = new TestNameResponsibilityEntryImpl(new TestName("aaa_active"), activeNameId, ResponsibilityEntry.State.TAKEN, user, user, new Date(), "Please, fix", project, ResponsibilityEntry.RemoveMethod.MANUALLY);
    TestNameResponsibilityEntryImpl fixedEntry = new TestNameResponsibilityEntryImpl(new TestName("bbb_fixed"), fixedNameId, ResponsibilityEntry.State.FIXED, user, user, new Date(), "Please, fix", project, ResponsibilityEntry.RemoveMethod.MANUALLY);
    TestNameResponsibilityEntryImpl givenUpEntry = new TestNameResponsibilityEntryImpl(new TestName("ccc_given_up"), givenUpNameId, ResponsibilityEntry.State.GIVEN_UP, user, user, new Date(), "Please, fix", project, ResponsibilityEntry.RemoveMethod.MANUALLY);
    TestNameResponsibilityFacade testNameResponsibilityFacade = myFixture.getSingletonService(TestNameResponsibilityFacade.class);
    testNameResponsibilityFacade.setTestNameResponsibility(new TestName("aaa_active"), project.getProjectId(), activeEntry);
    testNameResponsibilityFacade.setTestNameResponsibility(new TestName("bbb_fixed"), project.getProjectId(), fixedEntry);
    testNameResponsibilityFacade.setTestNameResponsibility(new TestName("ccc_given_up"), project.getProjectId(), givenUpEntry);
    TestRunData activeRunData = t("aaa_active", Status.FAILURE, 1);
    TestRunData fixedRunData = t("bbb_fixed", Status.FAILURE, 2);
    TestRunData givenUpRunData = t("ccc_given_up", Status.FAILURE, 3);
    TestRunData noneRunData = t("ddd_none", Status.FAILURE, 4);
    check("currentlyFailing:true,currentlyInvestigated:true", TEST_MATCHER, activeRunData);
    check("currentlyFailing:true,currentlyInvestigated:false", TEST_MATCHER, fixedRunData, givenUpRunData, noneRunData);
    check("currentlyFailing:true,investigationState:active", TEST_MATCHER, activeRunData);
    check("currentlyFailing:true,investigationState:fixed", TEST_MATCHER, fixedRunData);
    check("currentlyFailing:true,investigationState:givenUp", TEST_MATCHER, givenUpRunData);
    check("currentlyFailing:true,investigationState:none", TEST_MATCHER, noneRunData);
    check("currentlyFailing:true", TEST_MATCHER, activeRunData, fixedRunData, givenUpRunData, noneRunData);
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) TestName(jetbrains.buildServer.tests.TestName) TestNameResponsibilityFacade(jetbrains.buildServer.responsibility.TestNameResponsibilityFacade) SUser(jetbrains.buildServer.users.SUser) TestNameResponsibilityEntryImpl(jetbrains.buildServer.responsibility.impl.TestNameResponsibilityEntryImpl) BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) Date(java.util.Date) Test(org.testng.annotations.Test)

Aggregations

TestName (jetbrains.buildServer.tests.TestName)7 Test (org.testng.annotations.Test)6 ProjectEx (jetbrains.buildServer.serverSide.impl.ProjectEx)5 SUser (jetbrains.buildServer.users.SUser)5 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)3 Mutes (jetbrains.buildServer.server.rest.model.problem.Mutes)3 BuildTypeEx (jetbrains.buildServer.serverSide.BuildTypeEx)3 STest (jetbrains.buildServer.serverSide.STest)3 Date (java.util.Date)2 TestNameResponsibilityFacade (jetbrains.buildServer.responsibility.TestNameResponsibilityFacade)2 TestNameResponsibilityEntryImpl (jetbrains.buildServer.responsibility.impl.TestNameResponsibilityEntryImpl)2 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)2 InvestigationWrapper (jetbrains.buildServer.server.rest.data.investigations.InvestigationWrapper)1 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)1 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)1 Investigation (jetbrains.buildServer.server.rest.model.buildType.Investigation)1 Investigations (jetbrains.buildServer.server.rest.model.buildType.Investigations)1 TestName2Index (jetbrains.buildServer.serverSide.TestName2Index)1 Nullable (org.jetbrains.annotations.Nullable)1