Search in sources :

Example 1 with BeanFactory

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

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

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

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

the class PropEntity method getFakeBeanContext.

public static BeanContext getFakeBeanContext(@NotNull final ServiceLocator serviceLocator) {
    final ApiUrlBuilder apiUrlBuilder = new ApiUrlBuilder(new PathTransformer() {

        public String transform(final String path) {
            return 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) PathTransformer(jetbrains.buildServer.server.rest.PathTransformer)

Example 5 with BeanFactory

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

the class ServerRequestTest method setUp.

@Override
@BeforeMethod
public void setUp() throws Exception {
    super.setUp();
    BeanContext ctx = BaseFinderTest.getBeanContext(myFixture);
    PermissionChecker checker = new PermissionChecker(myServer.getSecurityContext(), myProjectManager);
    myFixture.addService(checker);
    myRequest = new ServerRequest();
    myRequest.initForTests(ctx.getServiceLocator(), ctx.getApiUrlBuilder(), new BeanFactory(null), ctx, checker);
}
Also used : BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) PermissionChecker(jetbrains.buildServer.server.rest.data.PermissionChecker) BeanFactory(jetbrains.buildServer.server.rest.util.BeanFactory) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

BeanContext (jetbrains.buildServer.server.rest.util.BeanContext)5 BeanFactory (jetbrains.buildServer.server.rest.util.BeanFactory)5 ApiUrlBuilder (jetbrains.buildServer.server.rest.ApiUrlBuilder)4 PathTransformer (jetbrains.buildServer.server.rest.PathTransformer)3 File (java.io.File)2 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)2 Build (jetbrains.buildServer.server.rest.model.build.Build)2 TestFor (jetbrains.buildServer.util.TestFor)2 Test (org.testng.annotations.Test)2 PermissionChecker (jetbrains.buildServer.server.rest.data.PermissionChecker)1 BeforeMethod (org.testng.annotations.BeforeMethod)1