Skip to content

Commit

Permalink
FDP-1880: Update to Java 21 and Spring Boot 3.2
Browse files Browse the repository at this point in the history
Signed-off-by: Jasper Kamerling <jasper.kamerling@alliander.com>
  • Loading branch information
jasperkamerling committed Jan 8, 2024
1 parent 2f24d9e commit f731fdd
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 71 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ out/

### VS Code ###
.vscode/

### Californium ###
Californium3.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.core.io.ClassPathResource
import java.net.URI
import java.time.Duration

@SpringBootTest
class SimulatorIntegrationTest {
@Value("\${simulator.config.port}")
private lateinit var port: String
@Value("\${simulator.config.uri}")
private lateinit var uri: URI

private lateinit var coapServer: CoapServer
private val coapResourceStub = CoapResourceStub()
Expand All @@ -29,7 +30,7 @@ class SimulatorIntegrationTest {
@BeforeEach
fun setup() {
coapServer = CoapServer(Configuration.getStandard())
coapServer.addEndpoint(CoapServerHelpers.createEndpoint(Configuration.getStandard(), port.toInt()))
coapServer.addEndpoint(CoapServerHelpers.createEndpoint(Configuration.getStandard(), uri.port))
coapServer.add(coapResourceStub)
coapServer.start()
}
Expand Down
16 changes: 2 additions & 14 deletions application/src/integrationTest/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,8 @@ simulator:
message-path: "messages/kod-message.json"
# Simulator will produce valid/invalid CBOR messages
produce-valid-cbor: true
# flag used for switching between local and remote testing
local-testing: true
# flag used for switching between coap and coaps (dtls)
use-dtls: false
# port used for coap
port: 55683
# port used for coaps (dtls)
dtls-port: 55684
# host used for local testing
local-host: localhost
# host used for remote testing
remote-host: 18.184.44.224
# coap resource path
path: "coap-path"
# Uri of the target coap server
uri: coap://localhost:55684/coap-path
# pre-shared key for coaps (dtls)
# pskIdentity: coap_simulator
# pskKey: coaps_secret_key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class CaliforniumConfiguration(private val simulatorProperties: SimulatorPropert
@Bean
fun configure(): Configuration {
return Configuration.getStandard()
.set(CoapConfig.COAP_PORT, simulatorProperties.port)
.set(CoapConfig.COAP_SECURE_PORT, simulatorProperties.dtlsPort)
.set(CoapConfig.COAP_PORT, simulatorProperties.uri.port)
.set(CoapConfig.COAP_SECURE_PORT, simulatorProperties.uri.port)
.set(DtlsConfig.DTLS_ROLE, DtlsRole.CLIENT_ONLY)
.set(DtlsConfig.DTLS_CIPHER_SUITES, listOf(CipherSuite.TLS_PSK_WITH_AES_256_CCM_8))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package org.gxf.crestdevicesimulator.configuration

import org.eclipse.californium.core.CoapClient
import org.eclipse.californium.core.coap.CoAP
import org.eclipse.californium.core.network.CoapEndpoint
import org.eclipse.californium.elements.config.Configuration
import org.eclipse.californium.scandium.DTLSConnector
Expand All @@ -23,9 +24,9 @@ class CoapClientConfiguration(private val configuration: Configuration,

@Bean
fun coapClient(dtlsConnector: DTLSConnector): CoapClient {
val uri = this.getUri()
val uri = simulatorProperties.uri
val coapClient = CoapClient(uri)
if (this.simulatorProperties.useDtls) {
if (uri.scheme == CoAP.COAP_SECURE_URI_SCHEME) {
val endpoint = CoapEndpoint.Builder()
.setConfiguration(configuration)
.setConnector(dtlsConnector)
Expand All @@ -35,16 +36,6 @@ class CoapClientConfiguration(private val configuration: Configuration,
return coapClient
}

private fun getUri(): String {
with(this.simulatorProperties) {
val protocol = if (useDtls) "coaps" else "coap"
val host = if (localTesting) localHost else remoteHost
val port = if (useDtls) dtlsPort else port
val path = path
return String.format("%s://%s:%d/%s", protocol, host, port, path)
}
}

@Bean
fun dtlsConnector(advancedSingleIdentityPskStore: AdvancedSingleIdentityPskStore): DTLSConnector {
val address = InetSocketAddress(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@
package org.gxf.crestdevicesimulator.configuration

import org.springframework.boot.context.properties.ConfigurationProperties
import java.net.URI

@ConfigurationProperties(prefix = "simulator.config")
class SimulatorProperties(
val localTesting: Boolean,
val useDtls: Boolean,
val port: Int,
val dtlsPort: Int,
val localHost: String,
val remoteHost: String,
val path: String,
val uri: URI,
val pskIdentity: String,
val pskKey: String,
val messagePath: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.dataformat.cbor.databind.CBORMapper

object CborFactory {
val invalidCborMessage = "B36249441B000313"
const val INVALID_CBOR_MESSAGE = "B36249441B000313"

fun createValidCbor(jsonNode: JsonNode): ByteArray = CBORMapper().writeValueAsBytes(jsonNode)

fun createInvalidCbor(): ByteArray = invalidCborMessage.toByteArray()
fun createInvalidCbor(): ByteArray = INVALID_CBOR_MESSAGE.toByteArray()
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package org.gxf.crestdevicesimulator.simulator

import com.fasterxml.jackson.databind.ObjectMapper
import mu.KotlinLogging
import io.github.oshai.kotlinlogging.KotlinLogging
import org.eclipse.californium.core.CoapClient
import org.eclipse.californium.core.coap.MediaTypeRegistry
import org.eclipse.californium.core.coap.Request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

package org.gxf.crestdevicesimulator.simulator.response

import mu.KotlinLogging
import io.github.oshai.kotlinlogging.KotlinLogging
import org.eclipse.californium.core.CoapResponse
import org.gxf.crestdevicesimulator.configuration.AdvancedSingleIdentityPskStore
import org.gxf.crestdevicesimulator.configuration.SimulatorProperties
Expand Down
16 changes: 2 additions & 14 deletions application/src/main/resources/application-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,8 @@ simulator:
message-path: "messages/kod-alarm-message.json"
# Simulator will produce valid/invalid CBOR messages
produce-valid-cbor: true
# flag used for switching between local and remote testing
local-testing: true
# flag used for switching between coap and coaps (dtls)
use-dtls: true
# port used for coap
port: 55683
# port used for coaps (dtls)
dtls-port: 55684
# host used for local testing
local-host: localhost
# host used for remote testing
remote-host: 18.184.44.224
# coap resource path
path: "sng"
# Uri of the target coap server
uri: coaps://localhost:55684/sng
# pre-shared key for coaps (dtls)
# pskIdentity: coap_simulator
# pskKey: coaps_secret_key
Expand Down
2 changes: 1 addition & 1 deletion application/src/test/kotlin/SimulatorTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class SimulatorTests {
simulator.sendPostMessage()

Mockito.verify(coapClient).advanced(argument.capture())
Assertions.assertEquals(CborFactory.invalidCborMessage, argument.value.payloadString)
Assertions.assertEquals(CborFactory.INVALID_CBOR_MESSAGE, argument.value.payloadString)
}

@Test
Expand Down
19 changes: 9 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import io.spring.gradle.dependencymanagement.internal.dsl.StandardDependencyMana
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("org.springframework.boot") version "3.1.6" apply false
id("io.spring.dependency-management") version "1.1.3" apply false
kotlin("jvm") version "1.9.10" apply false
kotlin("plugin.spring") version "1.9.10" apply false
kotlin("plugin.jpa") version "1.9.10" apply false
id("com.github.davidmc24.gradle.plugin.avro") version "1.8.0" apply false
id("org.sonarqube") version "4.2.1.3168"
id("org.springframework.boot") version "3.2.1" apply false
id("io.spring.dependency-management") version "1.1.4" apply false
kotlin("jvm") version "1.9.22" apply false
kotlin("plugin.spring") version "1.9.22" apply false
kotlin("plugin.jpa") version "1.9.22" apply false
id("com.github.davidmc24.gradle.plugin.avro") version "1.9.1" apply false
id("org.sonarqube") version "4.4.1.3373"
id("eclipse")
}

Expand All @@ -26,7 +26,6 @@ sonarqube {
property("sonar.gradle.skipCompile", true)
}
}
tasks.sonar

subprojects {
apply(plugin = "org.jetbrains.kotlin.jvm")
Expand All @@ -46,7 +45,7 @@ subprojects {

extensions.configure<JavaPluginExtension> {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
languageVersion.set(JavaLanguageVersion.of(21))
}
}

Expand All @@ -59,7 +58,7 @@ subprojects {
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "17"
jvmTarget = "21"
}
}

Expand Down
8 changes: 4 additions & 4 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: Apache-2.0

rootProject.name = "crest-device-simulator"
rootProject.name = "sng-crest-device-simulator"

include("application")

Expand All @@ -14,11 +14,11 @@ dependencyResolutionManagement {
library("californium-scandium", "org.eclipse.californium", "scandium").versionRef("californium")
bundle("californium", listOf("californium-core", "californium-scandium"))

library("postgresql", "org.postgresql", "postgresql").version("42.5.4")
library("flyway", "org.flywaydb", "flyway-core").version("9.22.3")
library("postgresql", "org.postgresql", "postgresql").withoutVersion()
library("flyway", "org.flywaydb", "flyway-core").withoutVersion()
bundle("data", listOf("postgresql", "flyway"))

library("logging", "io.github.microutils", "kotlin-logging-jvm").version("3.0.5")
library("logging", "io.github.oshai", "kotlin-logging-jvm").version("6.0.1")
}
create("integrationTestLibs") {
library("h2", "com.h2database", "h2").version("2.2.224")
Expand Down

0 comments on commit f731fdd

Please sign in to comment.