Search in sources :

Example 11 with BuildResult

use of org.gradle.testkit.runner.BuildResult in project spring-security by spring-projects.

the class SpringMavenPluginITest method signArchivesWhenInMemory.

@Disabled
@Test
public void signArchivesWhenInMemory() throws Exception {
    LinkedHashMap<String, String> map = new LinkedHashMap<String, String>(2);
    map.put("ORG_GRADLE_PROJECT_signingKey", getSigningKey());
    map.put("ORG_GRADLE_PROJECT_signingPassword", "password");
    BuildResult result = this.testKit.withProjectResource("samples/maven/signing").withArguments("signArchives").withEnvironment(map).forwardOutput().build();
    assertThat(result.getOutput()).contains("SUCCESS");
    final File jar = new File(testKit.getRootDir(), "build/libs/signing-1.0.0.RELEASE.jar");
    assertThat(jar).exists();
    File signature = new File(jar.getAbsolutePath() + ".asc");
    assertThat(signature).exists();
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 12 with BuildResult

use of org.gradle.testkit.runner.BuildResult in project spring-security by spring-projects.

the class ShowcaseITest method install.

@Test
@Disabled
public void install() throws Exception {
    BuildResult result = this.testKit.withProjectResource("samples/showcase/").withArguments("install", "--stacktrace").build();
    assertThat(result.getOutput()).contains("SUCCESS");
    File pom = new File(testKit.getRootDir(), "sgbcs-core/build/poms/pom-default.xml");
    assertThat(pom).exists();
    String pomText = new String(Files.readAllBytes(pom.toPath()));
    String pomTextNoSpace = pomText.replaceAll("\\s", "");
    assertThat(pomText).doesNotContain("<dependencyManagement>");
    assertThat(pomTextNoSpace).contains("<dependency>\n			<groupId>org.springframework</groupId>\n			<artifactId>spring-test</artifactId>\n			<scope>test</scope>\n			<version>4.3.6.RELEASE</version>\n		</dependency>".replaceAll("\\s", ""));
    assertThat(pomTextNoSpace).contains("<developers>\n			<developer>\n				<id>rwinch</id>\n				<name>Rob Winch</name>\n				<email>rwinch@pivotal.io</email>\n			</developer>\n			<developer>\n				<id>jgrandja</id>\n				<name>Joe Grandja</name>\n				<email>jgrandja@pivotal.io</email>\n			</developer>\n		</developers>".replaceAll("\\s", ""));
    assertThat(pomTextNoSpace).contains("<scm>\n			<connection>scm:git:git://github.com/spring-projects/spring-security</connection>\n			<developerConnection>scm:git:git://github.com/spring-projects/spring-security</developerConnection>\n			<url>https://github.com/spring-projects/spring-security</url>\n		</scm>".replaceAll("\\s", ""));
    assertThat(pomTextNoSpace).contains("<description>sgbcs-core</description>");
    assertThat(pomTextNoSpace).contains("<url>https://spring.io/spring-security</url>");
    assertThat(pomTextNoSpace).contains("<organization>\n			<name>spring.io</name>\n			<url>https://spring.io/</url>\n		</organization>".replaceAll("\\s", ""));
    assertThat(pomTextNoSpace).contains("	<licenses>\n			<license>\n				<name>The Apache Software License, Version 2.0</name>\n				<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>\n				<distribution>repo</distribution>\n			</license>\n		</licenses>".replaceAll("\\s", ""));
    assertThat(pomTextNoSpace).contains("<scm>\n			<connection>scm:git:git://github.com/spring-projects/spring-security</connection>\n			<developerConnection>scm:git:git://github.com/spring-projects/spring-security</developerConnection>\n			<url>https://github.com/spring-projects/spring-security</url>\n		</scm>".replaceAll("\\s", ""));
    File bom = new File(testKit.getRootDir(), "bom/build/poms/pom-default.xml");
    assertThat(bom).exists();
    assertThat(bom).hasContent("<artifactId>sgbcs-core</artifactId>");
    BuildResult secondBuild = this.testKit.withProjectResource("samples/showcase/").withArguments("mavenBom", "--stacktrace").build();
    // mavenBom is not up to date since install is never up to date
    assertThat(result.task(":bom:mavenBom").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) File(java.io.File) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 13 with BuildResult

use of org.gradle.testkit.runner.BuildResult in project gradle-retrolambda by evant.

the class AndroidTestPluginTest method test.

@Test
public void test() throws Exception {
    File settingsFile = testProjectDir.newFile("settings.gradle");
    writeFile(settingsFile, // language="Groovy"
    "include \":app\", \":test\"");
    File appRootDir = testProjectDir.newFolder("app");
    writeFile(new File(appRootDir, "build.gradle"), // language="Groovy"
    "buildscript {\n" + "    System.properties['com.android.build.gradle.overrideVersionCheck'] = 'true'\n" + "    \n" + "    repositories {\n" + "        maven { url 'https://maven.google.com' }\n" + "        jcenter()\n" + "    }\n" + "    \n" + "    dependencies {\n" + "        classpath files(" + getPluginClasspath() + ")\n" + "        classpath 'com.android.tools.build:gradle:" + androidVersion + "'\n" + "    }\n" + "}\n" + "\n" + "apply plugin: 'com.android.application'\n" + "apply plugin: 'me.tatarka.retrolambda'\n" + "\n" + "repositories {\n" + "    maven { url 'https://maven.google.com' }\n" + "    mavenCentral()\n" + "}\n" + "\n" + "android {\n" + "    compileSdkVersion 24\n" + "    buildToolsVersion '" + buildToolsVersion + "'\n" + "    \n" + "    defaultConfig {\n" + "        applicationId \"test.app\"\n" + "        minSdkVersion 15\n" + "        targetSdkVersion 24\n" + "    }\n" + "    \n" + "    publishNonDefault true\n" + "}");
    File appManifestFile = new File(appRootDir, "src/main/AndroidManifest.xml");
    writeFile(appManifestFile, // language="XML"
    "<manifest package=\"test.app\" " + "xmlns:android=\"http://schemas.android.com/apk/res/android\">\n" + "    <application/>\n" + "</manifest>");
    File javaFile = new File(appRootDir, "src/main/java/Main.java");
    writeFile(javaFile, "import java.util.concurrent.Callable;\n" + "\n" + "public class Main {\n" + "    public static Callable<String> f() {\n" + "        return () -> \"Hello, Lambda Test!\";\n" + "    }\n" + "}");
    File testRootDir = testProjectDir.newFolder("test");
    writeFile(new File(testRootDir, "build.gradle"), // language="Groovy"
    "buildscript {\n" + "    repositories {\n" + "        maven { url 'https://maven.google.com' }\n" + "        jcenter()\n" + "    }\n" + "    \n" + "    dependencies {\n" + "        classpath files(" + getPluginClasspath() + ")\n" + "        classpath 'com.android.tools.build:gradle:" + androidVersion + "'\n" + "    }\n" + "}\n" + "\n" + "apply plugin: 'com.android.test'\n" + "apply plugin: 'me.tatarka.retrolambda'\n" + "\n" + "repositories {\n" + "    maven { url 'https://maven.google.com' }\n" + "    mavenCentral()\n" + "}\n" + "\n" + "android {\n" + "    compileSdkVersion 23\n" + "    buildToolsVersion '" + buildToolsVersion + "'\n" + "    \n" + "    targetProjectPath ':app'\n" + "    targetVariant 'debug'\n" + "    \n" + "    defaultConfig {\n" + "        minSdkVersion 15\n" + "        targetSdkVersion 24\n" + "        testInstrumentationRunner \"android.support.test.runner.AndroidJUnitRunner\"\n" + "    }\n" + "}\n" + "\n" + "dependencies {\n" + "    compile 'com.android.support.test:runner:0.4'\n" + "    compile 'com.android.support.test:rules:0.4'\n" + "}");
    File testManifestFile = new File(testRootDir, "src/main/AndroidManifest.xml");
    writeFile(testManifestFile, // language="XML"
    "<manifest package=\"test.test\" " + "xmlns:android=\"http://schemas.android.com/apk/res/android\">\n" + "    <application/>\n" + "</manifest>");
    File testJavaFile = new File(testRootDir, "src/main/java/Test.java");
    writeFile(testJavaFile, "import org.junit.Assert;\n" + "import org.junit.runner.RunWith;\n" + "import android.support.test.runner.AndroidJUnit4;\n" + "\n" + "import java.util.concurrent.Callable;\n" + "\n" + "@RunWith(AndroidJUnit4.class)\n" + "public class Test {\n" + "    @org.junit.Test\n" + "    public void test() throws Exception {\n" + "        Runnable lambda = () -> Assert.assertTrue(true);\n" + "        lambda.run();\n" + "        Assert.assertEquals(\"Hello, Lambda Test!\", Main.f().call());\n" + "    }\n" + "}");
    StringWriter errorOutput = new StringWriter();
    BuildResult result = GradleRunner.create().withGradleVersion(gradleVersion).withProjectDir(rootDir).withArguments("connectedCheck", "--stacktrace").forwardStdError(errorOutput).build();
    assertThat(result.task(":test:connectedCheck").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) StringWriter(java.io.StringWriter) File(java.io.File) Test(org.junit.Test)

Example 14 with BuildResult

use of org.gradle.testkit.runner.BuildResult in project gradle-retrolambda by evant.

the class JavaPluginTest method test.

@Test
public void test() throws Exception {
    writeFile(buildFile, "buildscript {\n" + "    dependencies {\n" + "        classpath files(" + getPluginClasspath() + ")\n" + "    }\n" + "}\n" + "\n" + "apply plugin: 'java'\n" + "apply plugin: 'me.tatarka.retrolambda'\n" + "\n" + "repositories {\n" + "    mavenCentral()\n" + "}\n" + "\n" + "dependencies {\n" + "    testCompile 'junit:junit:4.12'\n" + "}\n" + "\n" + "test {\n" + "    testLogging { events \"failed\" }\n" + "}");
    File javaFile = new File(rootDir, "src/main/java/Main.java");
    writeFile(javaFile, "import java.util.concurrent.Callable;\n" + "\n" + "public class Main {\n" + "    public static Callable<String> f() {\n" + "        return () -> \"Hello, Lambda Test!\";\n" + "    }\n" + "}");
    File testJavaFile = new File(rootDir, "src/test/java/Test.java");
    writeFile(testJavaFile, "import org.junit.Assert;\n" + "import org.junit.runner.RunWith;\n" + "import org.junit.runners.JUnit4;\n" + "\n" + "import java.util.concurrent.Callable;\n" + "\n" + "@RunWith(JUnit4.class)\n" + "public class Test {\n" + "    @org.junit.Test\n" + "    public void test() throws Exception {\n" + "        Runnable lambda = () -> Assert.assertTrue(true);\n" + "        lambda.run();\n" + "        Assert.assertEquals(\"Hello, Lambda Test!\", Main.f().call());\n" + "    }\n" + "}");
    StringWriter errorOutput = new StringWriter();
    BuildResult result = GradleRunner.create().withGradleVersion(gradleVersion).withProjectDir(rootDir).withArguments("test", "--stacktrace").forwardStdError(errorOutput).build();
    assertThat(result.task(":test").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) StringWriter(java.io.StringWriter) TestHelpers.findFile(me.tatarka.TestHelpers.findFile) File(java.io.File) TestHelpers.writeFile(me.tatarka.TestHelpers.writeFile) Test(org.junit.Test)

Example 15 with BuildResult

use of org.gradle.testkit.runner.BuildResult in project gradle-retrolambda by evant.

the class JavaPluginTest method assemble.

@Test
public void assemble() throws Exception {
    writeFile(buildFile, "buildscript {\n" + "    dependencies {\n" + "        classpath files(" + getPluginClasspath() + ")\n" + "    }\n" + "}\n" + "\n" + "apply plugin: 'java'\n" + "apply plugin: 'me.tatarka.retrolambda'\n" + "\n" + "repositories {\n" + "    mavenCentral()\n" + "}");
    File javaFile = new File(rootDir, "src/main/java/Main.java");
    writeFile(javaFile, "public class Main {\n" + "    public static void main(String[] args) {\n" + "        Runnable lambda = () -> System.out.println(\"Hello, Lambda!\");\n" + "        lambda.run();\n" + "    }\n" + "}");
    StringWriter errorOutput = new StringWriter();
    BuildResult result = GradleRunner.create().withGradleVersion(gradleVersion).withProjectDir(rootDir).withArguments("assemble", "--stacktrace").forwardStdError(errorOutput).build();
    assertThat(result.task(":assemble").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
    File mainClassFile = findFile(rootDir, "Main.class");
    File lambdaClassFile = findFile(rootDir, "Main$$Lambda$1.class");
    assertThat(mainClassFile).exists();
    assertThat(lambdaClassFile).exists();
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) StringWriter(java.io.StringWriter) TestHelpers.findFile(me.tatarka.TestHelpers.findFile) File(java.io.File) TestHelpers.writeFile(me.tatarka.TestHelpers.writeFile) Test(org.junit.Test)

Aggregations

BuildResult (org.gradle.testkit.runner.BuildResult)149 File (java.io.File)65 TestTemplate (org.junit.jupiter.api.TestTemplate)60 Test (org.junit.Test)47 Test (org.junit.jupiter.api.Test)21 StringWriter (java.io.StringWriter)19 GradleRunner (org.gradle.testkit.runner.GradleRunner)17 Test (org.testng.annotations.Test)10 ImageReference (org.springframework.boot.buildpack.platform.docker.type.ImageReference)8 JarFile (java.util.jar.JarFile)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 TestHelpers.findFile (me.tatarka.TestHelpers.findFile)6 TestHelpers.writeFile (me.tatarka.TestHelpers.writeFile)6 ContainerConfig (com.github.dockerjava.api.model.ContainerConfig)5 FileWriter (java.io.FileWriter)5 IOException (java.io.IOException)5 PrintWriter (java.io.PrintWriter)5 Path (java.nio.file.Path)5 BuildTask (org.gradle.testkit.runner.BuildTask)5