Search in sources :

Example 76 with BuildTypeImpl

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

the class BuildTypeRequestTest method testCreatingWithTemplate.

@Test
public void testCreatingWithTemplate() {
    // see also alike setup in BuildTypeTest.testInheritance()
    ProjectEx project10 = createProject("project10", "project 10");
    MockVcsSupport vcs = vcsSupport().withName("vcs").dagBased(true).register();
    final SVcsRoot vcsRoot10 = project10.createVcsRoot("vcs", "extId10", "name10");
    final SVcsRoot vcsRoot20 = project10.createVcsRoot("vcs", "extId20", "name20");
    final SVcsRoot vcsRoot30 = project10.createVcsRoot("vcs", "extId30", "name30");
    project10.addParameter(new SimpleParameter("p", "v"));
    BuildTypeEx bt100 = project10.createBuildType("bt100", "bt 100");
    BuildTypeEx bt110 = project10.createBuildType("bt110", "bt 110");
    BuildTypeEx bt120 = project10.createBuildType("bt120", "bt 120");
    // TEMPLATE
    BuildTypeTemplate t10 = project10.createBuildTypeTemplate("t10", "bt 10");
    t10.setArtifactPaths("aaaaa");
    t10.setBuildNumberPattern("pattern");
    t10.setOption(BuildTypeOptions.BT_ALLOW_EXTERNAL_STATUS, true);
    t10.setOption(BuildTypeOptions.BT_FAIL_IF_TESTS_FAIL, true);
    t10.setOption(BuildTypeOptions.BT_CHECKOUT_DIR, "checkout_t");
    t10.setOption(BuildTypeOptions.BT_CHECKOUT_MODE, "ON_AGENT");
    t10.setOption(BuildTypeOptions.BT_FAIL_ON_ANY_ERROR_MESSAGE, true);
    t10.setOption(BuildTypeOptions.BT_EXECUTION_TIMEOUT, 11);
    t10.addVcsRoot(vcsRoot10);
    t10.addVcsRoot(vcsRoot20);
    t10.setCheckoutRules(vcsRoot20, new CheckoutRules("a=>b"));
    BuildRunnerDescriptorFactory runnerDescriptorFactory = myFixture.getSingletonService(BuildRunnerDescriptorFactory.class);
    t10.addBuildRunner(runnerDescriptorFactory.createBuildRunner(project10, "run10", "name10", "Ant1", map("a", "b")));
    t10.addBuildRunner(runnerDescriptorFactory.createBuildRunner(project10, "run20", "name20", "Ant2", map("a", "b")));
    BuildTriggerDescriptor trigger10 = t10.addBuildTrigger("Type", map("a", "b"));
    BuildTriggerDescriptor trigger20 = t10.addBuildTrigger("Type", map("a", "b"));
    t10.addBuildFeature(myFixture.getBuildFeatureDescriptorFactory().createBuildFeature("f10", "type", map("a", "b")));
    t10.addBuildFeature(myFixture.getBuildFeatureDescriptorFactory().createBuildFeature("f20", "type", map("a", "b")));
    t10.addBuildFeature(myFixture.getBuildFeatureDescriptorFactory().createBuildFeature("f30", "type", map("a", "b")));
    ArtifactDependencyFactory artifactDependencyFactory = myFixture.getSingletonService(ArtifactDependencyFactory.class);
    ArrayList<SArtifactDependency> artifactDeps = new ArrayList<>();
    artifactDeps.add(artifactDependencyFactory.createArtifactDependency("art10", bt100.getExternalId(), "path1", RevisionRules.LAST_PINNED_RULE));
    artifactDeps.add(artifactDependencyFactory.createArtifactDependency("art20", bt100.getExternalId(), "path2", RevisionRules.LAST_PINNED_RULE));
    artifactDeps.add(artifactDependencyFactory.createArtifactDependency("art30", bt100.getExternalId(), "path3", RevisionRules.LAST_PINNED_RULE));
    t10.setArtifactDependencies(artifactDeps);
    t10.addDependency(myFixture.getSingletonService(DependencyFactory.class).createDependency(bt100));
    t10.addDependency(myFixture.getSingletonService(DependencyFactory.class).createDependency(bt110));
    t10.addParameter(new SimpleParameter("a10", "b"));
    t10.addParameter(new SimpleParameter("a20", "b"));
    t10.addParameter(new SimpleParameter("a30", "b"));
    t10.addRequirement(myFixture.findSingletonService(RequirementFactory.class).createRequirement("req10", "a", null, RequirementType.EXISTS));
    t10.addRequirement(myFixture.findSingletonService(RequirementFactory.class).createRequirement("req20", "b", null, RequirementType.EXISTS));
    t10.addRequirement(myFixture.findSingletonService(RequirementFactory.class).createRequirement("req30", "c", null, RequirementType.EXISTS));
    // BUILD TYPE
    BuildTypeEx bt10 = project10.createBuildType("bt10", "bt 10");
    bt10.attachToTemplate(t10);
    // todo: test w/o override
    bt10.setArtifactPaths("bbbb");
    bt10.setOption(BuildTypeOptions.BT_ALLOW_EXTERNAL_STATUS, false);
    bt10.setOption(BuildTypeOptions.BT_FAIL_IF_TESTS_FAIL, false);
    {
    // hack to reproduce case related to https://youtrack.jetbrains.com/issue/TW-45273
    // comment until TW-45273 is fixed      t10.setOption(BuildTypeOptions.BT_FAIL_IF_TESTS_FAIL, false);
    }
    bt10.setOption(BuildTypeOptions.BT_CHECKOUT_DIR, "checkout_bt");
    bt10.setOption(BuildTypeOptions.BT_CHECKOUT_MODE, "ON_SERVER");
    bt10.setOption(BuildTypeOptions.BT_EXECUTION_TIMEOUT, 17);
    bt10.addVcsRoot(vcsRoot20);
    bt10.setCheckoutRules(vcsRoot20, new CheckoutRules("x=>y"));
    bt10.addVcsRoot(vcsRoot30);
    bt10.setEnabled("run20", false);
    bt10.addBuildRunner(runnerDescriptorFactory.createBuildRunner(project10, "run30", "name30", "Ant30", map("a", "b")));
    bt10.setEnabled(trigger20.getId(), false);
    BuildTriggerDescriptor trigger30 = bt10.addBuildTrigger("Type", map("a", "b"));
    bt10.setEnabled("f20", false);
    bt10.addBuildFeature(myFixture.getBuildFeatureDescriptorFactory().createBuildFeature("f30", "type_bt", map("a", "b")));
    bt10.addBuildFeature(myFixture.getBuildFeatureDescriptorFactory().createBuildFeature("f40", "type", map("a", "b")));
    ArrayList<SArtifactDependency> artifactDepsBt = new ArrayList<>();
    artifactDepsBt.add(artifactDependencyFactory.createArtifactDependency("art30", bt100.getExternalId(), "path30", RevisionRules.LAST_FINISHED_RULE));
    artifactDepsBt.add(artifactDependencyFactory.createArtifactDependency("art40", bt100.getExternalId(), "path4", RevisionRules.LAST_PINNED_RULE));
    bt10.setArtifactDependencies(artifactDepsBt);
    bt10.setEnabled("art20", false);
    bt10.addDependency(myFixture.getSingletonService(DependencyFactory.class).createDependency(bt110));
    bt10.addDependency(myFixture.getSingletonService(DependencyFactory.class).createDependency(bt120));
    bt10.addParameter(new SimpleParameter("a20", "x"));
    bt10.addParameter(new SimpleParameter("a30", "b"));
    bt10.addParameter(new SimpleParameter("a40", "x"));
    bt10.setEnabled("req20", false);
    bt10.addRequirement(myFixture.findSingletonService(RequirementFactory.class).createRequirement("req30", "x", null, RequirementType.EQUALS));
    bt10.addRequirement(myFixture.findSingletonService(RequirementFactory.class).createRequirement("req40", "y", null, RequirementType.EXISTS));
    // NOW, TEST TIME!
    // get buildType
    BuildType buildType = new BuildType(new BuildTypeOrTemplate(bt10), new Fields("$long"), getBeanContext(myServer));
    // post buildType to create new one
    buildType.initializeSubmittedFromUsual();
    buildType.setId("bt10_copy");
    buildType.setName("bt 10 - copy");
    BuildType buildType_copy = myBuildTypeRequest.addBuildType(buildType, Fields.LONG.getFieldsSpec());
    // compare initial and new buildType
    BuildTypeImpl bt10_copy = myFixture.getProjectManager().findBuildTypeByExternalId("bt10_copy");
    assertNotNull(bt10_copy);
    assertNull(BuildTypeUtil.compareBuildTypes(bt10.getSettings(), bt10_copy.getSettings(), true, false));
// todo:
// check different settings in submitted from the inherited one, but with inherited flag
// check submitting with different enabled state
// check submitting with different id
}
Also used : BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) CheckoutRules(jetbrains.buildServer.vcs.CheckoutRules) ArrayList(java.util.ArrayList) BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) SArtifactDependency(jetbrains.buildServer.serverSide.artifacts.SArtifactDependency) ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) BuildTriggerDescriptor(jetbrains.buildServer.buildTriggers.BuildTriggerDescriptor) SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) MockVcsSupport(jetbrains.buildServer.serverSide.impl.MockVcsSupport) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 77 with BuildTypeImpl

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

the class BuildTypeRequestTest method testBuildTypeSettings.

@Test
void testBuildTypeSettings() {
    BuildTypeImpl bt10 = registerBuildType("bt10", "projectName");
    bt10.setArtifactPaths("bbbb");
    bt10.setOption(BuildTypeOptions.BT_ALLOW_EXTERNAL_STATUS, false);
    bt10.setOption(BuildTypeOptions.BT_FAIL_IF_TESTS_FAIL, false);
    bt10.setOption(BuildTypeOptions.BT_CHECKOUT_DIR, "checkout_bt");
    bt10.setOption(BuildTypeOptions.BT_CHECKOUT_MODE, "ON_SERVER");
    bt10.setOption(BuildTypeOptions.BT_EXECUTION_TIMEOUT, 17);
    final String btLocator = "id:" + bt10.getExternalId();
    ParametersSubResource settingsSubResource = myBuildTypeRequest.getSettingsSubResource(btLocator);
    String fields = "$long,settings($long)";
    assertCollectionEquals("", settingsSubResource.getParameters(null, fields), p("artifactRules", "bbbb"), p("buildNumberCounter", "1"), p("checkoutDirectory", "checkout_bt"), p("checkoutMode", "ON_SERVER"), p("executionTimeoutMin", "17"), p("shouldFailBuildIfTestsFailed", "false"));
    // default value for direct get
    assertEquals("0", settingsSubResource.getParameter("maximumNumberOfBuilds", "$long").value);
    settingsSubResource.setParameter(new Property(new SimpleParameter("maximumNumberOfBuilds", "4"), false, Fields.LONG, myFixture), "$long");
    assertEquals("4", settingsSubResource.getParameter("maximumNumberOfBuilds", "$long").value);
    assertCollectionEquals("", settingsSubResource.getParameters(null, fields), p("artifactRules", "bbbb"), p("buildNumberCounter", "1"), p("checkoutDirectory", "checkout_bt"), p("checkoutMode", "ON_SERVER"), p("executionTimeoutMin", "17"), p("maximumNumberOfBuilds", "4"), p("shouldFailBuildIfTestsFailed", "false"));
    assertEquals("5", settingsSubResource.setParameter("maximumNumberOfBuilds", new Property(new SimpleParameter("maximumNumberOfBuilds", "5"), false, Fields.LONG, myFixture), "$long").value);
    assertEquals("5", settingsSubResource.getParameter("maximumNumberOfBuilds", "$long").value);
    assertEquals("6", settingsSubResource.setParameterValue("maximumNumberOfBuilds", "6"));
    assertEquals("6", settingsSubResource.getParameter("maximumNumberOfBuilds", "$long").value);
    assertEquals("7", settingsSubResource.setParameterValueLong("maximumNumberOfBuilds", "7"));
    assertEquals("7", settingsSubResource.getParameter("maximumNumberOfBuilds", "$long").value);
    // set to default value
    settingsSubResource.setParameter(new Property(new SimpleParameter("maximumNumberOfBuilds", "0"), false, Fields.LONG, myFixture), "$long");
    assertCollectionEquals("", settingsSubResource.getParameters(null, fields), p("artifactRules", "bbbb"), p("buildNumberCounter", "1"), p("checkoutDirectory", "checkout_bt"), p("checkoutMode", "ON_SERVER"), p("executionTimeoutMin", "17"), p("shouldFailBuildIfTestsFailed", "false"));
    settingsSubResource.deleteParameter("checkoutDirectory");
    assertCollectionEquals("", settingsSubResource.getParameters(null, fields), p("artifactRules", "bbbb"), p("buildNumberCounter", "1"), p("checkoutMode", "ON_SERVER"), p("executionTimeoutMin", "17"), p("shouldFailBuildIfTestsFailed", "false"));
    assertCollectionEquals("", settingsSubResource.getParameters(new Locator("defaults:any"), fields), p("allowExternalStatus", "false", true, null), p("allowPersonalBuildTriggering", "true", true, null), p("artifactRules", "bbbb", null, null), p("buildNumberCounter", "1", null, null), p("buildNumberPattern", "%build.counter%", true, null), p("checkoutDirectory", "", true, null), p("checkoutMode", "ON_SERVER", null, null), p("cleanBuild", "false", true, null), p("enableHangingBuildsDetection", "true", true, null), p("executionTimeoutMin", "17", null, null), p("maximumNumberOfBuilds", "0", true, null), p("publishArtifactCondition", "NORMALLY_FINISHED", true, null), p("shouldFailBuildIfTestsFailed", "false", null, null), p("shouldFailBuildOnAnyErrorMessage", "false", true, null), p("shouldFailBuildOnBadExitCode", "true", true, null), p("shouldFailBuildOnOOMEOrCrash", "true", true, null), p("showDependenciesChanges", "false", true, null), p("supportTestRetry", "false", true, null), p("vcsLabelingBranchFilter", "+:<default>", true, null), p("excludeDefaultBranchChanges", "false", true, null), p("buildDefaultBranch", "true", true, null), p("branchFilter", "+:*", true, null), p("generatedBuildConfigurationChecksum", "", true, null), p("buildConfigurationType", "REGULAR", true, null));
    assertCollectionEquals("", settingsSubResource.getParameters(new Locator("defaults:true"), fields), p("allowExternalStatus", "false", true, null), p("allowPersonalBuildTriggering", "true", true, null), p("buildNumberPattern", "%build.counter%", true, null), p("checkoutDirectory", "", true, null), p("cleanBuild", "false", true, null), p("enableHangingBuildsDetection", "true", true, null), p("maximumNumberOfBuilds", "0", true, null), p("publishArtifactCondition", "NORMALLY_FINISHED", true, null), p("shouldFailBuildOnAnyErrorMessage", "false", true, null), p("shouldFailBuildOnBadExitCode", "true", true, null), p("shouldFailBuildOnOOMEOrCrash", "true", true, null), p("showDependenciesChanges", "false", true, null), p("supportTestRetry", "false", true, null), p("vcsLabelingBranchFilter", "+:<default>", true, null), p("excludeDefaultBranchChanges", "false", true, null), p("buildDefaultBranch", "true", true, null), p("branchFilter", "+:*", true, null), p("generatedBuildConfigurationChecksum", "", true, null), p("buildConfigurationType", "REGULAR", true, null));
    assertCollectionEquals("", settingsSubResource.getParameters(new Locator("defaults:false"), fields), p("artifactRules", "bbbb", null, null), p("buildNumberCounter", "1", null, null), p("checkoutMode", "ON_SERVER", null, null), p("executionTimeoutMin", "17", null, null), p("shouldFailBuildIfTestsFailed", "false", null, null));
    assertCollectionEquals("", settingsSubResource.getParameters(new Locator("defaults:false,name:buildNumberCounter"), fields), p("buildNumberCounter", "1", null, null));
    HashMap<String, String> newParametersMap = new HashMap<>();
    // all the same
    newParametersMap.put("artifactRules", "bbbb");
    newParametersMap.put("buildNumberCounter", "1");
    newParametersMap.put("checkoutMode", "ON_SERVER");
    newParametersMap.put("executionTimeoutMin", "17");
    newParametersMap.put("shouldFailBuildIfTestsFailed", "false");
    settingsSubResource.setParameters(new Properties(newParametersMap, null, new Fields("**"), getBeanContext(myFixture)), "$long");
    assertCollectionEquals("", settingsSubResource.getParameters(null, fields), p("artifactRules", "bbbb"), p("buildNumberCounter", "1"), p("checkoutMode", "ON_SERVER"), p("executionTimeoutMin", "17"), p("shouldFailBuildIfTestsFailed", "false"));
    newParametersMap.remove("artifactRules");
    newParametersMap.put("buildNumberCounter", "2");
    settingsSubResource.setParameters(new Properties(newParametersMap, null, new Fields("**"), getBeanContext(myFixture)), "$long");
    assertCollectionEquals("", settingsSubResource.getParameters(null, fields), p("buildNumberCounter", "2"), p("checkoutMode", "ON_SERVER"), p("executionTimeoutMin", "17"), p("shouldFailBuildIfTestsFailed", "false"));
    newParametersMap.remove("buildNumberCounter");
    settingsSubResource.setParameters(new Properties(newParametersMap, null, new Fields("**"), getBeanContext(myFixture)), "$long");
    assertCollectionEquals(// is reset to "1"
    "", // is reset to "1"
    settingsSubResource.getParameters(null, fields), // is reset to "1"
    p("buildNumberCounter", "1"), p("checkoutMode", "ON_SERVER"), p("executionTimeoutMin", "17"), p("shouldFailBuildIfTestsFailed", "false"));
    checkException(LocatorProcessException.class, () -> settingsSubResource.getParameters(new Locator("a:b"), "$long"), null);
    checkException(BadRequestException.class, () -> settingsSubResource.setParameter(new Property(new SimpleParameter("aaa", "b"), false, Fields.LONG, myFixture), "$long"), null);
}
Also used : Locator(jetbrains.buildServer.server.rest.data.Locator) HashMap(java.util.HashMap) BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 78 with BuildTypeImpl

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

the class BuildTypeRequestTest method testUpdatingParametersWithTemplate1.

@Test
public void testUpdatingParametersWithTemplate1() {
    BuildTypeImpl buildType1 = registerTemplateBasedBuildType("buildType1");
    buildType1.addParameter(new SimpleParameter("a1", "b10"));
    buildType1.addParameter(new SimpleParameter("a2", "b9"));
    buildType1.addParameter(new SimpleParameter("a3", "b8"));
    buildType1.getTemplate().addParameter(new SimpleParameter("a1", "a7"));
    buildType1.getTemplate().addParameter(new SimpleParameter("a2", "b9"));
    buildType1.getTemplate().addParameter(new SimpleParameter("t1", "a5"));
    final String btLocator = "id:" + buildType1.getExternalId();
    final String templateLocator = "id:" + buildType1.getTemplate().getExternalId() + ",templateFlag:true";
    assertEquals(4, myBuildTypeRequest.getParametersSubResource(btLocator).getParameters(null, "$long,property($long)").properties.size());
    assertEquals(3, myBuildTypeRequest.getParametersSubResource(templateLocator).getParameters(null, "$long,property($long)").properties.size());
    myBuildTypeRequest.getParametersSubResource(btLocator).setParameter(new Property(new SimpleParameter("a4", "b"), false, Fields.LONG, myFixture), "$long");
    assertEquals(5, myBuildTypeRequest.getParametersSubResource(btLocator).getParameters(null, "$long,property($long)").properties.size());
    assertEquals(3, myBuildTypeRequest.getParametersSubResource(templateLocator).getParameters(null, "$long,property($long)").properties.size());
    myBuildTypeRequest.getParametersSubResource(btLocator).deleteParameter("a4");
    assertEquals(4, myBuildTypeRequest.getParametersSubResource(btLocator).getParameters(null, "$long,property($long)").properties.size());
    assertEquals("b10", myBuildTypeRequest.getParametersSubResource(btLocator).getParameters(null, "$long,property($long)").properties.get(0).value);
    // param from template is not deleted, but reset
    myBuildTypeRequest.getParametersSubResource(btLocator).deleteParameter("a1");
    assertEquals(4, myBuildTypeRequest.getParametersSubResource(btLocator).getParameters(null, "$long,property($long)").properties.size());
    assertEquals("a7", myBuildTypeRequest.getParametersSubResource(btLocator).getParameters(null, "$long,property($long)").properties.get(0).value);
    assertEquals(3, myBuildTypeRequest.getParametersSubResource(templateLocator).getParameters(null, "$long,property($long)").properties.size());
}
Also used : BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 79 with BuildTypeImpl

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

the class BuildTypeRequestTest method testUpdatingFeatures.

@Test
public void testUpdatingFeatures() {
    BuildTypeImpl buildType1 = registerBuildType("buildType1", "projectName");
    buildType1.addBuildFeature("featureType1", createMap("a", "b"));
    String disabledFeatureId = buildType1.addBuildFeature("featureType2", createMap("a", "b")).getId();
    buildType1.setEnabled(disabledFeatureId, false);
    buildType1.addBuildFeature("featureType3", createMap("a", "b"));
    BuildFeature buildFeature = singletonBuildFeature();
    myServer.registerExtension(BuildFeature.class, "", buildFeature);
    final String btLocator = "id:" + buildType1.getExternalId();
    assertEquals(3, myBuildTypeRequest.getFeatures(btLocator, "$long,feature($long)").propEntities.size());
    {
        PropEntityFeature submitted = new PropEntityFeature();
        submitted.type = buildFeature.getType();
        submitted.disabled = true;
        String newId = myBuildTypeRequest.addFeature(btLocator, "$long", submitted).id;
        assertEquals(4, myBuildTypeRequest.getFeatures(btLocator, "$long,feature($long)").propEntities.size());
        assertTrue(myBuildTypeRequest.getFeatures(btLocator, "$long,feature($long)").propEntities.get(3).disabled);
        myBuildTypeRequest.deleteFeature(btLocator, newId);
        assertEquals(3, myBuildTypeRequest.getFeatures(btLocator, "$long,feature($long)").propEntities.size());
    }
    {
        PropEntitiesFeature submitted = new PropEntitiesFeature();
        PropEntityFeature submitted1 = new PropEntityFeature();
        submitted1.type = buildFeature.getType();
        PropEntityFeature submitted2 = new PropEntityFeature();
        submitted2.type = buildFeature.getType();
        // two features of the type with isMultipleFeaturesPerBuildTypeAllowed==false will produce error on adding
        submitted.propEntities = Arrays.asList(submitted1, submitted2);
        checkException(BadRequestException.class, new Runnable() {

            public void run() {
                myBuildTypeRequest.replaceFeatures(btLocator, "$long", submitted);
            }
        }, null);
        assertEquals(3, myBuildTypeRequest.getFeatures(btLocator, "$long,feature($long)").propEntities.size());
        assertEquals(3, buildType1.getBuildFeatures().size());
        assertFalse(buildType1.isEnabled(disabledFeatureId));
    }
    buildType1.getSettings().addListener(new BuildTypeSettingsAdapter() {

        private int myTriggerOnCall = 1;

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

            public void run() {
                myBuildTypeRequest.addFeature(btLocator, "$long", submitted);
            }
        }, null);
        assertEquals(3, myBuildTypeRequest.getFeatures(btLocator, "$long,feature($long)").propEntities.size());
        assertEquals(3, buildType1.getBuildFeatures().size());
        assertFalse(buildType1.isEnabled(disabledFeatureId));
    }
    myBuildTypeRequest.replaceFeatures(btLocator, "$long", new PropEntitiesFeature());
    assertEquals(0, buildType1.getBuildFeatures().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 80 with BuildTypeImpl

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

the class BuildTypeRequestTest method testUpdatingSnapshotDependencies.

@Test
public void testUpdatingSnapshotDependencies() {
    BuildTypeImpl buildType1 = registerBuildType("buildType1", "projectName");
    BuildTypeImpl buildType2 = registerBuildType("buildType2", "projectName");
    BuildTypeImpl buildType3 = registerBuildType("buildType3", "projectName");
    BuildTypeImpl buildType4 = registerBuildType("buildType4", "projectName");
    BuildTypeImpl buildType5 = registerBuildType("buildType5", "projectName");
    DependencyFactory factory = myFixture.findSingletonService(DependencyFactory.class);
    assert factory != null;
    buildType1.addDependency(factory.createDependency(buildType2));
    buildType1.addDependency(factory.createDependency(buildType3));
    buildType1.addDependency(factory.createDependency(buildType4));
    final String btLocator = "id:" + buildType1.getExternalId();
    assertEquals(3, myBuildTypeRequest.getSnapshotDeps(btLocator, "$long,snapshot-dependencies($long)").propEntities.size());
    {
        PropEntitySnapshotDep submitted = new PropEntitySnapshotDep();
        submitted.type = "snapshot_dependency";
        submitted.sourceBuildType = new BuildType();
        submitted.sourceBuildType.setId(buildType5.getExternalId());
        String newId = myBuildTypeRequest.addSnapshotDep(btLocator, "$long", submitted).id;
        assertEquals(4, myBuildTypeRequest.getSnapshotDeps(btLocator, "$long,snapshot-dependencies($long)").propEntities.size());
        myBuildTypeRequest.deleteSnapshotDep(btLocator, newId);
        assertEquals(3, myBuildTypeRequest.getSnapshotDeps(btLocator, "$long,snapshot-dependencies($long)").propEntities.size());
    }
    {
        PropEntitiesSnapshotDep submitted = new PropEntitiesSnapshotDep();
        PropEntitySnapshotDep submitted1 = new PropEntitySnapshotDep();
        submitted1.type = "snapshot_dependency";
        submitted1.sourceBuildType = new BuildType();
        submitted1.sourceBuildType.setId(buildType1.getExternalId());
        submitted.propEntities = Arrays.asList(submitted1);
        checkException(BadRequestException.class, new Runnable() {

            public void run() {
                myBuildTypeRequest.replaceSnapshotDeps(btLocator, "$long", submitted);
            }
        }, null);
        assertNotNull(myBuildTypeRequest.getSnapshotDeps(btLocator, "$long,snapshot-dependencies($long)").propEntities);
        assertEquals(3, myBuildTypeRequest.getSnapshotDeps(btLocator, "$long,snapshot-dependencies($long)").propEntities.size());
        assertEquals(3, buildType1.getDependencies().size());
    }
    {
        PropEntitySnapshotDep submitted = new PropEntitySnapshotDep();
        submitted.type = "snapshot_dependency";
        submitted.sourceBuildType = new BuildType();
        submitted.sourceBuildType.setId(buildType1.getExternalId());
        checkException(BadRequestException.class, new Runnable() {

            public void run() {
                myBuildTypeRequest.addSnapshotDep(btLocator, "$long", submitted);
            }
        }, null);
        assertNotNull(myBuildTypeRequest.getSnapshotDeps(btLocator, "$long,snapshot-dependencies($long)").propEntities);
        assertEquals(3, myBuildTypeRequest.getSnapshotDeps(btLocator, "$long,snapshot-dependencies($long)").propEntities.size());
        assertEquals(3, buildType1.getDependencies().size());
    }
    myBuildTypeRequest.replaceSnapshotDeps(btLocator, "$long", new PropEntitiesSnapshotDep());
    assertEquals(0, buildType1.getDependencies().size());
}
Also used : DependencyFactory(jetbrains.buildServer.serverSide.dependency.DependencyFactory) 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)

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