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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations