Search in sources :

Example 1 with ParameterDescriptionFactory

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

use of jetbrains.buildServer.serverSide.parameters.ParameterDescriptionFactory 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)

Aggregations

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