Skip to content

Commit

Permalink
Merge branch 'release/1.11.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jangalinski committed May 26, 2024
2 parents 2cb3e53 + 407dded commit 019a1af
Show file tree
Hide file tree
Showing 332 changed files with 4,331 additions and 1,709 deletions.
2 changes: 2 additions & 0 deletions .mvn/jvm.config
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
4 changes: 2 additions & 2 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.7/apache-maven-3.9.7-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.1/maven-wrapper-3.3.1.jar
114 changes: 114 additions & 0 deletions _examples/java-example/pom.xml
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 _examples/java-example/src/main/avro/BankAccountCreated.avsc
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"
}
}
]
}
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.
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.
112 changes: 112 additions & 0 deletions _examples/kotlin-example/pom.xml
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 _examples/kotlin-example/src/main/kotlin/BankAccountCreatedData.kt
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,
)
9 changes: 9 additions & 0 deletions _examples/kotlin-example/src/main/kotlin/KotlinExample.kt
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.
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)
}
}
Loading

0 comments on commit 019a1af

Please sign in to comment.