Search in sources :

Example 1 with Build

use of jetbrains.buildServer.server.rest.model.build.Build in project teamcity-rest by JetBrains.

the class BuildTest method testBuildOnAgentTriggering.

@Test
public void testBuildOnAgentTriggering() {
    myFixture.addService(new AgentRestrictorFactoryImpl());
    final MockBuildAgent agent2 = myFixture.createEnabledAgent("agent2", "Ant");
    final Build build = new Build();
    final BuildType buildType = new BuildType();
    buildType.setId(myBuildType.getExternalId());
    build.setBuildType(buildType);
    final Agent submittedAgent = new Agent();
    submittedAgent.id = agent2.getId();
    build.setAgent(submittedAgent);
    final SUser triggeringUser = getOrCreateUser("user");
    final SQueuedBuild queuedBuild = build.triggerBuild(triggeringUser, myFixture, new HashMap<Long, Long>());
    assertEquals(Integer.valueOf(agent2.getId()), queuedBuild.getBuildAgentId());
}
Also used : Agent(jetbrains.buildServer.server.rest.model.agent.Agent) Build(jetbrains.buildServer.server.rest.model.build.Build) SUser(jetbrains.buildServer.users.SUser) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 2 with Build

use of jetbrains.buildServer.server.rest.model.build.Build 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 3 with Build

use of jetbrains.buildServer.server.rest.model.build.Build 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 4 with Build

use of jetbrains.buildServer.server.rest.model.build.Build 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 5 with Build

use of jetbrains.buildServer.server.rest.model.build.Build in project teamcity-rest by JetBrains.

the class BuildTest method testBuildTriggering1.

@Test
public void testBuildTriggering1() {
    final Build build = new Build();
    final BuildType buildType = new BuildType();
    buildType.setId(myBuildType.getExternalId());
    build.setBuildType(buildType);
    final SUser triggeringUser = getOrCreateUser("user");
    final SQueuedBuild queuedBuild = build.triggerBuild(triggeringUser, myFixture, new HashMap<Long, Long>());
    assertEquals(myBuildType, queuedBuild.getBuildPromotion().getBuildType());
}
Also used : Build(jetbrains.buildServer.server.rest.model.build.Build) SUser(jetbrains.buildServer.users.SUser) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Aggregations

Build (jetbrains.buildServer.server.rest.model.build.Build)33 Test (org.testng.annotations.Test)24 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)23 SUser (jetbrains.buildServer.users.SUser)22 ServiceLocator (jetbrains.buildServer.ServiceLocator)6 Agent (jetbrains.buildServer.server.rest.model.agent.Agent)6 ApiOperation (io.swagger.annotations.ApiOperation)5 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)5 jetbrains.buildServer.serverSide (jetbrains.buildServer.serverSide)5 Logger (com.intellij.openapi.diagnostic.Logger)4 java.util (java.util)4 Pattern (java.util.regex.Pattern)4 Collectors (java.util.stream.Collectors)4 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)4 LocatorProcessException (jetbrains.buildServer.server.rest.errors.LocatorProcessException)4 LocatorName (jetbrains.buildServer.server.rest.swagger.constants.LocatorName)4 SArtifactDependency (jetbrains.buildServer.serverSide.artifacts.SArtifactDependency)4 Permission (jetbrains.buildServer.serverSide.auth.Permission)4 CollectionsUtil (jetbrains.buildServer.util.CollectionsUtil)4 TestFor (jetbrains.buildServer.util.TestFor)4