Skip to content

Commit

Permalink
Merge 3.10.x into 4.0.x (#9404)
Browse files Browse the repository at this point in the history
* Bump micronaut-sql to 4.6.7 (#8868)

* Bump micronaut-kubernetes to 3.4.1 (#9037)

* Update netty monorepo to v4.1.92.Final (#9277)

see: https://netty.io/news/2023/04/25/4-1-92-Final.html

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* test: Writable in Controller and Filter (#9286)

* TCK Test for JSON additional types codec (#9272)

* test: additional types for json codec

add JSON additional types codec

* use lower kebap case for configuration

* add more tests

* Remove test limitation for TCK (#9317)

* Add test for `@Body` not being required in 3.9.x (#9318)

* Add test for `@Body` not being required in 3.9.x

This should be removed in 4.0.0 as the annotation is required

* Add test for with the annotation

* Bump micronaut-aws to 3.17.3 (#9368)

* TCK tests for boolean textplain and default media type for String return type (#9314)

* TCK Test txt media type boolean response

* TCK tests

* add license

* Bump micronaut-servlet to 3.3.7 (#9398)

* Bump micronaut-maven-plugin to 3.5.4 (#9370)

* build: Micronaut Build plugin to 5.4.9

* [skip ci] Release v3.9.3

* Back to 3.9.4-SNAPSHOT

* build. update to Netty 4.1.93 (#9401)

* checkstyle

---------

Co-authored-by: micronaut-build <65172877+micronaut-build@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Graeme Rocher <graeme.rocher@oracle.com>
Co-authored-by: Tim Yates <tim.yates@gmail.com>
Co-authored-by: micronaut-build <micronaut-build-account@grails.org>
  • Loading branch information
6 people authored Jun 7, 2023
1 parent d022519 commit 41dc562
Show file tree
Hide file tree
Showing 7 changed files with 385 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import io.micronaut.http.HttpHeaders;
import io.micronaut.http.HttpRequest;
import io.micronaut.http.HttpStatus;
import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
import io.micronaut.http.annotation.RouteCondition;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright 2017-2022 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.http.server.tck.tests;

import io.micronaut.context.annotation.Requires;
import io.micronaut.core.annotation.Introspected;
import io.micronaut.http.HttpRequest;
import io.micronaut.http.HttpStatus;
import io.micronaut.http.annotation.Body;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Post;
import io.micronaut.http.tck.AssertionUtils;
import io.micronaut.http.tck.HttpResponseAssertion;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import static io.micronaut.http.tck.TestScenario.asserts;

@SuppressWarnings({
"java:S5960", // We're allowed assertions, as these are used in tests only
"checkstyle:MissingJavadocType",
"checkstyle:DesignForExtension"
})
public class MissingBodyAnnotationTest {

public static final String SPEC_NAME = "MissingBodyAnnotationTest";

/**
* Test that we can use a body argument without the @Body annotation.
* @throws IOException IOException
* @see <a href="https://github.com/micronaut-projects/micronaut-core/blob/37874c634202233f35b7c9376a5edfd5d49861f2/src/main/docs/guide/appendix/breaks.adoc#body-annotation-on-controller-parameters">the breaking changes</a>
*/
@Disabled("Since Micronaut Framework the @Body annotation is required.")
@Test
void testBodyAnnotationMissing() throws IOException {
asserts(SPEC_NAME,
HttpRequest.POST("/missing-body-annotation-test/absent", new Dto("tim")),
(server, request) -> AssertionUtils.assertDoesNotThrow(server, request, HttpResponseAssertion.builder()
.status(HttpStatus.OK)
.body("tim")
.build()));
}

@Test
void testBodyAnnotationPresent() throws IOException {
asserts(SPEC_NAME,
HttpRequest.POST("/missing-body-annotation-test/present", new Dto("tim")),
(server, request) -> AssertionUtils.assertDoesNotThrow(server, request, HttpResponseAssertion.builder()
.status(HttpStatus.OK)
.body("tim")
.build()));
}

@Controller("/missing-body-annotation-test")
@Requires(property = "spec.name", value = SPEC_NAME)
static class BodyController {

@Post("/absent")
String absent(Dto dto) {
return dto.getValue();
}

@Post("/present")
String present(@Body Dto dto) {
return dto.getValue();
}
}

@Introspected
static class Dto {

private final String value;

public Dto(String value) {
this.value = value;
}

public String getValue() {
return value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ Map<String, Object> indexfluxfilter() {
@Requires(property = "spec.name", value = SPEC_NAME)
@Filter("/html/writablefluxfilter")
static class MockFilter implements HttpServerFilter {

@Override
public Publisher<MutableHttpResponse<?>> doFilter(HttpRequest<?> request, ServerFilterChain chain) {
return Flux.from(chain.proceed(request))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* 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.http.server.tck.tests.codec;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.micronaut.context.annotation.Requires;
import io.micronaut.core.annotation.Introspected;
import io.micronaut.http.HttpHeaders;
import io.micronaut.http.HttpRequest;
import io.micronaut.http.HttpStatus;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
import io.micronaut.http.annotation.Produces;
import io.micronaut.http.tck.AssertionUtils;
import io.micronaut.http.tck.BodyAssertion;
import io.micronaut.http.tck.HttpResponseAssertion;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.Collections;
import java.util.Map;

import static io.micronaut.http.tck.TestScenario.asserts;
import static org.junit.jupiter.api.Assertions.assertEquals;


@SuppressWarnings({
"java:S5960", // We're allowed assertions, as these are used in tests only
"checkstyle:MissingJavadocType",
"checkstyle:DesignForExtension"
})
public class JsonCodeAdditionalTypeTest {
public static final String SPEC_NAME = "JsonCodeAdditionalTypeTest";
public static final String APPLICATION_JSON_FEED = "application/json+feed";

@Test
void itIsPossibleToCanRegisterAdditionTypesForJsonCodec() throws IOException {
HttpResponseAssertion assertion = HttpResponseAssertion.builder()
.body(BodyAssertion.builder().body("https://jsonfeed.org").contains())
.status(HttpStatus.OK)
.assertResponse(response -> assertEquals(APPLICATION_JSON_FEED, response.header("Content-Type"))).build();

Map<String, Object> config = Collections.singletonMap("micronaut.codec.json.additional-types", Collections.singletonList(APPLICATION_JSON_FEED));
asserts(SPEC_NAME,
config,
HttpRequest.GET("/json-additional-codec").header(HttpHeaders.ACCEPT, APPLICATION_JSON_FEED),
(server, request) -> AssertionUtils.assertDoesNotThrow(server, request, assertion));

asserts(SPEC_NAME,
config,
HttpRequest.GET("/json-additional-codec/pojo").header(HttpHeaders.ACCEPT, APPLICATION_JSON_FEED),
(server, request) -> AssertionUtils.assertDoesNotThrow(server, request, assertion));
}

@Requires(property = "spec.name", value = SPEC_NAME)
@Controller
static class JsonFeedController {

@Produces(APPLICATION_JSON_FEED)
@Get("/json-additional-codec")
String index() {
return "{\n" +
" \"version\": \"https://jsonfeed.org/version/1\",\n" +
" \"title\": \"My Example Feed\",\n" +
" \"home_page_url\": \"https://example.org/\",\n" +
" \"feed_url\": \"https://example.org/feed.json\",\n" +
" ]\n" +
"}";
}

@Produces(APPLICATION_JSON_FEED)
@Get("/json-additional-codec/pojo")
JsonFeed pojo() {
return new JsonFeed("https://jsonfeed.org/version/1", "My Example Feed", "https://example.org/", "https://example.org/feed.json");
}
}

@Introspected
static class JsonFeed {
private final String version;
private final String title;
@JsonProperty("home_page_url")
private final String homePageUrl;
@JsonProperty("feed_url")
private final String feedUrl;

public JsonFeed(String version, String title, String homePageUrl, String feedUrl) {
this.version = version;
this.title = title;
this.homePageUrl = homePageUrl;
this.feedUrl = feedUrl;
}

public String getVersion() {
return version;
}

public String getTitle() {
return title;
}

public String getHomePageUrl() {
return homePageUrl;
}

public String getFeedUrl() {
return feedUrl;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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.http.server.tck.tests.mediatype;

import io.micronaut.context.annotation.Requires;
import io.micronaut.http.HttpRequest;
import io.micronaut.http.HttpStatus;
import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
import io.micronaut.http.tck.AssertionUtils;
import io.micronaut.http.tck.BodyAssertion;
import io.micronaut.http.tck.HttpResponseAssertion;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import static io.micronaut.http.tck.TestScenario.asserts;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

@SuppressWarnings({
"java:S5960", // We're allowed assertions, as these are used in tests only
"checkstyle:MissingJavadocType",
"checkstyle:DesignForExtension"
})
public class StringDefaultMediaTypeTest {
public static final String SPEC_NAME = "StringDefaultMediaTypeTest";
private static final HttpResponseAssertion ASSERTION = HttpResponseAssertion.builder()
.status(HttpStatus.OK)
.body(BodyAssertion.builder().body("Hello World").equals())
.assertResponse(response -> {
assertTrue(response.getContentType().isPresent());
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getContentType().get());
}).build();

@Test
void jsonIsDefaultMediaTypeForString() throws IOException {
asserts(SPEC_NAME,
HttpRequest.GET("/str"),
(server, request) -> AssertionUtils.assertDoesNotThrow(server, request, ASSERTION));
}

@Controller("/str")
@Requires(property = "spec.name", value = SPEC_NAME)
static class StrDefaultEncoding {
@Get
String index() {
return "Hello World";
}
}
}
Loading

0 comments on commit 41dc562

Please sign in to comment.