aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2013-10-08 21:22:43 +0000
committerFlorian Dold <florian.dold@gmail.com>2013-10-08 21:22:43 +0000
commit5b4933f12a3eadedf84e6adf00e1c1ac15924f6d (patch)
tree5824cf1236dbdbca515cc7d1f5f7bce1ee3eba6b /src/test/java/org
parenta8c1c65a00dce604ff829dfe10568cd06c8f8bda (diff)
downloadgnunet-java-5b4933f12a3eadedf84e6adf00e1c1ac15924f6d.tar.gz
gnunet-java-5b4933f12a3eadedf84e6adf00e1c1ac15924f6d.zip
- identity service implemented
- started with arm implementation - removed locking from scheduler - separated TaskConfiguration and TaskIdentifier - implemented proper message stream tokenizer - work on voting
Diffstat (limited to 'src/test/java/org')
-rw-r--r--src/test/java/org/gnunet/identity/IdentityTest.java123
-rw-r--r--src/test/java/org/gnunet/testbed/TestbedTest.java72
-rw-r--r--src/test/java/org/gnunet/util/CryptoECCTest.java8
3 files changed, 143 insertions, 60 deletions
diff --git a/src/test/java/org/gnunet/identity/IdentityTest.java b/src/test/java/org/gnunet/identity/IdentityTest.java
new file mode 100644
index 0000000..cda4e6b
--- /dev/null
+++ b/src/test/java/org/gnunet/identity/IdentityTest.java
@@ -0,0 +1,123 @@
1/*
2 This file is part of GNUnet.
3 (C) 2012, 2013 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 */
20
21package org.gnunet.identity;
22
23
24import org.gnunet.testing.TestingSubsystem;
25import org.gnunet.util.Program;
26import org.gnunet.util.Scheduler;
27import org.gnunet.util.Wrapper;
28import org.junit.Assert;
29import org.junit.Test;
30
31public class IdentityTest {
32 @Test
33 public void test_identity_connect() {
34 final Wrapper<Boolean> reachedEnd = new Wrapper<Boolean>(false);
35 Program.configureLogging("DEBUG");
36 TestingSubsystem ts = new TestingSubsystem("identity");
37
38 final Identity identity = new Identity();
39 identity.connect(ts.getConfiguration(), new IdentityListCallback() {
40 @Override
41 public void onEgoAdd(Identity.Ego ego) {
42 System.out.println("got ego " + ego.getName());
43 }
44
45 @Override
46 public void onEgoDelete(Identity.Ego ego) {
47 // should only happen after end of list,
48 // but we disconnect on end of list
49 Assert.fail();
50 }
51
52 @Override
53 public void onEgoRename(String oldName, Identity.Ego ego) {
54 Assert.fail();
55 }
56
57 @Override
58 public void onListEnd() {
59 System.out.println("got end of list");
60 reachedEnd.set(true);
61 identity.disconnect();
62 }
63 });
64 Scheduler.run();
65 Assert.assertTrue(reachedEnd.get());
66 }
67
68 @Test
69 public void test_identity_create() {
70 final Wrapper<Boolean> created = new Wrapper<Boolean>(false);
71 final Wrapper<Boolean> gotEnd = new Wrapper<Boolean>(false);
72 final Wrapper<Boolean> gotCreated = new Wrapper<Boolean>(false);
73 Program.configureLogging("DEBUG");
74 TestingSubsystem ts = new TestingSubsystem("identity");
75
76 final String myEgoName = "gnunet-java-test-ego";
77
78 final Identity identity = new Identity();
79 identity.connect(ts.getConfiguration(), new IdentityListCallback() {
80 @Override
81 public void onEgoAdd(Identity.Ego ego) {
82 if (created.get() && ego.getName().equals(myEgoName)) {
83 gotCreated.set(true);
84 identity.disconnect();
85 }
86 }
87
88 @Override
89 public void onEgoDelete(Identity.Ego ego) {
90 // should only happen after end of list,
91 // but we disconnect on end of list
92 Assert.fail();
93 }
94
95 @Override
96 public void onEgoRename(String oldName, Identity.Ego ego) {
97 Assert.fail();
98 }
99
100 @Override
101 public void onListEnd() {
102 System.out.println("got end of list");
103 gotEnd.set(true);
104 }
105 });
106 identity.create(myEgoName, new IdentityContinuation() {
107 @Override
108 public void onError(String errorMessage) {
109 Assert.fail(errorMessage);
110 }
111
112 @Override
113 public void onDone() {
114 Assert.assertFalse(created.get());
115 created.set(true);
116 }
117 });
118 Scheduler.run();
119 Assert.assertTrue(created.get());
120 Assert.assertTrue(gotCreated.get());
121 Assert.assertTrue(gotEnd.get());
122 }
123}
diff --git a/src/test/java/org/gnunet/testbed/TestbedTest.java b/src/test/java/org/gnunet/testbed/TestbedTest.java
index 56febde..6a6ed10 100644
--- a/src/test/java/org/gnunet/testbed/TestbedTest.java
+++ b/src/test/java/org/gnunet/testbed/TestbedTest.java
@@ -12,7 +12,7 @@ import org.junit.Test;
12 12
13public class TestbedTest extends TestingFixture { 13public class TestbedTest extends TestingFixture {
14 14
15 @Test(timeout = 1000) 15 @Test(timeout = 10000)
16 public void test_controller_proc() { 16 public void test_controller_proc() {
17 final Wrapper<Boolean> success = new Wrapper<Boolean>(false); 17 final Wrapper<Boolean> success = new Wrapper<Boolean>(false);
18 new Program("-LDEBUG") { 18 new Program("-LDEBUG") {
@@ -38,16 +38,13 @@ public class TestbedTest extends TestingFixture {
38 } 38 }
39 39
40 40
41 @Test(timeout = 1000) 41 @Test(timeout = 10000)
42 public void test_peer_create() { 42 public void test_peer_create() {
43 new Program("-LDEBUG") { 43 new Program("-LDEBUG") {
44 ControllerProc cp; 44 ControllerProc cp;
45 Host h; 45 Host h;
46 Controller c; 46 Controller c;
47 47
48 class CEC extends ControllerEventCallback {
49 }
50
51 class PCB implements PeerCreateCallback { 48 class PCB implements PeerCreateCallback {
52 @Override 49 @Override
53 public void onPeerCreated(Controller.Peer peer) { 50 public void onPeerCreated(Controller.Peer peer) {
@@ -71,7 +68,7 @@ public class TestbedTest extends TestingFixture {
71 @Override 68 @Override
72 public void onStartupSuccess(Configuration cfg) { 69 public void onStartupSuccess(Configuration cfg) {
73 System.out.println("startup success"); 70 System.out.println("startup success");
74 c = new Controller(h, 1 | 2 | 4 | 8 | 32, new CEC()); 71 c = new Controller(h);
75 // FIXME: use config from resource 72 // FIXME: use config from resource
76 c.createPeer(h, getConfiguration(), new PCB()); 73 c.createPeer(h, getConfiguration(), new PCB());
77 } 74 }
@@ -84,16 +81,13 @@ public class TestbedTest extends TestingFixture {
84 }.start(); 81 }.start();
85 } 82 }
86 83
87 @Test(timeout = 1000) 84 @Test(timeout = 10000)
88 public void test_peer_destroy() { 85 public void test_peer_destroy() {
89 new Program("-LDEBUG") { 86 new Program("-LDEBUG") {
90 ControllerProc cp; 87 ControllerProc cp;
91 Host h; 88 Host h;
92 Controller c; 89 Controller c;
93 90
94 class CEC extends ControllerEventCallback {
95 }
96
97 class PCB implements PeerCreateCallback { 91 class PCB implements PeerCreateCallback {
98 @Override 92 @Override
99 public void onPeerCreated(final Controller.Peer peer) { 93 public void onPeerCreated(final Controller.Peer peer) {
@@ -128,7 +122,7 @@ public class TestbedTest extends TestingFixture {
128 @Override 122 @Override
129 public void onStartupSuccess(Configuration cfg) { 123 public void onStartupSuccess(Configuration cfg) {
130 System.out.println("startup success"); 124 System.out.println("startup success");
131 c = new Controller(h, 1 | 2 | 4 | 8 | 32, new CEC()); 125 c = new Controller(h);
132 // FIXME: use config from resource 126 // FIXME: use config from resource
133 c.createPeer(h, getConfiguration(), new PCB()); 127 c.createPeer(h, getConfiguration(), new PCB());
134 } 128 }
@@ -141,7 +135,7 @@ public class TestbedTest extends TestingFixture {
141 }.start(); 135 }.start();
142 } 136 }
143 137
144 @Test(timeout = 5000) 138 @Test(timeout = 10000)
145 public void test_peer_start() { 139 public void test_peer_start() {
146 final Wrapper<Boolean> startSuccessful = new Wrapper<Boolean>(false); 140 final Wrapper<Boolean> startSuccessful = new Wrapper<Boolean>(false);
147 int ret = new Program("-LDEBUG") { 141 int ret = new Program("-LDEBUG") {
@@ -149,9 +143,6 @@ public class TestbedTest extends TestingFixture {
149 Host h; 143 Host h;
150 Controller c; 144 Controller c;
151 145
152 class CEC extends ControllerEventCallback {
153 }
154
155 class MyPeerChurnCallback implements PeerChurnCallback { 146 class MyPeerChurnCallback implements PeerChurnCallback {
156 147
157 @Override 148 @Override
@@ -190,7 +181,7 @@ public class TestbedTest extends TestingFixture {
190 @Override 181 @Override
191 public void onStartupSuccess(Configuration cfg) { 182 public void onStartupSuccess(Configuration cfg) {
192 System.out.println("controller started"); 183 System.out.println("controller started");
193 c = new Controller(h, 1 | 2 | 4 | 8 | 32, new CEC()); 184 c = new Controller(h);
194 // FIXME: use config from resource 185 // FIXME: use config from resource
195 c.createPeer(h, getConfiguration(), new MyPeerCreateCallback()); 186 c.createPeer(h, getConfiguration(), new MyPeerCreateCallback());
196 } 187 }
@@ -205,7 +196,7 @@ public class TestbedTest extends TestingFixture {
205 Assert.assertEquals(0, ret); 196 Assert.assertEquals(0, ret);
206 } 197 }
207 198
208 @Test(timeout = 5000) 199 @Test(timeout = 10000)
209 public void test_peer_stop() { 200 public void test_peer_stop() {
210 final Wrapper<Boolean> startSuccessful = new Wrapper<Boolean>(false); 201 final Wrapper<Boolean> startSuccessful = new Wrapper<Boolean>(false);
211 final Wrapper<Boolean> stopSuccessful = new Wrapper<Boolean>(false); 202 final Wrapper<Boolean> stopSuccessful = new Wrapper<Boolean>(false);
@@ -215,9 +206,6 @@ public class TestbedTest extends TestingFixture {
215 Controller c; 206 Controller c;
216 Controller.Peer p; 207 Controller.Peer p;
217 208
218 class CEC extends ControllerEventCallback {
219 }
220
221 class MyPeerStopCallback implements PeerChurnCallback { 209 class MyPeerStopCallback implements PeerChurnCallback {
222 210
223 @Override 211 @Override
@@ -271,7 +259,7 @@ public class TestbedTest extends TestingFixture {
271 @Override 259 @Override
272 public void onStartupSuccess(Configuration cfg) { 260 public void onStartupSuccess(Configuration cfg) {
273 System.out.println("controller started"); 261 System.out.println("controller started");
274 c = new Controller(h, 1 | 2 | 4 | 8 | 32, new CEC()); 262 c = new Controller(h);
275 // FIXME: use config from resource 263 // FIXME: use config from resource
276 c.createPeer(h, getConfiguration(), new MyPeerCreateCallback()); 264 c.createPeer(h, getConfiguration(), new MyPeerCreateCallback());
277 } 265 }
@@ -287,7 +275,7 @@ public class TestbedTest extends TestingFixture {
287 Assert.assertEquals(0, ret); 275 Assert.assertEquals(0, ret);
288 } 276 }
289 277
290 @Test(timeout = 5000) 278 @Test(timeout = 10000)
291 public void test_peer_stop_destroy() { 279 public void test_peer_stop_destroy() {
292 final Wrapper<Boolean> startSuccessful = new Wrapper<Boolean>(false); 280 final Wrapper<Boolean> startSuccessful = new Wrapper<Boolean>(false);
293 final Wrapper<Boolean> stopSuccessful = new Wrapper<Boolean>(false); 281 final Wrapper<Boolean> stopSuccessful = new Wrapper<Boolean>(false);
@@ -298,9 +286,6 @@ public class TestbedTest extends TestingFixture {
298 Controller c; 286 Controller c;
299 Controller.Peer p; 287 Controller.Peer p;
300 288
301 class CEC extends ControllerEventCallback {
302 }
303
304 class MyPeerDestroyCallback implements OperationCompletionCallback { 289 class MyPeerDestroyCallback implements OperationCompletionCallback {
305 290
306 @Override 291 @Override
@@ -367,7 +352,7 @@ public class TestbedTest extends TestingFixture {
367 @Override 352 @Override
368 public void onStartupSuccess(Configuration cfg) { 353 public void onStartupSuccess(Configuration cfg) {
369 System.out.println("controller started"); 354 System.out.println("controller started");
370 c = new Controller(h, 1 | 2 | 4 | 8 | 32, new CEC()); 355 c = new Controller(h);
371 // FIXME: use config from resource 356 // FIXME: use config from resource
372 c.createPeer(h, getConfiguration(), new MyPeerCreateCallback()); 357 c.createPeer(h, getConfiguration(), new MyPeerCreateCallback());
373 } 358 }
@@ -394,9 +379,6 @@ public class TestbedTest extends TestingFixture {
394 Controller c; 379 Controller c;
395 Controller.Peer p; 380 Controller.Peer p;
396 381
397 class CEC extends ControllerEventCallback {
398 }
399
400 class MyPeerInformationCallback implements PeerInformationCallback { 382 class MyPeerInformationCallback implements PeerInformationCallback {
401 @Override 383 @Override
402 public void onSuccess(PeerIdentity peerIdentity, Configuration configuration) { 384 public void onSuccess(PeerIdentity peerIdentity, Configuration configuration) {
@@ -433,7 +415,7 @@ public class TestbedTest extends TestingFixture {
433 @Override 415 @Override
434 public void onStartupSuccess(Configuration cfg) { 416 public void onStartupSuccess(Configuration cfg) {
435 System.out.println("controller started"); 417 System.out.println("controller started");
436 c = new Controller(h, 1 | 2 | 4 | 8 | 32, new CEC()); 418 c = new Controller(h);
437 // FIXME: use config from resource 419 // FIXME: use config from resource
438 c.createPeer(h, getConfiguration(), new MyPeerCreateCallback()); 420 c.createPeer(h, getConfiguration(), new MyPeerCreateCallback());
439 } 421 }
@@ -449,10 +431,9 @@ public class TestbedTest extends TestingFixture {
449 Assert.assertEquals(0, ret); 431 Assert.assertEquals(0, ret);
450 } 432 }
451 433
452 @Test(timeout = 5000) 434 @Test
453 public void test_peer_reconfigure() { 435 public void test_peer_reconfigure() {
454 final Wrapper<Boolean> startSuccessful = new Wrapper<Boolean>(false); 436 final Wrapper<Boolean> startSuccessful = new Wrapper<Boolean>(false);
455 final Wrapper<Boolean> infoSuccessful = new Wrapper<Boolean>(false);
456 final Wrapper<Boolean> reconfigureSuccessful = new Wrapper<Boolean>(false); 437 final Wrapper<Boolean> reconfigureSuccessful = new Wrapper<Boolean>(false);
457 int ret = new Program("-LDEBUG") { 438 int ret = new Program("-LDEBUG") {
458 ControllerProc cp; 439 ControllerProc cp;
@@ -460,9 +441,6 @@ public class TestbedTest extends TestingFixture {
460 Controller c; 441 Controller c;
461 Controller.Peer p; 442 Controller.Peer p;
462 443
463 class CEC extends ControllerEventCallback {
464 }
465
466 class MyUpdateConfigDoneCallback implements OperationCompletionCallback { 444 class MyUpdateConfigDoneCallback implements OperationCompletionCallback {
467 @Override 445 @Override
468 public void onCompletion() { 446 public void onCompletion() {
@@ -478,30 +456,15 @@ public class TestbedTest extends TestingFixture {
478 } 456 }
479 } 457 }
480 458
481 /*
482 class MyPeerInformationCallback implements PeerInformationCallback {
483 @Override
484 public void onSuccess(PeerIdentity peerIdentity, Configuration configuration) {
485 Assert.assertNotNull(peerIdentity);
486 Assert.assertNotNull(configuration);
487 Assert.assertTrue(configuration.getSections().size() > 0);
488 infoSuccessful.set(true);
489 System.out.println("updating configuration");
490 p.updateConfiguration(cfg, new MyUpdateConfigDoneCallback());
491 }
492 }
493
494 */
495
496 class MyPeerCreateCallback implements PeerCreateCallback { 459 class MyPeerCreateCallback implements PeerCreateCallback {
497 @Override 460 @Override
498 public void onPeerCreated(Controller.Peer peer) { 461 public void onPeerCreated(Controller.Peer peer) {
499 p = peer; 462 p = peer;
500 System.out.println("peer created"); 463 System.out.println("peer created");
501 startSuccessful.set(true); 464 startSuccessful.set(true);
502 //peer.requestInformation(new MyPeerInformationCallback());
503 465
504 Configuration cfg = new Configuration(); 466 Configuration cfg = new Configuration();
467 cfg.setValueNumber("foo", "bar", 42);
505 cfg.setValueString("my-test-section", "my-test-option", "my-test-value"); 468 cfg.setValueString("my-test-section", "my-test-option", "my-test-value");
506 peer.updateConfiguration(cfg, new MyUpdateConfigDoneCallback()); 469 peer.updateConfiguration(cfg, new MyUpdateConfigDoneCallback());
507 } 470 }
@@ -522,7 +485,7 @@ public class TestbedTest extends TestingFixture {
522 @Override 485 @Override
523 public void onStartupSuccess(Configuration cfg) { 486 public void onStartupSuccess(Configuration cfg) {
524 System.out.println("controller started"); 487 System.out.println("controller started");
525 c = new Controller(h, 1 | 2 | 4 | 8 | 32, new CEC()); 488 c = new Controller(h);
526 // FIXME: use config from resource 489 // FIXME: use config from resource
527 c.createPeer(h, configuration, new MyPeerCreateCallback()); 490 c.createPeer(h, configuration, new MyPeerCreateCallback());
528 } 491 }
@@ -549,9 +512,6 @@ public class TestbedTest extends TestingFixture {
549 Controller.Peer p1; 512 Controller.Peer p1;
550 int peersStarted = 0; 513 int peersStarted = 0;
551 514
552 class CEC extends ControllerEventCallback {
553 }
554
555 class MyConnectCompleteCallback implements OperationCompletionCallback { 515 class MyConnectCompleteCallback implements OperationCompletionCallback {
556 516
557 @Override 517 @Override
@@ -620,7 +580,7 @@ public class TestbedTest extends TestingFixture {
620 @Override 580 @Override
621 public void onStartupSuccess(Configuration cfg) { 581 public void onStartupSuccess(Configuration cfg) {
622 System.out.println("controller started"); 582 System.out.println("controller started");
623 c = new Controller(h, 1 | 2 | 4 | 8 | 32, new CEC()); 583 c = new Controller(h);
624 // FIXME: use config from resource 584 // FIXME: use config from resource
625 c.createPeer(h, getConfiguration(), new MyPeerCreateCallback(0)); 585 c.createPeer(h, getConfiguration(), new MyPeerCreateCallback(0));
626 c.createPeer(h, getConfiguration(), new MyPeerCreateCallback(1)); 586 c.createPeer(h, getConfiguration(), new MyPeerCreateCallback(1));
diff --git a/src/test/java/org/gnunet/util/CryptoECCTest.java b/src/test/java/org/gnunet/util/CryptoECCTest.java
index c4c85d2..1dda545 100644
--- a/src/test/java/org/gnunet/util/CryptoECCTest.java
+++ b/src/test/java/org/gnunet/util/CryptoECCTest.java
@@ -21,7 +21,7 @@ public class CryptoECCTest {
21 CryptoECC.PrivateKey privateKey = new CryptoECC.PrivateKey(); 21 CryptoECC.PrivateKey privateKey = new CryptoECC.PrivateKey();
22 privateKey.d = new byte[32]; 22 privateKey.d = new byte[32];
23 r.nextBytes(privateKey.d); 23 r.nextBytes(privateKey.d);
24 CryptoECC.PublicKey publicKey = CryptoECC.computePublicKey(privateKey); 24 CryptoECC.PublicSignKey publicKey = CryptoECC.computePublicKey(privateKey);
25 System.out.println("gen"); 25 System.out.println("gen");
26 CryptoECC.Signature sig = CryptoECC.sign(msg, privateKey, publicKey); 26 CryptoECC.Signature sig = CryptoECC.sign(msg, privateKey, publicKey);
27 System.out.println("sign"); 27 System.out.println("sign");
@@ -44,7 +44,7 @@ public class CryptoECCTest {
44 CryptoECC.PrivateKey privateKey = new CryptoECC.PrivateKey(); 44 CryptoECC.PrivateKey privateKey = new CryptoECC.PrivateKey();
45 privateKey.d = new byte[32]; 45 privateKey.d = new byte[32];
46 r.nextBytes(privateKey.d); 46 r.nextBytes(privateKey.d);
47 CryptoECC.PublicKey publicKey = CryptoECC.computePublicKey(privateKey); 47 CryptoECC.PublicSignKey publicKey = CryptoECC.computePublicKey(privateKey);
48 System.out.println("gen"); 48 System.out.println("gen");
49 CryptoECC.Signature sig = CryptoECC.sign(msg, privateKey, publicKey); 49 CryptoECC.Signature sig = CryptoECC.sign(msg, privateKey, publicKey);
50 System.out.println("sign"); 50 System.out.println("sign");
@@ -66,12 +66,12 @@ public class CryptoECCTest {
66 CryptoECC.PrivateKey privateAlice = new CryptoECC.PrivateKey(); 66 CryptoECC.PrivateKey privateAlice = new CryptoECC.PrivateKey();
67 privateAlice.d = new byte[32]; 67 privateAlice.d = new byte[32];
68 r.nextBytes(privateAlice.d); 68 r.nextBytes(privateAlice.d);
69 CryptoECC.PublicKey publicAlice = CryptoECC.computePublicKey(privateAlice); 69 CryptoECC.PublicSignKey publicAlice = CryptoECC.computePublicKey(privateAlice);
70 70
71 CryptoECC.PrivateKey privateBob = new CryptoECC.PrivateKey(); 71 CryptoECC.PrivateKey privateBob = new CryptoECC.PrivateKey();
72 privateBob.d = new byte[32]; 72 privateBob.d = new byte[32];
73 r.nextBytes(privateBob.d); 73 r.nextBytes(privateBob.d);
74 CryptoECC.PublicKey publicBob = CryptoECC.computePublicKey(privateBob); 74 CryptoECC.PublicSignKey publicBob = CryptoECC.computePublicKey(privateBob);
75 75
76 HashCode ssAlice = CryptoECC.ecdh(privateAlice, publicBob); 76 HashCode ssAlice = CryptoECC.ecdh(privateAlice, publicBob);
77 HashCode ssBob = CryptoECC.ecdh(privateBob, publicAlice); 77 HashCode ssBob = CryptoECC.ecdh(privateBob, publicAlice);