diff --git a/Makefile b/Makefile index 51ceb5e1bff4217c9e4ef9127a78b8a9dcae18e3..77d4d96ae6b9ebb3814599b22e4fb90cbc09683f 100755 --- a/Makefile +++ b/Makefile @@ -246,7 +246,7 @@ $(STDRELEASE:.tgz=.tar): $(BASERELEASE:.tgz=.tar) @cp $(TTOOL_DOC)/README_nc $(TTOOL_TARGET)/nc #DOC -@cd $(TTOOL_DOC_AVATARCODEGENERATION_DIR)/&&$(TTOOL_DOC_AVATARCODEGENERATION_CMD) + @cd $(TTOOL_DOC_AVATARCODEGENERATION_DIR)/&&$(TTOOL_DOC_AVATARCODEGENERATION_CMD) @cp $(TTOOL_DOC_AVATARCODEGENERATION_DIR)/codegeneration_documentation.pf $(TTOOL_TARGET)/doc/avatarcodegeneration_documentation.pdf @cd $(TTOOL_DOC_SOCLIB_USERGUIDE_DIR)/&&$(TTOOL_DOC_SOCLIB_USERGUIDE_CMD) diff --git a/tests/util/fr.tpt.ttool.tests.util/src/fr/tpt/ttool/tests/util/remote/TestRshClient.java b/tests/util/fr.tpt.ttool.tests.util/src/fr/tpt/ttool/tests/util/remote/TestRshClient.java index c75c854a94454113d064df154df83c46a4ab603e..c7fac835ec5b1d63335268a44b542dfa876a021b 100644 --- a/tests/util/fr.tpt.ttool.tests.util/src/fr/tpt/ttool/tests/util/remote/TestRshClient.java +++ b/tests/util/fr.tpt.ttool.tests.util/src/fr/tpt/ttool/tests/util/remote/TestRshClient.java @@ -21,311 +21,311 @@ import myutil.FileException; import myutil.FileUtils; public class TestRshClient { - - private static final String EXPECTED_COMMAND_OUTPUT = "!!!Hello World!!!" + System.lineSeparator(); - private static final String TEST_PROGRAM_NAME = "helloWorld"; - private static final String TEST_COMMAND = "./resources/" + TEST_PROGRAM_NAME; - private static final String TEST_COMMAND_NON_STOP = "./resources/helloWorldNonStop"; - private static final String TEST_FILE_NAME = "./resources/test.txt"; - private static final String TEST_FILE_DATA = "testDatafhkenomrcg ,jgh o"; - - - private RshClient client = null; - private static Thread serverThread = null; - - @BeforeClass - public static void setUpBeforeClass() - throws Exception { + + private static final String EXPECTED_COMMAND_OUTPUT = "!!!Hello World!!!" + System.lineSeparator(); + private static final String TEST_PROGRAM_NAME = "helloWorld"; + private static final String TEST_COMMAND = "./resources/" + TEST_PROGRAM_NAME; + private static final String TEST_COMMAND_NON_STOP = "./resources/helloWorldNonStop"; + private static final String TEST_FILE_NAME = "./resources/test.txt"; + private static final String TEST_FILE_DATA = "testDatafhkenomrcg ,jgh o"; + + + private RshClient client = null; + private static Thread serverThread = null; + + @BeforeClass + public static void setUpBeforeClass() + throws Exception { RshClient.PORT_NUMBER = 8080; RshServer.PORT_NUMBER = RshClient.PORT_NUMBER; final Runnable runnable = new Runnable() { - - @Override - public void run() { - new RshServer( null ).startServer(); - } - }; - - serverThread = new Thread( runnable ); - serverThread.start(); - Thread.sleep( 500 ); - } - - @Before - public void setUp() - throws Exception { - client = new RshClient( "localhost" ); - } - - @After - public void tearDown() - throws Exception { - client = null; - } - - @AfterClass - public static void tearDownAfterClass() - throws Exception { - serverThread.interrupt(); - } - - private void handleException( final Throwable th ) { - th.printStackTrace(); - fail( th.getLocalizedMessage() ); - } - - @Test - public void testStopCommand() { + + @Override + public void run() { + new RshServer( null ).startServer(); + } + }; + + serverThread = new Thread( runnable ); + serverThread.start(); + Thread.sleep( 500 ); + } + + @Before + public void setUp() + throws Exception { + client = new RshClient( "localhost" ); + } + + @After + public void tearDown() + throws Exception { + client = null; + } + + @AfterClass + public static void tearDownAfterClass() + throws Exception { + serverThread.interrupt(); + } + + private void handleException( final Throwable th ) { + th.printStackTrace(); + fail( th.getLocalizedMessage() ); + } + + @Test + public void testStopCommand() { final Runnable runnable = new Runnable() { - - @Override - public void run() { - try { - client.setCmd( TEST_COMMAND_NON_STOP ); - client.sendExecuteCommandRequest(); - final Writer writer = new StringWriter(); - client.writeCommandMessages( writer ); - } - catch (LauncherException e) { - handleException( e ); - } - } - }; - - final Thread thread = new Thread( runnable ); - thread.start(); - - try { - - // Ensure the remote process has enough time to start - Thread.sleep( 200 ); - client.stopCommand(); - - // Ensure the stop command has been processed on the server - Thread.sleep( 200 ); - assertTrue( killUnexistentProcess() ); - } - catch ( LauncherException ex ) { - handleException( ex ); - } - catch ( InterruptedException ex ) { - handleException( ex ); - } - } - - private boolean killUnexistentProcess() { - try { - client.sendKillProcessRequest(); - - return false; - } - catch ( LauncherException ex ) { - return RshClient.FAILED.equals( ex.getMessage() ); - } - } - - @Test - public void testGetId() { - try { - final int id = client.getId(); - assertTrue( id == 1 ); - } - catch ( LauncherException ex ) { - handleException( ex ); - } - } - - @Test - public void testFreeId() { - try { - client.freeId( 1 ); - } - catch ( LauncherException ex ) { - handleException( ex ); - } - } - - @Test - public void testSendExecuteCommandRequest() { - client.setCmd( TEST_COMMAND ); - - try { - client.sendExecuteCommandRequest(); - final Writer writer = new StringWriter(); - client.writeCommandMessages( writer ); - assertTrue( ( EXPECTED_COMMAND_OUTPUT + System.lineSeparator() ).equals( writer.toString() ) ); - } - catch ( LauncherException ex ) { - handleException( ex ); - } - } - - @Test - public void testSendExecuteCommandRequestBoolean() { - client.setCmd( TEST_COMMAND ); - - try { - client.sendExecuteCommandRequest( true ); - final Writer writer = new StringWriter(); - client.writeCommandMessages( writer ); - assertTrue( writer.toString().startsWith( EXPECTED_COMMAND_OUTPUT ) ); - - final Integer retCode = client.getProcessReturnCode(); - assertTrue( retCode != null && retCode == 0 ); - } - catch ( LauncherException ex ) { - handleException( ex ); - } - } - - @Test - public void testSendExecutePipedCommandsRequest() { - final String testFileName = "./resources/test_piped_commands.txt"; - final String expectedData = "Test Passed!" + System.lineSeparator(); - - try { - FileUtils.saveFile( testFileName, expectedData ); - client.sendExecutePipedCommandsRequest( "echo " + testFileName, "xargs cat" ); - final String data = client.getDataFromProcess(); - - assertTrue( "Piped commands returned " + data, expectedData.equals( data ) ); - } - catch ( LauncherException ex ) { - handleException( ex ); - } - catch ( FileException ex ) { - handleException( ex ); - } - finally { - new File( testFileName ).delete(); - } - } - - private boolean deleteTestFile() { - final File testFile = new File( TEST_FILE_NAME ); - - if ( testFile.exists() ) { - assertTrue( "Test file could not be deleted!", testFile.delete() ); - } - - return true; - } - - @Test - public void testSendFileData() { - deleteTestFile(); - - try { - client.sendFileData( TEST_FILE_NAME, TEST_FILE_DATA ); - - try { - final String readData = FileUtils.loadFile( TEST_FILE_NAME ); - - assertTrue( ( TEST_FILE_DATA + System.lineSeparator() ).equals( readData ) ); - } - catch ( FileException ex ) { - handleException( ex ); - } - } - catch( LauncherException ex ) { - handleException( ex ); - } - } - - @Test - public void testGetFileData() { - deleteTestFile(); - - try { - FileUtils.saveFile( TEST_FILE_NAME, TEST_FILE_DATA ); - - final String readData = client.getFileData( TEST_FILE_NAME ); - - assertTrue( TEST_FILE_DATA.equals( readData ) ); - } - catch ( FileException ex ) { - handleException( ex ); - } - catch ( LauncherException ex ) { - handleException( ex ); - } - } - - @Test - public void testDeleteFile() { - deleteTestFile(); - - try { - FileUtils.saveFile( TEST_FILE_NAME, TEST_FILE_DATA ); - - client.deleteFile( TEST_FILE_NAME ); - - assertFalse( new File( TEST_FILE_NAME ).exists() ); - } - catch ( FileException ex ) { - handleException( ex ); - } - catch ( LauncherException ex ) { - handleException( ex ); - } - } - - @Test - public void testSendKillProcessRequest() { - client.setCmd( TEST_COMMAND_NON_STOP ); - - try { - client.sendExecuteCommandRequest(); - Thread.sleep( 200 ); - client.sendKillProcessRequest(); - - Thread.sleep( 200 ); - assertTrue( killUnexistentProcess() ); - } - catch ( LauncherException ex ) { - handleException( ex ); - } - catch ( InterruptedException ex ) { - handleException( ex ); - } - } - - @Test - public void testSendKillAllProcessRequest() { - client.setCmd( TEST_COMMAND_NON_STOP ); - - try { - for ( int index = 0; index < 4; index++ ) { - client.sendExecuteCommandRequest(); - Thread.sleep( 200 ); - } - - client.sendKillAllProcessRequest(); - - Thread.sleep( 200 ); - assertTrue( killUnexistentProcess() ); - } - catch ( LauncherException ex ) { - handleException( ex ); - } - catch ( InterruptedException ex ) { - handleException( ex ); - } - } - - @Test - public void testGetDataFromProcess() { - client.setCmd( TEST_COMMAND ); - - try { - client.sendExecuteCommandRequest(); - final String messageFromProcess = client.getDataFromProcess(); - - assertTrue( ( EXPECTED_COMMAND_OUTPUT ).equals( messageFromProcess ) ); - } - catch ( LauncherException ex ) { - handleException( ex ); - } - } + + @Override + public void run() { + try { + client.setCmd( TEST_COMMAND_NON_STOP ); + client.sendExecuteCommandRequest(); + final Writer writer = new StringWriter(); + client.writeCommandMessages( writer ); + } + catch (LauncherException e) { + handleException( e ); + } + } + }; + + final Thread thread = new Thread( runnable ); + thread.start(); + + try { + + // Ensure the remote process has enough time to start + Thread.sleep( 200 ); + client.stopCommand(); + + // Ensure the stop command has been processed on the server + Thread.sleep( 200 ); + assertTrue( killUnexistentProcess() ); + } + catch ( LauncherException ex ) { + handleException( ex ); + } + catch ( InterruptedException ex ) { + handleException( ex ); + } + } + + private boolean killUnexistentProcess() { + try { + client.sendKillProcessRequest(); + + return false; + } + catch ( LauncherException ex ) { + return RshClient.FAILED.equals( ex.getMessage() ); + } + } + + @Test + public void testGetId() { + try { + final int id = client.getId(); + assertTrue( id == 1 ); + } + catch ( LauncherException ex ) { + handleException( ex ); + } + } + + @Test + public void testFreeId() { + try { + client.freeId( 1 ); + } + catch ( LauncherException ex ) { + handleException( ex ); + } + } + + @Test + public void testSendExecuteCommandRequest() { + client.setCmd( TEST_COMMAND ); + + try { + client.sendExecuteCommandRequest(); + final Writer writer = new StringWriter(); + client.writeCommandMessages( writer ); + assertTrue( ( EXPECTED_COMMAND_OUTPUT + System.lineSeparator() ).equals( writer.toString() ) ); + } + catch ( LauncherException ex ) { + handleException( ex ); + } + } + + @Test + public void testSendExecuteCommandRequestBoolean() { + client.setCmd( TEST_COMMAND ); + + try { + client.sendExecuteCommandRequest( true ); + final Writer writer = new StringWriter(); + client.writeCommandMessages( writer ); + assertTrue( writer.toString().startsWith( EXPECTED_COMMAND_OUTPUT ) ); + + final Integer retCode = client.getProcessReturnCode(); + assertTrue( retCode != null && retCode == 0 ); + } + catch ( LauncherException ex ) { + handleException( ex ); + } + } + + @Test + public void testSendExecutePipedCommandsRequest() { + final String testFileName = "./resources/test_piped_commands.txt"; + final String expectedData = "Test Passed!" + System.lineSeparator(); + + try { + FileUtils.saveFile( testFileName, expectedData ); + client.sendExecutePipedCommandsRequest( "echo " + testFileName, "xargs cat" ); + final String data = client.getDataFromProcess(); + + assertTrue( "Piped commands returned " + data, expectedData.equals( data ) ); + } + catch ( LauncherException ex ) { + handleException( ex ); + } + catch ( FileException ex ) { + handleException( ex ); + } + finally { + new File( testFileName ).delete(); + } + } + + private boolean deleteTestFile() { + final File testFile = new File( TEST_FILE_NAME ); + + if ( testFile.exists() ) { + assertTrue( "Test file could not be deleted!", testFile.delete() ); + } + + return true; + } + + @Test + public void testSendFileData() { + deleteTestFile(); + + try { + client.sendFileData( TEST_FILE_NAME, TEST_FILE_DATA ); + + try { + final String readData = FileUtils.loadFile( TEST_FILE_NAME ); + + assertTrue( ( TEST_FILE_DATA + System.lineSeparator() ).equals( readData ) ); + } + catch ( FileException ex ) { + handleException( ex ); + } + } + catch( LauncherException ex ) { + handleException( ex ); + } + } + + @Test + public void testGetFileData() { + deleteTestFile(); + + try { + FileUtils.saveFile( TEST_FILE_NAME, TEST_FILE_DATA ); + + final String readData = client.getFileData( TEST_FILE_NAME ); + + assertTrue( TEST_FILE_DATA.equals( readData ) ); + } + catch ( FileException ex ) { + handleException( ex ); + } + catch ( LauncherException ex ) { + handleException( ex ); + } + } + + @Test + public void testDeleteFile() { + deleteTestFile(); + + try { + FileUtils.saveFile( TEST_FILE_NAME, TEST_FILE_DATA ); + + client.deleteFile( TEST_FILE_NAME ); + + assertFalse( new File( TEST_FILE_NAME ).exists() ); + } + catch ( FileException ex ) { + handleException( ex ); + } + catch ( LauncherException ex ) { + handleException( ex ); + } + } + + @Test + public void testSendKillProcessRequest() { + client.setCmd( TEST_COMMAND_NON_STOP ); + + try { + client.sendExecuteCommandRequest(); + Thread.sleep( 200 ); + client.sendKillProcessRequest(); + + Thread.sleep( 200 ); + assertTrue( killUnexistentProcess() ); + } + catch ( LauncherException ex ) { + handleException( ex ); + } + catch ( InterruptedException ex ) { + handleException( ex ); + } + } + + @Test + public void testSendKillAllProcessRequest() { + client.setCmd( TEST_COMMAND_NON_STOP ); + + try { + for ( int index = 0; index < 4; index++ ) { + client.sendExecuteCommandRequest(); + Thread.sleep( 200 ); + } + + client.sendKillAllProcessRequest(); + + Thread.sleep( 200 ); + assertTrue( killUnexistentProcess() ); + } + catch ( LauncherException ex ) { + handleException( ex ); + } + catch ( InterruptedException ex ) { + handleException( ex ); + } + } + + @Test + public void testGetDataFromProcess() { + client.setCmd( TEST_COMMAND ); + + try { + client.sendExecuteCommandRequest(); + final String messageFromProcess = client.getDataFromProcess(); + + assertTrue( ( EXPECTED_COMMAND_OUTPUT ).equals( messageFromProcess ) ); + } + catch ( LauncherException ex ) { + handleException( ex ); + } + } }