-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1824 from dedis/work-be2-daniel-rumor-validator-db
Add Db handle of Rumors
- Loading branch information
Showing
10 changed files
with
272 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
be2-scala/src/main/scala/ch/epfl/pop/model/objects/RumorData.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package ch.epfl.pop.model.objects | ||
|
||
import ch.epfl.pop.model.network.Parsable | ||
import ch.epfl.pop.json.ObjectProtocol.* | ||
import ch.epfl.pop.model.network.method.Rumor | ||
import spray.json.* | ||
|
||
final case class RumorData( | ||
rumorIds: List[Int] | ||
) { | ||
def toJsonString: String = { | ||
this.toJson.toString | ||
} | ||
|
||
def updateWith(rumorId: Int): RumorData = { | ||
new RumorData((rumorId :: rumorIds).sorted) | ||
} | ||
|
||
} | ||
|
||
object RumorData extends Parsable { | ||
def apply( | ||
rumorIds: List[Int] | ||
): RumorData = { | ||
new RumorData(rumorIds) | ||
} | ||
|
||
override def buildFromJson(payload: String): RumorData = payload.parseJson.asJsObject.convertTo[RumorData] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
be2-scala/src/test/scala/ch/epfl/pop/model/objects/RumorDataSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package ch.epfl.pop.model.objects | ||
|
||
import org.scalatest.funsuite.{AnyFunSuite => FunSuite} | ||
import org.scalatest.matchers.should.Matchers | ||
import spray.json._ | ||
|
||
class RumorDataSuite extends FunSuite with Matchers { | ||
|
||
test("Json conversion works for RumorDataSuite") { | ||
val rumorData = RumorData(List(1, 2, 3, 4, 5)) | ||
|
||
val rumorDataJson = RumorData.buildFromJson(rumorData.toJsonString) | ||
|
||
rumorData should equal(rumorDataJson) | ||
} | ||
|
||
test("RumorData updates") { | ||
val rumorData = RumorData(List(1, 2, 3, 4, 5)) | ||
|
||
val updatedRumorData = rumorData.updateWith(6) | ||
|
||
updatedRumorData.rumorIds should equal(List(1, 2, 3, 4, 5, 6)) | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
be2-scala/src/test/scala/util/examples/Rumor/RumorExample.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package util.examples.Rumor | ||
|
||
import ch.epfl.pop.model.network.method.Rumor | ||
import ch.epfl.pop.model.network.method.message.Message | ||
import ch.epfl.pop.model.objects.{Base64Data, Channel, PublicKey} | ||
import util.examples.MessageExample | ||
|
||
object RumorExample { | ||
|
||
private val senderPk: PublicKey = PublicKey(Base64Data.encode("publicKey")) | ||
private val channel: Channel = Channel(Channel.ROOT_CHANNEL_PREFIX + "rumorExample") | ||
private val messages: List[Message] = (for i <- 0 until 10 yield MessageExample.MESSAGE).toList | ||
val rumorExample: Rumor = Rumor(senderPk, 1, Map(channel -> messages)) | ||
|
||
} |