Update socket and swt dependency on gclc last stable
This commit is contained in:
@@ -87,7 +87,7 @@ of Emmanuel Bigeon. -->
|
||||
<dependency>
|
||||
<groupId>fr.bigeon</groupId>
|
||||
<artifactId>gclc</artifactId>
|
||||
<version>1.1.1</version>
|
||||
<version>1.1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.bigeon</groupId>
|
||||
|
||||
@@ -50,7 +50,7 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import fr.bigeon.gclc.ConsoleApplication;
|
||||
import fr.bigeon.gclc.ConsoleManager;
|
||||
import fr.bigeon.gclc.manager.ConsoleManager;
|
||||
import fr.bigeon.smu.StringEncoder;
|
||||
|
||||
/** This is a socket communicating console consoleManager
|
||||
|
||||
@@ -44,7 +44,7 @@ import java.io.PrintWriter;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import fr.bigeon.gclc.ConsoleManager;
|
||||
import fr.bigeon.gclc.manager.ConsoleManager;
|
||||
import fr.bigeon.smu.StringEncoder;
|
||||
|
||||
/** The console manager for socket communication
|
||||
@@ -154,5 +154,11 @@ public class ThreadedServerConsoleManager implements ConsoleManager {
|
||||
return prompt;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.manager.ConsoleManager#close() */
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,21 +38,89 @@
|
||||
*/
|
||||
package fr.bigeon.gclc.socket;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import fr.bigeon.gclc.ConsoleApplication;
|
||||
import fr.bigeon.gclc.ConsoleManager;
|
||||
import fr.bigeon.gclc.system.SystemConsoleManager;
|
||||
import fr.bigeon.gclc.manager.ConsoleManager;
|
||||
import fr.bigeon.gclc.manager.SystemConsoleManager;
|
||||
|
||||
/** Test class for {@link ConsoleRunnable}
|
||||
*
|
||||
* @author Emmanuel Bigeon */
|
||||
@SuppressWarnings({"static-method", "unused"})
|
||||
@SuppressWarnings({"static-method", "unused", "javadoc"})
|
||||
public class ConsoleRunnableTest {
|
||||
|
||||
/**
|
||||
* Test method for {@link fr.bigeon.gclc.socket.ConsoleRunnable#ConsoleRunnable(fr.bigeon.gclc.ConsoleApplication, java.lang.Object)}.
|
||||
*/
|
||||
/** <p>
|
||||
* TODO
|
||||
*
|
||||
* @author Emmanuel Bigeon */
|
||||
private static final class ConsoleManagerTestImplementation
|
||||
implements ConsoleManager {
|
||||
int i = 0;
|
||||
String[] cmds;
|
||||
|
||||
/** @param cmds */
|
||||
public ConsoleManagerTestImplementation(String[] cmds) {
|
||||
super();
|
||||
this.cmds = cmds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPrompt(String prompt) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrompt() {
|
||||
// Not used in test
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public String prompt() {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) { // NOSONAR
|
||||
// do nothing
|
||||
}
|
||||
i++;
|
||||
if (i == cmds.length) {
|
||||
i = 0;
|
||||
}
|
||||
return cmds[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String prompt(String message) {
|
||||
return prompt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println(String message) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(String text) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.socket.ConsoleRunnable#ConsoleRunnable(fr.bigeon.gclc.ConsoleApplication, java.lang.Object)}
|
||||
* . */
|
||||
@Test
|
||||
public void testConsoleRunnable() {
|
||||
Object lock = new Object();
|
||||
@@ -62,56 +130,13 @@ public class ConsoleRunnableTest {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link fr.bigeon.gclc.socket.ConsoleRunnable#run()}.
|
||||
*/
|
||||
/** Test method for {@link fr.bigeon.gclc.socket.ConsoleRunnable#run()}. */
|
||||
@Test
|
||||
public void testRunFlow() {
|
||||
Object lock = new Object();
|
||||
ConsoleApplication app = new ConsoleTestApplication(
|
||||
new ConsoleManager() {
|
||||
|
||||
@Override
|
||||
public void setPrompt(String prompt) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrompt() {
|
||||
// Not used in test
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public String prompt() {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) { // NOSONAR
|
||||
// do nothing
|
||||
}
|
||||
return "mock"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public String prompt(String message) {
|
||||
return prompt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println(String message) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(String text) {
|
||||
// do nothing
|
||||
}
|
||||
});
|
||||
new ConsoleManagerTestImplementation(
|
||||
new String[] {"test", ConsoleTestApplication.EXIT}));
|
||||
ConsoleRunnable runnable = new ConsoleRunnable(app, lock);
|
||||
|
||||
Thread th = new Thread(runnable);
|
||||
@@ -120,55 +145,13 @@ public class ConsoleRunnableTest {
|
||||
runnable.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link fr.bigeon.gclc.socket.ConsoleRunnable#stop()}.
|
||||
*/
|
||||
/** Test method for {@link fr.bigeon.gclc.socket.ConsoleRunnable#stop()}. */
|
||||
@Test
|
||||
public void testStop() {
|
||||
Object lock = new Object();
|
||||
ConsoleApplication app = new ConsoleTestApplication(
|
||||
new ConsoleManager() {
|
||||
|
||||
@Override
|
||||
public void setPrompt(String prompt) {
|
||||
throw new RuntimeException("Not implemented yet"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrompt() {
|
||||
throw new RuntimeException("Not implemented yet"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public String prompt() {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "mock"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public String prompt(String message) {
|
||||
throw new RuntimeException("Not implemented yet"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println(String message) {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println() {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(String text) {
|
||||
//
|
||||
}
|
||||
});
|
||||
new ConsoleManagerTestImplementation(
|
||||
new String[] {"test", ConsoleTestApplication.EXIT}));
|
||||
ConsoleRunnable runnable = new ConsoleRunnable(app, lock);
|
||||
runnable.stop();
|
||||
Thread th = new Thread(runnable);
|
||||
@@ -182,48 +165,8 @@ public class ConsoleRunnableTest {
|
||||
public void testRun() {
|
||||
Object lock = new Object();
|
||||
ConsoleApplication app = new ConsoleTestApplication(
|
||||
new ConsoleManager() {
|
||||
|
||||
@Override
|
||||
public void setPrompt(String prompt) {
|
||||
throw new RuntimeException("Not implemented yet"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrompt() {
|
||||
throw new RuntimeException("Not implemented yet"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public String prompt() {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "exit"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public String prompt(String message) {
|
||||
throw new RuntimeException("Not implemented yet"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println(String message) {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println() {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(String text) {
|
||||
//
|
||||
}
|
||||
});
|
||||
new ConsoleManagerTestImplementation(
|
||||
new String[] {"test", ConsoleTestApplication.EXIT}));
|
||||
ConsoleRunnable runnable = new ConsoleRunnable(app, lock);
|
||||
runnable.run();
|
||||
}
|
||||
|
||||
@@ -35,9 +35,11 @@
|
||||
package fr.bigeon.gclc.socket;
|
||||
|
||||
import fr.bigeon.gclc.ConsoleApplication;
|
||||
import fr.bigeon.gclc.ConsoleManager;
|
||||
import fr.bigeon.gclc.command.Command;
|
||||
import fr.bigeon.gclc.command.ICommand;
|
||||
import fr.bigeon.gclc.exception.InvalidCommandName;
|
||||
import fr.bigeon.gclc.manager.ConsoleManager;
|
||||
import fr.bigeon.gclc.prompt.CLIPrompterMessages;
|
||||
|
||||
/** A test-purpose application
|
||||
*
|
||||
@@ -50,11 +52,11 @@ public class ConsoleTestApplication extends ConsoleApplication {
|
||||
/** @param manager the manager */
|
||||
@SuppressWarnings("nls")
|
||||
public ConsoleTestApplication(final ConsoleManager manager) {
|
||||
super(manager, EXIT,
|
||||
"Welcome to the test application. Type help or test.",
|
||||
super(manager, "Welcome to the test application. Type help or test.",
|
||||
"See you");
|
||||
addHelpCommand("help");
|
||||
try {
|
||||
add(new ExitCommand(EXIT, this));
|
||||
addHelpCommand("help");
|
||||
add(new Command("test") {
|
||||
|
||||
@Override
|
||||
@@ -71,4 +73,55 @@ public class ConsoleTestApplication extends ConsoleApplication {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/** <p>
|
||||
* A command to exit a {@link ConsoleApplication}.
|
||||
*
|
||||
* @author Emmanuel BIGEON */
|
||||
class ExitCommand implements ICommand {
|
||||
/** The exit command manual message key */
|
||||
private static final String EXIT_MAN = "exit.man"; //$NON-NLS-1$
|
||||
/** The tip of the exit command */
|
||||
private static final String EXIT_TIP = "exit.tip"; //$NON-NLS-1$
|
||||
/** The application that will be exited when this command runs */
|
||||
private final ConsoleApplication app;
|
||||
/** The exit command name */
|
||||
private final String name;
|
||||
|
||||
/** @param name the name of the command
|
||||
* @param app the application to exit */
|
||||
public ExitCommand(String name, ConsoleApplication app) {
|
||||
this.name = name;
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
/** The actions to take before exiting */
|
||||
public void beforeExit() {
|
||||
// Do nothing by default
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void execute(String... args) {
|
||||
beforeExit();
|
||||
app.exit();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.command.ICommand#getCommandName() */
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void help(ConsoleManager helpManager, String... args) {
|
||||
helpManager.println(
|
||||
CLIPrompterMessages.getString(EXIT_MAN, (Object[]) args));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return CLIPrompterMessages.getString(EXIT_TIP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user