[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [onionoo/master] Simplify servlet unit tests.
commit ae91b32a60f3521ddfbc2090cc7f8c6c2a8fea74
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Mon Jul 21 11:18:24 2014 +0200
Simplify servlet unit tests.
---
.../torproject/onionoo/ResourceServletTest.java | 166 ++++++++++++--------
1 file changed, 100 insertions(+), 66 deletions(-)
diff --git a/test/org/torproject/onionoo/ResourceServletTest.java b/test/org/torproject/onionoo/ResourceServletTest.java
index ff3ba35..f8d3281 100644
--- a/test/org/torproject/onionoo/ResourceServletTest.java
+++ b/test/org/torproject/onionoo/ResourceServletTest.java
@@ -6,17 +6,18 @@ package org.torproject.onionoo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
+import java.util.TreeSet;
import org.junit.Before;
import org.junit.Test;
@@ -30,7 +31,7 @@ import com.google.gson.Gson;
* which tests servlet specifics. */
public class ResourceServletTest {
- private SortedMap<String, String> relays, bridges;
+ private SortedMap<String, NodeStatus> relays, bridges;
private long currentTimeMillis = DateTimeHelper.parse(
"2013-04-24 12:22:22");
@@ -99,49 +100,83 @@ public class ResourceServletTest {
@Before
public void createSampleRelaysAndBridges() {
- this.relays = new TreeMap<String, String>();
+ NodeStatus relayTorkaZ = new NodeStatus(true, "TorkaZ",
+ "000C5F55BD4814B917CC474BD537F1A3B33CCE2A", "62.216.201.221",
+ new TreeSet<String>(), new TreeSet<String>(Arrays.asList(
+ new String[] { "62.216.201.222", "62.216.201.223" })),
+ DateTimeHelper.parse("2013-04-19 05:00:00"), 9001, 0,
+ new TreeSet<String>(Arrays.asList(new String[] { "Running",
+ "Valid" })), 20L, "de", null, -1L, "reject", "1-65535",
+ DateTimeHelper.parse("2013-04-18 05:00:00"),
+ DateTimeHelper.parse("2013-04-19 05:00:00"), "AS8767",
+ "torkaz <klaus dot zufall at gmx dot de> "
+ + "<fb-token:np5_g_83jmf=>", null, new TreeSet<String>(
+ Arrays.asList(new String[] {
+ "001C13B3A55A71B977CA65EC85539D79C653A3FC",
+ "0025C136C1F3A9EEFE2AE3F918F03BFA21B5070B" })));
+ NodeStatus relayFerrari458 = new NodeStatus(true, "Ferrari458",
+ "001C13B3A55A71B977CA65EC85539D79C653A3FC", "68.38.171.200",
+ new TreeSet<String>(Arrays.asList(new String[] {
+ "[2001:4f8:3:2e::51]:9001" })), new TreeSet<String>(),
+ DateTimeHelper.parse("2013-04-24 12:00:00"), 9001, 9030,
+ new TreeSet<String>(Arrays.asList(new String[] { "Fast", "Named",
+ "Running", "V2Dir", "Valid" })), 1140L, "us",
+ "c-68-38-171-200.hsd1.pa.comcast.net", 1366805763009L, "reject",
+ "1-65535", DateTimeHelper.parse("2013-02-12 16:00:00"),
+ DateTimeHelper.parse("2013-02-26 18:00:00"), "AS7922", null, null,
+ new TreeSet<String>(Arrays.asList(new String[] {
+ "000C5F55BD4814B917CC474BD537F1A3B33CCE2A" })));
+ relayFerrari458.setRunning(true);
+ NodeStatus relayTimMayTribute = new NodeStatus(true, "TimMayTribute",
+ "0025C136C1F3A9EEFE2AE3F918F03BFA21B5070B", "89.69.68.246",
+ new TreeSet<String>(), new TreeSet<String>(),
+ DateTimeHelper.parse("2013-04-22 20:00:00"), 9001, 9030,
+ new TreeSet<String>(Arrays.asList(new String[] { "Fast",
+ "Running", "Unnamed", "V2Dir", "Valid" })), 63L, "a1", null, -1L,
+ "reject", "1-65535", DateTimeHelper.parse("2013-04-16 18:00:00"),
+ DateTimeHelper.parse("2013-04-16 18:00:00"), "AS6830",
+ "1024D/51E2A1C7 steven j. murdoch "
+ + "<tor+steven.murdoch@xxxxxxxxxxxx> <fb-token:5sr_k_zs2wm=>",
+ null, new TreeSet<String>());
+ NodeStatus bridgeec2bridgercc7f31fe = new NodeStatus(false,
+ "ec2bridgercc7f31fe", "0000831B236DFF73D409AD17B40E2A728A53994F",
+ "10.199.7.176", new TreeSet<String>(), new TreeSet<String>(),
+ DateTimeHelper.parse("2013-04-21 18:07:03"), 443, 0,
+ new TreeSet<String>(Arrays.asList(new String[] { "Valid" })), -1L,
+ "??", null, -1L, null, null,
+ DateTimeHelper.parse("2013-04-20 15:37:04"), -1L, null, null,
+ null, null);
+ NodeStatus bridgeUnnamed = new NodeStatus(false, "Unnamed",
+ "0002D9BDBBC230BD9C78FF502A16E0033EF87E0C", "10.0.52.84",
+ new TreeSet<String>(), new TreeSet<String>(),
+ DateTimeHelper.parse("2013-04-20 17:37:04"), 443, 0,
+ new TreeSet<String>(Arrays.asList(new String[] { "Valid" })), -1L,
+ "??", null, -1L, null, null,
+ DateTimeHelper.parse("2013-04-14 07:07:05"), -1L, null, null,
+ null, null);
+ NodeStatus bridgegummy = new NodeStatus(false, "gummy",
+ "1FEDE50ED8DBA1DD9F9165F78C8131E4A44AB756", "10.63.169.98",
+ new TreeSet<String>(), new TreeSet<String>(),
+ DateTimeHelper.parse("2013-04-24 01:07:04"), 9001, 0,
+ new TreeSet<String>(Arrays.asList(new String[] { "Running",
+ "Valid" })), -1L, "??", null, -1L, null, null,
+ DateTimeHelper.parse("2013-01-16 21:07:04"), -1L, null, null,
+ null, null);
+ bridgegummy.setRunning(true);
+ this.relays = new TreeMap<String, NodeStatus>();
this.relays.put("000C5F55BD4814B917CC474BD537F1A3B33CCE2A",
- "r\tTorkaZ\t000C5F55BD4814B917CC474BD537F1A3B33CCE2A\t"
- + "62.216.201.221;;62.216.201.222+62.216.201.223\t"
- + "2013-04-19\t05:00:00\t9001\t0\tRunning,Valid\t20\tde\tnull\t"
- + "-1\treject\t1-65535\t2013-04-18\t05:00:00\t"
- + "2013-04-19\t05:00:00\tAS8767\ttorkaz <klaus dot zufall at "
- + "gmx dot de> <fb-token:np5_g_83jmf=>\tnull\t"
- + "001C13B3A55A71B977CA65EC85539D79C653A3FC;"
- + "0025C136C1F3A9EEFE2AE3F918F03BFA21B5070B");
+ relayTorkaZ);
this.relays.put("001C13B3A55A71B977CA65EC85539D79C653A3FC",
- "r\tFerrari458\t001C13B3A55A71B977CA65EC85539D79C653A3FC\t"
- + "68.38.171.200;[2001:4f8:3:2e::51]:9001;\t"
- + "2013-04-24\t12:00:00\t9001\t9030\t"
- + "Fast,Named,Running,V2Dir,Valid\t1140\tus\t"
- + "c-68-38-171-200.hsd1.pa.comcast.net\t1366805763009\treject\t"
- + "1-65535\t2013-02-12\t16:00:00\t2013-02-26\t18:00:00\t"
- + "AS7922\tnull\tnull\t000C5F55BD4814B917CC474BD537F1A3B33CCE2A");
+ relayFerrari458);
this.relays.put("0025C136C1F3A9EEFE2AE3F918F03BFA21B5070B",
- "r\tTimMayTribute\t0025C136C1F3A9EEFE2AE3F918F03BFA21B5070B\t"
- + "89.69.68.246;;\t2013-04-22\t20:00:00\t9001\t9030\t"
- + "Fast,Running,Unnamed,V2Dir,Valid\t63\ta1\tnull\t-1\treject\t"
- + "1-65535\t2013-04-16\t18:00:00\t2013-04-16\t18:00:00\t"
- + "AS6830\t1024D/51E2A1C7 steven j. murdoch "
- + "<tor+steven.murdoch@xxxxxxxxxxxx> <fb-token:5sr_k_zs2wm=>\t"
- + "null\tnull");
- this.bridges = new TreeMap<String, String>();
+ relayTimMayTribute);
+ this.bridges = new TreeMap<String, NodeStatus>();
this.bridges.put("0000831B236DFF73D409AD17B40E2A728A53994F",
- "b\tec2bridgercc7f31fe\t"
- + "0000831B236DFF73D409AD17B40E2A728A53994F\t10.199.7.176;;\t"
- + "2013-04-21\t18:07:03\t443\t0\tValid\t-1\t??\tnull\t-1\t"
- + "null\tnull\t2013-04-20\t15:37:04\tnull\tnull\tnull\tnull\t"
- + "null\tnull");
+ bridgeec2bridgercc7f31fe);
this.bridges.put("0002D9BDBBC230BD9C78FF502A16E0033EF87E0C",
- "b\tUnnamed\t0002D9BDBBC230BD9C78FF502A16E0033EF87E0C\t"
- + "10.0.52.84;;\t2013-04-20\t17:37:04\t443\t0\tValid\t-1\t??\t"
- + "null\t-1\tnull\tnull\t2013-04-14\t07:07:05\tnull\tnull\tnull\t"
- + "null\tnull\tnull");
+ bridgeUnnamed);
this.bridges.put("1FEDE50ED8DBA1DD9F9165F78C8131E4A44AB756",
- "b\tgummy\t1FEDE50ED8DBA1DD9F9165F78C8131E4A44AB756\t"
- + "10.63.169.98;;\t2013-04-24\t01:07:04\t9001\t0\tRunning,Valid\t"
- + "-1\t??\tnull\t-1\tnull\tnull\t2013-01-16\t21:07:04\tnull\t"
- + "null\tnull\tnull\tnull\tnull");
+ bridgegummy);
}
private void runTest(String requestURI,
@@ -168,13 +203,11 @@ public class ResourceServletTest {
updateStatus.setDocumentString(String.valueOf(
this.currentTimeMillis));
documentStore.addDocument(updateStatus, null);
- for (Map.Entry<String, String> e : relays.entrySet()) {
- documentStore.addDocument(NodeStatus.fromString(e.getValue()),
- e.getKey());
+ for (Map.Entry<String, NodeStatus> e : relays.entrySet()) {
+ documentStore.addDocument(e.getValue(), e.getKey());
}
- for (Map.Entry<String, String> e : bridges.entrySet()) {
- documentStore.addDocument(NodeStatus.fromString(e.getValue()),
- e.getKey());
+ for (Map.Entry<String, NodeStatus> e : bridges.entrySet()) {
+ documentStore.addDocument(e.getValue(), e.getKey());
}
ApplicationFactory.setDocumentStore(documentStore);
}
@@ -286,38 +319,39 @@ public class ResourceServletTest {
@Test()
public void testValidSummaryRelay() throws IOException {
- this.relays.clear();
- this.relays.put("000C5F55BD4814B917CC474BD537F1A3B33CCE2A",
- "r TorkaZ 000C5F55BD4814B917CC474BD537F1A3B33CCE2A "
- + "62.216.201.221;; 2013-04-19 05:00:00 9001 0 Running,Valid 20 "
- + "de null -1 reject 1-65535 2013-04-18 05:00:00 2013-04-19 "
- + "05:00:00 AS8767 null null null");
this.runTest("/summary", null);
- assertEquals("2013-04-19 05:00:00",
+ assertEquals("2013-04-24 12:00:00",
this.summaryDocument.relays_published);
- assertEquals(1, this.summaryDocument.relays.length);
- RelaySummary relay = this.summaryDocument.relays[0];
+ assertEquals(3, this.summaryDocument.relays.length);
+ RelaySummary relay = null;
+ for (RelaySummary r : this.summaryDocument.relays) {
+ if (r.f.equals("000C5F55BD4814B917CC474BD537F1A3B33CCE2A")) {
+ relay = r;
+ break;
+ }
+ }
+ assertNotNull(relay);
assertEquals("TorkaZ", relay.n);
- assertEquals("000C5F55BD4814B917CC474BD537F1A3B33CCE2A", relay.f);
- assertEquals(1, relay.a.length);
+ assertEquals(3, relay.a.length);
assertEquals("62.216.201.221", relay.a[0]);
- assertTrue(relay.r);
+ assertFalse(relay.r);
}
@Test()
public void testValidSummaryBridge() {
- this.bridges.clear();
- this.bridges.put("0000831B236DFF73D409AD17B40E2A728A53994F",
- "b ec2bridgercc7f31fe 0000831B236DFF73D409AD17B40E2A728A53994F "
- + "10.199.7.176;; 2013-04-21 18:07:03 443 0 Valid -1 ?? null -1 "
- + "null null 2013-04-20 15:37:04 null null null null null null");
this.runTest("/summary", null);
- assertEquals("2013-04-21 18:07:03",
+ assertEquals("2013-04-24 01:07:04",
this.summaryDocument.bridges_published);
- assertEquals(1, this.summaryDocument.bridges.length);
- BridgeSummary bridge = this.summaryDocument.bridges[0];
+ assertEquals(3, this.summaryDocument.bridges.length);
+ BridgeSummary bridge = null;
+ for (BridgeSummary b : this.summaryDocument.bridges) {
+ if (b.h.equals("0000831B236DFF73D409AD17B40E2A728A53994F")) {
+ bridge = b;
+ break;
+ }
+ }
+ assertNotNull(bridge);
assertEquals("ec2bridgercc7f31fe", bridge.n);
- assertEquals("0000831B236DFF73D409AD17B40E2A728A53994F", bridge.h);
assertFalse(bridge.r);
}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits