Search in sources :

Example 1 with ProjectFeatureDescriptorFactory

use of jetbrains.buildServer.serverSide.impl.ProjectFeatureDescriptorFactory 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)

Example 2 with ProjectFeatureDescriptorFactory

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

the class ProjectFinderTest method testProjectBean.

@Test
public void testProjectBean() throws Exception {
    final SProject project10 = createProject("p1", "project 1");
    final SProject project20 = createProject("p2", "project 2");
    final SProject project10_10 = project10.createProject("p10_10", "p1_child1");
    final SProject project10_20 = project10.createProject("p10_20", "xxx");
    final SProject project10_10_10 = project10_10.createProject("p10_10_10", "xxx");
    final SProject project30 = createProject(project10.getProjectId(), "p3");
    Project project = new Project(project10, new Fields("projects($long)"), getBeanContext(myServer));
    assertNotNull(project.projects.projects);
    checkOrderedCollection(CollectionsUtil.convertCollection(project.projects.projects, new Converter<String, Project>() {

        public String createFrom(@NotNull final Project source) {
            return source.id;
        }
    }), project10_10.getExternalId(), project10_20.getExternalId());
    project = new Project(project10, new Fields("projects($long,$locator(name:xxx))"), getBeanContext(myServer));
    assertNotNull(project.projects.projects);
    checkOrderedCollection(CollectionsUtil.convertCollection(project.projects.projects, new Converter<String, Project>() {

        public String createFrom(@NotNull final Project source) {
            return source.id;
        }
    }), project10_20.getExternalId());
    project = new Project(project10, new Fields("projects($long,$locator(project:$any,affectedProject:(" + project10.getExternalId() + ")))"), getBeanContext(myServer));
    assertNotNull(project.projects.projects);
    checkOrderedCollection(CollectionsUtil.convertCollection(project.projects.projects, new Converter<String, Project>() {

        public String createFrom(@NotNull final Project source) {
            return source.id;
        }
    }), project10_10.getExternalId(), project10_20.getExternalId(), project10_10_10.getExternalId());
    ProjectFeatureDescriptorFactory featureDescriptorFactory = myFixture.findSingletonService(ProjectFeatureDescriptorFactory.class);
    assert featureDescriptorFactory != null;
    project10.addFeature(featureDescriptorFactory.createProjectFeature("uniqueId10", "type10", asMap("a", "b", "c", "d"), project10.getProjectId()));
    project10_10.addFeature(featureDescriptorFactory.createProjectFeature("uniqueId20", "type20", asMap("a", "b", "c", "d"), project10_10.getProjectId()));
    project = new Project(project10_10, new Fields("$long"), getBeanContext(myServer));
    assertEquals(project.id, project10_10.getExternalId());
    assertNotNull(project.projectFeatures);
    assertEquals(Integer.valueOf(1), project.projectFeatures.count);
    List<PropEntityProjectFeature> propEntities = project.projectFeatures.propEntities;
    assertEquals(1, propEntities.size());
    PropEntityProjectFeature feature = propEntities.get(0);
    assertEquals("uniqueId20", feature.id);
    assertEquals("type20", feature.type);
    assertEquals(Integer.valueOf(2), feature.properties.count);
    assertEquals("a", feature.properties.properties.get(0).name);
    assertEquals("b", feature.properties.properties.get(0).value);
    assertEquals("c", feature.properties.properties.get(1).name);
    assertEquals("d", feature.properties.properties.get(1).value);
}
Also used : ProjectFeatureDescriptorFactory(jetbrains.buildServer.serverSide.impl.ProjectFeatureDescriptorFactory) Project(jetbrains.buildServer.server.rest.model.project.Project) SProject(jetbrains.buildServer.serverSide.SProject) Fields(jetbrains.buildServer.server.rest.model.Fields) PropEntityProjectFeature(jetbrains.buildServer.server.rest.model.project.PropEntityProjectFeature) Converter(jetbrains.buildServer.util.Converter) SProject(jetbrains.buildServer.serverSide.SProject) NotNull(org.jetbrains.annotations.NotNull) Test(org.testng.annotations.Test)

Example 3 with ProjectFeatureDescriptorFactory

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

the class PropEntityProjectFeature method addToInternal.

@NotNull
public SProjectFeatureDescriptor addToInternal(@NotNull final SProject project, @NotNull final ServiceLocator serviceLocator) {
    if (StringUtil.isEmpty(type)) {
        throw new BadRequestException("Project feature cannot have empty 'type'.");
    }
    @NotNull final ProjectFeatureDescriptorFactory factory = serviceLocator.getSingletonService(ProjectFeatureDescriptorFactory.class);
    String forcedId = null;
    // special case for "overriden" entities
    if (id != null) {
        for (SProjectFeatureDescriptor item : project.getOwnFeatures()) {
            if (id.equals(item.getId())) {
                forcedId = id;
                break;
            }
        }
    }
    SProjectFeatureDescriptor newFeature;
    if (forcedId != null) {
        newFeature = factory.createProjectFeature(forcedId, type, properties != null ? properties.getMap() : new HashMap<String, String>(), project.getProjectId());
    } else {
        newFeature = factory.createNewProjectFeature(type, properties != null ? properties.getMap() : new HashMap<String, String>(), project.getProjectId());
    }
    try {
        project.addFeature(newFeature);
    } catch (Exception e) {
        final String details = getDetails(project, newFeature, e);
        throw new BadRequestException("Error adding feature: " + details, e);
    }
    return getFeatureByLocator(project, newFeature.getId());
}
Also used : ProjectFeatureDescriptorFactory(jetbrains.buildServer.serverSide.impl.ProjectFeatureDescriptorFactory) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) SProjectFeatureDescriptor(jetbrains.buildServer.serverSide.SProjectFeatureDescriptor) NotNull(org.jetbrains.annotations.NotNull) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) InvalidStateException(jetbrains.buildServer.server.rest.errors.InvalidStateException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ProjectFeatureDescriptorFactory (jetbrains.buildServer.serverSide.impl.ProjectFeatureDescriptorFactory)3 NotNull (org.jetbrains.annotations.NotNull)2 Test (org.testng.annotations.Test)2 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)1 InvalidStateException (jetbrains.buildServer.server.rest.errors.InvalidStateException)1 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)1 Fields (jetbrains.buildServer.server.rest.model.Fields)1 Project (jetbrains.buildServer.server.rest.model.project.Project)1 PropEntityProjectFeature (jetbrains.buildServer.server.rest.model.project.PropEntityProjectFeature)1 SProject (jetbrains.buildServer.serverSide.SProject)1 SProjectFeatureDescriptor (jetbrains.buildServer.serverSide.SProjectFeatureDescriptor)1 ProjectEx (jetbrains.buildServer.serverSide.impl.ProjectEx)1 VersionedSettingsManager (jetbrains.buildServer.serverSide.versionedSettings.VersionedSettingsManager)1 Converter (jetbrains.buildServer.util.Converter)1