Search in sources :

Example 1 with ParameterFactory

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");
    }
    */
}
Also used : ParameterFactory(jetbrains.buildServer.serverSide.parameters.ParameterFactory) ParameterDescriptionFactory(jetbrains.buildServer.serverSide.parameters.ParameterDescriptionFactory) BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 2 with ParameterFactory

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());
    }
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) ParameterFactory(jetbrains.buildServer.serverSide.parameters.ParameterFactory) BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 3 with ParameterFactory

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));
    }
}
Also used : ParameterFactory(jetbrains.buildServer.serverSide.parameters.ParameterFactory) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException)

Example 4 with ParameterFactory

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);
}
Also used : ParameterFactory(jetbrains.buildServer.serverSide.parameters.ParameterFactory) ParameterDescriptionFactory(jetbrains.buildServer.serverSide.parameters.ParameterDescriptionFactory) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) ParseException(java.text.ParseException) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with ParameterFactory

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);
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) ParameterFactory(jetbrains.buildServer.serverSide.parameters.ParameterFactory) BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Aggregations

ParameterFactory (jetbrains.buildServer.serverSide.parameters.ParameterFactory)5 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)3 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)3 Test (org.testng.annotations.Test)3 BuildTypeOrTemplate (jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate)2 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)2 ProjectEx (jetbrains.buildServer.serverSide.impl.ProjectEx)2 ParameterDescriptionFactory (jetbrains.buildServer.serverSide.parameters.ParameterDescriptionFactory)2 ParseException (java.text.ParseException)1 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)1 NotNull (org.jetbrains.annotations.NotNull)1