summaryrefslogtreecommitdiffstats
path: root/src/test/java/org/openslx/imagemaster/AppTest.java
blob: 0add740f09b9dc46b702760786651c25674e404d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package org.openslx.imagemaster;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

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.apache.thrift.transport.TTransportException;
import org.openslx.imagemaster.thrift.iface.ImageServer.Client;
import org.openslx.imagemaster.thrift.iface.SessionData;
import org.openslx.imagemaster.thrift.iface.UserInfo;

/**
 * Unit test for simple App.
 */
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
     */
    public void testAuthentication() {
    	TTransport transport = new TSocket("localhost", 9090);
    	try {
			transport.open();
		} catch (TTransportException e) {
			assertTrue("Could not connect", false);
		}
    	
    	TProtocol protocol = new TBinaryProtocol(transport);
    	Client client = new Client(protocol);
    	
    	try {
			assertTrue("Could not ping server", client.ping());
		} catch (TException e) {
			assertTrue("Could not ping server", false);
		}
    	try {
    		SessionData sessionData = client.authenticate("ns202", "xxxxxxxxxxx");
			UserInfo userInfo = client.getUserFromToken(sessionData.getAuthToken());
			System.out.println("User info: " + userInfo);
			System.out.println("Server address from MySQL: " + sessionData.serverAddress);
		} catch (TException e) {
			e.printStackTrace();
			assertTrue("Could not login", false);
		}
    }
}