|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.sonyericsson.hudson.plugins.gerrit.trigger.test.SshdServerMock
public class SshdServerMock
The beginning of a mock of a sshd server. When it is done the idea is to use this to send in stream-events over the ssh connection, and make connection related tests without running Gerrit on the local machine. There is some progress but most of the predefined command types has issues.
| Nested Class Summary | |
|---|---|
static class |
SshdServerMock.CommandLookup
Utility class for looking up and creating commands. |
static class |
SshdServerMock.CommandMock
A mocked ssh command. |
static class |
SshdServerMock.EofCommandMock
A command that immediately returns 0. |
static class |
SshdServerMock.PrintLinesCommand
A Command that prints a given list of lines when the SshdServerMock.PrintLinesCommand.now() method is called and then exits with 0. |
| Field Summary | |
|---|---|
static int |
GERRIT_SSH_PORT
The default port that Gerrit usually listens to. |
static String |
GERRIT_STREAM_EVENTS
The stream-events command. |
protected static int |
MIN_SLEEP
Minimum time a thread can sleep. |
protected static int |
ONE_SECOND
One second in ms. |
protected static int |
WAIT_FOR_ERROR_OUTPUT
How long to sleep to let the ssh-keygen error output appear on stderr. |
| Constructor Summary | |
|---|---|
SshdServerMock()
|
|
| Method Summary | |
|---|---|
org.apache.sshd.server.Command |
createCommand(String s)
|
static File |
generateKeyPair()
Generates a rsa key-pair in /tmp/jenkins-testkey for use with authenticating the trigger against the mock server. |
SshdServerMock.CommandMock |
getCurrentCommand()
The last started command. |
SshdServerMock.CommandMock |
getRunningCommand(String commandSearch)
Gets the first running command that matches the given regular expression. |
void |
returnCommandFor(String commandPattern,
Class<? extends SshdServerMock.CommandMock> cmd)
Specifies a command type to instantiate and give to mina when a command matching the given regular expression is wanted. |
void |
returnCommandFor(String commandPattern,
Class<? extends SshdServerMock.CommandMock> cmd,
boolean oneShot,
Object[] arguments,
Class<?>[] types)
Specifies a command type to instantiate and give to mina when a command matching the given regular expression is wanted. |
void |
returnCommandFor(String commandPattern,
Class<? extends SshdServerMock.CommandMock> cmd,
Object[] arguments,
Class<?>[] types)
Specifies a command type to instantiate and give to mina when a command matching the given regular expression is wanted. |
protected SshdServerMock.CommandMock |
setCurrentCommand(SshdServerMock.CommandMock command)
Sets the current command being executed and adds it to the commandHistory. |
static org.apache.sshd.SshServer |
startServer(int port,
SshdServerMock server)
Starts a ssh server on the provided port. |
static org.apache.sshd.SshServer |
startServer(SshdServerMock server)
Starts a ssh server on the standard Gerrit port. |
SshdServerMock.CommandMock |
waitForCommand(String commandSearch,
int timeout)
Waits for a running command matching the provided regular expression to appear in the command history. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String GERRIT_STREAM_EVENTS
public static final int GERRIT_SSH_PORT
protected static final int WAIT_FOR_ERROR_OUTPUT
protected static final int ONE_SECOND
protected static final int MIN_SLEEP
| Constructor Detail |
|---|
public SshdServerMock()
| Method Detail |
|---|
public org.apache.sshd.server.Command createCommand(String s)
createCommand in interface org.apache.sshd.server.CommandFactoryprotected SshdServerMock.CommandMock setCurrentCommand(SshdServerMock.CommandMock command)
command - the command.
public SshdServerMock.CommandMock getCurrentCommand()
public SshdServerMock.CommandMock getRunningCommand(String commandSearch)
commandSearch - the regular expression to match.
public void returnCommandFor(String commandPattern,
Class<? extends SshdServerMock.CommandMock> cmd)
throws NoSuchMethodException
commandPattern - the regular expressioncmd - the class to create the command from. The class must have a constructor taking a single
String argument which is the command requested.
NoSuchMethodException - if there is no matching constructor.
public void returnCommandFor(String commandPattern,
Class<? extends SshdServerMock.CommandMock> cmd,
Object[] arguments,
Class<?>[] types)
throws NoSuchMethodException
commandPattern - the regular expressioncmd - the class to create the command from. The class must have a constructor where the first
argument is a String followed by the class types provided by the types parameter.arguments - the other arguments to the constructor besides the command.types - the other class types to match the constructor against.
NoSuchMethodException - if there is no matching constructor.
public void returnCommandFor(String commandPattern,
Class<? extends SshdServerMock.CommandMock> cmd,
boolean oneShot,
Object[] arguments,
Class<?>[] types)
throws NoSuchMethodException
commandPattern - the regular expressioncmd - the class to create the command from. The class must have a constructor where the first
argument is a String followed by the class types provided by the types parameter.oneShot - if this command should only be returned the first time it is called for.arguments - the other arguments to the constructor besides the command.types - the other class types to match the constructor against.
NoSuchMethodException - if there is no matching constructor.
public SshdServerMock.CommandMock waitForCommand(String commandSearch,
int timeout)
commandSearch - a regular expression.timeout - the maximum time to wait for the command in ms.
public static org.apache.sshd.SshServer startServer(int port,
SshdServerMock server)
throws IOException
port - the port to listen to.
IOException - if so.
public static org.apache.sshd.SshServer startServer(SshdServerMock server)
throws IOException
IOException - if so.GERRIT_SSH_PORT
public static File generateKeyPair()
throws IOException,
InterruptedException
IOException - if so.
InterruptedException - if interrupted while waiting for ssh-keygen to finish.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||