Skip to content

Commit dad4160

Browse files
committed
Unit tests form issue #8.
It test both type of connections, we expect an exception in both cases. Task #8 - Connection to Secure Combox via Socket Combox
1 parent 60e4e19 commit dad4160

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

workspace/popjava/src/junit/localtests/LocalTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import junit.localtests.jobmanager.POPJavaJobManagerLiveConfigurationTest;
1717
import junit.localtests.jvmObject.JVMObjectTest;
1818
import junit.localtests.parameters.ParameterTests;
19+
import junit.localtests.protocols.IncompatibleConnectionsTest;
1920
import junit.localtests.readerWriter.ReaderWriterTest;
2021
import junit.localtests.referencePassing.ReferenceTest;
2122
import junit.localtests.security.CreateKeyStoreTest;
@@ -31,7 +32,7 @@
3132
BigDataTests.class, SubclassingTest.class, ReferenceTest.class, JVMObjectTest.class, NestedPOPCreation.class,
3233
CreateKeyStoreTest.class, MethodAccessTest.class,
3334
POPJavaJobManagerConfigurationTest.class, POPJavaJobManagerLiveConfigurationTest.class,
34-
ProtocolsTests.class, JavaSerializableTest.class})
35+
ProtocolsTests.class, IncompatibleConnectionsTest.class, JavaSerializableTest.class})
3536
public class LocalTests {
3637

3738
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package junit.localtests.protocols;
2+
3+
import java.io.File;
4+
import java.io.IOException;
5+
import org.junit.After;
6+
import org.junit.AfterClass;
7+
import org.junit.Before;
8+
import org.junit.BeforeClass;
9+
import org.junit.Test;
10+
import popjava.PopJava;
11+
import popjava.baseobject.POPAccessPoint;
12+
import popjava.system.POPSystem;
13+
import popjava.util.Configuration;
14+
import popjava.util.Util;
15+
import popjava.util.ssl.KeyStoreCreationOptions;
16+
import popjava.util.ssl.SSLUtils;
17+
18+
/**
19+
*
20+
* @author dosky
21+
*/
22+
public class IncompatibleConnectionsTest {
23+
24+
A socket;
25+
A ssl;
26+
27+
static File keystore;
28+
static File userConfig;
29+
static KeyStoreCreationOptions options;
30+
31+
@BeforeClass
32+
public static void setup() throws IOException {
33+
userConfig = File.createTempFile("popjunit", ".properties");
34+
keystore = new File(String.format("popjunit-%s.jks", Util.generateUUID()));
35+
options = new KeyStoreCreationOptions("myTest", "storepass", "keypass", keystore);
36+
37+
Configuration conf = Configuration.getInstance();
38+
conf.setDebug(true);
39+
40+
SSLUtils.generateKeyStore(options);
41+
conf.setSSLKeyStoreOptions(options);
42+
conf.setUserConfig(userConfig);
43+
44+
conf.store();
45+
}
46+
47+
@AfterClass
48+
public static void cleanup() {
49+
userConfig.deleteOnExit();
50+
keystore.deleteOnExit();
51+
}
52+
53+
@Before
54+
public void before() {
55+
POPSystem.initialize();
56+
socket = PopJava.newActive(A.class, "localhost", new String[]{"socket"});
57+
ssl = PopJava.newActive(A.class, "localhost", new String[]{"ssl"});
58+
}
59+
60+
@After
61+
public void end() {
62+
POPSystem.end();
63+
}
64+
65+
@Test(timeout = 1000, expected = Exception.class)
66+
public void sslToSocket() {
67+
POPAccessPoint socketAP = socket.getAccessPoint();
68+
POPAccessPoint socketAsSSL = new POPAccessPoint(socketAP.toString());
69+
socketAsSSL.get(0).setProtocol("ssl");
70+
71+
System.out.format("From %s to %s\n", socketAP, socketAsSSL);
72+
A shouldThrow = PopJava.newActive(A.class, socketAsSSL);
73+
shouldThrow.sync();
74+
}
75+
76+
@Test(timeout = 1000, expected = Exception.class)
77+
public void socketToSSL() {
78+
POPAccessPoint sslAP = ssl.getAccessPoint();
79+
POPAccessPoint sslAsSocket = new POPAccessPoint(sslAP.toString());
80+
sslAsSocket.get(0).setProtocol("socket");
81+
82+
System.out.format("From %s to %s\n", sslAP, sslAsSocket);
83+
A shouldThrow = PopJava.newActive(A.class, sslAsSocket);
84+
shouldThrow.sync();
85+
}
86+
}

0 commit comments

Comments
 (0)