commit 9b02db9e2011786e7f1303dc83306912e867c4ca Author: iwakeh iwakeh@torproject.org Date: Tue Nov 15 17:40:26 2016 +0100
Implements task-20668 and made all tests checkstyle compliant. Responded to 199 checkstyle complaints; adapted copyright; added diamond operator here and there. --- .../onionoo/docs/BandwidthStatusTest.java | 17 ++- .../onionoo/docs/DummyDocumentStore.java | 24 +++- .../torproject/onionoo/docs/NodeStatusTest.java | 25 ++-- .../onionoo/docs/SummaryDocumentTest.java | 7 +- .../torproject/onionoo/docs/UptimeStatusTest.java | 6 +- .../onionoo/server/PerformanceMetricsTest.java | 47 ++++--- .../onionoo/server/ResourceServletTest.java | 105 +++++++++------ .../onionoo/updater/DummyBridgeStatus.java | 9 +- .../torproject/onionoo/updater/DummyConsensus.java | 11 +- .../onionoo/updater/DummyDescriptorSource.java | 38 +++--- .../onionoo/updater/DummyStatusEntry.java | 6 +- .../onionoo/updater/LookupServiceTest.java | 144 +++++++++++---------- .../onionoo/updater/UptimeStatusUpdaterTest.java | 3 +- .../org/torproject/onionoo/util/DummyTime.java | 5 +- .../onionoo/writer/UptimeDocumentWriterTest.java | 8 +- src/test/resources/metrics_checks.xml | 2 +- 16 files changed, 273 insertions(+), 184 deletions(-)
diff --git a/src/test/java/org/torproject/onionoo/docs/BandwidthStatusTest.java b/src/test/java/org/torproject/onionoo/docs/BandwidthStatusTest.java index 432f5d7..84bd116 100644 --- a/src/test/java/org/torproject/onionoo/docs/BandwidthStatusTest.java +++ b/src/test/java/org/torproject/onionoo/docs/BandwidthStatusTest.java @@ -1,5 +1,6 @@ -/* Copyright 2014 The Tor Project +/* Copyright 2014--2016 The Tor Project * See LICENSE for licensing information */ + package org.torproject.onionoo.docs;
import static org.junit.Assert.assertEquals; @@ -40,8 +41,8 @@ public class BandwidthStatusTest { this.historyEndMillis = DateTimeHelper.parse(parts[1] + " " + parts[2]); this.intervalLength = Long.parseLong(parts[3].substring(1)); - long intervalEndMillis = this.historyEndMillis, - intervalLengthMillis = this.intervalLength * 1000L; + long intervalEndMillis = this.historyEndMillis; + long intervalLengthMillis = this.intervalLength * 1000L; String[] valueStrings = parts[5].split(","); for (int i = valueStrings.length - 1; i >= 0; i--) { this.bandwidthValues.put(intervalEndMillis, @@ -49,20 +50,28 @@ public class BandwidthStatusTest { intervalEndMillis -= intervalLengthMillis; } } + private String line; + public String getLine() { return this.line; } + private long historyEndMillis; + public long getHistoryEndMillis() { return this.historyEndMillis; } + private long intervalLength; + public long getIntervalLength() { return this.intervalLength; } + private SortedMap<Long, Long> bandwidthValues = - new TreeMap<Long, Long>(); + new TreeMap<>(); + public SortedMap<Long, Long> getBandwidthValues() { return this.bandwidthValues; } diff --git a/src/test/java/org/torproject/onionoo/docs/DummyDocumentStore.java b/src/test/java/org/torproject/onionoo/docs/DummyDocumentStore.java index 34cd309..bf4acb0 100644 --- a/src/test/java/org/torproject/onionoo/docs/DummyDocumentStore.java +++ b/src/test/java/org/torproject/onionoo/docs/DummyDocumentStore.java @@ -1,3 +1,6 @@ +/* Copyright 2015--2016 The Tor Project + * See LICENSE for licensing information */ + package org.torproject.onionoo.docs;
import java.util.HashMap; @@ -10,8 +13,7 @@ import java.util.TreeSet; public class DummyDocumentStore extends DocumentStore {
private Map<Class<? extends Document>, SortedMap<String, Document>> - storedDocuments = new HashMap<Class<? extends Document>, - SortedMap<String, Document>>(); + storedDocuments = new HashMap<>();
private static final String FINGERPRINT_NULL = "";
@@ -32,8 +34,8 @@ public class DummyDocumentStore extends DocumentStore {
public <T extends Document> T getDocument(Class<T> documentType, String fingerprint) { - return documentType.cast(this.getStoredDocumentsByClass(documentType). - get(fingerprint == null ? FINGERPRINT_NULL : fingerprint)); + return documentType.cast(this.getStoredDocumentsByClass(documentType) + .get(fingerprint == null ? FINGERPRINT_NULL : fingerprint)); }
public void flushDocumentCache() { @@ -46,15 +48,18 @@ public class DummyDocumentStore extends DocumentStore { }
private int performedListOperations = 0; + public int getPerformedListOperations() { return this.performedListOperations; }
+ @SuppressWarnings("JavadocMethod") public <T extends Document> SortedSet<String> list( Class<T> documentType, long modifiedAfter) { return this.list(documentType); }
+ @SuppressWarnings("JavadocMethod") public <T extends Document> SortedSet<String> list( Class<T> documentType) { this.performedListOperations++; @@ -65,6 +70,8 @@ public class DummyDocumentStore extends DocumentStore { }
private int performedRemoveOperations = 0; + + @SuppressWarnings("JavadocMethod") public int getPerformedRemoveOperations() { return this.performedRemoveOperations; } @@ -73,6 +80,7 @@ public class DummyDocumentStore extends DocumentStore { return this.remove(documentType, null); }
+ @SuppressWarnings("JavadocMethod") public <T extends Document> boolean remove(Class<T> documentType, String fingerprint) { this.performedRemoveOperations++; @@ -81,6 +89,7 @@ public class DummyDocumentStore extends DocumentStore { }
private int performedRetrieveOperations = 0; + public int getPerformedRetrieveOperations() { return this.performedRetrieveOperations; } @@ -90,14 +99,16 @@ public class DummyDocumentStore extends DocumentStore { return this.retrieve(documentType, parse, null); }
+ @SuppressWarnings("JavadocMethod") public <T extends Document> T retrieve(Class<T> documentType, boolean parse, String fingerprint) { this.performedRetrieveOperations++; - return documentType.cast(this.getStoredDocumentsByClass(documentType). - get(fingerprint == null ? FINGERPRINT_NULL : fingerprint)); + return documentType.cast(this.getStoredDocumentsByClass(documentType) + .get(fingerprint == null ? FINGERPRINT_NULL : fingerprint)); }
private int performedStoreOperations = 0; + public int getPerformedStoreOperations() { return this.performedStoreOperations; } @@ -106,6 +117,7 @@ public class DummyDocumentStore extends DocumentStore { return this.store(document, null); }
+ @SuppressWarnings("JavadocMethod") public <T extends Document> boolean store(T document, String fingerprint) { this.performedStoreOperations++; diff --git a/src/test/java/org/torproject/onionoo/docs/NodeStatusTest.java b/src/test/java/org/torproject/onionoo/docs/NodeStatusTest.java index f001ea1..f00ce0a 100644 --- a/src/test/java/org/torproject/onionoo/docs/NodeStatusTest.java +++ b/src/test/java/org/torproject/onionoo/docs/NodeStatusTest.java @@ -1,3 +1,6 @@ +/* Copyright 2015--2016 The Tor Project + * See LICENSE for licensing information */ + package org.torproject.onionoo.docs;
import static org.junit.Assert.assertEquals; @@ -41,15 +44,15 @@ public class NodeStatusTest { deserialized.getEffectiveFamily()); assertEquals("Extended families don't match", extendedFamily, deserialized.getExtendedFamily()); - } + }
- private final String A = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", - B = "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", - C = "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC", - D = "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD", - E = "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE", - F = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", - N = "nickname"; + private static final String A = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; + private static final String B = "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"; + private static final String C = "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"; + private static final String D = "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"; + private static final String E = "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"; + private static final String F = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; + private static final String NICK = "nickname";
@Test public void testFamiliesEmpty() { @@ -88,13 +91,13 @@ public class NodeStatusTest { * with this relay. It's a valid case, because B can be in a mutual * family relationship with A. */ assertFamiliesCanBeDeSerialized( - new String[] { A, B }, new String[] { A }, new String[] { A, B }); + new String[] { A, B }, new String[] { A }, new String[] { A, B}); }
@Test public void testFamiliesOneNotMutualOneMutualOneIndirect() { assertFamiliesCanBeDeSerialized( - new String[] { A, B }, new String[] { B }, new String[] { B, C }); + new String[] { A, B }, new String[] { B }, new String[] { B, C}); }
@Test @@ -107,6 +110,6 @@ public class NodeStatusTest { @Test public void testFamiliesNickname() { assertFamiliesCanBeDeSerialized( - new String[] { N }, new String[] {}, new String[] {}); + new String[] { NICK }, new String[] {}, new String[] {}); } } diff --git a/src/test/java/org/torproject/onionoo/docs/SummaryDocumentTest.java b/src/test/java/org/torproject/onionoo/docs/SummaryDocumentTest.java index 99ae0c5..1ee150f 100644 --- a/src/test/java/org/torproject/onionoo/docs/SummaryDocumentTest.java +++ b/src/test/java/org/torproject/onionoo/docs/SummaryDocumentTest.java @@ -1,5 +1,6 @@ /* Copyright 2015--2016 The Tor Project * See LICENSE for licensing information */ + package org.torproject.onionoo.docs;
import static org.junit.Assert.assertArrayEquals; @@ -16,14 +17,14 @@ public class SummaryDocumentTest { return new SummaryDocument(true, "TorkaZ", "000C5F55BD4814B917CC474BD537F1A3B33CCE2A", Arrays.asList( new String[] { "62.216.201.221", "62.216.201.222", - "62.216.201.223" }), DateTimeHelper.parse("2013-04-19 05:00:00"), + "62.216.201.223" }), DateTimeHelper.parse("2013-04-19 05:00:00"), false, new TreeSet<String>(Arrays.asList(new String[] { "Running", - "Valid" })), 20L, "de", + "Valid" })), 20L, "de", DateTimeHelper.parse("2013-04-18 05:00:00"), "AS8767", "torkaz <klaus dot zufall at gmx dot de> " + "fb-token:np5_g_83jmf=", new TreeSet<String>(Arrays.asList( new String[] { "001C13B3A55A71B977CA65EC85539D79C653A3FC", - "0025C136C1F3A9EEFE2AE3F918F03BFA21B5070B" })), + "0025C136C1F3A9EEFE2AE3F918F03BFA21B5070B" })), new TreeSet<String>(Arrays.asList( new String[] { "001C13B3A55A71B977CA65EC85539D79C653A3FC" }))); } diff --git a/src/test/java/org/torproject/onionoo/docs/UptimeStatusTest.java b/src/test/java/org/torproject/onionoo/docs/UptimeStatusTest.java index 44da144..1a8066d 100644 --- a/src/test/java/org/torproject/onionoo/docs/UptimeStatusTest.java +++ b/src/test/java/org/torproject/onionoo/docs/UptimeStatusTest.java @@ -1,5 +1,6 @@ -/* Copyright 2014 The Tor Project +/* Copyright 2014--2016 The Tor Project * See LICENSE for licensing information */ + package org.torproject.onionoo.docs;
import static org.junit.Assert.assertEquals; @@ -257,8 +258,7 @@ public class UptimeStatusTest { }
private static final SortedSet<String> RUNNING_VALID_FLAGS = - new TreeSet<String>(Arrays.asList(new String[] { "Running", - "Valid" })); + new TreeSet<>(Arrays.asList(new String[] { "Running", "Valid" }));
@Test() public void testDontCompressDifferentFlags() { diff --git a/src/test/java/org/torproject/onionoo/server/PerformanceMetricsTest.java b/src/test/java/org/torproject/onionoo/server/PerformanceMetricsTest.java index 7a6614e..c2c781b 100644 --- a/src/test/java/org/torproject/onionoo/server/PerformanceMetricsTest.java +++ b/src/test/java/org/torproject/onionoo/server/PerformanceMetricsTest.java @@ -1,5 +1,6 @@ -/* Copyright 2014 The Tor Project +/* Copyright 2014--2016 The Tor Project * See LICENSE for licensing information */ + package org.torproject.onionoo.server;
import static org.junit.Assert.assertEquals; @@ -10,39 +11,39 @@ public class PerformanceMetricsTest {
@Test public void testCounterZero() { - Counter c = new Counter(); - assertEquals("0", c.toString()); + Counter count = new Counter(); + assertEquals("0", count.toString()); }
@Test public void testCounterClear() { - Counter c = new Counter(); - c.increment(); - c.clear(); - assertEquals("0", c.toString()); + Counter count = new Counter(); + count.increment(); + count.clear(); + assertEquals("0", count.toString()); }
@Test public void testCounterOne() { - Counter c = new Counter(); - c.increment(); - assertEquals("1", c.toString()); + Counter count = new Counter(); + count.increment(); + assertEquals("1", count.toString()); }
@Test public void testCounterTwo() { - Counter c = new Counter(); - c.increment(); - c.increment(); - assertEquals("2", c.toString()); + Counter count = new Counter(); + count.increment(); + count.increment(); + assertEquals("2", count.toString()); }
@Test public void testCounterOverflow() { - Counter c = new Counter(); - c.value = Integer.MAX_VALUE; - c.increment(); - assertEquals(String.valueOf(Integer.MIN_VALUE), c.toString()); + Counter count = new Counter(); + count.value = Integer.MAX_VALUE; + count.increment(); + assertEquals(String.valueOf(Integer.MIN_VALUE), count.toString()); }
@Test @@ -84,7 +85,7 @@ public class PerformanceMetricsTest { }
@Test - public void testMostFrequentStringABCD() { + public void testMostFrequentStringAbcd() { MostFrequentString mfs = new MostFrequentString(); mfs.addString("A"); mfs.addString("B"); @@ -184,14 +185,18 @@ public class PerformanceMetricsTest { @Test public void testIntegerDistributionToThirtyTwo() { IntegerDistribution id = new IntegerDistribution(); - for (int i = 13; i <= 32; i++) id.addLong(i); + for (int i = 13; i <= 32; i++) { + id.addLong(i); + } assertEquals(".500<32, .900<32, .990<64, .999<64", id.toString()); }
@Test public void testIntegerDistributionToOneHundredTwentyEight() { IntegerDistribution id = new IntegerDistribution(); - for (int i = 27; i <= 128; i++) id.addLong(i); + for (int i = 27; i <= 128; i++) { + id.addLong(i); + } assertEquals(".500<128, .900<128, .990<128, .999<256", id.toString()); } diff --git a/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java b/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java index ffea950..ac466c9 100644 --- a/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java +++ b/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java @@ -1,4 +1,4 @@ -/* Copyright 2013 The Tor Project +/* Copyright 2013--2016 The Tor Project * See LICENSE for licensing information */
package org.torproject.onionoo.server; @@ -37,35 +37,42 @@ import java.util.TreeSet; * which tests servlet specifics. */ public class ResourceServletTest {
+ private SortedMap<String, org.torproject.onionoo.docs.SummaryDocument> relays; private SortedMap<String, org.torproject.onionoo.docs.SummaryDocument> - relays, bridges; + bridges;
private long currentTimeMillis = DateTimeHelper.parse( "2013-04-24 12:22:22");
private class TestingHttpServletRequestWrapper extends HttpServletRequestWrapper { - private String requestURI; + private String requestUri; private String queryString; private Map<String, String[]> parameterMap; - private TestingHttpServletRequestWrapper(String requestURI, + + private TestingHttpServletRequestWrapper(String requestUri, String queryString, Map<String, String[]> parameterMap) { super(null); - this.requestURI = requestURI; + this.requestUri = requestUri; this.queryString = queryString; this.parameterMap = parameterMap == null ? new HashMap<String, String[]>() : parameterMap; } + + @Override protected String getRequestURI() { - return this.requestURI; + return this.requestUri; } + @SuppressWarnings("rawtypes") protected Map getParameterMap() { return this.parameterMap; } + protected String[] getParameterValues(String parameterKey) { return this.parameterMap.get(parameterKey); } + protected String getQueryString() { return this.queryString; } @@ -73,22 +80,31 @@ public class ResourceServletTest {
private class TestingHttpServletResponseWrapper extends HttpServletResponseWrapper { + private TestingHttpServletResponseWrapper() { super(null); } + private int errorStatusCode; + protected void sendError(int errorStatusCode) throws IOException { this.errorStatusCode = errorStatusCode; } - private Map<String, String> headers = new HashMap<String, String>(); + + private Map<String, String> headers = new HashMap<>(); + protected void setHeader(String headerName, String headerValue) { this.headers.put(headerName, headerValue); } + protected void setContentType(String contentType) { } + protected void setCharacterEncoding(String characterEncoding) { } + private StringWriter stringWriter; + protected PrintWriter getWriter() throws IOException { if (this.stringWriter == null) { this.stringWriter = new StringWriter(); @@ -97,6 +113,7 @@ public class ResourceServletTest { throw new IOException("Can only request writer once"); } } + private String getWrittenContent() { return this.stringWriter == null ? null : this.stringWriter.toString(); @@ -111,20 +128,21 @@ public class ResourceServletTest {
private SummaryDocument summaryDocument;
+ @SuppressWarnings("JavadocMethod") @Before public void createSampleRelaysAndBridges() { org.torproject.onionoo.docs.SummaryDocument relayTorkaZ = new org.torproject.onionoo.docs.SummaryDocument(true, "TorkaZ", "000C5F55BD4814B917CC474BD537F1A3B33CCE2A", Arrays.asList( new String[] { "62.216.201.221", "62.216.201.222", - "62.216.201.223" }), DateTimeHelper.parse("2013-04-19 05:00:00"), + "62.216.201.223" }), DateTimeHelper.parse("2013-04-19 05:00:00"), false, new TreeSet<String>(Arrays.asList(new String[] { "Running", - "Valid" })), 20L, "de", + "Valid" })), 20L, "de", DateTimeHelper.parse("2013-04-18 05:00:00"), "AS8767", "torkaz <klaus dot zufall at gmx dot de> " + "fb-token:np5_g_83jmf=", new TreeSet<String>(Arrays.asList( new String[] { "001C13B3A55A71B977CA65EC85539D79C653A3FC", - "0025C136C1F3A9EEFE2AE3F918F03BFA21B5070B" })), + "0025C136C1F3A9EEFE2AE3F918F03BFA21B5070B" })), new TreeSet<String>(Arrays.asList( new String[] { "001C13B3A55A71B977CA65EC85539D79C653A3FC" }))); org.torproject.onionoo.docs.SummaryDocument relayFerrari458 = @@ -133,12 +151,18 @@ public class ResourceServletTest { new String[] { "68.38.171.200", "[2001:4f8:3:2e::51]" }), DateTimeHelper.parse("2013-04-24 12:00:00"), true, new TreeSet<String>(Arrays.asList(new String[] { "Fast", "Named", - "Running", "V2Dir", "Valid" })), 1140L, "us", + "Running", "V2Dir", "Valid" })), 1140L, "us", DateTimeHelper.parse("2013-02-12 16:00:00"), "AS7922", null, new TreeSet<String>(Arrays.asList(new String[] { - "000C5F55BD4814B917CC474BD537F1A3B33CCE2A" })), + "000C5F55BD4814B917CC474BD537F1A3B33CCE2A" })), new TreeSet<String>(Arrays.asList(new String[] { - "000C5F55BD4814B917CC474BD537F1A3B33CCE2A" }))); + "000C5F55BD4814B917CC474BD537F1A3B33CCE2A" }))); + this.relays = + new TreeMap<String, org.torproject.onionoo.docs.SummaryDocument>(); + this.relays.put("000C5F55BD4814B917CC474BD537F1A3B33CCE2A", + relayTorkaZ); + this.relays.put("001C13B3A55A71B977CA65EC85539D79C653A3FC", + relayFerrari458); org.torproject.onionoo.docs.SummaryDocument relayTimMayTribute = new org.torproject.onionoo.docs.SummaryDocument(true, "TimMayTribute", "0025C136C1F3A9EEFE2AE3F918F03BFA21B5070B", Arrays.asList( @@ -150,6 +174,10 @@ public class ResourceServletTest { "1024D/51E2A1C7 steven j. murdoch " + "tor+steven.murdoch@cl.cam.ac.uk fb-token:5sr_k_zs2wm=", new TreeSet<String>(), new TreeSet<String>()); + this.relays.put("0025C136C1F3A9EEFE2AE3F918F03BFA21B5070B", + relayTimMayTribute); + this.bridges = + new TreeMap<String, org.torproject.onionoo.docs.SummaryDocument>(); org.torproject.onionoo.docs.SummaryDocument bridgeec2bridgercc7f31fe = new org.torproject.onionoo.docs.SummaryDocument(false, "ec2bridgercc7f31fe", "0000831B236DFF73D409AD17B40E2A728A53994F", @@ -158,6 +186,8 @@ public class ResourceServletTest { new TreeSet<String>(Arrays.asList(new String[] { "Valid" })), -1L, null, DateTimeHelper.parse("2013-04-20 15:37:04"), null, null, null, null); + this.bridges.put("0000831B236DFF73D409AD17B40E2A728A53994F", + bridgeec2bridgercc7f31fe); org.torproject.onionoo.docs.SummaryDocument bridgeUnnamed = new org.torproject.onionoo.docs.SummaryDocument(false, "Unnamed", "0002D9BDBBC230BD9C78FF502A16E0033EF87E0C", Arrays.asList( @@ -166,29 +196,17 @@ public class ResourceServletTest { new TreeSet<String>(Arrays.asList(new String[] { "Valid" })), -1L, null, DateTimeHelper.parse("2013-04-14 07:07:05"), null, null, null, null); + this.bridges.put("0002D9BDBBC230BD9C78FF502A16E0033EF87E0C", + bridgeUnnamed); org.torproject.onionoo.docs.SummaryDocument bridgegummy = new org.torproject.onionoo.docs.SummaryDocument(false, "gummy", "1FEDE50ED8DBA1DD9F9165F78C8131E4A44AB756", Arrays.asList( new String[] { "10.63.169.98" }), DateTimeHelper.parse("2013-04-24 01:07:04"), true, new TreeSet<String>(Arrays.asList(new String[] { "Running", - "Valid" })), -1L, null, + "Valid" })), -1L, null, DateTimeHelper.parse("2013-01-16 21:07:04"), null, null, null, null); - this.relays = - new TreeMap<String, org.torproject.onionoo.docs.SummaryDocument>(); - this.relays.put("000C5F55BD4814B917CC474BD537F1A3B33CCE2A", - relayTorkaZ); - this.relays.put("001C13B3A55A71B977CA65EC85539D79C653A3FC", - relayFerrari458); - this.relays.put("0025C136C1F3A9EEFE2AE3F918F03BFA21B5070B", - relayTimMayTribute); - this.bridges = - new TreeMap<String, org.torproject.onionoo.docs.SummaryDocument>(); - this.bridges.put("0000831B236DFF73D409AD17B40E2A728A53994F", - bridgeec2bridgercc7f31fe); - this.bridges.put("0002D9BDBBC230BD9C78FF502A16E0033EF87E0C", - bridgeUnnamed); this.bridges.put("1FEDE50ED8DBA1DD9F9165F78C8131E4A44AB756", bridgegummy); } @@ -234,7 +252,7 @@ public class ResourceServletTest {
private void makeRequest(String request) throws IOException { ResourceServlet rs = new ResourceServlet(); - String requestParts[] = request.split("\?"); + String[] requestParts = request.split("\?"); String path = requestParts[0]; String queryString = requestParts.length > 1 ? requestParts[1] : null; Map<String, String[]> parameterMap = parseParameters(request); @@ -287,7 +305,7 @@ public class ResourceServletTest { String[] uriParts = request.split("\?"); if (uriParts.length == 2) { Map<String, List<String>> parameterLists = - new HashMap<String, List<String>>(); + new HashMap<>(); for (String parameter : uriParts[1].split("&")) { String[] parameterParts = parameter.split("="); if (!parameterLists.containsKey(parameterParts[0])) { @@ -296,7 +314,7 @@ public class ResourceServletTest { } parameterLists.get(parameterParts[0]).add(parameterParts[1]); } - parameters = new HashMap<String, String[]>(); + parameters = new HashMap<>(); for (Map.Entry<String, List<String>> e : parameterLists.entrySet()) { parameters.put(e.getKey(), @@ -306,6 +324,7 @@ public class ResourceServletTest { return parameters; }
+ @SuppressWarnings("MemberName") private static class SummaryDocument { private String relays_published; private RelaySummary[] relays; @@ -313,6 +332,7 @@ public class ResourceServletTest { private BridgeSummary[] bridges; }
+ @SuppressWarnings("MemberName") private static class RelaySummary { private String n; private String f; @@ -320,6 +340,7 @@ public class ResourceServletTest { private boolean r; }
+ @SuppressWarnings("MemberName") private static class BridgeSummary { private String n; private String h; @@ -371,7 +392,7 @@ public class ResourceServletTest { }
@Test() - public void testSUMMARYDocument() { + public void testSummaryUpperCaseDocument() { this.assertErrorStatusCode( "/SUMMARY", 400); } @@ -413,13 +434,13 @@ public class ResourceServletTest { }
@Test() - public void testTYPERelay() { + public void testTypeUpperCaseRelay() { this.assertErrorStatusCode( "/summary?TYPE=relay", 400); }
@Test() - public void testTypeRELAY() { + public void testTypeRelayUpperCase() { this.assertSummaryDocument( "/summary?type=RELAY", 3, null, 0, null); } @@ -464,13 +485,13 @@ public class ResourceServletTest { }
@Test() - public void testRUNNINGTrue() { + public void testRunningUpperCaseTrue() { this.assertErrorStatusCode( "/summary?RUNNING=true", 400); }
@Test() - public void testRunningTRUE() { + public void testRunningTrueUpperCase() { this.assertSummaryDocument( "/summary?running=TRUE", 1, null, 1, null); } @@ -500,7 +521,7 @@ public class ResourceServletTest { }
@Test() - public void testSearchTORKAZ() { + public void testSearchTorkazUpperCase() { this.assertSummaryDocument( "/summary?search=TORKAZ", 1, new String[] { "TorkaZ" }, 0, null); } @@ -730,7 +751,7 @@ public class ResourceServletTest { }
@Test() - public void testSearchGUMMY() { + public void testSearchGummyUpperCase() { this.assertSummaryDocument( "/summary?search=GUMMY", 0, null, 1, new String[] { "gummy" }); } @@ -962,7 +983,7 @@ public class ResourceServletTest { }
@Test() - public void testCountryDE() { + public void testCountryDeUpperCase() { this.assertSummaryDocument( "/summary?country=DE", 1, new String[] { "TorkaZ" }, 0, null); } @@ -1006,7 +1027,7 @@ public class ResourceServletTest { }
@Test() - public void testAsAS() { + public void testAsAs() { this.assertErrorStatusCode( "/summary?as=AS", 400); } @@ -1018,7 +1039,7 @@ public class ResourceServletTest { }
@Test() - public void testAsASSpace8767() { + public void testAsAsSpace8767() { this.assertErrorStatusCode( "/summary?as=AS 8767", 400); } @@ -1258,7 +1279,7 @@ public class ResourceServletTest { }
@Test() - public void testOrderCONSENSUS_WEIGHT() { + public void testOrderConsensusWeight() { this.assertSummaryDocument( "/summary?order=CONSENSUS_WEIGHT", 3, new String[] { "TorkaZ", "TimMayTribute", "Ferrari458" }, 3, diff --git a/src/test/java/org/torproject/onionoo/updater/DummyBridgeStatus.java b/src/test/java/org/torproject/onionoo/updater/DummyBridgeStatus.java index f412de8..1e6990f 100644 --- a/src/test/java/org/torproject/onionoo/updater/DummyBridgeStatus.java +++ b/src/test/java/org/torproject/onionoo/updater/DummyBridgeStatus.java @@ -1,5 +1,6 @@ -/* Copyright 2014 The Tor Project +/* Copyright 2014--2016 The Tor Project * See LICENSE for licensing information */ + package org.torproject.onionoo.updater;
import org.torproject.descriptor.BridgeNetworkStatus; @@ -24,18 +25,22 @@ public class DummyBridgeStatus implements BridgeNetworkStatus { }
private long publishedMillis; + public void setPublishedMillis(long publishedMillis) { this.publishedMillis = publishedMillis; } + public long getPublishedMillis() { return this.publishedMillis; }
private SortedMap<String, NetworkStatusEntry> statusEntries = - new TreeMap<String, NetworkStatusEntry>(); + new TreeMap<>(); + public void addStatusEntry(NetworkStatusEntry statusEntry) { this.statusEntries.put(statusEntry.getFingerprint(), statusEntry); } + public SortedMap<String, NetworkStatusEntry> getStatusEntries() { return this.statusEntries; } diff --git a/src/test/java/org/torproject/onionoo/updater/DummyConsensus.java b/src/test/java/org/torproject/onionoo/updater/DummyConsensus.java index af03ccf..246916e 100644 --- a/src/test/java/org/torproject/onionoo/updater/DummyConsensus.java +++ b/src/test/java/org/torproject/onionoo/updater/DummyConsensus.java @@ -1,5 +1,6 @@ -/* Copyright 2014 The Tor Project +/* Copyright 2014--2016 The Tor Project * See LICENSE for licensing information */ + package org.torproject.onionoo.updater;
import org.torproject.descriptor.DirSourceEntry; @@ -40,9 +41,11 @@ public class DummyConsensus implements RelayNetworkStatusConsensus { }
private long validAfterMillis; + public void setValidAfterMillis(long validAfterMillis) { this.validAfterMillis = validAfterMillis; } + public long getValidAfterMillis() { return this.validAfterMillis; } @@ -72,9 +75,11 @@ public class DummyConsensus implements RelayNetworkStatusConsensus { }
private SortedSet<String> knownFlags = new TreeSet<String>(); + public void addKnownFlag(String flag) { this.knownFlags.add(flag); } + public SortedSet<String> getKnownFlags() { return this.knownFlags; } @@ -88,10 +93,12 @@ public class DummyConsensus implements RelayNetworkStatusConsensus { }
private SortedMap<String, NetworkStatusEntry> statusEntries = - new TreeMap<String, NetworkStatusEntry>(); + new TreeMap<>(); + public void addStatusEntry(NetworkStatusEntry statusEntry) { this.statusEntries.put(statusEntry.getFingerprint(), statusEntry); } + public SortedMap<String, NetworkStatusEntry> getStatusEntries() { return this.statusEntries; } diff --git a/src/test/java/org/torproject/onionoo/updater/DummyDescriptorSource.java b/src/test/java/org/torproject/onionoo/updater/DummyDescriptorSource.java index 40c1c65..878ef43 100644 --- a/src/test/java/org/torproject/onionoo/updater/DummyDescriptorSource.java +++ b/src/test/java/org/torproject/onionoo/updater/DummyDescriptorSource.java @@ -1,3 +1,6 @@ +/* Copyright 2014--2016 The Tor Project + * See LICENSE for licensing information */ + package org.torproject.onionoo.updater;
import org.torproject.descriptor.Descriptor; @@ -13,6 +16,7 @@ public class DummyDescriptorSource extends DescriptorSource { private Map<DescriptorType, Set<Descriptor>> descriptors = new HashMap<DescriptorType, Set<Descriptor>>();
+ /** Fills the given collection with descriptors of the requested type. */ public void provideDescriptors(DescriptorType descriptorType, Collection<Descriptor> descriptors) { for (Descriptor descriptor : descriptors) { @@ -20,6 +24,7 @@ public class DummyDescriptorSource extends DescriptorSource { } }
+ /** Add a descriptor of the given type. */ public void addDescriptor(DescriptorType descriptorType, Descriptor descriptor) { this.getDescriptorsByType(descriptorType).add(descriptor); @@ -34,9 +39,9 @@ public class DummyDescriptorSource extends DescriptorSource { }
private Map<DescriptorType, Set<DescriptorListener>> - descriptorListeners = new HashMap<DescriptorType, - Set<DescriptorListener>>(); + descriptorListeners = new HashMap<>();
+ /** Register a listener to receive descriptors of the demanded type. */ public void registerDescriptorListener(DescriptorListener listener, DescriptorType descriptorType) { if (!this.descriptorListeners.containsKey(descriptorType)) { @@ -46,27 +51,28 @@ public class DummyDescriptorSource extends DescriptorSource { this.descriptorListeners.get(descriptorType).add(listener); }
+ @Override public void readDescriptors() { Set<DescriptorType> descriptorTypes = new HashSet<DescriptorType>(); descriptorTypes.addAll(this.descriptorListeners.keySet()); for (DescriptorType descriptorType : descriptorTypes) { boolean relay; switch (descriptorType) { - case RELAY_CONSENSUSES: - case RELAY_SERVER_DESCRIPTORS: - case RELAY_EXTRA_INFOS: - case EXIT_LISTS: - relay = true; - break; - case BRIDGE_STATUSES: - case BRIDGE_SERVER_DESCRIPTORS: - case BRIDGE_EXTRA_INFOS: - default: - relay = false; - break; + case RELAY_CONSENSUSES: + case RELAY_SERVER_DESCRIPTORS: + case RELAY_EXTRA_INFOS: + case EXIT_LISTS: + relay = true; + break; + case BRIDGE_STATUSES: + case BRIDGE_SERVER_DESCRIPTORS: + case BRIDGE_EXTRA_INFOS: + default: + relay = false; + break; } - if (this.descriptors.containsKey(descriptorType) && - this.descriptorListeners.containsKey(descriptorType)) { + if (this.descriptors.containsKey(descriptorType) + && this.descriptorListeners.containsKey(descriptorType)) { Set<DescriptorListener> listeners = this.descriptorListeners.get(descriptorType); for (Descriptor descriptor : diff --git a/src/test/java/org/torproject/onionoo/updater/DummyStatusEntry.java b/src/test/java/org/torproject/onionoo/updater/DummyStatusEntry.java index 120fc28..c60bded 100644 --- a/src/test/java/org/torproject/onionoo/updater/DummyStatusEntry.java +++ b/src/test/java/org/torproject/onionoo/updater/DummyStatusEntry.java @@ -1,5 +1,6 @@ -/* Copyright 2014 The Tor Project +/* Copyright 2014--2016 The Tor Project * See LICENSE for licensing information */ + package org.torproject.onionoo.updater;
import org.torproject.descriptor.NetworkStatusEntry; @@ -25,6 +26,7 @@ public class DummyStatusEntry implements NetworkStatusEntry { }
private String fingerprint; + public String getFingerprint() { return this.fingerprint; } @@ -58,9 +60,11 @@ public class DummyStatusEntry implements NetworkStatusEntry { }
private SortedSet<String> flags = new TreeSet<String>(); + public void addFlag(String flag) { this.flags.add(flag); } + public SortedSet<String> getFlags() { return this.flags; } diff --git a/src/test/java/org/torproject/onionoo/updater/LookupServiceTest.java b/src/test/java/org/torproject/onionoo/updater/LookupServiceTest.java index 3b89b9a..7793e56 100644 --- a/src/test/java/org/torproject/onionoo/updater/LookupServiceTest.java +++ b/src/test/java/org/torproject/onionoo/updater/LookupServiceTest.java @@ -1,4 +1,4 @@ -/* Copyright 2013 The Tor Project +/* Copyright 2013--2016 The Tor Project * See LICENSE for licensing information */
package org.torproject.onionoo.updater; @@ -26,8 +26,9 @@ import java.util.TreeSet;
public class LookupServiceTest {
- private List<String> geoLite2CityBlocksIPv4Lines, - geoLite2CityLocationsEnLines, geoipASNum2Lines; + private List<String> geoLite2CityBlocksIPv4Lines; + private List<String> geoLite2CityLocationsEnLines; + private List<String> geoipAsNum2Lines;
private LookupService lookupService;
@@ -58,12 +59,12 @@ public class LookupServiceTest { this.geoLite2CityLocationsEnLines.add("5375480,en,NA," + ""North America",US,"United States",CA,California,,," + ""Mountain View",807,America/Los_Angeles"); - this.geoipASNum2Lines = new ArrayList<String>(); - this.geoipASNum2Lines.add("134743296,134744063,"AS3356 Level 3 " + this.geoipAsNum2Lines = new ArrayList<String>(); + this.geoipAsNum2Lines.add("134743296,134744063,"AS3356 Level 3 " + "Communications""); - this.geoipASNum2Lines.add("134744064,134744319,"AS15169 Google " + this.geoipAsNum2Lines.add("134744064,134744319,"AS15169 Google " + "Inc.""); - this.geoipASNum2Lines.add("134744320,134750463,"AS3356 Level 3 " + this.geoipAsNum2Lines.add("134744320,134750463,"AS3356 Level 3 " + "Communications""); }
@@ -73,7 +74,7 @@ public class LookupServiceTest { "GeoLite2-City-Blocks-IPv4.csv", "UTF-8"); this.writeCsvFile(this.geoLite2CityLocationsEnLines, "GeoLite2-City-Locations-en.csv", "UTF-8"); - this.writeCsvFile(this.geoipASNum2Lines, "GeoIPASNum2.csv", + this.writeCsvFile(this.geoipAsNum2Lines, "GeoIPASNum2.csv", "ISO-8859-1"); } catch (IOException e) { throw new RuntimeException(e); @@ -102,10 +103,10 @@ public class LookupServiceTest {
private void assertLookupResult(List<String> geoLite2CityBlocksLines, List<String> geoLite2CityLocationsLines, - List<String> geoipASNum2Lines, String addressString, + List<String> geoipAsNum2Lines, String addressString, String countryCode, String countryName, String regionName, - String cityName, Float latitude, Float longitude, String aSNumber, - String aSName) { + String cityName, Float latitude, Float longitude, String asNumber, + String asName) { this.addressStrings.add(addressString); this.populateLines(); if (geoLite2CityBlocksLines != null) { @@ -114,70 +115,70 @@ public class LookupServiceTest { if (geoLite2CityLocationsLines != null) { this.geoLite2CityLocationsEnLines = geoLite2CityLocationsLines; } - if (geoipASNum2Lines != null) { - this.geoipASNum2Lines = geoipASNum2Lines; + if (geoipAsNum2Lines != null) { + this.geoipAsNum2Lines = geoipAsNum2Lines; } this.writeCsvFiles(); /* Disable log messages printed to System.err. */ System.setErr(new PrintStream(new OutputStream() { - public void write(int b) { + public void write(int someInt) { } })); this.performLookups(); if (countryCode == null) { - assertTrue(!this.lookupResults.containsKey(addressString) || - this.lookupResults.get(addressString).getCountryCode() == null); + assertTrue(!this.lookupResults.containsKey(addressString) + || this.lookupResults.get(addressString).getCountryCode() == null); } else { assertEquals(countryCode, this.lookupResults.get(addressString).getCountryCode()); } if (countryName == null) { - assertTrue(!this.lookupResults.containsKey(addressString) || - this.lookupResults.get(addressString).getCountryName() == null); + assertTrue(!this.lookupResults.containsKey(addressString) + || this.lookupResults.get(addressString).getCountryName() == null); } else { assertEquals(countryName, this.lookupResults.get(addressString).getCountryName()); } if (regionName == null) { - assertTrue(!this.lookupResults.containsKey(addressString) || - this.lookupResults.get(addressString).getRegionName() == null); + assertTrue(!this.lookupResults.containsKey(addressString) + || this.lookupResults.get(addressString).getRegionName() == null); } else { assertEquals(regionName, this.lookupResults.get(addressString).getRegionName()); } if (cityName == null) { - assertTrue(!this.lookupResults.containsKey(addressString) || - this.lookupResults.get(addressString).getCityName() == null); + assertTrue(!this.lookupResults.containsKey(addressString) + || this.lookupResults.get(addressString).getCityName() == null); } else { assertEquals(cityName, this.lookupResults.get(addressString).getCityName()); } if (latitude == null) { - assertTrue(!this.lookupResults.containsKey(addressString) || - this.lookupResults.get(addressString).getLatitude() == null); + assertTrue(!this.lookupResults.containsKey(addressString) + || this.lookupResults.get(addressString).getLatitude() == null); } else { assertEquals(latitude, this.lookupResults.get(addressString).getLatitude(), 0.01); } if (longitude == null) { - assertTrue(!this.lookupResults.containsKey(addressString) || - this.lookupResults.get(addressString).getLongitude() == null); + assertTrue(!this.lookupResults.containsKey(addressString) + || this.lookupResults.get(addressString).getLongitude() == null); } else { assertEquals(longitude, this.lookupResults.get(addressString).getLongitude(), 0.01); } - if (aSNumber == null) { - assertTrue(!this.lookupResults.containsKey(addressString) || - this.lookupResults.get(addressString).getAsNumber() == null); + if (asNumber == null) { + assertTrue(!this.lookupResults.containsKey(addressString) + || this.lookupResults.get(addressString).getAsNumber() == null); } else { - assertEquals(aSNumber, + assertEquals(asNumber, this.lookupResults.get(addressString).getAsNumber()); } - if (aSName == null) { - assertTrue(!this.lookupResults.containsKey(addressString) || - this.lookupResults.get(addressString).getAsName() == null); + if (asName == null) { + assertTrue(!this.lookupResults.containsKey(addressString) + || this.lookupResults.get(addressString).getAsName() == null); } else { - assertEquals(aSName, + assertEquals(asName, this.lookupResults.get(addressString).getAsName()); } } @@ -244,7 +245,7 @@ public class LookupServiceTest { }
@Test() - public void testLookupNoGeoipASNum2Lines() { + public void testLookupNoGeoipAsNum2Lines() { this.assertLookupResult(null, null, new ArrayList<String>(), "8.8.8.8", null, null, null, null, null, null, null, null); } @@ -376,55 +377,56 @@ public class LookupServiceTest { }
@Test() - public void testLookupGeoipASNum2EndBeforeStart() { - List<String> geoipASNum2Lines = new ArrayList<String>(); - geoipASNum2Lines.add("134743296,134744063,"AS3356 Level 3 " + public void testLookupGeoipAsNum2EndBeforeStart() { + List<String> geoipAsNum2Lines = new ArrayList<String>(); + geoipAsNum2Lines.add("134743296,134744063,"AS3356 Level 3 " + "Communications""); - geoipASNum2Lines.add("134744319,134744064,"AS15169 Google Inc.""); - geoipASNum2Lines.add("134744320,134750463,"AS3356 Level 3 " + geoipAsNum2Lines.add("134744319,134744064,"AS15169 Google Inc.""); + geoipAsNum2Lines.add("134744320,134750463,"AS3356 Level 3 " + "Communications""); - this.assertLookupResult(null, null, geoipASNum2Lines, "8.8.8.8", "us", + this.assertLookupResult(null, null, geoipAsNum2Lines, "8.8.8.8", "us", "United States", "California", "Mountain View", 37.3860f, -122.0838f, null, null); }
@Test() - public void testLookupGeoipASNum2StartNotANumber() { - List<String> geoipASNum2Lines = new ArrayList<String>(); - geoipASNum2Lines.add("one,134744319,"AS15169 Google Inc.""); - this.assertLookupResult(null, null, geoipASNum2Lines, "8.8.8.8", null, + public void testLookupGeoipAsNum2StartNotANumber() { + List<String> geoipAsNum2Lines = new ArrayList<String>(); + geoipAsNum2Lines.add("one,134744319,"AS15169 Google Inc.""); + this.assertLookupResult(null, null, geoipAsNum2Lines, "8.8.8.8", null, null, null, null, null, null, null, null); }
@Test() - public void testLookupGeoipASNum2StartTooLarge() { - List<String> geoipASNum2Lines = new ArrayList<String>(); - geoipASNum2Lines.add("1" + String.valueOf(Long.MAX_VALUE) + public void testLookupGeoipAsNum2StartTooLarge() { + List<String> geoipAsNum2Lines = new ArrayList<String>(); + geoipAsNum2Lines.add("1" + String.valueOf(Long.MAX_VALUE) + ",134744319,"AS15169 Google Inc.""); - this.assertLookupResult(null, null, geoipASNum2Lines, "8.8.8.8", null, + this.assertLookupResult(null, null, geoipAsNum2Lines, "8.8.8.8", null, null, null, null, null, null, null, null); }
@Test() - public void testLookupGeoipASNum2TooFewFields() { - List<String> geoipASNum2Lines = new ArrayList<String>(); - geoipASNum2Lines.add("134744064,134744319"); - this.assertLookupResult(null, null, geoipASNum2Lines, "8.8.8.8", null, + public void testLookupGeoipAsNum2TooFewFields() { + List<String> geoipAsNum2Lines = new ArrayList<String>(); + geoipAsNum2Lines.add("134744064,134744319"); + this.assertLookupResult(null, null, geoipAsNum2Lines, "8.8.8.8", null, null, null, null, null, null, null, null); }
@Test() - public void testLookupGeoipASNum2NoASName() { - List<String> geoipASNum2Lines = new ArrayList<String>(); - geoipASNum2Lines.add("134743296,134744063,AS3356"); - geoipASNum2Lines.add("134744064,134744319,AS15169"); - geoipASNum2Lines.add("134744320,134750463,AS3356"); - this.assertLookupResult(null, null, geoipASNum2Lines, "8.8.8.8", "us", + public void testLookupGeoipAsNum2NoAsName() { + List<String> geoipAsNum2Lines = new ArrayList<String>(); + geoipAsNum2Lines.add("134743296,134744063,AS3356"); + geoipAsNum2Lines.add("134744064,134744319,AS15169"); + geoipAsNum2Lines.add("134744320,134750463,AS3356"); + this.assertLookupResult(null, null, geoipAsNum2Lines, "8.8.8.8", "us", "United States", "California", "Mountain View", 37.3860f, -122.0838f, "AS15169", ""); }
@Test() + @SuppressWarnings("AvoidEscapedUnicodeCharacters") public void testLookupLocationTurkey() { List<String> geoLite2CityBlocksIPv4Lines = new ArrayList<String>(); geoLite2CityBlocksIPv4Lines.add("network,geoname_id," @@ -472,6 +474,7 @@ public class LookupServiceTest { }
@Test() + @SuppressWarnings("AvoidEscapedUnicodeCharacters") public void testLookupLocationLatvia() { List<String> geoLite2CityBlocksIPv4Lines = new ArrayList<String>(); geoLite2CityBlocksIPv4Lines.add("network,geoname_id," @@ -494,6 +497,7 @@ public class LookupServiceTest { }
@Test() + @SuppressWarnings("AvoidEscapedUnicodeCharacters") public void testLookupLocationAzerbaijan() { List<String> geoLite2CityBlocksIPv4Lines = new ArrayList<String>(); geoLite2CityBlocksIPv4Lines.add("network,geoname_id," @@ -517,6 +521,7 @@ public class LookupServiceTest { }
@Test() + @SuppressWarnings("AvoidEscapedUnicodeCharacters") public void testLookupLocationVietnam() { List<String> geoLite2CityBlocksIPv4Lines = new ArrayList<String>(); geoLite2CityBlocksIPv4Lines.add("network,geoname_id," @@ -540,6 +545,7 @@ public class LookupServiceTest { }
@Test() + @SuppressWarnings("AvoidEscapedUnicodeCharacters") public void testLookupLocationJapan() { List<String> geoLite2CityBlocksIPv4Lines = new ArrayList<String>(); geoLite2CityBlocksIPv4Lines.add("network,geoname_id," @@ -563,6 +569,7 @@ public class LookupServiceTest { }
@Test() + @SuppressWarnings("AvoidEscapedUnicodeCharacters") public void testLookupLocationDenmark() { List<String> geoLite2CityBlocksIPv4Lines = new ArrayList<String>(); geoLite2CityBlocksIPv4Lines.add("network,geoname_id," @@ -587,6 +594,7 @@ public class LookupServiceTest { }
@Test() + @SuppressWarnings("AvoidEscapedUnicodeCharacters") public void testLookupLocationGermany() { List<String> geoLite2CityBlocksIPv4Lines = new ArrayList<String>(); geoLite2CityBlocksIPv4Lines.add("network,geoname_id," @@ -611,6 +619,7 @@ public class LookupServiceTest { }
@Test() + @SuppressWarnings("AvoidEscapedUnicodeCharacters") public void testLookupLocationPoland() { List<String> geoLite2CityBlocksIPv4Lines = new ArrayList<String>(); geoLite2CityBlocksIPv4Lines.add("network,geoname_id," @@ -634,20 +643,21 @@ public class LookupServiceTest { }
@Test() - public void testLookupLocationASNameNonAscii() { - List<String> geoipASNum2Lines = new ArrayList<String>(); - geoipASNum2Lines.add("3207917568,3207919615,"AS52693 Conectel " + @SuppressWarnings("AvoidEscapedUnicodeCharacters") + public void testLookupLocationAsNameNonAscii() { + List<String> geoipAsNum2Lines = new ArrayList<String>(); + geoipAsNum2Lines.add("3207917568,3207919615,"AS52693 Conectel " + "Telecomunica\u00E7\u00F5es e Inform\u00E1tica Ltda ME""); - geoipASNum2Lines.add("3211196416,3211198463,"AS262934 " + geoipAsNum2Lines.add("3211196416,3211198463,"AS262934 " + "IP\u00B7RED""); - geoipASNum2Lines.add("3227819264,3227819519,"AS263226 " + geoipAsNum2Lines.add("3227819264,3227819519,"AS263226 " + "COMPA\u00D1\u00CDA FINANCIERA ARGENTINA S.A.""); - this.assertLookupResult(null, null, geoipASNum2Lines, "191.52.240.0", + this.assertLookupResult(null, null, geoipAsNum2Lines, "191.52.240.0", null, null, null, null, null, null, "AS52693", "Conectel " + "Telecomunica\u00E7\u00F5es e Inform\u00E1tica Ltda ME"); - this.assertLookupResult(null, null, geoipASNum2Lines, "191.102.248.0", + this.assertLookupResult(null, null, geoipAsNum2Lines, "191.102.248.0", null, null, null, null, null, null, "AS262934", "IP\u00B7RED"); - this.assertLookupResult(null, null, geoipASNum2Lines, "192.100.157.0", + this.assertLookupResult(null, null, geoipAsNum2Lines, "192.100.157.0", null, null, null, null, null, null, "AS263226", "COMPA\u00D1\u00CDA FINANCIERA ARGENTINA S.A."); } diff --git a/src/test/java/org/torproject/onionoo/updater/UptimeStatusUpdaterTest.java b/src/test/java/org/torproject/onionoo/updater/UptimeStatusUpdaterTest.java index 278ed07..37a1b8e 100644 --- a/src/test/java/org/torproject/onionoo/updater/UptimeStatusUpdaterTest.java +++ b/src/test/java/org/torproject/onionoo/updater/UptimeStatusUpdaterTest.java @@ -1,5 +1,6 @@ -/* Copyright 2014 The Tor Project +/* Copyright 2014--2016 The Tor Project * See LICENSE for licensing information */ + package org.torproject.onionoo.updater;
import static org.junit.Assert.assertEquals; diff --git a/src/test/java/org/torproject/onionoo/util/DummyTime.java b/src/test/java/org/torproject/onionoo/util/DummyTime.java index 907805c..eacc200 100644 --- a/src/test/java/org/torproject/onionoo/util/DummyTime.java +++ b/src/test/java/org/torproject/onionoo/util/DummyTime.java @@ -1,12 +1,15 @@ -/* Copyright 2014 The Tor Project +/* Copyright 2014--2016 The Tor Project * See LICENSE for licensing information */ + package org.torproject.onionoo.util;
public class DummyTime extends Time { private long currentTimeMillis; + public DummyTime(long currentTimeMillis) { this.currentTimeMillis = currentTimeMillis; } + public long currentTimeMillis() { return this.currentTimeMillis; } diff --git a/src/test/java/org/torproject/onionoo/writer/UptimeDocumentWriterTest.java b/src/test/java/org/torproject/onionoo/writer/UptimeDocumentWriterTest.java index 4e5b69c..3661010 100644 --- a/src/test/java/org/torproject/onionoo/writer/UptimeDocumentWriterTest.java +++ b/src/test/java/org/torproject/onionoo/writer/UptimeDocumentWriterTest.java @@ -1,5 +1,6 @@ -/* Copyright 2014 The Tor Project +/* Copyright 2014--2016 The Tor Project * See LICENSE for licensing information */ + package org.torproject.onionoo.writer;
import static org.junit.Assert.assertEquals; @@ -75,8 +76,9 @@ public class UptimeDocumentWriterTest { this.documentStore.addDocument(status, GABELMOO_FINGERPRINT); }
- private static final long ONE_SECOND = 1000L, - ONE_HOUR = 60L * 60L * ONE_SECOND, FOUR_HOURS = 4L * ONE_HOUR; + private static final long ONE_SECOND = 1000L; + private static final long ONE_HOUR = 60L * 60L * ONE_SECOND; + private static final long FOUR_HOURS = 4L * ONE_HOUR;
private void assertOneWeekGraph(UptimeDocument document, int graphs, String first, String last, int count, List<Integer> values) { diff --git a/src/test/resources/metrics_checks.xml b/src/test/resources/metrics_checks.xml index a4af08a..6ba415a 100644 --- a/src/test/resources/metrics_checks.xml +++ b/src/test/resources/metrics_checks.xml @@ -48,7 +48,7 @@ <property name="allowNonPrintableEscapes" value="true"/> </module> <module name="LineLength"> - <property name="max" value="100"/> + <property name="max" value="80"/> <property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/> </module> <module name="AvoidStarImport"/>
tor-commits@lists.torproject.org