-
Notifications
You must be signed in to change notification settings - Fork 93
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 #998 from nickgrippin/tsvalidated-cerealizer
TsValidated Serializer
- Loading branch information
Showing
8 changed files
with
76 additions
and
34 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
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
12 changes: 8 additions & 4 deletions
12
...tion/LarValidatedProtobufSerializer.scala → ...ion/HmdaValidatorProtobufSerializer.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 |
---|---|---|
@@ -1,25 +1,29 @@ | ||
package hmda.persistence.serialization.validation | ||
|
||
import akka.serialization.SerializerWithStringManifest | ||
import hmda.persistence.messages.events.processing.CommonHmdaValidatorEvents.LarValidated | ||
import hmda.persistence.model.serialization.HmdaFilingEvents.LarValidatedMessage | ||
import hmda.persistence.serialization.validation.LarValidatedProtobufConverter._ | ||
import hmda.persistence.messages.events.processing.CommonHmdaValidatorEvents.{ LarValidated, TsValidated } | ||
import hmda.persistence.model.serialization.CommonHmdaValidator.{ LarValidatedMessage, TsValidatedMessage } | ||
import hmda.persistence.serialization.validation.HmdaValidatorProtobufConverter._ | ||
|
||
class LarValidatedProtobufSerializer extends SerializerWithStringManifest { | ||
class HmdaValidatorProtobufSerializer extends SerializerWithStringManifest { | ||
override def identifier: Int = 1004 | ||
|
||
override def manifest(o: AnyRef): String = o.getClass.getName | ||
|
||
final val LarValidatedManifest = classOf[LarValidated].getName | ||
final val TsValidatedManifest = classOf[TsValidated].getName | ||
|
||
override def toBinary(o: AnyRef): Array[Byte] = o match { | ||
case evt: LarValidated => larValidatedToProtobuf(evt).toByteArray | ||
case evt: TsValidated => tsValidatedToProtobuf(evt).toByteArray | ||
case msg: Any => throw new RuntimeException(s"Cannot serialize this message: ${msg.toString}") | ||
} | ||
|
||
override def fromBinary(bytes: Array[Byte], manifest: String): AnyRef = manifest match { | ||
case LarValidatedManifest => | ||
larValidatedFromProtobuf(LarValidatedMessage.parseFrom(bytes)) | ||
case TsValidatedManifest => | ||
tsValidatedFromProtobuf(TsValidatedMessage.parseFrom(bytes)) | ||
case msg: Any => throw new RuntimeException(s"Cannot deserialize this message: ${msg.toString}") | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
.../scala/hmda/persistence/serialization/validation/HmdaValidatorProtobufConverterSpec.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 hmda.persistence.serialization.validation | ||
|
||
import hmda.model.fi.lar.LarGenerators | ||
import hmda.model.fi.ts.TsGenerators | ||
import hmda.model.institution.SubmissionGenerators._ | ||
import hmda.persistence.messages.events.processing.CommonHmdaValidatorEvents.{ LarValidated, TsValidated } | ||
import hmda.persistence.model.serialization.CommonHmdaValidator.{ LarValidatedMessage, TsValidatedMessage } | ||
import HmdaValidatorProtobufConverter._ | ||
import org.scalatest.prop.PropertyChecks | ||
import org.scalatest.{ MustMatchers, PropSpec } | ||
|
||
class HmdaValidatorProtobufConverterSpec extends PropSpec with PropertyChecks with MustMatchers with LarGenerators with TsGenerators { | ||
|
||
property("Lar Validated must serialize to protobuf and back") { | ||
forAll(larGen, submissionIdGen) { (lar, submissionId) => | ||
val larValidated = LarValidated(lar, submissionId) | ||
val protobuf = larValidatedToProtobuf(larValidated).toByteArray | ||
larValidatedFromProtobuf(LarValidatedMessage.parseFrom(protobuf)) mustBe larValidated | ||
} | ||
} | ||
|
||
property("Ts Validated must serialize to protobuf and back") { | ||
forAll(tsGen) { ts => | ||
val tsValidated = TsValidated(ts) | ||
val protobuf = tsValidatedToProtobuf(tsValidated).toByteArray | ||
tsValidatedFromProtobuf(TsValidatedMessage.parseFrom(protobuf)) mustBe tsValidated | ||
} | ||
} | ||
} |
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
20 changes: 0 additions & 20 deletions
20
...t/scala/hmda/persistence/serialization/validation/LarValidatedProtobufConverterSpec.scala
This file was deleted.
Oops, something went wrong.