Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>5.17</version>
<version>5.24</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -35,14 +35,15 @@
<jenkins.baseline>2.479</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.3</jenkins.version>
<spotless.check.skip>false</spotless.check.skip>
<ban-junit4-imports.skip>false</ban-junit4-imports.skip>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-${jenkins.baseline}.x</artifactId>
<version>4948.vcf1d17350668</version>
<version>5054.v620b_5d2b_d5e6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
47 changes: 28 additions & 19 deletions src/test/java/org/jenkinsci/plugins/unity3d/IntegrationTests.java
Original file line number Diff line number Diff line change
@@ -1,73 +1,82 @@
package org.jenkinsci.plugins.unity3d;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assume.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Result;
import java.io.File;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
import org.jvnet.hudson.test.recipes.LocalData;

/**
* @author Jerome Lacoste
*/
public class IntegrationTests {
@WithJenkins
class IntegrationTests {

@Rule
public JenkinsRule rule = new JenkinsRule();
private JenkinsRule r;

@BeforeEach
void beforeEach(JenkinsRule rule) {
r = rule;
}

@Test
@LocalData
public void testEditorException() throws Exception {
void testEditorException() throws Exception {
ensureUnityHomeExists();

FreeStyleProject job = (FreeStyleProject) rule.jenkins.getItem("test_unity3d");
FreeStyleProject job = (FreeStyleProject) r.jenkins.getItem("test_unity3d");
assertNotNull(job);

FreeStyleBuild build = job.scheduleBuild2(0).get();

rule.assertLogContains("Exception: Simulated Exception", build);
r.assertLogContains("Exception: Simulated Exception", build);
}

private void ensureUnityHomeExists() {
Unity3dInstallation[] installations = rule.jenkins
Unity3dInstallation[] installations = r.jenkins
.getDescriptorByType(Unity3dInstallation.DescriptorImpl.class)
.getInstallations();
assertEquals(1, installations.length);

Unity3dInstallation inst = installations[0];
String unityHome = inst.getHome();

assumeTrue(new File(unityHome).exists()); // skip test if doesn't have unity
assumeTrue(
unityHome != null && new File(unityHome).exists(),
"Skip test due to missing unity installation: " + unityHome);
}

@Test
@LocalData
public void testEditorExceptionWithCustomLogFile() throws Exception {
void testEditorExceptionWithCustomLogFile() throws Exception {
ensureUnityHomeExists();

FreeStyleProject job = (FreeStyleProject) rule.jenkins.getItem("test_unity3d");
FreeStyleProject job = (FreeStyleProject) r.jenkins.getItem("test_unity3d");
assertNotNull(job);

FreeStyleBuild build = job.scheduleBuild2(0).get();

rule.assertLogContains("Exception: Simulated Exception", build);
r.assertLogContains("Exception: Simulated Exception", build);
}

@Test
@LocalData
public void testExpectADifferentExitCode() throws Exception {
void testExpectADifferentExitCode() throws Exception {
ensureUnityHomeExists();
FreeStyleProject job = (FreeStyleProject) rule.jenkins.getItem("test_unity3d");

FreeStyleProject job = (FreeStyleProject) r.jenkins.getItem("test_unity3d");
assertNotNull(job);

FreeStyleBuild build = job.scheduleBuild2(0).get();

rule.assertBuildStatus(Result.UNSTABLE, build);
r.assertBuildStatus(Result.UNSTABLE, build);
}
}
95 changes: 44 additions & 51 deletions src/test/java/org/jenkinsci/plugins/unity3d/Unity3dBuilderTest.java
Original file line number Diff line number Diff line change
@@ -1,82 +1,79 @@
package org.jenkinsci.plugins.unity3d;

import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import hudson.EnvVars;
import hudson.util.ArgumentListBuilder;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* @author Jerome Lacoste
*/
public class Unity3dBuilderTest {
class Unity3dBuilderTest {

private String exe = "/Applications/Unity/Unity.app";
private String moduleRootRemote = "/Users/Shared/Jenkins/Home/jobs/project1/workspace";

private String argLine;

private List<String> expectedArgs;
private static final String EXE = "/Applications/Unity/Unity.app";
private static final String MODULE_ROOT_REMOTE = "/Users/Shared/Jenkins/Home/jobs/project1/workspace";

@Test
public void typicalExecuteMethodArgumentsAddMissingProjectPath() {
argLine = "-quit -batchmode -nographics -executeMethod ExecuteClass.ExecuteMethod";
expectedArgs = asList(
exe,
void typicalExecuteMethodArgumentsAddMissingProjectPath() {
String argLine = "-quit -batchmode -nographics -executeMethod ExecuteClass.ExecuteMethod";
List<String> expectedArgs = asList(
EXE,
"-projectPath",
moduleRootRemote,
MODULE_ROOT_REMOTE,
"-quit",
"-batchmode",
"-nographics",
"-executeMethod",
"ExecuteClass.ExecuteMethod");
ensureCreateCommandlineArgs(expectedArgs);
ensureCreateCommandlineArgs(argLine, expectedArgs);
}

@Test
public void typicalExecuteMethodArgumentsWithCustomProjectPath() {
argLine = "-quit -batchmode -nographics -executeMethod ExecuteClass.ExecuteMethod -projectPath XXXX";
expectedArgs = asList(
exe,
void typicalExecuteMethodArgumentsWithCustomProjectPath() {
String argLine = "-quit -batchmode -nographics -executeMethod ExecuteClass.ExecuteMethod -projectPath XXXX";
List<String> expectedArgs = asList(
EXE,
"-quit",
"-batchmode",
"-nographics",
"-executeMethod",
"ExecuteClass.ExecuteMethod",
"-projectPath",
"XXXX");
ensureCreateCommandlineArgs(expectedArgs);
ensureCreateCommandlineArgs(argLine, expectedArgs);
}

@Test
public void buildWindowsPlayerAddMissingProjectPath() {
argLine = "-buildWindowsPlayer \"C:\\Temp\\The Win32.exe\"";
expectedArgs = asList(exe, "-projectPath", moduleRootRemote, "-buildWindowsPlayer", "C:\\Temp\\The Win32.exe");
ensureCreateCommandlineArgs(expectedArgs);
void buildWindowsPlayerAddMissingProjectPath() {
String argLine = "-buildWindowsPlayer \"C:\\Temp\\The Win32.exe\"";
List<String> expectedArgs =
asList(EXE, "-projectPath", MODULE_ROOT_REMOTE, "-buildWindowsPlayer", "C:\\Temp\\The Win32.exe");
ensureCreateCommandlineArgs(argLine, expectedArgs);
}

@Test
public void buildOSXPlayerAddMissingProjectPath() {
argLine = "-buildOSXPlayer the\\ dir.app";
expectedArgs = asList(exe, "-projectPath", moduleRootRemote, "-buildOSXPlayer", "the dir.app");
ensureCreateCommandlineArgs(expectedArgs);
void buildOSXPlayerAddMissingProjectPath() {
String argLine = "-buildOSXPlayer the\\ dir.app";
List<String> expectedArgs = asList(EXE, "-projectPath", MODULE_ROOT_REMOTE, "-buildOSXPlayer", "the dir.app");
ensureCreateCommandlineArgs(argLine, expectedArgs);
}

private void ensureCreateCommandlineArgs(List<String> expectedArgs1) {
private void ensureCreateCommandlineArgs(String argLine, List<String> expectedArgs) {
Unity3dBuilder builder = new Unity3dBuilder("Unity 3.5", argLine, "");
ArgumentListBuilder commandlineArgs =
builder.createCommandlineArgs(exe, moduleRootRemote, new EnvVars(), new Hashtable<>());
assertEquals(expectedArgs1, commandlineArgs.toList());
builder.createCommandlineArgs(EXE, MODULE_ROOT_REMOTE, new EnvVars(), new Hashtable<>());
assertEquals(expectedArgs, commandlineArgs.toList());
}

@Test
public void environmentAndBuildVariablesParsing() {
void environmentAndBuildVariablesParsing() {
EnvVars vars = new EnvVars();
vars.put("param1", "value1");
vars.put("param2", "value2");
Expand All @@ -86,36 +83,37 @@ public void environmentAndBuildVariablesParsing() {
Map<String, String> buildParameters = new Hashtable<>();
buildParameters.put("param2", param2overwrittenValue);

argLine = "-param1 $param1 -param2 $param2 -projectPath XXXX";
expectedArgs = asList(exe, "-param1", "value1", "-param2", param2overwrittenValue, "-projectPath", "XXXX");
String argLine = "-param1 $param1 -param2 $param2 -projectPath XXXX";
List<String> expectedArgs =
asList(EXE, "-param1", "value1", "-param2", param2overwrittenValue, "-projectPath", "XXXX");

Unity3dBuilder builder = new Unity3dBuilder("Unity 3.5", argLine, "");
ArgumentListBuilder commandlineArgs =
builder.createCommandlineArgs(exe, moduleRootRemote, vars, buildParameters);
builder.createCommandlineArgs(EXE, MODULE_ROOT_REMOTE, vars, buildParameters);
assertEquals(expectedArgs, commandlineArgs.toList());
assertEquals("Serialized arg line not modified", argLine, builder.getArgLine());
assertEquals(argLine, builder.getArgLine(), "Serialized arg line not modified");
}

@Test
public void environmentAndBuildVariablesParsingWithEnvVarsThatReferencesBuildParameters() {
void environmentAndBuildVariablesParsingWithEnvVarsThatReferencesBuildParameters() {
EnvVars vars = new EnvVars();
vars.put("ARGS", "-projectPath $param");

Map<String, String> buildParameters = new Hashtable<>();
buildParameters.put("param", "XXXX");

argLine = "-p1 v1 $ARGS";
expectedArgs = asList(exe, "-p1", "v1", "-projectPath", "XXXX");
String argLine = "-p1 v1 $ARGS";
List<String> expectedArgs = asList(EXE, "-p1", "v1", "-projectPath", "XXXX");

Unity3dBuilder builder = new Unity3dBuilder("Unity 3.5", argLine, "");
ArgumentListBuilder commandlineArgs =
builder.createCommandlineArgs(exe, moduleRootRemote, vars, buildParameters);
builder.createCommandlineArgs(EXE, MODULE_ROOT_REMOTE, vars, buildParameters);
assertEquals(expectedArgs, commandlineArgs.toList());
assertEquals("Serialized arg line not modified", argLine, builder.getArgLine());
assertEquals(argLine, builder.getArgLine(), "Serialized arg line not modified");
}

@Test
public void unstableErrorCodesParsing() throws Exception {
void unstableErrorCodesParsing() {
ensureUnstableReturnCodesParsingWorks(new Integer[] {}, "");
ensureUnstableReturnCodesParsingWorks(new Integer[] {2, 3}, "2,3");
ensureUnstableReturnCodesParsingWorks(new Integer[] {-1}, "-1");
Expand All @@ -125,17 +123,12 @@ public void unstableErrorCodesParsing() throws Exception {
}

private void ensureUnstableReturnCodesParsingWorks(Integer[] expectedResultCodes, String unstableReturnCodes) {
Unity3dBuilder builder = new Unity3dBuilder("Unity 3.5", argLine, unstableReturnCodes);
Unity3dBuilder builder = new Unity3dBuilder("Unity 3.5", null, unstableReturnCodes);
assertEquals(new HashSet<>(asList(expectedResultCodes)), builder.toUnstableReturnCodesSet());
}

private void ensureUnstableReturnCodesParsingFails(String unstableReturnCodes) {
Unity3dBuilder builder = new Unity3dBuilder("Unity 3.5", argLine, unstableReturnCodes);
try {
builder.toUnstableReturnCodesSet();
Assert.fail("Expected failure");
} catch (Exception expected) {
//
}
Unity3dBuilder builder = new Unity3dBuilder("Unity 3.5", null, unstableReturnCodes);
assertThrows(Exception.class, builder::toUnstableReturnCodesSet);
}
}
Original file line number Diff line number Diff line change
@@ -1,51 +1,49 @@
package org.jenkinsci.plugins.unity3d.io;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import hudson.util.ByteArrayOutputStream2;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.concurrent.atomic.AtomicLong;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* @author Jerome Lacoste
*/
public class PipeFileAfterModificationActionTest {
private String originalContent =
class PipeFileAfterModificationActionTest {

private static final String ORIGINAL_CONTENT =
"""
The original content of the file
Multiple lines of\s
Build information""";

private String newContent =
private static final String NEW_CONTENT =
"""
The new content of the file
Multiple lines of\s
""";

private String newContent2 = "Build information";

public static final Charset UTF_8 = StandardCharsets.UTF_8;
private static final String NEW_CONTENT_2 = "Build information";

@Test
public void simulateEditorLogRewritten() throws Exception {
void simulateEditorLogRewritten() throws Exception {
testRewriteFile(0);
}

@Test
public void simulateEditorLogSlowlyMoved() throws Exception {
void simulateEditorLogSlowlyMoved() throws Exception {
testRewriteFile(100);
}

private void testRewriteFile(int timeToWaitAfterRename) throws IOException, InterruptedException {
private void testRewriteFile(int timeToWaitAfterRename) throws Exception {
// Given
File fakeEditorLog = File.createTempFile("fake_editor", "log");
Files.writeString(fakeEditorLog.toPath(), originalContent, StandardCharsets.UTF_8);
Files.writeString(fakeEditorLog.toPath(), ORIGINAL_CONTENT, StandardCharsets.UTF_8);

ByteArrayOutputStream2 collectedContent = new ByteArrayOutputStream2();

Expand All @@ -69,19 +67,19 @@ private void testRewriteFile(int timeToWaitAfterRename) throws IOException, Inte

Thread.sleep(timeToWaitAfterRename);

Files.writeString(fakeEditorLog.toPath(), newContent, StandardCharsets.UTF_8);
Files.writeString(fakeEditorLog.toPath(), NEW_CONTENT, StandardCharsets.UTF_8);
Thread.sleep(20);
Files.writeString(fakeEditorLog.toPath(), newContent2, StandardCharsets.UTF_8, StandardOpenOption.APPEND);
Files.writeString(fakeEditorLog.toPath(), NEW_CONTENT_2, StandardCharsets.UTF_8, StandardOpenOption.APPEND);
Thread.sleep(80);
String expectedContent = newContent + newContent2;
String expectedContent = NEW_CONTENT + NEW_CONTENT_2;

// simulate remote cancellation. Using the remoting API, we cancel the task and this interrupts the remote
// thread
t.interrupt();
// give us the time to terminate properly the task
Thread.sleep(50);

assertEquals(expectedContent, new String(collectedContent.getBuffer(), UTF_8));
assertEquals(expectedContent, new String(collectedContent.getBuffer(), StandardCharsets.UTF_8));

Long read = (long) expectedContent.length();
assertEquals(read, (Long) nbBytesRead.get());
Expand Down
Loading
Loading