Search in sources :

Example 1 with BeanContext

use of jetbrains.buildServer.server.rest.util.BeanContext 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 2 with BeanContext

use of jetbrains.buildServer.server.rest.util.BeanContext 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)

Example 3 with BeanContext

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

the class BaseFinderTest method getBeanContext.

public static BeanContext getBeanContext(final ServiceLocator serviceLocator) {
    final ApiUrlBuilder apiUrlBuilder = new ApiUrlBuilder(path -> path);
    final BeanFactory beanFactory = new BeanFactory(null);
    return new BeanContext(beanFactory, serviceLocator, apiUrlBuilder);
}
Also used : BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) ApiUrlBuilder(jetbrains.buildServer.server.rest.ApiUrlBuilder) BeanFactory(jetbrains.buildServer.server.rest.util.BeanFactory)

Example 4 with BeanContext

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

the class TestOccurrenceRequestTest method testWontFetchItemsWhenNotNeededWithExplicitFieldsValue.

@Test
public void testWontFetchItemsWhenNotNeededWithExplicitFieldsValue() {
    BeanContext ctx = BaseFinderTest.getBeanContext(myFixture);
    myRequest.initForTests(ctx.getServiceLocator(), new TestOccurrenceFinderDenyingItemsFetch(), ctx.getApiUrlBuilder(), ctx);
    final SFinishedBuild build = build().in(myBuildType).withTest(BuildBuilder.TestData.test("aaa").duration(76)).finish();
    FakeHttpServletRequest mockRequest = new FakeHttpServletRequest();
    mockRequest.setRequestURL("http://test/httpAuth/app/rest/testOccurrences?locator=build:" + build.getBuildId() + "&fields=id,count,failed,testCounters(all,success)");
    TestOccurrences testOccurrences = myRequest.getTestOccurrences("build:" + build.getBuildId(), "", null, mockRequest);
    assertEquals(new Integer(1), testOccurrences.getCount());
}
Also used : BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) SFinishedBuild(jetbrains.buildServer.serverSide.SFinishedBuild) FakeHttpServletRequest(jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest) TestOccurrences(jetbrains.buildServer.server.rest.model.problem.TestOccurrences) Test(org.testng.annotations.Test)

Example 5 with BeanContext

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

the class RootApiRequest method serveBuildFieldShort.

@GET
@ApiOperation(value = "serveBuildFieldShort", hidden = true)
@Path("/{projectLocator}/{btLocator}/{buildLocator}/{field}")
@Produces("text/plain")
public String serveBuildFieldShort(@PathParam("projectLocator") String projectLocator, @PathParam("btLocator") String buildTypeLocator, @PathParam("buildLocator") String buildLocator, @PathParam("field") String field) {
    SProject project = myProjectFinder.getItem(projectLocator);
    SBuildType buildType = myBuildTypeFinder.getBuildType(project, buildTypeLocator, false);
    final BuildPromotion buildPromotion = myBuildFinder.getBuildPromotion(buildType, buildLocator);
    return Build.getFieldValue(buildPromotion, field, new BeanContext(myDataProvider.getBeanFactory(), myDataProvider.getServer(), myApiUrlBuilder));
}
Also used : BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) BuildPromotion(jetbrains.buildServer.serverSide.BuildPromotion) SBuildType(jetbrains.buildServer.serverSide.SBuildType) SProject(jetbrains.buildServer.serverSide.SProject) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

BeanContext (jetbrains.buildServer.server.rest.util.BeanContext)21 ApiOperation (io.swagger.annotations.ApiOperation)12 BuildTypeOrTemplate (jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate)10 SArtifactDependency (jetbrains.buildServer.serverSide.artifacts.SArtifactDependency)6 BeanFactory (jetbrains.buildServer.server.rest.util.BeanFactory)5 ApiUrlBuilder (jetbrains.buildServer.server.rest.ApiUrlBuilder)4 Test (org.testng.annotations.Test)4 PathTransformer (jetbrains.buildServer.server.rest.PathTransformer)3 Dependency (jetbrains.buildServer.serverSide.dependency.Dependency)3 File (java.io.File)2 FakeHttpServletRequest (jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest)2 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)2 Build (jetbrains.buildServer.server.rest.model.build.Build)2 TestOccurrences (jetbrains.buildServer.server.rest.model.problem.TestOccurrences)2 TestFor (jetbrains.buildServer.util.TestFor)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 Logger (com.intellij.openapi.diagnostic.Logger)1 ApiModelProperty (io.swagger.annotations.ApiModelProperty)1 Collections (java.util.Collections)1 List (java.util.List)1