Search in sources :

Example 41 with BuildTypeImpl

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

the class BuildTypeRequestTest method testUpdatingParameters.

@Test
public void testUpdatingParameters() {
    BuildTypeImpl buildType1 = registerBuildType("buildType1", "projectName");
    buildType1.addParameter(new SimpleParameter("a1", "b"));
    buildType1.addParameter(new SimpleParameter("a2", "b"));
    buildType1.addParameter(new SimpleParameter("a3", "b"));
    final String btLocator = "id:" + buildType1.getExternalId();
    assertEquals(3, myBuildTypeRequest.getParametersSubResource(btLocator).getParameters(null, "$long,property($long)").properties.size());
    myBuildTypeRequest.getParametersSubResource(btLocator).setParameter(new Property(new SimpleParameter("a4", "b"), false, Fields.LONG, myFixture), "$long");
    assertEquals(4, myBuildTypeRequest.getParametersSubResource(btLocator).getParameters(null, "$long,property($long)").properties.size());
    myBuildTypeRequest.getParametersSubResource(btLocator).deleteParameter("a3");
    assertEquals(3, myBuildTypeRequest.getParametersSubResource(btLocator).getParameters(null, "$long,property($long)").properties.size());
    {
        Properties submitted = new Properties();
        Property p10 = new Property();
        p10.name = "n1";
        p10.value = null;
        submitted.properties = Arrays.asList(p10);
        checkException(BadRequestException.class, new Runnable() {

            public void run() {
                myBuildTypeRequest.getParametersSubResource(btLocator).setParameters(submitted, "$long");
            }
        }, null);
        assertEquals(3, myBuildTypeRequest.getParametersSubResource(btLocator).getParameters(null, "$long,property($long)").properties.size());
        assertEquals(3, buildType1.getParameters().size());
    }
    buildType1.getSettings().addListener(new BuildTypeSettingsAdapter() {

        private int myTriggerOnCall = 1;

        @Override
        public void textValueChanged() {
            if (--myTriggerOnCall == 0) {
                throw new RuntimeException("I need error here ");
            }
        }
    });
    {
        Properties submitted = new Properties();
        submitted.properties = Arrays.asList(new Property(new SimpleParameter("n1", "v1"), false, Fields.LONG, myFixture));
        checkException(BadRequestException.class, new Runnable() {

            public void run() {
                myBuildTypeRequest.getParametersSubResource(btLocator).setParameters(submitted, "$long");
            }
        }, null);
        assertEquals(3, myBuildTypeRequest.getParametersSubResource(btLocator).getParameters(null, "$long,property($long)").properties.size());
        assertEquals(3, buildType1.getParameters().size());
    }
    buildType1.getSettings().addListener(new BuildTypeSettingsAdapter() {

        private int myTriggerOnCall = 1;

        @Override
        public void textValueChanged() {
            if (--myTriggerOnCall == 0) {
                throw new RuntimeException("I need error here ");
            }
        }
    });
    checkException(RuntimeException.class, new Runnable() {

        public void run() {
            myBuildTypeRequest.getParametersSubResource(btLocator).setParameter(new Property(new SimpleParameter("n1", "v1"), false, Fields.LONG, myFixture), "$long");
        }
    }, null);
    assertEquals(3, myBuildTypeRequest.getParametersSubResource(btLocator).getParameters(null, "$long,property($long)").properties.size());
    assertEquals(3, buildType1.getParameters().size());
    myBuildTypeRequest.getParametersSubResource(btLocator).setParameters(new Properties(), "$long");
    assertEquals(0, buildType1.getParameters().size());
}
Also used : BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 42 with BuildTypeImpl

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

the class BuildTypeRequestTest method testUpdatingTriggers.

@Test
public void testUpdatingTriggers() {
    BuildTypeImpl buildType1 = registerBuildType("buildType1", "projectName");
    buildType1.addBuildTrigger("trigger1", createMap("a", "b"));
    String disabledTriggerId = buildType1.addBuildTrigger("trigger2", createMap("a", "b")).getId();
    buildType1.setEnabled(disabledTriggerId, false);
    buildType1.addBuildTrigger("trigger3", createMap("a", "b"));
    final String btLocator = "id:" + buildType1.getExternalId();
    assertEquals(3, myBuildTypeRequest.getTriggers(btLocator, "$long,trigger($long)").propEntities.size());
    {
        PropEntityTrigger submitted = new PropEntityTrigger();
        submitted.type = "triggerType1";
        String newId = myBuildTypeRequest.addTrigger(btLocator, "$long", submitted).id;
        assertEquals(4, myBuildTypeRequest.getTriggers(btLocator, "$long,trigger($long)").propEntities.size());
        myBuildTypeRequest.deleteTrigger(btLocator, newId);
        assertEquals(3, myBuildTypeRequest.getTriggers(btLocator, "$long,trigger($long)").propEntities.size());
    }
    buildType1.getSettings().addListener(new BuildTypeSettingsAdapter() {

        private boolean myAlreadyThrown = false;

        @Override
        public void afterAddBuildTrigger(@NotNull final BuildTriggerDescriptor btd) {
            if (!myAlreadyThrown) {
                myAlreadyThrown = true;
                throw new RuntimeException("I need error here ");
            }
        }
    });
    {
        PropEntitiesTrigger submitted = new PropEntitiesTrigger();
        PropEntityTrigger submitted1 = new PropEntityTrigger();
        submitted1.type = "triggerType1";
        PropEntityTrigger submitted2 = new PropEntityTrigger();
        submitted2.type = "triggerType1";
        submitted.propEntities = Arrays.asList(submitted1, submitted2);
        checkException(BadRequestException.class, new Runnable() {

            public void run() {
                myBuildTypeRequest.replaceTriggers(btLocator, "$long", submitted);
            }
        }, null);
        assertEquals(3, myBuildTypeRequest.getTriggers(btLocator, "$long,trigger($long)").propEntities.size());
        assertEquals(3, buildType1.getBuildTriggersCollection().size());
        assertFalse(buildType1.isEnabled(disabledTriggerId));
    }
    buildType1.getSettings().addListener(new BuildTypeSettingsAdapter() {

        private boolean myAlreadyThrown = false;

        @Override
        public void afterAddBuildTrigger(@NotNull final BuildTriggerDescriptor btd) {
            if (!myAlreadyThrown) {
                myAlreadyThrown = true;
                throw new RuntimeException("I need error here ");
            }
        }
    });
    {
        PropEntityTrigger submitted = new PropEntityTrigger();
        submitted.type = "triggerType1";
        checkException(RuntimeException.class, new Runnable() {

            public void run() {
                myBuildTypeRequest.addTrigger(btLocator, "$long", submitted);
            }
        }, null);
        assertEquals(3, myBuildTypeRequest.getTriggers(btLocator, "$long,trigger($long)").propEntities.size());
        assertEquals(3, buildType1.getBuildTriggersCollection().size());
        assertFalse(buildType1.isEnabled(disabledTriggerId));
    }
    myBuildTypeRequest.replaceTriggers(btLocator, "$long", new PropEntitiesTrigger());
    assertEquals(0, buildType1.getBuildTriggersCollection().size());
}
Also used : BuildTriggerDescriptor(jetbrains.buildServer.buildTriggers.BuildTriggerDescriptor) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 43 with BuildTypeImpl

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

the class BuildType method getTemplates.

@Nullable
public static BuildTypes getTemplates(@NotNull final SBuildType buildType, @NotNull final Fields fields, final BeanContext beanContext) {
    try {
        PermissionChecker permissionChecker = beanContext.getSingletonService(PermissionChecker.class);
        List<? extends BuildTypeTemplate> templates = buildType.getTemplates();
        Set<String> ownTemplatesIds = buildType.getOwnTemplates().stream().map(t -> t.getInternalId()).collect(Collectors.toSet());
        return new BuildTypes(templates.stream().map(t -> shouldRestrictSettingsViewing(t, permissionChecker) ? new BuildTypeOrTemplate.IdsOnly(t.getExternalId(), t.getInternalId()) : new BuildTypeOrTemplate(t)).map(t -> t.markInherited(!ownTemplatesIds.contains(t.getInternalId()))).collect(Collectors.toList()), null, fields, beanContext);
    } catch (RuntimeException e) {
        LOG.debug("Error retrieving templates for build configuration " + LogUtil.describe(buildType) + ": " + e.toString(), e);
        List<String> templateIds = ((BuildTypeImpl) buildType).getOwnTemplateIds();
        if (templateIds.isEmpty())
            return null;
        List<BuildTypeOrTemplate> result = getBuildTypeOrTemplates(templateIds, fields.getNestedField("template"), beanContext);
        return result.isEmpty() ? null : new BuildTypes(result, null, fields, beanContext);
    }
}
Also used : AuthorityHolder(jetbrains.buildServer.serverSide.auth.AuthorityHolder) BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) jetbrains.buildServer.server.rest.data(jetbrains.buildServer.server.rest.data) InvestigationFinder(jetbrains.buildServer.server.rest.data.investigations.InvestigationFinder) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) jetbrains.buildServer.server.rest.model(jetbrains.buildServer.server.rest.model) Agents(jetbrains.buildServer.server.rest.model.agent.Agents) XmlType(javax.xml.bind.annotation.XmlType) BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) BuildTypeIdentifiersManager(jetbrains.buildServer.serverSide.identifiers.BuildTypeIdentifiersManager) ParametersPersistableEntity(jetbrains.buildServer.server.rest.data.parameters.ParametersPersistableEntity) InvestigationWrapper(jetbrains.buildServer.server.rest.data.investigations.InvestigationWrapper) StringUtil(jetbrains.buildServer.util.StringUtil) SecurityContext(jetbrains.buildServer.serverSide.auth.SecurityContext) LogUtil(jetbrains.buildServer.serverSide.impl.LogUtil) Logger(com.intellij.openapi.diagnostic.Logger) BuildTypeRequest(jetbrains.buildServer.server.rest.request.BuildTypeRequest) ModelDescription(jetbrains.buildServer.server.rest.swagger.annotations.ModelDescription) XmlAttribute(javax.xml.bind.annotation.XmlAttribute) Lazy(jetbrains.buildServer.util.impl.Lazy) ServiceLocator(jetbrains.buildServer.ServiceLocator) Branches(jetbrains.buildServer.server.rest.model.build.Branches) jetbrains.buildServer.serverSide(jetbrains.buildServer.serverSide) Builds(jetbrains.buildServer.server.rest.model.build.Builds) Set(java.util.Set) CachingValue(jetbrains.buildServer.server.rest.util.CachingValue) EntityWithParameters(jetbrains.buildServer.server.rest.data.parameters.EntityWithParameters) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) ValueWithDefault(jetbrains.buildServer.server.rest.util.ValueWithDefault) Collectors(java.util.stream.Collectors) APIController(jetbrains.buildServer.server.rest.APIController) Objects(java.util.Objects) Project(jetbrains.buildServer.server.rest.model.project.Project) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Permission(jetbrains.buildServer.serverSide.auth.Permission) AgentRequest(jetbrains.buildServer.server.rest.request.AgentRequest) AuthUtil(jetbrains.buildServer.serverSide.auth.AuthUtil) InheritableUserParametersHolderEntityWithParameters(jetbrains.buildServer.server.rest.data.parameters.InheritableUserParametersHolderEntityWithParameters) BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) ApiModelProperty(io.swagger.annotations.ApiModelProperty) InvestigationRequest(jetbrains.buildServer.server.rest.request.InvestigationRequest) SUser(jetbrains.buildServer.users.SUser) XmlElement(javax.xml.bind.annotation.XmlElement) BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) List(java.util.List) Nullable(org.jetbrains.annotations.Nullable)

Example 44 with BuildTypeImpl

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

the class ChangeFinderTest method testChangesByBuildTypeFromDependenciesHaveDescriptor.

@Test
@TestFor(issues = "TW-72448")
public void testChangesByBuildTypeFromDependenciesHaveDescriptor() {
    final BuildTypeImpl buildConf1 = registerBuildType("buildConf1", "project");
    final BuildTypeImpl buildConf2 = registerBuildType("buildConf2", "project");
    createDependencyChain(buildConf2, buildConf1);
    MockVcsSupport vcs = new MockVcsSupport("vcs");
    vcs.setDAGBased(true);
    myFixture.getVcsManager().registerVcsSupport(vcs);
    SVcsRootEx parentRoot1 = myFixture.addVcsRoot(vcs.getName(), "", buildConf1);
    SVcsRootEx parentRoot2 = myFixture.addVcsRoot(vcs.getName(), "", buildConf2);
    VcsRootInstance root1 = buildConf1.getVcsRootInstanceForParent(parentRoot1);
    VcsRootInstance root2 = buildConf2.getVcsRootInstanceForParent(parentRoot2);
    assert root1 != null;
    assert root2 != null;
    setBranchSpec(root1, "+:*");
    setBranchSpec(root2, "+:*");
    final BuildFinderTestBase.MockCollectRepositoryChangesPolicy changesPolicy = new BuildFinderTestBase.MockCollectRepositoryChangesPolicy();
    vcs.setCollectChangesPolicy(changesPolicy);
    myFixture.addModification(modification().in(root1).version("1").parentVersions("0"));
    myFixture.addModification(modification().in(root2).version("2").parentVersions("0"));
    List<SVcsModificationOrChangeDescriptor> items = getFinder().getItems("buildType:buildConf2,changesFromDependencies:true,vcsRoot:(id:" + root1.getExternalId() + ")").myEntries;
    assertEquals("There is exactly one pending change coming from dependency.", 1, items.size());
    ChangeDescriptor descriptor = items.get(0).getChangeDescriptor();
    assertNotNull("Depency change descriptor must be present when looking for changes using build type.", descriptor);
    assertEquals(ChangeDescriptorConstants.SNAPSHOT_DEPENDENCY_VCS_CHANGE, descriptor.getType());
    SVcsModification modification = items.get(0).getSVcsModification();
    assertEquals("1", modification.getDisplayVersion());
}
Also used : MockVcsSupport(jetbrains.buildServer.serverSide.impl.MockVcsSupport) SVcsModificationOrChangeDescriptor(jetbrains.buildServer.server.rest.data.change.SVcsModificationOrChangeDescriptor) BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) SVcsModificationOrChangeDescriptor(jetbrains.buildServer.server.rest.data.change.SVcsModificationOrChangeDescriptor) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Example 45 with BuildTypeImpl

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

the class ChangeFinderTest method testChangesFromDependenciesNoDAG.

@Test
public void testChangesFromDependenciesNoDAG() {
    final BuildTypeImpl buildConf1 = registerBuildType("buildConf1", "project");
    final BuildTypeImpl buildConf2 = registerBuildType("buildConf2", "project");
    createDependencyChain(buildConf2, buildConf1);
    SVcsRoot vcsRoot1 = myFixture.addVcsRoot("svn", "", buildConf1);
    SVcsModification m10 = myFixture.addModification(ModificationDataForTest.forTests("descr1", "user1", vcsRoot1, "ver1"));
    SVcsRoot vcsRoot2 = myFixture.addVcsRoot("svn", "", buildConf2);
    SVcsModification m20 = myFixture.addModification(ModificationDataForTest.forTests("descr2", "user2", vcsRoot2, "ver2"));
    check(null, m20, m10);
    String btLocator1 = "buildType:(id:" + buildConf1.getExternalId() + ")";
    String btLocator2 = "buildType:(id:" + buildConf2.getExternalId() + ")";
    check(btLocator1, m10);
    check(btLocator1 + ",pending:true", m10);
    check(btLocator2, m20);
    check(btLocator2 + ",pending:true", m20);
    buildConf2.setOption(BuildTypeOptions.BT_SHOW_DEPS_CHANGES, true);
    check(btLocator2, m20, m10);
    check(btLocator2 + ",pending:true", m20, m10);
}
Also used : BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) Test(org.testng.annotations.Test)

Aggregations

BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)80 Test (org.testng.annotations.Test)68 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)19 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)12 ChangeStatus (jetbrains.buildServer.server.rest.model.change.ChangeStatus)12 SVcsModification (jetbrains.buildServer.vcs.SVcsModification)12 VcsRootInstance (jetbrains.buildServer.vcs.VcsRootInstance)12 SUser (jetbrains.buildServer.users.SUser)11 MockVcsSupport (jetbrains.buildServer.serverSide.impl.MockVcsSupport)10 SFinishedBuild (jetbrains.buildServer.serverSide.SFinishedBuild)9 TestOccurrence (jetbrains.buildServer.server.rest.model.problem.TestOccurrence)7 ProjectEx (jetbrains.buildServer.serverSide.impl.ProjectEx)7 TestFor (jetbrains.buildServer.util.TestFor)7 BuildPromotionEx (jetbrains.buildServer.serverSide.BuildPromotionEx)6 TestOccurrences (jetbrains.buildServer.server.rest.model.problem.TestOccurrences)5 RunningBuildEx (jetbrains.buildServer.serverSide.RunningBuildEx)5 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 FakeHttpServletRequest (jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest)4 TestScope (jetbrains.buildServer.server.rest.data.problem.scope.TestScope)4