use of org.gradle.testkit.runner.BuildResult in project spring-boot by spring-projects.
the class PaketoBuilderTests method plainDistZipJarApp.
@Test
void plainDistZipJarApp() throws Exception {
writeMainClass();
String projectName = this.gradleBuild.getProjectDir().getName();
String imageName = "paketo-integration/" + projectName;
ImageReference imageReference = ImageReference.of(ImageName.of(imageName));
BuildResult result = buildImage(imageName, "assemble", "bootDistZip");
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
try (GenericContainer<?> container = new GenericContainer<>(imageName).withExposedPorts(8080)) {
container.waitingFor(Wait.forHttp("/test")).start();
ContainerConfig config = container.getContainerInfo().getConfig();
ImageAssertions.assertThat(config).buildMetadata((metadata) -> {
metadata.buildpacks().contains("paketo-buildpacks/ca-certificates", "paketo-buildpacks/bellsoft-liberica", "paketo-buildpacks/dist-zip", "paketo-buildpacks/spring-boot");
metadata.processOfType("web").extracting("command", "args").containsExactly("/workspace/" + projectName + "/bin/" + projectName, Collections.emptyList());
metadata.processOfType("dist-zip").extracting("command", "args").containsExactly("/workspace/" + projectName + "/bin/" + projectName, Collections.emptyList());
});
assertImageHasSbomLayer(imageReference, config, "dist-zip");
DigestCapturingCondition digest = new DigestCapturingCondition();
ImageAssertions.assertThat(config).lifecycleMetadata((metadata) -> metadata.appLayerShas().haveExactly(1, digest));
ImageAssertions.assertThat(imageReference).layer(digest.getDigest(), (layer) -> layer.entries().contains(projectName + "/bin/" + projectName, projectName + "/lib/" + projectName + "-plain.jar").anyMatch((s) -> s.startsWith(projectName + "/lib/spring-boot-")).anyMatch((s) -> s.startsWith(projectName + "/lib/spring-core-")).anyMatch((s) -> s.startsWith(projectName + "/lib/spring-web-")));
} finally {
removeImage(imageReference);
}
}
use of org.gradle.testkit.runner.BuildResult in project spring-boot by spring-projects.
the class PaketoBuilderTests method executableJarAppWithAdditionalArgs.
@Test
void executableJarAppWithAdditionalArgs() throws Exception {
writeMainClass();
String imageName = "paketo-integration/" + this.gradleBuild.getProjectDir().getName();
ImageReference imageReference = ImageReference.of(ImageName.of(imageName));
BuildResult result = buildImage(imageName);
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
try (GenericContainer<?> container = new GenericContainer<>(imageName).withCommand("--server.port=9090").withExposedPorts(9090)) {
container.waitingFor(Wait.forHttp("/test")).start();
} finally {
removeImage(imageReference);
}
}
use of org.gradle.testkit.runner.BuildResult in project crate by crate.
the class JdkDownloadPluginFunctionalTest method runBuild.
private static void runBuild(String task, Consumer<BuildResult> assertions, String os, String arch, String vendor, String version) {
var testKitDirPath = Paths.get(System.getProperty("user.dir"), "build", System.getProperty("user.name"));
WireMockServer wireMock = new WireMockServer(0);
try {
wireMock.stubFor(head(urlEqualTo(urlPath(vendor, version, os, arch))).willReturn(aResponse().withStatus(200)));
wireMock.stubFor(get(urlEqualTo(urlPath(vendor, version, os, arch))).willReturn(aResponse().withStatus(200).withBody(filebytes(vendor, version, os, arch))));
wireMock.start();
GradleRunner runner = GradleRunner.create().withDebug(true).withProjectDir(getTestKitProjectDir("jdk-download")).withTestKitDir(testKitDirPath.toFile()).withArguments(task, "-Dtests.jdk_vendor=" + vendor, "-Dtests.jdk_version=" + version, "-Dtests.jdk_repo=" + wireMock.baseUrl(), "-i").withPluginClasspath();
BuildResult result = runner.build();
assertions.accept(result);
} catch (IOException e) {
fail("cannot get artifacts from resources: " + e.getLocalizedMessage());
} finally {
wireMock.stop();
}
}
use of org.gradle.testkit.runner.BuildResult in project swagger-core by swagger-api.
the class SwaggerResolveTest method testSwaggerResolveTask.
@Test
public void testSwaggerResolveTask() throws IOException {
outputDir = testProjectDir.getRoot().toString() + "/target";
outputFile = testProjectDir.getRoot().toString() + "/testAPI.json";
// outputDir = "/tmp/a/target";
String resolveTask = "resolve";
String buildFileContent = "plugins {\n" + " id 'java'\n" + " id 'io.swagger.core.v3.swagger-gradle-plugin'\n" + "}\n" + "sourceSets {\n" + " test {\n" + " java {\n" + " srcDirs('" + toNormalizedPath(new File("src/test/java").getAbsolutePath()) + "')\n" + " exclude('**/*Test.java')\n" + " }\n" + " }\n" + "}\n" + "repositories {\n" + " mavenLocal()\n" + " mavenCentral()\n" + "}\n" + "dependencies { \n" + " compile group: 'io.swagger.core.v3', name: 'swagger-jaxrs2', version:'2.2.0-SNAPSHOT'\n" + " compile group: 'javax.ws.rs', name: 'javax.ws.rs-api', version:'2.1'\n" + " compile group: 'javax.servlet', name: 'javax.servlet-api', version:'3.1.0'\n" + " testCompile group: 'com.github.tomakehurst', name: 'wiremock', version:'2.27.2'\n" + " testCompile 'junit:junit:4+'\n" + "\n" + "\n" + "}\n" + resolveTask + " {\n" + " outputFileName = 'PetStoreAPI'\n" + " outputFormat = 'JSON'\n" + " prettyPrint = 'TRUE'\n" + // " classpath = compileTestJava.outputs.files\n" +
" classpath = sourceSets.test.runtimeClasspath\n" + " resourcePackages = ['io.swagger.v3.plugins.gradle.petstore']\n" + " outputPath = \'" + toNormalizedPath(outputDir) + "\'\n" + " filterClass = \'io.swagger.v3.plugins.gradle.resources.MyFilter\'\n" + " openApiFile = file(\'" + toNormalizedPath(openapiInputFile.getAbsolutePath()) + "\')\n" + "}";
String settingsFileContent = "pluginManagement {\n" + " repositories {\n" + " maven {\n" + " url mavenLocal().url\n" + " }\n" + " mavenCentral()\n" + " gradlePluginPortal()\n" + " }\n" + "}\n" + "rootProject.name = 'gradle-test'\n" + "\n";
writeFile(buildFile, buildFileContent);
writeFile(settingsFile, settingsFileContent);
BuildResult result = GradleRunner.create().withPluginClasspath().withProjectDir(testProjectDir.getRoot()).withDebug(true).withArguments(resolveTask, "--stacktrace", "--info").forwardOutput().build();
assertThat(result.taskPaths(SUCCESS), hasItem(format(":%s", resolveTask)));
assertThat(new File(outputDir + "/PetStoreAPI.json").exists(), is(true));
assertThat(new String(Files.readAllBytes(Paths.get(outputDir, "PetStoreAPI.json")), StandardCharsets.UTF_8), containsString("UPDATEDBYFILTER"));
}
use of org.gradle.testkit.runner.BuildResult in project gradle by gradle.
the class GreetingPluginFunctionalTest method canRunTask.
@Test
public void canRunTask() throws IOException {
// Setup the test build
File projectDir = new File("build/functionalTest");
Files.createDirectories(projectDir.toPath());
writeString(new File(projectDir, "settings.gradle"), "");
writeString(new File(projectDir, "build.gradle"), "plugins {" + " id('com.example.plugin.greeting')" + "}");
// Run the build
BuildResult result = GradleRunner.create().forwardOutput().withPluginClasspath().withArguments("greet").withProjectDir(projectDir).build();
// Verify the result
assertTrue(result.getOutput().contains("Hello from plugin 'com.example.plugin.greeting'"));
}
Aggregations