Java Code Examples for org.gradle.testkit.runner.GradleRunner#build()

The following examples show how to use org.gradle.testkit.runner.GradleRunner#build() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JdkDownloadPluginFunctionalTest.java    From crate with Apache License 2.0 6 votes vote down vote up
private static void runBuild(String task,
                             Consumer<BuildResult> assertions,
                             String vendor,
                             String version) {
    var testKitDirPath = Paths.get(
        System.getProperty("user.dir"),
        "build",
        System.getProperty("user.name")
    );
    GradleRunner runner = GradleRunner.create()
        .withDebug(true)
        .withProjectDir(getTestKitProjectDir("jdk-download"))
        .withTestKitDir(testKitDirPath.toFile())
        .withArguments(
            task,
            "-Dtests.jdk_vendor=" + vendor,
            "-Dtests.jdk_version=" + version,
            "-i"
        )
        .withPluginClasspath();

    BuildResult result = runner.build();
    assertions.accept(result);
}
 
Example 2
Source File: HelmPackageTest.java    From gradle-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenericExec() throws IOException {
	GradleRunner runner = GradleRunner.create();
	runner = runner.forwardOutput();
	runner = runner.withPluginClasspath();
	runner = runner.withProjectDir(workingDir).withArguments("testHelmGeneric", "--stacktrace").forwardOutput();
	runner.build();
}
 
Example 3
Source File: HelmPackageTest.java    From gradle-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void testPackaging() throws IOException {
	GradleRunner runner = GradleRunner.create();
	runner = runner.forwardOutput();
	runner = runner.withPluginClasspath();
	runner = runner.withProjectDir(workingDir).withArguments("helmPackage", "--stacktrace").forwardOutput();
	runner.build();

	File helmFile = new File(workingDir, "build/helm/helmapp-0.1.0.tgz");
	Assert.assertTrue(helmFile.exists());
}
 
Example 4
Source File: Web3jPluginTest.java    From web3j-gradle-plugin with Apache License 2.0 4 votes vote down vote up
@Test
public void generateContractWrappersExcluding() throws IOException {
    final String buildFileContent =
            "plugins {\n"
                    + "    id 'org.web3j'\n"
                    + "}\n"
                    + "web3j {\n"
                    + "    generatedPackageName = 'org.web3j.test'\n"
                    + "    excludedContracts = ['Token']\n"
                    + "}\n"
                    + "sourceSets {\n"
                    + "    main {\n"
                    + "        solidity {\n"
                    + "            srcDir {"
                    + "                '"
                    + sourceDir.getAbsolutePath()
                    + "'\n"
                    + "            }\n"
                    + "        }\n"
                    + "    }\n"
                    + "}\n"
                    + "repositories {\n"
                    + "   mavenCentral()\n"
                    + "   maven {\n"
                    + "       url 'https://oss.sonatype.org/content/repositories/snapshots'\n"
                    + "   }"
                    + "}\n";

    Files.write(buildFile.toPath(), buildFileContent.getBytes());

    final GradleRunner gradleRunner =
            GradleRunner.create()
                    .withProjectDir(testProjectDir.getRoot())
                    .withArguments("build")
                    .withPluginClasspath()
                    .forwardOutput();

    final BuildResult success = gradleRunner.build();
    assertNotNull(success.task(":generateContractWrappers"));
    assertEquals(SUCCESS, success.task(":generateContractWrappers").getOutcome());

    final File web3jContractsDir =
            new File(testProjectDir.getRoot(), "build/generated/source/web3j/main/java");

    final File generatedContract =
            new File(web3jContractsDir, "org/web3j/test/StandardToken.java");

    assertTrue(generatedContract.exists());

    final File excludedContract = new File(web3jContractsDir, "org/web3j/test/Token.java");

    assertFalse(excludedContract.exists());

    final BuildResult upToDate = gradleRunner.build();
    assertNotNull(upToDate.task(":generateContractWrappers"));
    assertEquals(UP_TO_DATE, upToDate.task(":generateContractWrappers").getOutcome());
}
 
Example 5
Source File: Web3jPluginTest.java    From web3j-gradle-plugin with Apache License 2.0 4 votes vote down vote up
@Test
public void generateContractWrappersIncluding() throws IOException {
    final String buildFileContent =
            "plugins {\n"
                    + "    id 'org.web3j'\n"
                    + "}\n"
                    + "web3j {\n"
                    + "    generatedPackageName = 'org.web3j.test'\n"
                    + "    includedContracts = ['StandardToken']\n"
                    + "}\n"
                    + "sourceSets {\n"
                    + "    main {\n"
                    + "        solidity {\n"
                    + "            srcDir {"
                    + "                '"
                    + sourceDir.getAbsolutePath()
                    + "'\n"
                    + "            }\n"
                    + "        }\n"
                    + "    }\n"
                    + "}\n"
                    + "repositories {\n"
                    + "   mavenCentral()\n"
                    + "   maven {\n"
                    + "       url 'https://oss.sonatype.org/content/repositories/snapshots'\n"
                    + "   }"
                    + "}\n";

    Files.write(buildFile.toPath(), buildFileContent.getBytes());

    final GradleRunner gradleRunner =
            GradleRunner.create()
                    .withProjectDir(testProjectDir.getRoot())
                    .withArguments("build")
                    .withPluginClasspath()
                    .forwardOutput();

    final BuildResult success = gradleRunner.build();
    assertNotNull(success.task(":generateContractWrappers"));
    assertEquals(SUCCESS, success.task(":generateContractWrappers").getOutcome());

    final File web3jContractsDir =
            new File(testProjectDir.getRoot(), "build/generated/source/web3j/main/java");

    final File generatedContract =
            new File(web3jContractsDir, "org/web3j/test/StandardToken.java");

    assertTrue(generatedContract.exists());

    final File excludedContract = new File(web3jContractsDir, "org/web3j/test/Token.java");

    assertFalse(excludedContract.exists());

    final BuildResult upToDate = gradleRunner.build();
    assertNotNull(upToDate.task(":generateContractWrappers"));
    assertEquals(UP_TO_DATE, upToDate.task(":generateContractWrappers").getOutcome());
}
 
Example 6
Source File: OpenAPIStyleValidatorGradlePluginFunctionalTest.java    From openapi-style-validator with Apache License 2.0 4 votes vote down vote up
@Test
public void validateWithOptionsMustBeASuccess() throws IOException {
    // Setup the test build
    File projectDir = new File("build/functionalTest");
    Files.createDirectories(projectDir.toPath());
    writeString(new File(projectDir, "openapi.yaml"),
            "openapi: 3.0.1\n" +
                    "info:\n" +
                    "  title: ping test\n" +
                    "  version: '1.0'\n" +
                    "servers:\n" +
                    "  - url: 'http://localhost:9999/'\n" +
                    "paths:\n" +
                    "  /ping:\n" +
                    "    post:\n" +
                    "      operationId: pingGet\n" +
                    "      responses:\n" +
                    "        '201':\n" +
                    "          description: OK");
    writeString(new File(projectDir, "settings.gradle"), "");
    writeString(new File(projectDir, "build.gradle"),
            "plugins {\n" +
                    "  id('org.openapitools.openapistylevalidator')\n" +
                    "}\n" +
                    "\n" +
                    "openAPIStyleValidator {\n" +
                    "    // set the input file option:\n" +
                    "    inputFile = file('openapi.yaml')\n" +
                    "\n" +
                    "    // customize the validation options:\n" +
                    "    validateInfoLicense = false\n" +
                    "    validateInfoDescription = false\n" +
                    "    validateInfoContact = false\n" +
                    "    validateOperationDescription = false\n" +
                    "    validateOperationTag = false\n" +
                    "    validateOperationSummary = false\n" +
                    "}");

    // Run the build
    GradleRunner runner = GradleRunner.create();
    runner.forwardOutput();
    runner.withPluginClasspath();
    runner.withArguments("openAPIStyleValidator");
    runner.withProjectDir(projectDir);
    BuildResult result = runner.build();

    // Verify the result
    assertEquals(TaskOutcome.SUCCESS, result.task(":openAPIStyleValidator").getOutcome());
}
 
Example 7
Source File: HelmSysTest.java    From gradle-plugins with Apache License 2.0 4 votes vote down vote up
@Test
public void testPackaging() throws IOException, InterruptedException {
	File tempDir = new File("build/tmp/systest");
	tempDir.mkdirs();

	workingDir = new File(tempDir, "demo");
	workingDir.mkdirs();

	File chartFolder = new File(workingDir, "src/main/helm/helmapp");
	File remplateFolder = new File(chartFolder, "templates");
	remplateFolder.mkdirs();

	System.setProperty("org.gradle.daemon", "false");

	File gradleFile = new File(workingDir, "build.gradle");
	File tillerFile = new File(workingDir, "src/main/kubectl/tiller-template.yaml");
	tillerFile.getParentFile().mkdirs();
	File chartFile = new File(chartFolder, "Chart.yaml");
	File valuesFile = new File(chartFolder, "values.yaml");
	File serviceFile = new File(remplateFolder, "service.yaml");
	File tplFile = new File(remplateFolder, "_helpers.tpl");

	Assert.assertNotNull(getClass().getClassLoader().getResource("plugin-under-test-metadata.properties"));

	IOUtils.copy(getClass().getClassLoader().getResourceAsStream("build.gradle"),
			new FileOutputStream(gradleFile));
	IOUtils.copy(getClass().getClassLoader().getResourceAsStream("Chart.yaml"),
			new FileOutputStream(chartFile));
	IOUtils.copy(getClass().getClassLoader().getResourceAsStream("values.yaml"),
			new FileOutputStream(valuesFile));
	IOUtils.copy(getClass().getClassLoader().getResourceAsStream("service.yaml"),
			new FileOutputStream(serviceFile));
	IOUtils.copy(getClass().getClassLoader().getResourceAsStream("_helpers.tpl"),
			new FileOutputStream(tplFile));
	IOUtils.copy(getClass().getClassLoader().getResourceAsStream("tiller-template.yaml"),
			new FileOutputStream(tillerFile));

	try {
		GradleRunner runner = GradleRunner.create();
		runner = runner.forwardOutput();
		runner = runner.withPluginClasspath();
		runner = runner.withProjectDir(workingDir).withArguments("ocSetup", "--stacktrace").forwardOutput();
		runner.build();

		// wait with oc client
		runner = GradleRunner.create();
		runner = runner.forwardOutput();
		runner = runner.withPluginClasspath();
		runner = runner.withProjectDir(workingDir).withArguments("ocWaitForTiller", "--stacktrace").forwardOutput();
		runner.build();

		// install software
		runner = GradleRunner.create();
		runner = runner.forwardOutput();
		runner = runner.withPluginClasspath();
		runner = runner.withProjectDir(workingDir).withArguments("helmInstall", "--stacktrace").forwardOutput();
		runner.build();

		//  wait for tiller again (with kubectl client for testing purposes)
		// TODO replacce with something meaningful => setup proper app
		runner = GradleRunner.create();
		runner = runner.forwardOutput();
		runner = runner.withPluginClasspath();
		runner = runner.withProjectDir(workingDir).withArguments("kubectlWaitForTiller", "--stacktrace").forwardOutput();
		runner.build();

		File helmPackageFile = new File(workingDir, "build/distributions/helmapp-0.1.0.tgz");
		Assert.assertTrue(helmPackageFile.exists());
	} finally {
		/*
		GradleRunner runner = GradleRunner.create();
		runner = runner.forwardOutput();
		runner = runner.withPluginClasspath();
		runner = runner.withProjectDir(workingDir).withArguments("ocDeleteProject", "--stacktrace").forwardOutput();
		runner.build();
		*/
	}
}
 
Example 8
Source File: HelmBootstrapSysTest.java    From gradle-plugins with Apache License 2.0 4 votes vote down vote up
@Test
public void testPackaging() throws IOException, InterruptedException {
	File tempDir = new File("build/tmp/systest");
	tempDir.mkdirs();

	workingDir = new File(tempDir, "demoBootstrap");
	workingDir.mkdirs();

	File chartFolder = new File(workingDir, "src/main/helm/helmapp");
	File remplateFolder = new File(chartFolder, "templates");
	remplateFolder.mkdirs();

	System.setProperty("org.gradle.daemon", "false");

	File gradleFile = new File(workingDir, "build.gradle");
	File tillerFile = new File(workingDir, "tiller-template.yaml");
	File chartFile = new File(chartFolder, "Chart.yaml");
	File valuesFile = new File(chartFolder, "values.yaml");
	File serviceFile = new File(remplateFolder, "service.yaml");
	File tplFile = new File(remplateFolder, "_helpers.tpl");

	Assert.assertNotNull(getClass().getClassLoader().getResource("plugin-under-test-metadata.properties"));

	IOUtils.copy(getClass().getClassLoader().getResourceAsStream("build.gradle"),
			new FileOutputStream(gradleFile));
	IOUtils.copy(getClass().getClassLoader().getResourceAsStream("Chart.yaml"),
			new FileOutputStream(chartFile));
	IOUtils.copy(getClass().getClassLoader().getResourceAsStream("values.yaml"),
			new FileOutputStream(valuesFile));
	IOUtils.copy(getClass().getClassLoader().getResourceAsStream("service.yaml"),
			new FileOutputStream(serviceFile));
	IOUtils.copy(getClass().getClassLoader().getResourceAsStream("_helpers.tpl"),
			new FileOutputStream(tplFile));
	IOUtils.copy(getClass().getClassLoader().getResourceAsStream("tiller-template.yaml"),
			new FileOutputStream(tillerFile));

	try {
		// install software
		GradleRunner runner = GradleRunner.create();
		runner = runner.forwardOutput();
		runner = runner.withPluginClasspath();
		runner = runner.withProjectDir(workingDir).withArguments("helmClientVersion", "--stacktrace").forwardOutput();
		runner.build();
	} finally {
		/*
		GradleRunner runner = GradleRunner.create();
		runner = runner.forwardOutput();
		runner = runner.withPluginClasspath();
		runner = runner.withProjectDir(workingDir).withArguments("ocDeleteProject", "--stacktrace").forwardOutput();
		runner.build();
		*/
	}
}
 
Example 9
Source File: SchemaGenerationPluginTest.java    From gradle-plugins with Apache License 2.0 4 votes vote down vote up
private void check(boolean liquibase, String example) throws IOException {
	testFolder.create();
	workingDir = testFolder.getRoot();

	File javaFolder = testFolder.newFolder("src", "main", "java", "example");
	File secondJavaPackage = testFolder.newFolder("src", "main", "java", "excluded");
	File resourceFolder = testFolder.newFolder("src", "main", "resources");
	File metaInfFolder = testFolder.newFolder("src", "main", "resources", "META-INF");

	System.setProperty("org.gradle.daemon", "false");

	File gradleFile = testFolder.newFile("build.gradle");
	File entityFile = new File(javaFolder, "ExampleEntity.java");
	File excludedFile = new File(secondJavaPackage, "ExcludedEntity.java");
	File persistenceFile = new File(metaInfFolder, "persistence.xml");
	File exampleResource = new File(resourceFolder, "example_config.properties");
	File settingsFile = testFolder.newFile("settings.gradle");
	FileUtils.write(settingsFile, "", StandardCharsets.UTF_8);

	// make sure to run gradle first
	Assert.assertNotNull(getClass().getClassLoader().getResource("plugin-under-test-metadata.properties"));

	IOUtils.copy(getClass().getClassLoader().getResourceAsStream(
			example + (liquibase ? "/input_liquibase.gradle" : "/input_flyway.gradle")),
			new FileOutputStream(gradleFile));
	IOUtils.copy(getClass().getClassLoader().getResourceAsStream(example + "/input_persistence.xml"),
			new FileOutputStream(persistenceFile));
	IOUtils.copy(getClass().getClassLoader().getResourceAsStream(example + "/input_entity.java"),
			new FileOutputStream(entityFile));
	InputStream excludedFileContents = getClass().getClassLoader().getResourceAsStream(example + "/input_excluded_entity.java");
	if (excludedFileContents != null) {
		IOUtils.copy(excludedFileContents, new FileOutputStream(excludedFile));
	}
	IOUtils.copy(getClass().getClassLoader().getResourceAsStream(example + "/input_example_config.properties"),
			new FileOutputStream(exampleResource));

	GradleRunner runner = GradleRunner.create();
	runner = runner.withPluginClasspath().withDebug(true);
	List<String> args = new ArrayList<>();
	args.add("build");
	args.add("--stacktrace");
	httpProxyArguments(args);
	runner = runner.withProjectDir(workingDir).withArguments(args).forwardOutput();
	runner.build();

	File exampleResourceOutputFile = new File(workingDir, "build/classes/java/main/example_config.properties");
	Assert.assertTrue(exampleResourceOutputFile.exists());
}
 
Example 10
Source File: SystemdApplicationTest.java    From gradle-plugins with Apache License 2.0 4 votes vote down vote up
@Test
public void check() throws IOException {
    File tempDir = new File("build/tmp");
    tempDir.mkdirs();
    testFolder = new TemporaryFolder(tempDir);

    testFolder.create();
    workingDir = new File(testFolder.getRoot(), "demo");
    workingDir.mkdirs();

    File javaFolder = new File(workingDir, "src/main/java/example");
    javaFolder.mkdirs();
    File rpmFolder = new File(workingDir, "src/main/rpm");
    rpmFolder.mkdirs();

    System.setProperty("org.gradle.daemon", "false");

    File gradleFile = new File(workingDir, "build.gradle");
    File settingsFile = new File(workingDir, "settings.gradle");
    File entityFile = new File(javaFolder, "Main.java");
    File propertiesFile = new File(rpmFolder, "application.properties");

    Assert.assertNotNull(getClass().getClassLoader().getResource("plugin-under-test-metadata.properties"));

    IOUtils.copy(getClass().getClassLoader().getResourceAsStream("helm-app/input.gradle"),
            new FileOutputStream(gradleFile));
    IOUtils.copy(getClass().getClassLoader().getResourceAsStream("helm-app/input_settings.gradle"),
            new FileOutputStream(settingsFile));
    IOUtils.copy(getClass().getClassLoader().getResourceAsStream("helm-app/input_main.java"),
            new FileOutputStream(entityFile));
    IOUtils.copy(getClass().getClassLoader().getResourceAsStream("helm-app/input_application.properties"),
            new FileOutputStream(propertiesFile));

    GradleRunner runner = GradleRunner.create();
    runner = runner.forwardOutput();
    runner = runner.withPluginClasspath();
    runner = runner.withProjectDir(workingDir).withArguments("buildRpm", "--stacktrace").forwardOutput();
    runner.build();

    File rpmFile = new File(workingDir, "build/distributions/demo.rpm");
    Assert.assertTrue(rpmFile.exists());

    File serviceFile = new File(workingDir, "build/systemd/services/demo-app.service");
    Assert.assertTrue(serviceFile.exists());

    String serviceDesc = IOUtils.toString(new FileInputStream(serviceFile));
    Assert.assertTrue(serviceDesc.contains("ExecStart=/var/demo-app/bin/demo run"));
}