use of jetbrains.buildServer.serverSide.parameters.ParameterFactory in project teamcity-rest by JetBrains.
the class BuildTypeRequestTest method testParameterTypeResourses.
@Test
public void testParameterTypeResourses() {
BuildTypeImpl buildType1 = registerTemplateBasedBuildType("buildType1");
ParameterFactory parameterFactory = myFixture.getSingletonService(ParameterFactory.class);
ParameterDescriptionFactory parameterDescriptionFactory = myFixture.getSingletonService(ParameterDescriptionFactory.class);
buildType1.addParameter(parameterFactory.createParameter("a1", "b10", parameterDescriptionFactory.createDescription("cType", CollectionsUtil.asMap("a", "b", "c", "d"))));
buildType1.addParameter(new SimpleParameter("a2", "b9"));
final String btLocator = "id:" + buildType1.getExternalId();
TypedParametersSubResource parametersSubResource = myBuildTypeRequest.getParametersSubResource(btLocator);
assertEquals(2, parametersSubResource.getParameters(null, "$long,property($long)").properties.size());
{
Property parameter = parametersSubResource.getParameter("a1", "$long");
assertEquals("a1", parameter.name);
assertEquals("b10", parameter.value);
assertEquals("cType a='b' c='d'", parameter.type.rawValue);
}
{
ParameterType parameterType = parametersSubResource.getParameterType("a1");
assertEquals("cType a='b' c='d'", parameterType.rawValue);
}
/*
{
assertEquals("cType", buildType1.getParameter("a1").getControlDescription().getParameterType());
assertMap(buildType1.getParameter("a1").getControlDescription().getParameterTypeArguments(), "a", "b", "c", "d");
ParameterType parameterType = new ParameterType();
parameterType.rawValue = "cType a='b1' c='d'";
ParameterType newParameterType = parametersSubResource.setParameterType("a1", parameterType);
assertEquals("cType a='b1' c='d'", newParameterType.rawValue);
assertEquals("cType", buildType1.getParameter("a1").getControlDescription().getParameterType());
assertMap(buildType1.getParameter("a1").getControlDescription().getParameterTypeArguments(), "a", "b1", "c", "d");
}
*/
}
use of jetbrains.buildServer.serverSide.parameters.ParameterFactory in project teamcity-rest by JetBrains.
the class BuildTypeRequestTest method testCreatingWithInheritedParams.
@Test
public void testCreatingWithInheritedParams() {
// see also alike setup in BuildTypeTest.testInheritance()
ProjectEx project10 = createProject("project10", "project 10");
final ParameterFactory parameterFactory = myFixture.getSingletonService(ParameterFactory.class);
project10.addParameter(parameterFactory.createTypedParameter("a_pwd", "secret", "password"));
project10.addParameter(new SimpleParameter("b_normal", "value"));
BuildTypeEx bt10 = project10.createBuildType("bt10", "bt 10");
// 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());
BuildTypeImpl bt10_copy = myFixture.getProjectManager().findBuildTypeByExternalId("bt10_copy");
assertNotNull(bt10_copy);
assertNull(BuildTypeUtil.compareBuildTypes(bt10.getSettings(), bt10_copy.getSettings(), true, false));
bt10_copy.remove();
}
{
Properties parameters = buildType.getParameters();
parameters.properties.get(1).value = null;
buildType.setParameters(parameters);
BuildType buildType_copy = myBuildTypeRequest.addBuildType(buildType, Fields.LONG.getFieldsSpec());
BuildTypeImpl bt10_copy = myFixture.getProjectManager().findBuildTypeByExternalId("bt10_copy");
assertNotNull(bt10_copy);
assertNull(BuildTypeUtil.compareBuildTypes(bt10.getSettings(), bt10_copy.getSettings(), true, false));
bt10_copy.remove();
// reset params
buildType.setParameters(buildType.getParameters());
}
{
Properties parameters = buildType.getParameters();
parameters.properties.get(0).type.rawValue = "text";
buildType.setParameters(parameters);
checkException(BadRequestException.class, () -> myBuildTypeRequest.addBuildType(buildType, Fields.LONG.getFieldsSpec()), null);
// reset params
buildType.setParameters(buildType.getParameters());
}
{
{
Properties parameters = buildType.getParameters();
parameters.properties.get(0).inherited = null;
buildType.setParameters(parameters);
}
checkException(BadRequestException.class, () -> myBuildTypeRequest.addBuildType(buildType, Fields.LONG.getFieldsSpec()), null);
{
Properties parameters = buildType.getParameters();
parameters.properties.get(0).inherited = false;
buildType.setParameters(parameters);
}
checkException(BadRequestException.class, () -> myBuildTypeRequest.addBuildType(buildType, Fields.LONG.getFieldsSpec()), null);
// reset params
buildType.setParameters(buildType.getParameters());
}
{
Properties parameters = buildType.getParameters();
parameters.properties.get(0).value = "secret";
buildType.setParameters(parameters);
BuildType buildType_copy = myBuildTypeRequest.addBuildType(buildType, Fields.LONG.getFieldsSpec());
BuildTypeImpl bt10_copy = myFixture.getProjectManager().findBuildTypeByExternalId("bt10_copy");
assertNotNull(bt10_copy);
assertNull(BuildTypeUtil.compareBuildTypes(bt10.getSettings(), bt10_copy.getSettings(), true, false));
bt10_copy.remove();
// reset params
buildType.setParameters(buildType.getParameters());
}
{
Properties parameters = buildType.getParameters();
parameters.properties.get(0).value = "secret2";
buildType.setParameters(parameters);
BuildType buildType_copy = myBuildTypeRequest.addBuildType(buildType, Fields.LONG.getFieldsSpec());
BuildTypeImpl bt10_copy = myFixture.getProjectManager().findBuildTypeByExternalId("bt10_copy");
assertNotNull(bt10_copy);
// present - another value
assertNotNull(bt10_copy.getOwnParameter("a_pwd"));
assertEquals("secret2", parameterFactory.getRawValue(bt10_copy.getOwnParameter("a_pwd")));
bt10_copy.remove();
// reset params
buildType.setParameters(buildType.getParameters());
}
}
use of jetbrains.buildServer.serverSide.parameters.ParameterFactory in project teamcity-rest by JetBrains.
the class BuildTypeUtil method changeParameterType.
public static void changeParameterType(final String parameterName, @Nullable final String newRawTypeValue, @NotNull final EntityWithModifiableParameters parametrizedEntity, @NotNull final ServiceLocator serviceLocator) {
if (StringUtil.isEmpty(parameterName)) {
throw new BadRequestException("Parameter name cannot be empty.");
}
Parameter parameter = parametrizedEntity.getParameter(parameterName);
if (parameter == null) {
throw new NotFoundException("Parameter with name '" + parameterName + "' not found");
}
final ParameterFactory parameterFactory = getParameterFactory(serviceLocator);
final String newValue = parameterFactory.isSecureParameter(parameter.getControlDescription()) ? "" : parameter.getValue();
if (newRawTypeValue != null) {
parametrizedEntity.addParameter(parameterFactory.createTypedParameter(parameterName, newValue, newRawTypeValue));
} else {
parametrizedEntity.addParameter(parameterFactory.createSimpleParameter(parameterName, newValue));
}
}
use of jetbrains.buildServer.serverSide.parameters.ParameterFactory in project teamcity-rest by JetBrains.
the class Property method getFromPosted.
@NotNull
public Parameter getFromPosted(@NotNull final ServiceLocator serviceLocator) {
isValid();
final ParameterFactory parameterFactory = serviceLocator.getSingletonService(ParameterFactory.class);
if (type == null || type.rawValue == null) {
return parameterFactory.createSimpleParameter(name, value);
}
// workaround for https://youtrack.jetbrains.com/issue/TW-41041
final ParameterDescriptionFactory parameterDescriptionFactory = serviceLocator.getSingletonService(jetbrains.buildServer.serverSide.parameters.ParameterDescriptionFactory.class);
try {
parameterDescriptionFactory.parseDescription(type.rawValue);
} catch (ParseException e) {
throw new BadRequestException("Wrong parameter type \"" + type.rawValue + "\" provided: " + e.getMessage());
}
return parameterFactory.createTypedParameter(name, value, type.rawValue);
}
use of jetbrains.buildServer.serverSide.parameters.ParameterFactory in project teamcity-rest by JetBrains.
the class BuildTypeRequestTest method testPasswordParams.
@Test
public void testPasswordParams() {
// see also alike setup in BuildTypeTest.testInheritance()
ProjectEx project10 = createProject("project10", "project 10");
final ParameterFactory parameterFactory = myFixture.getSingletonService(ParameterFactory.class);
project10.addParameter(parameterFactory.createTypedParameter("a_pwd", "secret", "password"));
project10.addParameter(new SimpleParameter("b_normal", "value"));
BuildTypeEx bt10 = project10.createBuildType("bt10", "bt 10");
// get buildType
BuildType buildType = new BuildType(new BuildTypeOrTemplate(bt10), new Fields("$long"), getBeanContext(myServer));
assertNull(buildType.getParameters().properties.get(0).value);
project10.addParameter(parameterFactory.createTypedParameter("a_pwd", "", "password"));
assertEquals("", buildType.getParameters().properties.get(0).value);
}
Aggregations