From 881d755dd31e378f661aaa9209b21406a505ba8b Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Sun, 2 Jun 2019 22:47:43 +0100 Subject: [PATCH] update test work with personas --- .../groovy/com/muwire/core/Personas.groovy | 11 +++++ .../muwire/core/trust/TrustServiceTest.groovy | 40 ++++++++++--------- 2 files changed, 32 insertions(+), 19 deletions(-) create mode 100644 core/src/test/groovy/com/muwire/core/Personas.groovy diff --git a/core/src/test/groovy/com/muwire/core/Personas.groovy b/core/src/test/groovy/com/muwire/core/Personas.groovy new file mode 100644 index 00000000..88039b1f --- /dev/null +++ b/core/src/test/groovy/com/muwire/core/Personas.groovy @@ -0,0 +1,11 @@ +package com.muwire.core + +import net.i2p.data.Base64 + +class Personas { + private final String encoded1 = "AQADemFiO~pgSoEo8wQfwncYMvBQWkvPY9I7DYUllHp289UE~zBaLdbl~wbliktAUsW-S70f3UeYgHq34~c7zVuUQjgHZ506iG9hX8B9S3a9gQ3CSG0GuDpeNyiXmZkpHp5m8vT9PZ1zMWzxvzZY~fP9yKFKgO4yrso5I9~DGOPeyJZJ4BFsTJDERv41aZqjFLYUBDmeHGgg9RjYy~93h-nQMVYj9JSO3AgowW-ix49rtiKYIXHMa2PxWHUXkUHWJZtIZntNIDEFeMnPdzLxjAl8so2G6pDcTMZPLLwyb73Ee5ZVfxUynPqyp~fIGVP8Rl4rlaGFli2~ATGBz3XY54aObC~0p7us2JnWaTC~oQT5DVDM7gaOO885o-m8BB8b0duzMBelbdnMZFQJ5jIHVKxkC6Niw4fxTOoXTyOqQmVhtK-9xcwxMuN5DF9IewkR5bhpq5rgnfBP5zvyBaAHMq-d3TCOjTsZ-d3liB98xX5p8G5zmS7gfKArQtM5~CcK~AlX-lGLBQAEAAcAAN5MW1Tq983szfZgY1l8tQFqy8I9tdMf7vc1Ktj~TCIvXYw6AYMbMGy3S67FSPLZVmfHEMQKj2KLAdaRKQkHPAY" + private final String encoded2 = "AQAHemxhdGluYiN~3G-hPoBfJ04mhcC52lC6TYSwWxH-WNWno9Y35JS-WrXlnPsodZtwy96ttEaiKTg-hkRqMsaYKpWar1FwayR6qlo0pZCo5pQOLfR7GIM3~wde0JIBEp8BUpgzF1-QXLhuRG1t7tBbenW2tSgp5jQH61RI-c9flyUlOvf6nrhQMZ3aoviZ4aZW23Fx-ajYQBDk7PIxuyn8qYNwWy3kWOhGan05c54NnumS3XCzQWFDDPlADmco1WROeY9qrwwtmLM8lzDCEtJQXJlk~K5yLbyB63hmAeTK7J4iS6f9nnWv7TbB5r-Z3kC6D9TLYrQbu3h4AAxrqso45P8yHQtKUA4QJicS-6NJoBOnlCCU887wx2k9YSxxwNydlIxb1mZsX65Ke4uY0HDFokZHTzUcxvfLB6G~5JkSPDCyZz~2fREgW2-VXu7gokEdEugkuZRrsiQzyfAOOkv53ti5MzTbMOXinBskSb1vZyN2-XcZNaDJvEqUNj~qpfhe-ov2F7FuwQUABAAHAAAfqq-MneIqWBQY92-sy9Z0s~iQsq6lUFa~sYMdY-5o-94fF8a140dm-emF3rO8vuidUIPNaS-37Rl05mAKUCcB" + + Persona persona1 = new Persona(new ByteArrayInputStream(Base64.decode(encoded1))) + Persona persona2 = new Persona(new ByteArrayInputStream(Base64.decode(encoded2))) +} diff --git a/core/src/test/groovy/com/muwire/core/trust/TrustServiceTest.groovy b/core/src/test/groovy/com/muwire/core/trust/TrustServiceTest.groovy index c9bf3718..9be4ef6e 100644 --- a/core/src/test/groovy/com/muwire/core/trust/TrustServiceTest.groovy +++ b/core/src/test/groovy/com/muwire/core/trust/TrustServiceTest.groovy @@ -5,14 +5,17 @@ import org.junit.Before import org.junit.Test import com.muwire.core.Destinations +import com.muwire.core.Persona +import com.muwire.core.Personas +import net.i2p.data.Base64 import net.i2p.data.Destination class TrustServiceTest { TrustService service File persistGood, persistBad - Destinations dests = new Destinations() + Personas personas = new Personas() @Before void before() { @@ -33,51 +36,50 @@ class TrustServiceTest { @Test void testEmpty() { - assert TrustLevel.NEUTRAL == service.getLevel(dests.dest1) - assert TrustLevel.NEUTRAL == service.getLevel(dests.dest2) + assert TrustLevel.NEUTRAL == service.getLevel(personas.persona1.destination) + assert TrustLevel.NEUTRAL == service.getLevel(personas.persona2.destination) } @Test void testOnEvent() { - service.onTrustEvent new TrustEvent(level: TrustLevel.TRUSTED, destination: dests.dest1) - service.onTrustEvent new TrustEvent(level: TrustLevel.DISTRUSTED, destination: dests.dest2) + service.onTrustEvent new TrustEvent(level: TrustLevel.TRUSTED, persona: personas.persona1) + service.onTrustEvent new TrustEvent(level: TrustLevel.DISTRUSTED, persona: personas.persona2) - assert TrustLevel.TRUSTED == service.getLevel(dests.dest1) - assert TrustLevel.DISTRUSTED == service.getLevel(dests.dest2) + assert TrustLevel.TRUSTED == service.getLevel(personas.persona1.destination) + assert TrustLevel.DISTRUSTED == service.getLevel(personas.persona2.destination) } @Test void testPersist() { - service.onTrustEvent new TrustEvent(level: TrustLevel.TRUSTED, destination: dests.dest1) - service.onTrustEvent new TrustEvent(level: TrustLevel.DISTRUSTED, destination: dests.dest2) + service.onTrustEvent new TrustEvent(level: TrustLevel.TRUSTED, persona: personas.persona1) + service.onTrustEvent new TrustEvent(level: TrustLevel.DISTRUSTED, persona: personas.persona2) Thread.sleep(250) def trusted = new HashSet<>() persistGood.eachLine { - trusted.add(new Destination(it)) + trusted.add(new Persona(new ByteArrayInputStream(Base64.decode(it)))) } def distrusted = new HashSet<>() persistBad.eachLine { - distrusted.add(new Destination(it)) + distrusted.add(new Persona(new ByteArrayInputStream(Base64.decode(it)))) } assert trusted.size() == 1 - assert trusted.contains(dests.dest1) + assert trusted.contains(personas.persona1) assert distrusted.size() == 1 - assert distrusted.contains(dests.dest2) + assert distrusted.contains(personas.persona2) } @Test void testLoad() { service.stop() - persistGood.append("${dests.dest1.toBase64()}\n") - persistBad.append("${dests.dest2.toBase64()}\n") + persistGood.append("${personas.persona1.toBase64()}\n") + persistBad.append("${personas.persona2.toBase64()}\n") service = new TrustService(persistGood, persistBad, 100) service.start() - Thread.sleep(10) + Thread.sleep(50) - assert TrustLevel.TRUSTED == service.getLevel(dests.dest1) - assert TrustLevel.DISTRUSTED == service.getLevel(dests.dest2) - + assert TrustLevel.TRUSTED == service.getLevel(personas.persona1.destination) + assert TrustLevel.DISTRUSTED == service.getLevel(personas.persona2.destination) } }