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
46 changes: 23 additions & 23 deletions src/test/java/org/jenkinsci/plugins/p4/DefaultEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@
import java.util.logging.LogRecord;
import java.util.logging.Logger;

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

abstract public class DefaultEnvironment {
public abstract class DefaultEnvironment {

private static Logger logger = Logger.getLogger(DefaultEnvironment.class.getName());
private static final Logger LOGGER = Logger.getLogger(DefaultEnvironment.class.getName());

protected final static String R15_1 = "r15.1";
protected final static String R17_1 = "r17.1";
protected final static String R18_1 = "r18.1";
protected static final String R15_1 = "r15.1";
protected static final String R17_1 = "r17.1";
protected static final String R18_1 = "r18.1";

protected final static String R19_1 = "r19.1";
protected final static String R24_1_r15 = "r24.1_r15"; //Binaries R24_1 checkpoint r15
protected final static String R24_1_r17 = "r24.1_r17"; //Binaries R24_1 checkpoint r17
protected static final String R19_1 = "r19.1";
protected static final String R24_1_r15 = "r24.1_r15"; //Binaries R24_1 checkpoint r15
protected static final String R24_1_r17 = "r24.1_r17"; //Binaries R24_1 checkpoint r17

protected final static String CREDENTIAL = "id";
protected final static int HTTP_PORT = 1888;
protected final static String HTTP_URL = "http://localhost:" + HTTP_PORT;
protected static final String CREDENTIAL = "id";
protected static final int HTTP_PORT = 1888;
protected static final String HTTP_URL = "http://localhost:" + HTTP_PORT;
protected final int LOG_LIMIT = 1000;

protected P4PasswordImpl createCredentials(String user, String password, String p4port, String id) throws IOException {
Expand Down Expand Up @@ -153,7 +153,7 @@ private void setP4Ignore(ConnectionHelper p4, String p4ignore) {
}

private ManualWorkspaceImpl createWorkspace(String path) {
String filename = path.substring(path.lastIndexOf("/") + 1, path.length());
String filename = path.substring(path.lastIndexOf("/") + 1);

// Create workspace
String client = "submit.ws";
Expand All @@ -162,7 +162,7 @@ private ManualWorkspaceImpl createWorkspace(String path) {
String view = "\"" + path + "\"" + " //" + client + "/" + filename;
WorkspaceSpec spec = new WorkspaceSpec(true, true, false, false, false, false, stream, line, view, null, null, null, true);
ManualWorkspaceImpl workspace = new ManualWorkspaceImpl("none", true, client, spec, false);
workspace.setExpand(new HashMap<String, String>());
workspace.setExpand(new HashMap<>());

File wsRoot = new File("target/submit.ws").getAbsoluteFile();
workspace.setRootPath(wsRoot.toString());
Expand All @@ -171,19 +171,19 @@ private ManualWorkspaceImpl createWorkspace(String path) {
}

private StreamWorkspaceImpl createStreamsWorkspace(String path, int depth) {
String p[] = path.substring(2).split("/");
String[] p = path.substring(2).split("/");

StringBuffer sb = new StringBuffer("//");
StringBuilder sb = new StringBuilder("//");
for (int i = 0; i < depth; i++) {
sb.append(p[i]);
sb.append("/");
}

String stream = sb.toString().substring(0, sb.lastIndexOf("/"));
String stream = sb.substring(0, sb.lastIndexOf("/"));

String client = "stream.ws";
StreamWorkspaceImpl workspace = new StreamWorkspaceImpl("none", false, stream, client);
workspace.setExpand(new HashMap<String, String>());
workspace.setExpand(new HashMap<>());

File wsRoot = new File("target/stream.ws").getAbsoluteFile();
workspace.setRootPath(wsRoot.toString());
Expand All @@ -192,7 +192,7 @@ private StreamWorkspaceImpl createStreamsWorkspace(String path, int depth) {
}

private FilePath createFilePath(String path, String content, Workspace workspace) throws IOException, InterruptedException {
String filename = path.substring(path.lastIndexOf("/") + 1, path.length());
String filename = path.substring(path.lastIndexOf("/") + 1);

File wsRoot = new File(workspace.getRootPath()).getAbsoluteFile();

Expand All @@ -205,7 +205,7 @@ private FilePath createFilePath(String path, String content, Workspace workspace
}

protected void commitFile(JenkinsRule jenkins, String path, String content) throws Exception {
String filename = path.substring(path.lastIndexOf("/") + 1, path.length());
String filename = path.substring(path.lastIndexOf("/") + 1);

// Create workspace
String client = "graphCommit.ws";
Expand Down Expand Up @@ -248,16 +248,16 @@ protected boolean waitForBuild(WorkflowJob job, int buildNumber, final int retry
while (r > 0) {
r--;
if (job.getLastBuild().number == buildNumber) {
logger.info("waitForBuild(): Attempts: " + (retry - r));
LOGGER.info("waitForBuild(): Attempts: " + (retry - r));
return true;
}
Thread.sleep(delay);
}
logger.severe("Gave up waiting for build");
LOGGER.severe("Gave up waiting for build");
return false;
}

public class TestHandler extends Handler {
public static class TestHandler extends Handler {

private StringBuffer sb = new StringBuffer();

Expand Down
11 changes: 0 additions & 11 deletions src/test/java/org/jenkinsci/plugins/p4/ExtendedJenkinsRule.java

This file was deleted.

38 changes: 22 additions & 16 deletions src/test/java/org/jenkinsci/plugins/p4/PerforceScmTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,29 @@
import org.jenkinsci.plugins.p4.populate.Populate;
import org.jenkinsci.plugins.p4.workspace.StaticWorkspaceImpl;
import org.jenkinsci.plugins.p4.workspace.Workspace;
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 java.io.IOException;

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

public class PerforceScmTest extends DefaultEnvironment {
@WithJenkins
class PerforceScmTest extends DefaultEnvironment {

@Rule
public JenkinsRule jenkins = new JenkinsRule();
private JenkinsRule jenkins;

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

@Test
public void testConfigBasic() throws Exception {
void testConfigBasic() throws Exception {
FreeStyleProject project = jenkins.createFreeStyleProject();

String credential = "123";
Expand All @@ -44,7 +50,7 @@ public void testConfigBasic() throws Exception {
}

@Test
public void testIsBuildParent() throws IOException {
void testIsBuildParent() throws IOException {
MatrixProject project = new MatrixProject("MatrixTest");

String credential = "123";
Expand All @@ -54,16 +60,16 @@ public void testIsBuildParent() throws IOException {
project.setScm(scm);

project.setExecutionStrategy(new DefaultMatrixExecutionStrategyImpl());
assertFalse("isBuildParent should be false for default execution strategy",
scm.isBuildParent(project));
assertFalse(scm.isBuildParent(project),
"isBuildParent should be false for default execution strategy");

project.setExecutionStrategy(new MatrixOptions(true, false, false));
assertTrue("isBuildParent should be true when MatrixOptions#buildParent is true",
scm.isBuildParent(project));
assertTrue(scm.isBuildParent(project),
"isBuildParent should be true when MatrixOptions#buildParent is true");

project.setExecutionStrategy(new MatrixOptions(false, true, true));
assertFalse("isBuildParent should be false when MatrixOptions#buildParent is false",
scm.isBuildParent(project));
assertFalse(scm.isBuildParent(project),
"isBuildParent should be false when MatrixOptions#buildParent is false");
}

}
27 changes: 27 additions & 0 deletions src/test/java/org/jenkinsci/plugins/p4/SampleServerExtension.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.jenkinsci.plugins.p4;

import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;

import java.io.File;

public class SampleServerExtension extends SimpleTestServer implements BeforeEachCallback, AfterEachCallback {

public SampleServerExtension(String root, String version) {
super(root, version);
}

@Override
public void beforeEach(ExtensionContext context) throws Exception {
clean();
extract(new File(getResources() + "/depot.tar.gz"));
restore(new File(getResources() + "/checkpoint.gz"));
upgrade();
}

@Override
public void afterEach(ExtensionContext context) throws Exception {
destroy();
}
}
40 changes: 0 additions & 40 deletions src/test/java/org/jenkinsci/plugins/p4/SampleServerRule.java

This file was deleted.

14 changes: 7 additions & 7 deletions src/test/java/org/jenkinsci/plugins/p4/SimpleTestServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class SimpleTestServer {

private static Logger logger = LoggerFactory.getLogger(SimpleTestServer.class);
private static final Logger LOGGER = LoggerFactory.getLogger(SimpleTestServer.class);

private static final String RESOURCES = "src/test/resources/";

Expand All @@ -32,7 +32,7 @@ public class SimpleTestServer {
private final String p4ver;

public SimpleTestServer(String root, String version) {
String p4d = new File(RESOURCES + version).getAbsolutePath().toString();
String p4d = new File(RESOURCES + version).getAbsolutePath();
String os = System.getProperty("os.name").toLowerCase();
if (os.contains("win")) {
p4d += "/bin.ntx64/p4d.exe";
Expand Down Expand Up @@ -84,7 +84,7 @@ public void extract(File archive) throws Exception {
TarArchiveEntry tarEntry = tarIn.getNextTarEntry();
while (tarEntry != null) {
File node = new File(p4root, tarEntry.getName());
logger.debug("extracting: " + node.getCanonicalPath());
LOGGER.debug("extracting: {}", node.getCanonicalPath());
if (tarEntry.isDirectory()) {
node.mkdirs();
} else {
Expand Down Expand Up @@ -140,7 +140,7 @@ public int getVersion() throws Exception {
executor.execute(cmdLine);

int version = 0;
for (String line : outputStream.toString(Charset.forName("UTF-8")).split("\\n")) {
for (String line : outputStream.toString(StandardCharsets.UTF_8).split("\\n")) {
if (line.startsWith("Rev. P4D")) {
Pattern p = Pattern.compile("\\d{4}\\.\\d{1}");
Matcher m = p.matcher(line);
Expand All @@ -151,7 +151,7 @@ public int getVersion() throws Exception {
}
}
}
logger.info("P4D Version: " + version);
LOGGER.info("P4D Version: {}", version);
return version;
}

Expand All @@ -164,7 +164,7 @@ private int exec(String[] args) throws Exception {
cmdLine.addArgument(arg);
}

logger.debug("EXEC: " + cmdLine.toString());
LOGGER.debug("EXEC: {}", cmdLine);

DefaultExecutor executor = new DefaultExecutor();
return executor.execute(cmdLine);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package org.jenkinsci.plugins.p4.build;

import hudson.FilePath;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.io.File;

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

public class GetExecutorTest {
class GetExecutorTest {

@Test
public void testGetExecutor() {
void testGetExecutor() {
//Windows path test
File windowsWorkspaceDir = new File("C:\\Windows\\workspace\\path");
FilePath windowsWorkspace = new FilePath(windowsWorkspaceDir);
Expand All @@ -25,7 +25,7 @@ public void testGetExecutor() {
}

@Test
public void testGetExecutorWhenUsingSubDirectory() {
void testGetExecutorWhenUsingSubDirectory() {
//Windows path test
File windowsWorkspaceDir = new File("C:\\Windows\\workspace\\path\\subDir");
FilePath windowsWorkspace = new FilePath(windowsWorkspaceDir);
Expand All @@ -40,7 +40,7 @@ public void testGetExecutorWhenUsingSubDirectory() {
}

@Test
public void testGetExecutorWhenWorkspaceHasAtSignIn() {
void testGetExecutorWhenWorkspaceHasAtSignIn() {
//Windows path test
File windowsWorkspaceDir = new File("C:\\Windows\\worksp@ce\\path");
FilePath windowsWorkspace = new FilePath(windowsWorkspaceDir);
Expand All @@ -55,7 +55,7 @@ public void testGetExecutorWhenWorkspaceHasAtSignIn() {
}

@Test
public void testGetExecutorUsingNonStandardExecutor() {
void testGetExecutorUsingNonStandardExecutor() {
//Windows path test
File windowsWorkspaceDir = new File("C:\\Windows\\workspace\\path@2");
FilePath windowsWorkspace = new FilePath(windowsWorkspaceDir);
Expand All @@ -70,7 +70,7 @@ public void testGetExecutorUsingNonStandardExecutor() {
}

@Test
public void testGetExecutorWhenUsingSubDirectoryAndNonStandardExecutor() {
void testGetExecutorWhenUsingSubDirectoryAndNonStandardExecutor() {
//Windows path test
File windowsWorkspaceDir = new File("C:\\Windows\\workspace\\path@2\\subDir");
FilePath windowsWorkspace = new FilePath(windowsWorkspaceDir);
Expand All @@ -85,7 +85,7 @@ public void testGetExecutorWhenUsingSubDirectoryAndNonStandardExecutor() {
}

@Test
public void testGetExecutorWhenWorkspaceHasAtSignInUsingNonStandardExecutor() {
void testGetExecutorWhenWorkspaceHasAtSignInUsingNonStandardExecutor() {
//Windows path test
File windowsWorkspaceDir = new File("C:\\Windows\\worksp@1ce\\path@2");
FilePath windowsWorkspace = new FilePath(windowsWorkspaceDir);
Expand Down
Loading
Loading