From b06523b78c79ceab23b879da7f395bcb5d20670e Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Mon, 11 Apr 2016 09:09:50 -0500 Subject: Bug 490273 - Move tests to JUnit 4 Move console tests to archived folder Change-Id: I158ce0adae4c50853368308c946ebf42b29c6166 Signed-off-by: Thomas Watson --- .../.classpath | 8 + .../org.eclipse.equinox.console.ssh.tests/.project | 28 ++ .../.settings/org.eclipse.jdt.core.prefs | 8 + .../META-INF/MANIFEST.MF | 12 + .../build.properties | 4 + .../forceQualifierUpdate.txt | 2 + .../hostkey.ser | Bin 0 -> 1201 bytes ...eclipse.equinox.console.ssh.SshShellTests_store | 3 + .../org.eclipse.equinox.console.ssh.tests/pom.xml | 24 ++ .../equinox/console/jaas/RolePrincipalTests.java | 45 +++ .../equinox/console/jaas/UserPrincipalTests.java | 99 +++++++ .../equinox/console/ssh/SshCommandTests.java | 188 ++++++++++++ .../ssh/SshCommandWithConfigAdminTests.java | 320 +++++++++++++++++++++ .../equinox/console/ssh/SshInputHandlerTests.java | 47 +++ .../equinox/console/ssh/SshInputScannerTests.java | 67 +++++ .../eclipse/equinox/console/ssh/SshShellTests.java | 152 ++++++++++ .../equinox/console/ssh/UserAdminCommandTests.java | 119 ++++++++ .../equinox/console/storage/DigestUtilTests.java | 56 ++++ .../console/storage/SecureUserStoreTests.java | 109 +++++++ .../org.eclipse.equinox.console.tests/.classpath | 8 + .../org.eclipse.equinox.console.tests/.gitignore | 1 + .../org.eclipse.equinox.console.tests/.project | 28 ++ .../.settings/org.eclipse.core.runtime.prefs | 2 + .../.settings/org.eclipse.jdt.core.prefs | 7 + .../META-INF/MANIFEST.MF | 12 + .../org.eclipse.equinox.console.tests/about.html | 28 ++ .../build.properties | 4 + .../forceQualifierUpdate.txt | 2 + .../org.eclipse.equinox.console.tests/pom.xml | 24 ++ .../src/org/eclipse/equinox/console/Activator.java | 35 +++ .../console/command/adapter/ActivatorTests.java | 81 ++++++ .../adapter/CommandProviderAdapterTest.java | 62 ++++ .../console/common/ConsoleInputStreamTests.java | 45 +++ .../console/common/ConsoleOutputStreamTests.java | 41 +++ .../equinox/console/common/HistoryHolderTests.java | 67 +++++ .../console/common/SimpleByteBufferTests.java | 96 +++++++ .../console/completion/CommandLineParserTests.java | 86 ++++++ .../completion/CommandNamesCompleterTests.java | 82 ++++++ .../console/completion/CompletionHandlerTests.java | 175 +++++++++++ .../completion/FileNamesCompleterTests.java | 97 +++++++ .../console/completion/StringsCompleterTests.java | 62 ++++ .../completion/VariableNamesCompleterTests.java | 59 ++++ .../supportability/ConsoleInputHandlerTests.java | 56 ++++ .../supportability/ConsoleInputScannerTests.java | 268 +++++++++++++++++ .../telnet/NegotiationFinishedCallbackTests.java | 27 ++ .../equinox/console/telnet/TelnetCommandTests.java | 83 ++++++ .../telnet/TelnetCommandWithConfigAdminTests.java | 206 +++++++++++++ .../console/telnet/TelnetConnectionTests.java | 99 +++++++ .../console/telnet/TelnetDisconnectionTest.java | 104 +++++++ .../console/telnet/TelnetInputHandlerTests.java | 49 ++++ .../console/telnet/TelnetInputScannerTests.java | 223 ++++++++++++++ .../console/telnet/TelnetOutputStreamTests.java | 39 +++ .../equinox/console/telnet/TelnetServerTests.java | 125 ++++++++ .../.classpath | 8 - .../org.eclipse.equinox.console.ssh.tests/.project | 28 -- .../.settings/org.eclipse.jdt.core.prefs | 8 - .../META-INF/MANIFEST.MF | 12 - .../build.properties | 4 - .../forceQualifierUpdate.txt | 2 - .../hostkey.ser | Bin 1201 -> 0 bytes ...eclipse.equinox.console.ssh.SshShellTests_store | 3 - .../org.eclipse.equinox.console.ssh.tests/pom.xml | 24 -- .../equinox/console/jaas/RolePrincipalTests.java | 45 --- .../equinox/console/jaas/UserPrincipalTests.java | 99 ------- .../equinox/console/ssh/SshCommandTests.java | 188 ------------ .../ssh/SshCommandWithConfigAdminTests.java | 320 --------------------- .../equinox/console/ssh/SshInputHandlerTests.java | 47 --- .../equinox/console/ssh/SshInputScannerTests.java | 67 ----- .../eclipse/equinox/console/ssh/SshShellTests.java | 152 ---------- .../equinox/console/ssh/UserAdminCommandTests.java | 119 -------- .../equinox/console/storage/DigestUtilTests.java | 56 ---- .../console/storage/SecureUserStoreTests.java | 109 ------- .../org.eclipse.equinox.console.tests/.classpath | 8 - .../org.eclipse.equinox.console.tests/.gitignore | 1 - bundles/org.eclipse.equinox.console.tests/.project | 28 -- .../.settings/org.eclipse.core.runtime.prefs | 2 - .../.settings/org.eclipse.jdt.core.prefs | 7 - .../META-INF/MANIFEST.MF | 12 - .../org.eclipse.equinox.console.tests/about.html | 28 -- .../build.properties | 4 - .../forceQualifierUpdate.txt | 2 - bundles/org.eclipse.equinox.console.tests/pom.xml | 24 -- .../src/org/eclipse/equinox/console/Activator.java | 35 --- .../console/command/adapter/ActivatorTests.java | 81 ------ .../adapter/CommandProviderAdapterTest.java | 62 ---- .../console/common/ConsoleInputStreamTests.java | 45 --- .../console/common/ConsoleOutputStreamTests.java | 41 --- .../equinox/console/common/HistoryHolderTests.java | 67 ----- .../console/common/SimpleByteBufferTests.java | 96 ------- .../console/completion/CommandLineParserTests.java | 86 ------ .../completion/CommandNamesCompleterTests.java | 82 ------ .../console/completion/CompletionHandlerTests.java | 175 ----------- .../completion/FileNamesCompleterTests.java | 97 ------- .../console/completion/StringsCompleterTests.java | 62 ---- .../completion/VariableNamesCompleterTests.java | 59 ---- .../supportability/ConsoleInputHandlerTests.java | 56 ---- .../supportability/ConsoleInputScannerTests.java | 268 ----------------- .../telnet/NegotiationFinishedCallbackTests.java | 27 -- .../equinox/console/telnet/TelnetCommandTests.java | 83 ------ .../telnet/TelnetCommandWithConfigAdminTests.java | 206 ------------- .../console/telnet/TelnetConnectionTests.java | 99 ------- .../console/telnet/TelnetDisconnectionTest.java | 104 ------- .../console/telnet/TelnetInputHandlerTests.java | 49 ---- .../console/telnet/TelnetInputScannerTests.java | 223 -------------- .../console/telnet/TelnetOutputStreamTests.java | 39 --- .../equinox/console/telnet/TelnetServerTests.java | 125 -------- 106 files changed, 3674 insertions(+), 3674 deletions(-) create mode 100755 bundles/archived/org.eclipse.equinox.console.ssh.tests/.classpath create mode 100755 bundles/archived/org.eclipse.equinox.console.ssh.tests/.project create mode 100755 bundles/archived/org.eclipse.equinox.console.ssh.tests/.settings/org.eclipse.jdt.core.prefs create mode 100755 bundles/archived/org.eclipse.equinox.console.ssh.tests/META-INF/MANIFEST.MF create mode 100755 bundles/archived/org.eclipse.equinox.console.ssh.tests/build.properties create mode 100644 bundles/archived/org.eclipse.equinox.console.ssh.tests/forceQualifierUpdate.txt create mode 100755 bundles/archived/org.eclipse.equinox.console.ssh.tests/hostkey.ser create mode 100755 bundles/archived/org.eclipse.equinox.console.ssh.tests/org.eclipse.equinox.console.ssh.SshShellTests_store create mode 100644 bundles/archived/org.eclipse.equinox.console.ssh.tests/pom.xml create mode 100755 bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/jaas/RolePrincipalTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/jaas/UserPrincipalTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshCommandTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshCommandWithConfigAdminTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshInputHandlerTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshInputScannerTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshShellTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/UserAdminCommandTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/storage/DigestUtilTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/storage/SecureUserStoreTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/.classpath create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/.gitignore create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/.project create mode 100644 bundles/archived/org.eclipse.equinox.console.tests/.settings/org.eclipse.core.runtime.prefs create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/.settings/org.eclipse.jdt.core.prefs create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/META-INF/MANIFEST.MF create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/about.html create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/build.properties create mode 100644 bundles/archived/org.eclipse.equinox.console.tests/forceQualifierUpdate.txt create mode 100644 bundles/archived/org.eclipse.equinox.console.tests/pom.xml create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/Activator.java create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/command/adapter/ActivatorTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/command/adapter/CommandProviderAdapterTest.java create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/ConsoleInputStreamTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/ConsoleOutputStreamTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/HistoryHolderTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/SimpleByteBufferTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CommandLineParserTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CommandNamesCompleterTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CompletionHandlerTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/FileNamesCompleterTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/StringsCompleterTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/VariableNamesCompleterTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/supportability/ConsoleInputHandlerTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/supportability/ConsoleInputScannerTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/NegotiationFinishedCallbackTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandWithConfigAdminTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetConnectionTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetDisconnectionTest.java create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetInputHandlerTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetInputScannerTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetOutputStreamTests.java create mode 100755 bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetServerTests.java delete mode 100755 bundles/org.eclipse.equinox.console.ssh.tests/.classpath delete mode 100755 bundles/org.eclipse.equinox.console.ssh.tests/.project delete mode 100755 bundles/org.eclipse.equinox.console.ssh.tests/.settings/org.eclipse.jdt.core.prefs delete mode 100755 bundles/org.eclipse.equinox.console.ssh.tests/META-INF/MANIFEST.MF delete mode 100755 bundles/org.eclipse.equinox.console.ssh.tests/build.properties delete mode 100644 bundles/org.eclipse.equinox.console.ssh.tests/forceQualifierUpdate.txt delete mode 100755 bundles/org.eclipse.equinox.console.ssh.tests/hostkey.ser delete mode 100755 bundles/org.eclipse.equinox.console.ssh.tests/org.eclipse.equinox.console.ssh.SshShellTests_store delete mode 100644 bundles/org.eclipse.equinox.console.ssh.tests/pom.xml delete mode 100755 bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/jaas/RolePrincipalTests.java delete mode 100755 bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/jaas/UserPrincipalTests.java delete mode 100755 bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshCommandTests.java delete mode 100755 bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshCommandWithConfigAdminTests.java delete mode 100755 bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshInputHandlerTests.java delete mode 100755 bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshInputScannerTests.java delete mode 100755 bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshShellTests.java delete mode 100755 bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/UserAdminCommandTests.java delete mode 100755 bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/storage/DigestUtilTests.java delete mode 100755 bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/storage/SecureUserStoreTests.java delete mode 100755 bundles/org.eclipse.equinox.console.tests/.classpath delete mode 100755 bundles/org.eclipse.equinox.console.tests/.gitignore delete mode 100755 bundles/org.eclipse.equinox.console.tests/.project delete mode 100644 bundles/org.eclipse.equinox.console.tests/.settings/org.eclipse.core.runtime.prefs delete mode 100755 bundles/org.eclipse.equinox.console.tests/.settings/org.eclipse.jdt.core.prefs delete mode 100755 bundles/org.eclipse.equinox.console.tests/META-INF/MANIFEST.MF delete mode 100755 bundles/org.eclipse.equinox.console.tests/about.html delete mode 100755 bundles/org.eclipse.equinox.console.tests/build.properties delete mode 100644 bundles/org.eclipse.equinox.console.tests/forceQualifierUpdate.txt delete mode 100644 bundles/org.eclipse.equinox.console.tests/pom.xml delete mode 100755 bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/Activator.java delete mode 100755 bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/command/adapter/ActivatorTests.java delete mode 100755 bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/command/adapter/CommandProviderAdapterTest.java delete mode 100755 bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/ConsoleInputStreamTests.java delete mode 100755 bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/ConsoleOutputStreamTests.java delete mode 100755 bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/HistoryHolderTests.java delete mode 100755 bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/SimpleByteBufferTests.java delete mode 100755 bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CommandLineParserTests.java delete mode 100755 bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CommandNamesCompleterTests.java delete mode 100755 bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CompletionHandlerTests.java delete mode 100755 bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/FileNamesCompleterTests.java delete mode 100755 bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/StringsCompleterTests.java delete mode 100755 bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/VariableNamesCompleterTests.java delete mode 100755 bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/supportability/ConsoleInputHandlerTests.java delete mode 100755 bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/supportability/ConsoleInputScannerTests.java delete mode 100755 bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/NegotiationFinishedCallbackTests.java delete mode 100755 bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandTests.java delete mode 100755 bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandWithConfigAdminTests.java delete mode 100755 bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetConnectionTests.java delete mode 100755 bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetDisconnectionTest.java delete mode 100755 bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetInputHandlerTests.java delete mode 100755 bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetInputScannerTests.java delete mode 100755 bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetOutputStreamTests.java delete mode 100755 bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetServerTests.java diff --git a/bundles/archived/org.eclipse.equinox.console.ssh.tests/.classpath b/bundles/archived/org.eclipse.equinox.console.ssh.tests/.classpath new file mode 100755 index 000000000..23f11b11a --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.ssh.tests/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/bundles/archived/org.eclipse.equinox.console.ssh.tests/.project b/bundles/archived/org.eclipse.equinox.console.ssh.tests/.project new file mode 100755 index 000000000..ffacebcdd --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.ssh.tests/.project @@ -0,0 +1,28 @@ + + + org.eclipse.equinox.console.ssh.tests + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/bundles/archived/org.eclipse.equinox.console.ssh.tests/.settings/org.eclipse.jdt.core.prefs b/bundles/archived/org.eclipse.equinox.console.ssh.tests/.settings/org.eclipse.jdt.core.prefs new file mode 100755 index 000000000..c3a62744c --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.ssh.tests/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Tue Oct 18 16:14:30 EEST 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/bundles/archived/org.eclipse.equinox.console.ssh.tests/META-INF/MANIFEST.MF b/bundles/archived/org.eclipse.equinox.console.ssh.tests/META-INF/MANIFEST.MF new file mode 100755 index 000000000..20f5ae4ba --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.ssh.tests/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ssh Tests +Bundle-SymbolicName: org.eclipse.equinox.console.ssh.tests +Bundle-Version: 1.0.0.qualifier +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Import-Package: junit.framework;version="4.8.1", + org.apache.sshd.client.future, + org.easymock;version="2.4.0", + org.junit;version="4.8.1" +Fragment-Host: org.eclipse.equinox.console.ssh, org.eclipse.equinox.console diff --git a/bundles/archived/org.eclipse.equinox.console.ssh.tests/build.properties b/bundles/archived/org.eclipse.equinox.console.ssh.tests/build.properties new file mode 100755 index 000000000..34d2e4d2d --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.ssh.tests/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/archived/org.eclipse.equinox.console.ssh.tests/forceQualifierUpdate.txt b/bundles/archived/org.eclipse.equinox.console.ssh.tests/forceQualifierUpdate.txt new file mode 100644 index 000000000..56f1032a8 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.ssh.tests/forceQualifierUpdate.txt @@ -0,0 +1,2 @@ +# To force a version qualifier update add the bug here +Bug 403352 - Update all parent versions to match our build stream diff --git a/bundles/archived/org.eclipse.equinox.console.ssh.tests/hostkey.ser b/bundles/archived/org.eclipse.equinox.console.ssh.tests/hostkey.ser new file mode 100755 index 000000000..cb61e708c Binary files /dev/null and b/bundles/archived/org.eclipse.equinox.console.ssh.tests/hostkey.ser differ diff --git a/bundles/archived/org.eclipse.equinox.console.ssh.tests/org.eclipse.equinox.console.ssh.SshShellTests_store b/bundles/archived/org.eclipse.equinox.console.ssh.tests/org.eclipse.equinox.console.ssh.SshShellTests_store new file mode 100755 index 000000000..f80649daa --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.ssh.tests/org.eclipse.equinox.console.ssh.SshShellTests_store @@ -0,0 +1,3 @@ +#Wed Oct 19 10:21:35 EEST 2011 +/ssh/username/roles= +/ssh/username/password=0d85584b3529eaac630d1b7ddde2418308d56317 diff --git a/bundles/archived/org.eclipse.equinox.console.ssh.tests/pom.xml b/bundles/archived/org.eclipse.equinox.console.ssh.tests/pom.xml new file mode 100644 index 000000000..38444f5ee --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.ssh.tests/pom.xml @@ -0,0 +1,24 @@ + + + + 4.0.0 + + tests-pom + org.eclipse.equinox.bundles + 4.6.0-SNAPSHOT + ../../tests-pom/ + + org.eclipse.equinox + org.eclipse.equinox.console.ssh.tests + 1.0.0-SNAPSHOT + eclipse-test-plugin + diff --git a/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/jaas/RolePrincipalTests.java b/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/jaas/RolePrincipalTests.java new file mode 100755 index 000000000..edae26f3b --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/jaas/RolePrincipalTests.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial API and implementation + *******************************************************************************/ + +package org.eclipse.equinox.console.jaas; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class RolePrincipalTests { + + private static final String ROLE_NAME = "administrator"; + + @Test + public void testHashCode() { + RolePrincipal role = new RolePrincipal(ROLE_NAME); + assertEquals("Role hash code not as expected", 73 + ROLE_NAME.hashCode(), role.hashCode()); + } + + @Test + public void testGetName() { + RolePrincipal role = new RolePrincipal(ROLE_NAME); + assertEquals("Role not as expected", ROLE_NAME, role.getName()); + } + + @Test + public void testEqualsObject() { + RolePrincipal role = new RolePrincipal(ROLE_NAME); + RolePrincipal sameRole = new RolePrincipal(ROLE_NAME); + RolePrincipal emptyRole = new RolePrincipal(null); + + assertTrue("Roles should be equal", role.equals(role)); + assertTrue("Roles should be equal", role.equals(sameRole)); + assertFalse("Roles should not be equal", role.equals(emptyRole)); + } + +} diff --git a/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/jaas/UserPrincipalTests.java b/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/jaas/UserPrincipalTests.java new file mode 100755 index 000000000..50239be1c --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/jaas/UserPrincipalTests.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial API and implementation + *******************************************************************************/ + +package org.eclipse.equinox.console.jaas; + +import static org.junit.Assert.*; + +import java.util.Set; + +import org.junit.BeforeClass; +import org.junit.Test; + +public class UserPrincipalTests { + + private static final String USERNAME = "username"; + private static final String PASSWORD = "password"; + private static final String OTHERUSER = "otheruser"; + private static final String OTHERPASSWORD = "otherpass"; + private static final String WRONG_PASS = "wrong_pass"; + private static final String ROLE = "administrator"; + private static final String OTHERROLE = "otherrole"; + + @Test + public void testHashCode() { + UserPrincipal user = new UserPrincipal(USERNAME, PASSWORD); + RolePrincipal role = new RolePrincipal(ROLE); + user.addRole(role); + + int expectedHash = 73 + USERNAME.hashCode(); + expectedHash = 73*expectedHash + PASSWORD.hashCode(); + expectedHash = 73*expectedHash + role.hashCode(); + assertEquals("User hash code not as expected", expectedHash, user.hashCode()); + } + + @Test + public void testGetName() { + UserPrincipal user = new UserPrincipal(USERNAME, PASSWORD); + assertEquals("Username not as expected", USERNAME, user.getName()); + } + + @Test + public void testAuthenticate() { + UserPrincipal user = new UserPrincipal(USERNAME, PASSWORD); + assertTrue("User should be successfully authenticated", user.authenticate(PASSWORD.toCharArray())); + assertFalse("User should not be authenticated", user.authenticate(WRONG_PASS.toCharArray())); + } + + @Test + public void testGetRoles() { + UserPrincipal user = new UserPrincipal(USERNAME, PASSWORD); + RolePrincipal role = new RolePrincipal(ROLE); + user.addRole(role); + Set roles = user.getRoles(); + assertEquals("There should be one role", 1, roles.size()); + assertTrue("User roles should contain the role administrator", roles.contains(role)); + } + + @Test + public void testEqualsObject() { + UserPrincipal user = new UserPrincipal(USERNAME, PASSWORD); + RolePrincipal role = new RolePrincipal(ROLE); + user.addRole(role); + + UserPrincipal sameUser = new UserPrincipal(USERNAME, PASSWORD); + RolePrincipal sameRole = new RolePrincipal(ROLE); + sameUser.addRole(sameRole); + + UserPrincipal otherUser = new UserPrincipal(OTHERUSER, OTHERPASSWORD); + RolePrincipal otherRole = new RolePrincipal(OTHERROLE); + otherUser.addRole(otherRole); + + UserPrincipal userOtherRole = new UserPrincipal(USERNAME, PASSWORD); + RolePrincipal otherRolePrincipal = new RolePrincipal(OTHERROLE); + userOtherRole.addRole(otherRolePrincipal); + + assertTrue("User should be equal to itself", user.equals(user)); + assertTrue("Users should be equal", user.equals(sameUser)); + assertFalse("Users should not be equal", user.equals(otherUser)); + assertFalse("Users should not be equal", user.equals(userOtherRole)); + } + + @Test + public void testDestroy() { + UserPrincipal user = new UserPrincipal(USERNAME, PASSWORD); + UserPrincipal same = new UserPrincipal(USERNAME, PASSWORD); + + user.destroy(); + assertFalse("Users should not be equal", user.equals(same)); + } + +} diff --git a/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshCommandTests.java b/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshCommandTests.java new file mode 100755 index 000000000..7fab9788b --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshCommandTests.java @@ -0,0 +1,188 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial API and implementation + *******************************************************************************/ + +package org.eclipse.equinox.console.ssh; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.PrintStream; +import java.io.PrintWriter; +import java.io.StringBufferInputStream; +import java.util.Dictionary; +import java.util.HashMap; +import java.util.Map; + +import org.apache.felix.service.command.CommandProcessor; +import org.apache.felix.service.command.CommandSession; +import org.apache.sshd.ClientChannel; +import org.apache.sshd.ClientSession; +import org.apache.sshd.SshClient; +import org.apache.sshd.client.future.ConnectFuture; +import org.apache.sshd.client.future.DefaultConnectFuture; +import org.apache.sshd.server.Environment; +import org.easymock.EasyMock; +import org.eclipse.equinox.console.common.ConsoleInputStream; +import org.eclipse.equinox.console.storage.DigestUtil; +import org.eclipse.equinox.console.storage.SecureUserStore; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.osgi.framework.BundleContext; + + +public class SshCommandTests { + private static final int TEST_CONTENT = 100; + private static final String USER_STORE_FILE_NAME = "org.eclipse.equinox.console.jaas.file"; + private static final String JAAS_CONFIG_FILE_NAME = "jaas.config"; + private static final String JAAS_CONFIG_PROPERTY_NAME = "java.security.auth.login.config"; + private static final String DEFAULT_USER_STORAGE = "osgi.console.ssh.useDefaultSecureStorage"; + private static final String SSH_PORT_PROP_NAME = "osgi.console.ssh"; + private static final String USE_CONFIG_ADMIN_PROP = "osgi.console.useConfigAdmin"; + private static final String STORE_FILE_NAME = SshCommandTests.class.getName() + "_store"; + private static final String GOGO_SHELL_COMMAND = "gosh --login --noshutdown"; + private static final String TRUE = "true"; + private static final String FALSE = "false"; + private static final String USERNAME = "username"; + private static final String PASSWORD = "password"; + private static final String START_COMMAND = "start"; + private static final String STOP_COMMAND = "stop"; + private static final String TERM_PROPERTY = "TERM"; + private static final String XTERM = "XTERM"; + private static final String HOST = "localhost"; + private static final int SSH_PORT = 2222; + private static final long WAIT_TIME = 5000; + + @Before + public void init() throws Exception { + clean(); + initStore(); + initJaasConfigFile(); + } + + @Test + public void testSshCommand() throws Exception { + CommandSession session = EasyMock.createMock(CommandSession.class); + EasyMock.makeThreadSafe(session, true); + session.put((String)EasyMock.anyObject(), EasyMock.anyObject()); + EasyMock.expectLastCall().times(5); + EasyMock.expect(session.execute(GOGO_SHELL_COMMAND)).andReturn(null); + session.close(); + EasyMock.expectLastCall(); + EasyMock.replay(session); + + CommandProcessor processor = EasyMock.createMock(CommandProcessor.class); + EasyMock.expect(processor.createSession((ConsoleInputStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject())).andReturn(session); + EasyMock.replay(processor); + + BundleContext context = EasyMock.createMock(BundleContext.class); + EasyMock.makeThreadSafe(context, true); + EasyMock.expect(context.getProperty(USE_CONFIG_ADMIN_PROP)).andReturn(FALSE); + EasyMock.expect(context.getProperty(DEFAULT_USER_STORAGE)).andReturn(TRUE).anyTimes(); + EasyMock.expect(context.getProperty(SSH_PORT_PROP_NAME)).andReturn(Integer.toString(SSH_PORT)); + EasyMock.expect(context.registerService((String)EasyMock.anyObject(), EasyMock.anyObject(), (Dictionary)EasyMock.anyObject())).andReturn(null); + EasyMock.replay(context); + + Map environment = new HashMap(); + environment.put(TERM_PROPERTY, XTERM); + Environment env = EasyMock.createMock(Environment.class); + EasyMock.expect(env.getEnv()).andReturn(environment); + EasyMock.replay(env); + + SshCommand command = new SshCommand(processor, context); + command.ssh(new String[] {START_COMMAND}); + + SshClient client = SshClient.setUpDefaultClient(); + client.start(); + try { + ConnectFuture connectFuture = client.connect(HOST, SSH_PORT); + DefaultConnectFuture defaultConnectFuture = (DefaultConnectFuture) connectFuture; + + try { + Thread.sleep(WAIT_TIME); + } catch (InterruptedException ie) { + // do nothing + } + ClientSession sshSession = defaultConnectFuture.getSession(); + + int ret = ClientSession.WAIT_AUTH; + sshSession.authPassword(USERNAME, PASSWORD); + ret = sshSession.waitFor(ClientSession.WAIT_AUTH | ClientSession.CLOSED | ClientSession.AUTHED, 0); + + if ((ret & ClientSession.CLOSED) != 0) { + System.err.println("error"); + System.exit(-1); + } + ClientChannel channel = sshSession.createChannel("shell"); + channel.setIn(new StringBufferInputStream(TEST_CONTENT + "\n")); + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + channel.setOut(byteOut); + channel.setErr(byteOut); + channel.open(); + try { + Thread.sleep(WAIT_TIME); + } catch (InterruptedException ie) { + // do nothing + } + byte[] output = byteOut.toByteArray(); + Assert.assertEquals("Output not as expected",Integer.toString(TEST_CONTENT), new String(output).trim()); + sshSession.close(true); + } finally { + client.stop(); + } + + command.ssh(new String[] {STOP_COMMAND}); + return; + } + + @After + public void cleanUp() { + clean(); + } + + private void clean() { + System.setProperty(USER_STORE_FILE_NAME, ""); + File file = new File(STORE_FILE_NAME); + if (file.exists()) { + file.delete(); + } + + System.setProperty(JAAS_CONFIG_PROPERTY_NAME, ""); + File jaasConfFile = new File(JAAS_CONFIG_FILE_NAME); + if (jaasConfFile.exists()) { + jaasConfFile.delete(); + } + } + + private void initStore() throws Exception { + System.setProperty(USER_STORE_FILE_NAME, STORE_FILE_NAME); + SecureUserStore.initStorage(); + SecureUserStore.putUser(USERNAME, DigestUtil.encrypt(PASSWORD), null); + } + + private void initJaasConfigFile() throws Exception { + System.setProperty(JAAS_CONFIG_PROPERTY_NAME, JAAS_CONFIG_FILE_NAME); + File jaasConfFile = new File(JAAS_CONFIG_FILE_NAME); + if (!jaasConfFile.exists()) { + PrintWriter out = null; + try { + out = new PrintWriter(jaasConfFile); + out.println("equinox_console {"); + out.println(" org.eclipse.equinox.console.jaas.SecureStorageLoginModule REQUIRED;"); + out.println("};"); + } finally { + if (out != null) { + out.close(); + } + } + } + } +} diff --git a/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshCommandWithConfigAdminTests.java b/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshCommandWithConfigAdminTests.java new file mode 100755 index 000000000..43d924470 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshCommandWithConfigAdminTests.java @@ -0,0 +1,320 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.console.ssh; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.InputStream; +import java.io.PrintStream; +import java.io.PrintWriter; +import java.io.StringBufferInputStream; +import java.util.Collection; +import java.util.Dictionary; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Map; + +import org.apache.felix.service.command.CommandProcessor; +import org.apache.felix.service.command.CommandSession; +import org.apache.sshd.ClientChannel; +import org.apache.sshd.ClientSession; +import org.apache.sshd.SshClient; +import org.apache.sshd.client.future.ConnectFuture; +import org.apache.sshd.client.future.DefaultConnectFuture; +import org.apache.sshd.common.RuntimeSshException; +import org.apache.sshd.server.Environment; +import org.easymock.EasyMock; +import org.easymock.IAnswer; +import org.eclipse.equinox.console.common.ConsoleInputStream; +import org.eclipse.equinox.console.storage.DigestUtil; +import org.eclipse.equinox.console.storage.SecureUserStore; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleException; +import org.osgi.framework.BundleListener; +import org.osgi.framework.Filter; +import org.osgi.framework.FrameworkListener; +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.ServiceListener; +import org.osgi.framework.ServiceReference; +import org.osgi.framework.ServiceRegistration; +import org.osgi.service.cm.ManagedService; + + +public class SshCommandWithConfigAdminTests { + private static final int TEST_CONTENT = 100; + private static final String USER_STORE_FILE_NAME = "org.eclipse.equinox.console.jaas.file"; + private static final String JAAS_CONFIG_FILE_NAME = "jaas.config"; + private static final String JAAS_CONFIG_PROPERTY_NAME = "java.security.auth.login.config"; + private static final String DEFAULT_USER_STORAGE = "osgi.console.ssh.useDefaultSecureStorage"; + private static final String STORE_FILE_NAME = SshCommandTests.class.getName() + "_store"; + private static final String GOGO_SHELL_COMMAND = "gosh --login --noshutdown"; + private static final String TRUE = "true"; + private static final String FALSE = "false"; + private static final String USERNAME = "username"; + private static final String PASSWORD = "password"; + private static final String STOP_COMMAND = "stop"; + private static final String TERM_PROPERTY = "TERM"; + private static final String XTERM = "XTERM"; + private static final String HOST = "localhost"; + private static final String SSH_PORT = "2222"; + private static final long WAIT_TIME = 5000; + private static final String USE_CONFIG_ADMIN_PROP = "osgi.console.useConfigAdmin"; + private ManagedService configurator; + + @Before + public void init() throws Exception { + clean(); + initStore(); + initJaasConfigFile(); + } + + @Test + public void testSshCommandWithConfigAdmin() throws Exception { + + CommandSession session = EasyMock.createMock(CommandSession.class); + EasyMock.makeThreadSafe(session, true); + session.put((String)EasyMock.anyObject(), EasyMock.anyObject()); + EasyMock.expectLastCall().times(5); + EasyMock.expect(session.execute(GOGO_SHELL_COMMAND)).andReturn(null); + session.close(); + EasyMock.expectLastCall(); + EasyMock.replay(session); + + CommandProcessor processor = EasyMock.createMock(CommandProcessor.class); + EasyMock.expect(processor.createSession((ConsoleInputStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject())).andReturn(session); + EasyMock.replay(processor); + + final ServiceRegistration registration = EasyMock.createMock(ServiceRegistration.class); + registration.setProperties((Dictionary)EasyMock.anyObject()); + EasyMock.expectLastCall(); + EasyMock.replay(registration); + + BundleContext context = EasyMock.createMock(BundleContext.class); + EasyMock.makeThreadSafe(context, true); + EasyMock.expect(context.getProperty(USE_CONFIG_ADMIN_PROP)).andReturn(TRUE); + EasyMock.expect(context.getProperty(DEFAULT_USER_STORAGE)).andReturn(TRUE).anyTimes(); + EasyMock.expect( + (ServiceRegistration) context.registerService( + (String)EasyMock.anyObject(), + (ManagedService)EasyMock.anyObject(), + (Dictionary)EasyMock.anyObject()) + ).andAnswer((IAnswer>) new IAnswer>() { + public ServiceRegistration answer() { + configurator = (ManagedService) EasyMock.getCurrentArguments()[1]; + return registration; + } + }); + EasyMock.expect( + context.registerService( + (String)EasyMock.anyObject(), + (SshCommand)EasyMock.anyObject(), + (Dictionary)EasyMock.anyObject())).andReturn(null); + EasyMock.replay(context); + + Map environment = new HashMap(); + environment.put(TERM_PROPERTY, XTERM); + Environment env = EasyMock.createMock(Environment.class); + EasyMock.expect(env.getEnv()).andReturn(environment); + EasyMock.replay(env); + + SshCommand command = new SshCommand(processor, context); + Dictionary props = new Hashtable(); + props.put("port", SSH_PORT); + props.put("host", HOST); + props.put("enabled", TRUE); + configurator.updated(props); + + SshClient client = SshClient.setUpDefaultClient(); + client.start(); + try { + ConnectFuture connectFuture = client.connect(HOST, Integer.valueOf(SSH_PORT)); + DefaultConnectFuture defaultConnectFuture = (DefaultConnectFuture) connectFuture; + + try { + Thread.sleep(WAIT_TIME); + } catch (InterruptedException ie) { + // do nothing + } + ClientSession sshSession = defaultConnectFuture.getSession(); + + int ret = ClientSession.WAIT_AUTH; + sshSession.authPassword(USERNAME, PASSWORD); + ret = sshSession.waitFor(ClientSession.WAIT_AUTH | ClientSession.CLOSED | ClientSession.AUTHED, 0); + + if ((ret & ClientSession.CLOSED) != 0) { + System.err.println("error"); + System.exit(-1); + } + ClientChannel channel = sshSession.createChannel("shell"); + channel.setIn(new StringBufferInputStream(TEST_CONTENT + "\n")); + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + channel.setOut(byteOut); + channel.setErr(byteOut); + channel.open(); + try { + Thread.sleep(WAIT_TIME); + } catch (InterruptedException ie) { + // do nothing + } + byte[] output = byteOut.toByteArray(); + Assert.assertEquals("Output not as expected",Integer.toString(TEST_CONTENT), new String(output).trim()); + sshSession.close(true); + } finally { + client.stop(); + } + + command.ssh(new String[] {STOP_COMMAND}); + return; + } + + @Test + public void testSshCommandWithConfigAdminDisabledSsh() throws Exception { + testDisabled(false); + } + + @Test + public void testSshCommandWithConfigAdminDisabledSshByDefault() throws Exception { + testDisabled(true); + } + + private void testDisabled(boolean isDefault) throws Exception { + CommandSession session = EasyMock.createMock(CommandSession.class); + session.put((String)EasyMock.anyObject(), EasyMock.anyObject()); + EasyMock.expectLastCall().times(4); + EasyMock.expect(session.execute(GOGO_SHELL_COMMAND)).andReturn(null); + session.close(); + EasyMock.expectLastCall(); + EasyMock.replay(session); + + CommandProcessor processor = EasyMock.createMock(CommandProcessor.class); + EasyMock.expect(processor.createSession((ConsoleInputStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject())).andReturn(session); + EasyMock.replay(processor); + + final ServiceRegistration registration = EasyMock.createMock(ServiceRegistration.class); + registration.setProperties((Dictionary)EasyMock.anyObject()); + EasyMock.expectLastCall(); + EasyMock.replay(registration); + + BundleContext context = EasyMock.createMock(BundleContext.class); + EasyMock.expect(context.getProperty(USE_CONFIG_ADMIN_PROP)).andReturn(TRUE); + EasyMock.expect(context.getProperty(DEFAULT_USER_STORAGE)).andReturn(TRUE).anyTimes(); + EasyMock.expect( + (ServiceRegistration) context.registerService( + (String)EasyMock.anyObject(), + (ManagedService)EasyMock.anyObject(), + (Dictionary)EasyMock.anyObject()) + ).andAnswer((IAnswer>) new IAnswer>() { + public ServiceRegistration answer() { + configurator = (ManagedService) EasyMock.getCurrentArguments()[1]; + return registration; + } + }); + EasyMock.expect( + context.registerService( + (String)EasyMock.anyObject(), + (SshCommand)EasyMock.anyObject(), + (Dictionary)EasyMock.anyObject())).andReturn(null); + EasyMock.replay(context); + + Map environment = new HashMap(); + environment.put(TERM_PROPERTY, XTERM); + Environment env = EasyMock.createMock(Environment.class); + EasyMock.expect(env.getEnv()).andReturn(environment); + EasyMock.replay(env); + + SshCommand command = new SshCommand(processor, context); + Dictionary props = new Hashtable(); + props.put("port", SSH_PORT); + props.put("host", HOST); + if (isDefault == false) { + props.put("enabled", FALSE); + } + configurator.updated(props); + + SshClient client = SshClient.setUpDefaultClient(); + client.start(); + try { + ConnectFuture connectFuture = client.connect(HOST, Integer.valueOf(SSH_PORT)); + DefaultConnectFuture defaultConnectFuture = (DefaultConnectFuture) connectFuture; + + try { + Thread.sleep(WAIT_TIME); + } catch (InterruptedException ie) { + // do nothing + } + ClientSession sshSession; + try { + sshSession = defaultConnectFuture.getSession(); + Assert.fail("It should not be possible to connect to " + HOST + ":" + SSH_PORT); + } catch (RuntimeSshException e) { + //this is expected + } + } finally { + client.stop(); + } + + try { + command.ssh(new String[] {STOP_COMMAND}); + } catch (IllegalStateException e) { + // this is expected + } + return; + } + + @After + public void cleanUp() { + clean(); + } + + private void clean() { + System.setProperty(USER_STORE_FILE_NAME, ""); + File file = new File(STORE_FILE_NAME); + if (file.exists()) { + file.delete(); + } + + System.setProperty(JAAS_CONFIG_PROPERTY_NAME, ""); + File jaasConfFile = new File(JAAS_CONFIG_FILE_NAME); + if (jaasConfFile.exists()) { + jaasConfFile.delete(); + } + } + + private void initStore() throws Exception { + System.setProperty(USER_STORE_FILE_NAME, STORE_FILE_NAME); + SecureUserStore.initStorage(); + SecureUserStore.putUser(USERNAME, DigestUtil.encrypt(PASSWORD), null); + } + + private void initJaasConfigFile() throws Exception { + System.setProperty(JAAS_CONFIG_PROPERTY_NAME, JAAS_CONFIG_FILE_NAME); + File jaasConfFile = new File(JAAS_CONFIG_FILE_NAME); + if (!jaasConfFile.exists()) { + PrintWriter out = null; + try { + out = new PrintWriter(jaasConfFile); + out.println("equinox_console {"); + out.println(" org.eclipse.equinox.console.jaas.SecureStorageLoginModule REQUIRED;"); + out.println("};"); + } finally { + if (out != null) { + out.close(); + } + } + } + } + +} diff --git a/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshInputHandlerTests.java b/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshInputHandlerTests.java new file mode 100755 index 000000000..e7ed407a0 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshInputHandlerTests.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial API and implementation + *******************************************************************************/ + +package org.eclipse.equinox.console.ssh; + +import java.io.ByteArrayOutputStream; +import java.io.StringBufferInputStream; + +import org.eclipse.equinox.console.common.ConsoleInputStream; +import org.eclipse.equinox.console.common.ConsoleOutputStream; +import org.eclipse.equinox.console.ssh.SshInputHandler; +import org.junit.Assert; +import org.junit.Test; + + +public class SshInputHandlerTests { + + private static final long WAIT_TIME = 10000; + + @Test + public void testHandler() throws Exception { + StringBufferInputStream input = new StringBufferInputStream("abcde"); + ConsoleInputStream in = new ConsoleInputStream(); + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + ConsoleOutputStream out = new ConsoleOutputStream(byteOut); + SshInputHandler handler = new SshInputHandler(input, in, out); + handler.start(); + + // wait for the accept thread to start execution + try { + Thread.sleep(WAIT_TIME); + } catch (InterruptedException ie) { + // do nothing + } + + String res = byteOut.toString(); + Assert.assertTrue("Wrong input. Expected abcde, read " + res, res.equals("abcde")); + } +} diff --git a/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshInputScannerTests.java b/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshInputScannerTests.java new file mode 100755 index 000000000..5f246fbdc --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshInputScannerTests.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial API and implementation + *******************************************************************************/ + +package org.eclipse.equinox.console.ssh; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import org.eclipse.equinox.console.common.ConsoleInputStream; +import org.eclipse.equinox.console.common.ConsoleOutputStream; +import org.junit.Assert; +import org.junit.Test; + + +public class SshInputScannerTests { + + private static final byte ESC = 27; + + @Test + public void testScan() throws Exception { + ConsoleInputStream in = new ConsoleInputStream(); + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + ConsoleOutputStream out = new ConsoleOutputStream(byteOut); + SshInputScanner scanner = new SshInputScanner(in, out); + try { + scanner.scan((byte) 'a'); + scanner.scan((byte) 'b'); + scanner.scan((byte) 'c'); + } catch (IOException e) { + System.out.println("Error while scanning: " + e.getMessage()); + e.printStackTrace(); + throw e; + } + + String output = byteOut.toString(); + Assert.assertTrue("Output incorrect. Expected abc, but read " + output, output.equals("abc")); + } + + @Test + public void testScanESC() throws Exception { + ConsoleInputStream in = new ConsoleInputStream(); + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + ConsoleOutputStream out = new ConsoleOutputStream(byteOut); + SshInputScanner scanner = new SshInputScanner(in, out); + + try { + scanner.scan((byte) 'a'); + scanner.scan((byte) ESC); + scanner.scan((byte) 'b'); + } catch (IOException e) { + System.out.println("Error while scanning: " + e.getMessage()); + e.printStackTrace(); + throw e; + } + + String output = byteOut.toString(); + Assert.assertTrue("Output incorrect. Expected ab, but read " + output, output.equals("ab")); + } +} diff --git a/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshShellTests.java b/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshShellTests.java new file mode 100755 index 000000000..9c041fdf0 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshShellTests.java @@ -0,0 +1,152 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial API and implementation + *******************************************************************************/ + +package org.eclipse.equinox.console.ssh; + +import java.io.File; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintStream; +import java.net.ServerSocket; +import java.net.Socket; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.felix.service.command.CommandProcessor; +import org.apache.felix.service.command.CommandSession; +import org.apache.sshd.server.Environment; +import org.easymock.EasyMock; +import org.eclipse.equinox.console.common.ConsoleInputStream; +import org.eclipse.equinox.console.storage.DigestUtil; +import org.eclipse.equinox.console.storage.SecureUserStore; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.osgi.framework.BundleContext; + + +public class SshShellTests { + + private static final int TEST_CONTENT = 100; + private static final String USER_STORE_FILE_NAME = "org.eclipse.equinox.console.jaas.file"; + private static final String DEFAULT_USER_STORAGE = "osgi.console.ssh.useDefaultSecureStorage"; + private static final String USER_STORE_NAME = SshShellTests.class.getName() + "_store"; + private static final String HOST = "localhost"; + private static final String GOGO_SHELL_COMMAND = "gosh --login --noshutdown"; + private static final String TERM_PROPERTY = "TERM"; + private static final String XTERM = "XTERM"; + private static final String USERNAME = "username"; + private static final String PASSWORD = "password"; + private static final String TRUE = "true"; + + @Before + public void init() throws Exception { + clean(); + initStore(); + } + + @Test + public void testSshConnection() throws Exception { + ServerSocket servSocket = null; + Socket socketClient = null; + Socket socketServer = null; + SshShell shell = null; + OutputStream outClient = null; + OutputStream outServer = null; + + try { + + servSocket = new ServerSocket(0); + socketClient = new Socket(HOST, servSocket.getLocalPort()); + socketServer = servSocket.accept(); + + CommandSession session = EasyMock.createMock(CommandSession.class); + EasyMock.makeThreadSafe(session, true); + session.put((String)EasyMock.anyObject(), EasyMock.anyObject()); + EasyMock.expectLastCall().times(5); + EasyMock.expect(session.execute(GOGO_SHELL_COMMAND)).andReturn(null); + session.close(); + EasyMock.expectLastCall(); + EasyMock.replay(session); + + CommandProcessor processor = EasyMock.createMock(CommandProcessor.class); + EasyMock.expect(processor.createSession((ConsoleInputStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject())).andReturn(session); + EasyMock.replay(processor); + + BundleContext context = EasyMock.createMock(BundleContext.class); + EasyMock.makeThreadSafe(context, true); + EasyMock.expect(context.getProperty(DEFAULT_USER_STORAGE)).andReturn(TRUE); + EasyMock.replay(context); + + Map environment = new HashMap(); + environment.put(TERM_PROPERTY, XTERM); + Environment env = EasyMock.createMock(Environment.class); + EasyMock.expect(env.getEnv()).andReturn(environment); + EasyMock.replay(env); + + List processors = new ArrayList(); + processors.add(processor); + shell = new SshShell(processors, context); + shell.setInputStream(socketServer.getInputStream()); + shell.setOutputStream(socketServer.getOutputStream()); + shell.start(env); + + outClient = socketClient.getOutputStream(); + outClient.write(TEST_CONTENT); + outClient.write('\n'); + outClient.flush(); + InputStream input = socketClient.getInputStream(); + int in = input.read(); + Assert.assertTrue("Server received [" + in + "] instead of " + TEST_CONTENT + " from the ssh client.", in == TEST_CONTENT); + } finally { + if (socketClient != null) { + socketClient.close(); + } + if (outClient != null) { + outClient.close(); + } + if (outServer != null) { + outServer.close(); + } + + if (socketServer != null) { + socketServer.close(); + } + + if (servSocket != null) { + servSocket.close(); + } + + } + } + + @After + public void cleanUp() { + clean(); + } + + private void initStore() throws Exception { + System.setProperty(USER_STORE_FILE_NAME, USER_STORE_NAME); + SecureUserStore.initStorage(); + SecureUserStore.putUser(USERNAME, DigestUtil.encrypt(PASSWORD), null); + } + + private void clean() { + System.setProperty(USER_STORE_FILE_NAME, ""); + File file = new File(USER_STORE_NAME); + if(file.exists()) { + file.delete(); + } + } +} diff --git a/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/UserAdminCommandTests.java b/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/UserAdminCommandTests.java new file mode 100755 index 000000000..658690178 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/UserAdminCommandTests.java @@ -0,0 +1,119 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial API and implementation + *******************************************************************************/ + +package org.eclipse.equinox.console.ssh; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.util.HashSet; +import java.util.Set; + +import org.apache.felix.service.command.CommandSession; +import org.easymock.EasyMock; +import org.eclipse.equinox.console.storage.DigestUtil; +import org.eclipse.equinox.console.storage.SecureUserStore; +import org.junit.After; +import org.junit.Test; + + +public class UserAdminCommandTests { + + private static final String USER_STORE_FILE_NAME_PROPERTY = "org.eclipse.equinox.console.jaas.file"; + private static final String USER_STORE_FILE_NAME = UserAdminCommandTests.class.getName() + "_store"; + private static final String USERNAME_OPTION = "-username"; + private static final String PASSWORD_OPTION = "-password"; + private static final String ROLES_OPTION = "-roles"; + private static final String USERNAME1 = "username1"; + private static final String USERNAME2 = "username2"; + private static final String PASSWORD1 = "password1"; + private static final String PASSWORD2 = "password2"; + private static final String ROLES1 = "role1,role2"; + private static final String ROLES2 = "role3,role4"; + private static final String ROLES_TO_REMOVE = "role2"; + private static final String REMAINING_ROLES = "role1"; + + @Test + public void testCommand() throws Exception { + cleanUp(); + + System.setProperty(USER_STORE_FILE_NAME_PROPERTY, USER_STORE_FILE_NAME); + SecureUserStore.initStorage(); + + CommandSession session = EasyMock.createMock(CommandSession.class); + session.put((String)EasyMock.anyObject(), EasyMock.anyObject()); + EasyMock.expectLastCall().times(3); + EasyMock.replay(session); + + UserAdminCommand command = new UserAdminCommand(); + command.addUser(new String[] {USERNAME_OPTION, USERNAME1, PASSWORD_OPTION, PASSWORD1}); + command.addUser(new String[] {USERNAME_OPTION, USERNAME2, PASSWORD_OPTION, PASSWORD2, ROLES_OPTION, ROLES2}); + + String[] usernames = SecureUserStore.getUserNames(); + boolean arePresent = (usernames[0].equals(USERNAME1) || usernames[0].equals(USERNAME2)) && (usernames[1].equals(USERNAME1) || usernames[1].equals(USERNAME2)) && (!usernames[0].equals(usernames[1])); + assertTrue("Usernames not correctly saved", arePresent); + + String pass1 = SecureUserStore.getPassword(USERNAME1); + String pass2 = SecureUserStore.getPassword(USERNAME2); + assertTrue("Passwords not correctly saved", pass1.equals(DigestUtil.encrypt(PASSWORD1)) && pass2.equals(DigestUtil.encrypt(PASSWORD2))); + + String roles = SecureUserStore.getRoles(USERNAME2); + assertEquals("Roles for the second user are not as expected", ROLES2, roles); + + command.addRoles(new String[] {USERNAME_OPTION, USERNAME1, ROLES_OPTION, ROLES1}); + roles = SecureUserStore.getRoles(USERNAME1); + boolean areRolesEqual = compareRoles(ROLES1, roles); + assertTrue("Roles for the first user are not as expected", areRolesEqual); + + command.removeRoles(new String[] {USERNAME_OPTION, USERNAME1, ROLES_OPTION, ROLES_TO_REMOVE}); + roles = SecureUserStore.getRoles(USERNAME1); + areRolesEqual = compareRoles(REMAINING_ROLES, roles); + assertTrue("Roles for the first user are not as expected", areRolesEqual); + + command.resetPassword(USERNAME1); + String pass = SecureUserStore.getPassword(USERNAME1); + assertNull("Password should be null", pass); + + command.setPassword(new String[] {USERNAME_OPTION, USERNAME1, PASSWORD_OPTION, PASSWORD1}); + pass = SecureUserStore.getPassword(USERNAME1); + assertEquals("Password should be null", DigestUtil.encrypt(PASSWORD1), pass); + + command.deleteUser(USERNAME2); + assertFalse("User2 should not exist", SecureUserStore.existsUser(USERNAME2)); + } + + @After + public void cleanUp() { + System.setProperty(USER_STORE_FILE_NAME_PROPERTY, ""); + File file = new File(USER_STORE_FILE_NAME); + if(file.exists()) { + file.delete(); + } + } + + private boolean compareRoles(String expectedRoles, String actualRoles) { + Set expectedRolesSet = new HashSet(); + for(String role : expectedRoles.split(",")) { + expectedRolesSet.add(role); + } + + Set actualRolesSet = new HashSet(); + for(String role : actualRoles.split(",")) { + actualRolesSet.add(role); + } + + return expectedRolesSet.equals(actualRolesSet); + } + +} diff --git a/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/storage/DigestUtilTests.java b/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/storage/DigestUtilTests.java new file mode 100755 index 000000000..d1a040b30 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/storage/DigestUtilTests.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial API and implementation + *******************************************************************************/ + +package org.eclipse.equinox.console.storage; + +import static org.junit.Assert.*; +import java.security.MessageDigest; + +import org.junit.Test; + + +public class DigestUtilTests { + + private static final char[] HEX_CHARS = "0123456789abcdef".toCharArray(); + private static final String MD5 = "MD5"; + private static final String SHA1 = "SHA1"; + private static final String TEXT = "sometext"; + + @Test + public void testEncrypt() throws Exception { + MessageDigest md = MessageDigest.getInstance(MD5); + md.update(TEXT.getBytes()); + byte[] digest = md.digest(); + + char[] chars = new char[2 * digest.length]; + for (int i = 0; i < digest.length; ++i) + { + chars[2 * i] = HEX_CHARS[(digest[i] & 0xF0) >>> 4]; + chars[2 * i + 1] = HEX_CHARS[digest[i] & 0x0F]; + } + + String modifiedText = TEXT + new String(chars); + md = MessageDigest.getInstance(SHA1); + md.update(modifiedText.getBytes()); + digest = md.digest(); + + chars = new char[2 * digest.length]; + for (int i = 0; i < digest.length; ++i) + { + chars[2 * i] = HEX_CHARS[(digest[i] & 0xF0) >>> 4]; + chars[2 * i + 1] = HEX_CHARS[digest[i] & 0x0F]; + } + + String expectedEncryptedText = new String(chars); + + assertEquals("Encrypted text not as expected", expectedEncryptedText, DigestUtil.encrypt(TEXT)); + } +} diff --git a/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/storage/SecureUserStoreTests.java b/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/storage/SecureUserStoreTests.java new file mode 100755 index 000000000..20062e17b --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/storage/SecureUserStoreTests.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial API and implementation + *******************************************************************************/ + +package org.eclipse.equinox.console.storage; + +import static org.junit.Assert.*; + +import java.io.File; +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.equinox.console.jaas.SecureStorageLoginModule; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class SecureUserStoreTests { + + private static final String USER_STORE_FILE_NAME_PROPERTY = "org.eclipse.equinox.console.jaas.file"; + private static final String USER_STORE_FILE_NAME = SecureUserStoreTests.class.getName() + "_store"; + private static final String USERNAME1 = "username1"; + private static final String USERNAME2 = "username2"; + private static final String PASSWORD1 = "password1"; + private static final String PASSWORD2 = "password2"; + private static final String ROLES1 = "role1,role2"; + private static final String ROLES2 = "role3,role4"; + private static final String ROLES_TO_REMOVE = "role2"; + private static final String REMAINING_ROLES = "role1"; + + @Test + public void testStore() throws Exception { + cleanUp(); + + System.setProperty(USER_STORE_FILE_NAME_PROPERTY, USER_STORE_FILE_NAME); + + SecureUserStore.initStorage(); + assertTrue("Secure store file does not exist", new File(USER_STORE_FILE_NAME).exists()); + + SecureUserStore.putUser(USERNAME1, PASSWORD1, null); + SecureUserStore.putUser(USERNAME2, PASSWORD2, ROLES2); + + String[] usernames = SecureUserStore.getUserNames(); + boolean arePresent = (usernames[0].equals(USERNAME1) || usernames[0].equals(USERNAME2)) && (usernames[1].equals(USERNAME1) || usernames[1].equals(USERNAME2)) && (!usernames[0].equals(usernames[1])); + assertTrue("Usernames not correctly saved", arePresent); + + String pass1 = SecureUserStore.getPassword(USERNAME1); + String pass2 = SecureUserStore.getPassword(USERNAME2); + assertTrue("Passwords not correctly saved", pass1.equals(PASSWORD1) && pass2.equals(PASSWORD2)); + + boolean existsUser1 = SecureUserStore.existsUser(USERNAME1); + boolean existsUser2 = SecureUserStore.existsUser(USERNAME2); + assertTrue("Users should exist", existsUser1 && existsUser2); + + String roles = SecureUserStore.getRoles(USERNAME2); + assertEquals("Roles for the second user are not as expected", ROLES2, roles); + + SecureUserStore.addRoles(USERNAME1, ROLES1); + roles = SecureUserStore.getRoles(USERNAME1); + boolean areRolesEqual = compareRoles(ROLES1, roles); + assertTrue("Roles for the first user are not as expected", areRolesEqual); + + SecureUserStore.removeRoles(USERNAME1, ROLES_TO_REMOVE); + roles = SecureUserStore.getRoles(USERNAME1); + areRolesEqual = compareRoles(REMAINING_ROLES, roles); + assertTrue("Roles for the first user are not as expected", areRolesEqual); + + SecureUserStore.resetPassword(USERNAME1); + String pass = SecureUserStore.getPassword(USERNAME1); + assertNull("Password should be null", pass); + + SecureUserStore.setPassword(USERNAME1, PASSWORD1); + pass = SecureUserStore.getPassword(USERNAME1); + assertEquals("Password should be null", PASSWORD1, pass); + + SecureUserStore.deleteUser(USERNAME2); + assertFalse("User2 should not exist", SecureUserStore.existsUser(USERNAME2)); + } + + @After + public void cleanUp() { + System.setProperty(USER_STORE_FILE_NAME_PROPERTY, ""); + File file = new File(USER_STORE_FILE_NAME); + if(file.exists()) { + file.delete(); + } + } + + private boolean compareRoles(String expectedRoles, String actualRoles) { + Set expectedRolesSet = new HashSet(); + for(String role : expectedRoles.split(",")) { + expectedRolesSet.add(role); + } + + Set actualRolesSet = new HashSet(); + for(String role : actualRoles.split(",")) { + actualRolesSet.add(role); + } + + return expectedRolesSet.equals(actualRolesSet); + } +} diff --git a/bundles/archived/org.eclipse.equinox.console.tests/.classpath b/bundles/archived/org.eclipse.equinox.console.tests/.classpath new file mode 100755 index 000000000..a7d4b6245 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/bundles/archived/org.eclipse.equinox.console.tests/.gitignore b/bundles/archived/org.eclipse.equinox.console.tests/.gitignore new file mode 100755 index 000000000..3b8360084 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/.gitignore @@ -0,0 +1 @@ +/hostkey.ser diff --git a/bundles/archived/org.eclipse.equinox.console.tests/.project b/bundles/archived/org.eclipse.equinox.console.tests/.project new file mode 100755 index 000000000..7d67a8eb6 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/.project @@ -0,0 +1,28 @@ + + + org.eclipse.equinox.console.tests + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/bundles/archived/org.eclipse.equinox.console.tests/.settings/org.eclipse.core.runtime.prefs b/bundles/archived/org.eclipse.equinox.console.tests/.settings/org.eclipse.core.runtime.prefs new file mode 100644 index 000000000..5a0ad22d2 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/.settings/org.eclipse.core.runtime.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +line.separator=\n diff --git a/bundles/archived/org.eclipse.equinox.console.tests/.settings/org.eclipse.jdt.core.prefs b/bundles/archived/org.eclipse.equinox.console.tests/.settings/org.eclipse.jdt.core.prefs new file mode 100755 index 000000000..af0f20f97 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/bundles/archived/org.eclipse.equinox.console.tests/META-INF/MANIFEST.MF b/bundles/archived/org.eclipse.equinox.console.tests/META-INF/MANIFEST.MF new file mode 100755 index 000000000..aa559b375 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Console tests +Bundle-SymbolicName: org.eclipse.equinox.console.tests +Bundle-Version: 1.0.0.qualifier +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Import-Package: junit.framework;version="4.8.1", + org.apache.sshd.client.future, + org.easymock;version="2.4.0", + org.junit;version="4.8.1" +Fragment-Host: org.eclipse.equinox.console diff --git a/bundles/archived/org.eclipse.equinox.console.tests/about.html b/bundles/archived/org.eclipse.equinox.console.tests/about.html new file mode 100755 index 000000000..bed8451cf --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/about.html @@ -0,0 +1,28 @@ + + + + +About + + +

About This Content

+ +

May 28, 2011

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at http://www.eclipse.org.

+ + + \ No newline at end of file diff --git a/bundles/archived/org.eclipse.equinox.console.tests/build.properties b/bundles/archived/org.eclipse.equinox.console.tests/build.properties new file mode 100755 index 000000000..34d2e4d2d --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/archived/org.eclipse.equinox.console.tests/forceQualifierUpdate.txt b/bundles/archived/org.eclipse.equinox.console.tests/forceQualifierUpdate.txt new file mode 100644 index 000000000..56f1032a8 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/forceQualifierUpdate.txt @@ -0,0 +1,2 @@ +# To force a version qualifier update add the bug here +Bug 403352 - Update all parent versions to match our build stream diff --git a/bundles/archived/org.eclipse.equinox.console.tests/pom.xml b/bundles/archived/org.eclipse.equinox.console.tests/pom.xml new file mode 100644 index 000000000..1ed67a724 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/pom.xml @@ -0,0 +1,24 @@ + + + + 4.0.0 + + tests-pom + org.eclipse.equinox.bundles + 4.6.0-SNAPSHOT + ../../tests-pom/ + + org.eclipse.equinox + org.eclipse.equinox.console.tests + 1.0.0-SNAPSHOT + eclipse-test-plugin + diff --git a/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/Activator.java b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/Activator.java new file mode 100755 index 000000000..e024b14fa --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/Activator.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial API and implementation + *******************************************************************************/ + +package org.eclipse.equinox.console; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator implements BundleActivator { + private static BundleContext context; + + public void start(BundleContext context) throws Exception { + this.context = context; + } + + + public void stop(BundleContext context) throws Exception { + this.context = null; + } + + public static BundleContext getContext() { + return context; + } +} diff --git a/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/command/adapter/ActivatorTests.java b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/command/adapter/ActivatorTests.java new file mode 100755 index 000000000..677fc4099 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/command/adapter/ActivatorTests.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial API and implementation + *******************************************************************************/ + +package org.eclipse.equinox.console.command.adapter; + +import static org.junit.Assert.*; + +import java.lang.reflect.Method; +import java.util.Dictionary; +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.osgi.framework.console.CommandInterpreter; +import org.eclipse.osgi.framework.console.CommandProvider; +import org.junit.Test; + +public class ActivatorTests { + + private static final String SCOPE_PROPERTY_NAME = "osgi.command.scope"; + private static final String FUNCTION_PROPERTY_NAME = "osgi.command.function"; + private static final String EQUINOX_SCOPE = "equinox"; + + @Test + public void testGetCommandMethods() { + Set commandNames = new HashSet(); + commandNames.add("_testMethod1"); + commandNames.add("_testMethod2"); + commandNames.add("_testMethod3"); + + Activator activator = new Activator(); + CommandProvider command = new TestCommandProvider(); + Method[] methods = activator.getCommandMethods(command); + + assertEquals("Command methods not as expected", 3, methods.length); + for (Method method : methods) { + assertTrue("Command methods should not include " + method.getName(), commandNames.contains(method.getName())); + } + + Dictionary props = activator.getAttributes(methods); + assertTrue("Attributes should contain property " + SCOPE_PROPERTY_NAME + " with value " + EQUINOX_SCOPE, EQUINOX_SCOPE.equals(props.get(SCOPE_PROPERTY_NAME))); + String[] methodNames = (String[])props.get(FUNCTION_PROPERTY_NAME); + assertEquals("Methods number not as expected", methods.length, methodNames.length); + + for(int i = 0; i < methods.length; i++) { + assertEquals("Wrong method name", methods[i].getName().substring(1), methodNames[i]); + } + } + + class TestCommandProvider implements CommandProvider { + public void _testMethod1(CommandInterpreter i) { + + } + + public void _testMethod2(CommandInterpreter i) { + + } + + public void _testMethod3(CommandInterpreter i) { + + } + + private void _method(CommandInterpreter i) { + + } + + public String getHelp() { + // TODO Auto-generated method stub + return null; + } + + } + +} diff --git a/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/command/adapter/CommandProviderAdapterTest.java b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/command/adapter/CommandProviderAdapterTest.java new file mode 100755 index 000000000..91ce5f5d2 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/command/adapter/CommandProviderAdapterTest.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial API and implementation + *******************************************************************************/ + +package org.eclipse.equinox.console.command.adapter; + +import static org.junit.Assert.*; + +import java.lang.reflect.Method; +import java.util.HashSet; +import java.util.Set; + +import org.apache.felix.service.command.CommandSession; +import org.eclipse.osgi.framework.console.CommandInterpreter; +import org.eclipse.osgi.framework.console.CommandProvider; +import org.junit.Test; +import org.easymock.EasyMock; + +public class CommandProviderAdapterTest { + + @Test + public void testMain() throws Exception { + CommandProvider provider = new TestCommandProvider(); + Method[] methods = TestCommandProvider.class.getMethods(); + Set m = new HashSet(); + for (Method method : methods) { + if (method.getName().startsWith("_")) { + m.add(method); + } + } + CommandProviderAdapter providerAdapter = new CommandProviderAdapter(provider, m.toArray(new Method[0])); + CommandSession session = EasyMock.createMock(CommandSession.class); + + String result = (String) providerAdapter.main(session, new Object[] {"test"}); + assertEquals("Result should be test", "test", result); + + result = (String) providerAdapter.main(session, new Object[] {"echo", "hello"}); + assertEquals("Result should be hello", "hello", result); + } + + class TestCommandProvider implements CommandProvider { + public String _test(CommandInterpreter i) { + return "test"; + } + + public String _echo(CommandInterpreter i) { + return i.nextArgument(); + } + + public String getHelp() { + return "this is a test command provider"; + } + + } +} diff --git a/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/ConsoleInputStreamTests.java b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/ConsoleInputStreamTests.java new file mode 100755 index 000000000..b3732bbfc --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/ConsoleInputStreamTests.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial contribution + ******************************************************************************/ + +package org.eclipse.equinox.console.common; + +import org.junit.Assert; +import org.junit.Test; + +import org.eclipse.equinox.console.common.ConsoleInputStream; + +public class ConsoleInputStreamTests { + + private static final int DATA_LENGTH = 4; + + @Test + public void addReadBufferTest() throws Exception { + ConsoleInputStream in = new ConsoleInputStream(); + byte[] data = new byte[] { (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd' }; + in.add(data); + byte[] read = new byte[DATA_LENGTH]; + for (int i = 0; i < DATA_LENGTH; i++) { + in.read(read, i, 1); + Assert.assertEquals("Incorrect char read; position " + i + " expected: " + data[i] + ", actual: " + read[i], read[i], data[i]); + } + } + + @Test + public void addReadTest() throws Exception { + ConsoleInputStream in = new ConsoleInputStream(); + byte[] data = new byte[] { (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd' }; + in.add(data); + for (int i = 0; i < DATA_LENGTH; i++) { + byte symbol = (byte) in.read(); + Assert.assertEquals("Incorrect char read; position " + i + " expected: " + data[i] + ", actual: " + symbol, symbol, data[i]); + } + } +} diff --git a/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/ConsoleOutputStreamTests.java b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/ConsoleOutputStreamTests.java new file mode 100755 index 000000000..c1044ee8b --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/ConsoleOutputStreamTests.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial contribution + ******************************************************************************/ + +package org.eclipse.equinox.console.common; + +import org.junit.Assert; +import org.junit.Test; + +import java.io.ByteArrayOutputStream; + +public class ConsoleOutputStreamTests { + + private static final int DATA_LENGTH = 4; + + @Test + public void testWrite() throws Exception { + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + ConsoleOutputStream out = new ConsoleOutputStream(byteOut); + byte[] data = new byte[] { 'a', 'b', 'c', 'd' }; + for (byte b : data) { + out.write(b); + } + out.flush(); + byte[] res = byteOut.toByteArray(); + + Assert.assertNotNull("Bytes not written; result null", res); + Assert.assertFalse("Bytes not written; result empty", res.length == 0); + + for (int i = 0; i < DATA_LENGTH; i++) { + Assert.assertEquals("Wrong char read. Position " + i + ", expected " + data[i] + ", read " + res[i], data[i], res[i]); + } + } +} diff --git a/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/HistoryHolderTests.java b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/HistoryHolderTests.java new file mode 100755 index 000000000..5ee9bba4d --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/HistoryHolderTests.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial contribution + ******************************************************************************/ + +package org.eclipse.equinox.console.common; + +import org.junit.Assert; +import org.junit.Test; + + +public class HistoryHolderTests { + + @Test + public void test() { + HistoryHolder historyHolder = new HistoryHolder(); + byte[] line1 = new byte[] { 'a', 'b', 'c', 'd' }; + byte[] line2 = new byte[] { 'x', 'y', 'z' }; + byte[] line3 = new byte[] { 'k', 'l', 'm', 'n' }; + + historyHolder.add(line1); + historyHolder.add(line2); + historyHolder.add(line3); + + byte[] first = historyHolder.first(); + Assert.assertEquals("Wrong length of first member", line1.length, first.length); + Assert.assertArrayEquals("Wrong first member", line1, first); + + byte[] last = historyHolder.last(); + Assert.assertEquals("Wrong length of last member", line3.length, last.length); + Assert.assertArrayEquals("Wrong last member", line3, last); + + byte[] prev = historyHolder.prev(); + Assert.assertEquals("Wrong length of previous member", line2.length, prev.length); + Assert.assertArrayEquals("Wrong previous member", line2, prev); + + byte[] next = historyHolder.next(); + Assert.assertEquals("Wrong length of next member", line3.length, next.length); + Assert.assertArrayEquals("Wrong next member", line3, next); + + historyHolder.first(); + historyHolder.add(new byte[] {}); + byte[] current = historyHolder.prev(); + Assert.assertEquals("Wrong length of next member", line3.length, current.length); + Assert.assertArrayEquals("Wrong next member", line3, current); + + historyHolder.first(); + historyHolder.add(line1); + current = historyHolder.prev(); + Assert.assertEquals("Wrong length of next member", line1.length, current.length); + Assert.assertArrayEquals("Wrong next member", line1, current); + Assert.assertArrayEquals("Second line should now be first", line2, historyHolder.first()); + + historyHolder.reset(); + Assert.assertNull("History should be empty", historyHolder.first()); + Assert.assertNull("History should be empty", historyHolder.last()); + Assert.assertNull("History should be empty", historyHolder.next()); + Assert.assertNull("History should be empty", historyHolder.prev()); + } + +} diff --git a/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/SimpleByteBufferTests.java b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/SimpleByteBufferTests.java new file mode 100755 index 000000000..9d4362431 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/SimpleByteBufferTests.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial contribution + ******************************************************************************/ + +package org.eclipse.equinox.console.common; + +import org.junit.Assert; +import org.junit.Test; + +public class SimpleByteBufferTests { + + @Test + public void testBuffer() throws Exception { + SimpleByteBuffer buffer = new SimpleByteBuffer(); + buffer.add('a'); + buffer.add('b'); + buffer.add('c'); + buffer.add('d'); + + Assert.assertTrue("Wrong buffer size; expected 4, actual " + buffer.getSize(), buffer.getSize() == 4); + + check(buffer, new byte[] { 'a', 'b', 'c', 'd' }); + + byte[] data = buffer.getCurrentData(); + byte[] expected = new byte[] { 'a', 'b', 'c', 'd' }; + + Assert.assertTrue("Data not as expected: expected length " + expected.length + ", actual length " + data.length, + data.length == expected.length); + + for (int i = 0; i < data.length; i++) { + Assert.assertEquals("Incorrect data read. Position " + i + ", expected " + expected[i] + ", read " + data[i], expected[i], data[i]); + } + + buffer.insert('a'); + buffer.insert('b'); + buffer.insert('c'); + buffer.insert('d'); + + int pos = buffer.getPos(); + buffer.goLeft(); + int newPos = buffer.getPos(); + Assert.assertEquals("Error while moving left; old pos: " + pos + ", new pos: ", pos - 1, newPos); + + buffer.insert('e'); + check(buffer, new byte[] { 'a', 'b', 'c', 'e', 'd' }); + + buffer.goLeft(); + buffer.delete(); + check(buffer, new byte[] { 'a', 'b', 'c', 'd' }); + + pos = buffer.getPos(); + buffer.goRight(); + newPos = buffer.getPos(); + Assert.assertEquals("Error while moving right; old pos: " + pos + ", new pos: ", pos + 1, newPos); + + buffer.backSpace(); + check(buffer, new byte[] { 'a', 'b', 'c' }); + + buffer.delAll(); + Assert.assertTrue("Bytes in buffer not correctly deleted", (buffer.getSize() == 0) && (buffer.getPos() == 0)); + + buffer.set(new byte[] { 'a', 'b', 'c', 'd' }); + check(buffer, new byte[] { 'a', 'b', 'c', 'd' }); + + data = buffer.copyCurrentData(); + Assert.assertArrayEquals("Buffer copy does not work properly", new byte[] { 'a', 'b', 'c', 'd' }, data); + + buffer.goLeft(); + buffer.replace('e'); + check(buffer, new byte[] { 'a', 'b', 'c', 'e' }); + + buffer.resetPos(); + Assert.assertTrue("Resetting position does not work properly", buffer.getPos() == 0); + + Assert.assertEquals("Wrong current char", 'a', buffer.getCurrentChar()); + } + + private void check(SimpleByteBuffer buffer, byte[] expected) throws Exception { + byte[] data = buffer.copyCurrentData(); + + Assert.assertTrue("Data not as expected: expected length " + expected.length + ", actual length " + data.length, + data.length == expected.length); + + for (int i = 0; i < data.length; i++) { + Assert.assertEquals("Incorrect data read. Position " + i + ", expected " + expected[i] + ", read " + data[i], expected[i], data[i]); + } + } + +} diff --git a/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CommandLineParserTests.java b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CommandLineParserTests.java new file mode 100755 index 000000000..408c8a8f1 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CommandLineParserTests.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial API and implementation + *******************************************************************************/ + +package org.eclipse.equinox.console.completion; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class CommandLineParserTests { + + private static final String PIPE_TEST_INPUT = "command1|comm"; + private static final String CONSECUTIVE_COMMANDS_TEST_INPUT = "command1;comm"; + private static final String ASSIGNMENT_TEST_INPUT = "var=val"; + private static final String START_CLOSURE_TEST_INPUT = "${comm"; + private static final String END_CLOSURE_TEST_INPUT = "${command}arg1"; + private static final String START_MACRO_TEST_INPUT = "$(macr"; + private static final String END_MACRO_TEST_INPUT = "$(macro)val"; + private static final String VARIABLE_TEST_INPUT = "$VAR"; + private static final String START_MAP_TEST_INPUT = " commands = new HashSet(); + commands.add("equinox:bundles"); + commands.add("equinox:diag"); + commands.add("equinox:setprop"); + commands.add("gogo:lb"); + commands.add("gogo:echo"); + commands.add("gogo:set"); + + CommandSession session = createMock(CommandSession.class); + expect(session.get(COMMANDS)).andReturn(commands).times(4); + replay(session); + + Filter filter = createMock(Filter.class); + replay(filter); + + BundleContext context = createMock(BundleContext.class); +// expect(context.createFilter(String.format("(&(%s=*)(%s=*))", CommandProcessor.COMMAND_SCOPE, CommandProcessor.COMMAND_FUNCTION))).andReturn(filter); + expect(context.createFilter("(objectClass=org.eclipse.equinox.console.commands.CommandsTracker)")).andReturn(filter); + context.addServiceListener(isA(ServiceListener.class), isA(String.class)); + expect(context.getServiceReferences("org.eclipse.equinox.console.commands.CommandsTracker", null)).andReturn(new ServiceReference[]{}); + replay(context); + + CommandNamesCompleter completer = new CommandNamesCompleter(context, session); + Map candidates; + + candidates = completer.getCandidates("se", 2); + assertNotNull("Candidates null", candidates); + assertEquals("Candidates not as expected", 2, candidates.size()); + assertNotNull("set should be in the resultset, but it is not", candidates.get("set")); + assertNotNull("setprop should be in the resultset, but it is not", candidates.get("setprop")); + + candidates = completer.getCandidates("equinox:bun", "equinox:bun".length()); + assertNotNull("Candidates null", candidates); + assertEquals("Candidates not as expected", 1, candidates.size()); + assertNotNull("equinox:bundles should be in the resultset, but it is not", candidates.get("equinox:bundles")); + + candidates = completer.getCandidates("ec", 2); + assertNotNull("Candidates null", candidates); + assertEquals("Candidates not as expected", 1, candidates.size()); + assertNotNull("echo should be in the resultset, but it is not", candidates.get("echo")); + + candidates = completer.getCandidates("head", 4); + assertNotNull("Candidates null", candidates); + assertEquals("Candidates not as expected", 0, candidates.size()); + + verify(session); + } + +} diff --git a/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CompletionHandlerTests.java b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CompletionHandlerTests.java new file mode 100755 index 000000000..07663db15 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CompletionHandlerTests.java @@ -0,0 +1,175 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial API and implementation + *******************************************************************************/ + +package org.eclipse.equinox.console.completion; + +import static org.junit.Assert.*; +import static org.easymock.EasyMock.*; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.apache.felix.service.command.CommandSession; +import org.eclipse.equinox.console.completion.common.Completer; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Filter; +import org.osgi.framework.ServiceListener; +import org.osgi.framework.ServiceReference; + +public class CompletionHandlerTests { + + private static final String COMMANDS = ".commands"; + private static final String WORK_DIR_NAME = "work"; + private static final String TESTFILE = "testfile"; + private static final String TESTOUTPUT = "testoutput"; + private static final String FILE = "file"; + + @Before + public void init() throws IOException { + File currentDir = new File("."); + File[] files = currentDir.listFiles(); + for (File file : files) { + if(file.getName().equals(WORK_DIR_NAME)) { + clean(); + break; + } + } + + File workDir = new File(currentDir.getAbsolutePath() + File.separator + WORK_DIR_NAME); + workDir.mkdir(); + + createFile(workDir, TESTFILE); + createFile(workDir, TESTOUTPUT); + createFile(workDir, FILE); + } + + @Test + public void testGetCandidates() throws Exception { + Filter filter = createMock(Filter.class); + replay(filter); + + BundleContext context = createMock(BundleContext.class); + expect(context.getServiceReferences(Completer.class.getName(), null)).andReturn(null).anyTimes(); + expect(context.createFilter("(objectClass=org.eclipse.equinox.console.commands.CommandsTracker)")).andReturn(filter).anyTimes(); + context.addServiceListener(isA(ServiceListener.class), isA(String.class)); + expectLastCall().anyTimes(); + expect(context.getServiceReferences("org.eclipse.equinox.console.commands.CommandsTracker", null)).andReturn(new ServiceReference[]{}).anyTimes(); + replay(context); + + Set variables = new HashSet(); + variables.add("SCOPE"); + variables.add("PROMPT"); + variables.add("ECHO_ON"); + variables.add("ECHO"); + + Set commands = new HashSet(); + commands.add("equinox:bundles"); + commands.add("equinox:diag"); + commands.add("equinox:setprop"); + commands.add("gogo:lb"); + commands.add("gogo:echo"); + commands.add("gogo:set"); + + CommandSession session = createMock(CommandSession.class); + expect(session.get(null)).andReturn(variables).anyTimes(); + expect(session.get(COMMANDS)).andReturn(commands).anyTimes(); + replay(session); + + CompletionHandler completer = new CompletionHandler(context, session); + Map candidates; + + candidates = completer.getCandidates("$SC".getBytes(), 2); + assertNotNull("Candidates null", candidates); + assertEquals("Candidates not as expected", 1, candidates.size()); + assertNotNull("SCOPE should be in the resultset, but it is not", candidates.get("SCOPE")); + + candidates = completer.getCandidates("$EC".getBytes(), 2); + assertNotNull("Candidates null", candidates); + assertEquals("Candidates not as expected", 2, candidates.size()); + assertNotNull("ECHO_ON should be in the resultset, but it is not", candidates.get("ECHO_ON")); + assertNotNull("ECHO should be in the resultset, but it is not", candidates.get("ECHO")); + + candidates = completer.getCandidates("$AB".getBytes(), 2); + assertNotNull("Candidates null", candidates); + assertEquals("Candidates not as expected", 0, candidates.size()); + + completer = new CompletionHandler(context, session); + candidates = completer.getCandidates("se".getBytes(), 2); + assertNotNull("Candidates null", candidates); + assertEquals("Candidates not as expected", 2, candidates.size()); + assertNotNull("set should be in the resultset, but it is not", candidates.get("set")); + assertNotNull("setprop should be in the resultset, but it is not", candidates.get("setprop")); + + candidates = completer.getCandidates("equinox:bun".getBytes(), "equinox:bun".length()); + assertNotNull("Candidates null", candidates); + assertEquals("Candidates not as expected", 1, candidates.size()); + assertNotNull("equinox:bundles should be in the resultset, but it is not", candidates.get("equinox:bundles")); + + candidates = completer.getCandidates("ec".getBytes(), 2); + assertNotNull("Candidates null", candidates); + assertEquals("Candidates not as expected", 1, candidates.size()); + assertNotNull("echo should be in the resultset, but it is not", candidates.get("echo")); + + candidates = completer.getCandidates("head".getBytes(), "head".length()); + assertNotNull("Candidates null", candidates); + assertEquals("Candidates not as expected", 0, candidates.size()); + + completer = new CompletionHandler(context, session); + candidates = completer.getCandidates("wor".getBytes(), "wor".length()); + assertNotNull("Candidates null", candidates); + assertEquals("Candidates not as expected", 1, candidates.size()); + assertNotNull("work should be in the resultset, but it is not", candidates.get(WORK_DIR_NAME)); + + candidates = completer.getCandidates("work/test".getBytes(), "work/test".length()); + assertNotNull("Candidates null", candidates); + assertEquals("Candidates not as expected", 2, candidates.size()); + assertNotNull("testfile should be in the resultset, but it is not", candidates.get(TESTFILE)); + assertNotNull("testoutput should be in the resultset, but it is not", candidates.get(TESTOUTPUT)); + + candidates = completer.getCandidates("work/".getBytes(), "work/".length()); + assertEquals("Candidates not as expected", 3, candidates.size()); + assertNotNull("testfile should be in the resultset, but it is not", candidates.get(TESTFILE)); + assertNotNull("testoutput should be in the resultset, but it is not", candidates.get(TESTOUTPUT)); + assertNotNull("file should be in the resultset, but it is not", candidates.get(FILE)); + } + + @After + public void cleanUp() { + clean(); + } + + private void clean() { + File currentFile = new File("."); + File workDir = new File(currentFile.getAbsolutePath() + File.separator + WORK_DIR_NAME); + File[] files = workDir.listFiles(); + for (File file : files) { + file.delete(); + } + workDir.delete(); + } + + private void createFile(File parentDir, String filename) throws IOException { + File file = new File(parentDir.getAbsolutePath() + File.separator + filename); + PrintWriter out = new PrintWriter(new FileOutputStream(file)); + out.write(filename); + out.flush(); + out.close(); + } + +} diff --git a/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/FileNamesCompleterTests.java b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/FileNamesCompleterTests.java new file mode 100755 index 000000000..91540a13f --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/FileNamesCompleterTests.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial API and implementation + *******************************************************************************/ + +package org.eclipse.equinox.console.completion; + +import static org.junit.Assert.*; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Map; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class FileNamesCompleterTests { + private static final String WORK_DIR_NAME = "work"; + private static final String TESTFILE = "testfile"; + private static final String TESTOUTPUT = "testoutput"; + private static final String FILE = "file"; + + @Before + public void init() throws IOException { + File currentDir = new File("."); + File[] files = currentDir.listFiles(); + for (File file : files) { + if(file.getName().equals(WORK_DIR_NAME)) { + clean(); + break; + } + } + + File workDir = new File(currentDir.getAbsolutePath() + File.separator + WORK_DIR_NAME); + workDir.mkdir(); + + createFile(workDir, TESTFILE); + createFile(workDir, TESTOUTPUT); + createFile(workDir, FILE); + } + + @Test + public void testGetCandidates() { + FileNamesCompleter completer = new FileNamesCompleter(); + + Map candidates; + + candidates = completer.getCandidates("wor", "wor".length()); + assertNotNull("Candidates null", candidates); + assertEquals("Candidates not as expected", 1, candidates.size()); + assertNotNull("work should be in the resultset, but it is not", candidates.get(WORK_DIR_NAME)); + + candidates = completer.getCandidates("work/test", "work/test".length()); + assertNotNull("Candidates null", candidates); + assertEquals("Candidates not as expected", 2, candidates.size()); + assertNotNull("testfile should be in the resultset, but it is not", candidates.get(TESTFILE)); + assertNotNull("testoutput should be in the resultset, but it is not", candidates.get(TESTOUTPUT)); + + candidates = completer.getCandidates(WORK_DIR_NAME + "/", 5); + assertEquals("Candidates not as expected", 3, candidates.size()); + assertNotNull("testfile should be in the resultset, but it is not", candidates.get(TESTFILE)); + assertNotNull("testoutput should be in the resultset, but it is not", candidates.get(TESTOUTPUT)); + assertNotNull("file should be in the resultset, but it is not", candidates.get(FILE)); + } + + @After + public void cleanUp() { + clean(); + } + + private void clean() { + File currentFile = new File("."); + File workDir = new File(currentFile.getAbsolutePath() + File.separator + WORK_DIR_NAME); + File[] files = workDir.listFiles(); + for (File file : files) { + file.delete(); + } + workDir.delete(); + } + + private void createFile(File parentDir, String filename) throws IOException { + File file = new File(parentDir.getAbsolutePath() + File.separator + filename); + PrintWriter out = new PrintWriter(new FileOutputStream(file)); + out.write(filename); + out.flush(); + out.close(); + } +} diff --git a/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/StringsCompleterTests.java b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/StringsCompleterTests.java new file mode 100755 index 000000000..05096ba5b --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/StringsCompleterTests.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial API and implementation + *******************************************************************************/ + +package org.eclipse.equinox.console.completion; + +import static org.junit.Assert.*; + +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.junit.Test; + +public class StringsCompleterTests { + + @Test + public void testGetCandidates() { + Set strings = new HashSet(); + strings.add("command"); + strings.add("SCOPE"); + strings.add("equinox:bundles"); + strings.add("common"); + + StringsCompleter completer = new StringsCompleter(strings, false); + Map candidates; + + candidates = completer.getCandidates("sco", 3); + assertNotNull("Candidates null", candidates); + assertEquals("Candidates not as expected", 1, candidates.size()); + assertNotNull("SCOPE should be in the resultset, but it is not", candidates.get("SCOPE")); + + candidates = completer.getCandidates("com", 3); + assertNotNull("Candidates null", candidates); + assertEquals("Candidates not as expected", 2, candidates.size()); + assertNotNull("command should be in the resultset, but it is not", candidates.get("command")); + assertNotNull("common should be in the resultset, but it is not", candidates.get("common")); + + candidates = completer.getCandidates("tr", 2); + assertNotNull("Candidates null", candidates); + assertEquals("Candidates not as expected", 0, candidates.size()); + + completer = new StringsCompleter(strings, true); + + candidates = completer.getCandidates("sco", 3); + assertNotNull("Candidates null", candidates); + assertEquals("Candidates not as expected", 0, candidates.size()); + + candidates = completer.getCandidates("SCO", 3); + assertNotNull("Candidates null", candidates); + assertEquals("Candidates not as expected", 1, candidates.size()); + assertNotNull("SCOPE should be in the resultset, but it is not", candidates.get("SCOPE")); + } + +} diff --git a/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/VariableNamesCompleterTests.java b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/VariableNamesCompleterTests.java new file mode 100755 index 000000000..2b6ca5290 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/VariableNamesCompleterTests.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial API and implementation + *******************************************************************************/ + +package org.eclipse.equinox.console.completion; + +import static org.easymock.EasyMock.*; +import static org.junit.Assert.*; + +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.apache.felix.service.command.CommandSession; +import org.junit.Test; + +public class VariableNamesCompleterTests { + + @Test + public void testGetCandidates() { + Set variables = new HashSet(); + variables.add("SCOPE"); + variables.add("PROMPT"); + variables.add("ECHO_ON"); + variables.add("ECHO"); + + CommandSession session = createMock(CommandSession.class); + expect(session.get(null)).andReturn(variables).times(3); + replay(session); + + VariableNamesCompleter completer = new VariableNamesCompleter(session); + Map candidates; + + candidates = completer.getCandidates("SC", 2); + assertNotNull("Candidates null", candidates); + assertEquals("Candidates not as expected", 1, candidates.size()); + assertNotNull("SCOPE should be in the resultset, but it is not", candidates.get("SCOPE")); + + candidates = completer.getCandidates("EC", 2); + assertNotNull("Candidates null", candidates); + assertEquals("Candidates not as expected", 2, candidates.size()); + assertNotNull("ECHO_ON should be in the resultset, but it is not", candidates.get("ECHO_ON")); + assertNotNull("ECHO should be in the resultset, but it is not", candidates.get("ECHO")); + + candidates = completer.getCandidates("AB", 2); + assertNotNull("Candidates null", candidates); + assertEquals("Candidates not as expected", 0, candidates.size()); + + verify(session); + } + +} diff --git a/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/supportability/ConsoleInputHandlerTests.java b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/supportability/ConsoleInputHandlerTests.java new file mode 100755 index 000000000..e595b627c --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/supportability/ConsoleInputHandlerTests.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial contribution + ******************************************************************************/ + +package org.eclipse.equinox.console.supportability; + +import org.eclipse.equinox.console.common.ConsoleInputHandler; +import org.eclipse.equinox.console.common.ConsoleInputStream; +import org.junit.Assert; +import org.junit.Test; + +import java.io.ByteArrayOutputStream; +import java.io.PipedInputStream; +import java.io.PipedOutputStream; + +public class ConsoleInputHandlerTests { + + private static final long WAIT_TIME = 10000; + + @Test + public void testHandler() throws Exception { + PipedInputStream input = new PipedInputStream(); + PipedOutputStream output = new PipedOutputStream(input); + ConsoleInputStream in = new ConsoleInputStream(); + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + ConsoleInputHandler handler = new ConsoleInputHandler(input, in, byteOut); + byte[] testInput = new byte[] { 'a', 'b', 'c', 'd', 'e', '\r', '\n' }; + byte[] expected = new byte[] { 'a', 'b', 'c', 'd', 'e', '\n' }; + output.write(testInput); + output.flush(); + handler.start(); + + try { + Thread.sleep(WAIT_TIME); + } catch (Exception e) { + // do nothing + } + + byte[] read = new byte[expected.length]; + in.read(read, 0, expected.length); + for (int i = 0; i < expected.length; i++) { + Assert.assertEquals("Incorrect char read. Position " + i + ", expected " + expected[i] + ", read " + read[i], expected[i], read[i]); + } + + output.close(); + input.close(); + } + +} diff --git a/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/supportability/ConsoleInputScannerTests.java b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/supportability/ConsoleInputScannerTests.java new file mode 100755 index 000000000..5c07ca1fb --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/supportability/ConsoleInputScannerTests.java @@ -0,0 +1,268 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial contribution + ******************************************************************************/ + +package org.eclipse.equinox.console.supportability; + +import static org.easymock.EasyMock.isA; +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; + +import org.apache.felix.service.command.CommandSession; +import org.eclipse.equinox.console.common.ConsoleInputScanner; +import org.eclipse.equinox.console.common.ConsoleInputStream; +import org.eclipse.equinox.console.common.ConsoleOutputStream; +import org.eclipse.equinox.console.common.KEYS; +import org.eclipse.equinox.console.common.terminal.ANSITerminalTypeMappings; +import org.eclipse.equinox.console.common.terminal.SCOTerminalTypeMappings; +import org.eclipse.equinox.console.common.terminal.TerminalTypeMappings; +import org.eclipse.equinox.console.common.terminal.VT100TerminalTypeMappings; +import org.eclipse.equinox.console.common.terminal.VT220TerminalTypeMappings; +import org.eclipse.equinox.console.common.terminal.VT320TerminalTypeMappings; +import org.eclipse.equinox.console.completion.common.Completer; +import org.junit.Assert; +import org.junit.Test; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Filter; +import org.osgi.framework.ServiceListener; +import org.osgi.framework.ServiceReference; + +import java.io.ByteArrayOutputStream; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +public class ConsoleInputScannerTests { + + private static int BS; + + private static final int LF = 10; + + private static final int CR = 13; + + private static final int ESC = 27; + + private static int DELL; + + private static int TAB = 9; + + private static final String COMMANDS = ".commands"; + + @Test + public void test() throws Exception { + Set supportedEscapeSequences = new HashSet(); + supportedEscapeSequences.add(new ANSITerminalTypeMappings()); + supportedEscapeSequences.add(new VT100TerminalTypeMappings()); + supportedEscapeSequences.add(new VT220TerminalTypeMappings()); + supportedEscapeSequences.add(new VT320TerminalTypeMappings()); + supportedEscapeSequences.add(new SCOTerminalTypeMappings()); + + for (TerminalTypeMappings ttMappings : supportedEscapeSequences) { + Map escapesToKey = ttMappings.getEscapesToKey(); + Map keysToEscapes = new HashMap(); + for (Entry entry : escapesToKey.entrySet()) { + keysToEscapes.put(entry.getValue(), entry.getKey().getBytes()); + } + + BS = ttMappings.getBackspace(); + DELL = ttMappings.getDel(); + + testScan(ttMappings, keysToEscapes); + } + } + + private void testScan(TerminalTypeMappings mappings, Map keysToEscapes) throws Exception { + ConsoleInputStream in = new ConsoleInputStream(); + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + ConsoleOutputStream out = new ConsoleOutputStream(byteOut); + ConsoleInputScanner scanner = new ConsoleInputScanner(in, out); + scanner.setBackspace(mappings.getBackspace()); + scanner.setCurrentEscapesToKey(mappings.getEscapesToKey()); + scanner.setDel(mappings.getDel()); + scanner.setEscapes(mappings.getEscapes()); + + byte[] line1 = new byte[] { 'a', 'b', 'c', 'd', 'e' }; + byte[] line2 = new byte[] { 't', 'e', 's', 't' }; + byte[] line3 = new byte[] { 'l', 'a', 's', 't' }; + + addLine(scanner, line1); + checkInpusStream(in, line1); + + addLine(scanner, line2); + checkInpusStream(in, line2); + + addLine(scanner, line3); + checkInpusStream(in, line3); + + add(scanner, keysToEscapes.get(KEYS.UP)); + add(scanner, keysToEscapes.get(KEYS.UP)); + String res = byteOut.toString(); + Assert.assertTrue("Error processing up arrow; expected test, actual " + res.substring(res.length() - 4), res.endsWith("test")); + + add(scanner, keysToEscapes.get(KEYS.DOWN)); + res = byteOut.toString(); + Assert.assertTrue("Error processing down arrow; expected last, actual " + res.substring(res.length() - 4), res.endsWith("last")); + + add(scanner, keysToEscapes.get(KEYS.PGUP)); + res = byteOut.toString(); + Assert.assertTrue("Error processing PageUp; expected abcde, actual " + res.substring(res.length() - 4), res.endsWith("abcde")); + + add(scanner, keysToEscapes.get(KEYS.PGDN)); + res = byteOut.toString(); + Assert.assertTrue("Error processing PageDown; expected last, actual " + res.substring(res.length() - 4), res.endsWith("last")); + + if (BS > 0) { + scanner.scan(BS); + res = byteOut.toString(); + Assert.assertTrue("Error processing backspace; expected las, actual " + res.substring(res.length() - 3), res.endsWith("las")); + scanner.scan('t'); + } + + if (DELL > 0) { + add(scanner, keysToEscapes.get(KEYS.LEFT)); + scanner.scan(DELL); + res = byteOut.toString(); + Assert.assertTrue("Error processing del; expected las, actual " + res.substring(res.length() - 3), res.endsWith("las")); + scanner.scan('t'); + } + + add(scanner, keysToEscapes.get(KEYS.LEFT)); + add(scanner, keysToEscapes.get(KEYS.LEFT)); + add(scanner, keysToEscapes.get(KEYS.RIGHT)); + if (DELL > 0) { + scanner.scan(DELL); + } else { + add(scanner, keysToEscapes.get(KEYS.DEL)); + } + res = byteOut.toString(); + Assert.assertTrue("Error processing arrows; expected las, actual " + res.substring(res.length() - 3), res.endsWith("las")); + scanner.scan('t'); + + if (keysToEscapes.get(KEYS.DEL) != null) { + add(scanner, keysToEscapes.get(KEYS.LEFT)); + add(scanner, keysToEscapes.get(KEYS.DEL)); + res = byteOut.toString(); + Assert.assertTrue("Error processing delete; expected las, actual " + res.substring(res.length() - 3), res.endsWith("las")); + scanner.scan('t'); + } + + add(scanner, keysToEscapes.get(KEYS.HOME)); + if (DELL > 0) { + scanner.scan(DELL); + } else { + add(scanner, keysToEscapes.get(KEYS.DEL)); + } + res = byteOut.toString(); + res = res.substring(res.length() - 6, res.length() - 3); + Assert.assertTrue("Error processing Home; expected ast, actual " + res, res.equals("ast")); + scanner.scan('l'); + + add(scanner, keysToEscapes.get(KEYS.END)); + add(scanner, keysToEscapes.get(KEYS.LEFT)); + if (DELL > 0) { + scanner.scan(DELL); + } else { + add(scanner, keysToEscapes.get(KEYS.DEL)); + } + res = byteOut.toString(); + Assert.assertTrue("Error processing End; expected las, actual " + res.substring(res.length() - 3), res.endsWith("las")); + scanner.scan('t'); + + add(scanner, keysToEscapes.get(KEYS.LEFT)); + add(scanner, keysToEscapes.get(KEYS.INS)); + scanner.scan('a'); + res = byteOut.toString(); + Assert.assertTrue("Error processing Ins; expected las, actual " + res.substring(res.length() - 4), res.endsWith("lasa")); + + Filter filter = createMock(Filter.class); + replay(filter); + + BundleContext context = createMock(BundleContext.class); + expect(context.getServiceReferences(Completer.class.getName(), null)).andReturn(null).anyTimes(); + expect(context.createFilter("(objectClass=org.eclipse.equinox.console.commands.CommandsTracker)")).andReturn(filter); + context.addServiceListener(isA(ServiceListener.class), isA(String.class)); + expect(context.getServiceReferences("org.eclipse.equinox.console.commands.CommandsTracker", null)).andReturn(new ServiceReference[]{}); + replay(context); + + Set commands = new HashSet(); + commands.add("equinox:bundles"); + commands.add("equinox:bundle"); + commands.add("gogo:bundlebylocation"); + commands.add("gogo:bundlelevel"); + commands.add("equinox:headers"); + + CommandSession session = createMock(CommandSession.class); + expect(session.get(COMMANDS)).andReturn(commands).anyTimes(); + replay(session); + + scanner.setContext(context); + scanner.setSession(session); + + scanner.scan(CR); + scanner.scan(LF); + scanner.scan('b'); + scanner.scan('u'); + scanner.scan('n'); + scanner.scan(TAB); + res = byteOut.toString(); + Assert.assertTrue("Expected completion suggestion is not contained in the output", res.contains("bundles\r\n")); + Assert.assertTrue("Expected completion suggestion is not contained in the output", res.contains("bundle\r\n")); + Assert.assertTrue("bun should be completed to bundle", res.endsWith("bundle")); + Assert.assertTrue("Expected completion suggestion is not contained in the output", res.contains("bundlebylocation\r\n")); + Assert.assertTrue("Expected completion suggestion is not contained in the output", res.contains("bundlelevel\r\n")); + Assert.assertFalse("Not expected completion suggestion", res.contains("headers\r\n")); + } + + private static void addLine(ConsoleInputScanner scanner, byte[] line) throws Exception { + for (byte b : line) { + try { + scanner.scan(b); + } catch (Exception e) { + System.out.println("Error scanning symbol " + b); + throw new Exception("Error scanning symbol" + b); + } + } + + try { + scanner.scan(CR); + } catch (Exception e) { + System.out.println("Error scanning symbol " + CR); + throw new Exception("Error scanning symbol " + CR); + } + + try { + scanner.scan(LF); + } catch (Exception e) { + System.out.println("Error scanning symbol " + LF); + throw new Exception("Error scanning symbol " + LF); + } + } + + private void add(ConsoleInputScanner scanner, byte[] sequence) throws Exception { + scanner.scan(ESC); + for (byte b : sequence) { + scanner.scan(b); + } + } + + private void checkInpusStream(ConsoleInputStream in, byte[] expected) throws Exception { + // the actual number of bytes in the stream is two more than the bytes in the array, because of the CR and LF + // symbols, added after the array + byte[] read = new byte[expected.length + 1]; + in.read(read, 0, read.length); + for (int i = 0; i < expected.length; i++) { + Assert.assertEquals("Incorrect char read. Position " + i + ", expected " + expected[i] + ", read " + read[i], expected[i], read[i]); + } + } + +} diff --git a/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/NegotiationFinishedCallbackTests.java b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/NegotiationFinishedCallbackTests.java new file mode 100755 index 000000000..225dfdb09 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/NegotiationFinishedCallbackTests.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial contribution + ******************************************************************************/ + +package org.eclipse.equinox.console.telnet; + +import org.junit.Assert; +import org.junit.Test; + +public class NegotiationFinishedCallbackTests { + + @Test + public void finishTest() throws Exception { + TelnetConnection telnetConnection = null; + telnetConnection = new TelnetConnection (null, null, null); + NegotiationFinishedCallback callback = new NegotiationFinishedCallback(telnetConnection); + callback.finished(); + Assert.assertTrue("Finished not called on console session", telnetConnection.isTelnetNegotiationFinished); + } +} diff --git a/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandTests.java b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandTests.java new file mode 100755 index 000000000..5cd1f9f89 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandTests.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2011, 2012 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial API and implementation + *******************************************************************************/ + +package org.eclipse.equinox.console.telnet; + +import java.io.OutputStream; +import java.io.PrintStream; +import java.net.Socket; +import java.util.Dictionary; + +import org.apache.felix.service.command.CommandProcessor; +import org.apache.felix.service.command.CommandSession; +import org.easymock.EasyMock; +import org.eclipse.equinox.console.common.ConsoleInputStream; +import org.junit.Test; +import org.osgi.framework.BundleContext; + + +public class TelnetCommandTests { + + private static final int TEST_CONTENT = 100; + private static final String TELNET_PORT_PROP_NAME = "osgi.console"; + private static final String USE_CONFIG_ADMIN_PROP = "osgi.console.useConfigAdmin"; + private static final String STOP_COMMAND = "stop"; + private static final String HOST = "localhost"; + private static final String FALSE = "false"; + private static final int TELNET_PORT = 2223; + private static final long WAIT_TIME = 5000; + + @Test + public void testTelnetCommand() throws Exception { + CommandSession session = EasyMock.createMock(CommandSession.class); + session.put((String)EasyMock.anyObject(), EasyMock.anyObject()); + EasyMock.expectLastCall().times(3); + EasyMock.expect(session.execute((String)EasyMock.anyObject())).andReturn(new Object()); + session.close(); + EasyMock.expectLastCall(); + EasyMock.replay(session); + + CommandProcessor processor = EasyMock.createMock(CommandProcessor.class); + EasyMock.expect(processor.createSession((ConsoleInputStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject())).andReturn(session); + EasyMock.replay(processor); + + BundleContext context = EasyMock.createMock(BundleContext.class); + EasyMock.expect(context.getProperty(USE_CONFIG_ADMIN_PROP)).andReturn(FALSE); + EasyMock.expect(context.getProperty(TELNET_PORT_PROP_NAME)).andReturn(Integer.toString(TELNET_PORT)); + EasyMock.expect(context.registerService((String)EasyMock.anyObject(), EasyMock.anyObject(), (Dictionary)EasyMock.anyObject())).andReturn(null); + EasyMock.replay(context); + + TelnetCommand command = new TelnetCommand(processor, context); + command.startService(); + + Socket socketClient = null; + try { + socketClient = new Socket(HOST, TELNET_PORT); + OutputStream outClient = socketClient.getOutputStream(); + outClient.write(TEST_CONTENT); + outClient.write('\n'); + outClient.flush(); + + // wait for the accept thread to finish execution + try { + Thread.sleep(WAIT_TIME); + } catch (InterruptedException ie) { + // do nothing + } + } finally { + if (socketClient != null) { + socketClient.close(); + } + command.telnet(new String[] {STOP_COMMAND}); + } + EasyMock.verify(context); + } +} diff --git a/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandWithConfigAdminTests.java b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandWithConfigAdminTests.java new file mode 100755 index 000000000..15480ef54 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandWithConfigAdminTests.java @@ -0,0 +1,206 @@ +/******************************************************************************* + * Copyright (c) 2011, 2012 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.console.telnet; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintStream; +import java.net.Socket; +import java.util.Collection; +import java.util.Dictionary; +import java.util.Hashtable; + +import junit.framework.Assert; + +import org.apache.felix.service.command.CommandProcessor; +import org.apache.felix.service.command.CommandSession; +import org.easymock.EasyMock; +import org.easymock.IAnswer; +import org.eclipse.equinox.console.common.ConsoleInputStream; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleException; +import org.osgi.framework.BundleListener; +import org.osgi.framework.Filter; +import org.osgi.framework.FrameworkListener; +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.ServiceListener; +import org.osgi.framework.ServiceReference; +import org.osgi.framework.ServiceRegistration; +import org.osgi.service.cm.ManagedService; + + +public class TelnetCommandWithConfigAdminTests { + private static final int TEST_CONTENT = 100; + private static final String STOP_COMMAND = "stop"; + private static final String HOST = "localhost"; + private static final String TELNET_PORT = "2223"; + private static final long WAIT_TIME = 5000; + private static final String USE_CONFIG_ADMIN_PROP = "osgi.console.useConfigAdmin"; + private static final String TRUE = "true"; + private static final String FALSE = "false"; + private ManagedService configurator; + + @Test + public void testTelnetCommandWithConfigAdminEnabledTelnet() throws Exception { + CommandSession session = EasyMock.createMock(CommandSession.class); + session.put((String)EasyMock.anyObject(), EasyMock.anyObject()); + EasyMock.expectLastCall().times(3); + EasyMock.expect(session.execute((String)EasyMock.anyObject())).andReturn(new Object()); + session.close(); + EasyMock.expectLastCall(); + EasyMock.replay(session); + + CommandProcessor processor = EasyMock.createMock(CommandProcessor.class); + EasyMock.expect(processor.createSession((ConsoleInputStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject())).andReturn(session); + EasyMock.replay(processor); + + final ServiceRegistration registration = EasyMock.createMock(ServiceRegistration.class); + registration.setProperties((Dictionary)EasyMock.anyObject()); + + EasyMock.expectLastCall(); + EasyMock.replay(registration); + + BundleContext context = EasyMock.createMock(BundleContext.class); + EasyMock.expect(context.getProperty(USE_CONFIG_ADMIN_PROP)).andReturn(TRUE); + EasyMock.expect( + (ServiceRegistration) context.registerService( + (String)EasyMock.anyObject(), + (ManagedService)EasyMock.anyObject(), + (Dictionary)EasyMock.anyObject()) + ).andAnswer((IAnswer>) new IAnswer>() { + public ServiceRegistration answer() { + configurator = (ManagedService) EasyMock.getCurrentArguments()[1]; + return registration; + } + }); + EasyMock.expect( + context.registerService( + (String)EasyMock.anyObject(), + (TelnetCommand)EasyMock.anyObject(), + (Dictionary)EasyMock.anyObject())).andReturn(null); + EasyMock.replay(context); + + TelnetCommand command = new TelnetCommand(processor, context); + command.startService(); + Dictionary props = new Hashtable(); + props.put("port", TELNET_PORT); + props.put("host", HOST); + props.put("enabled", TRUE); + configurator.updated(props); + + Socket socketClient = null; + try { + socketClient = new Socket(HOST, Integer.parseInt(TELNET_PORT)); + OutputStream outClient = socketClient.getOutputStream(); + outClient.write(TEST_CONTENT); + outClient.write('\n'); + outClient.flush(); + + // wait for the accept thread to finish execution + try { + Thread.sleep(WAIT_TIME); + } catch (InterruptedException ie) { + // do nothing + } + } finally { + if (socketClient != null) { + socketClient.close(); + } + command.telnet(new String[] {STOP_COMMAND}); + } + EasyMock.verify(context); + } + + @Test + public void testTelnetCommandWithConfigAdminDisabledTelnet() throws Exception { + disabledTelnet(false); + } + + @Test + public void testTelnetCommandWithConfigAdminDisabledTelnetByDefault() throws Exception { + disabledTelnet(true); + } + + private void disabledTelnet(boolean isDefault) throws Exception { + CommandSession session = EasyMock.createMock(CommandSession.class); + session.put((String)EasyMock.anyObject(), EasyMock.anyObject()); + EasyMock.expectLastCall().times(4); + EasyMock.expect(session.execute((String)EasyMock.anyObject())).andReturn(new Object()); + session.close(); + EasyMock.expectLastCall(); + EasyMock.replay(session); + + CommandProcessor processor = EasyMock.createMock(CommandProcessor.class); + EasyMock.expect(processor.createSession((ConsoleInputStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject())).andReturn(session); + EasyMock.replay(processor); + + final ServiceRegistration registration = EasyMock.createMock(ServiceRegistration.class); + registration.setProperties((Dictionary)EasyMock.anyObject()); + + EasyMock.expectLastCall(); + EasyMock.replay(registration); + + BundleContext context = EasyMock.createMock(BundleContext.class); + EasyMock.expect(context.getProperty(USE_CONFIG_ADMIN_PROP)).andReturn(TRUE); + EasyMock.expect( + (ServiceRegistration) context.registerService( + (String)EasyMock.anyObject(), + (ManagedService)EasyMock.anyObject(), + (Dictionary)EasyMock.anyObject()) + ).andAnswer((IAnswer>) new IAnswer>() { + public ServiceRegistration answer() { + configurator = (ManagedService) EasyMock.getCurrentArguments()[1]; + return registration; + } + }); + EasyMock.expect( + context.registerService( + (String)EasyMock.anyObject(), + (TelnetCommand)EasyMock.anyObject(), + (Dictionary)EasyMock.anyObject())).andReturn(null); + EasyMock.replay(context); + + TelnetCommand command = new TelnetCommand(processor, context); + command.startService(); + Dictionary props = new Hashtable(); + props.put("port", TELNET_PORT); + props.put("host", HOST); + if (isDefault == false) { + props.put("enabled", FALSE); + } + configurator.updated(props); + + Socket socketClient = null; + try { + socketClient = new Socket(HOST, Integer.parseInt(TELNET_PORT)); + Assert.fail("It should not be possible to open a socket to " + HOST + ":" + TELNET_PORT); + } catch (IOException e) { + // this is ok, there should be an exception + } finally { + if (socketClient != null) { + socketClient.close(); + } + try { + command.telnet(new String[] {STOP_COMMAND}); + } catch (IllegalStateException e) { + //this is expected + } + } + EasyMock.verify(context); + } + +} diff --git a/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetConnectionTests.java b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetConnectionTests.java new file mode 100755 index 000000000..bebcd222f --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetConnectionTests.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2011, 2012 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial contribution + ******************************************************************************/ + +package org.eclipse.equinox.console.telnet; + +import org.apache.felix.service.command.CommandProcessor; +import org.apache.felix.service.command.CommandSession; +import org.junit.Assert; +import org.junit.Test; +import org.easymock.EasyMock; +import org.eclipse.equinox.console.common.ConsoleInputStream; + +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintStream; +import java.net.ServerSocket; +import java.net.Socket; + +public class TelnetConnectionTests { + + private static final String HOST = "localhost"; + private static final int TEST_CONTENT = 100; + private static final int IAC = 255; + + @Test + public void testTelneConnection() throws Exception { + ServerSocket servSocket = null; + Socket socketClient = null; + Socket socketServer = null; + TelnetConnection connection = null; + OutputStream outClient = null; + OutputStream outServer = null; + + try { + servSocket = new ServerSocket(0); + socketClient = new Socket(HOST, servSocket.getLocalPort()); + socketServer = servSocket.accept(); + + CommandSession session = EasyMock.createMock(CommandSession.class); + session.put((String)EasyMock.anyObject(), EasyMock.anyObject()); + EasyMock.expectLastCall().times(3); + EasyMock.expect(session.execute((String)EasyMock.anyObject())).andReturn(null); + session.close(); + EasyMock.expectLastCall(); + EasyMock.replay(session); + + CommandProcessor processor = EasyMock.createMock(CommandProcessor.class); + EasyMock.expect(processor.createSession((ConsoleInputStream) EasyMock.anyObject(), (PrintStream) EasyMock.anyObject(), (PrintStream) EasyMock.anyObject())).andReturn(session); + EasyMock.replay(processor); + + connection = new TelnetConnection(socketServer, processor, null); + connection.start(); + + outClient = socketClient.getOutputStream(); + outClient.write(TEST_CONTENT); + outClient.write('\n'); + outClient.flush(); + + InputStream input = socketServer.getInputStream(); + int in = input.read(); + Assert.assertTrue("Server received [" + in + "] instead of " + TEST_CONTENT + " from the telnet client.", in == TEST_CONTENT); + + input = socketClient.getInputStream(); + in = input.read(); + // here IAC is expected, since when the output stream in TelnetConsoleSession is created, several telnet + // commands are written to it, each of them starting with IAC + Assert.assertTrue("Client receive telnet responses from the server unexpected value [" + in + "] instead of " + IAC + ".", in == IAC); + connection.telnetNegotiationFinished(); + Thread.sleep(5000); + EasyMock.verify(session, processor); + } finally { + if (socketClient != null) { + socketClient.close(); + } + if (outClient != null) { + outClient.close(); + } + if (outServer != null) { + outServer.close(); + } + + if (socketServer != null) { + socketServer.close(); + } + + if (servSocket != null) { + servSocket.close(); + } + } + } +} diff --git a/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetDisconnectionTest.java b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetDisconnectionTest.java new file mode 100755 index 000000000..066f5c3d7 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetDisconnectionTest.java @@ -0,0 +1,104 @@ +package org.eclipse.equinox.console.telnet; + +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PipedInputStream; +import java.io.PipedOutputStream; +import java.io.PrintStream; +import java.net.ServerSocket; +import java.net.Socket; + +import org.apache.felix.service.command.CommandProcessor; +import org.apache.felix.service.command.CommandSession; +import org.easymock.EasyMock; +import org.eclipse.equinox.console.commands.DisconnectCommand; +import org.eclipse.equinox.console.common.ConsoleInputStream; +import org.junit.Assert; +import org.junit.Test; +import org.osgi.framework.BundleContext; + +public class TelnetDisconnectionTest { + private static final String HOST = "localhost"; + private InputStream in; + + @Test + public void testTelneConnection() throws Exception { + ServerSocket servSocket = null; + Socket socketClient = null; + Socket socketServer = null; + TelnetConnection connection = null; + OutputStream outClient = null; + OutputStream outServer = null; + + try { + servSocket = new ServerSocket(0); + socketClient = new Socket(HOST, servSocket.getLocalPort()); + socketServer = servSocket.accept(); + + CommandProcessor processor = EasyMock.createMock(CommandProcessor.class); + connection = new TelnetConnection(socketServer, processor, null); + + final CommandSession session = EasyMock.createMock(CommandSession.class); + EasyMock.makeThreadSafe(session, true); + session.put((String)EasyMock.anyObject(), EasyMock.anyObject()); + EasyMock.expectLastCall().times(3); + EasyMock.expect(session.get("CLOSEABLE")).andReturn(connection); + EasyMock.expect(session.execute((String)EasyMock.anyObject())).andReturn(null); + session.close(); + EasyMock.expectLastCall(); + EasyMock.replay(session); + + EasyMock.expect(processor.createSession((ConsoleInputStream) EasyMock.anyObject(), (PrintStream) EasyMock.anyObject(), (PrintStream) EasyMock.anyObject())).andReturn(session); + EasyMock.replay(processor); + + connection.start(); + Thread.sleep(60000); + + BundleContext context = EasyMock.createMock(BundleContext.class); + final DisconnectCommand command = new DisconnectCommand(context); + + PipedOutputStream outputStream = new PipedOutputStream(); + PipedInputStream inputStream = new PipedInputStream(outputStream); + + in = System.in; + System.setIn(inputStream); + + new Thread() { + public void run() { + command.disconnect(session); + } + }.start(); + + outputStream.write(new byte[]{'y'}); + outputStream.write('\n'); + outputStream.flush(); + + Thread.sleep(3000); + Assert.assertTrue("Socket is not closed!", socketServer.isClosed()); + + connection.telnetNegotiationFinished(); + Thread.sleep(5000); + EasyMock.verify(session, processor); + } finally { + if (socketClient != null) { + socketClient.close(); + } + if (outClient != null) { + outClient.close(); + } + if (outServer != null) { + outServer.close(); + } + + if (socketServer != null) { + socketServer.close(); + } + + if (servSocket != null) { + servSocket.close(); + } + + System.setIn(in); + } + } +} diff --git a/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetInputHandlerTests.java b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetInputHandlerTests.java new file mode 100755 index 000000000..f5d3bd6a8 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetInputHandlerTests.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial contribution + ******************************************************************************/ + +package org.eclipse.equinox.console.telnet; + +import org.eclipse.equinox.console.common.ConsoleInputStream; +import org.eclipse.equinox.console.common.ConsoleOutputStream; +import org.junit.Assert; +import org.junit.Test; + +import static org.easymock.EasyMock.*; + +import java.io.ByteArrayOutputStream; +import java.io.StringBufferInputStream; + +public class TelnetInputHandlerTests { + + private static final long WAIT_TIME = 10000; + + @Test + public void testHandler() throws Exception { + StringBufferInputStream input = new StringBufferInputStream("abcde"); + ConsoleInputStream in = new ConsoleInputStream(); + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + ConsoleOutputStream out = new ConsoleOutputStream(byteOut); + Callback callback = createMock(Callback.class); + TelnetInputHandler handler = new TelnetInputHandler(input, in, out, callback); + handler.start(); + + // wait for the accept thread to start execution + try { + Thread.sleep(WAIT_TIME); + } catch (InterruptedException ie) { + // do nothing + } + + String res = byteOut.toString(); + Assert.assertTrue("Wrong input. Expected abcde, read " + res, res.equals("abcde")); + } + +} diff --git a/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetInputScannerTests.java b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetInputScannerTests.java new file mode 100755 index 000000000..679597358 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetInputScannerTests.java @@ -0,0 +1,223 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial contribution + ******************************************************************************/ + +package org.eclipse.equinox.console.telnet; + +import org.eclipse.equinox.console.common.ConsoleInputStream; +import org.eclipse.equinox.console.common.ConsoleOutputStream; +import org.eclipse.equinox.console.common.KEYS; +import org.eclipse.equinox.console.common.terminal.ANSITerminalTypeMappings; +import org.eclipse.equinox.console.common.terminal.SCOTerminalTypeMappings; +import org.eclipse.equinox.console.common.terminal.TerminalTypeMappings; +import org.eclipse.equinox.console.common.terminal.VT100TerminalTypeMappings; +import org.eclipse.equinox.console.common.terminal.VT220TerminalTypeMappings; +import org.eclipse.equinox.console.common.terminal.VT320TerminalTypeMappings; +import org.junit.Assert; +import org.junit.Test; + +import static org.easymock.EasyMock.*; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PipedInputStream; +import java.io.PipedOutputStream; +import java.util.HashMap; +import java.util.Map; + +public class TelnetInputScannerTests { + + private static final int IAC = 255; + + private static final int DO = 253; + + private static final int DO_NOT = 254; + + private static final int TTYPE = 24; + + private static final int WILL = 251; + + private static final int WILL_NOT = 252; + + private static final int SB = 250; + + private static final int SE = 240; + + private static final int EL = 248; + + private static final int SEND = 1; + + private static final int IS = 0; + + protected static final byte ESC = 27; + + @Test + public void testScan() throws Exception { + ConsoleInputStream in = new ConsoleInputStream(); + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + ConsoleOutputStream out = new ConsoleOutputStream(byteOut); + Callback callback = createMock(Callback.class); + TelnetInputScanner scanner = new TelnetInputScanner(in, out, callback); + try { + scanner.scan((byte) SE); + scanner.scan((byte) EL); + scanner.scan((byte) SB); + scanner.scan((byte) WILL); + scanner.scan((byte) WILL_NOT); + scanner.scan((byte) DO); + scanner.scan((byte) DO_NOT); + scanner.scan((byte) 'a'); + scanner.scan((byte) 'b'); + scanner.scan((byte) 'c'); + } catch (IOException e) { + System.out.println("Error while scanning: " + e.getMessage()); + e.printStackTrace(); + throw e; + } + + String output = byteOut.toString(); + Assert.assertTrue("Output incorrect. Expected abc, but read " + output, output.equals("abc")); + } + + @Test + public void testScanESC() throws Exception { + ConsoleInputStream in = new ConsoleInputStream(); + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + ConsoleOutputStream out = new ConsoleOutputStream(byteOut); + Callback callback = createMock(Callback.class); + TelnetInputScanner scanner = new TelnetInputScanner(in, out, callback); + + try { + scanner.scan((byte) 'a'); + scanner.scan((byte) ESC); + scanner.scan((byte) 'b'); + } catch (IOException e) { + System.out.println("Error while scanning: " + e.getMessage()); + e.printStackTrace(); + throw e; + } + + String output = byteOut.toString(); + Assert.assertTrue("Output incorrect. Expected ab, but read " + output, output.equals("ab")); + } + + @Test + public void testTTNegotiations() throws Exception { + Map ttMappings = new HashMap(); + ttMappings.put(new byte[] { 'A', 'N', 'S', 'I' }, new ANSITerminalTypeMappings()); + ttMappings.put(new byte[] { 'V', 'T', '1', '0', '0' }, new VT100TerminalTypeMappings()); + ttMappings.put(new byte[] { 'V', 'T', '2', '2', '0' }, new VT220TerminalTypeMappings()); + ttMappings.put(new byte[] { 'X', 'T', 'E', 'R', 'M' }, new VT220TerminalTypeMappings()); + ttMappings.put(new byte[] { 'V', 'T', '3', '2', '0' }, new VT320TerminalTypeMappings()); + ttMappings.put(new byte[] { 'S', 'C', 'O' }, new SCOTerminalTypeMappings()); + + for (byte[] ttype : ttMappings.keySet()) { + testTerminalTypeNegotiation(ttype, ttMappings.get(ttype)); + } + } + + private void testTerminalTypeNegotiation(byte[] terminalType, TerminalTypeMappings mappings) throws Exception { + PipedInputStream clientIn = new PipedInputStream(); + PipedOutputStream serverOut = new PipedOutputStream(clientIn); + + byte[] requestNegotiation = { (byte) IAC, (byte) DO, (byte) TTYPE }; + + TestCallback testCallback = new TestCallback(); + TelnetOutputStream out = new TelnetOutputStream(serverOut); + TelnetInputScanner scanner = new TelnetInputScanner(new ConsoleInputStream(), out, testCallback); + out.write(requestNegotiation); + out.flush(); + + int read = clientIn.read(); + Assert.assertEquals("Unexpected input ", IAC, read); + read = clientIn.read(); + Assert.assertEquals("Unexpected input ", DO, read); + read = clientIn.read(); + Assert.assertEquals("Unexpected input ", TTYPE, read); + + scanner.scan(IAC); + scanner.scan(WILL); + scanner.scan(TTYPE); + + read = clientIn.read(); + Assert.assertEquals("Unexpected input ", IAC, read); + read = clientIn.read(); + Assert.assertEquals("Unexpected input ", SB, read); + read = clientIn.read(); + Assert.assertEquals("Unexpected input ", TTYPE, read); + read = clientIn.read(); + Assert.assertEquals("Unexpected input ", SEND, read); + read = clientIn.read(); + Assert.assertEquals("Unexpected input ", IAC, read); + read = clientIn.read(); + Assert.assertEquals("Unexpected input ", SE, read); + + scanner.scan(IAC); + scanner.scan(SB); + scanner.scan(TTYPE); + scanner.scan(IS); + scanner.scan('A'); + scanner.scan('B'); + scanner.scan('C'); + scanner.scan('D'); + scanner.scan('E'); + scanner.scan(IAC); + scanner.scan(SE); + + read = clientIn.read(); + Assert.assertEquals("Unexpected input ", IAC, read); + read = clientIn.read(); + Assert.assertEquals("Unexpected input ", SB, read); + read = clientIn.read(); + Assert.assertEquals("Unexpected input ", TTYPE, read); + read = clientIn.read(); + Assert.assertEquals("Unexpected input ", SEND, read); + read = clientIn.read(); + Assert.assertEquals("Unexpected input ", IAC, read); + read = clientIn.read(); + Assert.assertEquals("Unexpected input ", SE, read); + + scanner.scan(IAC); + scanner.scan(SB); + scanner.scan(TTYPE); + scanner.scan(IS); + for (byte symbol : terminalType) { + scanner.scan(symbol); + } + scanner.scan(IAC); + scanner.scan(SE); + + Assert.assertEquals("Incorrect BACKSPACE: ", mappings.getBackspace(), scanner.getBackspace()); + Assert.assertEquals("Incorrect DELL: ", mappings.getDel(), scanner.getDel()); + + Map currentEscapesToKey = scanner.getCurrentEscapesToKey(); + Map expectedEscapesToKey = mappings.getEscapesToKey(); + for (String escape : expectedEscapesToKey.keySet()) { + KEYS key = expectedEscapesToKey.get(escape); + Assert.assertEquals("Incorrect " + key.name(), key, currentEscapesToKey.get(escape)); + } + + Assert.assertTrue("Callback not called ", testCallback.getState()); + } + + class TestCallback implements Callback { + + private boolean isCalled = false; + + public void finished() { + isCalled = true; + } + + public boolean getState() { + return isCalled; + } + } + +} diff --git a/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetOutputStreamTests.java b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetOutputStreamTests.java new file mode 100755 index 000000000..f975f4dc7 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetOutputStreamTests.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial contribution + ******************************************************************************/ + +package org.eclipse.equinox.console.telnet; + +import org.junit.Assert; +import org.junit.Test; + +import java.io.ByteArrayOutputStream; + +public class TelnetOutputStreamTests { + + @Test + public void testAutoSend() throws Exception { + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + TelnetOutputStream out = new TelnetOutputStream(byteOut); + out.autoSend(); + out.flush(); + byte[] message = byteOut.toByteArray(); + + Assert.assertNotNull("Auto message not sent", message); + Assert.assertFalse("Auto message not sent", message.length == 0); + Assert.assertTrue("Error sending auto message. Expected length: " + TelnetOutputStream.autoMessage.length + ", actual length: " + + message.length, message.length == TelnetOutputStream.autoMessage.length); + + for (int i = 0; i < message.length; i++) { + Assert.assertEquals("Wrong char in auto message. Position: " + i + ", expected: " + TelnetOutputStream.autoMessage[i] + ", read: " + + message[i], TelnetOutputStream.autoMessage[i], message[i]); + } + } +} diff --git a/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetServerTests.java b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetServerTests.java new file mode 100755 index 000000000..21eb4c546 --- /dev/null +++ b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetServerTests.java @@ -0,0 +1,125 @@ +/******************************************************************************* + * Copyright (c) 2011 SAP AG + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lazar Kirchev, SAP AG - initial contribution + ******************************************************************************/ + +package org.eclipse.equinox.console.telnet; + +import org.apache.felix.service.command.CommandProcessor; +import org.apache.felix.service.command.CommandSession; +import org.easymock.EasyMock; +import org.eclipse.equinox.console.common.ConsoleInputStream; +import org.junit.Assert; +import org.junit.Test; + +import java.io.OutputStream; +import java.io.PrintStream; +import java.net.ConnectException; +import java.net.Socket; +import java.util.ArrayList; +import java.util.List; + +import static org.easymock.EasyMock.*; + +public class TelnetServerTests { + + private static final String HOST = "localhost"; + private static final int PORT = 38888; + private static final long WAIT_TIME = 5000; + private static final int TEST_CONTENT = 100; + + @Test + public void testTelnetServer() throws Exception { + + CommandSession session = EasyMock.createMock(CommandSession.class); + session.put((String)EasyMock.anyObject(), EasyMock.anyObject()); + EasyMock.expectLastCall().times(3); + EasyMock.expect(session.execute((String)EasyMock.anyObject())).andReturn(new Object()); + session.close(); + EasyMock.expectLastCall(); + EasyMock.replay(session); + + CommandProcessor processor = EasyMock.createMock(CommandProcessor.class); + EasyMock.expect(processor.createSession((ConsoleInputStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject())).andReturn(session); + EasyMock.replay(processor); + + List processors = new ArrayList(); + processors.add(processor); + TelnetServer telnetServer = new TelnetServer(null, processors, HOST, PORT); + telnetServer.start(); + Socket socketClient = null; + + try { + socketClient = new Socket("localhost", PORT); + OutputStream outClient = socketClient.getOutputStream(); + outClient.write(TEST_CONTENT); + outClient.write('\n'); + outClient.flush(); + // wait for the accept thread to finish execution + try { + Thread.sleep(WAIT_TIME); + } catch (InterruptedException ie) { + // do nothing + } + verify(); + } catch(ConnectException e) { + Assert.fail("Telnet port not open"); + } finally { + if (socketClient != null) { + socketClient.close(); + } + telnetServer.stopTelnetServer(); + } + } + + @Test + public void testTelnetServerWithoutHost() throws Exception { + CommandSession session = EasyMock.createMock(CommandSession.class); + session.put((String)EasyMock.anyObject(), EasyMock.anyObject()); + EasyMock.expectLastCall().times(4); + EasyMock.expect(session.execute((String)EasyMock.anyObject())).andReturn(new Object()); + session.close(); + EasyMock.expectLastCall(); + EasyMock.replay(session); + + CommandProcessor processor = EasyMock.createMock(CommandProcessor.class); + EasyMock.expect(processor.createSession((ConsoleInputStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject())).andReturn(session); + EasyMock.replay(processor); + + List processors = new ArrayList(); + processors.add(processor); + TelnetServer telnetServer = new TelnetServer(null, processors, null, PORT); + telnetServer.start(); + Socket socketClient = null; + + try { + socketClient = new Socket("localhost", PORT); + OutputStream outClient = socketClient.getOutputStream(); + outClient.write(TEST_CONTENT); + outClient.write('\n'); + outClient.flush(); + + // wait for the accept thread to finish execution + try { + Thread.sleep(WAIT_TIME); + } catch (InterruptedException ie) { + // do nothing + } + } catch(ConnectException e) { + Assert.fail("Telnet port not open"); + } finally { + if (socketClient != null) { + socketClient.close(); + } + telnetServer.stopTelnetServer(); + } + + } + +} diff --git a/bundles/org.eclipse.equinox.console.ssh.tests/.classpath b/bundles/org.eclipse.equinox.console.ssh.tests/.classpath deleted file mode 100755 index 23f11b11a..000000000 --- a/bundles/org.eclipse.equinox.console.ssh.tests/.classpath +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/bundles/org.eclipse.equinox.console.ssh.tests/.project b/bundles/org.eclipse.equinox.console.ssh.tests/.project deleted file mode 100755 index ffacebcdd..000000000 --- a/bundles/org.eclipse.equinox.console.ssh.tests/.project +++ /dev/null @@ -1,28 +0,0 @@ - - - org.eclipse.equinox.console.ssh.tests - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - diff --git a/bundles/org.eclipse.equinox.console.ssh.tests/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.equinox.console.ssh.tests/.settings/org.eclipse.jdt.core.prefs deleted file mode 100755 index c3a62744c..000000000 --- a/bundles/org.eclipse.equinox.console.ssh.tests/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,8 +0,0 @@ -#Tue Oct 18 16:14:30 EEST 2011 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.6 diff --git a/bundles/org.eclipse.equinox.console.ssh.tests/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.console.ssh.tests/META-INF/MANIFEST.MF deleted file mode 100755 index 20f5ae4ba..000000000 --- a/bundles/org.eclipse.equinox.console.ssh.tests/META-INF/MANIFEST.MF +++ /dev/null @@ -1,12 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: Ssh Tests -Bundle-SymbolicName: org.eclipse.equinox.console.ssh.tests -Bundle-Version: 1.0.0.qualifier -Bundle-ActivationPolicy: lazy -Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Import-Package: junit.framework;version="4.8.1", - org.apache.sshd.client.future, - org.easymock;version="2.4.0", - org.junit;version="4.8.1" -Fragment-Host: org.eclipse.equinox.console.ssh, org.eclipse.equinox.console diff --git a/bundles/org.eclipse.equinox.console.ssh.tests/build.properties b/bundles/org.eclipse.equinox.console.ssh.tests/build.properties deleted file mode 100755 index 34d2e4d2d..000000000 --- a/bundles/org.eclipse.equinox.console.ssh.tests/build.properties +++ /dev/null @@ -1,4 +0,0 @@ -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - . diff --git a/bundles/org.eclipse.equinox.console.ssh.tests/forceQualifierUpdate.txt b/bundles/org.eclipse.equinox.console.ssh.tests/forceQualifierUpdate.txt deleted file mode 100644 index 56f1032a8..000000000 --- a/bundles/org.eclipse.equinox.console.ssh.tests/forceQualifierUpdate.txt +++ /dev/null @@ -1,2 +0,0 @@ -# To force a version qualifier update add the bug here -Bug 403352 - Update all parent versions to match our build stream diff --git a/bundles/org.eclipse.equinox.console.ssh.tests/hostkey.ser b/bundles/org.eclipse.equinox.console.ssh.tests/hostkey.ser deleted file mode 100755 index cb61e708c..000000000 Binary files a/bundles/org.eclipse.equinox.console.ssh.tests/hostkey.ser and /dev/null differ diff --git a/bundles/org.eclipse.equinox.console.ssh.tests/org.eclipse.equinox.console.ssh.SshShellTests_store b/bundles/org.eclipse.equinox.console.ssh.tests/org.eclipse.equinox.console.ssh.SshShellTests_store deleted file mode 100755 index f80649daa..000000000 --- a/bundles/org.eclipse.equinox.console.ssh.tests/org.eclipse.equinox.console.ssh.SshShellTests_store +++ /dev/null @@ -1,3 +0,0 @@ -#Wed Oct 19 10:21:35 EEST 2011 -/ssh/username/roles= -/ssh/username/password=0d85584b3529eaac630d1b7ddde2418308d56317 diff --git a/bundles/org.eclipse.equinox.console.ssh.tests/pom.xml b/bundles/org.eclipse.equinox.console.ssh.tests/pom.xml deleted file mode 100644 index 38444f5ee..000000000 --- a/bundles/org.eclipse.equinox.console.ssh.tests/pom.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - 4.0.0 - - tests-pom - org.eclipse.equinox.bundles - 4.6.0-SNAPSHOT - ../../tests-pom/ - - org.eclipse.equinox - org.eclipse.equinox.console.ssh.tests - 1.0.0-SNAPSHOT - eclipse-test-plugin - diff --git a/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/jaas/RolePrincipalTests.java b/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/jaas/RolePrincipalTests.java deleted file mode 100755 index edae26f3b..000000000 --- a/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/jaas/RolePrincipalTests.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial API and implementation - *******************************************************************************/ - -package org.eclipse.equinox.console.jaas; - -import static org.junit.Assert.*; - -import org.junit.Test; - -public class RolePrincipalTests { - - private static final String ROLE_NAME = "administrator"; - - @Test - public void testHashCode() { - RolePrincipal role = new RolePrincipal(ROLE_NAME); - assertEquals("Role hash code not as expected", 73 + ROLE_NAME.hashCode(), role.hashCode()); - } - - @Test - public void testGetName() { - RolePrincipal role = new RolePrincipal(ROLE_NAME); - assertEquals("Role not as expected", ROLE_NAME, role.getName()); - } - - @Test - public void testEqualsObject() { - RolePrincipal role = new RolePrincipal(ROLE_NAME); - RolePrincipal sameRole = new RolePrincipal(ROLE_NAME); - RolePrincipal emptyRole = new RolePrincipal(null); - - assertTrue("Roles should be equal", role.equals(role)); - assertTrue("Roles should be equal", role.equals(sameRole)); - assertFalse("Roles should not be equal", role.equals(emptyRole)); - } - -} diff --git a/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/jaas/UserPrincipalTests.java b/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/jaas/UserPrincipalTests.java deleted file mode 100755 index 50239be1c..000000000 --- a/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/jaas/UserPrincipalTests.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial API and implementation - *******************************************************************************/ - -package org.eclipse.equinox.console.jaas; - -import static org.junit.Assert.*; - -import java.util.Set; - -import org.junit.BeforeClass; -import org.junit.Test; - -public class UserPrincipalTests { - - private static final String USERNAME = "username"; - private static final String PASSWORD = "password"; - private static final String OTHERUSER = "otheruser"; - private static final String OTHERPASSWORD = "otherpass"; - private static final String WRONG_PASS = "wrong_pass"; - private static final String ROLE = "administrator"; - private static final String OTHERROLE = "otherrole"; - - @Test - public void testHashCode() { - UserPrincipal user = new UserPrincipal(USERNAME, PASSWORD); - RolePrincipal role = new RolePrincipal(ROLE); - user.addRole(role); - - int expectedHash = 73 + USERNAME.hashCode(); - expectedHash = 73*expectedHash + PASSWORD.hashCode(); - expectedHash = 73*expectedHash + role.hashCode(); - assertEquals("User hash code not as expected", expectedHash, user.hashCode()); - } - - @Test - public void testGetName() { - UserPrincipal user = new UserPrincipal(USERNAME, PASSWORD); - assertEquals("Username not as expected", USERNAME, user.getName()); - } - - @Test - public void testAuthenticate() { - UserPrincipal user = new UserPrincipal(USERNAME, PASSWORD); - assertTrue("User should be successfully authenticated", user.authenticate(PASSWORD.toCharArray())); - assertFalse("User should not be authenticated", user.authenticate(WRONG_PASS.toCharArray())); - } - - @Test - public void testGetRoles() { - UserPrincipal user = new UserPrincipal(USERNAME, PASSWORD); - RolePrincipal role = new RolePrincipal(ROLE); - user.addRole(role); - Set roles = user.getRoles(); - assertEquals("There should be one role", 1, roles.size()); - assertTrue("User roles should contain the role administrator", roles.contains(role)); - } - - @Test - public void testEqualsObject() { - UserPrincipal user = new UserPrincipal(USERNAME, PASSWORD); - RolePrincipal role = new RolePrincipal(ROLE); - user.addRole(role); - - UserPrincipal sameUser = new UserPrincipal(USERNAME, PASSWORD); - RolePrincipal sameRole = new RolePrincipal(ROLE); - sameUser.addRole(sameRole); - - UserPrincipal otherUser = new UserPrincipal(OTHERUSER, OTHERPASSWORD); - RolePrincipal otherRole = new RolePrincipal(OTHERROLE); - otherUser.addRole(otherRole); - - UserPrincipal userOtherRole = new UserPrincipal(USERNAME, PASSWORD); - RolePrincipal otherRolePrincipal = new RolePrincipal(OTHERROLE); - userOtherRole.addRole(otherRolePrincipal); - - assertTrue("User should be equal to itself", user.equals(user)); - assertTrue("Users should be equal", user.equals(sameUser)); - assertFalse("Users should not be equal", user.equals(otherUser)); - assertFalse("Users should not be equal", user.equals(userOtherRole)); - } - - @Test - public void testDestroy() { - UserPrincipal user = new UserPrincipal(USERNAME, PASSWORD); - UserPrincipal same = new UserPrincipal(USERNAME, PASSWORD); - - user.destroy(); - assertFalse("Users should not be equal", user.equals(same)); - } - -} diff --git a/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshCommandTests.java b/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshCommandTests.java deleted file mode 100755 index 7fab9788b..000000000 --- a/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshCommandTests.java +++ /dev/null @@ -1,188 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial API and implementation - *******************************************************************************/ - -package org.eclipse.equinox.console.ssh; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.PrintStream; -import java.io.PrintWriter; -import java.io.StringBufferInputStream; -import java.util.Dictionary; -import java.util.HashMap; -import java.util.Map; - -import org.apache.felix.service.command.CommandProcessor; -import org.apache.felix.service.command.CommandSession; -import org.apache.sshd.ClientChannel; -import org.apache.sshd.ClientSession; -import org.apache.sshd.SshClient; -import org.apache.sshd.client.future.ConnectFuture; -import org.apache.sshd.client.future.DefaultConnectFuture; -import org.apache.sshd.server.Environment; -import org.easymock.EasyMock; -import org.eclipse.equinox.console.common.ConsoleInputStream; -import org.eclipse.equinox.console.storage.DigestUtil; -import org.eclipse.equinox.console.storage.SecureUserStore; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.osgi.framework.BundleContext; - - -public class SshCommandTests { - private static final int TEST_CONTENT = 100; - private static final String USER_STORE_FILE_NAME = "org.eclipse.equinox.console.jaas.file"; - private static final String JAAS_CONFIG_FILE_NAME = "jaas.config"; - private static final String JAAS_CONFIG_PROPERTY_NAME = "java.security.auth.login.config"; - private static final String DEFAULT_USER_STORAGE = "osgi.console.ssh.useDefaultSecureStorage"; - private static final String SSH_PORT_PROP_NAME = "osgi.console.ssh"; - private static final String USE_CONFIG_ADMIN_PROP = "osgi.console.useConfigAdmin"; - private static final String STORE_FILE_NAME = SshCommandTests.class.getName() + "_store"; - private static final String GOGO_SHELL_COMMAND = "gosh --login --noshutdown"; - private static final String TRUE = "true"; - private static final String FALSE = "false"; - private static final String USERNAME = "username"; - private static final String PASSWORD = "password"; - private static final String START_COMMAND = "start"; - private static final String STOP_COMMAND = "stop"; - private static final String TERM_PROPERTY = "TERM"; - private static final String XTERM = "XTERM"; - private static final String HOST = "localhost"; - private static final int SSH_PORT = 2222; - private static final long WAIT_TIME = 5000; - - @Before - public void init() throws Exception { - clean(); - initStore(); - initJaasConfigFile(); - } - - @Test - public void testSshCommand() throws Exception { - CommandSession session = EasyMock.createMock(CommandSession.class); - EasyMock.makeThreadSafe(session, true); - session.put((String)EasyMock.anyObject(), EasyMock.anyObject()); - EasyMock.expectLastCall().times(5); - EasyMock.expect(session.execute(GOGO_SHELL_COMMAND)).andReturn(null); - session.close(); - EasyMock.expectLastCall(); - EasyMock.replay(session); - - CommandProcessor processor = EasyMock.createMock(CommandProcessor.class); - EasyMock.expect(processor.createSession((ConsoleInputStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject())).andReturn(session); - EasyMock.replay(processor); - - BundleContext context = EasyMock.createMock(BundleContext.class); - EasyMock.makeThreadSafe(context, true); - EasyMock.expect(context.getProperty(USE_CONFIG_ADMIN_PROP)).andReturn(FALSE); - EasyMock.expect(context.getProperty(DEFAULT_USER_STORAGE)).andReturn(TRUE).anyTimes(); - EasyMock.expect(context.getProperty(SSH_PORT_PROP_NAME)).andReturn(Integer.toString(SSH_PORT)); - EasyMock.expect(context.registerService((String)EasyMock.anyObject(), EasyMock.anyObject(), (Dictionary)EasyMock.anyObject())).andReturn(null); - EasyMock.replay(context); - - Map environment = new HashMap(); - environment.put(TERM_PROPERTY, XTERM); - Environment env = EasyMock.createMock(Environment.class); - EasyMock.expect(env.getEnv()).andReturn(environment); - EasyMock.replay(env); - - SshCommand command = new SshCommand(processor, context); - command.ssh(new String[] {START_COMMAND}); - - SshClient client = SshClient.setUpDefaultClient(); - client.start(); - try { - ConnectFuture connectFuture = client.connect(HOST, SSH_PORT); - DefaultConnectFuture defaultConnectFuture = (DefaultConnectFuture) connectFuture; - - try { - Thread.sleep(WAIT_TIME); - } catch (InterruptedException ie) { - // do nothing - } - ClientSession sshSession = defaultConnectFuture.getSession(); - - int ret = ClientSession.WAIT_AUTH; - sshSession.authPassword(USERNAME, PASSWORD); - ret = sshSession.waitFor(ClientSession.WAIT_AUTH | ClientSession.CLOSED | ClientSession.AUTHED, 0); - - if ((ret & ClientSession.CLOSED) != 0) { - System.err.println("error"); - System.exit(-1); - } - ClientChannel channel = sshSession.createChannel("shell"); - channel.setIn(new StringBufferInputStream(TEST_CONTENT + "\n")); - ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - channel.setOut(byteOut); - channel.setErr(byteOut); - channel.open(); - try { - Thread.sleep(WAIT_TIME); - } catch (InterruptedException ie) { - // do nothing - } - byte[] output = byteOut.toByteArray(); - Assert.assertEquals("Output not as expected",Integer.toString(TEST_CONTENT), new String(output).trim()); - sshSession.close(true); - } finally { - client.stop(); - } - - command.ssh(new String[] {STOP_COMMAND}); - return; - } - - @After - public void cleanUp() { - clean(); - } - - private void clean() { - System.setProperty(USER_STORE_FILE_NAME, ""); - File file = new File(STORE_FILE_NAME); - if (file.exists()) { - file.delete(); - } - - System.setProperty(JAAS_CONFIG_PROPERTY_NAME, ""); - File jaasConfFile = new File(JAAS_CONFIG_FILE_NAME); - if (jaasConfFile.exists()) { - jaasConfFile.delete(); - } - } - - private void initStore() throws Exception { - System.setProperty(USER_STORE_FILE_NAME, STORE_FILE_NAME); - SecureUserStore.initStorage(); - SecureUserStore.putUser(USERNAME, DigestUtil.encrypt(PASSWORD), null); - } - - private void initJaasConfigFile() throws Exception { - System.setProperty(JAAS_CONFIG_PROPERTY_NAME, JAAS_CONFIG_FILE_NAME); - File jaasConfFile = new File(JAAS_CONFIG_FILE_NAME); - if (!jaasConfFile.exists()) { - PrintWriter out = null; - try { - out = new PrintWriter(jaasConfFile); - out.println("equinox_console {"); - out.println(" org.eclipse.equinox.console.jaas.SecureStorageLoginModule REQUIRED;"); - out.println("};"); - } finally { - if (out != null) { - out.close(); - } - } - } - } -} diff --git a/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshCommandWithConfigAdminTests.java b/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshCommandWithConfigAdminTests.java deleted file mode 100755 index 43d924470..000000000 --- a/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshCommandWithConfigAdminTests.java +++ /dev/null @@ -1,320 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.console.ssh; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.InputStream; -import java.io.PrintStream; -import java.io.PrintWriter; -import java.io.StringBufferInputStream; -import java.util.Collection; -import java.util.Dictionary; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.Map; - -import org.apache.felix.service.command.CommandProcessor; -import org.apache.felix.service.command.CommandSession; -import org.apache.sshd.ClientChannel; -import org.apache.sshd.ClientSession; -import org.apache.sshd.SshClient; -import org.apache.sshd.client.future.ConnectFuture; -import org.apache.sshd.client.future.DefaultConnectFuture; -import org.apache.sshd.common.RuntimeSshException; -import org.apache.sshd.server.Environment; -import org.easymock.EasyMock; -import org.easymock.IAnswer; -import org.eclipse.equinox.console.common.ConsoleInputStream; -import org.eclipse.equinox.console.storage.DigestUtil; -import org.eclipse.equinox.console.storage.SecureUserStore; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleException; -import org.osgi.framework.BundleListener; -import org.osgi.framework.Filter; -import org.osgi.framework.FrameworkListener; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceListener; -import org.osgi.framework.ServiceReference; -import org.osgi.framework.ServiceRegistration; -import org.osgi.service.cm.ManagedService; - - -public class SshCommandWithConfigAdminTests { - private static final int TEST_CONTENT = 100; - private static final String USER_STORE_FILE_NAME = "org.eclipse.equinox.console.jaas.file"; - private static final String JAAS_CONFIG_FILE_NAME = "jaas.config"; - private static final String JAAS_CONFIG_PROPERTY_NAME = "java.security.auth.login.config"; - private static final String DEFAULT_USER_STORAGE = "osgi.console.ssh.useDefaultSecureStorage"; - private static final String STORE_FILE_NAME = SshCommandTests.class.getName() + "_store"; - private static final String GOGO_SHELL_COMMAND = "gosh --login --noshutdown"; - private static final String TRUE = "true"; - private static final String FALSE = "false"; - private static final String USERNAME = "username"; - private static final String PASSWORD = "password"; - private static final String STOP_COMMAND = "stop"; - private static final String TERM_PROPERTY = "TERM"; - private static final String XTERM = "XTERM"; - private static final String HOST = "localhost"; - private static final String SSH_PORT = "2222"; - private static final long WAIT_TIME = 5000; - private static final String USE_CONFIG_ADMIN_PROP = "osgi.console.useConfigAdmin"; - private ManagedService configurator; - - @Before - public void init() throws Exception { - clean(); - initStore(); - initJaasConfigFile(); - } - - @Test - public void testSshCommandWithConfigAdmin() throws Exception { - - CommandSession session = EasyMock.createMock(CommandSession.class); - EasyMock.makeThreadSafe(session, true); - session.put((String)EasyMock.anyObject(), EasyMock.anyObject()); - EasyMock.expectLastCall().times(5); - EasyMock.expect(session.execute(GOGO_SHELL_COMMAND)).andReturn(null); - session.close(); - EasyMock.expectLastCall(); - EasyMock.replay(session); - - CommandProcessor processor = EasyMock.createMock(CommandProcessor.class); - EasyMock.expect(processor.createSession((ConsoleInputStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject())).andReturn(session); - EasyMock.replay(processor); - - final ServiceRegistration registration = EasyMock.createMock(ServiceRegistration.class); - registration.setProperties((Dictionary)EasyMock.anyObject()); - EasyMock.expectLastCall(); - EasyMock.replay(registration); - - BundleContext context = EasyMock.createMock(BundleContext.class); - EasyMock.makeThreadSafe(context, true); - EasyMock.expect(context.getProperty(USE_CONFIG_ADMIN_PROP)).andReturn(TRUE); - EasyMock.expect(context.getProperty(DEFAULT_USER_STORAGE)).andReturn(TRUE).anyTimes(); - EasyMock.expect( - (ServiceRegistration) context.registerService( - (String)EasyMock.anyObject(), - (ManagedService)EasyMock.anyObject(), - (Dictionary)EasyMock.anyObject()) - ).andAnswer((IAnswer>) new IAnswer>() { - public ServiceRegistration answer() { - configurator = (ManagedService) EasyMock.getCurrentArguments()[1]; - return registration; - } - }); - EasyMock.expect( - context.registerService( - (String)EasyMock.anyObject(), - (SshCommand)EasyMock.anyObject(), - (Dictionary)EasyMock.anyObject())).andReturn(null); - EasyMock.replay(context); - - Map environment = new HashMap(); - environment.put(TERM_PROPERTY, XTERM); - Environment env = EasyMock.createMock(Environment.class); - EasyMock.expect(env.getEnv()).andReturn(environment); - EasyMock.replay(env); - - SshCommand command = new SshCommand(processor, context); - Dictionary props = new Hashtable(); - props.put("port", SSH_PORT); - props.put("host", HOST); - props.put("enabled", TRUE); - configurator.updated(props); - - SshClient client = SshClient.setUpDefaultClient(); - client.start(); - try { - ConnectFuture connectFuture = client.connect(HOST, Integer.valueOf(SSH_PORT)); - DefaultConnectFuture defaultConnectFuture = (DefaultConnectFuture) connectFuture; - - try { - Thread.sleep(WAIT_TIME); - } catch (InterruptedException ie) { - // do nothing - } - ClientSession sshSession = defaultConnectFuture.getSession(); - - int ret = ClientSession.WAIT_AUTH; - sshSession.authPassword(USERNAME, PASSWORD); - ret = sshSession.waitFor(ClientSession.WAIT_AUTH | ClientSession.CLOSED | ClientSession.AUTHED, 0); - - if ((ret & ClientSession.CLOSED) != 0) { - System.err.println("error"); - System.exit(-1); - } - ClientChannel channel = sshSession.createChannel("shell"); - channel.setIn(new StringBufferInputStream(TEST_CONTENT + "\n")); - ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - channel.setOut(byteOut); - channel.setErr(byteOut); - channel.open(); - try { - Thread.sleep(WAIT_TIME); - } catch (InterruptedException ie) { - // do nothing - } - byte[] output = byteOut.toByteArray(); - Assert.assertEquals("Output not as expected",Integer.toString(TEST_CONTENT), new String(output).trim()); - sshSession.close(true); - } finally { - client.stop(); - } - - command.ssh(new String[] {STOP_COMMAND}); - return; - } - - @Test - public void testSshCommandWithConfigAdminDisabledSsh() throws Exception { - testDisabled(false); - } - - @Test - public void testSshCommandWithConfigAdminDisabledSshByDefault() throws Exception { - testDisabled(true); - } - - private void testDisabled(boolean isDefault) throws Exception { - CommandSession session = EasyMock.createMock(CommandSession.class); - session.put((String)EasyMock.anyObject(), EasyMock.anyObject()); - EasyMock.expectLastCall().times(4); - EasyMock.expect(session.execute(GOGO_SHELL_COMMAND)).andReturn(null); - session.close(); - EasyMock.expectLastCall(); - EasyMock.replay(session); - - CommandProcessor processor = EasyMock.createMock(CommandProcessor.class); - EasyMock.expect(processor.createSession((ConsoleInputStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject())).andReturn(session); - EasyMock.replay(processor); - - final ServiceRegistration registration = EasyMock.createMock(ServiceRegistration.class); - registration.setProperties((Dictionary)EasyMock.anyObject()); - EasyMock.expectLastCall(); - EasyMock.replay(registration); - - BundleContext context = EasyMock.createMock(BundleContext.class); - EasyMock.expect(context.getProperty(USE_CONFIG_ADMIN_PROP)).andReturn(TRUE); - EasyMock.expect(context.getProperty(DEFAULT_USER_STORAGE)).andReturn(TRUE).anyTimes(); - EasyMock.expect( - (ServiceRegistration) context.registerService( - (String)EasyMock.anyObject(), - (ManagedService)EasyMock.anyObject(), - (Dictionary)EasyMock.anyObject()) - ).andAnswer((IAnswer>) new IAnswer>() { - public ServiceRegistration answer() { - configurator = (ManagedService) EasyMock.getCurrentArguments()[1]; - return registration; - } - }); - EasyMock.expect( - context.registerService( - (String)EasyMock.anyObject(), - (SshCommand)EasyMock.anyObject(), - (Dictionary)EasyMock.anyObject())).andReturn(null); - EasyMock.replay(context); - - Map environment = new HashMap(); - environment.put(TERM_PROPERTY, XTERM); - Environment env = EasyMock.createMock(Environment.class); - EasyMock.expect(env.getEnv()).andReturn(environment); - EasyMock.replay(env); - - SshCommand command = new SshCommand(processor, context); - Dictionary props = new Hashtable(); - props.put("port", SSH_PORT); - props.put("host", HOST); - if (isDefault == false) { - props.put("enabled", FALSE); - } - configurator.updated(props); - - SshClient client = SshClient.setUpDefaultClient(); - client.start(); - try { - ConnectFuture connectFuture = client.connect(HOST, Integer.valueOf(SSH_PORT)); - DefaultConnectFuture defaultConnectFuture = (DefaultConnectFuture) connectFuture; - - try { - Thread.sleep(WAIT_TIME); - } catch (InterruptedException ie) { - // do nothing - } - ClientSession sshSession; - try { - sshSession = defaultConnectFuture.getSession(); - Assert.fail("It should not be possible to connect to " + HOST + ":" + SSH_PORT); - } catch (RuntimeSshException e) { - //this is expected - } - } finally { - client.stop(); - } - - try { - command.ssh(new String[] {STOP_COMMAND}); - } catch (IllegalStateException e) { - // this is expected - } - return; - } - - @After - public void cleanUp() { - clean(); - } - - private void clean() { - System.setProperty(USER_STORE_FILE_NAME, ""); - File file = new File(STORE_FILE_NAME); - if (file.exists()) { - file.delete(); - } - - System.setProperty(JAAS_CONFIG_PROPERTY_NAME, ""); - File jaasConfFile = new File(JAAS_CONFIG_FILE_NAME); - if (jaasConfFile.exists()) { - jaasConfFile.delete(); - } - } - - private void initStore() throws Exception { - System.setProperty(USER_STORE_FILE_NAME, STORE_FILE_NAME); - SecureUserStore.initStorage(); - SecureUserStore.putUser(USERNAME, DigestUtil.encrypt(PASSWORD), null); - } - - private void initJaasConfigFile() throws Exception { - System.setProperty(JAAS_CONFIG_PROPERTY_NAME, JAAS_CONFIG_FILE_NAME); - File jaasConfFile = new File(JAAS_CONFIG_FILE_NAME); - if (!jaasConfFile.exists()) { - PrintWriter out = null; - try { - out = new PrintWriter(jaasConfFile); - out.println("equinox_console {"); - out.println(" org.eclipse.equinox.console.jaas.SecureStorageLoginModule REQUIRED;"); - out.println("};"); - } finally { - if (out != null) { - out.close(); - } - } - } - } - -} diff --git a/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshInputHandlerTests.java b/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshInputHandlerTests.java deleted file mode 100755 index e7ed407a0..000000000 --- a/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshInputHandlerTests.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial API and implementation - *******************************************************************************/ - -package org.eclipse.equinox.console.ssh; - -import java.io.ByteArrayOutputStream; -import java.io.StringBufferInputStream; - -import org.eclipse.equinox.console.common.ConsoleInputStream; -import org.eclipse.equinox.console.common.ConsoleOutputStream; -import org.eclipse.equinox.console.ssh.SshInputHandler; -import org.junit.Assert; -import org.junit.Test; - - -public class SshInputHandlerTests { - - private static final long WAIT_TIME = 10000; - - @Test - public void testHandler() throws Exception { - StringBufferInputStream input = new StringBufferInputStream("abcde"); - ConsoleInputStream in = new ConsoleInputStream(); - ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - ConsoleOutputStream out = new ConsoleOutputStream(byteOut); - SshInputHandler handler = new SshInputHandler(input, in, out); - handler.start(); - - // wait for the accept thread to start execution - try { - Thread.sleep(WAIT_TIME); - } catch (InterruptedException ie) { - // do nothing - } - - String res = byteOut.toString(); - Assert.assertTrue("Wrong input. Expected abcde, read " + res, res.equals("abcde")); - } -} diff --git a/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshInputScannerTests.java b/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshInputScannerTests.java deleted file mode 100755 index 5f246fbdc..000000000 --- a/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshInputScannerTests.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial API and implementation - *******************************************************************************/ - -package org.eclipse.equinox.console.ssh; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -import org.eclipse.equinox.console.common.ConsoleInputStream; -import org.eclipse.equinox.console.common.ConsoleOutputStream; -import org.junit.Assert; -import org.junit.Test; - - -public class SshInputScannerTests { - - private static final byte ESC = 27; - - @Test - public void testScan() throws Exception { - ConsoleInputStream in = new ConsoleInputStream(); - ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - ConsoleOutputStream out = new ConsoleOutputStream(byteOut); - SshInputScanner scanner = new SshInputScanner(in, out); - try { - scanner.scan((byte) 'a'); - scanner.scan((byte) 'b'); - scanner.scan((byte) 'c'); - } catch (IOException e) { - System.out.println("Error while scanning: " + e.getMessage()); - e.printStackTrace(); - throw e; - } - - String output = byteOut.toString(); - Assert.assertTrue("Output incorrect. Expected abc, but read " + output, output.equals("abc")); - } - - @Test - public void testScanESC() throws Exception { - ConsoleInputStream in = new ConsoleInputStream(); - ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - ConsoleOutputStream out = new ConsoleOutputStream(byteOut); - SshInputScanner scanner = new SshInputScanner(in, out); - - try { - scanner.scan((byte) 'a'); - scanner.scan((byte) ESC); - scanner.scan((byte) 'b'); - } catch (IOException e) { - System.out.println("Error while scanning: " + e.getMessage()); - e.printStackTrace(); - throw e; - } - - String output = byteOut.toString(); - Assert.assertTrue("Output incorrect. Expected ab, but read " + output, output.equals("ab")); - } -} diff --git a/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshShellTests.java b/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshShellTests.java deleted file mode 100755 index 9c041fdf0..000000000 --- a/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshShellTests.java +++ /dev/null @@ -1,152 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial API and implementation - *******************************************************************************/ - -package org.eclipse.equinox.console.ssh; - -import java.io.File; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PrintStream; -import java.net.ServerSocket; -import java.net.Socket; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.felix.service.command.CommandProcessor; -import org.apache.felix.service.command.CommandSession; -import org.apache.sshd.server.Environment; -import org.easymock.EasyMock; -import org.eclipse.equinox.console.common.ConsoleInputStream; -import org.eclipse.equinox.console.storage.DigestUtil; -import org.eclipse.equinox.console.storage.SecureUserStore; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.osgi.framework.BundleContext; - - -public class SshShellTests { - - private static final int TEST_CONTENT = 100; - private static final String USER_STORE_FILE_NAME = "org.eclipse.equinox.console.jaas.file"; - private static final String DEFAULT_USER_STORAGE = "osgi.console.ssh.useDefaultSecureStorage"; - private static final String USER_STORE_NAME = SshShellTests.class.getName() + "_store"; - private static final String HOST = "localhost"; - private static final String GOGO_SHELL_COMMAND = "gosh --login --noshutdown"; - private static final String TERM_PROPERTY = "TERM"; - private static final String XTERM = "XTERM"; - private static final String USERNAME = "username"; - private static final String PASSWORD = "password"; - private static final String TRUE = "true"; - - @Before - public void init() throws Exception { - clean(); - initStore(); - } - - @Test - public void testSshConnection() throws Exception { - ServerSocket servSocket = null; - Socket socketClient = null; - Socket socketServer = null; - SshShell shell = null; - OutputStream outClient = null; - OutputStream outServer = null; - - try { - - servSocket = new ServerSocket(0); - socketClient = new Socket(HOST, servSocket.getLocalPort()); - socketServer = servSocket.accept(); - - CommandSession session = EasyMock.createMock(CommandSession.class); - EasyMock.makeThreadSafe(session, true); - session.put((String)EasyMock.anyObject(), EasyMock.anyObject()); - EasyMock.expectLastCall().times(5); - EasyMock.expect(session.execute(GOGO_SHELL_COMMAND)).andReturn(null); - session.close(); - EasyMock.expectLastCall(); - EasyMock.replay(session); - - CommandProcessor processor = EasyMock.createMock(CommandProcessor.class); - EasyMock.expect(processor.createSession((ConsoleInputStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject())).andReturn(session); - EasyMock.replay(processor); - - BundleContext context = EasyMock.createMock(BundleContext.class); - EasyMock.makeThreadSafe(context, true); - EasyMock.expect(context.getProperty(DEFAULT_USER_STORAGE)).andReturn(TRUE); - EasyMock.replay(context); - - Map environment = new HashMap(); - environment.put(TERM_PROPERTY, XTERM); - Environment env = EasyMock.createMock(Environment.class); - EasyMock.expect(env.getEnv()).andReturn(environment); - EasyMock.replay(env); - - List processors = new ArrayList(); - processors.add(processor); - shell = new SshShell(processors, context); - shell.setInputStream(socketServer.getInputStream()); - shell.setOutputStream(socketServer.getOutputStream()); - shell.start(env); - - outClient = socketClient.getOutputStream(); - outClient.write(TEST_CONTENT); - outClient.write('\n'); - outClient.flush(); - InputStream input = socketClient.getInputStream(); - int in = input.read(); - Assert.assertTrue("Server received [" + in + "] instead of " + TEST_CONTENT + " from the ssh client.", in == TEST_CONTENT); - } finally { - if (socketClient != null) { - socketClient.close(); - } - if (outClient != null) { - outClient.close(); - } - if (outServer != null) { - outServer.close(); - } - - if (socketServer != null) { - socketServer.close(); - } - - if (servSocket != null) { - servSocket.close(); - } - - } - } - - @After - public void cleanUp() { - clean(); - } - - private void initStore() throws Exception { - System.setProperty(USER_STORE_FILE_NAME, USER_STORE_NAME); - SecureUserStore.initStorage(); - SecureUserStore.putUser(USERNAME, DigestUtil.encrypt(PASSWORD), null); - } - - private void clean() { - System.setProperty(USER_STORE_FILE_NAME, ""); - File file = new File(USER_STORE_NAME); - if(file.exists()) { - file.delete(); - } - } -} diff --git a/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/UserAdminCommandTests.java b/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/UserAdminCommandTests.java deleted file mode 100755 index 658690178..000000000 --- a/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/UserAdminCommandTests.java +++ /dev/null @@ -1,119 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial API and implementation - *******************************************************************************/ - -package org.eclipse.equinox.console.ssh; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.util.HashSet; -import java.util.Set; - -import org.apache.felix.service.command.CommandSession; -import org.easymock.EasyMock; -import org.eclipse.equinox.console.storage.DigestUtil; -import org.eclipse.equinox.console.storage.SecureUserStore; -import org.junit.After; -import org.junit.Test; - - -public class UserAdminCommandTests { - - private static final String USER_STORE_FILE_NAME_PROPERTY = "org.eclipse.equinox.console.jaas.file"; - private static final String USER_STORE_FILE_NAME = UserAdminCommandTests.class.getName() + "_store"; - private static final String USERNAME_OPTION = "-username"; - private static final String PASSWORD_OPTION = "-password"; - private static final String ROLES_OPTION = "-roles"; - private static final String USERNAME1 = "username1"; - private static final String USERNAME2 = "username2"; - private static final String PASSWORD1 = "password1"; - private static final String PASSWORD2 = "password2"; - private static final String ROLES1 = "role1,role2"; - private static final String ROLES2 = "role3,role4"; - private static final String ROLES_TO_REMOVE = "role2"; - private static final String REMAINING_ROLES = "role1"; - - @Test - public void testCommand() throws Exception { - cleanUp(); - - System.setProperty(USER_STORE_FILE_NAME_PROPERTY, USER_STORE_FILE_NAME); - SecureUserStore.initStorage(); - - CommandSession session = EasyMock.createMock(CommandSession.class); - session.put((String)EasyMock.anyObject(), EasyMock.anyObject()); - EasyMock.expectLastCall().times(3); - EasyMock.replay(session); - - UserAdminCommand command = new UserAdminCommand(); - command.addUser(new String[] {USERNAME_OPTION, USERNAME1, PASSWORD_OPTION, PASSWORD1}); - command.addUser(new String[] {USERNAME_OPTION, USERNAME2, PASSWORD_OPTION, PASSWORD2, ROLES_OPTION, ROLES2}); - - String[] usernames = SecureUserStore.getUserNames(); - boolean arePresent = (usernames[0].equals(USERNAME1) || usernames[0].equals(USERNAME2)) && (usernames[1].equals(USERNAME1) || usernames[1].equals(USERNAME2)) && (!usernames[0].equals(usernames[1])); - assertTrue("Usernames not correctly saved", arePresent); - - String pass1 = SecureUserStore.getPassword(USERNAME1); - String pass2 = SecureUserStore.getPassword(USERNAME2); - assertTrue("Passwords not correctly saved", pass1.equals(DigestUtil.encrypt(PASSWORD1)) && pass2.equals(DigestUtil.encrypt(PASSWORD2))); - - String roles = SecureUserStore.getRoles(USERNAME2); - assertEquals("Roles for the second user are not as expected", ROLES2, roles); - - command.addRoles(new String[] {USERNAME_OPTION, USERNAME1, ROLES_OPTION, ROLES1}); - roles = SecureUserStore.getRoles(USERNAME1); - boolean areRolesEqual = compareRoles(ROLES1, roles); - assertTrue("Roles for the first user are not as expected", areRolesEqual); - - command.removeRoles(new String[] {USERNAME_OPTION, USERNAME1, ROLES_OPTION, ROLES_TO_REMOVE}); - roles = SecureUserStore.getRoles(USERNAME1); - areRolesEqual = compareRoles(REMAINING_ROLES, roles); - assertTrue("Roles for the first user are not as expected", areRolesEqual); - - command.resetPassword(USERNAME1); - String pass = SecureUserStore.getPassword(USERNAME1); - assertNull("Password should be null", pass); - - command.setPassword(new String[] {USERNAME_OPTION, USERNAME1, PASSWORD_OPTION, PASSWORD1}); - pass = SecureUserStore.getPassword(USERNAME1); - assertEquals("Password should be null", DigestUtil.encrypt(PASSWORD1), pass); - - command.deleteUser(USERNAME2); - assertFalse("User2 should not exist", SecureUserStore.existsUser(USERNAME2)); - } - - @After - public void cleanUp() { - System.setProperty(USER_STORE_FILE_NAME_PROPERTY, ""); - File file = new File(USER_STORE_FILE_NAME); - if(file.exists()) { - file.delete(); - } - } - - private boolean compareRoles(String expectedRoles, String actualRoles) { - Set expectedRolesSet = new HashSet(); - for(String role : expectedRoles.split(",")) { - expectedRolesSet.add(role); - } - - Set actualRolesSet = new HashSet(); - for(String role : actualRoles.split(",")) { - actualRolesSet.add(role); - } - - return expectedRolesSet.equals(actualRolesSet); - } - -} diff --git a/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/storage/DigestUtilTests.java b/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/storage/DigestUtilTests.java deleted file mode 100755 index d1a040b30..000000000 --- a/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/storage/DigestUtilTests.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial API and implementation - *******************************************************************************/ - -package org.eclipse.equinox.console.storage; - -import static org.junit.Assert.*; -import java.security.MessageDigest; - -import org.junit.Test; - - -public class DigestUtilTests { - - private static final char[] HEX_CHARS = "0123456789abcdef".toCharArray(); - private static final String MD5 = "MD5"; - private static final String SHA1 = "SHA1"; - private static final String TEXT = "sometext"; - - @Test - public void testEncrypt() throws Exception { - MessageDigest md = MessageDigest.getInstance(MD5); - md.update(TEXT.getBytes()); - byte[] digest = md.digest(); - - char[] chars = new char[2 * digest.length]; - for (int i = 0; i < digest.length; ++i) - { - chars[2 * i] = HEX_CHARS[(digest[i] & 0xF0) >>> 4]; - chars[2 * i + 1] = HEX_CHARS[digest[i] & 0x0F]; - } - - String modifiedText = TEXT + new String(chars); - md = MessageDigest.getInstance(SHA1); - md.update(modifiedText.getBytes()); - digest = md.digest(); - - chars = new char[2 * digest.length]; - for (int i = 0; i < digest.length; ++i) - { - chars[2 * i] = HEX_CHARS[(digest[i] & 0xF0) >>> 4]; - chars[2 * i + 1] = HEX_CHARS[digest[i] & 0x0F]; - } - - String expectedEncryptedText = new String(chars); - - assertEquals("Encrypted text not as expected", expectedEncryptedText, DigestUtil.encrypt(TEXT)); - } -} diff --git a/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/storage/SecureUserStoreTests.java b/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/storage/SecureUserStoreTests.java deleted file mode 100755 index 20062e17b..000000000 --- a/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/storage/SecureUserStoreTests.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial API and implementation - *******************************************************************************/ - -package org.eclipse.equinox.console.storage; - -import static org.junit.Assert.*; - -import java.io.File; -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.equinox.console.jaas.SecureStorageLoginModule; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class SecureUserStoreTests { - - private static final String USER_STORE_FILE_NAME_PROPERTY = "org.eclipse.equinox.console.jaas.file"; - private static final String USER_STORE_FILE_NAME = SecureUserStoreTests.class.getName() + "_store"; - private static final String USERNAME1 = "username1"; - private static final String USERNAME2 = "username2"; - private static final String PASSWORD1 = "password1"; - private static final String PASSWORD2 = "password2"; - private static final String ROLES1 = "role1,role2"; - private static final String ROLES2 = "role3,role4"; - private static final String ROLES_TO_REMOVE = "role2"; - private static final String REMAINING_ROLES = "role1"; - - @Test - public void testStore() throws Exception { - cleanUp(); - - System.setProperty(USER_STORE_FILE_NAME_PROPERTY, USER_STORE_FILE_NAME); - - SecureUserStore.initStorage(); - assertTrue("Secure store file does not exist", new File(USER_STORE_FILE_NAME).exists()); - - SecureUserStore.putUser(USERNAME1, PASSWORD1, null); - SecureUserStore.putUser(USERNAME2, PASSWORD2, ROLES2); - - String[] usernames = SecureUserStore.getUserNames(); - boolean arePresent = (usernames[0].equals(USERNAME1) || usernames[0].equals(USERNAME2)) && (usernames[1].equals(USERNAME1) || usernames[1].equals(USERNAME2)) && (!usernames[0].equals(usernames[1])); - assertTrue("Usernames not correctly saved", arePresent); - - String pass1 = SecureUserStore.getPassword(USERNAME1); - String pass2 = SecureUserStore.getPassword(USERNAME2); - assertTrue("Passwords not correctly saved", pass1.equals(PASSWORD1) && pass2.equals(PASSWORD2)); - - boolean existsUser1 = SecureUserStore.existsUser(USERNAME1); - boolean existsUser2 = SecureUserStore.existsUser(USERNAME2); - assertTrue("Users should exist", existsUser1 && existsUser2); - - String roles = SecureUserStore.getRoles(USERNAME2); - assertEquals("Roles for the second user are not as expected", ROLES2, roles); - - SecureUserStore.addRoles(USERNAME1, ROLES1); - roles = SecureUserStore.getRoles(USERNAME1); - boolean areRolesEqual = compareRoles(ROLES1, roles); - assertTrue("Roles for the first user are not as expected", areRolesEqual); - - SecureUserStore.removeRoles(USERNAME1, ROLES_TO_REMOVE); - roles = SecureUserStore.getRoles(USERNAME1); - areRolesEqual = compareRoles(REMAINING_ROLES, roles); - assertTrue("Roles for the first user are not as expected", areRolesEqual); - - SecureUserStore.resetPassword(USERNAME1); - String pass = SecureUserStore.getPassword(USERNAME1); - assertNull("Password should be null", pass); - - SecureUserStore.setPassword(USERNAME1, PASSWORD1); - pass = SecureUserStore.getPassword(USERNAME1); - assertEquals("Password should be null", PASSWORD1, pass); - - SecureUserStore.deleteUser(USERNAME2); - assertFalse("User2 should not exist", SecureUserStore.existsUser(USERNAME2)); - } - - @After - public void cleanUp() { - System.setProperty(USER_STORE_FILE_NAME_PROPERTY, ""); - File file = new File(USER_STORE_FILE_NAME); - if(file.exists()) { - file.delete(); - } - } - - private boolean compareRoles(String expectedRoles, String actualRoles) { - Set expectedRolesSet = new HashSet(); - for(String role : expectedRoles.split(",")) { - expectedRolesSet.add(role); - } - - Set actualRolesSet = new HashSet(); - for(String role : actualRoles.split(",")) { - actualRolesSet.add(role); - } - - return expectedRolesSet.equals(actualRolesSet); - } -} diff --git a/bundles/org.eclipse.equinox.console.tests/.classpath b/bundles/org.eclipse.equinox.console.tests/.classpath deleted file mode 100755 index a7d4b6245..000000000 --- a/bundles/org.eclipse.equinox.console.tests/.classpath +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/bundles/org.eclipse.equinox.console.tests/.gitignore b/bundles/org.eclipse.equinox.console.tests/.gitignore deleted file mode 100755 index 3b8360084..000000000 --- a/bundles/org.eclipse.equinox.console.tests/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/hostkey.ser diff --git a/bundles/org.eclipse.equinox.console.tests/.project b/bundles/org.eclipse.equinox.console.tests/.project deleted file mode 100755 index 7d67a8eb6..000000000 --- a/bundles/org.eclipse.equinox.console.tests/.project +++ /dev/null @@ -1,28 +0,0 @@ - - - org.eclipse.equinox.console.tests - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - diff --git a/bundles/org.eclipse.equinox.console.tests/.settings/org.eclipse.core.runtime.prefs b/bundles/org.eclipse.equinox.console.tests/.settings/org.eclipse.core.runtime.prefs deleted file mode 100644 index 5a0ad22d2..000000000 --- a/bundles/org.eclipse.equinox.console.tests/.settings/org.eclipse.core.runtime.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -line.separator=\n diff --git a/bundles/org.eclipse.equinox.console.tests/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.equinox.console.tests/.settings/org.eclipse.jdt.core.prefs deleted file mode 100755 index af0f20f97..000000000 --- a/bundles/org.eclipse.equinox.console.tests/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,7 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.5 diff --git a/bundles/org.eclipse.equinox.console.tests/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.console.tests/META-INF/MANIFEST.MF deleted file mode 100755 index aa559b375..000000000 --- a/bundles/org.eclipse.equinox.console.tests/META-INF/MANIFEST.MF +++ /dev/null @@ -1,12 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: Console tests -Bundle-SymbolicName: org.eclipse.equinox.console.tests -Bundle-Version: 1.0.0.qualifier -Bundle-ActivationPolicy: lazy -Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Import-Package: junit.framework;version="4.8.1", - org.apache.sshd.client.future, - org.easymock;version="2.4.0", - org.junit;version="4.8.1" -Fragment-Host: org.eclipse.equinox.console diff --git a/bundles/org.eclipse.equinox.console.tests/about.html b/bundles/org.eclipse.equinox.console.tests/about.html deleted file mode 100755 index bed8451cf..000000000 --- a/bundles/org.eclipse.equinox.console.tests/about.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - -About - - -

About This Content

- -

May 28, 2011

-

License

- -

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise -indicated below, the Content is provided to you under the terms and conditions of the -Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available -at http://www.eclipse.org/legal/epl-v10.html. -For purposes of the EPL, "Program" will mean the Content.

- -

If you did not receive this Content directly from the Eclipse Foundation, the Content is -being redistributed by another party ("Redistributor") and different terms and conditions may -apply to your use of any object code in the Content. Check the Redistributor's license that was -provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise -indicated below, the terms and conditions of the EPL still apply to any source code in the Content -and such source code may be obtained at http://www.eclipse.org.

- - - \ No newline at end of file diff --git a/bundles/org.eclipse.equinox.console.tests/build.properties b/bundles/org.eclipse.equinox.console.tests/build.properties deleted file mode 100755 index 34d2e4d2d..000000000 --- a/bundles/org.eclipse.equinox.console.tests/build.properties +++ /dev/null @@ -1,4 +0,0 @@ -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - . diff --git a/bundles/org.eclipse.equinox.console.tests/forceQualifierUpdate.txt b/bundles/org.eclipse.equinox.console.tests/forceQualifierUpdate.txt deleted file mode 100644 index 56f1032a8..000000000 --- a/bundles/org.eclipse.equinox.console.tests/forceQualifierUpdate.txt +++ /dev/null @@ -1,2 +0,0 @@ -# To force a version qualifier update add the bug here -Bug 403352 - Update all parent versions to match our build stream diff --git a/bundles/org.eclipse.equinox.console.tests/pom.xml b/bundles/org.eclipse.equinox.console.tests/pom.xml deleted file mode 100644 index 1ed67a724..000000000 --- a/bundles/org.eclipse.equinox.console.tests/pom.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - 4.0.0 - - tests-pom - org.eclipse.equinox.bundles - 4.6.0-SNAPSHOT - ../../tests-pom/ - - org.eclipse.equinox - org.eclipse.equinox.console.tests - 1.0.0-SNAPSHOT - eclipse-test-plugin - diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/Activator.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/Activator.java deleted file mode 100755 index e024b14fa..000000000 --- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/Activator.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial API and implementation - *******************************************************************************/ - -package org.eclipse.equinox.console; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; - -/** - * The activator class controls the plug-in life cycle - */ -public class Activator implements BundleActivator { - private static BundleContext context; - - public void start(BundleContext context) throws Exception { - this.context = context; - } - - - public void stop(BundleContext context) throws Exception { - this.context = null; - } - - public static BundleContext getContext() { - return context; - } -} diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/command/adapter/ActivatorTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/command/adapter/ActivatorTests.java deleted file mode 100755 index 677fc4099..000000000 --- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/command/adapter/ActivatorTests.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial API and implementation - *******************************************************************************/ - -package org.eclipse.equinox.console.command.adapter; - -import static org.junit.Assert.*; - -import java.lang.reflect.Method; -import java.util.Dictionary; -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.osgi.framework.console.CommandInterpreter; -import org.eclipse.osgi.framework.console.CommandProvider; -import org.junit.Test; - -public class ActivatorTests { - - private static final String SCOPE_PROPERTY_NAME = "osgi.command.scope"; - private static final String FUNCTION_PROPERTY_NAME = "osgi.command.function"; - private static final String EQUINOX_SCOPE = "equinox"; - - @Test - public void testGetCommandMethods() { - Set commandNames = new HashSet(); - commandNames.add("_testMethod1"); - commandNames.add("_testMethod2"); - commandNames.add("_testMethod3"); - - Activator activator = new Activator(); - CommandProvider command = new TestCommandProvider(); - Method[] methods = activator.getCommandMethods(command); - - assertEquals("Command methods not as expected", 3, methods.length); - for (Method method : methods) { - assertTrue("Command methods should not include " + method.getName(), commandNames.contains(method.getName())); - } - - Dictionary props = activator.getAttributes(methods); - assertTrue("Attributes should contain property " + SCOPE_PROPERTY_NAME + " with value " + EQUINOX_SCOPE, EQUINOX_SCOPE.equals(props.get(SCOPE_PROPERTY_NAME))); - String[] methodNames = (String[])props.get(FUNCTION_PROPERTY_NAME); - assertEquals("Methods number not as expected", methods.length, methodNames.length); - - for(int i = 0; i < methods.length; i++) { - assertEquals("Wrong method name", methods[i].getName().substring(1), methodNames[i]); - } - } - - class TestCommandProvider implements CommandProvider { - public void _testMethod1(CommandInterpreter i) { - - } - - public void _testMethod2(CommandInterpreter i) { - - } - - public void _testMethod3(CommandInterpreter i) { - - } - - private void _method(CommandInterpreter i) { - - } - - public String getHelp() { - // TODO Auto-generated method stub - return null; - } - - } - -} diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/command/adapter/CommandProviderAdapterTest.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/command/adapter/CommandProviderAdapterTest.java deleted file mode 100755 index 91ce5f5d2..000000000 --- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/command/adapter/CommandProviderAdapterTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial API and implementation - *******************************************************************************/ - -package org.eclipse.equinox.console.command.adapter; - -import static org.junit.Assert.*; - -import java.lang.reflect.Method; -import java.util.HashSet; -import java.util.Set; - -import org.apache.felix.service.command.CommandSession; -import org.eclipse.osgi.framework.console.CommandInterpreter; -import org.eclipse.osgi.framework.console.CommandProvider; -import org.junit.Test; -import org.easymock.EasyMock; - -public class CommandProviderAdapterTest { - - @Test - public void testMain() throws Exception { - CommandProvider provider = new TestCommandProvider(); - Method[] methods = TestCommandProvider.class.getMethods(); - Set m = new HashSet(); - for (Method method : methods) { - if (method.getName().startsWith("_")) { - m.add(method); - } - } - CommandProviderAdapter providerAdapter = new CommandProviderAdapter(provider, m.toArray(new Method[0])); - CommandSession session = EasyMock.createMock(CommandSession.class); - - String result = (String) providerAdapter.main(session, new Object[] {"test"}); - assertEquals("Result should be test", "test", result); - - result = (String) providerAdapter.main(session, new Object[] {"echo", "hello"}); - assertEquals("Result should be hello", "hello", result); - } - - class TestCommandProvider implements CommandProvider { - public String _test(CommandInterpreter i) { - return "test"; - } - - public String _echo(CommandInterpreter i) { - return i.nextArgument(); - } - - public String getHelp() { - return "this is a test command provider"; - } - - } -} diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/ConsoleInputStreamTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/ConsoleInputStreamTests.java deleted file mode 100755 index b3732bbfc..000000000 --- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/ConsoleInputStreamTests.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial contribution - ******************************************************************************/ - -package org.eclipse.equinox.console.common; - -import org.junit.Assert; -import org.junit.Test; - -import org.eclipse.equinox.console.common.ConsoleInputStream; - -public class ConsoleInputStreamTests { - - private static final int DATA_LENGTH = 4; - - @Test - public void addReadBufferTest() throws Exception { - ConsoleInputStream in = new ConsoleInputStream(); - byte[] data = new byte[] { (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd' }; - in.add(data); - byte[] read = new byte[DATA_LENGTH]; - for (int i = 0; i < DATA_LENGTH; i++) { - in.read(read, i, 1); - Assert.assertEquals("Incorrect char read; position " + i + " expected: " + data[i] + ", actual: " + read[i], read[i], data[i]); - } - } - - @Test - public void addReadTest() throws Exception { - ConsoleInputStream in = new ConsoleInputStream(); - byte[] data = new byte[] { (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd' }; - in.add(data); - for (int i = 0; i < DATA_LENGTH; i++) { - byte symbol = (byte) in.read(); - Assert.assertEquals("Incorrect char read; position " + i + " expected: " + data[i] + ", actual: " + symbol, symbol, data[i]); - } - } -} diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/ConsoleOutputStreamTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/ConsoleOutputStreamTests.java deleted file mode 100755 index c1044ee8b..000000000 --- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/ConsoleOutputStreamTests.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial contribution - ******************************************************************************/ - -package org.eclipse.equinox.console.common; - -import org.junit.Assert; -import org.junit.Test; - -import java.io.ByteArrayOutputStream; - -public class ConsoleOutputStreamTests { - - private static final int DATA_LENGTH = 4; - - @Test - public void testWrite() throws Exception { - ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - ConsoleOutputStream out = new ConsoleOutputStream(byteOut); - byte[] data = new byte[] { 'a', 'b', 'c', 'd' }; - for (byte b : data) { - out.write(b); - } - out.flush(); - byte[] res = byteOut.toByteArray(); - - Assert.assertNotNull("Bytes not written; result null", res); - Assert.assertFalse("Bytes not written; result empty", res.length == 0); - - for (int i = 0; i < DATA_LENGTH; i++) { - Assert.assertEquals("Wrong char read. Position " + i + ", expected " + data[i] + ", read " + res[i], data[i], res[i]); - } - } -} diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/HistoryHolderTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/HistoryHolderTests.java deleted file mode 100755 index 5ee9bba4d..000000000 --- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/HistoryHolderTests.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial contribution - ******************************************************************************/ - -package org.eclipse.equinox.console.common; - -import org.junit.Assert; -import org.junit.Test; - - -public class HistoryHolderTests { - - @Test - public void test() { - HistoryHolder historyHolder = new HistoryHolder(); - byte[] line1 = new byte[] { 'a', 'b', 'c', 'd' }; - byte[] line2 = new byte[] { 'x', 'y', 'z' }; - byte[] line3 = new byte[] { 'k', 'l', 'm', 'n' }; - - historyHolder.add(line1); - historyHolder.add(line2); - historyHolder.add(line3); - - byte[] first = historyHolder.first(); - Assert.assertEquals("Wrong length of first member", line1.length, first.length); - Assert.assertArrayEquals("Wrong first member", line1, first); - - byte[] last = historyHolder.last(); - Assert.assertEquals("Wrong length of last member", line3.length, last.length); - Assert.assertArrayEquals("Wrong last member", line3, last); - - byte[] prev = historyHolder.prev(); - Assert.assertEquals("Wrong length of previous member", line2.length, prev.length); - Assert.assertArrayEquals("Wrong previous member", line2, prev); - - byte[] next = historyHolder.next(); - Assert.assertEquals("Wrong length of next member", line3.length, next.length); - Assert.assertArrayEquals("Wrong next member", line3, next); - - historyHolder.first(); - historyHolder.add(new byte[] {}); - byte[] current = historyHolder.prev(); - Assert.assertEquals("Wrong length of next member", line3.length, current.length); - Assert.assertArrayEquals("Wrong next member", line3, current); - - historyHolder.first(); - historyHolder.add(line1); - current = historyHolder.prev(); - Assert.assertEquals("Wrong length of next member", line1.length, current.length); - Assert.assertArrayEquals("Wrong next member", line1, current); - Assert.assertArrayEquals("Second line should now be first", line2, historyHolder.first()); - - historyHolder.reset(); - Assert.assertNull("History should be empty", historyHolder.first()); - Assert.assertNull("History should be empty", historyHolder.last()); - Assert.assertNull("History should be empty", historyHolder.next()); - Assert.assertNull("History should be empty", historyHolder.prev()); - } - -} diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/SimpleByteBufferTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/SimpleByteBufferTests.java deleted file mode 100755 index 9d4362431..000000000 --- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/common/SimpleByteBufferTests.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial contribution - ******************************************************************************/ - -package org.eclipse.equinox.console.common; - -import org.junit.Assert; -import org.junit.Test; - -public class SimpleByteBufferTests { - - @Test - public void testBuffer() throws Exception { - SimpleByteBuffer buffer = new SimpleByteBuffer(); - buffer.add('a'); - buffer.add('b'); - buffer.add('c'); - buffer.add('d'); - - Assert.assertTrue("Wrong buffer size; expected 4, actual " + buffer.getSize(), buffer.getSize() == 4); - - check(buffer, new byte[] { 'a', 'b', 'c', 'd' }); - - byte[] data = buffer.getCurrentData(); - byte[] expected = new byte[] { 'a', 'b', 'c', 'd' }; - - Assert.assertTrue("Data not as expected: expected length " + expected.length + ", actual length " + data.length, - data.length == expected.length); - - for (int i = 0; i < data.length; i++) { - Assert.assertEquals("Incorrect data read. Position " + i + ", expected " + expected[i] + ", read " + data[i], expected[i], data[i]); - } - - buffer.insert('a'); - buffer.insert('b'); - buffer.insert('c'); - buffer.insert('d'); - - int pos = buffer.getPos(); - buffer.goLeft(); - int newPos = buffer.getPos(); - Assert.assertEquals("Error while moving left; old pos: " + pos + ", new pos: ", pos - 1, newPos); - - buffer.insert('e'); - check(buffer, new byte[] { 'a', 'b', 'c', 'e', 'd' }); - - buffer.goLeft(); - buffer.delete(); - check(buffer, new byte[] { 'a', 'b', 'c', 'd' }); - - pos = buffer.getPos(); - buffer.goRight(); - newPos = buffer.getPos(); - Assert.assertEquals("Error while moving right; old pos: " + pos + ", new pos: ", pos + 1, newPos); - - buffer.backSpace(); - check(buffer, new byte[] { 'a', 'b', 'c' }); - - buffer.delAll(); - Assert.assertTrue("Bytes in buffer not correctly deleted", (buffer.getSize() == 0) && (buffer.getPos() == 0)); - - buffer.set(new byte[] { 'a', 'b', 'c', 'd' }); - check(buffer, new byte[] { 'a', 'b', 'c', 'd' }); - - data = buffer.copyCurrentData(); - Assert.assertArrayEquals("Buffer copy does not work properly", new byte[] { 'a', 'b', 'c', 'd' }, data); - - buffer.goLeft(); - buffer.replace('e'); - check(buffer, new byte[] { 'a', 'b', 'c', 'e' }); - - buffer.resetPos(); - Assert.assertTrue("Resetting position does not work properly", buffer.getPos() == 0); - - Assert.assertEquals("Wrong current char", 'a', buffer.getCurrentChar()); - } - - private void check(SimpleByteBuffer buffer, byte[] expected) throws Exception { - byte[] data = buffer.copyCurrentData(); - - Assert.assertTrue("Data not as expected: expected length " + expected.length + ", actual length " + data.length, - data.length == expected.length); - - for (int i = 0; i < data.length; i++) { - Assert.assertEquals("Incorrect data read. Position " + i + ", expected " + expected[i] + ", read " + data[i], expected[i], data[i]); - } - } - -} diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CommandLineParserTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CommandLineParserTests.java deleted file mode 100755 index 408c8a8f1..000000000 --- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CommandLineParserTests.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial API and implementation - *******************************************************************************/ - -package org.eclipse.equinox.console.completion; - -import static org.junit.Assert.*; - -import org.junit.Test; - -public class CommandLineParserTests { - - private static final String PIPE_TEST_INPUT = "command1|comm"; - private static final String CONSECUTIVE_COMMANDS_TEST_INPUT = "command1;comm"; - private static final String ASSIGNMENT_TEST_INPUT = "var=val"; - private static final String START_CLOSURE_TEST_INPUT = "${comm"; - private static final String END_CLOSURE_TEST_INPUT = "${command}arg1"; - private static final String START_MACRO_TEST_INPUT = "$(macr"; - private static final String END_MACRO_TEST_INPUT = "$(macro)val"; - private static final String VARIABLE_TEST_INPUT = "$VAR"; - private static final String START_MAP_TEST_INPUT = " commands = new HashSet(); - commands.add("equinox:bundles"); - commands.add("equinox:diag"); - commands.add("equinox:setprop"); - commands.add("gogo:lb"); - commands.add("gogo:echo"); - commands.add("gogo:set"); - - CommandSession session = createMock(CommandSession.class); - expect(session.get(COMMANDS)).andReturn(commands).times(4); - replay(session); - - Filter filter = createMock(Filter.class); - replay(filter); - - BundleContext context = createMock(BundleContext.class); -// expect(context.createFilter(String.format("(&(%s=*)(%s=*))", CommandProcessor.COMMAND_SCOPE, CommandProcessor.COMMAND_FUNCTION))).andReturn(filter); - expect(context.createFilter("(objectClass=org.eclipse.equinox.console.commands.CommandsTracker)")).andReturn(filter); - context.addServiceListener(isA(ServiceListener.class), isA(String.class)); - expect(context.getServiceReferences("org.eclipse.equinox.console.commands.CommandsTracker", null)).andReturn(new ServiceReference[]{}); - replay(context); - - CommandNamesCompleter completer = new CommandNamesCompleter(context, session); - Map candidates; - - candidates = completer.getCandidates("se", 2); - assertNotNull("Candidates null", candidates); - assertEquals("Candidates not as expected", 2, candidates.size()); - assertNotNull("set should be in the resultset, but it is not", candidates.get("set")); - assertNotNull("setprop should be in the resultset, but it is not", candidates.get("setprop")); - - candidates = completer.getCandidates("equinox:bun", "equinox:bun".length()); - assertNotNull("Candidates null", candidates); - assertEquals("Candidates not as expected", 1, candidates.size()); - assertNotNull("equinox:bundles should be in the resultset, but it is not", candidates.get("equinox:bundles")); - - candidates = completer.getCandidates("ec", 2); - assertNotNull("Candidates null", candidates); - assertEquals("Candidates not as expected", 1, candidates.size()); - assertNotNull("echo should be in the resultset, but it is not", candidates.get("echo")); - - candidates = completer.getCandidates("head", 4); - assertNotNull("Candidates null", candidates); - assertEquals("Candidates not as expected", 0, candidates.size()); - - verify(session); - } - -} diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CompletionHandlerTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CompletionHandlerTests.java deleted file mode 100755 index 07663db15..000000000 --- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CompletionHandlerTests.java +++ /dev/null @@ -1,175 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial API and implementation - *******************************************************************************/ - -package org.eclipse.equinox.console.completion; - -import static org.junit.Assert.*; -import static org.easymock.EasyMock.*; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.apache.felix.service.command.CommandSession; -import org.eclipse.equinox.console.completion.common.Completer; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.osgi.framework.BundleContext; -import org.osgi.framework.Filter; -import org.osgi.framework.ServiceListener; -import org.osgi.framework.ServiceReference; - -public class CompletionHandlerTests { - - private static final String COMMANDS = ".commands"; - private static final String WORK_DIR_NAME = "work"; - private static final String TESTFILE = "testfile"; - private static final String TESTOUTPUT = "testoutput"; - private static final String FILE = "file"; - - @Before - public void init() throws IOException { - File currentDir = new File("."); - File[] files = currentDir.listFiles(); - for (File file : files) { - if(file.getName().equals(WORK_DIR_NAME)) { - clean(); - break; - } - } - - File workDir = new File(currentDir.getAbsolutePath() + File.separator + WORK_DIR_NAME); - workDir.mkdir(); - - createFile(workDir, TESTFILE); - createFile(workDir, TESTOUTPUT); - createFile(workDir, FILE); - } - - @Test - public void testGetCandidates() throws Exception { - Filter filter = createMock(Filter.class); - replay(filter); - - BundleContext context = createMock(BundleContext.class); - expect(context.getServiceReferences(Completer.class.getName(), null)).andReturn(null).anyTimes(); - expect(context.createFilter("(objectClass=org.eclipse.equinox.console.commands.CommandsTracker)")).andReturn(filter).anyTimes(); - context.addServiceListener(isA(ServiceListener.class), isA(String.class)); - expectLastCall().anyTimes(); - expect(context.getServiceReferences("org.eclipse.equinox.console.commands.CommandsTracker", null)).andReturn(new ServiceReference[]{}).anyTimes(); - replay(context); - - Set variables = new HashSet(); - variables.add("SCOPE"); - variables.add("PROMPT"); - variables.add("ECHO_ON"); - variables.add("ECHO"); - - Set commands = new HashSet(); - commands.add("equinox:bundles"); - commands.add("equinox:diag"); - commands.add("equinox:setprop"); - commands.add("gogo:lb"); - commands.add("gogo:echo"); - commands.add("gogo:set"); - - CommandSession session = createMock(CommandSession.class); - expect(session.get(null)).andReturn(variables).anyTimes(); - expect(session.get(COMMANDS)).andReturn(commands).anyTimes(); - replay(session); - - CompletionHandler completer = new CompletionHandler(context, session); - Map candidates; - - candidates = completer.getCandidates("$SC".getBytes(), 2); - assertNotNull("Candidates null", candidates); - assertEquals("Candidates not as expected", 1, candidates.size()); - assertNotNull("SCOPE should be in the resultset, but it is not", candidates.get("SCOPE")); - - candidates = completer.getCandidates("$EC".getBytes(), 2); - assertNotNull("Candidates null", candidates); - assertEquals("Candidates not as expected", 2, candidates.size()); - assertNotNull("ECHO_ON should be in the resultset, but it is not", candidates.get("ECHO_ON")); - assertNotNull("ECHO should be in the resultset, but it is not", candidates.get("ECHO")); - - candidates = completer.getCandidates("$AB".getBytes(), 2); - assertNotNull("Candidates null", candidates); - assertEquals("Candidates not as expected", 0, candidates.size()); - - completer = new CompletionHandler(context, session); - candidates = completer.getCandidates("se".getBytes(), 2); - assertNotNull("Candidates null", candidates); - assertEquals("Candidates not as expected", 2, candidates.size()); - assertNotNull("set should be in the resultset, but it is not", candidates.get("set")); - assertNotNull("setprop should be in the resultset, but it is not", candidates.get("setprop")); - - candidates = completer.getCandidates("equinox:bun".getBytes(), "equinox:bun".length()); - assertNotNull("Candidates null", candidates); - assertEquals("Candidates not as expected", 1, candidates.size()); - assertNotNull("equinox:bundles should be in the resultset, but it is not", candidates.get("equinox:bundles")); - - candidates = completer.getCandidates("ec".getBytes(), 2); - assertNotNull("Candidates null", candidates); - assertEquals("Candidates not as expected", 1, candidates.size()); - assertNotNull("echo should be in the resultset, but it is not", candidates.get("echo")); - - candidates = completer.getCandidates("head".getBytes(), "head".length()); - assertNotNull("Candidates null", candidates); - assertEquals("Candidates not as expected", 0, candidates.size()); - - completer = new CompletionHandler(context, session); - candidates = completer.getCandidates("wor".getBytes(), "wor".length()); - assertNotNull("Candidates null", candidates); - assertEquals("Candidates not as expected", 1, candidates.size()); - assertNotNull("work should be in the resultset, but it is not", candidates.get(WORK_DIR_NAME)); - - candidates = completer.getCandidates("work/test".getBytes(), "work/test".length()); - assertNotNull("Candidates null", candidates); - assertEquals("Candidates not as expected", 2, candidates.size()); - assertNotNull("testfile should be in the resultset, but it is not", candidates.get(TESTFILE)); - assertNotNull("testoutput should be in the resultset, but it is not", candidates.get(TESTOUTPUT)); - - candidates = completer.getCandidates("work/".getBytes(), "work/".length()); - assertEquals("Candidates not as expected", 3, candidates.size()); - assertNotNull("testfile should be in the resultset, but it is not", candidates.get(TESTFILE)); - assertNotNull("testoutput should be in the resultset, but it is not", candidates.get(TESTOUTPUT)); - assertNotNull("file should be in the resultset, but it is not", candidates.get(FILE)); - } - - @After - public void cleanUp() { - clean(); - } - - private void clean() { - File currentFile = new File("."); - File workDir = new File(currentFile.getAbsolutePath() + File.separator + WORK_DIR_NAME); - File[] files = workDir.listFiles(); - for (File file : files) { - file.delete(); - } - workDir.delete(); - } - - private void createFile(File parentDir, String filename) throws IOException { - File file = new File(parentDir.getAbsolutePath() + File.separator + filename); - PrintWriter out = new PrintWriter(new FileOutputStream(file)); - out.write(filename); - out.flush(); - out.close(); - } - -} diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/FileNamesCompleterTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/FileNamesCompleterTests.java deleted file mode 100755 index 91540a13f..000000000 --- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/FileNamesCompleterTests.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial API and implementation - *******************************************************************************/ - -package org.eclipse.equinox.console.completion; - -import static org.junit.Assert.*; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Map; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class FileNamesCompleterTests { - private static final String WORK_DIR_NAME = "work"; - private static final String TESTFILE = "testfile"; - private static final String TESTOUTPUT = "testoutput"; - private static final String FILE = "file"; - - @Before - public void init() throws IOException { - File currentDir = new File("."); - File[] files = currentDir.listFiles(); - for (File file : files) { - if(file.getName().equals(WORK_DIR_NAME)) { - clean(); - break; - } - } - - File workDir = new File(currentDir.getAbsolutePath() + File.separator + WORK_DIR_NAME); - workDir.mkdir(); - - createFile(workDir, TESTFILE); - createFile(workDir, TESTOUTPUT); - createFile(workDir, FILE); - } - - @Test - public void testGetCandidates() { - FileNamesCompleter completer = new FileNamesCompleter(); - - Map candidates; - - candidates = completer.getCandidates("wor", "wor".length()); - assertNotNull("Candidates null", candidates); - assertEquals("Candidates not as expected", 1, candidates.size()); - assertNotNull("work should be in the resultset, but it is not", candidates.get(WORK_DIR_NAME)); - - candidates = completer.getCandidates("work/test", "work/test".length()); - assertNotNull("Candidates null", candidates); - assertEquals("Candidates not as expected", 2, candidates.size()); - assertNotNull("testfile should be in the resultset, but it is not", candidates.get(TESTFILE)); - assertNotNull("testoutput should be in the resultset, but it is not", candidates.get(TESTOUTPUT)); - - candidates = completer.getCandidates(WORK_DIR_NAME + "/", 5); - assertEquals("Candidates not as expected", 3, candidates.size()); - assertNotNull("testfile should be in the resultset, but it is not", candidates.get(TESTFILE)); - assertNotNull("testoutput should be in the resultset, but it is not", candidates.get(TESTOUTPUT)); - assertNotNull("file should be in the resultset, but it is not", candidates.get(FILE)); - } - - @After - public void cleanUp() { - clean(); - } - - private void clean() { - File currentFile = new File("."); - File workDir = new File(currentFile.getAbsolutePath() + File.separator + WORK_DIR_NAME); - File[] files = workDir.listFiles(); - for (File file : files) { - file.delete(); - } - workDir.delete(); - } - - private void createFile(File parentDir, String filename) throws IOException { - File file = new File(parentDir.getAbsolutePath() + File.separator + filename); - PrintWriter out = new PrintWriter(new FileOutputStream(file)); - out.write(filename); - out.flush(); - out.close(); - } -} diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/StringsCompleterTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/StringsCompleterTests.java deleted file mode 100755 index 05096ba5b..000000000 --- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/StringsCompleterTests.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial API and implementation - *******************************************************************************/ - -package org.eclipse.equinox.console.completion; - -import static org.junit.Assert.*; - -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.junit.Test; - -public class StringsCompleterTests { - - @Test - public void testGetCandidates() { - Set strings = new HashSet(); - strings.add("command"); - strings.add("SCOPE"); - strings.add("equinox:bundles"); - strings.add("common"); - - StringsCompleter completer = new StringsCompleter(strings, false); - Map candidates; - - candidates = completer.getCandidates("sco", 3); - assertNotNull("Candidates null", candidates); - assertEquals("Candidates not as expected", 1, candidates.size()); - assertNotNull("SCOPE should be in the resultset, but it is not", candidates.get("SCOPE")); - - candidates = completer.getCandidates("com", 3); - assertNotNull("Candidates null", candidates); - assertEquals("Candidates not as expected", 2, candidates.size()); - assertNotNull("command should be in the resultset, but it is not", candidates.get("command")); - assertNotNull("common should be in the resultset, but it is not", candidates.get("common")); - - candidates = completer.getCandidates("tr", 2); - assertNotNull("Candidates null", candidates); - assertEquals("Candidates not as expected", 0, candidates.size()); - - completer = new StringsCompleter(strings, true); - - candidates = completer.getCandidates("sco", 3); - assertNotNull("Candidates null", candidates); - assertEquals("Candidates not as expected", 0, candidates.size()); - - candidates = completer.getCandidates("SCO", 3); - assertNotNull("Candidates null", candidates); - assertEquals("Candidates not as expected", 1, candidates.size()); - assertNotNull("SCOPE should be in the resultset, but it is not", candidates.get("SCOPE")); - } - -} diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/VariableNamesCompleterTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/VariableNamesCompleterTests.java deleted file mode 100755 index 2b6ca5290..000000000 --- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/VariableNamesCompleterTests.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial API and implementation - *******************************************************************************/ - -package org.eclipse.equinox.console.completion; - -import static org.easymock.EasyMock.*; -import static org.junit.Assert.*; - -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.apache.felix.service.command.CommandSession; -import org.junit.Test; - -public class VariableNamesCompleterTests { - - @Test - public void testGetCandidates() { - Set variables = new HashSet(); - variables.add("SCOPE"); - variables.add("PROMPT"); - variables.add("ECHO_ON"); - variables.add("ECHO"); - - CommandSession session = createMock(CommandSession.class); - expect(session.get(null)).andReturn(variables).times(3); - replay(session); - - VariableNamesCompleter completer = new VariableNamesCompleter(session); - Map candidates; - - candidates = completer.getCandidates("SC", 2); - assertNotNull("Candidates null", candidates); - assertEquals("Candidates not as expected", 1, candidates.size()); - assertNotNull("SCOPE should be in the resultset, but it is not", candidates.get("SCOPE")); - - candidates = completer.getCandidates("EC", 2); - assertNotNull("Candidates null", candidates); - assertEquals("Candidates not as expected", 2, candidates.size()); - assertNotNull("ECHO_ON should be in the resultset, but it is not", candidates.get("ECHO_ON")); - assertNotNull("ECHO should be in the resultset, but it is not", candidates.get("ECHO")); - - candidates = completer.getCandidates("AB", 2); - assertNotNull("Candidates null", candidates); - assertEquals("Candidates not as expected", 0, candidates.size()); - - verify(session); - } - -} diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/supportability/ConsoleInputHandlerTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/supportability/ConsoleInputHandlerTests.java deleted file mode 100755 index e595b627c..000000000 --- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/supportability/ConsoleInputHandlerTests.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial contribution - ******************************************************************************/ - -package org.eclipse.equinox.console.supportability; - -import org.eclipse.equinox.console.common.ConsoleInputHandler; -import org.eclipse.equinox.console.common.ConsoleInputStream; -import org.junit.Assert; -import org.junit.Test; - -import java.io.ByteArrayOutputStream; -import java.io.PipedInputStream; -import java.io.PipedOutputStream; - -public class ConsoleInputHandlerTests { - - private static final long WAIT_TIME = 10000; - - @Test - public void testHandler() throws Exception { - PipedInputStream input = new PipedInputStream(); - PipedOutputStream output = new PipedOutputStream(input); - ConsoleInputStream in = new ConsoleInputStream(); - ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - ConsoleInputHandler handler = new ConsoleInputHandler(input, in, byteOut); - byte[] testInput = new byte[] { 'a', 'b', 'c', 'd', 'e', '\r', '\n' }; - byte[] expected = new byte[] { 'a', 'b', 'c', 'd', 'e', '\n' }; - output.write(testInput); - output.flush(); - handler.start(); - - try { - Thread.sleep(WAIT_TIME); - } catch (Exception e) { - // do nothing - } - - byte[] read = new byte[expected.length]; - in.read(read, 0, expected.length); - for (int i = 0; i < expected.length; i++) { - Assert.assertEquals("Incorrect char read. Position " + i + ", expected " + expected[i] + ", read " + read[i], expected[i], read[i]); - } - - output.close(); - input.close(); - } - -} diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/supportability/ConsoleInputScannerTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/supportability/ConsoleInputScannerTests.java deleted file mode 100755 index 5c07ca1fb..000000000 --- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/supportability/ConsoleInputScannerTests.java +++ /dev/null @@ -1,268 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial contribution - ******************************************************************************/ - -package org.eclipse.equinox.console.supportability; - -import static org.easymock.EasyMock.isA; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; - -import org.apache.felix.service.command.CommandSession; -import org.eclipse.equinox.console.common.ConsoleInputScanner; -import org.eclipse.equinox.console.common.ConsoleInputStream; -import org.eclipse.equinox.console.common.ConsoleOutputStream; -import org.eclipse.equinox.console.common.KEYS; -import org.eclipse.equinox.console.common.terminal.ANSITerminalTypeMappings; -import org.eclipse.equinox.console.common.terminal.SCOTerminalTypeMappings; -import org.eclipse.equinox.console.common.terminal.TerminalTypeMappings; -import org.eclipse.equinox.console.common.terminal.VT100TerminalTypeMappings; -import org.eclipse.equinox.console.common.terminal.VT220TerminalTypeMappings; -import org.eclipse.equinox.console.common.terminal.VT320TerminalTypeMappings; -import org.eclipse.equinox.console.completion.common.Completer; -import org.junit.Assert; -import org.junit.Test; -import org.osgi.framework.BundleContext; -import org.osgi.framework.Filter; -import org.osgi.framework.ServiceListener; -import org.osgi.framework.ServiceReference; - -import java.io.ByteArrayOutputStream; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -public class ConsoleInputScannerTests { - - private static int BS; - - private static final int LF = 10; - - private static final int CR = 13; - - private static final int ESC = 27; - - private static int DELL; - - private static int TAB = 9; - - private static final String COMMANDS = ".commands"; - - @Test - public void test() throws Exception { - Set supportedEscapeSequences = new HashSet(); - supportedEscapeSequences.add(new ANSITerminalTypeMappings()); - supportedEscapeSequences.add(new VT100TerminalTypeMappings()); - supportedEscapeSequences.add(new VT220TerminalTypeMappings()); - supportedEscapeSequences.add(new VT320TerminalTypeMappings()); - supportedEscapeSequences.add(new SCOTerminalTypeMappings()); - - for (TerminalTypeMappings ttMappings : supportedEscapeSequences) { - Map escapesToKey = ttMappings.getEscapesToKey(); - Map keysToEscapes = new HashMap(); - for (Entry entry : escapesToKey.entrySet()) { - keysToEscapes.put(entry.getValue(), entry.getKey().getBytes()); - } - - BS = ttMappings.getBackspace(); - DELL = ttMappings.getDel(); - - testScan(ttMappings, keysToEscapes); - } - } - - private void testScan(TerminalTypeMappings mappings, Map keysToEscapes) throws Exception { - ConsoleInputStream in = new ConsoleInputStream(); - ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - ConsoleOutputStream out = new ConsoleOutputStream(byteOut); - ConsoleInputScanner scanner = new ConsoleInputScanner(in, out); - scanner.setBackspace(mappings.getBackspace()); - scanner.setCurrentEscapesToKey(mappings.getEscapesToKey()); - scanner.setDel(mappings.getDel()); - scanner.setEscapes(mappings.getEscapes()); - - byte[] line1 = new byte[] { 'a', 'b', 'c', 'd', 'e' }; - byte[] line2 = new byte[] { 't', 'e', 's', 't' }; - byte[] line3 = new byte[] { 'l', 'a', 's', 't' }; - - addLine(scanner, line1); - checkInpusStream(in, line1); - - addLine(scanner, line2); - checkInpusStream(in, line2); - - addLine(scanner, line3); - checkInpusStream(in, line3); - - add(scanner, keysToEscapes.get(KEYS.UP)); - add(scanner, keysToEscapes.get(KEYS.UP)); - String res = byteOut.toString(); - Assert.assertTrue("Error processing up arrow; expected test, actual " + res.substring(res.length() - 4), res.endsWith("test")); - - add(scanner, keysToEscapes.get(KEYS.DOWN)); - res = byteOut.toString(); - Assert.assertTrue("Error processing down arrow; expected last, actual " + res.substring(res.length() - 4), res.endsWith("last")); - - add(scanner, keysToEscapes.get(KEYS.PGUP)); - res = byteOut.toString(); - Assert.assertTrue("Error processing PageUp; expected abcde, actual " + res.substring(res.length() - 4), res.endsWith("abcde")); - - add(scanner, keysToEscapes.get(KEYS.PGDN)); - res = byteOut.toString(); - Assert.assertTrue("Error processing PageDown; expected last, actual " + res.substring(res.length() - 4), res.endsWith("last")); - - if (BS > 0) { - scanner.scan(BS); - res = byteOut.toString(); - Assert.assertTrue("Error processing backspace; expected las, actual " + res.substring(res.length() - 3), res.endsWith("las")); - scanner.scan('t'); - } - - if (DELL > 0) { - add(scanner, keysToEscapes.get(KEYS.LEFT)); - scanner.scan(DELL); - res = byteOut.toString(); - Assert.assertTrue("Error processing del; expected las, actual " + res.substring(res.length() - 3), res.endsWith("las")); - scanner.scan('t'); - } - - add(scanner, keysToEscapes.get(KEYS.LEFT)); - add(scanner, keysToEscapes.get(KEYS.LEFT)); - add(scanner, keysToEscapes.get(KEYS.RIGHT)); - if (DELL > 0) { - scanner.scan(DELL); - } else { - add(scanner, keysToEscapes.get(KEYS.DEL)); - } - res = byteOut.toString(); - Assert.assertTrue("Error processing arrows; expected las, actual " + res.substring(res.length() - 3), res.endsWith("las")); - scanner.scan('t'); - - if (keysToEscapes.get(KEYS.DEL) != null) { - add(scanner, keysToEscapes.get(KEYS.LEFT)); - add(scanner, keysToEscapes.get(KEYS.DEL)); - res = byteOut.toString(); - Assert.assertTrue("Error processing delete; expected las, actual " + res.substring(res.length() - 3), res.endsWith("las")); - scanner.scan('t'); - } - - add(scanner, keysToEscapes.get(KEYS.HOME)); - if (DELL > 0) { - scanner.scan(DELL); - } else { - add(scanner, keysToEscapes.get(KEYS.DEL)); - } - res = byteOut.toString(); - res = res.substring(res.length() - 6, res.length() - 3); - Assert.assertTrue("Error processing Home; expected ast, actual " + res, res.equals("ast")); - scanner.scan('l'); - - add(scanner, keysToEscapes.get(KEYS.END)); - add(scanner, keysToEscapes.get(KEYS.LEFT)); - if (DELL > 0) { - scanner.scan(DELL); - } else { - add(scanner, keysToEscapes.get(KEYS.DEL)); - } - res = byteOut.toString(); - Assert.assertTrue("Error processing End; expected las, actual " + res.substring(res.length() - 3), res.endsWith("las")); - scanner.scan('t'); - - add(scanner, keysToEscapes.get(KEYS.LEFT)); - add(scanner, keysToEscapes.get(KEYS.INS)); - scanner.scan('a'); - res = byteOut.toString(); - Assert.assertTrue("Error processing Ins; expected las, actual " + res.substring(res.length() - 4), res.endsWith("lasa")); - - Filter filter = createMock(Filter.class); - replay(filter); - - BundleContext context = createMock(BundleContext.class); - expect(context.getServiceReferences(Completer.class.getName(), null)).andReturn(null).anyTimes(); - expect(context.createFilter("(objectClass=org.eclipse.equinox.console.commands.CommandsTracker)")).andReturn(filter); - context.addServiceListener(isA(ServiceListener.class), isA(String.class)); - expect(context.getServiceReferences("org.eclipse.equinox.console.commands.CommandsTracker", null)).andReturn(new ServiceReference[]{}); - replay(context); - - Set commands = new HashSet(); - commands.add("equinox:bundles"); - commands.add("equinox:bundle"); - commands.add("gogo:bundlebylocation"); - commands.add("gogo:bundlelevel"); - commands.add("equinox:headers"); - - CommandSession session = createMock(CommandSession.class); - expect(session.get(COMMANDS)).andReturn(commands).anyTimes(); - replay(session); - - scanner.setContext(context); - scanner.setSession(session); - - scanner.scan(CR); - scanner.scan(LF); - scanner.scan('b'); - scanner.scan('u'); - scanner.scan('n'); - scanner.scan(TAB); - res = byteOut.toString(); - Assert.assertTrue("Expected completion suggestion is not contained in the output", res.contains("bundles\r\n")); - Assert.assertTrue("Expected completion suggestion is not contained in the output", res.contains("bundle\r\n")); - Assert.assertTrue("bun should be completed to bundle", res.endsWith("bundle")); - Assert.assertTrue("Expected completion suggestion is not contained in the output", res.contains("bundlebylocation\r\n")); - Assert.assertTrue("Expected completion suggestion is not contained in the output", res.contains("bundlelevel\r\n")); - Assert.assertFalse("Not expected completion suggestion", res.contains("headers\r\n")); - } - - private static void addLine(ConsoleInputScanner scanner, byte[] line) throws Exception { - for (byte b : line) { - try { - scanner.scan(b); - } catch (Exception e) { - System.out.println("Error scanning symbol " + b); - throw new Exception("Error scanning symbol" + b); - } - } - - try { - scanner.scan(CR); - } catch (Exception e) { - System.out.println("Error scanning symbol " + CR); - throw new Exception("Error scanning symbol " + CR); - } - - try { - scanner.scan(LF); - } catch (Exception e) { - System.out.println("Error scanning symbol " + LF); - throw new Exception("Error scanning symbol " + LF); - } - } - - private void add(ConsoleInputScanner scanner, byte[] sequence) throws Exception { - scanner.scan(ESC); - for (byte b : sequence) { - scanner.scan(b); - } - } - - private void checkInpusStream(ConsoleInputStream in, byte[] expected) throws Exception { - // the actual number of bytes in the stream is two more than the bytes in the array, because of the CR and LF - // symbols, added after the array - byte[] read = new byte[expected.length + 1]; - in.read(read, 0, read.length); - for (int i = 0; i < expected.length; i++) { - Assert.assertEquals("Incorrect char read. Position " + i + ", expected " + expected[i] + ", read " + read[i], expected[i], read[i]); - } - } - -} diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/NegotiationFinishedCallbackTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/NegotiationFinishedCallbackTests.java deleted file mode 100755 index 225dfdb09..000000000 --- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/NegotiationFinishedCallbackTests.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial contribution - ******************************************************************************/ - -package org.eclipse.equinox.console.telnet; - -import org.junit.Assert; -import org.junit.Test; - -public class NegotiationFinishedCallbackTests { - - @Test - public void finishTest() throws Exception { - TelnetConnection telnetConnection = null; - telnetConnection = new TelnetConnection (null, null, null); - NegotiationFinishedCallback callback = new NegotiationFinishedCallback(telnetConnection); - callback.finished(); - Assert.assertTrue("Finished not called on console session", telnetConnection.isTelnetNegotiationFinished); - } -} diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandTests.java deleted file mode 100755 index 5cd1f9f89..000000000 --- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandTests.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2012 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial API and implementation - *******************************************************************************/ - -package org.eclipse.equinox.console.telnet; - -import java.io.OutputStream; -import java.io.PrintStream; -import java.net.Socket; -import java.util.Dictionary; - -import org.apache.felix.service.command.CommandProcessor; -import org.apache.felix.service.command.CommandSession; -import org.easymock.EasyMock; -import org.eclipse.equinox.console.common.ConsoleInputStream; -import org.junit.Test; -import org.osgi.framework.BundleContext; - - -public class TelnetCommandTests { - - private static final int TEST_CONTENT = 100; - private static final String TELNET_PORT_PROP_NAME = "osgi.console"; - private static final String USE_CONFIG_ADMIN_PROP = "osgi.console.useConfigAdmin"; - private static final String STOP_COMMAND = "stop"; - private static final String HOST = "localhost"; - private static final String FALSE = "false"; - private static final int TELNET_PORT = 2223; - private static final long WAIT_TIME = 5000; - - @Test - public void testTelnetCommand() throws Exception { - CommandSession session = EasyMock.createMock(CommandSession.class); - session.put((String)EasyMock.anyObject(), EasyMock.anyObject()); - EasyMock.expectLastCall().times(3); - EasyMock.expect(session.execute((String)EasyMock.anyObject())).andReturn(new Object()); - session.close(); - EasyMock.expectLastCall(); - EasyMock.replay(session); - - CommandProcessor processor = EasyMock.createMock(CommandProcessor.class); - EasyMock.expect(processor.createSession((ConsoleInputStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject())).andReturn(session); - EasyMock.replay(processor); - - BundleContext context = EasyMock.createMock(BundleContext.class); - EasyMock.expect(context.getProperty(USE_CONFIG_ADMIN_PROP)).andReturn(FALSE); - EasyMock.expect(context.getProperty(TELNET_PORT_PROP_NAME)).andReturn(Integer.toString(TELNET_PORT)); - EasyMock.expect(context.registerService((String)EasyMock.anyObject(), EasyMock.anyObject(), (Dictionary)EasyMock.anyObject())).andReturn(null); - EasyMock.replay(context); - - TelnetCommand command = new TelnetCommand(processor, context); - command.startService(); - - Socket socketClient = null; - try { - socketClient = new Socket(HOST, TELNET_PORT); - OutputStream outClient = socketClient.getOutputStream(); - outClient.write(TEST_CONTENT); - outClient.write('\n'); - outClient.flush(); - - // wait for the accept thread to finish execution - try { - Thread.sleep(WAIT_TIME); - } catch (InterruptedException ie) { - // do nothing - } - } finally { - if (socketClient != null) { - socketClient.close(); - } - command.telnet(new String[] {STOP_COMMAND}); - } - EasyMock.verify(context); - } -} diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandWithConfigAdminTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandWithConfigAdminTests.java deleted file mode 100755 index 15480ef54..000000000 --- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandWithConfigAdminTests.java +++ /dev/null @@ -1,206 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2012 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.console.telnet; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PrintStream; -import java.net.Socket; -import java.util.Collection; -import java.util.Dictionary; -import java.util.Hashtable; - -import junit.framework.Assert; - -import org.apache.felix.service.command.CommandProcessor; -import org.apache.felix.service.command.CommandSession; -import org.easymock.EasyMock; -import org.easymock.IAnswer; -import org.eclipse.equinox.console.common.ConsoleInputStream; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleException; -import org.osgi.framework.BundleListener; -import org.osgi.framework.Filter; -import org.osgi.framework.FrameworkListener; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceListener; -import org.osgi.framework.ServiceReference; -import org.osgi.framework.ServiceRegistration; -import org.osgi.service.cm.ManagedService; - - -public class TelnetCommandWithConfigAdminTests { - private static final int TEST_CONTENT = 100; - private static final String STOP_COMMAND = "stop"; - private static final String HOST = "localhost"; - private static final String TELNET_PORT = "2223"; - private static final long WAIT_TIME = 5000; - private static final String USE_CONFIG_ADMIN_PROP = "osgi.console.useConfigAdmin"; - private static final String TRUE = "true"; - private static final String FALSE = "false"; - private ManagedService configurator; - - @Test - public void testTelnetCommandWithConfigAdminEnabledTelnet() throws Exception { - CommandSession session = EasyMock.createMock(CommandSession.class); - session.put((String)EasyMock.anyObject(), EasyMock.anyObject()); - EasyMock.expectLastCall().times(3); - EasyMock.expect(session.execute((String)EasyMock.anyObject())).andReturn(new Object()); - session.close(); - EasyMock.expectLastCall(); - EasyMock.replay(session); - - CommandProcessor processor = EasyMock.createMock(CommandProcessor.class); - EasyMock.expect(processor.createSession((ConsoleInputStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject())).andReturn(session); - EasyMock.replay(processor); - - final ServiceRegistration registration = EasyMock.createMock(ServiceRegistration.class); - registration.setProperties((Dictionary)EasyMock.anyObject()); - - EasyMock.expectLastCall(); - EasyMock.replay(registration); - - BundleContext context = EasyMock.createMock(BundleContext.class); - EasyMock.expect(context.getProperty(USE_CONFIG_ADMIN_PROP)).andReturn(TRUE); - EasyMock.expect( - (ServiceRegistration) context.registerService( - (String)EasyMock.anyObject(), - (ManagedService)EasyMock.anyObject(), - (Dictionary)EasyMock.anyObject()) - ).andAnswer((IAnswer>) new IAnswer>() { - public ServiceRegistration answer() { - configurator = (ManagedService) EasyMock.getCurrentArguments()[1]; - return registration; - } - }); - EasyMock.expect( - context.registerService( - (String)EasyMock.anyObject(), - (TelnetCommand)EasyMock.anyObject(), - (Dictionary)EasyMock.anyObject())).andReturn(null); - EasyMock.replay(context); - - TelnetCommand command = new TelnetCommand(processor, context); - command.startService(); - Dictionary props = new Hashtable(); - props.put("port", TELNET_PORT); - props.put("host", HOST); - props.put("enabled", TRUE); - configurator.updated(props); - - Socket socketClient = null; - try { - socketClient = new Socket(HOST, Integer.parseInt(TELNET_PORT)); - OutputStream outClient = socketClient.getOutputStream(); - outClient.write(TEST_CONTENT); - outClient.write('\n'); - outClient.flush(); - - // wait for the accept thread to finish execution - try { - Thread.sleep(WAIT_TIME); - } catch (InterruptedException ie) { - // do nothing - } - } finally { - if (socketClient != null) { - socketClient.close(); - } - command.telnet(new String[] {STOP_COMMAND}); - } - EasyMock.verify(context); - } - - @Test - public void testTelnetCommandWithConfigAdminDisabledTelnet() throws Exception { - disabledTelnet(false); - } - - @Test - public void testTelnetCommandWithConfigAdminDisabledTelnetByDefault() throws Exception { - disabledTelnet(true); - } - - private void disabledTelnet(boolean isDefault) throws Exception { - CommandSession session = EasyMock.createMock(CommandSession.class); - session.put((String)EasyMock.anyObject(), EasyMock.anyObject()); - EasyMock.expectLastCall().times(4); - EasyMock.expect(session.execute((String)EasyMock.anyObject())).andReturn(new Object()); - session.close(); - EasyMock.expectLastCall(); - EasyMock.replay(session); - - CommandProcessor processor = EasyMock.createMock(CommandProcessor.class); - EasyMock.expect(processor.createSession((ConsoleInputStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject())).andReturn(session); - EasyMock.replay(processor); - - final ServiceRegistration registration = EasyMock.createMock(ServiceRegistration.class); - registration.setProperties((Dictionary)EasyMock.anyObject()); - - EasyMock.expectLastCall(); - EasyMock.replay(registration); - - BundleContext context = EasyMock.createMock(BundleContext.class); - EasyMock.expect(context.getProperty(USE_CONFIG_ADMIN_PROP)).andReturn(TRUE); - EasyMock.expect( - (ServiceRegistration) context.registerService( - (String)EasyMock.anyObject(), - (ManagedService)EasyMock.anyObject(), - (Dictionary)EasyMock.anyObject()) - ).andAnswer((IAnswer>) new IAnswer>() { - public ServiceRegistration answer() { - configurator = (ManagedService) EasyMock.getCurrentArguments()[1]; - return registration; - } - }); - EasyMock.expect( - context.registerService( - (String)EasyMock.anyObject(), - (TelnetCommand)EasyMock.anyObject(), - (Dictionary)EasyMock.anyObject())).andReturn(null); - EasyMock.replay(context); - - TelnetCommand command = new TelnetCommand(processor, context); - command.startService(); - Dictionary props = new Hashtable(); - props.put("port", TELNET_PORT); - props.put("host", HOST); - if (isDefault == false) { - props.put("enabled", FALSE); - } - configurator.updated(props); - - Socket socketClient = null; - try { - socketClient = new Socket(HOST, Integer.parseInt(TELNET_PORT)); - Assert.fail("It should not be possible to open a socket to " + HOST + ":" + TELNET_PORT); - } catch (IOException e) { - // this is ok, there should be an exception - } finally { - if (socketClient != null) { - socketClient.close(); - } - try { - command.telnet(new String[] {STOP_COMMAND}); - } catch (IllegalStateException e) { - //this is expected - } - } - EasyMock.verify(context); - } - -} diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetConnectionTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetConnectionTests.java deleted file mode 100755 index bebcd222f..000000000 --- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetConnectionTests.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2012 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial contribution - ******************************************************************************/ - -package org.eclipse.equinox.console.telnet; - -import org.apache.felix.service.command.CommandProcessor; -import org.apache.felix.service.command.CommandSession; -import org.junit.Assert; -import org.junit.Test; -import org.easymock.EasyMock; -import org.eclipse.equinox.console.common.ConsoleInputStream; - -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PrintStream; -import java.net.ServerSocket; -import java.net.Socket; - -public class TelnetConnectionTests { - - private static final String HOST = "localhost"; - private static final int TEST_CONTENT = 100; - private static final int IAC = 255; - - @Test - public void testTelneConnection() throws Exception { - ServerSocket servSocket = null; - Socket socketClient = null; - Socket socketServer = null; - TelnetConnection connection = null; - OutputStream outClient = null; - OutputStream outServer = null; - - try { - servSocket = new ServerSocket(0); - socketClient = new Socket(HOST, servSocket.getLocalPort()); - socketServer = servSocket.accept(); - - CommandSession session = EasyMock.createMock(CommandSession.class); - session.put((String)EasyMock.anyObject(), EasyMock.anyObject()); - EasyMock.expectLastCall().times(3); - EasyMock.expect(session.execute((String)EasyMock.anyObject())).andReturn(null); - session.close(); - EasyMock.expectLastCall(); - EasyMock.replay(session); - - CommandProcessor processor = EasyMock.createMock(CommandProcessor.class); - EasyMock.expect(processor.createSession((ConsoleInputStream) EasyMock.anyObject(), (PrintStream) EasyMock.anyObject(), (PrintStream) EasyMock.anyObject())).andReturn(session); - EasyMock.replay(processor); - - connection = new TelnetConnection(socketServer, processor, null); - connection.start(); - - outClient = socketClient.getOutputStream(); - outClient.write(TEST_CONTENT); - outClient.write('\n'); - outClient.flush(); - - InputStream input = socketServer.getInputStream(); - int in = input.read(); - Assert.assertTrue("Server received [" + in + "] instead of " + TEST_CONTENT + " from the telnet client.", in == TEST_CONTENT); - - input = socketClient.getInputStream(); - in = input.read(); - // here IAC is expected, since when the output stream in TelnetConsoleSession is created, several telnet - // commands are written to it, each of them starting with IAC - Assert.assertTrue("Client receive telnet responses from the server unexpected value [" + in + "] instead of " + IAC + ".", in == IAC); - connection.telnetNegotiationFinished(); - Thread.sleep(5000); - EasyMock.verify(session, processor); - } finally { - if (socketClient != null) { - socketClient.close(); - } - if (outClient != null) { - outClient.close(); - } - if (outServer != null) { - outServer.close(); - } - - if (socketServer != null) { - socketServer.close(); - } - - if (servSocket != null) { - servSocket.close(); - } - } - } -} diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetDisconnectionTest.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetDisconnectionTest.java deleted file mode 100755 index 066f5c3d7..000000000 --- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetDisconnectionTest.java +++ /dev/null @@ -1,104 +0,0 @@ -package org.eclipse.equinox.console.telnet; - -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PipedInputStream; -import java.io.PipedOutputStream; -import java.io.PrintStream; -import java.net.ServerSocket; -import java.net.Socket; - -import org.apache.felix.service.command.CommandProcessor; -import org.apache.felix.service.command.CommandSession; -import org.easymock.EasyMock; -import org.eclipse.equinox.console.commands.DisconnectCommand; -import org.eclipse.equinox.console.common.ConsoleInputStream; -import org.junit.Assert; -import org.junit.Test; -import org.osgi.framework.BundleContext; - -public class TelnetDisconnectionTest { - private static final String HOST = "localhost"; - private InputStream in; - - @Test - public void testTelneConnection() throws Exception { - ServerSocket servSocket = null; - Socket socketClient = null; - Socket socketServer = null; - TelnetConnection connection = null; - OutputStream outClient = null; - OutputStream outServer = null; - - try { - servSocket = new ServerSocket(0); - socketClient = new Socket(HOST, servSocket.getLocalPort()); - socketServer = servSocket.accept(); - - CommandProcessor processor = EasyMock.createMock(CommandProcessor.class); - connection = new TelnetConnection(socketServer, processor, null); - - final CommandSession session = EasyMock.createMock(CommandSession.class); - EasyMock.makeThreadSafe(session, true); - session.put((String)EasyMock.anyObject(), EasyMock.anyObject()); - EasyMock.expectLastCall().times(3); - EasyMock.expect(session.get("CLOSEABLE")).andReturn(connection); - EasyMock.expect(session.execute((String)EasyMock.anyObject())).andReturn(null); - session.close(); - EasyMock.expectLastCall(); - EasyMock.replay(session); - - EasyMock.expect(processor.createSession((ConsoleInputStream) EasyMock.anyObject(), (PrintStream) EasyMock.anyObject(), (PrintStream) EasyMock.anyObject())).andReturn(session); - EasyMock.replay(processor); - - connection.start(); - Thread.sleep(60000); - - BundleContext context = EasyMock.createMock(BundleContext.class); - final DisconnectCommand command = new DisconnectCommand(context); - - PipedOutputStream outputStream = new PipedOutputStream(); - PipedInputStream inputStream = new PipedInputStream(outputStream); - - in = System.in; - System.setIn(inputStream); - - new Thread() { - public void run() { - command.disconnect(session); - } - }.start(); - - outputStream.write(new byte[]{'y'}); - outputStream.write('\n'); - outputStream.flush(); - - Thread.sleep(3000); - Assert.assertTrue("Socket is not closed!", socketServer.isClosed()); - - connection.telnetNegotiationFinished(); - Thread.sleep(5000); - EasyMock.verify(session, processor); - } finally { - if (socketClient != null) { - socketClient.close(); - } - if (outClient != null) { - outClient.close(); - } - if (outServer != null) { - outServer.close(); - } - - if (socketServer != null) { - socketServer.close(); - } - - if (servSocket != null) { - servSocket.close(); - } - - System.setIn(in); - } - } -} diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetInputHandlerTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetInputHandlerTests.java deleted file mode 100755 index f5d3bd6a8..000000000 --- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetInputHandlerTests.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial contribution - ******************************************************************************/ - -package org.eclipse.equinox.console.telnet; - -import org.eclipse.equinox.console.common.ConsoleInputStream; -import org.eclipse.equinox.console.common.ConsoleOutputStream; -import org.junit.Assert; -import org.junit.Test; - -import static org.easymock.EasyMock.*; - -import java.io.ByteArrayOutputStream; -import java.io.StringBufferInputStream; - -public class TelnetInputHandlerTests { - - private static final long WAIT_TIME = 10000; - - @Test - public void testHandler() throws Exception { - StringBufferInputStream input = new StringBufferInputStream("abcde"); - ConsoleInputStream in = new ConsoleInputStream(); - ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - ConsoleOutputStream out = new ConsoleOutputStream(byteOut); - Callback callback = createMock(Callback.class); - TelnetInputHandler handler = new TelnetInputHandler(input, in, out, callback); - handler.start(); - - // wait for the accept thread to start execution - try { - Thread.sleep(WAIT_TIME); - } catch (InterruptedException ie) { - // do nothing - } - - String res = byteOut.toString(); - Assert.assertTrue("Wrong input. Expected abcde, read " + res, res.equals("abcde")); - } - -} diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetInputScannerTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetInputScannerTests.java deleted file mode 100755 index 679597358..000000000 --- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetInputScannerTests.java +++ /dev/null @@ -1,223 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial contribution - ******************************************************************************/ - -package org.eclipse.equinox.console.telnet; - -import org.eclipse.equinox.console.common.ConsoleInputStream; -import org.eclipse.equinox.console.common.ConsoleOutputStream; -import org.eclipse.equinox.console.common.KEYS; -import org.eclipse.equinox.console.common.terminal.ANSITerminalTypeMappings; -import org.eclipse.equinox.console.common.terminal.SCOTerminalTypeMappings; -import org.eclipse.equinox.console.common.terminal.TerminalTypeMappings; -import org.eclipse.equinox.console.common.terminal.VT100TerminalTypeMappings; -import org.eclipse.equinox.console.common.terminal.VT220TerminalTypeMappings; -import org.eclipse.equinox.console.common.terminal.VT320TerminalTypeMappings; -import org.junit.Assert; -import org.junit.Test; - -import static org.easymock.EasyMock.*; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PipedInputStream; -import java.io.PipedOutputStream; -import java.util.HashMap; -import java.util.Map; - -public class TelnetInputScannerTests { - - private static final int IAC = 255; - - private static final int DO = 253; - - private static final int DO_NOT = 254; - - private static final int TTYPE = 24; - - private static final int WILL = 251; - - private static final int WILL_NOT = 252; - - private static final int SB = 250; - - private static final int SE = 240; - - private static final int EL = 248; - - private static final int SEND = 1; - - private static final int IS = 0; - - protected static final byte ESC = 27; - - @Test - public void testScan() throws Exception { - ConsoleInputStream in = new ConsoleInputStream(); - ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - ConsoleOutputStream out = new ConsoleOutputStream(byteOut); - Callback callback = createMock(Callback.class); - TelnetInputScanner scanner = new TelnetInputScanner(in, out, callback); - try { - scanner.scan((byte) SE); - scanner.scan((byte) EL); - scanner.scan((byte) SB); - scanner.scan((byte) WILL); - scanner.scan((byte) WILL_NOT); - scanner.scan((byte) DO); - scanner.scan((byte) DO_NOT); - scanner.scan((byte) 'a'); - scanner.scan((byte) 'b'); - scanner.scan((byte) 'c'); - } catch (IOException e) { - System.out.println("Error while scanning: " + e.getMessage()); - e.printStackTrace(); - throw e; - } - - String output = byteOut.toString(); - Assert.assertTrue("Output incorrect. Expected abc, but read " + output, output.equals("abc")); - } - - @Test - public void testScanESC() throws Exception { - ConsoleInputStream in = new ConsoleInputStream(); - ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - ConsoleOutputStream out = new ConsoleOutputStream(byteOut); - Callback callback = createMock(Callback.class); - TelnetInputScanner scanner = new TelnetInputScanner(in, out, callback); - - try { - scanner.scan((byte) 'a'); - scanner.scan((byte) ESC); - scanner.scan((byte) 'b'); - } catch (IOException e) { - System.out.println("Error while scanning: " + e.getMessage()); - e.printStackTrace(); - throw e; - } - - String output = byteOut.toString(); - Assert.assertTrue("Output incorrect. Expected ab, but read " + output, output.equals("ab")); - } - - @Test - public void testTTNegotiations() throws Exception { - Map ttMappings = new HashMap(); - ttMappings.put(new byte[] { 'A', 'N', 'S', 'I' }, new ANSITerminalTypeMappings()); - ttMappings.put(new byte[] { 'V', 'T', '1', '0', '0' }, new VT100TerminalTypeMappings()); - ttMappings.put(new byte[] { 'V', 'T', '2', '2', '0' }, new VT220TerminalTypeMappings()); - ttMappings.put(new byte[] { 'X', 'T', 'E', 'R', 'M' }, new VT220TerminalTypeMappings()); - ttMappings.put(new byte[] { 'V', 'T', '3', '2', '0' }, new VT320TerminalTypeMappings()); - ttMappings.put(new byte[] { 'S', 'C', 'O' }, new SCOTerminalTypeMappings()); - - for (byte[] ttype : ttMappings.keySet()) { - testTerminalTypeNegotiation(ttype, ttMappings.get(ttype)); - } - } - - private void testTerminalTypeNegotiation(byte[] terminalType, TerminalTypeMappings mappings) throws Exception { - PipedInputStream clientIn = new PipedInputStream(); - PipedOutputStream serverOut = new PipedOutputStream(clientIn); - - byte[] requestNegotiation = { (byte) IAC, (byte) DO, (byte) TTYPE }; - - TestCallback testCallback = new TestCallback(); - TelnetOutputStream out = new TelnetOutputStream(serverOut); - TelnetInputScanner scanner = new TelnetInputScanner(new ConsoleInputStream(), out, testCallback); - out.write(requestNegotiation); - out.flush(); - - int read = clientIn.read(); - Assert.assertEquals("Unexpected input ", IAC, read); - read = clientIn.read(); - Assert.assertEquals("Unexpected input ", DO, read); - read = clientIn.read(); - Assert.assertEquals("Unexpected input ", TTYPE, read); - - scanner.scan(IAC); - scanner.scan(WILL); - scanner.scan(TTYPE); - - read = clientIn.read(); - Assert.assertEquals("Unexpected input ", IAC, read); - read = clientIn.read(); - Assert.assertEquals("Unexpected input ", SB, read); - read = clientIn.read(); - Assert.assertEquals("Unexpected input ", TTYPE, read); - read = clientIn.read(); - Assert.assertEquals("Unexpected input ", SEND, read); - read = clientIn.read(); - Assert.assertEquals("Unexpected input ", IAC, read); - read = clientIn.read(); - Assert.assertEquals("Unexpected input ", SE, read); - - scanner.scan(IAC); - scanner.scan(SB); - scanner.scan(TTYPE); - scanner.scan(IS); - scanner.scan('A'); - scanner.scan('B'); - scanner.scan('C'); - scanner.scan('D'); - scanner.scan('E'); - scanner.scan(IAC); - scanner.scan(SE); - - read = clientIn.read(); - Assert.assertEquals("Unexpected input ", IAC, read); - read = clientIn.read(); - Assert.assertEquals("Unexpected input ", SB, read); - read = clientIn.read(); - Assert.assertEquals("Unexpected input ", TTYPE, read); - read = clientIn.read(); - Assert.assertEquals("Unexpected input ", SEND, read); - read = clientIn.read(); - Assert.assertEquals("Unexpected input ", IAC, read); - read = clientIn.read(); - Assert.assertEquals("Unexpected input ", SE, read); - - scanner.scan(IAC); - scanner.scan(SB); - scanner.scan(TTYPE); - scanner.scan(IS); - for (byte symbol : terminalType) { - scanner.scan(symbol); - } - scanner.scan(IAC); - scanner.scan(SE); - - Assert.assertEquals("Incorrect BACKSPACE: ", mappings.getBackspace(), scanner.getBackspace()); - Assert.assertEquals("Incorrect DELL: ", mappings.getDel(), scanner.getDel()); - - Map currentEscapesToKey = scanner.getCurrentEscapesToKey(); - Map expectedEscapesToKey = mappings.getEscapesToKey(); - for (String escape : expectedEscapesToKey.keySet()) { - KEYS key = expectedEscapesToKey.get(escape); - Assert.assertEquals("Incorrect " + key.name(), key, currentEscapesToKey.get(escape)); - } - - Assert.assertTrue("Callback not called ", testCallback.getState()); - } - - class TestCallback implements Callback { - - private boolean isCalled = false; - - public void finished() { - isCalled = true; - } - - public boolean getState() { - return isCalled; - } - } - -} diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetOutputStreamTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetOutputStreamTests.java deleted file mode 100755 index f975f4dc7..000000000 --- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetOutputStreamTests.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial contribution - ******************************************************************************/ - -package org.eclipse.equinox.console.telnet; - -import org.junit.Assert; -import org.junit.Test; - -import java.io.ByteArrayOutputStream; - -public class TelnetOutputStreamTests { - - @Test - public void testAutoSend() throws Exception { - ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - TelnetOutputStream out = new TelnetOutputStream(byteOut); - out.autoSend(); - out.flush(); - byte[] message = byteOut.toByteArray(); - - Assert.assertNotNull("Auto message not sent", message); - Assert.assertFalse("Auto message not sent", message.length == 0); - Assert.assertTrue("Error sending auto message. Expected length: " + TelnetOutputStream.autoMessage.length + ", actual length: " - + message.length, message.length == TelnetOutputStream.autoMessage.length); - - for (int i = 0; i < message.length; i++) { - Assert.assertEquals("Wrong char in auto message. Position: " + i + ", expected: " + TelnetOutputStream.autoMessage[i] + ", read: " - + message[i], TelnetOutputStream.autoMessage[i], message[i]); - } - } -} diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetServerTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetServerTests.java deleted file mode 100755 index 21eb4c546..000000000 --- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetServerTests.java +++ /dev/null @@ -1,125 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 SAP AG - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Lazar Kirchev, SAP AG - initial contribution - ******************************************************************************/ - -package org.eclipse.equinox.console.telnet; - -import org.apache.felix.service.command.CommandProcessor; -import org.apache.felix.service.command.CommandSession; -import org.easymock.EasyMock; -import org.eclipse.equinox.console.common.ConsoleInputStream; -import org.junit.Assert; -import org.junit.Test; - -import java.io.OutputStream; -import java.io.PrintStream; -import java.net.ConnectException; -import java.net.Socket; -import java.util.ArrayList; -import java.util.List; - -import static org.easymock.EasyMock.*; - -public class TelnetServerTests { - - private static final String HOST = "localhost"; - private static final int PORT = 38888; - private static final long WAIT_TIME = 5000; - private static final int TEST_CONTENT = 100; - - @Test - public void testTelnetServer() throws Exception { - - CommandSession session = EasyMock.createMock(CommandSession.class); - session.put((String)EasyMock.anyObject(), EasyMock.anyObject()); - EasyMock.expectLastCall().times(3); - EasyMock.expect(session.execute((String)EasyMock.anyObject())).andReturn(new Object()); - session.close(); - EasyMock.expectLastCall(); - EasyMock.replay(session); - - CommandProcessor processor = EasyMock.createMock(CommandProcessor.class); - EasyMock.expect(processor.createSession((ConsoleInputStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject())).andReturn(session); - EasyMock.replay(processor); - - List processors = new ArrayList(); - processors.add(processor); - TelnetServer telnetServer = new TelnetServer(null, processors, HOST, PORT); - telnetServer.start(); - Socket socketClient = null; - - try { - socketClient = new Socket("localhost", PORT); - OutputStream outClient = socketClient.getOutputStream(); - outClient.write(TEST_CONTENT); - outClient.write('\n'); - outClient.flush(); - // wait for the accept thread to finish execution - try { - Thread.sleep(WAIT_TIME); - } catch (InterruptedException ie) { - // do nothing - } - verify(); - } catch(ConnectException e) { - Assert.fail("Telnet port not open"); - } finally { - if (socketClient != null) { - socketClient.close(); - } - telnetServer.stopTelnetServer(); - } - } - - @Test - public void testTelnetServerWithoutHost() throws Exception { - CommandSession session = EasyMock.createMock(CommandSession.class); - session.put((String)EasyMock.anyObject(), EasyMock.anyObject()); - EasyMock.expectLastCall().times(4); - EasyMock.expect(session.execute((String)EasyMock.anyObject())).andReturn(new Object()); - session.close(); - EasyMock.expectLastCall(); - EasyMock.replay(session); - - CommandProcessor processor = EasyMock.createMock(CommandProcessor.class); - EasyMock.expect(processor.createSession((ConsoleInputStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject())).andReturn(session); - EasyMock.replay(processor); - - List processors = new ArrayList(); - processors.add(processor); - TelnetServer telnetServer = new TelnetServer(null, processors, null, PORT); - telnetServer.start(); - Socket socketClient = null; - - try { - socketClient = new Socket("localhost", PORT); - OutputStream outClient = socketClient.getOutputStream(); - outClient.write(TEST_CONTENT); - outClient.write('\n'); - outClient.flush(); - - // wait for the accept thread to finish execution - try { - Thread.sleep(WAIT_TIME); - } catch (InterruptedException ie) { - // do nothing - } - } catch(ConnectException e) { - Assert.fail("Telnet port not open"); - } finally { - if (socketClient != null) { - socketClient.close(); - } - telnetServer.stopTelnetServer(); - } - - } - -} -- cgit v1.2.3