generated from micronaut-projects/micronaut-project-template
-
Notifications
You must be signed in to change notification settings - Fork 16
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,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() | ||
} |
31 changes: 31 additions & 0 deletions
31
...etty/src/test/java/io/micronaut/serde/http/server/tck/netty/NettyHttpServerTestSuite.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,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") | ||
@SelectPackages({ | ||
"io.micronaut.http.server.tck.tests", | ||
"io.micronaut.serde.http.server.tck.netty" | ||
}) | ||
@SuiteDisplayName("HTTP Server TCK for Netty") | ||
public class NettyHttpServerTestSuite { | ||
} |
1 change: 1 addition & 0 deletions
1
...-netty/src/test/resources/META-INF/services/io.micronaut.http.tck.ServerUnderTestProvider
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 @@ | ||
io.micronaut.http.tck.EmbeddedServerUnderTestProvider |
17 changes: 17 additions & 0 deletions
17
test-suite-http-server-tck-netty/src/test/resources/logback.xml
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,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> | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test fails for serde https://github.com/micronaut-projects/micronaut-core/blob/4.2.x/http-server-tck/src/main/java/io/micronaut/http/server/tck/tests/constraintshandler/ControllerConstraintHandlerTest.java#L118-L119
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 onThere was a problem hiding this comment.
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.