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