use of jetbrains.buildServer.serverSide.STest in project teamcity-rest by JetBrains.
the class InvestigationFinder method getPrefilteredItems.
@NotNull
@Override
public ItemHolder<InvestigationWrapper> getPrefilteredItems(@NotNull final Locator locator) {
final String problemDimension = locator.getSingleDimensionValue(PROBLEM_DIMENSION);
if (problemDimension != null) {
final ProblemWrapper problem = myProblemFinder.getItem(problemDimension);
return getItemHolder(problem.getInvestigations());
}
final String testDimension = locator.getSingleDimensionValue(TEST_DIMENSION);
if (testDimension != null) {
final STest test = myTestFinder.getItem(testDimension);
return getItemHolder(getInvestigationWrappers(test));
}
final String buildTypeDimension = locator.getSingleDimensionValue(BUILD_TYPE);
if (buildTypeDimension != null) {
final SBuildType buildType = myBuildTypeFinder.getBuildType(null, buildTypeDimension, false);
return getItemHolder(getInvestigationWrappersForBuildType(buildType));
}
@Nullable User user = null;
final String investigatorDimension = locator.getSingleDimensionValue(ASSIGNEE);
if (investigatorDimension != null) {
user = myUserFinder.getItem(investigatorDimension);
}
final String assignmentProjectDimension = locator.getSingleDimensionValue(ASSIGNMENT_PROJECT);
if (assignmentProjectDimension != null) {
@NotNull final SProject project = myProjectFinder.getItem(assignmentProjectDimension);
return getItemHolder(getInvestigationWrappersForProject(project, user));
}
final String affectedProjectDimension = locator.getSingleDimensionValue(AFFECTED_PROJECT);
if (affectedProjectDimension != null) {
@NotNull final SProject project = myProjectFinder.getItem(affectedProjectDimension);
return getItemHolder(getInvestigationWrappersForProjectWithSubprojects(project, user));
}
if (user != null) {
return getItemHolder(getInvestigationWrappersForProjectWithSubprojects(myProjectFinder.getRootProject(), user));
}
locator.markUnused(ASSIGNEE);
return getItemHolder(getInvestigationWrappersForProjectWithSubprojects(myProjectFinder.getRootProject(), null));
}
use of jetbrains.buildServer.serverSide.STest 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());
}
}
use of jetbrains.buildServer.serverSide.STest 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());
}
}
use of jetbrains.buildServer.serverSide.STest in project teamcity-rest by JetBrains.
the class Investigation method getFromPostedAndApply.
@NotNull
public List<InvestigationWrapper> getFromPostedAndApply(@NotNull final ServiceLocator serviceLocator, final boolean allowMultipleResult) {
checkIsValid();
if (target == null) {
throw new BadRequestException("Invalid 'investigation' entity: 'target' should be specified");
}
ProblemTarget.ProblemTargetData targetData;
try {
targetData = target.getFromPosted(serviceLocator);
} catch (BadRequestException e) {
throw new BadRequestException("Invalid 'investigation' entity: " + e.getMessage());
}
ResponsibilityEntry entry = new ResponsibilityEntryEx(TypedFinderBuilder.getEnumValue(state, ResponsibilityEntry.State.class), assignee.getFromPosted(serviceLocator.getSingletonService(UserFinder.class)), serviceLocator.getSingletonService(UserFinder.class).getCurrentUser(), new Date(), assignment == null || assignment.getTextFromPosted() == null ? "" : assignment.getTextFromPosted(), resolution.getFromPostedForInvestigation(serviceLocator));
ResponsibilityFacadeEx responsibilityFacade = serviceLocator.getSingletonService(ResponsibilityFacadeEx.class);
InvestigationFinder investigationFinder = serviceLocator.findSingletonService(InvestigationFinder.class);
assert investigationFinder != null;
List<InvestigationWrapper> resultEntries = new ArrayList<>(1);
if (targetData.isAnyProblem()) {
List<BuildType> buildTypesFromPosted = scope.getBuildTypesFromPosted(serviceLocator);
if (!allowMultipleResult && buildTypesFromPosted.size() > 1) {
throw new OnlySingleEntitySupportedException("Invalid 'scope' entity: for this request only single buildType is supported within 'buildTypes' entity");
}
for (BuildType buildType : buildTypesFromPosted) {
responsibilityFacade.setBuildTypeResponsibility(buildType, entry);
resultEntries.add(investigationFinder.getItem(InvestigationFinder.getLocator((SBuildType) buildType)));
}
} else {
if (scope.buildTypes != null) {
throw new BadRequestException("Invalid 'investigation' entity: Invalid 'scope' entity: 'buildTypes' should not be specified for not buildType-level investigation");
}
SProject project = scope.getProjectFromPosted(serviceLocator);
List<STest> tests = targetData.getTests();
if (!tests.isEmpty()) {
if (!allowMultipleResult && tests.size() > 1) {
throw new OnlySingleEntitySupportedException("Invalid 'target' entity: for this request only single test is supported within 'tests' entity");
}
responsibilityFacade.setTestNameResponsibility(tests.stream().map(sTest -> sTest.getName()).distinct().collect(Collectors.toList()), project.getProjectId(), entry);
tests.stream().map(test -> // only one item should be found in the project
investigationFinder.getItem(InvestigationFinder.getLocatorForTest(test.getTestNameId(), project))).distinct().forEachOrdered(resultEntries::add);
}
List<Long> problems = targetData.getProblemIds();
if (!problems.isEmpty()) {
if (!allowMultipleResult && problems.size() > 1) {
throw new OnlySingleEntitySupportedException("Invalid 'target' entity: for this request only single problem is supported within 'problems' entity");
}
responsibilityFacade.setBuildProblemResponsibility(// seems like only id is used inside
problems.stream().distinct().map(problemId -> ProblemWrapper.getBuildProblemInfo(problemId.intValue(), project.getProjectId())).collect(Collectors.toList()), project.getProjectId(), entry);
problems.stream().distinct().map(problemId -> // only one item should be found in the project
investigationFinder.getItem(InvestigationFinder.getLocatorForProblem(problemId.intValue(), project))).forEachOrdered(resultEntries::add);
}
}
if (!allowMultipleResult && resultEntries.size() != 1) {
throw new BadRequestException("Invalid 'investigation' entity: Invalid 'target' entity: found " + resultEntries.size() + " result entities, while exactly one is required");
}
return resultEntries;
}
use of jetbrains.buildServer.serverSide.STest 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());
}
}
Aggregations