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

The following examples show how to use org.gradle.testkit.runner.GradleRunner#forwardOutput() . 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: 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 2
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 3
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 4
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 5
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 6
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"));
}