-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* micronaut framework implemented. (#673) * micronaut framework implemented * hardcoded versions fixed, comment lines removed * Delete starters/micronaut-starter/stove-micronaut-testing-e2e directory Signed-off-by: Anılcan <[email protected]> * Delete examples/micronaut-example/.gitignore Signed-off-by: Anılcan <[email protected]> * Delete examples/micronaut-example/gradle/wrapper directory Signed-off-by: Anılcan <[email protected]> * fixed hardcoded lines * fixed test name, duplicated versions, variable name * removed packages configuration from main meth * revert gradle properties and binaryvalidator * fix micronaut bridge tests but it does not work yet --------- Signed-off-by: Anılcan <[email protected]> Signed-off-by: Oğuzhan Soykan <[email protected]> Co-authored-by: anilcan.gul <[email protected]> Co-authored-by: Oguzhan Soykan <[email protected]> * works * use different port for wiremock * add pre-commmit hook * bump version * kotest arrow * fix for api --------- Signed-off-by: Anılcan <[email protected]> Signed-off-by: Oğuzhan Soykan <[email protected]> Co-authored-by: Anılcan <[email protected]> Co-authored-by: anilcan.gul <[email protected]>
- Loading branch information
1 parent
efbbc7e
commit b441736
Showing
34 changed files
with
1,156 additions
and
19 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,73 @@ | ||
plugins { | ||
kotlin("jvm") version libs.versions.kotlin | ||
id("org.jetbrains.kotlin.plugin.allopen") version libs.versions.kotlin | ||
kotlin("plugin.serialization") version libs.versions.kotlin | ||
alias(libs.plugins.google.ksp) | ||
alias(libs.plugins.shadowJar) | ||
alias(libs.plugins.micronaut.application) | ||
alias(libs.plugins.micronaut.aot) | ||
application | ||
idea | ||
} | ||
|
||
dependencies { | ||
runtimeOnly(libs.snakeyaml) | ||
implementation(platform(libs.micronaut.parent)) | ||
implementation(libs.micronaut.kotlin.runtime) | ||
implementation(libs.micronaut.serde.jackson) | ||
implementation(libs.micronaut.http.client) | ||
implementation(libs.micronaut.http.server.netty) | ||
implementation(libs.micronaut.inject) | ||
implementation(libs.micronaut.core) | ||
implementation(libs.micronaut.micrometer.core) | ||
implementation(libs.jackson.kotlin) | ||
implementation(libs.couchbase.client.metrics) | ||
implementation(libs.kafka) | ||
implementation(libs.kotlinx.reactor) | ||
implementation(libs.kotlinx.core) | ||
implementation(libs.kotlinx.reactive) | ||
implementation(libs.couchbase.client) | ||
implementation(libs.couchbase.client.metrics) | ||
implementation(libs.jackson.kotlin) | ||
implementation(libs.kotlinx.slf4j) | ||
} | ||
|
||
dependencies { | ||
testImplementation(libs.kotest.property) | ||
testImplementation(libs.kotest.runner.junit5) | ||
testImplementation(projects.stove.lib.stoveTestingE2eHttp) | ||
testImplementation(projects.stove.lib.stoveTestingE2eWiremock) | ||
testImplementation(projects.stove.lib.stoveTestingE2eCouchbase) | ||
testImplementation(projects.stove.lib.stoveTestingE2eElasticsearch) | ||
testImplementation(projects.stove.starters.micronaut.stoveMicronautTestingE2e) | ||
} | ||
|
||
application { | ||
mainClass = "stove.micronaut.example.ApplicationKt" | ||
} | ||
|
||
graalvmNative.toolchainDetection = false | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.toVersion("17") | ||
} | ||
|
||
micronaut { | ||
version(libs.versions.micronaut.starter.get()) | ||
runtime("netty") | ||
testRuntime("kotest5") | ||
processing { | ||
incremental(true) | ||
annotations("stove.micronaut.example.*") | ||
} | ||
aot { | ||
optimizeServiceLoading = false | ||
convertYamlToJava = false | ||
precomputeOperations = true | ||
cacheEnvironment = true | ||
optimizeClassLoading = true | ||
deduceEnvironment = true | ||
optimizeNetty = true | ||
replaceLogbackXml = true | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
examples/micronaut-example/src/main/kotlin/stove/micronaut/example/Application.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,28 @@ | ||
package stove.micronaut.example | ||
|
||
import io.micronaut.context.ApplicationContext | ||
import io.micronaut.runtime.EmbeddedApplication | ||
|
||
fun main(args: Array<String>) { | ||
run(args) | ||
} | ||
|
||
fun run( | ||
args: Array<String>, | ||
init: ApplicationContext.() -> Unit = {} | ||
): ApplicationContext { | ||
val context = ApplicationContext | ||
.builder() | ||
.args(*args) | ||
.build() | ||
.also(init) | ||
.start() | ||
|
||
context.findBean(EmbeddedApplication::class.java).ifPresent { app -> | ||
if (!app.isRunning) { | ||
app.start() | ||
} | ||
} | ||
|
||
return context | ||
} |
23 changes: 23 additions & 0 deletions
23
...s/micronaut-example/src/main/kotlin/stove/micronaut/example/application/domain/Product.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,23 @@ | ||
package stove.micronaut.example.application.domain | ||
|
||
import io.micronaut.serde.annotation.Serdeable | ||
import java.util.* | ||
|
||
@Serdeable | ||
data class Product( | ||
val id: String, | ||
val name: String, | ||
val supplierId: Long, | ||
val isBlacklist: Boolean, | ||
val createdDate: Date | ||
) { | ||
companion object { | ||
fun new(id: String, name: String, supplierId: Long, isBlacklist: Boolean): Product = Product( | ||
id = id, | ||
name = name, | ||
supplierId = supplierId, | ||
createdDate = Date(), | ||
isBlacklist = isBlacklist | ||
) | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...ample/src/main/kotlin/stove/micronaut/example/application/repository/ProductRepository.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,9 @@ | ||
package stove.micronaut.example.application.repository | ||
|
||
import stove.micronaut.example.application.domain.Product | ||
|
||
interface ProductRepository { | ||
suspend fun save(product: Product): Product | ||
|
||
suspend fun findById(id: Long): Product? | ||
} |
19 changes: 19 additions & 0 deletions
19
...ut-example/src/main/kotlin/stove/micronaut/example/application/services/ProductService.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,19 @@ | ||
package stove.micronaut.example.application.services | ||
|
||
import jakarta.inject.Singleton | ||
import stove.micronaut.example.application.domain.Product | ||
import stove.micronaut.example.application.repository.ProductRepository | ||
import stove.micronaut.example.infrastructure.http.SupplierHttpService | ||
|
||
@Singleton | ||
class ProductService( | ||
private val productRepository: ProductRepository, | ||
private val supplierHttpService: SupplierHttpService | ||
) { | ||
suspend fun createProduct(id: String, productName: String, supplierId: Long): Product { | ||
val supplier = supplierHttpService.getSupplierPermission(supplierId) | ||
val product = Product.new(id, productName, supplierId, supplier!!.isBlacklisted) | ||
productRepository.save(product) | ||
return product | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...t-example/src/main/kotlin/stove/micronaut/example/application/services/SupplierService.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,13 @@ | ||
package stove.micronaut.example.application.services | ||
|
||
import io.micronaut.serde.annotation.Serdeable | ||
|
||
@Serdeable | ||
data class SupplierPermission( | ||
val id: Long, | ||
val isBlacklisted: Boolean | ||
) | ||
|
||
interface SupplierService { | ||
suspend fun getSupplierPermission(supplierId: Long): SupplierPermission? | ||
} |
25 changes: 25 additions & 0 deletions
25
...t-example/src/main/kotlin/stove/micronaut/example/infrastructure/api/ProductController.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,25 @@ | ||
package stove.micronaut.example.infrastructure.api | ||
|
||
import io.micronaut.http.annotation.* | ||
import stove.micronaut.example.application.domain.Product | ||
import stove.micronaut.example.application.services.ProductService | ||
import stove.micronaut.example.infrastructure.api.model.request.CreateProductRequest | ||
|
||
@Controller("/products") | ||
class ProductController( | ||
private val productService: ProductService | ||
) { | ||
@Get("/index") | ||
fun get( | ||
@QueryValue keyword: String = "default" | ||
): String = "Hi from Stove framework with $keyword" | ||
|
||
@Post("/create") | ||
suspend fun createProduct( | ||
@Body request: CreateProductRequest | ||
): Product = productService.createProduct( | ||
id = request.id, | ||
productName = request.name, | ||
supplierId = request.supplierId | ||
) | ||
} |
10 changes: 10 additions & 0 deletions
10
...n/kotlin/stove/micronaut/example/infrastructure/api/model/request/CreateProductRequest.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,10 @@ | ||
package stove.micronaut.example.infrastructure.api.model.request | ||
|
||
import io.micronaut.serde.annotation.Serdeable | ||
|
||
@Serdeable | ||
data class CreateProductRequest( | ||
val id: String, | ||
val name: String, | ||
val supplierId: Long | ||
) |
64 changes: 64 additions & 0 deletions
64
...rc/main/kotlin/stove/micronaut/example/infrastructure/couchbase/CouchbaseConfiguration.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,64 @@ | ||
package stove.micronaut.example.infrastructure.couchbase | ||
|
||
import com.couchbase.client.java.* | ||
import com.couchbase.client.java.Collection | ||
import com.couchbase.client.java.codec.JacksonJsonSerializer | ||
import com.couchbase.client.java.env.ClusterEnvironment | ||
import com.couchbase.client.java.json.JsonValueModule | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import io.micronaut.context.annotation.* | ||
import jakarta.annotation.PreDestroy | ||
import jakarta.inject.Singleton | ||
import java.time.Duration | ||
|
||
@Factory | ||
class CouchbaseConfiguration( | ||
private val couchbaseProperties: CouchbaseProperties | ||
) { | ||
companion object { | ||
val objectMapper: ObjectMapper = | ||
ObjectMapper() | ||
.findAndRegisterModules() | ||
.registerModule(JsonValueModule()) | ||
} | ||
|
||
@Primary | ||
@Context | ||
fun clusterEnvironment(): ClusterEnvironment { | ||
val cbSerializer = JacksonJsonSerializer.create(objectMapper) | ||
return ClusterEnvironment | ||
.builder() | ||
.timeoutConfig { | ||
it | ||
.kvTimeout(Duration.ofMillis(couchbaseProperties.kvTimeout)) | ||
.connectTimeout(Duration.ofMillis(couchbaseProperties.connectTimeout)) | ||
.queryTimeout(Duration.ofMillis(couchbaseProperties.queryTimeout)) | ||
.viewTimeout(Duration.ofMillis(couchbaseProperties.viewTimeout)) | ||
}.jsonSerializer(cbSerializer) | ||
.build() | ||
} | ||
|
||
@Primary | ||
@Singleton | ||
fun cluster(clusterEnvironment: ClusterEnvironment): Cluster { | ||
val clusterOptions = ClusterOptions | ||
.clusterOptions(couchbaseProperties.username, couchbaseProperties.password) | ||
.environment(clusterEnvironment) | ||
|
||
return Cluster.connect(couchbaseProperties.hosts.joinToString(","), clusterOptions) | ||
} | ||
|
||
@Primary | ||
@Singleton | ||
fun bucket(cluster: Cluster): Bucket = cluster.bucket(couchbaseProperties.bucketName) | ||
|
||
@Primary | ||
@Singleton | ||
fun productCouchbaseCollection(bucket: Bucket): Collection = bucket.defaultCollection() | ||
|
||
@PreDestroy | ||
fun cleanup(cluster: Cluster, clusterEnvironment: ClusterEnvironment) { | ||
cluster.disconnect() | ||
clusterEnvironment.shutdown() | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...e/src/main/kotlin/stove/micronaut/example/infrastructure/couchbase/CouchbaseProperties.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,15 @@ | ||
package stove.micronaut.example.infrastructure.couchbase | ||
|
||
import io.micronaut.context.annotation.* | ||
|
||
@ConfigurationProperties("couchbase") | ||
class CouchbaseProperties { | ||
var username: String? = null | ||
var password: String? = null | ||
var bucketName: String = "" | ||
var hosts: List<String> = listOf() | ||
var kvTimeout: Long = 0 | ||
var connectTimeout: Long = 0 | ||
var queryTimeout: Long = 0 | ||
var viewTimeout: Long = 0 | ||
} |
26 changes: 26 additions & 0 deletions
26
...le/src/main/kotlin/stove/micronaut/example/infrastructure/couchbase/ObjectMapperConfig.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 stove.micronaut.example.infrastructure.couchbase | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude | ||
import com.fasterxml.jackson.databind.DeserializationFeature | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.databind.module.SimpleModule | ||
import com.fasterxml.jackson.module.kotlin.KotlinModule | ||
import io.micronaut.context.annotation.Bean | ||
import io.micronaut.context.annotation.Factory | ||
|
||
@Factory | ||
class ObjectMapperConfig { | ||
companion object { | ||
fun createObjectMapperWithDefaults(): ObjectMapper { | ||
val isoInstantModule = SimpleModule() | ||
return ObjectMapper() | ||
.registerModule(KotlinModule.Builder().build()) | ||
.registerModule(isoInstantModule) | ||
.setSerializationInclusion(JsonInclude.Include.NON_NULL) | ||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) | ||
} | ||
} | ||
|
||
@Bean | ||
fun objectMapper(): ObjectMapper = createObjectMapperWithDefaults() | ||
} |
Oops, something went wrong.