Search in sources :

Example 1 with VersionedSettingsManager

use of jetbrains.buildServer.serverSide.versionedSettings.VersionedSettingsManager in project teamcity-rest by JetBrains.

the class VcsRootInstanceFinderTest method testVersionedSettingsInstances.

@Test
public void testVersionedSettingsInstances() throws Exception {
    myFixture.registerVcsSupport("svn");
    final ProjectEx project10 = getRootProject().createProject("project10", "Project name 10");
    final ProjectEx project20 = project10.createProject("project20", "Project name 20");
    final ProjectEx project30 = project20.createProject("project30", "Project name 30");
    final ProjectEx project40 = project30.createProject("project40", "Project name 40");
    final ProjectEx project50 = project40.createProject("project50", "Project name 50");
    final ProjectEx project60 = project40.createProject("project60", "Project name 60");
    final SVcsRoot vcsRoot20 = project20.createVcsRoot("svn", "id10", "VCS root 10 name");
    vcsRoot20.setProperties(CollectionsUtil.asMap("aaa", "%param%"));
    final SVcsRoot vcsRoot30 = project20.createVcsRoot("svn", "id30", "id30");
    ProjectFeatureDescriptorFactory projectFeatureFactory = myFixture.getSingletonService(ProjectFeatureDescriptorFactory.class);
    Map<String, String> params = CollectionsUtil.asMap("buildSettings", "ALWAYS_USE_CURRENT", "rootId", vcsRoot20.getExternalId(), "showChanges", "false");
    SProjectFeatureDescriptor featureDescriptor30 = projectFeatureFactory.createNewProjectFeature("versionedSettings", params, project30.getProjectId());
    project30.addFeature(featureDescriptor30);
    Map<String, String> params2 = CollectionsUtil.asMap("buildSettings", "ALWAYS_USE_CURRENT", "rootId", vcsRoot20.getExternalId(), "showChanges", "true");
    SProjectFeatureDescriptor featureDescriptor40 = projectFeatureFactory.createNewProjectFeature("versionedSettings", params2, project40.getProjectId());
    project30.addFeature(featureDescriptor40);
    Map<String, String> params3 = CollectionsUtil.asMap("enabled", "false");
    SProjectFeatureDescriptor featureDescriptor60 = projectFeatureFactory.createNewProjectFeature("versionedSettings", params3, project60.getProjectId());
    project60.addFeature(featureDescriptor60);
    VersionedSettingsManager versionedSettingsManager = myFixture.getSingletonService(VersionedSettingsManager.class);
    {
        VcsRootInstance versionedSettingsVcsRoot_p30 = versionedSettingsManager.getVersionedSettingsVcsRootInstance(project30);
        check(null, versionedSettingsVcsRoot_p30);
        check("affectedProject:(id:" + project20.getExternalId() + ")", versionedSettingsVcsRoot_p30);
        check("affectedProject:(id:" + project30.getExternalId() + ")", versionedSettingsVcsRoot_p30);
        check("affectedProject:(id:" + project40.getExternalId() + ")", versionedSettingsVcsRoot_p30);
    }
    project20.addParameter(new SimpleParameter("param", "p20"));
    project30.addParameter(new SimpleParameter("param", "p30"));
    project40.addParameter(new SimpleParameter("param", "p40"));
    BuildTypeEx p40_bt10 = project40.createBuildType("p40_bt10");
    p40_bt10.addParameter(new SimpleParameter("param", "bt"));
    BuildTypeEx p40_bt20 = project40.createBuildType("p40_bt20");
    BuildTypeEx p40_bt30 = project40.createBuildType("p40_bt30");
    {
        VcsRootInstance versionedSettingsVcsRoot_p30 = versionedSettingsManager.getVersionedSettingsVcsRootInstance(project30);
        VcsRootInstance versionedSettingsVcsRoot_p40 = versionedSettingsManager.getVersionedSettingsVcsRootInstance(project40);
        VcsRootInstance btInstance10 = attachVcsRoot(p40_bt10, vcsRoot20);
        VcsRootInstance btInstance20 = attachVcsRoot(p40_bt20, vcsRoot20);
        VcsRootInstance btInstance30 = attachVcsRoot(p40_bt20, vcsRoot30);
        assert btInstance20.equals(versionedSettingsVcsRoot_p40);
        check(null, versionedSettingsVcsRoot_p30, versionedSettingsVcsRoot_p40, btInstance10, btInstance30);
        check("property:(name:aaa,value:p30)", versionedSettingsVcsRoot_p30);
        check("buildType:(id:" + p40_bt10.getExternalId() + ")", btInstance10);
        check("buildType:(id:" + p40_bt20.getExternalId() + ")", versionedSettingsVcsRoot_p40, btInstance30);
        check("buildType:(id:" + p40_bt30.getExternalId() + ")");
        check("buildType:(id:" + p40_bt10.getExternalId() + "),versionedSettings:any", versionedSettingsVcsRoot_p40, btInstance10);
        check("buildType:(id:" + p40_bt10.getExternalId() + "),versionedSettings:false", btInstance10);
        check("buildType:(id:" + p40_bt10.getExternalId() + "),versionedSettings:true", versionedSettingsVcsRoot_p40);
        check("buildType:(id:" + p40_bt20.getExternalId() + "),versionedSettings:any", versionedSettingsVcsRoot_p40, btInstance30);
        check("buildType:(id:" + p40_bt20.getExternalId() + "),versionedSettings:false", versionedSettingsVcsRoot_p40, btInstance30);
        check("buildType:(id:" + p40_bt20.getExternalId() + "),versionedSettings:true", versionedSettingsVcsRoot_p40);
        check("buildType:(id:" + p40_bt30.getExternalId() + "),versionedSettings:any", versionedSettingsVcsRoot_p40);
        check("buildType:(id:" + p40_bt30.getExternalId() + "),versionedSettings:false");
        check("buildType:(id:" + p40_bt30.getExternalId() + "),versionedSettings:true", versionedSettingsVcsRoot_p40);
        check("buildType:(id:" + p40_bt10.getExternalId() + "),vcsRoot:(id:" + vcsRoot20.getExternalId() + "),versionedSettings:false", btInstance10);
        check("buildType:(id:" + p40_bt10.getExternalId() + "),vcsRoot:(id:" + vcsRoot20.getExternalId() + "),versionedSettings:any", versionedSettingsVcsRoot_p40, btInstance10);
        check("buildType:(id:" + p40_bt10.getExternalId() + "),vcsRoot:(id:" + vcsRoot20.getExternalId() + "),versionedSettings:true", versionedSettingsVcsRoot_p40);
        check("buildType:(id:" + p40_bt20.getExternalId() + "),vcsRoot:(id:" + vcsRoot20.getExternalId() + "),versionedSettings:false", versionedSettingsVcsRoot_p40);
        check("buildType:(id:" + p40_bt20.getExternalId() + "),vcsRoot:(id:" + vcsRoot20.getExternalId() + "),versionedSettings:any", versionedSettingsVcsRoot_p40);
        check("buildType:(id:" + p40_bt20.getExternalId() + "),vcsRoot:(id:" + vcsRoot20.getExternalId() + "),versionedSettings:true", versionedSettingsVcsRoot_p40);
        check("buildType:(id:" + p40_bt20.getExternalId() + "),vcsRoot:(id:" + vcsRoot30.getExternalId() + "),versionedSettings:false", btInstance30);
        check("buildType:(id:" + p40_bt20.getExternalId() + "),vcsRoot:(id:" + vcsRoot30.getExternalId() + "),versionedSettings:any", btInstance30);
        check("buildType:(id:" + p40_bt20.getExternalId() + "),vcsRoot:(id:" + vcsRoot30.getExternalId() + "),versionedSettings:true");
        check("vcsRoot:(id:" + vcsRoot20.getExternalId() + ")", versionedSettingsVcsRoot_p30, versionedSettingsVcsRoot_p40, btInstance10);
        check("vcsRoot:(id:" + vcsRoot20.getExternalId() + "),versionedSettings:true", versionedSettingsVcsRoot_p30, versionedSettingsVcsRoot_p40);
        check("vcsRoot:(id:" + vcsRoot20.getExternalId() + "),versionedSettings:false", versionedSettingsVcsRoot_p40, btInstance10);
        check("vcsRoot:(id:" + vcsRoot20.getExternalId() + "),versionedSettings:any", versionedSettingsVcsRoot_p30, versionedSettingsVcsRoot_p40, btInstance10);
        check("buildType:(count:1000)", versionedSettingsVcsRoot_p40, btInstance10, btInstance30);
        project50.addParameter(new SimpleParameter("param", "p50"));
        VcsRootInstance versionedSettingsVcsRoot_p50 = versionedSettingsManager.getVersionedSettingsVcsRootInstance(project50);
        check(null, versionedSettingsVcsRoot_p30, versionedSettingsVcsRoot_p40, btInstance10, btInstance30, versionedSettingsVcsRoot_p50);
        check("vcsRoot:(id:" + vcsRoot20.getExternalId() + "),versionedSettings:true", versionedSettingsVcsRoot_p30, versionedSettingsVcsRoot_p40, versionedSettingsVcsRoot_p50);
        check("versionedSettings:true", versionedSettingsVcsRoot_p30, versionedSettingsVcsRoot_p40, versionedSettingsVcsRoot_p50);
        check("buildType:(count:1000)", versionedSettingsVcsRoot_p40, btInstance10, btInstance30);
        // versionedSettingsVcsRoot_p50 not included as no configs in the project
        check("buildType:(count:1000),versionedSettings:any", versionedSettingsVcsRoot_p40, btInstance10, btInstance30);
        check("item:(buildType:(count:1000),versionedSettings:false),item:(versionedSettings:true)", versionedSettingsVcsRoot_p40, btInstance10, btInstance30, // so far sorting does not work for "or"
        versionedSettingsVcsRoot_p30, versionedSettingsVcsRoot_p50);
        // has showChanges=false in versioned settings
        BuildTypeEx p30_bt10 = project30.createBuildType("p30_bt10");
        check("buildType:(id:" + p30_bt10.getExternalId() + "),versionedSettings:true", versionedSettingsVcsRoot_p30);
        p40_bt20.removeVcsRoot(vcsRoot30);
        project50.removeParameter("param");
        // check("project:(id:" + project20.getExternalId() + ")");
        check("project:(id:" + project30.getExternalId() + ")", versionedSettingsVcsRoot_p30);
        check("project:(id:" + project40.getExternalId() + ")", versionedSettingsVcsRoot_p40);
        check("project:(id:" + project50.getExternalId() + ")", versionedSettingsVcsRoot_p40);
        check("project:(id:" + project60.getExternalId() + ")");
        check("affectedProject:(id:" + project20.getExternalId() + ")", versionedSettingsVcsRoot_p30, versionedSettingsVcsRoot_p40, btInstance10);
        check("affectedProject:(id:" + project30.getExternalId() + ")", versionedSettingsVcsRoot_p30, versionedSettingsVcsRoot_p40, btInstance10);
        check("affectedProject:(id:" + project40.getExternalId() + ")", versionedSettingsVcsRoot_p40, btInstance10);
        check("affectedProject:(id:" + project20.getExternalId() + "),versionedSettings:any", versionedSettingsVcsRoot_p30, versionedSettingsVcsRoot_p40, btInstance10);
        check("affectedProject:(id:" + project20.getExternalId() + "),versionedSettings:false", versionedSettingsVcsRoot_p40, btInstance10);
        check("affectedProject:(id:" + project20.getExternalId() + "),versionedSettings:true", versionedSettingsVcsRoot_p30, versionedSettingsVcsRoot_p40);
        final ProjectEx project70 = project40.createProject("project70", "Project name 70");
        project70.addParameter(new SimpleParameter("param", "bt"));
        VcsRootInstance versionedSettingsVcsRoot_p70 = versionedSettingsManager.getVersionedSettingsVcsRootInstance(project70);
        assert versionedSettingsVcsRoot_p70 != null;
        assert versionedSettingsVcsRoot_p70.equals(btInstance10);
        check("buildType:(id:" + p40_bt10.getExternalId() + ")", btInstance10);
        check("project:(id:" + project40.getExternalId() + ")", versionedSettingsVcsRoot_p40);
        check("project:(id:" + project70.getExternalId() + ")", btInstance10);
        check("project:(id:" + project70.getExternalId() + "),versionedSettings:true", btInstance10);
        check("project:(id:" + project70.getExternalId() + "),versionedSettings:false");
        check("affectedProject:(id:" + project40.getExternalId() + ")", versionedSettingsVcsRoot_p40, btInstance10);
        check("affectedProject:(id:" + project40.getExternalId() + "),versionedSettings:any", versionedSettingsVcsRoot_p40, btInstance10);
        check("affectedProject:(id:" + project40.getExternalId() + "),versionedSettings:false", btInstance20, btInstance10);
        check("affectedProject:(id:" + project40.getExternalId() + "),versionedSettings:true", versionedSettingsVcsRoot_p40, btInstance10);
        check("affectedProject:(id:" + project70.getExternalId() + "),versionedSettings:false");
        check("affectedProject:(id:" + project70.getExternalId() + "),versionedSettings:true", versionedSettingsVcsRoot_p70);
    }
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) ProjectFeatureDescriptorFactory(jetbrains.buildServer.serverSide.impl.ProjectFeatureDescriptorFactory) VersionedSettingsManager(jetbrains.buildServer.serverSide.versionedSettings.VersionedSettingsManager) Test(org.testng.annotations.Test)

Aggregations

ProjectEx (jetbrains.buildServer.serverSide.impl.ProjectEx)1 ProjectFeatureDescriptorFactory (jetbrains.buildServer.serverSide.impl.ProjectFeatureDescriptorFactory)1 VersionedSettingsManager (jetbrains.buildServer.serverSide.versionedSettings.VersionedSettingsManager)1 Test (org.testng.annotations.Test)1