diff options
author | Nils Schwabe | 2014-04-23 15:10:36 +0200 |
---|---|---|
committer | Nils Schwabe | 2014-04-23 15:10:36 +0200 |
commit | f71e8a5bcd2d7f85f58fedf3f6ea8dc8c7f89b63 (patch) | |
tree | 5a79e7f320e6ca76ade3cf8039079d182f0178ad /src/test/java/org/openslx/imagemaster | |
parent | Fix some issues with FtpCredentialsScheduler (diff) | |
download | masterserver-f71e8a5bcd2d7f85f58fedf3f6ea8dc8c7f89b63.tar.gz masterserver-f71e8a5bcd2d7f85f58fedf3f6ea8dc8c7f89b63.tar.xz masterserver-f71e8a5bcd2d7f85f58fedf3f6ea8dc8c7f89b63.zip |
Reformat all files with simon's new layout
Diffstat (limited to 'src/test/java/org/openslx/imagemaster')
-rw-r--r-- | src/test/java/org/openslx/imagemaster/AppTest.java | 220 |
1 files changed, 112 insertions, 108 deletions
diff --git a/src/test/java/org/openslx/imagemaster/AppTest.java b/src/test/java/org/openslx/imagemaster/AppTest.java index fecf9ac..291206b 100644 --- a/src/test/java/org/openslx/imagemaster/AppTest.java +++ b/src/test/java/org/openslx/imagemaster/AppTest.java @@ -31,83 +31,87 @@ import org.openslx.imagemaster.util.Sha512Crypt; /** * Unit test for simple App. */ -public class AppTest - extends TestCase +public class AppTest + extends TestCase { - /** - * Create the test case - * - * @param testName name of the test case - */ - public AppTest( String testName ) - { - super( testName ); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( AppTest.class ); - } - - /** - * Rigourous Test :-) - */ - public void testApp() - { - assertTrue( true ); - } - - /** - * Test the authentication - * @throws TException - */ - public void testAuthentication() throws TException { - TTransport transport = new TSocket("localhost", 9090); + + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest(String testName) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } + + /** + * Test the authentication + * + * @throws TException + */ + public void testAuthentication() throws TException + { + TTransport transport = new TSocket( "localhost", 9090 ); transport.open(); - - TProtocol protocol = new TBinaryProtocol(transport); - Client client = new Client(protocol); - - assertTrue("Could not ping server", client.ping()); - - SessionData sessionData = client.authenticate("ns202", "xxxxxxxxxxxx"); - UserInfo userInfo = client.getUserFromToken(sessionData.getAuthToken()); - System.out.println("User info: " + userInfo); - System.out.println("Server address from MySQL: " + sessionData.serverAddress); - } - - /** - * Test the server authentication and FTP Upload. - * @throws TException - * @throws IOException - * @throws SocketException - */ - public void testServerAuth() throws TException, SocketException, IOException { - TTransport transport = new TSocket("localhost", 9090); + + TProtocol protocol = new TBinaryProtocol( transport ); + Client client = new Client( protocol ); + + assertTrue( "Could not ping server", client.ping() ); + + SessionData sessionData = client.authenticate( "ns202", "xxxxxxxxxxxx" ); + UserInfo userInfo = client.getUserFromToken( sessionData.getAuthToken() ); + System.out.println( "User info: " + userInfo ); + System.out.println( "Server address from MySQL: " + sessionData.serverAddress ); + } + + /** + * Test the server authentication and FTP Upload. + * + * @throws TException + * @throws IOException + * @throws SocketException + */ + public void testServerAuth() throws TException, SocketException, IOException + { + TTransport transport = new TSocket( "localhost", 9090 ); transport.open(); - - TProtocol protocol = new TBinaryProtocol(transport); - Client client = new Client(protocol); - - assertTrue("Could not ping server", client.ping()); - - String stringToEncrypt = client.startServerAuthentication("Test Organization"); - System.out.println("Authentication started. Got string: " + stringToEncrypt); - + + TProtocol protocol = new TBinaryProtocol( transport ); + Client client = new Client( protocol ); + + assertTrue( "Could not ping server", client.ping() ); + + String stringToEncrypt = client.startServerAuthentication( "Test Organization" ); + System.out.println( "Authentication started. Got string: " + stringToEncrypt ); + String response = stringToEncrypt; - - ServerSessionData data = client.serverAuthenticate("Test Organization", response); - System.out.println("Authenticated and got sid: '" + data.getSessionId() + "'"); - - + + ServerSessionData data = client.serverAuthenticate( "Test Organization", response ); + System.out.println( "Authenticated and got sid: '" + data.getSessionId() + "'" ); + // Create ImageData int version = 1; String imageName = "maschine.vmkd"; UUID uuid = UUID.randomUUID(); - int imageCreateTime = (int) new Date().getTime(); + int imageCreateTime = (int)new Date().getTime(); int imageUpdateTime = imageCreateTime; String imageOwner = "ns202"; String contentOperatingSystem = "win7"; @@ -115,59 +119,59 @@ public class AppTest boolean statusIsDeleted = false; String imageShortDescrption = "EIN SUPER TOLLES IMAGE!"; String imageLongDescription = "Lorem ipsum dolor sit amet."; - - ImageData imageData = new ImageData(uuid.toString(), version, imageName, + + ImageData imageData = new ImageData( uuid.toString(), version, imageName, imageCreateTime, imageUpdateTime, imageOwner, contentOperatingSystem, - statusIsValid, statusIsDeleted, imageShortDescrption, imageLongDescription); - - System.out.println("Created imageData"); - - FtpCredentials ftpCredentials = client.submitImage(data.sessionId, imageData); - System.out.println("Got FTP credentials. User: " + ftpCredentials.username + ", password: " + ftpCredentials.password); - - FTPClient FtpClient = new FTPClient(); - String host = "localhost"; - int port = 2221; - String user = ftpCredentials.username; - String password = ftpCredentials.password; - String fileName = "/home/nils/file_to_upload.bin"; - - try { - FtpClient.connect(host, port); - System.out.println("Connected to " + host + ":" + port + ". Reply code: " + FtpClient.getReplyCode()); + statusIsValid, statusIsDeleted, imageShortDescrption, imageLongDescription ); + + System.out.println( "Created imageData" ); + + FtpCredentials ftpCredentials = client.submitImage( data.sessionId, imageData ); + System.out.println( "Got FTP credentials. User: " + ftpCredentials.username + ", password: " + ftpCredentials.password ); + + FTPClient FtpClient = new FTPClient(); + String host = "localhost"; + int port = 2221; + String user = ftpCredentials.username; + String password = ftpCredentials.password; + String fileName = "/home/nils/file_to_upload.bin"; + + try { + FtpClient.connect( host, port ); + System.out.println( "Connected to " + host + ":" + port + ". Reply code: " + FtpClient.getReplyCode() ); if ( !FTPReply.isPositiveCompletion( FtpClient.getReplyCode() ) ) { - ConnectException ce = new ConnectException("No positive reply code."); + ConnectException ce = new ConnectException( "No positive reply code." ); throw ce; } - if ( !FtpClient.login(user, password) ) { - ConnectException ce = new ConnectException("Could not login."); + if ( !FtpClient.login( user, password ) ) { + ConnectException ce = new ConnectException( "Could not login." ); throw ce; } - System.out.println("Logged in with user: " + user); - FtpClient.setFileType(FTP.BINARY_FILE_TYPE); + System.out.println( "Logged in with user: " + user ); + FtpClient.setFileType( FTP.BINARY_FILE_TYPE ); FtpClient.enterLocalPassiveMode(); - System.out.println("Entered PASSIVE MODE"); - InputStream input = new FileInputStream(fileName); - System.out.print("Starting file upload ... "); - FtpClient.storeFile("xcvb.vmdk", input); - System.out.println("done."); + System.out.println( "Entered PASSIVE MODE" ); + InputStream input = new FileInputStream( fileName ); + System.out.print( "Starting file upload ... " ); + FtpClient.storeFile( "xcvb.vmdk", input ); + System.out.println( "done." ); FtpClient.noop(); client.finshedUpload( data.sessionId, imageData ); } finally { - if (FtpClient.isConnected()) { + if ( FtpClient.isConnected() ) { try { FtpClient.logout(); FtpClient.disconnect(); - } catch (IOException e) { + } catch ( IOException e ) { e.printStackTrace(); } } - } - - } - - public void testSha512_Crypt() - { - Sha512Crypt.selfTest(); - } + } + + } + + public void testSha512_Crypt() + { + Sha512Crypt.selfTest(); + } } |