-
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.
- Loading branch information
Showing
332 changed files
with
4,331 additions
and
1,709 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--add-opens=java.base/java.lang=ALL-UNNAMED | ||
--add-opens=java.base/java.io=ALL-UNNAMED |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>io.toolisticon.kotlin.avro._</groupId> | ||
<artifactId>avro-kotlin-examples-root</artifactId> | ||
<version>1.11.4.0</version> | ||
</parent> | ||
|
||
<groupId>io.toolisticon.kotlin.avro.examples</groupId> | ||
<artifactId>java-example</artifactId> | ||
<name>example: ${project.artifactId}</name> | ||
<description>Java app using libs.</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.toolisticon.kotlin.avro.examples</groupId> | ||
<artifactId>logical-type-money</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.toolisticon.kotlin.avro.examples</groupId> | ||
<artifactId>logical-type-customer-id</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.toolisticon.kotlin.avro.test</groupId> | ||
<artifactId>avro-kotlin-test</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.avro</groupId> | ||
<artifactId>avro-compiler</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.fasterxml.jackson.module</groupId> | ||
<artifactId>jackson-module-kotlin</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-simple</artifactId> | ||
<version>2.0.13</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<!-- configure to be an ordinary Java Project --> | ||
<sourceDirectory>src/main/java</sourceDirectory> | ||
<testSourceDirectory>src/test/java</testSourceDirectory> | ||
|
||
<plugins> | ||
<plugin> | ||
<!-- kotlin compiler --> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-plugin</artifactId> | ||
<configuration> | ||
<skip>true</skip> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.avro</groupId> | ||
<artifactId>avro-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals><goal>schema</goal></goals> | ||
</execution> | ||
</executions> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.toolisticon.kotlin.avro.examples</groupId> | ||
<artifactId>logical-type-money</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.toolisticon.kotlin.avro.examples</groupId> | ||
<artifactId>logical-type-customer-id</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>build-helper-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<phase>generate-sources</phase> | ||
<goals> | ||
<goal>add-source</goal> | ||
</goals> | ||
<configuration> | ||
<sources> | ||
<source>${kp.generatedSources}/avro</source> | ||
</sources> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
27 changes: 27 additions & 0 deletions
27
_examples/java-example/src/main/avro/BankAccountCreated.avsc
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,27 @@ | ||
{ | ||
"name": "BankAccountCreated", | ||
"namespace": "io.toolisticon.example.bank", | ||
"type": "record", | ||
"fields": [ | ||
{ | ||
"name": "accountId", | ||
"type": { | ||
"type": "string", | ||
"logicalType": "uuid" | ||
} | ||
}, | ||
{ | ||
"name": "customerId", | ||
"type": { | ||
"type": "string" | ||
} | ||
}, | ||
{ | ||
"name": "initialBalance", | ||
"type": { | ||
"type": "string", | ||
"logicalType": "money" | ||
} | ||
} | ||
] | ||
} |
6 changes: 6 additions & 0 deletions
6
...mples/java-example/src/main/java/io/toolisticon/kotlin/avro/example/java/JavaExample.java
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,6 @@ | ||
package io.toolisticon.kotlin.avro.example.java; | ||
|
||
public enum JavaExample { | ||
; | ||
// empty | ||
} |
File renamed without changes.
34 changes: 34 additions & 0 deletions
34
...example/src/test/java/io/toolisticon/kotlin/avro/example/java/BankAccountCreatedTest.java
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 io.toolisticon.kotlin.avro.example.java; | ||
|
||
import io.toolisticon.example.bank.BankAccountCreated; | ||
import org.javamoney.moneta.Money; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.UUID; | ||
|
||
import static io.toolisticon.kotlin.avro.AvroKotlin.avroSchemaResolver; | ||
import static io.toolisticon.kotlin.avro.codec.SpecificRecordCodec.specificRecordSingleObjectDecoder; | ||
import static io.toolisticon.kotlin.avro.codec.SpecificRecordCodec.specificRecordSingleObjectEncoder; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class BankAccountCreatedTest { | ||
|
||
@Test | ||
void encodeAndDecodeEventWithMoneyLogicalType() { | ||
//CustomerId customerId = CustomerId.of("1"); | ||
final BankAccountCreated bankAccountCreated = BankAccountCreated.newBuilder() | ||
.setAccountId(UUID.randomUUID()) | ||
.setCustomerId("1") | ||
.setInitialBalance(Money.of(100.123456, "EUR")) | ||
.build(); | ||
final var resolver = avroSchemaResolver(BankAccountCreated.getClassSchema()); | ||
|
||
final var encoded = specificRecordSingleObjectEncoder().encode(bankAccountCreated); | ||
|
||
final BankAccountCreated decoded = (BankAccountCreated) specificRecordSingleObjectDecoder(resolver).decode(encoded); | ||
|
||
assertThat(decoded.getAccountId()).isEqualTo(bankAccountCreated.getAccountId()); | ||
assertThat(decoded.getCustomerId()).isEqualTo("1"); | ||
assertThat(decoded.getInitialBalance()).isEqualTo(Money.of(100.12, "EUR")); | ||
} | ||
} |
Empty file.
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,112 @@ | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>io.toolisticon.kotlin.avro._</groupId> | ||
<artifactId>avro-kotlin-examples-root</artifactId> | ||
<version>1.11.4.0</version> | ||
</parent> | ||
|
||
<groupId>io.toolisticon.kotlin.avro.examples</groupId> | ||
<artifactId>kotlin-example</artifactId> | ||
<name>example: ${project.artifactId}</name> | ||
<description>Kotlin app using libs.</description> | ||
|
||
<dependencies> | ||
<!-- KOTLIN --> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-stdlib</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-reflect</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.github.microutils</groupId> | ||
<artifactId>kotlin-logging-jvm</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<!-- /KOTLIN --> | ||
|
||
<dependency> | ||
<groupId>io.toolisticon.kotlin.avro</groupId> | ||
<artifactId>avro-kotlin-serialization</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.toolisticon.kotlin.avro.examples</groupId> | ||
<artifactId>logical-type-money</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.toolisticon.kotlin.avro.examples</groupId> | ||
<artifactId>logical-type-customer-id</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.toolisticon.kotlin.avro.examples</groupId> | ||
<artifactId>java-example</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.toolisticon.kotlin.avro.test</groupId> | ||
<artifactId>avro-kotlin-test</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.avro</groupId> | ||
<artifactId>avro-compiler</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.fasterxml.jackson.module</groupId> | ||
<artifactId>jackson-module-kotlin</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<!-- kotlin compiler --> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-plugin</artifactId> | ||
<configuration> | ||
<jvmTarget>${java.version}</jvmTarget> | ||
<apiVersion>1.9</apiVersion> | ||
<languageVersion>1.9</languageVersion> | ||
<args> | ||
<arg>-Xjsr305=strict</arg> | ||
</args> | ||
<compilerPlugins> | ||
<plugin>no-arg</plugin> | ||
<plugin>all-open</plugin> | ||
<plugin>kotlinx-serialization</plugin> | ||
</compilerPlugins> | ||
<pluginOptions> | ||
<!-- <option>all-open:annotation=...fqn...</option>--> | ||
</pluginOptions> | ||
</configuration> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-serialization</artifactId> | ||
<version>${kotlin.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
26 changes: 26 additions & 0 deletions
26
_examples/kotlin-example/src/main/kotlin/BankAccountCreatedData.kt
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 io.toolisticon.kotlin.avro.example | ||
|
||
import com.github.avrokotlin.avro4k.AvroName | ||
import com.github.avrokotlin.avro4k.AvroNamespace | ||
import com.github.avrokotlin.avro4k.serializer.UUIDSerializer | ||
import io.toolisticon.kotlin.avro.example.customerid.CustomerId | ||
import io.toolisticon.kotlin.avro.example.customerid.CustomerIdLogicalType | ||
import io.toolisticon.kotlin.avro.example.money.MoneyLogicalType.MoneySerializer | ||
import kotlinx.serialization.Serializable | ||
import org.javamoney.moneta.Money | ||
import java.util.* | ||
|
||
@Serializable | ||
@AvroName("BankAccountCreated") | ||
@AvroNamespace("io.toolisticon.bank") | ||
data class BankAccountCreatedData( | ||
|
||
@Serializable(with = UUIDSerializer::class) | ||
val accountId: UUID, | ||
|
||
@Serializable(with = CustomerIdLogicalType.CustomerIdSerializer::class) | ||
val customerId: CustomerId, | ||
|
||
@Serializable(with = MoneySerializer::class) | ||
val initialBalance: Money, | ||
) |
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,9 @@ | ||
package io.toolisticon.kotlin.avro.example | ||
|
||
import io.toolisticon.kotlin.avro.serialization.AvroKotlinSerialization | ||
|
||
object KotlinExample { | ||
|
||
val avro = AvroKotlinSerialization() | ||
|
||
} |
Empty file.
44 changes: 44 additions & 0 deletions
44
_examples/kotlin-example/src/test/kotlin/BankAccountCreatedDataTest.kt
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,44 @@ | ||
package io.toolisticon.kotlin.avro.example | ||
|
||
import io.toolisticon.kotlin.avro.codec.GenericRecordCodec | ||
import io.toolisticon.kotlin.avro.example.customerid.CustomerId | ||
import io.toolisticon.kotlin.avro.example.money.MoneyLogicalType | ||
import io.toolisticon.kotlin.avro.repository.avroSchemaResolver | ||
import io.toolisticon.kotlin.avro.value.CanonicalName.Companion.toCanonicalName | ||
import io.toolisticon.kotlin.avro.value.Name.Companion.toName | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.javamoney.moneta.Money | ||
import org.junit.jupiter.api.Test | ||
import java.util.* | ||
|
||
internal class BankAccountCreatedDataTest { | ||
|
||
@Test | ||
fun `show schema`() { | ||
val schema = KotlinExample.avro.schema(BankAccountCreatedData::class) | ||
println(schema) | ||
assertThat(schema.canonicalName).isEqualTo("io.toolisticon.bank.BankAccountCreated".toCanonicalName()) | ||
assertThat(schema.fields).hasSize(3) | ||
|
||
val props = schema.getField("initialBalance")?.properties | ||
assertThat(schema.getField("initialBalance".toName())?.schema?.logicalTypeName).isEqualTo(MoneyLogicalType.name) | ||
} | ||
|
||
@Test | ||
fun `serialize single object with uuid customerId and money`() { | ||
val amount = Money.of(10, "EUR") | ||
val accountId = UUID.randomUUID() | ||
val customerId = CustomerId.random() | ||
|
||
val event = BankAccountCreatedData(accountId, customerId, amount) | ||
val resolver = avroSchemaResolver(KotlinExample.avro.schema(BankAccountCreatedData::class)) | ||
|
||
val record = KotlinExample.avro.toRecord(event) | ||
|
||
val json = GenericRecordCodec.encodeJson(record) | ||
|
||
val decodedRecord = GenericRecordCodec.decodeJson(json, KotlinExample.avro.schema(BankAccountCreatedData::class)) | ||
|
||
assertThat(KotlinExample.avro.fromRecord(record, BankAccountCreatedData::class)).isEqualTo(event) | ||
} | ||
} |
Oops, something went wrong.