Add a first test example using the injectedEnvVars.txt
package io.jenkins.plugins.analysis.warnings.plugins;
-import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.util.Arrays;
import java.util.List;
import org.junit.Test;
-import com.google.common.collect.Lists;
-
import org.jenkinsci.plugins.envinject.EnvInjectBuildWrapper;
import org.jenkinsci.plugins.envinject.EnvInjectJobPropertyInfo;
import org.jenkinsci.plugins.envinject.EnvInjectPlugin;
@@ -22,9 +18,14 @@ import hudson.model.Result;
import io.jenkins.plugins.analysis.core.model.AnalysisResult;
import io.jenkins.plugins.analysis.core.testutil.IntegrationTestWithJenkinsPerTest;
import io.jenkins.plugins.analysis.warnings.Java;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import static io.jenkins.plugins.analysis.core.assertions.Assertions.*;
+
public class EnvInjectPluginITest extends IntegrationTestWithJenkinsPerTest {
@Test
@@ -59,6 +60,32 @@ public class EnvInjectPluginITest extends IntegrationTestWithJenkinsPerTest {
}
+ @Test
+ public void shouldStoreEnvironmentVariablesInFile() throws IOException {
+ // Set up the project and configure the java warnings
+ FreeStyleProject project = createFreeStyleProject();
+
+ Java java = new Java();
+ java.setPattern("**/*.txt");
+ enableWarnings(project, java);
+
+ createFileWithJavaWarnings(project, 1, 2);
+
+ EnvInjectPlugin envInjectPlugin = new EnvInjectPlugin();
+ EnvInjectBuildWrapper envInjectBuildWrapper = new EnvInjectBuildWrapper(new EnvInjectJobPropertyInfo());
+ project.getBuildWrappersList().add(envInjectBuildWrapper);
+
+ scheduleBuildAndAssertStatus(project, Result.SUCCESS);
+
+ Path envFile = Paths.get(project.getLastBuild().getRootDir().getPath(), "injectedEnvVars.txt");
+ List<String> lines = Files.readAllLines(envFile, Charset.forName("ISO-8859-1"));
+ for (String line: lines)
+ {
+ System.out.println(line);
+ }
+ }
+
+
private void assertThatLogContainsNTimes(final FreeStyleProject project, final String element, final int times) throws IOException {
FreeStyleBuild lastBuild = project.getLastBuild();
assertThat(lastBuild).isNotNull();
