forked from TheHive-Project/TheHive
-
Notifications
You must be signed in to change notification settings - Fork 0
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 TheHive-Project#2103 from vdebergue/fix/case-numbe…
…r-serialization Fix serialization for case number messages
- Loading branch information
Showing
2 changed files
with
38 additions
and
10 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
34 changes: 34 additions & 0 deletions
34
thehive/test/org/thp/thehive/services/CaseNumberTest.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,34 @@ | ||
package org.thp.thehive.services | ||
|
||
import akka.actor.ExtendedActorSystem | ||
import akka.actor.typed.ActorSystem | ||
import akka.actor.typed.scaladsl.Behaviors | ||
import org.thp.thehive.TestAppBuilder | ||
import play.api.test.PlaySpecification | ||
|
||
class CaseNumberTest extends PlaySpecification with TestAppBuilder { | ||
|
||
"case number actor" should { | ||
"serialize and deserialize messages" in withActorSystem { system => | ||
val ref = system.deadLetters[CaseNumberActor.Response] | ||
val sut = new CaseNumberSerializer(system.classicSystem.asInstanceOf[ExtendedActorSystem]) | ||
|
||
val messages = Seq( | ||
CaseNumberActor.GetNextNumber(ref), | ||
CaseNumberActor.NextNumber(42), | ||
CaseNumberActor.NextNumber(Int.MaxValue) | ||
) | ||
val out = messages.map(message => sut.toBinary(message)) | ||
|
||
val result = out.map(bin => sut.fromBinary(bin)) | ||
|
||
result must beEqualTo(messages) | ||
} | ||
} | ||
|
||
private def withActorSystem[T](body: ActorSystem[Nothing] => T) = { | ||
val system = ActorSystem(Behaviors.empty, "test") | ||
try body(system) | ||
finally system.terminate() | ||
} | ||
} |