Search in sources :

Example 11 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-powershell by JetBrains.

the class PowerShellRunTypeTest method testGenerateAnyBitnessRequirement_WithMinVersion.

@Test(dataProvider = "versionProvider")
@TestFor(issues = "TW-44808")
public void testGenerateAnyBitnessRequirement_WithMinVersion(@Nullable final String version) {
    final Map<String, String> input = createDummyParameters(null);
    if (version != null) {
        input.put(PowerShellConstants.RUNNER_MIN_VERSION, version);
    }
    final Collection<Requirement> requirements = runType.getRunnerSpecificRequirements(input);
    assertEquals(1, requirements.size());
    final Requirement r = requirements.iterator().next();
    assertEquals("Exists=>(powershell_Core_x86|powershell_Core_x64|powershell_Desktop_x86|powershell_Desktop_x64)", r.getPropertyName());
    assertEquals(version, r.getPropertyValue());
    if (version != null) {
        assertEquals(RequirementType.VER_NO_LESS_THAN, r.getType());
    }
}
Also used : Requirement(jetbrains.buildServer.requirements.Requirement) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Example 12 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-rest by JetBrains.

the class BuildTest method testBuildEstimates.

@Test
@TestFor(issues = "TW-50824")
public void testBuildEstimates() throws Exception {
    BuildTypeImpl bt1 = registerBuildType("buildType1", "projectName");
    // ~setting build estimate to 10 minutes
    Date tenMinutesAgo = Date.from(Instant.now().minus(10, ChronoUnit.MINUTES));
    createBuildWithBuildDurationStatistic(bt1, Status.NORMAL, tenMinutesAgo, tenMinutesAgo, myBuildAgent);
    build().in(bt1).addToQueue();
    build().in(bt1).parameter("a", "prevent merging").addToQueue();
    BuildTypeImpl bt2 = registerBuildType("buildType2", "projectName");
    bt2.addRequirement(myFixture.getSingletonService(RequirementFactory.class).createRequirement("missing", "some", RequirementType.EQUALS));
    build().in(bt2).addToQueue();
    myFixture.getSingletonService(CachingBuildEstimator.class).invalidate(true);
    TimeInterval timeInterval = myServer.getQueue().getItems().get(1).getBuildEstimates().getTimeInterval();
    long diff = timeInterval.getStartPoint().getAbsoluteTime().getTime() - Date.from(Instant.now().plus(10, ChronoUnit.MINUTES)).getTime();
    assertTrue(timeInterval.getStartPoint().getAbsoluteTime().toString() + " -- " + Dates.now().toString() + ", diff: " + diff, diff < 60000);
    Build build1 = new Build(myServer.getQueue().getItems().get(1).getBuildPromotion(), Fields.LONG, getBeanContext(myFixture));
    assertEquals(Util.formatTime(myServer.getQueue().getItems().get(1).getBuildEstimates().getTimeInterval().getStartPoint().getAbsoluteTime()), build1.getStartEstimate());
    assertEquals(Util.formatTime(myServer.getQueue().getItems().get(1).getBuildEstimates().getTimeInterval().getEndPoint().getAbsoluteTime()), build1.getFinishEstimate());
    build1 = new Build(myServer.getQueue().getItems().get(2).getBuildPromotion(), Fields.LONG, getBeanContext(myFixture));
    assertNull(build1.getStartEstimate());
}
Also used : CachingBuildEstimator(jetbrains.buildServer.serverSide.impl.timeEstimation.CachingBuildEstimator) Build(jetbrains.buildServer.server.rest.model.build.Build) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest) TestFor(jetbrains.buildServer.util.TestFor)

Example 13 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-rest by JetBrains.

the class BuildTest method testBuildArtifactsHrefWithSpecialSymbols.

@SuppressWarnings("ResultOfMethodCallIgnored")
@Test
@TestFor(issues = "TW-27205")
public void testBuildArtifactsHrefWithSpecialSymbols() throws IOException {
    SFinishedBuild finishedBuild = build().in(myBuildType).finish();
    final File artifactsDir = finishedBuild.getArtifactsDirectory();
    artifactsDir.mkdirs();
    String specialCharacters = "~!@#$%^&()_+=-`][{}'; .,\u044B%61";
    File dir = new File(artifactsDir, specialCharacters);
    dir.mkdirs();
    File file = new File(dir, specialCharacters);
    file.createNewFile();
    final ApiUrlBuilder apiUrlBuilder = new ApiUrlBuilder(new PathTransformer() {

        public String transform(final String path) {
            return StringUtil.replace(path, "/app/rest/", "/app/rest/version/");
        }
    });
    final Build build = new Build(finishedBuild, new Fields("href,artifacts($locator(recursive:true),href,file(name,fullName,href,children($long,$locator(pattern(+:**,+:%))),content))"), new BeanContext(new BeanFactory(null), myFixture, apiUrlBuilder));
    assertEquals("/app/rest/version/builds/id:1", build.getHref());
    // noinspection ConstantConditions
    jetbrains.buildServer.server.rest.model.files.File artifact1 = build.getArtifacts().files.get(0);
    jetbrains.buildServer.server.rest.model.files.File artifact2 = build.getArtifacts().files.get(1);
    String specialCharacters_escaped;
    if (!specialCharacters.equals(artifact1.name)) {
        System.out.println("File system does not seem to support some characters. Was creating file \"" + specialCharacters + "\" but got \"" + artifact1.name + "\"");
        specialCharacters_escaped = WebUtil.encode(artifact1.name);
    } else {
        specialCharacters_escaped = WebUtil.encode(specialCharacters);
        assertEquals(specialCharacters, artifact2.name);
        assertEquals(specialCharacters + "/" + specialCharacters, artifact2.fullName);
    }
    assertEquals("/app/rest/version/builds/id:1/artifacts/metadata/" + specialCharacters_escaped, artifact1.href);
    // noinspection ConstantConditions
    assertEquals("/app/rest/version/builds/id:1/artifacts/children/" + specialCharacters_escaped + "?locator=pattern(%2B:**,%2B:%25)", artifact1.getChildren().href);
    assertEquals("/app/rest/version/builds/id:1/artifacts/metadata/" + specialCharacters_escaped + "/" + specialCharacters_escaped, artifact2.href);
    // noinspection ConstantConditions
    assertEquals("/app/rest/version/builds/id:1/artifacts/content/" + specialCharacters_escaped + "/" + specialCharacters_escaped, artifact2.getContent().href);
}
Also used : ApiUrlBuilder(jetbrains.buildServer.server.rest.ApiUrlBuilder) PathTransformer(jetbrains.buildServer.server.rest.PathTransformer) BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) Build(jetbrains.buildServer.server.rest.model.build.Build) BeanFactory(jetbrains.buildServer.server.rest.util.BeanFactory) File(java.io.File) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest) TestFor(jetbrains.buildServer.util.TestFor)

Example 14 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-rest by JetBrains.

the class BuildTest method testDownloadedArtifacts.

@Test
@TestFor(issues = "TW-21036")
public void testDownloadedArtifacts() {
    DownloadedArtifactsLoggerImpl artifactsLogger = myFixture.getSingletonService(DownloadedArtifactsLoggerImpl.class);
    SBuildType bt1 = registerBuildType("bt1", "project1", "Ant");
    SBuild build1 = createBuild(bt1, Status.NORMAL);
    SBuildType bt2 = registerBuildType("bt2", "project2", "Ant");
    SBuild build2 = createBuild(bt2, Status.NORMAL);
    artifactsLogger.logArtifactDownload(build2.getBuildId(), build1.getBuildId(), "path1");
    artifactsLogger.waitForQueuePersisting();
    Build build2model = new Build(build2, Fields.ALL_NESTED, getBeanContext(myFixture));
    jetbrains.buildServer.server.rest.model.build.downloadedArtifacts.DownloadedArtifacts build2Artifacts = build2model.getDownloadedArtifacts();
    assertEquals("There is 1 build as a source of artifacts", 1, (int) build2Artifacts.getUnfilteredCount());
    assertEquals("There is 1 build as a source of artifacts", 1, (int) build2Artifacts.getCount());
    assertEquals("There is 1 build as a source of artifacts", 1, build2Artifacts.getDownloadInfo().size());
    BuildArtifactsDownloadInfo build2downloadInfo = build2Artifacts.getDownloadInfo().get(0);
    assertEquals("There is 1 downloaded artifact", 1, (int) build2downloadInfo.getCount());
    assertEquals("Build(" + build2.getBuildId() + ") downloaded artifact from build(" + build1.getBuildId() + ")", build1.getBuildId(), (long) build2downloadInfo.getBuild().getId());
    DownloadedArtifacts realDownloaded = build2.getDownloadedArtifacts();
    ArtifactDownloadInfo artifactInfo = build2downloadInfo.getArtifactInfo().get(0);
    assertEquals("path1", artifactInfo.getArtifactPath());
    assertEquals(Util.formatTime(realDownloaded.getArtifacts().get(build1).get(0).getDownloadTimestamp()), artifactInfo.getDownloadTimestamp());
}
Also used : Build(jetbrains.buildServer.server.rest.model.build.Build) BuildArtifactsDownloadInfo(jetbrains.buildServer.server.rest.model.build.downloadedArtifacts.BuildArtifactsDownloadInfo) ArtifactDownloadInfo(jetbrains.buildServer.server.rest.model.build.downloadedArtifacts.ArtifactDownloadInfo) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest) TestFor(jetbrains.buildServer.util.TestFor)

Example 15 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-rest by JetBrains.

the class BuildTest method testBuildArtifactsHrefForVersionedUrls.

@Test
@TestFor(issues = "TW-51092")
public void testBuildArtifactsHrefForVersionedUrls() throws IOException {
    SFinishedBuild finishedBuild = build().in(myBuildType).finish();
    final File artifactsDir = finishedBuild.getArtifactsDirectory();
    // noinspection ResultOfMethodCallIgnored
    artifactsDir.mkdirs();
    File dir = new File(artifactsDir, "dir");
    // noinspection ResultOfMethodCallIgnored
    dir.mkdirs();
    File file = new File(artifactsDir, "file.txt");
    // noinspection ResultOfMethodCallIgnored
    file.createNewFile();
    final ApiUrlBuilder apiUrlBuilder = new ApiUrlBuilder(new PathTransformer() {

        public String transform(final String path) {
            return StringUtil.replace(path, "/app/rest/", "/app/rest/version/");
        }
    });
    final Build build = new Build(finishedBuild, new Fields("href,artifacts(href,file(children,content))"), new BeanContext(new BeanFactory(null), myFixture, apiUrlBuilder));
    assertEquals("/app/rest/version/builds/id:1", build.getHref());
    assertEquals("/app/rest/version/builds/id:1/artifacts/children/", build.getArtifacts().href);
    // noinspection ConstantConditions
    assertEquals("/app/rest/version/builds/id:1/artifacts/children/dir", build.getArtifacts().files.get(0).getChildren().href);
    // noinspection ConstantConditions
    assertEquals("/app/rest/version/builds/id:1/artifacts/content/file.txt", build.getArtifacts().files.get(1).getContent().href);
}
Also used : BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) Build(jetbrains.buildServer.server.rest.model.build.Build) ApiUrlBuilder(jetbrains.buildServer.server.rest.ApiUrlBuilder) BeanFactory(jetbrains.buildServer.server.rest.util.BeanFactory) PathTransformer(jetbrains.buildServer.server.rest.PathTransformer) File(java.io.File) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest) TestFor(jetbrains.buildServer.util.TestFor)

Aggregations

TestFor (jetbrains.buildServer.util.TestFor)129 Test (org.testng.annotations.Test)81 File (java.io.File)65 GitTestUtil.dataFile (jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile)56 VcsRootImpl (jetbrains.buildServer.vcs.impl.VcsRootImpl)26 CheckoutRules (jetbrains.buildServer.vcs.CheckoutRules)21 VcsRoot (jetbrains.buildServer.vcs.VcsRoot)17 SFinishedBuild (jetbrains.buildServer.serverSide.SFinishedBuild)12 VcsException (jetbrains.buildServer.vcs.VcsException)11 URIish (org.eclipse.jgit.transport.URIish)11 Repository (org.eclipse.jgit.lib.Repository)9 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)7 AfterMethod (org.testng.annotations.AfterMethod)7 BeforeMethod (org.testng.annotations.BeforeMethod)7 Method (java.lang.reflect.Method)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 GitTestUtil.copyRepository (jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.copyRepository)6 Build (jetbrains.buildServer.server.rest.model.build.Build)6 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)6 FileUtil.writeFile (jetbrains.buildServer.util.FileUtil.writeFile)6