Search in sources :

Example 1 with SProjectFeatureDescriptor

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

the class ProjectRequestTest method testProjectFeaturesParameters.

@Test
void testProjectFeaturesParameters() {
    ProjectEx project10 = createProject("project10", "project10");
    SProjectFeatureDescriptor feature10 = myFixture.getSingletonService(ProjectFeatureDescriptorFactory.class).createNewProjectFeature("feature_type", CollectionsUtil.asMap("a", "b"), project10.getProjectId());
    project10.addFeature(feature10);
    {
        String newValue = myRequest.getFeatures("id:" + project10.getExternalId()).getParametersSubResource(feature10.getId(), "$long").setParameterValue("a", "B");
        assertEquals("B", newValue);
        assertEquals(1, project10.getAvailableFeatures().size());
        assertEquals("B", project10.findFeatureById(feature10.getId()).getParameters().get("a"));
    }
    {
        String newValue = myRequest.getFeatures("id:" + project10.getExternalId()).getParametersSubResource("id:" + feature10.getId(), "$long").setParameterValue("a", "X");
        assertEquals("X", newValue);
        assertEquals(1, project10.getAvailableFeatures().size());
        assertEquals("X", project10.findFeatureById(feature10.getId()).getParameters().get("a"));
        assertEquals(1, project10.findFeatureById(feature10.getId()).getParameters().size());
    }
    {
        String newValue = myRequest.getFeatures("id:" + project10.getExternalId()).getParametersSubResource("id:" + feature10.getId(), "$long").setParameterValue("b", "Y");
        assertEquals("Y", newValue);
        assertEquals(1, project10.getAvailableFeatures().size());
        assertEquals(2, project10.findFeatureById(feature10.getId()).getParameters().size());
        assertEquals("Y", project10.findFeatureById(feature10.getId()).getParameters().get("b"));
    }
    {
        myRequest.getFeatures("id:" + project10.getExternalId()).getParametersSubResource("id:" + feature10.getId(), "$long").deleteParameter("b");
        assertEquals(1, project10.getAvailableFeatures().size());
        assertEquals(1, project10.findFeatureById(feature10.getId()).getParameters().size());
        assertEquals(null, project10.findFeatureById(feature10.getId()).getParameters().get("b"));
        assertEquals("X", project10.findFeatureById(feature10.getId()).getParameters().get("a"));
    }
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) ProjectFeatureDescriptorFactory(jetbrains.buildServer.serverSide.impl.ProjectFeatureDescriptorFactory) SProjectFeatureDescriptor(jetbrains.buildServer.serverSide.SProjectFeatureDescriptor) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 2 with SProjectFeatureDescriptor

use of jetbrains.buildServer.serverSide.SProjectFeatureDescriptor 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

SProjectFeatureDescriptor (jetbrains.buildServer.serverSide.SProjectFeatureDescriptor)2 ProjectFeatureDescriptorFactory (jetbrains.buildServer.serverSide.impl.ProjectFeatureDescriptorFactory)2 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)1 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)1 InvalidStateException (jetbrains.buildServer.server.rest.errors.InvalidStateException)1 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)1 ProjectEx (jetbrains.buildServer.serverSide.impl.ProjectEx)1 NotNull (org.jetbrains.annotations.NotNull)1 Test (org.testng.annotations.Test)1