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"));
}
}
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());
}
Aggregations