summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorNils Schwabe2014-06-30 17:11:03 +0200
committerNils Schwabe2014-06-30 17:11:03 +0200
commit1a3dbab6ca7118f4ca9f61043f416f074ede13bc (patch)
treefad14555be544c3ba2afdf31b8f315364a67e7a6 /src/test
parent[Webinterface] Add "images" tab (diff)
downloadmasterserver-1a3dbab6ca7118f4ca9f61043f416f074ede13bc.tar.gz
masterserver-1a3dbab6ca7118f4ca9f61043f416f074ede13bc.tar.xz
masterserver-1a3dbab6ca7118f4ca9f61043f416f074ede13bc.zip
Add implementation for the new up- and download protocoll
Remove some old stuff that is not needed anymore Fix some small bugs
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/openslx/imagemaster/AppTest.java35
-rw-r--r--src/test/java/org/openslx/imagemaster/ServerTest.java223
2 files changed, 26 insertions, 232 deletions
diff --git a/src/test/java/org/openslx/imagemaster/AppTest.java b/src/test/java/org/openslx/imagemaster/AppTest.java
index 00be484..7904efc 100644
--- a/src/test/java/org/openslx/imagemaster/AppTest.java
+++ b/src/test/java/org/openslx/imagemaster/AppTest.java
@@ -1,19 +1,14 @@
package org.openslx.imagemaster;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.security.InvalidKeyException;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.SignatureException;
-import java.security.UnrecoverableKeyException;
-import java.security.cert.CertificateException;
+import java.util.UUID;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
-import org.openslx.imagemaster.util.AsymMessageVerifier;
+import org.openslx.imagemaster.serverconnection.ImageProcessor;
+import org.openslx.imagemaster.thrift.iface.ImageData;
+import org.openslx.imagemaster.thrift.iface.UploadInfos;
import org.openslx.imagemaster.util.Sha512Crypt;
/**
@@ -52,4 +47,26 @@ public class AppTest extends TestCase
{
Sha512Crypt.selfTest();
}
+
+ public void testImageProcessor() {
+ ImageData imageData = new ImageData(UUID.randomUUID().toString(), 1, "windows7.vmdk",
+ System.currentTimeMillis(), System.currentTimeMillis(), "ns202@uni-freiburg.de", "win7",
+ true, false, "Windows 7", "Das ist ein tolles Windows 7", 40*16*1024*1024L); // exactly 40 blocks
+
+ UploadInfos uploadInfos = ImageProcessor.getUploadInfos( "asdfasdfasdf", imageData );
+ assertEquals( "Not the right number of blocks", 20, uploadInfos.missingBlocks.size() );
+ for (int i = 0; i < uploadInfos.missingBlocks.size(); i++) {
+ assertEquals(i, uploadInfos.missingBlocks.remove( 0 ).intValue());
+ }
+
+ String token = uploadInfos.getToken();
+
+ uploadInfos = ImageProcessor.getUploadInfos( "asdfasdfasdf", imageData );
+ assertEquals( "Not the right number of blocks", 20, uploadInfos.missingBlocks.size() );
+ for (int i = 0; i < uploadInfos.missingBlocks.size(); i++) {
+ assertEquals(i, uploadInfos.missingBlocks.remove( 0 ).intValue());
+ }
+
+ assertEquals("Wrong token was sent back.", token, uploadInfos.getToken());
+ }
}
diff --git a/src/test/java/org/openslx/imagemaster/ServerTest.java b/src/test/java/org/openslx/imagemaster/ServerTest.java
deleted file mode 100644
index 946b33f..0000000
--- a/src/test/java/org/openslx/imagemaster/ServerTest.java
+++ /dev/null
@@ -1,223 +0,0 @@
-package org.openslx.imagemaster;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.ConnectException;
-import java.net.SocketException;
-import java.nio.ByteBuffer;
-import java.security.InvalidAlgorithmParameterException;
-import java.security.InvalidKeyException;
-import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.SignatureException;
-import java.security.UnrecoverableKeyException;
-import java.security.cert.CertificateException;
-import java.util.UUID;
-
-import javax.net.ssl.KeyManagerFactory;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.TrustManagerFactory;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.net.ftp.FTP;
-import org.apache.commons.net.ftp.FTPReply;
-import org.apache.commons.net.ftp.FTPSClient;
-import org.apache.log4j.Logger;
-import org.apache.thrift.TException;
-import org.apache.thrift.protocol.TBinaryProtocol;
-import org.apache.thrift.protocol.TProtocol;
-import org.apache.thrift.transport.TSocket;
-import org.apache.thrift.transport.TTransport;
-import org.openslx.imagemaster.thrift.iface.FtpCredentials;
-import org.openslx.imagemaster.thrift.iface.ImageData;
-import org.openslx.imagemaster.thrift.iface.ImageServer.Client;
-import org.openslx.imagemaster.thrift.iface.ServerSessionData;
-import org.openslx.imagemaster.thrift.iface.SessionData;
-import org.openslx.imagemaster.thrift.iface.UserInfo;
-import org.openslx.imagemaster.util.AsymMessageVerifier;
-
-
-public class ServerTest extends TestCase
-{
- private static Logger log = Logger.getLogger( ServerTest.class );
-
- @Override
- public void setUp() throws Exception {
- // start the server
-// Thread t = new Thread(new Runnable() {
-//
-// @Override
-// public void run()
-// {
-// App.main( null );
-// }
-// }, "App");
-// t.start();
-// Thread.sleep( 2000 );
- }
-
- public void test() {
- assertTrue(true);
- }
-
-// public void testSomething() 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() );
-//
-// client.getImage( "8fbaf5cb-ebf6-11e3-996b-f5a55bd7273c", "" );
-// }
-
- /**
- * Test the authentication
- *
- * @throws TException
- * @throws IOException
- */
-// public void testAuthentication() throws TException, 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() );
-//
-// BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
-// System.out.print("Enter username: ");
-// String username = reader.readLine();
-// System.out.print("Enter password: ");
-// String password = reader.readLine();
-//
-// SessionData sessionData = client.authenticate( username, password );
-// 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
- * @throws KeyStoreException
- * @throws CertificateException
- * @throws NoSuchAlgorithmException
- * @throws UnrecoverableKeyException
- * @throws SignatureException
- * @throws InvalidKeyException
- * @throws InvalidAlgorithmParameterException
- */
-// public void testServerAuthAndFtpUpload() throws TException, SocketException, IOException, UnrecoverableKeyException, NoSuchAlgorithmException, CertificateException, KeyStoreException, InvalidKeyException, SignatureException, InvalidAlgorithmParameterException
-// {
-// if (true) return;
-//
-// @SuppressWarnings( "unused" )
-// 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 );
-//
-// AsymMessageSign messageSigner = new AsymMessageSign( "ftp", "password", "./config/keystore.jks" );
-// byte[] response = messageSigner.signMessage( stringToEncrypt );
-//
-// System.out.println( "Signed string: " + response );
-// ByteBuffer bBuffer = ByteBuffer.wrap( response );
-//
-// ServerSessionData data = client.serverAuthenticate( "Test Organization", bBuffer );
-// System.out.println( "Authenticated and got sid: '" + data.getSessionId() + "'" );
-//
-// // Create ImageData
-// int version = 1;
-// String imageName = "maschine.vmkd";
-// UUID uuid = UUID.randomUUID();
-// long imageCreateTime = System.currentTimeMillis();
-// long imageUpdateTime = imageCreateTime;
-// String imageOwner = "ns202";
-// String contentOperatingSystem = "win7";
-// boolean statusIsValid = true;
-// boolean statusIsDeleted = false;
-// String imageShortDescrption = "EIN SUPER TOLLES IMAGE!";
-// String imageLongDescription = "Lorem ipsum dolor sit amet.";
-//
-// String fileName = "/home/nils/file_to_upload.bin";
-//
-// ImageData imageData = new ImageData( uuid.toString(), version, imageName,
-// imageCreateTime, imageUpdateTime, imageOwner, contentOperatingSystem,
-// statusIsValid, statusIsDeleted, imageShortDescrption, imageLongDescription, new File(fileName).getTotalSpace() );
-//
-// System.out.println( "Created imageData..." );
-//
-// FtpCredentials ftpCredentials = client.submitImage( data.sessionId, imageData );
-// System.out.println( "Got FTP credentials. User: " + ftpCredentials.username + ", password: " + ftpCredentials.password );
-//
-// FTPSClient FtpClient = new FTPSClient( "SSL", true );
-// System.out.println("Created new ftpsclient...");
-// TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance( KeyManagerFactory.getDefaultAlgorithm() );
-// KeyStore keystore = KeyStore.getInstance( "JKS" );
-// keystore.load( new FileInputStream( new File( "./config/keystore.jks" ) ), "password".toCharArray() );
-// System.out.println("Loaded keystore..");
-// trustManagerFactory.init( keystore );
-// TrustManager trustManager = trustManagerFactory.getTrustManagers()[0];
-// FtpClient.setTrustManager(trustManager);
-//
-// System.out.println("Trying to connect...");
-//
-// String host = "localhost";
-// int port = 2221;
-// String user = ftpCredentials.username;
-// String password = ftpCredentials.password;
-//
-// try {
-// FtpClient.connect( host, port );
-// System.out.println( "Connected to " + host + ":" + port + ". Reply code: " + FtpClient.getReplyCode() );
-// if ( !FTPReply.isPositiveCompletion( FtpClient.getReplyCode() ) ) {
-// throw new ConnectException( "No positive reply code." );
-// }
-// if ( !FtpClient.login( user, password ) ) {
-// throw new ConnectException( "Could not login." );
-// }
-// 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." );
-// FtpClient.noop();
-// } catch (Exception e) {
-// e.printStackTrace();
-// } finally {
-// if ( FtpClient.isConnected() ) {
-// try {
-// FtpClient.logout();
-// FtpClient.disconnect();
-// boolean result = client.finshedUpload( ftpCredentials.username, imageData );
-// System.out.println("Telling server that upload finished: " + result);
-// } catch ( IOException e ) {
-// e.printStackTrace();
-// }
-// }
-// }
-//
-// }
-}