Skip to content

Commit

Permalink
test: add embedded avro test case
Browse files Browse the repository at this point in the history
  • Loading branch information
rbalaban-mdsol committed Oct 31, 2022
1 parent da72a72 commit 0263d72
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
@@ -1,11 +1,6 @@
package io.epiphanous.flinkrunner.model

import com.typesafe.config.{
Config,
ConfigFactory,
ConfigObject,
ConfigOriginFactory
}
import com.typesafe.config.{Config, ConfigFactory, ConfigObject, ConfigOriginFactory}
import com.typesafe.scalalogging.LazyLogging
import io.epiphanous.flinkrunner.util.ConfigToProps.RichConfigObject
import io.epiphanous.flinkrunner.util.FileUtils.getResourceOrFile
Expand Down
Expand Up @@ -43,4 +43,6 @@ class ConfluentAvroRegistryKafkaRecordDeserializationSchemaTest
collected.head shouldEqual aWrapper
}



}
34 changes: 28 additions & 6 deletions src/test/scala/io/epiphanous/flinkrunner/util/AvroUtilsTest.scala
@@ -1,12 +1,7 @@
package io.epiphanous.flinkrunner.util

import io.epiphanous.flinkrunner.PropSpec
import io.epiphanous.flinkrunner.model.{
BRecord,
BWrapper,
FlinkConfig,
MyAvroADT
}
import io.epiphanous.flinkrunner.model.{BRecord, BWrapper, CRecord, FlinkConfig, MyAvroADT}
import io.epiphanous.flinkrunner.util.AvroUtils.GenericToSpecific
import org.apache.avro.SchemaBuilder
import org.apache.avro.generic.{GenericRecord, GenericRecordBuilder}
Expand All @@ -23,6 +18,15 @@ class AvroUtilsTest extends PropSpec {
.set("b3", spec.b3.toEpochMilli)
.build()

def fromSpecCRecord(spec: CRecord): GenericRecord =
new GenericRecordBuilder(CRecord.SCHEMA$)
.set("id", spec.id)
.set("cOptInt", spec.cOptInt.getOrElse(null))
.set("cOptDouble", spec.cOptDouble.getOrElse(null))
.set("bRecord", spec.bRecord.getOrElse(null))
.set("ts", spec.ts.toEpochMilli)
.build()

property("isGeneric property") {
AvroUtils.isGeneric(classOf[GenericRecord]) shouldEqual true
AvroUtils.isGeneric(classOf[BRecord]) shouldEqual false
Expand All @@ -41,6 +45,24 @@ class AvroUtilsTest extends PropSpec {
}
}

property("GenericToSpecific embedded Avro") {
forAll { c: CRecord =>
val v = fromSpecCRecord(c)
val s = v.toSpecific(new CRecord())
print(s)
s shouldEqual c
}
}

property("instanceOf property embedded avro") {
val x = AvroUtils.instanceOf(classOf[CRecord])
val y = new CRecord()
x.id shouldEqual y.id
x.cOptInt shouldEqual y.cOptInt
x.cOptDouble shouldEqual y.cOptDouble
x.bRecord shouldEqual y.bRecord
}

property("instanceOf property") {
val x = AvroUtils.instanceOf(classOf[BRecord])
val y = new BRecord()
Expand Down

0 comments on commit 0263d72

Please sign in to comment.