Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: run http server tck against Micronaut Serialization Jackson #617

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ managed-jakarta-json-bindApi = "3.0.0"
managed-eclipse-parsson = "1.1.4"

micronaut-reactor = "3.0.3"
micronaut-validation = "4.0.3"

oracle-jdbc-driver = "23.3.0.23.09"
jetbrains-annotations = "24.0.1"
Expand All @@ -31,6 +32,7 @@ jmh = "1.37"
[libraries]
# Core
micronaut-core = { module = 'io.micronaut:micronaut-core-bom', version.ref = 'micronaut' }
micronaut-validation = { module = 'io.micronaut.validation:micronaut-validation-bom', version.ref = 'micronaut-validation' }

managed-bson = { module = "org.mongodb:bson", version.ref = "managed-bson" }
managed-eclipse-parsson = { module = "org.eclipse.parsson:parsson", version.ref = "managed-eclipse-parsson" }
Expand Down
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ include("benchmarks")

include("test-suite-tck-jackson-databind")
include("test-suite-tck-serde")
include("test-suite-http-server-tck-netty")

val micronautVersion = providers.gradleProperty("micronautVersion")

configure<io.micronaut.build.MicronautBuildSettingsExtension> {
useStandardizedProjectNames.set(true)
importMicronautCatalog()
importMicronautCatalog("micronaut-reactor")
importMicronautCatalog("micronaut-validation")
}
25 changes: 25 additions & 0 deletions test-suite-http-server-tck-netty/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
plugins {
java
}
repositories {
mavenCentral()
}

dependencies {
testAnnotationProcessor(platform(mn.micronaut.core.bom))
testAnnotationProcessor(mn.micronaut.inject.java)
implementation(mn.micronaut.http.server.tck) {
exclude("io.micronaut", "micronaut-jackson-databind")
}
implementation(projects.micronautSerdeJackson)
testImplementation(mn.micronaut.http.server.netty)
testImplementation(mn.micronaut.http.client)
testImplementation(libs.junit.platform.engine)
testImplementation(libs.junit.jupiter.engine)
runtimeOnly(mnLogging.logback.classic)
testAnnotationProcessor(mnValidation.micronaut.validation.processor)
testImplementation(mnValidation.micronaut.validation)
}
tasks.withType<Test> {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2017-2023 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.serde.http.server.tck.netty;

import org.junit.platform.suite.api.ExcludeClassNamePatterns;
import org.junit.platform.suite.api.SelectPackages;
import org.junit.platform.suite.api.Suite;
import org.junit.platform.suite.api.SuiteDisplayName;

@Suite
@ExcludeClassNamePatterns("io.micronaut.http.server.tck.tests.constraintshandler.ControllerConstraintHandlerTest")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a weird test, it relies on a NonNull parameter being set to null and then failing later in constraint validation, which works with jackson-databind (doesnt care about NonNull) but not serde. serde's behavior is fine here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't a weird test. It describes a scenario many users will anticipate to work. Myself included. You create a controller with a POJO with the nullability annotations. The POJO describes the valid payload of your endpoint. The person invoking the API does not supply a valid JSON. You expect the object to be populated with the available information and the validation submission to be triggered so that you can handle the ConstraintViolationException. What are you working on

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NonNull is not a validation annotation though, it is more fundamental and is checked at a different stage than validation annotations. I see your point, but we can't throw ConstraintViolationException from serde, it's not even on the compile path. And we made the explicit choice to check for null in serde.

Consider it from a different angle. If the JSON included {\"username\":{},\"password\":\"secret\"} (entirely wrong type for username), then both jackson-databind and serde will fail with not-a-ConstraintViolationException. Serde just extends this same behavior to null (or in this case missing fields). The line between a type error and a constraint error has to be drawn somewhere, and serde (intentionally) checks nulls.

@SelectPackages({
"io.micronaut.http.server.tck.tests",
"io.micronaut.serde.http.server.tck.netty"
})
@SuiteDisplayName("HTTP Server TCK for Netty")
public class NettyHttpServerTestSuite {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.micronaut.http.tck.EmbeddedServerUnderTestProvider
17 changes: 17 additions & 0 deletions test-suite-http-server-tck-netty/src/test/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<root level="info">
<appender-ref ref="STDOUT" />
</root>

<logger name="io.micronaut.http.client" level="trace" />
</configuration>

Loading