diff --git a/src/main/resources/index.jelly b/src/main/resources/index.jelly
new file mode 100644
index 0000000..093acfb
--- /dev/null
+++ b/src/main/resources/index.jelly
@@ -0,0 +1,4 @@
+
+
+ Jenkins pipeline steps which provides SSH facilities such as command execution or file transfer for continuous delivery.
+
diff --git a/src/test/java/org/jenkinsci/plugins/sshsteps/steps/BaseTest.java b/src/test/java/org/jenkinsci/plugins/sshsteps/steps/BaseTest.java
new file mode 100644
index 0000000..1bef193
--- /dev/null
+++ b/src/test/java/org/jenkinsci/plugins/sshsteps/steps/BaseTest.java
@@ -0,0 +1,73 @@
+package org.jenkinsci.plugins.sshsteps.steps;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.when;
+
+import hudson.EnvVars;
+import hudson.Launcher;
+import hudson.model.Run;
+import hudson.model.TaskListener;
+import java.io.IOException;
+import java.io.PrintStream;
+import org.jenkinsci.plugins.sshsteps.SSHService;
+import org.jenkinsci.plugins.sshsteps.util.TestVirtualChannel;
+import org.jenkinsci.plugins.workflow.steps.StepContext;
+import org.junit.After;
+import org.junit.Before;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+
+/**
+ * Base Test Class.
+ *
+ * @author Naresh Rayapati
+ */
+public class BaseTest {
+
+ @Mock
+ TaskListener taskListenerMock;
+ @Mock
+ Run, ?> runMock;
+ @Mock
+ EnvVars envVarsMock;
+ @Mock
+ PrintStream printStreamMock;
+ @Mock
+ SSHService sshServiceMock;
+ @Mock
+ StepContext contextMock;
+ @Mock
+ Launcher launcherMock;
+
+ private AutoCloseable closeable;
+ private MockedStatic sshService;
+
+ @Before
+ public void setUpBase() throws IOException, InterruptedException {
+
+ closeable = MockitoAnnotations.openMocks(this);
+
+ when(runMock.getCauses()).thenReturn(null);
+ when(taskListenerMock.getLogger()).thenReturn(printStreamMock);
+ doNothing().when(printStreamMock).println();
+ when(launcherMock.getChannel()).thenReturn(new TestVirtualChannel());
+
+ sshService = Mockito.mockStatic(SSHService.class);
+ sshService.when(() -> SSHService.create(any(), anyBoolean(), anyBoolean(), any())).thenReturn(sshServiceMock);
+
+ when(contextMock.get(Run.class)).thenReturn(runMock);
+ when(contextMock.get(TaskListener.class)).thenReturn(taskListenerMock);
+ when(contextMock.get(EnvVars.class)).thenReturn(envVarsMock);
+ when(contextMock.get(Launcher.class)).thenReturn(launcherMock);
+ }
+
+ @After
+ public void tearUpBase() throws Exception {
+ sshService.close();
+ closeable.close();
+ }
+}
diff --git a/src/test/java/org/jenkinsci/plugins/sshsteps/steps/CommandStepTest.java b/src/test/java/org/jenkinsci/plugins/sshsteps/steps/CommandStepTest.java
index 6cea436..8ffa0f2 100644
--- a/src/test/java/org/jenkinsci/plugins/sshsteps/steps/CommandStepTest.java
+++ b/src/test/java/org/jenkinsci/plugins/sshsteps/steps/CommandStepTest.java
@@ -1,8 +1,8 @@
package org.jenkinsci.plugins.sshsteps.steps;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -21,54 +21,16 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
/**
* Unit test cases for CommandStep class.
*
* @author Naresh Rayapati
*/
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({CommandStepTest.class, SSHService.class})
-public class CommandStepTest {
-
- @Mock
- TaskListener taskListenerMock;
- @Mock
- Run, ?> runMock;
- @Mock
- EnvVars envVarsMock;
- @Mock
- PrintStream printStreamMock;
- @Mock
- SSHService sshServiceMock;
- @Mock
- StepContext contextMock;
- @Mock
- Launcher launcherMock;
+public class CommandStepTest extends BaseTest {
CommandStep.Execution stepExecution;
- @Before
- public void setup() throws IOException, InterruptedException {
-
- when(runMock.getCauses()).thenReturn(null);
- when(taskListenerMock.getLogger()).thenReturn(printStreamMock);
- doNothing().when(printStreamMock).println();
- when(launcherMock.getChannel()).thenReturn(new TestVirtualChannel());
-
- PowerMockito.mockStatic(SSHService.class);
- when(SSHService.create(any(), anyBoolean(), anyBoolean(), any())).thenReturn(sshServiceMock);
-
- when(contextMock.get(Run.class)).thenReturn(runMock);
- when(contextMock.get(TaskListener.class)).thenReturn(taskListenerMock);
- when(contextMock.get(EnvVars.class)).thenReturn(envVarsMock);
- when(contextMock.get(Launcher.class)).thenReturn(launcherMock);
-
- }
-
@Test
public void testWithEmptyCommandThrowsIllegalArgumentException() throws Exception {
final CommandStep step = new CommandStep("");
diff --git a/src/test/java/org/jenkinsci/plugins/sshsteps/steps/GetStepTest.java b/src/test/java/org/jenkinsci/plugins/sshsteps/steps/GetStepTest.java
index 71d42a1..d1ac21a 100644
--- a/src/test/java/org/jenkinsci/plugins/sshsteps/steps/GetStepTest.java
+++ b/src/test/java/org/jenkinsci/plugins/sshsteps/steps/GetStepTest.java
@@ -1,8 +1,8 @@
package org.jenkinsci.plugins.sshsteps.steps;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -22,37 +22,18 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
/**
* Unit test cases for GetStep class.
*
* @author Naresh Rayapati
*/
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({GetStepTest.class, SSHService.class, FilePath.class})
-public class GetStepTest {
+public class GetStepTest extends BaseTest {
final String path = "test.sh";
final String filterBy = "name";
final String filterRegex = null;
- @Mock
- TaskListener taskListenerMock;
- @Mock
- Run, ?> runMock;
- @Mock
- EnvVars envVarsMock;
- @Mock
- PrintStream printStreamMock;
- @Mock
- SSHService sshServiceMock;
- @Mock
- StepContext contextMock;
- @Mock
- Launcher launcherMock;
@Mock
FilePath filePathMock;
@@ -61,23 +42,11 @@ public class GetStepTest {
@Before
public void setup() throws IOException, InterruptedException {
- when(runMock.getCauses()).thenReturn(null);
- when(taskListenerMock.getLogger()).thenReturn(printStreamMock);
- doNothing().when(printStreamMock).println();
- when(launcherMock.getChannel()).thenReturn(new TestVirtualChannel());
-
- PowerMockito.mockStatic(SSHService.class);
- when(SSHService.create(any(), anyBoolean(), anyBoolean(), any())).thenReturn(sshServiceMock);
-
when(filePathMock.child(any())).thenReturn(filePathMock);
when(filePathMock.exists()).thenReturn(true);
when(filePathMock.isDirectory()).thenReturn(false);
when(filePathMock.getRemote()).thenReturn(path);
- when(contextMock.get(Run.class)).thenReturn(runMock);
- when(contextMock.get(TaskListener.class)).thenReturn(taskListenerMock);
- when(contextMock.get(EnvVars.class)).thenReturn(envVarsMock);
- when(contextMock.get(Launcher.class)).thenReturn(launcherMock);
when(contextMock.get(FilePath.class)).thenReturn(filePathMock);
}
diff --git a/src/test/java/org/jenkinsci/plugins/sshsteps/steps/PutStepTest.java b/src/test/java/org/jenkinsci/plugins/sshsteps/steps/PutStepTest.java
index a10328b..5949577 100644
--- a/src/test/java/org/jenkinsci/plugins/sshsteps/steps/PutStepTest.java
+++ b/src/test/java/org/jenkinsci/plugins/sshsteps/steps/PutStepTest.java
@@ -1,8 +1,8 @@
package org.jenkinsci.plugins.sshsteps.steps;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -22,37 +22,18 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
/**
* Unit test cases for PutStep class.
*
* @author Naresh Rayapati
*/
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({PutStepTest.class, SSHService.class, FilePath.class})
-public class PutStepTest {
+public class PutStepTest extends BaseTest {
final String path = "test.sh";
final String filterBy = "name";
final String filterRegex = null;
- @Mock
- TaskListener taskListenerMock;
- @Mock
- Run, ?> runMock;
- @Mock
- EnvVars envVarsMock;
- @Mock
- PrintStream printStreamMock;
- @Mock
- SSHService sshServiceMock;
- @Mock
- StepContext contextMock;
- @Mock
- Launcher launcherMock;
@Mock
FilePath filePathMock;
@@ -61,23 +42,11 @@ public class PutStepTest {
@Before
public void setup() throws IOException, InterruptedException {
- when(runMock.getCauses()).thenReturn(null);
- when(taskListenerMock.getLogger()).thenReturn(printStreamMock);
- doNothing().when(printStreamMock).println();
- when(launcherMock.getChannel()).thenReturn(new TestVirtualChannel());
-
- PowerMockito.mockStatic(SSHService.class);
- when(SSHService.create(any(), anyBoolean(), anyBoolean(), any())).thenReturn(sshServiceMock);
-
when(filePathMock.child(any())).thenReturn(filePathMock);
when(filePathMock.exists()).thenReturn(true);
when(filePathMock.isDirectory()).thenReturn(false);
when(filePathMock.getRemote()).thenReturn(path);
- when(contextMock.get(Run.class)).thenReturn(runMock);
- when(contextMock.get(TaskListener.class)).thenReturn(taskListenerMock);
- when(contextMock.get(EnvVars.class)).thenReturn(envVarsMock);
- when(contextMock.get(Launcher.class)).thenReturn(launcherMock);
when(contextMock.get(FilePath.class)).thenReturn(filePathMock);
}
diff --git a/src/test/java/org/jenkinsci/plugins/sshsteps/steps/RemoveStepTest.java b/src/test/java/org/jenkinsci/plugins/sshsteps/steps/RemoveStepTest.java
index 5b36ae9..ad6c9f0 100644
--- a/src/test/java/org/jenkinsci/plugins/sshsteps/steps/RemoveStepTest.java
+++ b/src/test/java/org/jenkinsci/plugins/sshsteps/steps/RemoveStepTest.java
@@ -1,8 +1,8 @@
package org.jenkinsci.plugins.sshsteps.steps;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -22,35 +22,16 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
/**
* Unit test cases for RemoveStep class.
*
* @author Naresh Rayapati
*/
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({RemoveStepTest.class, SSHService.class, FilePath.class})
-public class RemoveStepTest {
+public class RemoveStepTest extends BaseTest {
final String path = "test.sh";
- @Mock
- TaskListener taskListenerMock;
- @Mock
- Run, ?> runMock;
- @Mock
- EnvVars envVarsMock;
- @Mock
- PrintStream printStreamMock;
- @Mock
- SSHService sshServiceMock;
- @Mock
- StepContext contextMock;
- @Mock
- Launcher launcherMock;
@Mock
FilePath filePathMock;
@@ -59,23 +40,11 @@ public class RemoveStepTest {
@Before
public void setup() throws IOException, InterruptedException {
- when(runMock.getCauses()).thenReturn(null);
- when(taskListenerMock.getLogger()).thenReturn(printStreamMock);
- doNothing().when(printStreamMock).println();
- when(launcherMock.getChannel()).thenReturn(new TestVirtualChannel());
-
- PowerMockito.mockStatic(SSHService.class);
- when(SSHService.create(any(), anyBoolean(), anyBoolean(), any())).thenReturn(sshServiceMock);
-
when(filePathMock.child(any())).thenReturn(filePathMock);
when(filePathMock.exists()).thenReturn(true);
when(filePathMock.isDirectory()).thenReturn(false);
when(filePathMock.getRemote()).thenReturn(path);
- when(contextMock.get(Run.class)).thenReturn(runMock);
- when(contextMock.get(TaskListener.class)).thenReturn(taskListenerMock);
- when(contextMock.get(EnvVars.class)).thenReturn(envVarsMock);
- when(contextMock.get(Launcher.class)).thenReturn(launcherMock);
when(contextMock.get(FilePath.class)).thenReturn(filePathMock);
}
diff --git a/src/test/java/org/jenkinsci/plugins/sshsteps/steps/ScriptStepTest.java b/src/test/java/org/jenkinsci/plugins/sshsteps/steps/ScriptStepTest.java
index d46e152..6ee415c 100644
--- a/src/test/java/org/jenkinsci/plugins/sshsteps/steps/ScriptStepTest.java
+++ b/src/test/java/org/jenkinsci/plugins/sshsteps/steps/ScriptStepTest.java
@@ -1,8 +1,8 @@
package org.jenkinsci.plugins.sshsteps.steps;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -22,35 +22,16 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
/**
* Unit test cases for ScriptStep class.
*
* @author Naresh Rayapati
*/
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({ScriptStepTest.class, SSHService.class, FilePath.class})
-public class ScriptStepTest {
+public class ScriptStepTest extends BaseTest {
final String scriptName = "test.sh";
- @Mock
- TaskListener taskListenerMock;
- @Mock
- Run, ?> runMock;
- @Mock
- EnvVars envVarsMock;
- @Mock
- PrintStream printStreamMock;
- @Mock
- SSHService sshServiceMock;
- @Mock
- StepContext contextMock;
- @Mock
- Launcher launcherMock;
@Mock
FilePath filePathMock;
@@ -59,23 +40,11 @@ public class ScriptStepTest {
@Before
public void setup() throws IOException, InterruptedException {
- when(runMock.getCauses()).thenReturn(null);
- when(taskListenerMock.getLogger()).thenReturn(printStreamMock);
- doNothing().when(printStreamMock).println();
- when(launcherMock.getChannel()).thenReturn(new TestVirtualChannel());
-
- PowerMockito.mockStatic(SSHService.class);
- when(SSHService.create(any(), anyBoolean(), anyBoolean(), any())).thenReturn(sshServiceMock);
-
when(filePathMock.child(any())).thenReturn(filePathMock);
when(filePathMock.exists()).thenReturn(true);
when(filePathMock.isDirectory()).thenReturn(false);
when(filePathMock.getRemote()).thenReturn(scriptName);
- when(contextMock.get(Run.class)).thenReturn(runMock);
- when(contextMock.get(TaskListener.class)).thenReturn(taskListenerMock);
- when(contextMock.get(EnvVars.class)).thenReturn(envVarsMock);
- when(contextMock.get(Launcher.class)).thenReturn(launcherMock);
when(contextMock.get(FilePath.class)).thenReturn(filePathMock);
}