Search in sources :

Example 11 with Requirement

use of jetbrains.buildServer.requirements.Requirement in project teamcity-powershell by JetBrains.

the class PowerShellRunTypeTest method shouldUseInternalValueAsPArtOfRequirement.

@Test(dataProvider = "bitnessProvider")
public void shouldUseInternalValueAsPArtOfRequirement(@NotNull final PowerShellBitness bit) {
    final Collection<Requirement> requirements = runType.getRunnerSpecificRequirements(createDummyParameters(bit));
    assertEquals(1, requirements.size());
    final Requirement req = requirements.iterator().next();
    assertEquals("Exists=>(powershell_Core_" + bit.getValue() + "|powershell_Desktop_" + bit.getValue() + ")", req.getPropertyName());
}
Also used : Requirement(jetbrains.buildServer.requirements.Requirement) Test(org.testng.annotations.Test)

Example 12 with Requirement

use of jetbrains.buildServer.requirements.Requirement in project teamcity-powershell by JetBrains.

the class PowerShellRunTypeTest method shouldProviderSemanticVersionRestriction.

@Test(dataProvider = "bitnessAndVersionProvider")
@TestFor(issues = "TW-33570")
public void shouldProviderSemanticVersionRestriction(@NotNull final PowerShellBitness bitness, @Nullable final String version) {
    final Map<String, String> parameters = createDummyParameters(bitness);
    if (version != null) {
        parameters.put(PowerShellConstants.RUNNER_MIN_VERSION, version);
    }
    final Collection<Requirement> requirements = runType.getRunnerSpecificRequirements(parameters);
    assertEquals(1, requirements.size());
    final Requirement req = requirements.iterator().next();
    assertEquals("Exists=>(powershell_Core_" + bitness.getValue() + "|powershell_Desktop_" + bitness.getValue() + ")", req.getPropertyName());
    if (version == null) {
        assertEquals(RequirementType.EXISTS, req.getType());
    } else {
        assertEquals(RequirementType.VER_NO_LESS_THAN, req.getType());
        assertEquals(version, req.getPropertyValue());
    }
}
Also used : Requirement(jetbrains.buildServer.requirements.Requirement) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Example 13 with Requirement

use of jetbrains.buildServer.requirements.Requirement in project teamcity-powershell by JetBrains.

the class PowerShellRunTypeTest method testSingleMatchingRequirement.

/**
 * Tests we provide single property requirement without {@code Exists} qualifier in case of fixed bitness and edition
 */
@Test(dataProvider = "versionProvider")
public void testSingleMatchingRequirement(@Nullable final String version) {
    for (PowerShellBitness bitness : PowerShellBitness.values()) {
        for (PowerShellEdition edition : PowerShellEdition.values()) {
            final Map<String, String> parameters = createDummyParameters(bitness);
            if (version != null) {
                parameters.put(PowerShellConstants.RUNNER_MIN_VERSION, version);
            }
            parameters.put(PowerShellConstants.RUNNER_EDITION, edition.getValue());
            final Collection<Requirement> requirements = runType.getRunnerSpecificRequirements(parameters);
            assertEquals(1, requirements.size());
            final Requirement req = requirements.iterator().next();
            assertEquals("powershell_" + edition.getValue() + "_" + bitness.getValue(), req.getPropertyName());
            if (version == null) {
                assertEquals(RequirementType.EXISTS, req.getType());
            } else {
                assertEquals(RequirementType.VER_NO_LESS_THAN, req.getType());
                assertEquals(version, req.getPropertyValue());
            }
        }
    }
}
Also used : Requirement(jetbrains.buildServer.requirements.Requirement) Test(org.testng.annotations.Test)

Example 14 with Requirement

use of jetbrains.buildServer.requirements.Requirement in project teamcity-powershell by JetBrains.

the class PowerShellRunTypeTest method testAnyBitnessSpecificEdition.

@Test(dataProvider = "editionProvider")
public void testAnyBitnessSpecificEdition(@NotNull final PowerShellEdition edition) {
    final Map<String, String> input = createDummyParameters(null);
    input.put(PowerShellConstants.RUNNER_EDITION, edition.getValue());
    final Collection<Requirement> requirements = runType.getRunnerSpecificRequirements(input);
    assertEquals(1, requirements.size());
    final Requirement r = requirements.iterator().next();
    assertEquals("Exists=>(powershell_" + edition.getValue() + "_x86|powershell_" + edition.getValue() + "_x64)", r.getPropertyName());
    assertEquals(RequirementType.EXISTS, r.getType());
}
Also used : Requirement(jetbrains.buildServer.requirements.Requirement) Test(org.testng.annotations.Test)

Example 15 with Requirement

use of jetbrains.buildServer.requirements.Requirement in project teamcity-powershell by JetBrains.

the class PowerShellRunType method getRunnerSpecificRequirements.

@NotNull
@Override
public List<Requirement> getRunnerSpecificRequirements(@NotNull final Map<String, String> runParameters) {
    final List<Requirement> result = new ArrayList<>();
    final String minVersion = getMinimalVersion(runParameters);
    final PowerShellBitness bit = getBitness(runParameters);
    final PowerShellEdition edition = getEdition(runParameters);
    // filter editions
    final List<PowerShellEdition> editions = new ArrayList<>();
    if (edition == null) {
        // for all editions
        editions.addAll(Arrays.asList(PowerShellEdition.values()));
    } else {
        editions.add(edition);
    }
    final List<PowerShellBitness> bits = new ArrayList<>();
    if (bit == null) {
        bits.addAll(Arrays.asList(PowerShellBitness.values()));
    } else {
        bits.add(bit);
    }
    List<String> keys = new ArrayList<>();
    for (PowerShellEdition e : editions) {
        for (PowerShellBitness b : bits) {
            keys.add(generateGeneralKey(e, b));
        }
    }
    if (minVersion == null) {
        // EXISTS requirement type, as we have no specific version set
        result.add(new Requirement(getRequirementPropertyName(keys), null, RequirementType.EXISTS));
    } else {
        // VER_NO_LESS_THAN requirement type, as minimal version is set
        result.add(new Requirement(getRequirementPropertyName(keys), minVersion, RequirementType.VER_NO_LESS_THAN));
    }
    return result;
}
Also used : Requirement(jetbrains.buildServer.requirements.Requirement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Requirement (jetbrains.buildServer.requirements.Requirement)19 Test (org.testng.annotations.Test)10 ApiOperation (io.swagger.annotations.ApiOperation)6 BuildTypeOrTemplate (jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate)6 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)5 TestFor (jetbrains.buildServer.util.TestFor)3 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)2 NotNull (org.jetbrains.annotations.NotNull)2 ServiceLocator (jetbrains.buildServer.ServiceLocator)1 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)1 OperationException (jetbrains.buildServer.server.rest.errors.OperationException)1 Build (jetbrains.buildServer.server.rest.model.build.Build)1 RequirementFactory (jetbrains.buildServer.serverSide.RequirementFactory)1 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)1 SUser (jetbrains.buildServer.users.SUser)1