From ac84a1fce762fe603ccc109230cdecfd6fe7e6bd Mon Sep 17 00:00:00 2001 From: chenglu Date: Mon, 25 Apr 2022 15:31:28 +0800 Subject: [PATCH 01/13] [Integration test] remove the jaxrs in spring mvc test project. --- restlight-integration-test/springmvc-test/pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/restlight-integration-test/springmvc-test/pom.xml b/restlight-integration-test/springmvc-test/pom.xml index 43e86037..61800dc6 100644 --- a/restlight-integration-test/springmvc-test/pom.xml +++ b/restlight-integration-test/springmvc-test/pom.xml @@ -28,6 +28,12 @@ io.esastack restlight-starter ${project.version} + + + io.esastack + restlight-jaxrs-provider + + From e0c301c387a7cc589a9b98357f79c125eb924d8d Mon Sep 17 00:00:00 2001 From: chenglu Date: Mon, 25 Apr 2022 20:29:37 +0800 Subject: [PATCH 02/13] [Intergration Test] SpringMVC package rename & add jaxrs integration test. --- restlight-integration-test/jaxrs-test/pom.xml | 62 +++++++++++++++++++ .../cases/applications/ApplicationImpl.java | 17 +++++ .../cases/resources/AnnotationResource.java | 3 + .../resources/AsyncResponseResource.java | 49 +++++++++++++++ .../resources/ManualInjectController.java | 30 +++++++++ .../cases/resources/ValidationResource.java | 34 ++++++++++ .../integration/jaxrs/entity/UserData.java | 17 +++++ .../jaxrs/test/AnnotationTest.java | 30 +++++++++ .../jaxrs/test/AsyncResponseTest.java | 30 +++++++++ .../jaxrs/test/BaseIntegrationTest.java | 8 +++ .../jaxrs/test/ManualInjectTest.java | 30 +++++++++ .../jaxrs/test/ValidationTest.java | 34 ++++++++++ .../cases/annotation/CustomRequestBean.java | 2 +- .../cases/annotation/CustomRequestBody.java | 2 +- .../cases/annotation/CustomResponseBody.java | 2 +- .../cases/config/AdviceConfig.java | 4 +- .../cases/config/FilterConfig.java | 2 +- .../cases/config/InterceptorConfig.java | 2 +- .../cases/config/ResolverConfig.java | 20 ++++-- .../cases/config/SchedulerConfig.java | 2 +- .../cases/config/SerializeConfig.java | 2 +- .../cases/controller/AdviceController.java | 4 +- .../controller/AnnotationController.java | 10 +-- .../cases/controller/AwareController.java | 2 +- .../cases/controller/ExceptionController.java | 4 +- .../cases/controller/FailFastController.java | 2 +- .../cases/controller/FilterController.java | 4 +- .../cases/controller/SchedulerController.java | 2 +- .../cases/controller/SerializeController.java | 6 +- .../cases/exception/CustomException.java | 2 +- .../exception/CustomExceptionHandler.java | 2 +- .../exception/GlobalExceptionResolver.java | 2 +- .../{ => springmvc}/entity/UserData.java | 2 +- .../{ => springmvc}/test/AdviceTest.java | 4 +- .../{ => springmvc}/test/AnnotationTest.java | 4 +- .../{ => springmvc}/test/AwareTest.java | 2 +- .../test/BaseIntegrationTest.java | 2 +- .../{ => springmvc}/test/ExceptionTest.java | 2 +- .../{ => springmvc}/test/FailFastTest.java | 2 +- .../{ => springmvc}/test/FilterTest.java | 4 +- .../{ => springmvc}/test/SchedulerTest.java | 2 +- .../{ => springmvc}/test/SerializeTest.java | 6 +- 42 files changed, 402 insertions(+), 50 deletions(-) create mode 100644 restlight-integration-test/jaxrs-test/pom.xml create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/applications/ApplicationImpl.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/AnnotationResource.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/AsyncResponseResource.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/ManualInjectController.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/ValidationResource.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/entity/UserData.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/AnnotationTest.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/AsyncResponseTest.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/BaseIntegrationTest.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ManualInjectTest.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ValidationTest.java rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/cases/annotation/CustomRequestBean.java (92%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/cases/annotation/CustomRequestBody.java (92%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/cases/annotation/CustomResponseBody.java (92%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/cases/config/AdviceConfig.java (97%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/cases/config/FilterConfig.java (94%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/cases/config/InterceptorConfig.java (95%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/cases/config/ResolverConfig.java (82%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/cases/config/SchedulerConfig.java (97%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/cases/config/SerializeConfig.java (95%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/cases/controller/AdviceController.java (93%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/cases/controller/AnnotationController.java (88%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/cases/controller/AwareController.java (97%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/cases/controller/ExceptionController.java (88%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/cases/controller/FailFastController.java (94%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/cases/controller/FilterController.java (89%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/cases/controller/SchedulerController.java (95%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/cases/controller/SerializeController.java (87%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/cases/exception/CustomException.java (91%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/cases/exception/CustomExceptionHandler.java (94%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/cases/exception/GlobalExceptionResolver.java (95%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/entity/UserData.java (97%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/test/AdviceTest.java (96%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/test/AnnotationTest.java (97%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/test/AwareTest.java (97%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/test/BaseIntegrationTest.java (97%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/test/ExceptionTest.java (96%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/test/FailFastTest.java (96%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/test/FilterTest.java (89%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/test/SchedulerTest.java (96%) rename restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/{ => springmvc}/test/SerializeTest.java (91%) diff --git a/restlight-integration-test/jaxrs-test/pom.xml b/restlight-integration-test/jaxrs-test/pom.xml new file mode 100644 index 00000000..66ababf6 --- /dev/null +++ b/restlight-integration-test/jaxrs-test/pom.xml @@ -0,0 +1,62 @@ + + + + + + restlight-integration-test + io.esastack + 1.0.0-SNAPSHOT + + 4.0.0 + + jaxrs-test + + Restlight :: Integration Test :: Jaxrs test + + + 8 + 8 + + + + + io.esastack + restlight-starter + ${project.version} + + + io.esastack + restlight-springmvc-annotation + + + io.esastack + restlight-springmvc-provider + + + + + + junit + junit + + + + io.esastack + restclient + + + + \ No newline at end of file diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/applications/ApplicationImpl.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/applications/ApplicationImpl.java new file mode 100644 index 00000000..0a1353ee --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/applications/ApplicationImpl.java @@ -0,0 +1,17 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.cases; + +public class ApplicationImpl extends Application { +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/AnnotationResource.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/AnnotationResource.java new file mode 100644 index 00000000..95a9a861 --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/AnnotationResource.java @@ -0,0 +1,3 @@ +package io.esastack.restlight.integration.jaxrs.cases.resources; +public class AnnotationResource { +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/AsyncResponseResource.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/AsyncResponseResource.java new file mode 100644 index 00000000..94080608 --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/AsyncResponseResource.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.cases.resources; + + +import io.esastack.restlight.integration.jaxrs.entity.UserData; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.QueryParam; +import jakarta.ws.rs.container.AsyncResponse; +import jakarta.ws.rs.container.Suspended; +import org.springframework.stereotype.Controller; + +import java.util.concurrent.TimeUnit; + +@Controller +@Path("/async/response/") +public class AsyncResponseResource { + + @QueryParam("name") + String name; + + @QueryParam("timeout") + Long timeout; + + @GET + @Path("async") + public UserData async(@Suspended AsyncResponse asyncResponse) throws InterruptedException { + asyncResponse.setTimeoutHandler(rsp -> + asyncResponse.resume(UserData.Builder.anUserData().name("timeout").build())); + asyncResponse.setTimeout(200, TimeUnit.MILLISECONDS); + + TimeUnit.MILLISECONDS.sleep(timeout); + asyncResponse.resume(UserData.Builder.anUserData().name(name).build()); + return UserData.Builder.anUserData() + .name(name).build(); + } +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/ManualInjectController.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/ManualInjectController.java new file mode 100644 index 00000000..4aca5dc6 --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/ManualInjectController.java @@ -0,0 +1,30 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.cases.resources; + +import io.esastack.restlight.integration.jaxrs.entity.UserData; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.QueryParam; + +@Path("/manual/inject") +public class ManualInjectController { + + @GET + @Path("get") + public UserData get(@QueryParam("name") String name) { + return UserData.Builder.anUserData() + .name(name).build(); + } +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/ValidationResource.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/ValidationResource.java new file mode 100644 index 00000000..2fb9548e --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/ValidationResource.java @@ -0,0 +1,34 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.cases.resources; + +import io.esastack.restlight.integration.jaxrs.entity.UserData; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.QueryParam; +import org.springframework.stereotype.Controller; + +import javax.validation.constraints.NotEmpty; + +@Controller +@Path("/validation/") +public class ValidationResource { + + @GET + @Path("param") + public UserData param(@NotEmpty @QueryParam("name") String name) { + return UserData.Builder.anUserData() + .name(name).build(); + } +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/entity/UserData.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/entity/UserData.java new file mode 100644 index 00000000..5e00eb10 --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/entity/UserData.java @@ -0,0 +1,17 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.entity; + +public class UserData { +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/AnnotationTest.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/AnnotationTest.java new file mode 100644 index 00000000..bf64fb56 --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/AnnotationTest.java @@ -0,0 +1,30 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.test; + +import io.esastack.restclient.RestResponseBase; +import io.esastack.restlight.integration.jaxrs.entity.UserData; +import org.junit.Assert; +import org.junit.Test; + +public class AnnotationTest extends BaseIntegrationTest { + + @Test + public void testGet() throws Exception { + RestResponseBase responseBase = restClient.get(domain + "/annotation/get").addParam("name", "test") + .execute().toCompletableFuture().get(); + UserData userData = responseBase.bodyToEntity(UserData.class); + Assert.assertEquals("test", userData.getName()); + } +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/AsyncResponseTest.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/AsyncResponseTest.java new file mode 100644 index 00000000..6099f707 --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/AsyncResponseTest.java @@ -0,0 +1,30 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.test; + +import io.esastack.restclient.RestResponseBase; +import io.esastack.restlight.integration.jaxrs.entity.UserData; +import org.junit.Assert; +import org.junit.Test; + +public class AsyncResponseTest extends BaseIntegrationTest { + + @Test + public void testAsync() throws Exception { + RestResponseBase responseBase = restClient.get(domain + "/async/response/async").addParam("name", "test") + .addParam("timeout", "100").execute().toCompletableFuture().get(); + UserData userData = responseBase.bodyToEntity(UserData.class); + Assert.assertEquals("test", userData.getName()); + } +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/BaseIntegrationTest.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/BaseIntegrationTest.java new file mode 100644 index 00000000..85196fe7 --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/BaseIntegrationTest.java @@ -0,0 +1,8 @@ +package io.esastack.restlight.integration.jaxrs.test; +/** + * + * + * @author chenglu + */ +public class BaseIntegrationTest { +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ManualInjectTest.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ManualInjectTest.java new file mode 100644 index 00000000..7eb74048 --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ManualInjectTest.java @@ -0,0 +1,30 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.test; + +import io.esastack.restclient.RestResponseBase; +import io.esastack.restlight.integration.jaxrs.entity.UserData; +import org.junit.Assert; +import org.junit.Test; + +public class ManualInjectTest extends BaseIntegrationTest { + + @Test + public void get() throws Exception { + RestResponseBase responseBase = restClient.get(domain + "/manual/inject/get").addParam("name", "test") + .execute().toCompletableFuture().get(); + UserData userData = responseBase.bodyToEntity(UserData.class); + Assert.assertEquals("test", userData.getName()); + } +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ValidationTest.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ValidationTest.java new file mode 100644 index 00000000..d3d1ce61 --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ValidationTest.java @@ -0,0 +1,34 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.test; + +import io.esastack.commons.net.http.HttpStatus; +import io.esastack.restclient.RestResponseBase; +import io.esastack.restlight.integration.jaxrs.entity.UserData; +import org.junit.Assert; +import org.junit.Test; + +public class ValidationTest extends BaseIntegrationTest { + + @Test + public void testParam() throws Exception { + RestResponseBase responseBase = restClient.get(domain + "/validation/param").addParam("name", "test") + .execute().toCompletableFuture().get(); + UserData userData = responseBase.bodyToEntity(UserData.class); + Assert.assertEquals("test", userData.getName()); + + responseBase = restClient.get(domain + "/validation/param").execute().toCompletableFuture().get(); + Assert.assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.code(), responseBase.status()); + } +} diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/annotation/CustomRequestBean.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/annotation/CustomRequestBean.java similarity index 92% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/annotation/CustomRequestBean.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/annotation/CustomRequestBean.java index 6cb8d949..8ab5bc83 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/annotation/CustomRequestBean.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/annotation/CustomRequestBean.java @@ -11,7 +11,7 @@ * limitations under the License. */ -package io.esastack.restlight.integration.cases.annotation; +package io.esastack.restlight.integration.springmvc.cases.annotation; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/annotation/CustomRequestBody.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/annotation/CustomRequestBody.java similarity index 92% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/annotation/CustomRequestBody.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/annotation/CustomRequestBody.java index 3d8d6fc3..a265ed92 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/annotation/CustomRequestBody.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/annotation/CustomRequestBody.java @@ -11,7 +11,7 @@ * limitations under the License. */ -package io.esastack.restlight.integration.cases.annotation; +package io.esastack.restlight.integration.springmvc.cases.annotation; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/annotation/CustomResponseBody.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/annotation/CustomResponseBody.java similarity index 92% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/annotation/CustomResponseBody.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/annotation/CustomResponseBody.java index 7f3507f9..83688fff 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/annotation/CustomResponseBody.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/annotation/CustomResponseBody.java @@ -11,7 +11,7 @@ * limitations under the License. */ -package io.esastack.restlight.integration.cases.annotation; +package io.esastack.restlight.integration.springmvc.cases.annotation; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/config/AdviceConfig.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/config/AdviceConfig.java similarity index 97% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/config/AdviceConfig.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/config/AdviceConfig.java index fbca991e..a461e6d8 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/config/AdviceConfig.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/config/AdviceConfig.java @@ -11,7 +11,7 @@ * limitations under the License. */ -package io.esastack.restlight.integration.cases.config; +package io.esastack.restlight.integration.springmvc.cases.config; import io.esastack.restlight.core.method.HandlerMethod; import io.esastack.restlight.core.method.Param; @@ -28,7 +28,7 @@ import io.esastack.restlight.core.resolver.ResponseEntityResolverAdviceAdapter; import io.esastack.restlight.core.resolver.ResponseEntityResolverAdviceFactory; import io.esastack.restlight.core.resolver.ResponseEntityResolverContext; -import io.esastack.restlight.integration.entity.UserData; +import io.esastack.restlight.springmvc.entity.UserData; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/config/FilterConfig.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/config/FilterConfig.java similarity index 94% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/config/FilterConfig.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/config/FilterConfig.java index aff2cc22..1c2c59e3 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/config/FilterConfig.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/config/FilterConfig.java @@ -11,7 +11,7 @@ * limitations under the License. */ -package io.esastack.restlight.integration.cases.config; +package io.esastack.restlight.integration.springmvc.cases.config; import io.esastack.restlight.server.handler.Filter; import org.springframework.context.annotation.Bean; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/config/InterceptorConfig.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/config/InterceptorConfig.java similarity index 95% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/config/InterceptorConfig.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/config/InterceptorConfig.java index 5ea9ca5c..09660b51 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/config/InterceptorConfig.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/config/InterceptorConfig.java @@ -11,7 +11,7 @@ * limitations under the License. */ -package io.esastack.restlight.integration.cases.config; +package io.esastack.restlight.integration.springmvc.cases.config; import esa.commons.collection.AttributeKey; import io.esastack.restlight.core.interceptor.InterceptorFactory; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/config/ResolverConfig.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/config/ResolverConfig.java similarity index 82% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/config/ResolverConfig.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/config/ResolverConfig.java index 127d0a14..4f8750d0 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/config/ResolverConfig.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/config/ResolverConfig.java @@ -11,21 +11,29 @@ * limitations under the License. */ -package io.esastack.restlight.integration.cases.config; +package io.esastack.restlight.integration.springmvc.cases.config; import esa.commons.Result; import io.esastack.commons.net.http.MediaType; import io.esastack.restlight.core.method.HandlerMethod; import io.esastack.restlight.core.method.Param; -import io.esastack.restlight.core.resolver.*; +import io.esastack.restlight.core.resolver.ParamResolver; +import io.esastack.restlight.core.resolver.ParamResolverFactory; +import io.esastack.restlight.core.resolver.RequestEntity; +import io.esastack.restlight.core.resolver.RequestEntityResolver; +import io.esastack.restlight.core.resolver.RequestEntityResolverFactory; +import io.esastack.restlight.core.resolver.ResponseEntity; +import io.esastack.restlight.core.resolver.ResponseEntityResolver; +import io.esastack.restlight.core.resolver.ResponseEntityResolverFactory; +import io.esastack.restlight.core.resolver.StringConverterProvider; import io.esastack.restlight.core.resolver.rspentity.AbstractResponseEntityResolver; import io.esastack.restlight.core.serialize.HttpRequestSerializer; import io.esastack.restlight.core.serialize.HttpResponseSerializer; -import io.esastack.restlight.integration.cases.annotation.CustomRequestBean; -import io.esastack.restlight.integration.cases.annotation.CustomRequestBody; -import io.esastack.restlight.integration.cases.annotation.CustomResponseBody; -import io.esastack.restlight.integration.entity.UserData; +import io.esastack.restlight.integration.springmvc.cases.annotation.CustomRequestBean; import io.esastack.restlight.server.context.RequestContext; +import io.esastack.restlight.integration.springmvc.cases.annotation.CustomRequestBody; +import io.esastack.restlight.integration.springmvc.cases.annotation.CustomResponseBody; +import io.esastack.restlight.springmvc.entity.UserData; import io.netty.handler.codec.http.HttpHeaderNames; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/config/SchedulerConfig.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/config/SchedulerConfig.java similarity index 97% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/config/SchedulerConfig.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/config/SchedulerConfig.java index 191829e5..b4a26d00 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/config/SchedulerConfig.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/config/SchedulerConfig.java @@ -11,7 +11,7 @@ * limitations under the License. */ -package io.esastack.restlight.integration.cases.config; +package io.esastack.restlight.integration.springmvc.cases.config; import esa.commons.concurrent.ThreadFactories; import io.esastack.restlight.server.config.TimeoutOptions; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/config/SerializeConfig.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/config/SerializeConfig.java similarity index 95% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/config/SerializeConfig.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/config/SerializeConfig.java index 30284d14..260a3f05 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/config/SerializeConfig.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/config/SerializeConfig.java @@ -11,7 +11,7 @@ * limitations under the License. */ -package io.esastack.restlight.integration.cases.config; +package io.esastack.restlight.integration.springmvc.cases.config; import io.esastack.restlight.core.serialize.GsonHttpBodySerializer; import io.esastack.restlight.core.serialize.HttpBodySerializer; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/controller/AdviceController.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/AdviceController.java similarity index 93% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/controller/AdviceController.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/AdviceController.java index 69e8314b..0bb28bee 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/controller/AdviceController.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/AdviceController.java @@ -11,9 +11,9 @@ * limitations under the License. */ -package io.esastack.restlight.integration.cases.controller; +package io.esastack.restlight.integration.springmvc.cases.controller; -import io.esastack.restlight.integration.entity.UserData; +import io.esastack.restlight.springmvc.entity.UserData; import org.springframework.web.bind.annotation.*; @RestController diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/controller/AnnotationController.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/AnnotationController.java similarity index 88% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/controller/AnnotationController.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/AnnotationController.java index 2b36728f..0629d232 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/controller/AnnotationController.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/AnnotationController.java @@ -11,14 +11,14 @@ * limitations under the License. */ -package io.esastack.restlight.integration.cases.controller; +package io.esastack.restlight.integration.springmvc.cases.controller; import io.esastack.restlight.core.annotation.QueryBean; import io.esastack.restlight.core.annotation.RequestBean; -import io.esastack.restlight.integration.cases.annotation.CustomRequestBean; -import io.esastack.restlight.integration.cases.annotation.CustomRequestBody; -import io.esastack.restlight.integration.cases.annotation.CustomResponseBody; -import io.esastack.restlight.integration.entity.UserData; +import io.esastack.restlight.integration.springmvc.cases.annotation.CustomRequestBean; +import io.esastack.restlight.integration.springmvc.cases.annotation.CustomRequestBody; +import io.esastack.restlight.integration.springmvc.cases.annotation.CustomResponseBody; +import io.esastack.restlight.springmvc.entity.UserData; import org.springframework.http.HttpStatus; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.*; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/controller/AwareController.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/AwareController.java similarity index 97% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/controller/AwareController.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/AwareController.java index 9a7d11ef..d0896ca5 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/controller/AwareController.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/AwareController.java @@ -11,7 +11,7 @@ * limitations under the License. */ -package io.esastack.restlight.integration.cases.controller; +package io.esastack.restlight.integration.springmvc.cases.controller; import io.esastack.restlight.core.DeployContext; import io.esastack.restlight.server.bootstrap.RestlightServer; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/controller/ExceptionController.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/ExceptionController.java similarity index 88% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/controller/ExceptionController.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/ExceptionController.java index cf9892d3..0e6ac8fe 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/controller/ExceptionController.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/ExceptionController.java @@ -11,9 +11,9 @@ * limitations under the License. */ -package io.esastack.restlight.integration.cases.controller; +package io.esastack.restlight.integration.springmvc.cases.controller; -import io.esastack.restlight.integration.cases.exception.CustomException; +import io.esastack.restlight.springmvc.cases.exception.CustomException; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/controller/FailFastController.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/FailFastController.java similarity index 94% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/controller/FailFastController.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/FailFastController.java index 222386a5..97bb8b36 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/controller/FailFastController.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/FailFastController.java @@ -11,7 +11,7 @@ * limitations under the License. */ -package io.esastack.restlight.integration.cases.controller; +package io.esastack.restlight.integration.springmvc.cases.controller; import io.esastack.restlight.core.annotation.Scheduled; import org.springframework.web.bind.annotation.GetMapping; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/controller/FilterController.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/FilterController.java similarity index 89% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/controller/FilterController.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/FilterController.java index 01e64159..6aac75eb 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/controller/FilterController.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/FilterController.java @@ -11,9 +11,9 @@ * limitations under the License. */ -package io.esastack.restlight.integration.cases.controller; +package io.esastack.restlight.integration.springmvc.cases.controller; -import io.esastack.restlight.integration.entity.UserData; +import io.esastack.restlight.springmvc.entity.UserData; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/controller/SchedulerController.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/SchedulerController.java similarity index 95% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/controller/SchedulerController.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/SchedulerController.java index 115dd25e..d5d47d43 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/controller/SchedulerController.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/SchedulerController.java @@ -11,7 +11,7 @@ * limitations under the License. */ -package io.esastack.restlight.integration.cases.controller; +package io.esastack.restlight.integration.springmvc.cases.controller; import io.esastack.restlight.core.annotation.Scheduled; import org.springframework.web.bind.annotation.GetMapping; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/controller/SerializeController.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/SerializeController.java similarity index 87% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/controller/SerializeController.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/SerializeController.java index b97055b8..f1b2eef6 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/controller/SerializeController.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/SerializeController.java @@ -11,12 +11,12 @@ * limitations under the License. */ -package io.esastack.restlight.integration.cases.controller; +package io.esastack.restlight.integration.springmvc.cases.controller; import io.esastack.restlight.core.annotation.Serializer; import io.esastack.restlight.core.serialize.GsonHttpBodySerializer; -import io.esastack.restlight.integration.entity.UserData; -import io.esastack.restlight.integration.entity.UserProtobufData; +import io.esastack.restlight.springmvc.entity.UserData; +import io.esastack.restlight.springmvc.entity.UserProtobufData; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/exception/CustomException.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/exception/CustomException.java similarity index 91% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/exception/CustomException.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/exception/CustomException.java index b3f17de8..21b46aa3 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/exception/CustomException.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/exception/CustomException.java @@ -11,7 +11,7 @@ * limitations under the License. */ -package io.esastack.restlight.integration.cases.exception; +package io.esastack.restlight.integration.springmvc.cases.exception; public class CustomException extends RuntimeException { diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/exception/CustomExceptionHandler.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/exception/CustomExceptionHandler.java similarity index 94% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/exception/CustomExceptionHandler.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/exception/CustomExceptionHandler.java index 032aea14..75e17de5 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/exception/CustomExceptionHandler.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/exception/CustomExceptionHandler.java @@ -11,7 +11,7 @@ * limitations under the License. */ -package io.esastack.restlight.integration.cases.exception; +package io.esastack.restlight.integration.springmvc.cases.exception; import io.esastack.commons.net.http.HttpStatus; import io.esastack.restlight.server.core.HttpResponse; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/exception/GlobalExceptionResolver.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/exception/GlobalExceptionResolver.java similarity index 95% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/exception/GlobalExceptionResolver.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/exception/GlobalExceptionResolver.java index 1f7b4ac3..8cac957e 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/cases/exception/GlobalExceptionResolver.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/exception/GlobalExceptionResolver.java @@ -11,7 +11,7 @@ * limitations under the License. */ -package io.esastack.restlight.integration.cases.exception; +package io.esastack.restlight.integration.springmvc.cases.exception; import io.esastack.commons.net.http.HttpStatus; import io.esastack.restlight.core.resolver.ExceptionResolver; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/entity/UserData.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/entity/UserData.java similarity index 97% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/entity/UserData.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/entity/UserData.java index 6a14abf4..56c7f6e9 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/entity/UserData.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/entity/UserData.java @@ -11,7 +11,7 @@ * limitations under the License. */ -package io.esastack.restlight.integration.entity; +package io.esastack.restlight.integration.springmvc.entity; import java.math.BigDecimal; import java.util.Date; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/test/AdviceTest.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/AdviceTest.java similarity index 96% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/test/AdviceTest.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/AdviceTest.java index 2e44cf19..28dd2709 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/test/AdviceTest.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/AdviceTest.java @@ -11,10 +11,10 @@ * limitations under the License. */ -package io.esastack.restlight.integration.test; +package io.esastack.restlight.integration.springmvc.test; import io.esastack.restclient.RestResponseBase; -import io.esastack.restlight.integration.entity.UserData; +import io.esastack.restlight.integration.springmvc.entity.UserData; import org.junit.Assert; import org.junit.Test; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/test/AnnotationTest.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/AnnotationTest.java similarity index 97% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/test/AnnotationTest.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/AnnotationTest.java index 8e445753..49369de4 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/test/AnnotationTest.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/AnnotationTest.java @@ -11,11 +11,11 @@ * limitations under the License. */ -package io.esastack.restlight.integration.test; +package io.esastack.restlight.integration.springmvc.test; import io.esastack.commons.net.http.HttpStatus; import io.esastack.restclient.RestResponseBase; -import io.esastack.restlight.integration.entity.UserData; +import io.esastack.restlight.integration.springmvc.entity.UserData; import org.junit.Assert; import org.junit.Test; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/test/AwareTest.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/AwareTest.java similarity index 97% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/test/AwareTest.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/AwareTest.java index 8f2a855d..cc6ff7ff 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/test/AwareTest.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/AwareTest.java @@ -11,7 +11,7 @@ * limitations under the License. */ -package io.esastack.restlight.integration.test; +package io.esastack.restlight.integration.springmvc.test; import io.esastack.restclient.RestResponseBase; import io.netty.channel.nio.NioEventLoopGroup; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/test/BaseIntegrationTest.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/BaseIntegrationTest.java similarity index 97% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/test/BaseIntegrationTest.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/BaseIntegrationTest.java index aa2420d8..b798f4ac 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/test/BaseIntegrationTest.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/BaseIntegrationTest.java @@ -11,7 +11,7 @@ * limitations under the License. */ -package io.esastack.restlight.integration.test; +package io.esastack.restlight.integration.springmvc.test; import esa.commons.NetworkUtils; import io.esastack.restclient.RestClient; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/test/ExceptionTest.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/ExceptionTest.java similarity index 96% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/test/ExceptionTest.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/ExceptionTest.java index 7e030ad7..c59a7a5c 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/test/ExceptionTest.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/ExceptionTest.java @@ -11,7 +11,7 @@ * limitations under the License. */ -package io.esastack.restlight.integration.test; +package io.esastack.restlight.integration.springmvc.test; import io.esastack.commons.net.http.HttpStatus; import io.esastack.restclient.RestResponseBase; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/test/FailFastTest.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/FailFastTest.java similarity index 96% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/test/FailFastTest.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/FailFastTest.java index 1e444feb..e9ad705c 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/test/FailFastTest.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/FailFastTest.java @@ -11,7 +11,7 @@ * limitations under the License. */ -package io.esastack.restlight.integration.test; +package io.esastack.restlight.integration.springmvc.test; import io.esastack.commons.net.http.HttpStatus; import io.esastack.restclient.RestResponseBase; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/test/FilterTest.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/FilterTest.java similarity index 89% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/test/FilterTest.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/FilterTest.java index f36c9879..79ed7cb2 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/test/FilterTest.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/FilterTest.java @@ -11,10 +11,10 @@ * limitations under the License. */ -package io.esastack.restlight.integration.test; +package io.esastack.restlight.integration.springmvc.test; import io.esastack.restclient.RestResponseBase; -import io.esastack.restlight.integration.entity.UserData; +import io.esastack.restlight.integration.springmvc.entity.UserData; import org.junit.Assert; import org.junit.Test; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/test/SchedulerTest.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/SchedulerTest.java similarity index 96% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/test/SchedulerTest.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/SchedulerTest.java index 24fe2454..1e54cad5 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/test/SchedulerTest.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/SchedulerTest.java @@ -11,7 +11,7 @@ * limitations under the License. */ -package io.esastack.restlight.integration.test; +package io.esastack.restlight.integration.springmvc.test; import io.esastack.restclient.RestResponseBase; import org.junit.Assert; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/test/SerializeTest.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/SerializeTest.java similarity index 91% rename from restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/test/SerializeTest.java rename to restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/SerializeTest.java index 4e10d2b6..5335102e 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/test/SerializeTest.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/SerializeTest.java @@ -11,12 +11,12 @@ * limitations under the License. */ -package io.esastack.restlight.integration.test; +package io.esastack.restlight.integration.springmvc.test; import io.esastack.restclient.RestResponseBase; import io.esastack.restclient.codec.impl.ProtoBufCodec; -import io.esastack.restlight.integration.entity.UserData; -import io.esastack.restlight.integration.entity.UserProtobufData; +import io.esastack.restlight.integration.springmvc.entity.UserData; +import io.esastack.restlight.integration.springmvc.entity.UserProtobufData; import org.junit.Assert; import org.junit.Test; From 7a69bbb51c21bd7adc6aa5afe79e20be1f6866d6 Mon Sep 17 00:00:00 2001 From: chenglu Date: Tue, 26 Apr 2022 09:57:05 +0800 Subject: [PATCH 03/13] [Intergration Test] SpringMVC package rename & add jaxrs integration test. --- pom.xml | 1 + restlight-integration-test/jaxrs-test/pom.xml | 11 +++ .../cases/applications/ApplicationImpl.java | 19 +++- .../cases/resources/AnnotationResource.java | 97 +++++++++++++++++++ .../resources/AsyncResponseResource.java | 28 ++++-- .../cases/resources/ValidationResource.java | 27 +++++- .../integration/jaxrs/entity/UserData.java | 65 +++++++++++++ .../jaxrs/test/AnnotationTest.java | 77 +++++++++++++++ .../jaxrs/test/AsyncResponseTest.java | 13 +++ .../jaxrs/test/BaseIntegrationTest.java | 62 ++++++++++-- .../jaxrs/test/ValidationTest.java | 29 +++++- .../springmvc-test/pom.xml | 1 - .../springmvc/cases/config/AdviceConfig.java | 2 +- .../cases/config/ResolverConfig.java | 2 +- .../cases/controller/AdviceController.java | 2 +- .../controller/AnnotationController.java | 2 +- .../cases/controller/ExceptionController.java | 2 +- .../cases/controller/FilterController.java | 2 +- .../cases/controller/SerializeController.java | 4 +- .../resources/protobuf/UserProtobufData.proto | 2 +- 20 files changed, 418 insertions(+), 30 deletions(-) diff --git a/pom.xml b/pom.xml index 7ad88c57..92bd13b5 100644 --- a/pom.xml +++ b/pom.xml @@ -137,6 +137,7 @@ restlight-bom restlight-benchmarks restlight-integration-test + restlight-integration-test/jaxrs-test diff --git a/restlight-integration-test/jaxrs-test/pom.xml b/restlight-integration-test/jaxrs-test/pom.xml index 66ababf6..914666fe 100644 --- a/restlight-integration-test/jaxrs-test/pom.xml +++ b/restlight-integration-test/jaxrs-test/pom.xml @@ -57,6 +57,17 @@ io.esastack restclient + + org.springframework + spring-context + compile + + + + io.esastack + restlight-jaxrs-provider + ${project.version} + \ No newline at end of file diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/applications/ApplicationImpl.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/applications/ApplicationImpl.java index 0a1353ee..963d0e56 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/applications/ApplicationImpl.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/applications/ApplicationImpl.java @@ -11,7 +11,24 @@ * limitations under the License. */ -package io.esastack.restlight.integration.jaxrs.cases; +package io.esastack.restlight.integration.jaxrs.cases.applications; +import io.esastack.restlight.integration.jaxrs.cases.resources.ManualInjectController; +import jakarta.ws.rs.ApplicationPath; +import jakarta.ws.rs.core.Application; +import org.springframework.stereotype.Component; + +import java.util.HashSet; +import java.util.Set; + +@ApplicationPath("/integration/test") +@Component public class ApplicationImpl extends Application { + + @Override + public Set> getClasses() { + Set> classes = new HashSet<>(); + classes.add(ManualInjectController.class); + return classes; + } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/AnnotationResource.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/AnnotationResource.java index 95a9a861..eb3fd723 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/AnnotationResource.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/AnnotationResource.java @@ -1,3 +1,100 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.cases.resources; + +import io.esastack.restlight.integration.jaxrs.entity.UserData; +import jakarta.ws.rs.BeanParam; +import jakarta.ws.rs.DELETE; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.PUT; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.QueryParam; +import jakarta.ws.rs.container.ResourceContext; +import jakarta.ws.rs.core.Configuration; +import jakarta.ws.rs.core.Context; +import jakarta.ws.rs.core.HttpHeaders; +import jakarta.ws.rs.core.Request; +import jakarta.ws.rs.core.UriInfo; +import jakarta.ws.rs.ext.Providers; +import org.springframework.stereotype.Controller; + +@Path("/annotation/") +@Controller public class AnnotationResource { + + @GET + @Path("get") + public UserData get(@QueryParam("name") String name) { + return UserData.Builder.anUserData() + .name(name).build(); + } + + @POST + @Path("post") + public UserData post(UserData userData) { + return userData; + } + + @DELETE + @Path("delete") + public UserData delete(@BeanParam UserData userData) { + return userData; + } + + @PUT + @Path("/put/{name}") + public UserData put(@PathParam("name") String name) { + return UserData.Builder.anUserData() + .name(name).build(); + } + + @GET + @Path("get/context/headers") + public UserData headers(@Context HttpHeaders httpHeaders) { + return UserData.Builder.anUserData() + .name(httpHeaders.getHeaderString("name")).build(); + } + + @GET + @Path("get/context/providers") + public String providers(@Context Providers providers) { + return providers.getClass().getName(); + } + + @GET + @Path("get/context/request") + public String request(@Context Request request) { + return request.getMethod(); + } + + @GET + @Path("get/context/resource") + public String resource(@Context ResourceContext resourceContext) { + return resourceContext.getResource(this.getClass()).getClass().getName(); + } + + @GET + @Path("get/context/uri") + public String uri(@Context UriInfo uriInfo) { + return uriInfo.getRequestUri().getPath(); + } + + @GET + @Path("get/context/configuration") + public String configuration(@Context Configuration configuration) { + return configuration.getClass().getName(); + } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/AsyncResponseResource.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/AsyncResponseResource.java index 94080608..df1344b1 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/AsyncResponseResource.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/AsyncResponseResource.java @@ -22,21 +22,18 @@ import jakarta.ws.rs.container.Suspended; import org.springframework.stereotype.Controller; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionStage; import java.util.concurrent.TimeUnit; @Controller @Path("/async/response/") public class AsyncResponseResource { - @QueryParam("name") - String name; - - @QueryParam("timeout") - Long timeout; - @GET @Path("async") - public UserData async(@Suspended AsyncResponse asyncResponse) throws InterruptedException { + public UserData async(@Suspended AsyncResponse asyncResponse, @QueryParam("name") String name, + @QueryParam("timeout") Long timeout) throws InterruptedException { asyncResponse.setTimeoutHandler(rsp -> asyncResponse.resume(UserData.Builder.anUserData().name("timeout").build())); asyncResponse.setTimeout(200, TimeUnit.MILLISECONDS); @@ -44,6 +41,21 @@ public UserData async(@Suspended AsyncResponse asyncResponse) throws Interrupted TimeUnit.MILLISECONDS.sleep(timeout); asyncResponse.resume(UserData.Builder.anUserData().name(name).build()); return UserData.Builder.anUserData() - .name(name).build(); + .name("normal").build(); + } + + @GET + @Path("future") + public CompletionStage future( @QueryParam("name") String name, @QueryParam("timeout") Long timeout) { + CompletableFuture promise = new CompletableFuture<>(); + new Thread(() -> { + try { + TimeUnit.MILLISECONDS.sleep(timeout); + } catch (Exception e) { + // ignore it + } + promise.complete(UserData.Builder.anUserData().name(name).build()); + }).start(); + return promise; } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/ValidationResource.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/ValidationResource.java index 2fb9548e..ff3f9e04 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/ValidationResource.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/ValidationResource.java @@ -15,20 +15,43 @@ import io.esastack.restlight.integration.jaxrs.entity.UserData; import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; import jakarta.ws.rs.QueryParam; import org.springframework.stereotype.Controller; +import javax.validation.Valid; import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; @Controller @Path("/validation/") public class ValidationResource { @GET - @Path("param") - public UserData param(@NotEmpty @QueryParam("name") String name) { + @Path("request/param") + public UserData requestParam(@NotEmpty @QueryParam("name") String name) { return UserData.Builder.anUserData() .name(name).build(); } + + @POST + @Path("request/entity") + public UserData requestEntity(@Valid UserData userData) { + return userData; + } + + @GET + @Path("response/param") + @NotNull + public UserData responseParam(@QueryParam("name") String name) { + return null; + } + + @POST + @Path("response/entity") + @Valid + public UserData responseEntity(UserData userData) { + return userData; + } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/entity/UserData.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/entity/UserData.java index 5e00eb10..91fc6661 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/entity/UserData.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/entity/UserData.java @@ -13,5 +13,70 @@ package io.esastack.restlight.integration.jaxrs.entity; +import jakarta.ws.rs.CookieParam; +import jakarta.ws.rs.HeaderParam; +import jakarta.ws.rs.QueryParam; + +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Positive; +import java.math.BigDecimal; + public class UserData { + + @NotNull + @QueryParam("name") + private String name; + + @HeaderParam("age") + @Positive + private Integer age; + + @CookieParam("weight") + private BigDecimal weight; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getAge() { + return age; + } + + public void setAge(Integer age) { + this.age = age; + } + + public BigDecimal getWeight() { + return weight; + } + + public void setWeight(BigDecimal weight) { + this.weight = weight; + } + + public static final class Builder { + private String name; + + private Builder() { + } + + public static Builder anUserData() { + return new Builder(); + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public UserData build() { + UserData userData = new UserData(); + userData.setName(name); + return userData; + } + } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/AnnotationTest.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/AnnotationTest.java index bf64fb56..eb9c2a43 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/AnnotationTest.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/AnnotationTest.java @@ -14,10 +14,15 @@ package io.esastack.restlight.integration.jaxrs.test; import io.esastack.restclient.RestResponseBase; +import io.esastack.restlight.integration.jaxrs.cases.resources.AnnotationResource; import io.esastack.restlight.integration.jaxrs.entity.UserData; +import io.esastack.restlight.jaxrs.impl.core.ConfigurationImpl; +import io.esastack.restlight.jaxrs.impl.ext.ProvidersImpl; import org.junit.Assert; import org.junit.Test; +import java.math.BigDecimal; + public class AnnotationTest extends BaseIntegrationTest { @Test @@ -27,4 +32,76 @@ public void testGet() throws Exception { UserData userData = responseBase.bodyToEntity(UserData.class); Assert.assertEquals("test", userData.getName()); } + + @Test + public void testPost() throws Exception { + UserData entity = UserData.Builder.anUserData() + .name("test").build(); + RestResponseBase responseBase = restClient.post(domain + "/annotation/post").entity(entity) + .execute().toCompletableFuture().get(); + UserData userData = responseBase.bodyToEntity(UserData.class); + Assert.assertEquals(entity.getName(), userData.getName()); + } + + @Test + public void testDelete() throws Exception { + RestResponseBase responseBase = restClient.delete(domain + "/annotation/delete").addParam("name", "test") + .addHeader("age", "10").addCookie("weight", "100").execute().toCompletableFuture().get(); + UserData userData = responseBase.bodyToEntity(UserData.class); + Assert.assertEquals("test", userData.getName()); + Assert.assertTrue(10 == userData.getAge()); + Assert.assertTrue(BigDecimal.valueOf(100).equals(userData.getWeight())); + } + + @Test + public void testPut() throws Exception { + RestResponseBase responseBase = restClient.put(domain + "/annotation/put/test") + .execute().toCompletableFuture().get(); + UserData userData = responseBase.bodyToEntity(UserData.class); + Assert.assertEquals("test", userData.getName()); + } + + @Test + public void testContextHeaders () throws Exception { + RestResponseBase responseBase = restClient.get(domain + "/annotation/get/context/headers") + .addHeader("name", "test").execute().toCompletableFuture().get(); + UserData userData = responseBase.bodyToEntity(UserData.class); + Assert.assertEquals("test", userData.getName()); + } + + @Test + public void testContextProviders () throws Exception { + RestResponseBase responseBase = restClient.get(domain + "/annotation/get/context/providers") + .execute().toCompletableFuture().get(); + Assert.assertEquals(ProvidersImpl.class.getName(), responseBase.bodyToEntity(String.class)); + } + + @Test + public void testRequest () throws Exception { + RestResponseBase responseBase = restClient.get(domain + "/annotation/get/context/request") + .execute().toCompletableFuture().get(); + Assert.assertEquals("GET", responseBase.bodyToEntity(String.class)); + } + + @Test + public void testResource () throws Exception { + RestResponseBase responseBase = restClient.get(domain + "/annotation/get/context/resource") + .execute().toCompletableFuture().get(); + Assert.assertEquals(AnnotationResource.class.getName(), responseBase.bodyToEntity(String.class)); + } + + @Test + public void testUri() throws Exception { + RestResponseBase responseBase = restClient.get(domain + "/annotation/get/context/uri") + .execute().toCompletableFuture().get(); + Assert.assertEquals("/integration/test/annotation/get/context/uri", responseBase.bodyToEntity(String.class)); + } + + @Test + public void testConfiguration() throws Exception { + RestResponseBase responseBase = restClient.get(domain + "/annotation/get/context/configuration") + .execute().toCompletableFuture().get(); + System.out.println(); + Assert.assertEquals(ConfigurationImpl.class.getName(), responseBase.bodyToEntity(String.class)); + } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/AsyncResponseTest.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/AsyncResponseTest.java index 6099f707..74554b14 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/AsyncResponseTest.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/AsyncResponseTest.java @@ -26,5 +26,18 @@ public void testAsync() throws Exception { .addParam("timeout", "100").execute().toCompletableFuture().get(); UserData userData = responseBase.bodyToEntity(UserData.class); Assert.assertEquals("test", userData.getName()); + + responseBase = restClient.get(domain + "/async/response/async").addParam("name", "test") + .addParam("timeout", "300").execute().toCompletableFuture().get(); + userData = responseBase.bodyToEntity(UserData.class); + Assert.assertEquals("timeout", userData.getName()); + } + + @Test + public void testFuture() throws Exception { + RestResponseBase responseBase = restClient.get(domain + "/async/response/future").addParam("name", "test") + .addParam("timeout", "100").execute().toCompletableFuture().get(); + UserData userData = responseBase.bodyToEntity(UserData.class); + Assert.assertEquals("test", userData.getName()); } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/BaseIntegrationTest.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/BaseIntegrationTest.java index 85196fe7..249dced6 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/BaseIntegrationTest.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/BaseIntegrationTest.java @@ -1,8 +1,58 @@ -package io.esastack.restlight.integration.jaxrs.test; -/** - * - * - * @author chenglu +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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. */ -public class BaseIntegrationTest { + +package io.esastack.restlight.integration.jaxrs.test; + +import esa.commons.NetworkUtils; +import io.esastack.restclient.RestClient; +import io.esastack.restlight.starter.ServerStarter; +import io.esastack.restlight.starter.autoconfigure.AutoRestlightServerOptions; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +public abstract class BaseIntegrationTest { + + public static RestClient restClient; + + public static String domain; + + private static AnnotationConfigApplicationContext ctx; + + @BeforeClass + public static void setUp() { + restClient = RestClient.ofDefault(); + + ctx = new AnnotationConfigApplicationContext(); + ctx.scan("io.esastack.restlight.integration.jaxrs.cases"); + ctx.refresh(); + final AutoRestlightServerOptions options = new AutoRestlightServerOptions(); + + // set port and host + final int port = NetworkUtils.selectRandomPort(); + final String host = "127.0.0.1"; + options.setPort(port); + options.setHost(host); + + // start server + final ServerStarter starter = new ServerStarter(options); + starter.setApplicationContext(ctx); + starter.afterSingletonsInstantiated(); + domain = "http://" + host + ":" + port + "/integration/test"; + } + + @AfterClass + public static void tearDown() { + ctx.close(); + } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ValidationTest.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ValidationTest.java index d3d1ce61..a0662646 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ValidationTest.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ValidationTest.java @@ -22,13 +22,36 @@ public class ValidationTest extends BaseIntegrationTest { @Test - public void testParam() throws Exception { - RestResponseBase responseBase = restClient.get(domain + "/validation/param").addParam("name", "test") + public void testRequestParam() throws Exception { + RestResponseBase responseBase = restClient.get(domain + "/validation/request/param").addParam("name", "test") .execute().toCompletableFuture().get(); UserData userData = responseBase.bodyToEntity(UserData.class); Assert.assertEquals("test", userData.getName()); - responseBase = restClient.get(domain + "/validation/param").execute().toCompletableFuture().get(); + responseBase = restClient.get(domain + "/validation/request/param").execute().toCompletableFuture().get(); + Assert.assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.code(), responseBase.status()); + } + + @Test + public void testRequestEntity() throws Exception { + UserData entity = UserData.Builder.anUserData().build(); + RestResponseBase responseBase = restClient.post(domain + "/validation/request/entity").entity(entity) + .execute().toCompletableFuture().get(); + UserData userData = responseBase.bodyToEntity(UserData.class); + Assert.assertEquals("test", userData.getName()); + } + + @Test + public void testResponseParam() throws Exception { + RestResponseBase responseBase = restClient.get(domain + "/validation/response/param").execute().toCompletableFuture().get(); + Assert.assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.code(), responseBase.status()); + } + + @Test + public void testResponseEntity() throws Exception { + UserData entity = UserData.Builder.anUserData().build(); + RestResponseBase responseBase = restClient.post(domain + "/validation/response/entity").entity(entity) + .execute().toCompletableFuture().get(); Assert.assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.code(), responseBase.status()); } } diff --git a/restlight-integration-test/springmvc-test/pom.xml b/restlight-integration-test/springmvc-test/pom.xml index 61800dc6..942bbdbd 100644 --- a/restlight-integration-test/springmvc-test/pom.xml +++ b/restlight-integration-test/springmvc-test/pom.xml @@ -36,7 +36,6 @@ - io.esastack restclient diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/config/AdviceConfig.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/config/AdviceConfig.java index a461e6d8..23e674b8 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/config/AdviceConfig.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/config/AdviceConfig.java @@ -28,7 +28,7 @@ import io.esastack.restlight.core.resolver.ResponseEntityResolverAdviceAdapter; import io.esastack.restlight.core.resolver.ResponseEntityResolverAdviceFactory; import io.esastack.restlight.core.resolver.ResponseEntityResolverContext; -import io.esastack.restlight.springmvc.entity.UserData; +import io.esastack.restlight.integration.springmvc.entity.UserData; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/config/ResolverConfig.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/config/ResolverConfig.java index 4f8750d0..a3ef5862 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/config/ResolverConfig.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/config/ResolverConfig.java @@ -33,7 +33,7 @@ import io.esastack.restlight.server.context.RequestContext; import io.esastack.restlight.integration.springmvc.cases.annotation.CustomRequestBody; import io.esastack.restlight.integration.springmvc.cases.annotation.CustomResponseBody; -import io.esastack.restlight.springmvc.entity.UserData; +import io.esastack.restlight.integration.springmvc.entity.UserData; import io.netty.handler.codec.http.HttpHeaderNames; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/AdviceController.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/AdviceController.java index 0bb28bee..ff5c3e57 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/AdviceController.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/AdviceController.java @@ -13,7 +13,7 @@ package io.esastack.restlight.integration.springmvc.cases.controller; -import io.esastack.restlight.springmvc.entity.UserData; +import io.esastack.restlight.integration.springmvc.entity.UserData; import org.springframework.web.bind.annotation.*; @RestController diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/AnnotationController.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/AnnotationController.java index 0629d232..15c6d193 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/AnnotationController.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/AnnotationController.java @@ -18,7 +18,7 @@ import io.esastack.restlight.integration.springmvc.cases.annotation.CustomRequestBean; import io.esastack.restlight.integration.springmvc.cases.annotation.CustomRequestBody; import io.esastack.restlight.integration.springmvc.cases.annotation.CustomResponseBody; -import io.esastack.restlight.springmvc.entity.UserData; +import io.esastack.restlight.integration.springmvc.entity.UserData; import org.springframework.http.HttpStatus; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.*; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/ExceptionController.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/ExceptionController.java index 0e6ac8fe..40eba28f 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/ExceptionController.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/ExceptionController.java @@ -13,7 +13,7 @@ package io.esastack.restlight.integration.springmvc.cases.controller; -import io.esastack.restlight.springmvc.cases.exception.CustomException; +import io.esastack.restlight.integration.springmvc.cases.exception.CustomException; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/FilterController.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/FilterController.java index 6aac75eb..8596c5fb 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/FilterController.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/FilterController.java @@ -13,7 +13,7 @@ package io.esastack.restlight.integration.springmvc.cases.controller; -import io.esastack.restlight.springmvc.entity.UserData; +import io.esastack.restlight.integration.springmvc.entity.UserData; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/SerializeController.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/SerializeController.java index f1b2eef6..bed56ec3 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/SerializeController.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/SerializeController.java @@ -15,8 +15,8 @@ import io.esastack.restlight.core.annotation.Serializer; import io.esastack.restlight.core.serialize.GsonHttpBodySerializer; -import io.esastack.restlight.springmvc.entity.UserData; -import io.esastack.restlight.springmvc.entity.UserProtobufData; +import io.esastack.restlight.integration.springmvc.entity.UserData; +import io.esastack.restlight.integration.springmvc.entity.UserProtobufData; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/restlight-integration-test/springmvc-test/src/main/resources/protobuf/UserProtobufData.proto b/restlight-integration-test/springmvc-test/src/main/resources/protobuf/UserProtobufData.proto index 2b8f8861..1527263b 100644 --- a/restlight-integration-test/springmvc-test/src/main/resources/protobuf/UserProtobufData.proto +++ b/restlight-integration-test/springmvc-test/src/main/resources/protobuf/UserProtobufData.proto @@ -1,6 +1,6 @@ syntax="proto3"; -option java_package = "io.esastack.restlight.integration.entity"; +option java_package = "io.esastack.restlight.integration.springmvc.entity"; option java_outer_classname = "UserProtobufData"; message Data { From 6079ac88254ef5c0f54076d0c5e5c55ace7efa3f Mon Sep 17 00:00:00 2001 From: chenglu Date: Tue, 26 Apr 2022 15:44:03 +0800 Subject: [PATCH 04/13] [Integration Test] add Jaxrs test case. --- .../jaxrs/cases/annotation/Filter.java | 27 ++++++++++ .../jaxrs/cases/annotation/Interceptor.java | 27 ++++++++++ .../jaxrs/cases/providers/BodyReader.java | 3 ++ .../jaxrs/cases/providers/BodyWriter.java | 42 +++++++++++++++ .../jaxrs/cases/providers/DynamicFeature.java | 25 +++++++++ .../providers/GlobalExceptionMapper.java | 3 ++ .../providers/NameBindingRequestFilter.java | 31 +++++++++++ .../providers/NameBindingResponseFilter.java | 34 ++++++++++++ .../jaxrs/cases/providers/RequestFilter.java | 3 ++ .../cases/providers/RequestInterceptor.java | 3 ++ .../jaxrs/cases/providers/ResponseFilter.java | 30 +++++++++++ .../cases/providers/ResponseInterceptor.java | 3 ++ .../jaxrs/cases/providers/StaticFeature.java | 29 ++++++++++ .../cases/resources/ExceptionResource.java | 3 ++ .../jaxrs/cases/resources/FilterResource.java | 3 ++ .../cases/resources/InterceptorResource.java | 3 ++ .../cases/resources/LocatorResource.java | 54 +++++++++++++++++++ ...troller.java => ManualInjectResource.java} | 2 +- .../cases/resources/MessageBodyResource.java | 3 ++ .../integration/jaxrs/test/ExceptionTest.java | 3 ++ .../integration/jaxrs/test/FilterTest.java | 3 ++ .../jaxrs/test/InterceptorTest.java | 30 +++++++++++ .../integration/jaxrs/test/LocatorTest.java | 3 ++ .../jaxrs/test/MessageBodyTest.java | 38 +++++++++++++ 24 files changed, 404 insertions(+), 1 deletion(-) create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/annotation/Filter.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/annotation/Interceptor.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyReader.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyWriter.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/DynamicFeature.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/GlobalExceptionMapper.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/NameBindingRequestFilter.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/NameBindingResponseFilter.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/RequestFilter.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/RequestInterceptor.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/ResponseFilter.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/ResponseInterceptor.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/StaticFeature.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/ExceptionResource.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/FilterResource.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/InterceptorResource.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/LocatorResource.java rename restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/{ManualInjectController.java => ManualInjectResource.java} (96%) create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/MessageBodyResource.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ExceptionTest.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/FilterTest.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/InterceptorTest.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/LocatorTest.java create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/MessageBodyTest.java diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/annotation/Filter.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/annotation/Filter.java new file mode 100644 index 00000000..9cdfbc1a --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/annotation/Filter.java @@ -0,0 +1,27 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.cases.annotation; + +import jakarta.ws.rs.NameBinding; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@NameBinding +@Target({ElementType.TYPE, ElementType.METHOD}) +@Retention(value = RetentionPolicy.RUNTIME) +public @interface Filter { +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/annotation/Interceptor.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/annotation/Interceptor.java new file mode 100644 index 00000000..88341cbd --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/annotation/Interceptor.java @@ -0,0 +1,27 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.cases.annotation; + +import jakarta.ws.rs.NameBinding; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@NameBinding +@Target({ElementType.TYPE, ElementType.METHOD}) +@Retention(value = RetentionPolicy.RUNTIME) +public @interface Interceptor { +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyReader.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyReader.java new file mode 100644 index 00000000..9e6b6b58 --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyReader.java @@ -0,0 +1,3 @@ +package io.esastack.restlight.integration.jaxrs.cases.providers; +public class BodyReader { +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyWriter.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyWriter.java new file mode 100644 index 00000000..83c13d00 --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyWriter.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.cases.providers; + +import io.esastack.restlight.integration.jaxrs.entity.UserData; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +@Provider +@Component +public class BodyWriter implements MessageBodyWriter { + + @Override + public boolean isWriteable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) { + return false; + } + + @Override + public void writeTo(UserData userData, Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { + + } +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/DynamicFeature.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/DynamicFeature.java new file mode 100644 index 00000000..3090f86e --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/DynamicFeature.java @@ -0,0 +1,25 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.cases.providers; + +import jakarta.ws.rs.core.Feature; +import jakarta.ws.rs.core.FeatureContext; + +public class DynamicFeature implements Feature { + + @Override + public boolean configure(FeatureContext context) { + return false; + } +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/GlobalExceptionMapper.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/GlobalExceptionMapper.java new file mode 100644 index 00000000..269061e0 --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/GlobalExceptionMapper.java @@ -0,0 +1,3 @@ +package io.esastack.restlight.integration.jaxrs.cases.providers; +public class GlobalExceptionMapper { +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/NameBindingRequestFilter.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/NameBindingRequestFilter.java new file mode 100644 index 00000000..37013a03 --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/NameBindingRequestFilter.java @@ -0,0 +1,31 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.cases.providers; + +import io.esastack.restlight.integration.jaxrs.cases.annotation.Filter; +import jakarta.ws.rs.container.ContainerRequestContext; +import jakarta.ws.rs.container.ContainerRequestFilter; +import jakarta.ws.rs.ext.Provider; +import org.springframework.stereotype.Component; + +@Filter +@Provider +@Component +public class NameBindingRequestFilter implements ContainerRequestFilter { + + @Override + public void filter(ContainerRequestContext requestContext) { + requestContext.getHeaders().add("name", "test"); + } +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/NameBindingResponseFilter.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/NameBindingResponseFilter.java new file mode 100644 index 00000000..03215853 --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/NameBindingResponseFilter.java @@ -0,0 +1,34 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.cases.providers; + +import io.esastack.restlight.integration.jaxrs.cases.annotation.Filter; +import io.esastack.restlight.integration.jaxrs.entity.UserData; +import jakarta.ws.rs.container.ContainerRequestContext; +import jakarta.ws.rs.container.ContainerResponseContext; +import jakarta.ws.rs.container.ContainerResponseFilter; +import jakarta.ws.rs.ext.Provider; +import org.springframework.stereotype.Component; + +@Filter +@Provider +@Component +public class NameBindingResponseFilter implements ContainerResponseFilter { + + @Override + public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) { + UserData userData = (UserData) responseContext.getEntity(); + userData.setName("test"); + } +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/RequestFilter.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/RequestFilter.java new file mode 100644 index 00000000..96c87199 --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/RequestFilter.java @@ -0,0 +1,3 @@ +package io.esastack.restlight.integration.jaxrs.cases.providers; +public class RequestFilter { +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/RequestInterceptor.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/RequestInterceptor.java new file mode 100644 index 00000000..90964c17 --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/RequestInterceptor.java @@ -0,0 +1,3 @@ +package io.esastack.restlight.integration.jaxrs.cases.providers; +public class RequestInterceptor { +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/ResponseFilter.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/ResponseFilter.java new file mode 100644 index 00000000..dd7043b3 --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/ResponseFilter.java @@ -0,0 +1,30 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.cases.providers; + +import io.esastack.restlight.integration.jaxrs.entity.UserData; +import jakarta.ws.rs.container.ContainerRequestContext; +import jakarta.ws.rs.container.ContainerResponseContext; +import jakarta.ws.rs.container.ContainerResponseFilter; + +public class ResponseFilter implements ContainerResponseFilter { + + @Override + public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) { + if (requestContext.getUriInfo().getRequestUri().getPath().equals("/integration/test/filter/response/global")) { + UserData userData = (UserData) responseContext.getEntity(); + userData.setName("test"); + } + } +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/ResponseInterceptor.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/ResponseInterceptor.java new file mode 100644 index 00000000..45d895a0 --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/ResponseInterceptor.java @@ -0,0 +1,3 @@ +package io.esastack.restlight.integration.jaxrs.cases.providers; +public class ResponseInterceptor { +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/StaticFeature.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/StaticFeature.java new file mode 100644 index 00000000..f70b44d5 --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/StaticFeature.java @@ -0,0 +1,29 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.cases.providers; + +import jakarta.ws.rs.core.Feature; +import jakarta.ws.rs.core.FeatureContext; +import jakarta.ws.rs.ext.Provider; +import org.springframework.stereotype.Component; + +@Component +@Provider +public class StaticFeature implements Feature { + + @Override + public boolean configure(FeatureContext context) { + return false; + } +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/ExceptionResource.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/ExceptionResource.java new file mode 100644 index 00000000..1113bd47 --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/ExceptionResource.java @@ -0,0 +1,3 @@ +package io.esastack.restlight.integration.jaxrs.cases.resources; +public class ExceptionResource { +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/FilterResource.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/FilterResource.java new file mode 100644 index 00000000..d157f602 --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/FilterResource.java @@ -0,0 +1,3 @@ +package io.esastack.restlight.integration.jaxrs.cases.resources; +public class FilterResource { +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/InterceptorResource.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/InterceptorResource.java new file mode 100644 index 00000000..2fbec423 --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/InterceptorResource.java @@ -0,0 +1,3 @@ +package io.esastack.restlight.integration.jaxrs.cases.resources; +public class InterceptorResource { +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/LocatorResource.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/LocatorResource.java new file mode 100644 index 00000000..c5c3b61f --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/LocatorResource.java @@ -0,0 +1,54 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.cases.resources; + +import io.esastack.restlight.integration.jaxrs.entity.UserData; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.QueryParam; +import org.springframework.stereotype.Controller; + +@Controller +@Path("/locator/") +public class LocatorResource { + + @Path("locate") + public SubLocatorResource locate() { + return new SubLocatorResource(); + } + + static class SubLocatorResource { + + @GET + public UserData subLocate(@QueryParam("name") String name) { + return UserData.Builder.anUserData() + .name(name).build(); + } + + @Path("cascade") + public Class cascadeSubLocate() { + return CascadeSubLocatorResource.class; + } + + } + + public static class CascadeSubLocatorResource { + + @GET + public UserData cascadeSubLocate(@QueryParam("name") String name) { + return UserData.Builder.anUserData() + .name(name).build(); + } + } +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/ManualInjectController.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/ManualInjectResource.java similarity index 96% rename from restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/ManualInjectController.java rename to restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/ManualInjectResource.java index 4aca5dc6..6675625f 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/ManualInjectController.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/ManualInjectResource.java @@ -19,7 +19,7 @@ import jakarta.ws.rs.QueryParam; @Path("/manual/inject") -public class ManualInjectController { +public class ManualInjectResource { @GET @Path("get") diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/MessageBodyResource.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/MessageBodyResource.java new file mode 100644 index 00000000..55f3d429 --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/MessageBodyResource.java @@ -0,0 +1,3 @@ +package io.esastack.restlight.integration.jaxrs.cases.resources; +public class MessageBodyResource { +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ExceptionTest.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ExceptionTest.java new file mode 100644 index 00000000..6fee23b4 --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ExceptionTest.java @@ -0,0 +1,3 @@ +package io.esastack.restlight.integration.jaxrs.test; +public class ExceptionTest { +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/FilterTest.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/FilterTest.java new file mode 100644 index 00000000..78963180 --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/FilterTest.java @@ -0,0 +1,3 @@ +package io.esastack.restlight.integration.jaxrs.test; +public class FilterTest { +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/InterceptorTest.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/InterceptorTest.java new file mode 100644 index 00000000..853f9621 --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/InterceptorTest.java @@ -0,0 +1,30 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.test; + +import io.esastack.restclient.RestResponseBase; +import io.esastack.restlight.integration.jaxrs.entity.UserData; +import org.junit.Assert; +import org.junit.Test; + +public class InterceptorTest extends BaseIntegrationTest { + + @Test + public void testRead() throws Exception { + RestResponseBase responseBase = restClient.get(domain + "/interceptor/read") + .execute().toCompletableFuture().get(); + UserData userData = responseBase.bodyToEntity(UserData.class); + Assert.assertEquals("test", userData.getName()); + } +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/LocatorTest.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/LocatorTest.java new file mode 100644 index 00000000..cfa367dc --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/LocatorTest.java @@ -0,0 +1,3 @@ +package io.esastack.restlight.integration.jaxrs.test; +public class LocatorTest { +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/MessageBodyTest.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/MessageBodyTest.java new file mode 100644 index 00000000..12dadd7a --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/MessageBodyTest.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.test; + +import io.esastack.restclient.RestResponseBase; +import io.esastack.restlight.integration.jaxrs.entity.UserData; +import org.junit.Assert; +import org.junit.Test; + +public class MessageBodyTest extends BaseIntegrationTest { + + @Test + public void testReader() throws Exception { + RestResponseBase responseBase = restClient.get(domain + "/message/body/reader") + .execute().toCompletableFuture().get(); + UserData userData = responseBase.bodyToEntity(UserData.class); + Assert.assertEquals("test", userData.getName()); + } + + @Test + public void testWriter() throws Exception { + RestResponseBase responseBase = restClient.get(domain + "/message/body/writer") + .execute().toCompletableFuture().get(); + UserData userData = responseBase.bodyToEntity(UserData.class); + Assert.assertEquals("test", userData.getName()); + } +} From 9f1954ad22064b49c345d6f3a0fa073e7f5ef67e Mon Sep 17 00:00:00 2001 From: chenglu Date: Tue, 26 Apr 2022 17:08:22 +0800 Subject: [PATCH 05/13] [Integration Test] fix the pom.xml issue --- pom.xml | 1 - .../cases/applications/ApplicationImpl.java | 4 +- .../jaxrs/cases/providers/BodyReader.java | 46 +++++++++++++- .../jaxrs/cases/providers/BodyWriter.java | 15 ++++- .../jaxrs/cases/providers/DynamicFeature.java | 10 +-- .../providers/GlobalExceptionMapper.java | 31 +++++++++- .../jaxrs/cases/providers/RequestFilter.java | 28 ++++++++- .../cases/providers/RequestInterceptor.java | 34 ++++++++++- .../cases/providers/ResponseInterceptor.java | 37 ++++++++++- .../jaxrs/cases/providers/StaticFeature.java | 3 + .../cases/resources/AnnotationResource.java | 10 +++ .../resources/AsyncResponseResource.java | 2 +- .../cases/resources/ExceptionResource.java | 27 ++++++++ .../jaxrs/cases/resources/FilterResource.java | 59 ++++++++++++++++++ .../cases/resources/InterceptorResource.java | 38 ++++++++++++ .../cases/resources/MessageBodyResource.java | 33 ++++++++++ .../jaxrs/test/AnnotationTest.java | 18 ++++-- .../integration/jaxrs/test/ExceptionTest.java | 29 ++++++++- .../integration/jaxrs/test/FilterTest.java | 61 ++++++++++++++++++- .../jaxrs/test/InterceptorTest.java | 8 +++ .../integration/jaxrs/test/LocatorTest.java | 37 ++++++++++- .../jaxrs/test/ValidationTest.java | 3 +- restlight-integration-test/pom.xml | 1 + .../springmvc/test/BaseIntegrationTest.java | 2 +- 24 files changed, 511 insertions(+), 26 deletions(-) diff --git a/pom.xml b/pom.xml index 92bd13b5..7ad88c57 100644 --- a/pom.xml +++ b/pom.xml @@ -137,7 +137,6 @@ restlight-bom restlight-benchmarks restlight-integration-test - restlight-integration-test/jaxrs-test diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/applications/ApplicationImpl.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/applications/ApplicationImpl.java index 963d0e56..78465357 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/applications/ApplicationImpl.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/applications/ApplicationImpl.java @@ -13,7 +13,7 @@ package io.esastack.restlight.integration.jaxrs.cases.applications; -import io.esastack.restlight.integration.jaxrs.cases.resources.ManualInjectController; +import io.esastack.restlight.integration.jaxrs.cases.resources.ManualInjectResource; import jakarta.ws.rs.ApplicationPath; import jakarta.ws.rs.core.Application; import org.springframework.stereotype.Component; @@ -28,7 +28,7 @@ public class ApplicationImpl extends Application { @Override public Set> getClasses() { Set> classes = new HashSet<>(); - classes.add(ManualInjectController.class); + classes.add(ManualInjectResource.class); return classes; } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyReader.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyReader.java index 9e6b6b58..4f39518f 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyReader.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyReader.java @@ -1,3 +1,47 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.cases.providers; -public class BodyReader { + +import io.esastack.restlight.integration.jaxrs.cases.resources.MessageBodyResource; +import io.esastack.restlight.integration.jaxrs.entity.UserData; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyReader; +import jakarta.ws.rs.ext.Provider; +import org.springframework.stereotype.Component; + +import java.io.InputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +@Provider +@Component +public class BodyReader implements MessageBodyReader { + + @Override + public boolean isReadable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) { + if (type.equals(MessageBodyResource.class)) { + return true; + } + return false; + } + + @Override + public UserData readFrom(Class type, Type genericType, Annotation[] annotations, + MediaType mediaType, MultivaluedMap httpHeaders, + InputStream entityStream) throws WebApplicationException { + return UserData.Builder.anUserData().name("test").build(); + } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyWriter.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyWriter.java index 83c13d00..de6b551a 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyWriter.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyWriter.java @@ -13,6 +13,7 @@ package io.esastack.restlight.integration.jaxrs.cases.providers; +import io.esastack.restlight.integration.jaxrs.cases.resources.MessageBodyResource; import io.esastack.restlight.integration.jaxrs.entity.UserData; import jakarta.ws.rs.WebApplicationException; import jakarta.ws.rs.core.MediaType; @@ -25,18 +26,26 @@ import java.io.OutputStream; import java.lang.annotation.Annotation; import java.lang.reflect.Type; +import java.nio.charset.StandardCharsets; @Provider @Component public class BodyWriter implements MessageBodyWriter { - + @Override public boolean isWriteable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) { + if (type.equals(MessageBodyResource.class)) { + return true; + } return false; } @Override - public void writeTo(UserData userData, Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { - + public void writeTo(UserData userData, Class type, Type genericType, Annotation[] annotations, + MediaType mediaType, MultivaluedMap httpHeaders, + OutputStream entityStream) throws WebApplicationException, IOException { + if (userData == null) { + entityStream.write("{\"name\": \"test\"}".getBytes(StandardCharsets.UTF_8)); + } } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/DynamicFeature.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/DynamicFeature.java index 3090f86e..b3013cf9 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/DynamicFeature.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/DynamicFeature.java @@ -13,13 +13,15 @@ package io.esastack.restlight.integration.jaxrs.cases.providers; -import jakarta.ws.rs.core.Feature; +import jakarta.ws.rs.container.ResourceInfo; import jakarta.ws.rs.core.FeatureContext; -public class DynamicFeature implements Feature { +public class DynamicFeature implements jakarta.ws.rs.container.DynamicFeature { @Override - public boolean configure(FeatureContext context) { - return false; + public void configure(ResourceInfo resourceInfo, FeatureContext context) { + if (resourceInfo.getResourceMethod().getName().equals("dynamicFeature")) { + context.property("name", "test"); + } } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/GlobalExceptionMapper.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/GlobalExceptionMapper.java index 269061e0..d58182a5 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/GlobalExceptionMapper.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/GlobalExceptionMapper.java @@ -1,3 +1,32 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.cases.providers; -public class GlobalExceptionMapper { + +import io.esastack.restlight.integration.jaxrs.entity.UserData; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.ext.ExceptionMapper; +import jakarta.ws.rs.ext.Provider; +import org.springframework.stereotype.Component; + +@Provider +@Component +public class GlobalExceptionMapper implements ExceptionMapper { + + @Override + public Response toResponse(IllegalArgumentException exception) { + return Response.status(200) + .entity(UserData.Builder.anUserData().name(exception.getMessage()).build()) + .build(); + } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/RequestFilter.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/RequestFilter.java index 96c87199..a8a3cf68 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/RequestFilter.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/RequestFilter.java @@ -1,3 +1,29 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.cases.providers; -public class RequestFilter { + +import jakarta.ws.rs.container.ContainerRequestContext; +import jakarta.ws.rs.container.ContainerRequestFilter; +import jakarta.ws.rs.ext.Provider; + +@Provider +public class RequestFilter implements ContainerRequestFilter { + + @Override + public void filter(ContainerRequestContext requestContext) { + if (requestContext.getUriInfo().getRequestUri().getPath().equals("/integration/test/filter/request/global")) { + requestContext.getHeaders().add("name", "test"); + } + } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/RequestInterceptor.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/RequestInterceptor.java index 90964c17..953618fd 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/RequestInterceptor.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/RequestInterceptor.java @@ -1,3 +1,35 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.cases.providers; -public class RequestInterceptor { + +import io.esastack.restlight.integration.jaxrs.cases.annotation.Interceptor; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.ext.Provider; +import jakarta.ws.rs.ext.ReaderInterceptor; +import jakarta.ws.rs.ext.ReaderInterceptorContext; +import org.springframework.stereotype.Component; + +import java.io.IOException; + +@Interceptor +@Provider +@Component +public class RequestInterceptor implements ReaderInterceptor { + + @Override + public Object aroundReadFrom(ReaderInterceptorContext context) throws WebApplicationException, IOException { + context.getHeaders().add("interceptorName", "test"); + return context.proceed(); + } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/ResponseInterceptor.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/ResponseInterceptor.java index 45d895a0..daee5125 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/ResponseInterceptor.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/ResponseInterceptor.java @@ -1,3 +1,38 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.cases.providers; -public class ResponseInterceptor { + +import io.esastack.restlight.integration.jaxrs.cases.annotation.Interceptor; +import io.esastack.restlight.integration.jaxrs.entity.UserData; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.ext.Provider; +import jakarta.ws.rs.ext.WriterInterceptor; +import jakarta.ws.rs.ext.WriterInterceptorContext; +import org.springframework.stereotype.Component; + +import java.io.IOException; + +@Interceptor +@Provider +@Component +public class ResponseInterceptor implements WriterInterceptor { + + @Override + public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException { + if (context.getEntity() == null) { + context.setEntity(UserData.Builder.anUserData().name("test").build()); + } + context.proceed(); + } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/StaticFeature.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/StaticFeature.java index f70b44d5..a2059f50 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/StaticFeature.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/StaticFeature.java @@ -24,6 +24,9 @@ public class StaticFeature implements Feature { @Override public boolean configure(FeatureContext context) { + context.register(RequestFilter.class); + context.register(ResponseFilter.class); + context.register(DynamicFeature.class); return false; } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/AnnotationResource.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/AnnotationResource.java index eb3fd723..4a365ce9 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/AnnotationResource.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/AnnotationResource.java @@ -17,6 +17,7 @@ import jakarta.ws.rs.BeanParam; import jakarta.ws.rs.DELETE; import jakarta.ws.rs.GET; +import jakarta.ws.rs.MatrixParam; import jakarta.ws.rs.POST; import jakarta.ws.rs.PUT; import jakarta.ws.rs.Path; @@ -61,6 +62,15 @@ public UserData put(@PathParam("name") String name) { .name(name).build(); } + @GET + @Path("get/matrix/{age}") + public UserData matrix(@MatrixParam("name") String name, @PathParam("age") Integer age) { + UserData userData = UserData.Builder.anUserData() + .name(name).build(); + userData.setAge(age); + return userData; + } + @GET @Path("get/context/headers") public UserData headers(@Context HttpHeaders httpHeaders) { diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/AsyncResponseResource.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/AsyncResponseResource.java index df1344b1..2eb7911d 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/AsyncResponseResource.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/AsyncResponseResource.java @@ -46,7 +46,7 @@ public UserData async(@Suspended AsyncResponse asyncResponse, @QueryParam("name" @GET @Path("future") - public CompletionStage future( @QueryParam("name") String name, @QueryParam("timeout") Long timeout) { + public CompletionStage future(@QueryParam("name") String name, @QueryParam("timeout") Long timeout) { CompletableFuture promise = new CompletableFuture<>(); new Thread(() -> { try { diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/ExceptionResource.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/ExceptionResource.java index 1113bd47..1ee053a0 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/ExceptionResource.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/ExceptionResource.java @@ -1,3 +1,30 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.cases.resources; + +import io.esastack.restlight.integration.jaxrs.entity.UserData; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import org.springframework.stereotype.Controller; + +@Controller +@Path("/exception/") public class ExceptionResource { + + @GET + @Path("illegal") + public UserData illegal() { + throw new IllegalArgumentException("IllegalArgument"); + } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/FilterResource.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/FilterResource.java index d157f602..5249d0c9 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/FilterResource.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/FilterResource.java @@ -1,3 +1,62 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.cases.resources; + +import io.esastack.restlight.integration.jaxrs.cases.annotation.Filter; +import io.esastack.restlight.integration.jaxrs.entity.UserData; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.HeaderParam; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.core.Configuration; +import jakarta.ws.rs.core.Context; +import org.springframework.stereotype.Controller; + +@Controller +@Path("/filter/") public class FilterResource { + + @GET + @Path("request/global") + public UserData requestGlobal(@HeaderParam("name") String name) { + return UserData.Builder.anUserData() + .name(name).build(); + } + + @GET + @Path("response/global") + public UserData responseGlobal() { + return UserData.Builder.anUserData().build(); + } + + @GET + @Path("request/binding") + @Filter + public UserData requestBinding(@HeaderParam("name") String name) { + return UserData.Builder.anUserData().name(name).build(); + } + + @GET + @Path("response/binding") + @Filter + public UserData responseBinding() { + return UserData.Builder.anUserData().build(); + } + + @GET + @Path("dynamic/feature") + public UserData dynamicFeature(@Context Configuration configuration) { + return UserData.Builder.anUserData() + .name(configuration.getProperty("name").toString()).build(); + } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/InterceptorResource.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/InterceptorResource.java index 2fbec423..e7d33a22 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/InterceptorResource.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/InterceptorResource.java @@ -1,3 +1,41 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.cases.resources; + +import io.esastack.restlight.integration.jaxrs.cases.annotation.Interceptor; +import io.esastack.restlight.integration.jaxrs.entity.UserData; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.HeaderParam; +import jakarta.ws.rs.Path; +import org.springframework.stereotype.Controller; + +@Controller +@Path("/interceptor/") public class InterceptorResource { + + @Interceptor + @GET + @Path("read") + public UserData read(@HeaderParam("interceptorName") String name) { + return UserData.Builder.anUserData() + .name(name).build(); + } + + @Interceptor + @GET + @Path("write") + public UserData write() { + return null; + } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/MessageBodyResource.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/MessageBodyResource.java index 55f3d429..1995f4c0 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/MessageBodyResource.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/MessageBodyResource.java @@ -1,3 +1,36 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.cases.resources; + +import io.esastack.restlight.integration.jaxrs.entity.UserData; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import org.springframework.stereotype.Controller; + +@Controller +@Path("/message/body/") public class MessageBodyResource { + + @GET + @Path("reader") + public UserData reader(UserData userData) { + return userData; + } + + @GET + @Path("writer") + public UserData writer() { + return null; + } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/AnnotationTest.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/AnnotationTest.java index eb9c2a43..f4117be0 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/AnnotationTest.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/AnnotationTest.java @@ -62,7 +62,16 @@ public void testPut() throws Exception { } @Test - public void testContextHeaders () throws Exception { + public void testMatrix() throws Exception { + RestResponseBase responseBase = restClient.get(domain + "/annotation/get/matrix/10;name=test") + .execute().toCompletableFuture().get(); + UserData userData = responseBase.bodyToEntity(UserData.class); + Assert.assertEquals("test", userData.getName()); + Assert.assertTrue(10 == userData.getAge()); + } + + @Test + public void testContextHeaders() throws Exception { RestResponseBase responseBase = restClient.get(domain + "/annotation/get/context/headers") .addHeader("name", "test").execute().toCompletableFuture().get(); UserData userData = responseBase.bodyToEntity(UserData.class); @@ -70,21 +79,21 @@ public void testContextHeaders () throws Exception { } @Test - public void testContextProviders () throws Exception { + public void testContextProviders() throws Exception { RestResponseBase responseBase = restClient.get(domain + "/annotation/get/context/providers") .execute().toCompletableFuture().get(); Assert.assertEquals(ProvidersImpl.class.getName(), responseBase.bodyToEntity(String.class)); } @Test - public void testRequest () throws Exception { + public void testRequest() throws Exception { RestResponseBase responseBase = restClient.get(domain + "/annotation/get/context/request") .execute().toCompletableFuture().get(); Assert.assertEquals("GET", responseBase.bodyToEntity(String.class)); } @Test - public void testResource () throws Exception { + public void testResource() throws Exception { RestResponseBase responseBase = restClient.get(domain + "/annotation/get/context/resource") .execute().toCompletableFuture().get(); Assert.assertEquals(AnnotationResource.class.getName(), responseBase.bodyToEntity(String.class)); @@ -101,7 +110,6 @@ public void testUri() throws Exception { public void testConfiguration() throws Exception { RestResponseBase responseBase = restClient.get(domain + "/annotation/get/context/configuration") .execute().toCompletableFuture().get(); - System.out.println(); Assert.assertEquals(ConfigurationImpl.class.getName(), responseBase.bodyToEntity(String.class)); } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ExceptionTest.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ExceptionTest.java index 6fee23b4..e457b5ed 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ExceptionTest.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ExceptionTest.java @@ -1,3 +1,30 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.test; -public class ExceptionTest { + +import io.esastack.restclient.RestResponseBase; +import io.esastack.restlight.integration.jaxrs.entity.UserData; +import org.junit.Assert; +import org.junit.Test; + +public class ExceptionTest extends BaseIntegrationTest { + + @Test + public void testIllegal() throws Exception { + RestResponseBase responseBase = restClient.get(domain + "/exception/illegal") + .execute().toCompletableFuture().get(); + UserData userData = responseBase.bodyToEntity(UserData.class); + Assert.assertEquals("IllegalArgument", userData.getName()); + } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/FilterTest.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/FilterTest.java index 78963180..1e960869 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/FilterTest.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/FilterTest.java @@ -1,3 +1,62 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.test; -public class FilterTest { + +import io.esastack.restclient.RestResponseBase; +import io.esastack.restlight.integration.jaxrs.entity.UserData; +import org.junit.Assert; +import org.junit.Test; + +public class FilterTest extends BaseIntegrationTest { + + @Test + public void testRequestGlobal() throws Exception { + RestResponseBase responseBase = restClient.get(domain + "/filter/request/global") + .execute().toCompletableFuture().get(); + UserData userData = responseBase.bodyToEntity(UserData.class); + Assert.assertEquals("test", userData.getName()); + } + + @Test + public void testResponseGlobal() throws Exception { + RestResponseBase responseBase = restClient.get(domain + "/filter/response/global") + .execute().toCompletableFuture().get(); + UserData userData = responseBase.bodyToEntity(UserData.class); + Assert.assertEquals("test", userData.getName()); + } + + @Test + public void testRequestBinding() throws Exception { + RestResponseBase responseBase = restClient.get(domain + "/filter/request/binding") + .execute().toCompletableFuture().get(); + UserData userData = responseBase.bodyToEntity(UserData.class); + Assert.assertEquals("test", userData.getName()); + } + + @Test + public void testResponseBinding() throws Exception { + RestResponseBase responseBase = restClient.get(domain + "/filter/response/binding") + .execute().toCompletableFuture().get(); + UserData userData = responseBase.bodyToEntity(UserData.class); + Assert.assertEquals("test", userData.getName()); + } + + @Test + public void testDynamicFeature() throws Exception { + RestResponseBase responseBase = restClient.get(domain + "/filter/dynamic/feature") + .execute().toCompletableFuture().get(); + UserData userData = responseBase.bodyToEntity(UserData.class); + Assert.assertEquals("test", userData.getName()); + } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/InterceptorTest.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/InterceptorTest.java index 853f9621..3e9dfea2 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/InterceptorTest.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/InterceptorTest.java @@ -27,4 +27,12 @@ public void testRead() throws Exception { UserData userData = responseBase.bodyToEntity(UserData.class); Assert.assertEquals("test", userData.getName()); } + + @Test + public void testWrite() throws Exception { + RestResponseBase responseBase = restClient.get(domain + "/interceptor/write") + .execute().toCompletableFuture().get(); + UserData userData = responseBase.bodyToEntity(UserData.class); + Assert.assertEquals("test", userData.getName()); + } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/LocatorTest.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/LocatorTest.java index cfa367dc..1c20eeef 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/LocatorTest.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/LocatorTest.java @@ -1,3 +1,38 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.test; -public class LocatorTest { + +import io.esastack.restclient.RestResponseBase; +import io.esastack.restlight.integration.jaxrs.entity.UserData; +import org.junit.Assert; +import org.junit.Test; + +public class LocatorTest extends BaseIntegrationTest { + + @Test + public void testLocate() throws Exception { + RestResponseBase responseBase = restClient.get(domain + "/locator/locate") + .addParam("name", "test").execute().toCompletableFuture().get(); + UserData userData = responseBase.bodyToEntity(UserData.class); + Assert.assertEquals("test", userData.getName()); + } + + @Test + public void testCascadeLocate() throws Exception { + RestResponseBase responseBase = restClient.get(domain + "/locator/locate/cascade") + .addParam("name", "test").execute().toCompletableFuture().get(); + UserData userData = responseBase.bodyToEntity(UserData.class); + Assert.assertEquals("test", userData.getName()); + } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ValidationTest.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ValidationTest.java index a0662646..e70fbd86 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ValidationTest.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ValidationTest.java @@ -43,7 +43,8 @@ public void testRequestEntity() throws Exception { @Test public void testResponseParam() throws Exception { - RestResponseBase responseBase = restClient.get(domain + "/validation/response/param").execute().toCompletableFuture().get(); + RestResponseBase responseBase = restClient.get(domain + "/validation/response/param") + .execute().toCompletableFuture().get(); Assert.assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.code(), responseBase.status()); } diff --git a/restlight-integration-test/pom.xml b/restlight-integration-test/pom.xml index 9687a0bc..2404bbd6 100644 --- a/restlight-integration-test/pom.xml +++ b/restlight-integration-test/pom.xml @@ -15,6 +15,7 @@ springmvc-test + jaxrs-test diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/BaseIntegrationTest.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/BaseIntegrationTest.java index b798f4ac..d09b34fc 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/BaseIntegrationTest.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/BaseIntegrationTest.java @@ -36,7 +36,7 @@ public static void setUp() { restClient = RestClient.ofDefault(); ctx = new AnnotationConfigApplicationContext(); - ctx.scan("io.esastack.restlight.integration.cases"); + ctx.scan("io.esastack.restlight.integration.springmvc.cases"); ctx.refresh(); final String contextPath = "/intergration/test"; From ed41ef0f7fb2955560d478475a2acc975dc4b0a9 Mon Sep 17 00:00:00 2001 From: chenglu Date: Tue, 26 Apr 2022 17:56:17 +0800 Subject: [PATCH 06/13] [Integration Test] fix the reader and writer case --- .../jaxrs/cases/providers/BodyReader.java | 18 +++---- .../jaxrs/cases/providers/BodyWriter.java | 8 +-- .../cases/resources/MessageBodyResource.java | 8 +-- .../jaxrs/entity/MessageBodyData.java | 49 +++++++++++++++++++ .../jaxrs/test/MessageBodyTest.java | 10 ++-- .../adapter/MessageBodyReaderAdapter.java | 2 +- 6 files changed, 70 insertions(+), 25 deletions(-) create mode 100644 restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/entity/MessageBodyData.java diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyReader.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyReader.java index 4f39518f..facd002d 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyReader.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyReader.java @@ -13,8 +13,7 @@ package io.esastack.restlight.integration.jaxrs.cases.providers; -import io.esastack.restlight.integration.jaxrs.cases.resources.MessageBodyResource; -import io.esastack.restlight.integration.jaxrs.entity.UserData; +import io.esastack.restlight.integration.jaxrs.entity.MessageBodyData; import jakarta.ws.rs.WebApplicationException; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.MultivaluedMap; @@ -28,20 +27,17 @@ @Provider @Component -public class BodyReader implements MessageBodyReader { +public class BodyReader implements MessageBodyReader { @Override public boolean isReadable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) { - if (type.equals(MessageBodyResource.class)) { - return true; - } - return false; + return true; } @Override - public UserData readFrom(Class type, Type genericType, Annotation[] annotations, - MediaType mediaType, MultivaluedMap httpHeaders, - InputStream entityStream) throws WebApplicationException { - return UserData.Builder.anUserData().name("test").build(); + public MessageBodyData readFrom(Class type, Type genericType, Annotation[] annotations, + MediaType mediaType, MultivaluedMap httpHeaders, + InputStream entityStream) throws WebApplicationException { + return MessageBodyData.Builder.aBodyMessageData().name("test").build(); } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyWriter.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyWriter.java index de6b551a..8605cff5 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyWriter.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyWriter.java @@ -14,7 +14,7 @@ package io.esastack.restlight.integration.jaxrs.cases.providers; import io.esastack.restlight.integration.jaxrs.cases.resources.MessageBodyResource; -import io.esastack.restlight.integration.jaxrs.entity.UserData; +import io.esastack.restlight.integration.jaxrs.entity.MessageBodyData; import jakarta.ws.rs.WebApplicationException; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.MultivaluedMap; @@ -30,7 +30,7 @@ @Provider @Component -public class BodyWriter implements MessageBodyWriter { +public class BodyWriter implements MessageBodyWriter { @Override public boolean isWriteable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) { @@ -41,10 +41,10 @@ public boolean isWriteable(Class type, Type genericType, Annotation[] annotat } @Override - public void writeTo(UserData userData, Class type, Type genericType, Annotation[] annotations, + public void writeTo(MessageBodyData messageBodyData, Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, OutputStream entityStream) throws WebApplicationException, IOException { - if (userData == null) { + if (messageBodyData == null) { entityStream.write("{\"name\": \"test\"}".getBytes(StandardCharsets.UTF_8)); } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/MessageBodyResource.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/MessageBodyResource.java index 1995f4c0..fa5a9ee0 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/MessageBodyResource.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/MessageBodyResource.java @@ -13,7 +13,7 @@ package io.esastack.restlight.integration.jaxrs.cases.resources; -import io.esastack.restlight.integration.jaxrs.entity.UserData; +import io.esastack.restlight.integration.jaxrs.entity.MessageBodyData; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import org.springframework.stereotype.Controller; @@ -24,13 +24,13 @@ public class MessageBodyResource { @GET @Path("reader") - public UserData reader(UserData userData) { - return userData; + public MessageBodyData reader(MessageBodyData messageBodyData) { + return messageBodyData; } @GET @Path("writer") - public UserData writer() { + public MessageBodyData writer() { return null; } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/entity/MessageBodyData.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/entity/MessageBodyData.java new file mode 100644 index 00000000..71a293ea --- /dev/null +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/entity/MessageBodyData.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 OPPO ESA Stack Project + * 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 + * http://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.esastack.restlight.integration.jaxrs.entity; + +public class MessageBodyData { + + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public static final class Builder { + private String name; + + private Builder() { + } + + public static Builder aBodyMessageData() { + return new Builder(); + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public MessageBodyData build() { + MessageBodyData messageBodyData = new MessageBodyData(); + messageBodyData.setName(name); + return messageBodyData; + } + } +} diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/MessageBodyTest.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/MessageBodyTest.java index 12dadd7a..3c73dc9a 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/MessageBodyTest.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/MessageBodyTest.java @@ -14,7 +14,7 @@ package io.esastack.restlight.integration.jaxrs.test; import io.esastack.restclient.RestResponseBase; -import io.esastack.restlight.integration.jaxrs.entity.UserData; +import io.esastack.restlight.integration.jaxrs.entity.MessageBodyData; import org.junit.Assert; import org.junit.Test; @@ -24,15 +24,15 @@ public class MessageBodyTest extends BaseIntegrationTest { public void testReader() throws Exception { RestResponseBase responseBase = restClient.get(domain + "/message/body/reader") .execute().toCompletableFuture().get(); - UserData userData = responseBase.bodyToEntity(UserData.class); - Assert.assertEquals("test", userData.getName()); + MessageBodyData messageBodyData = responseBase.bodyToEntity(MessageBodyData.class); + Assert.assertEquals("test", messageBodyData.getName()); } @Test public void testWriter() throws Exception { RestResponseBase responseBase = restClient.get(domain + "/message/body/writer") .execute().toCompletableFuture().get(); - UserData userData = responseBase.bodyToEntity(UserData.class); - Assert.assertEquals("test", userData.getName()); + MessageBodyData messageBodyData = responseBase.bodyToEntity(MessageBodyData.class); + Assert.assertEquals("test", messageBodyData.getName()); } } diff --git a/restlight-jaxrs-provider/src/main/java/io/esastack/restlight/jaxrs/adapter/MessageBodyReaderAdapter.java b/restlight-jaxrs-provider/src/main/java/io/esastack/restlight/jaxrs/adapter/MessageBodyReaderAdapter.java index cc96deea..31b57edf 100644 --- a/restlight-jaxrs-provider/src/main/java/io/esastack/restlight/jaxrs/adapter/MessageBodyReaderAdapter.java +++ b/restlight-jaxrs-provider/src/main/java/io/esastack/restlight/jaxrs/adapter/MessageBodyReaderAdapter.java @@ -66,7 +66,7 @@ public boolean supports(Param param) { @Override public int getOrder() { - return Ordered.LOWEST_PRECEDENCE; + return Ordered.HIGHEST_PRECEDENCE; } } From c4cdbb6cac549f770a5b291970d839c22f09f948 Mon Sep 17 00:00:00 2001 From: chenglu Date: Tue, 26 Apr 2022 17:57:10 +0800 Subject: [PATCH 07/13] [Integration Test] revert the bug change --- .../restlight/jaxrs/adapter/MessageBodyReaderAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/restlight-jaxrs-provider/src/main/java/io/esastack/restlight/jaxrs/adapter/MessageBodyReaderAdapter.java b/restlight-jaxrs-provider/src/main/java/io/esastack/restlight/jaxrs/adapter/MessageBodyReaderAdapter.java index 31b57edf..cc96deea 100644 --- a/restlight-jaxrs-provider/src/main/java/io/esastack/restlight/jaxrs/adapter/MessageBodyReaderAdapter.java +++ b/restlight-jaxrs-provider/src/main/java/io/esastack/restlight/jaxrs/adapter/MessageBodyReaderAdapter.java @@ -66,7 +66,7 @@ public boolean supports(Param param) { @Override public int getOrder() { - return Ordered.HIGHEST_PRECEDENCE; + return Ordered.LOWEST_PRECEDENCE; } } From ce1e3944e72ad6fec4e505716cee0cb1d54de289 Mon Sep 17 00:00:00 2001 From: chenglu Date: Tue, 26 Apr 2022 18:00:09 +0800 Subject: [PATCH 08/13] [Integration test] fix the case issue --- .../integration/jaxrs/cases/providers/BodyWriter.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyWriter.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyWriter.java index 8605cff5..44114fdb 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyWriter.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyWriter.java @@ -13,7 +13,6 @@ package io.esastack.restlight.integration.jaxrs.cases.providers; -import io.esastack.restlight.integration.jaxrs.cases.resources.MessageBodyResource; import io.esastack.restlight.integration.jaxrs.entity.MessageBodyData; import jakarta.ws.rs.WebApplicationException; import jakarta.ws.rs.core.MediaType; @@ -34,10 +33,7 @@ public class BodyWriter implements MessageBodyWriter { @Override public boolean isWriteable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) { - if (type.equals(MessageBodyResource.class)) { - return true; - } - return false; + return true; } @Override From f839f64bd1472c058a3913a2c5c6f5c5d0b454ec Mon Sep 17 00:00:00 2001 From: chenglu Date: Tue, 26 Apr 2022 19:50:37 +0800 Subject: [PATCH 09/13] [Integration test] fix the body message ci problem. --- .../integration/jaxrs/cases/providers/BodyWriter.java | 4 ++++ .../jaxrs/cases/resources/MessageBodyResource.java | 4 ++++ .../restlight/integration/jaxrs/test/MessageBodyTest.java | 5 +++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyWriter.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyWriter.java index 44114fdb..f14866c1 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyWriter.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyWriter.java @@ -13,6 +13,7 @@ package io.esastack.restlight.integration.jaxrs.cases.providers; +import io.esastack.restlight.core.serialize.JacksonSerializer; import io.esastack.restlight.integration.jaxrs.entity.MessageBodyData; import jakarta.ws.rs.WebApplicationException; import jakarta.ws.rs.core.MediaType; @@ -40,8 +41,11 @@ public boolean isWriteable(Class type, Type genericType, Annotation[] annotat public void writeTo(MessageBodyData messageBodyData, Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, OutputStream entityStream) throws WebApplicationException, IOException { + httpHeaders.add("Content-Type", mediaType.getType() + "/" + mediaType.getSubtype()); if (messageBodyData == null) { entityStream.write("{\"name\": \"test\"}".getBytes(StandardCharsets.UTF_8)); + } else { + entityStream.write(new JacksonSerializer().serialize(messageBodyData)); } } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/MessageBodyResource.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/MessageBodyResource.java index fa5a9ee0..8e4617eb 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/MessageBodyResource.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/MessageBodyResource.java @@ -16,18 +16,22 @@ import io.esastack.restlight.integration.jaxrs.entity.MessageBodyData; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; import org.springframework.stereotype.Controller; @Controller @Path("/message/body/") public class MessageBodyResource { + @Produces(MediaType.APPLICATION_JSON) @GET @Path("reader") public MessageBodyData reader(MessageBodyData messageBodyData) { return messageBodyData; } + @Produces(MediaType.APPLICATION_JSON) @GET @Path("writer") public MessageBodyData writer() { diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/MessageBodyTest.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/MessageBodyTest.java index 3c73dc9a..e2e4854e 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/MessageBodyTest.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/MessageBodyTest.java @@ -13,6 +13,7 @@ package io.esastack.restlight.integration.jaxrs.test; +import io.esastack.commons.net.http.MediaType; import io.esastack.restclient.RestResponseBase; import io.esastack.restlight.integration.jaxrs.entity.MessageBodyData; import org.junit.Assert; @@ -23,7 +24,7 @@ public class MessageBodyTest extends BaseIntegrationTest { @Test public void testReader() throws Exception { RestResponseBase responseBase = restClient.get(domain + "/message/body/reader") - .execute().toCompletableFuture().get(); + .contentType(MediaType.APPLICATION_JSON).execute().toCompletableFuture().get(); MessageBodyData messageBodyData = responseBase.bodyToEntity(MessageBodyData.class); Assert.assertEquals("test", messageBodyData.getName()); } @@ -31,7 +32,7 @@ public void testReader() throws Exception { @Test public void testWriter() throws Exception { RestResponseBase responseBase = restClient.get(domain + "/message/body/writer") - .execute().toCompletableFuture().get(); + .contentType(MediaType.APPLICATION_JSON).execute().toCompletableFuture().get(); MessageBodyData messageBodyData = responseBase.bodyToEntity(MessageBodyData.class); Assert.assertEquals("test", messageBodyData.getName()); } From 85c49eb9501170de7f01b52a4caa2e80408959a6 Mon Sep 17 00:00:00 2001 From: chenglu Date: Wed, 27 Apr 2022 11:53:33 +0800 Subject: [PATCH 10/13] [ISSUE #155] fix the ci case problem. --- .../integration/jaxrs/cases/providers/BodyWriter.java | 10 ++++------ .../jaxrs/cases/resources/InterceptorResource.java | 2 +- .../jaxrs/cases/resources/MessageBodyResource.java | 2 +- .../integration/jaxrs/test/MessageBodyTest.java | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyWriter.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyWriter.java index f14866c1..3e369337 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyWriter.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyWriter.java @@ -26,7 +26,6 @@ import java.io.OutputStream; import java.lang.annotation.Annotation; import java.lang.reflect.Type; -import java.nio.charset.StandardCharsets; @Provider @Component @@ -41,11 +40,10 @@ public boolean isWriteable(Class type, Type genericType, Annotation[] annotat public void writeTo(MessageBodyData messageBodyData, Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, OutputStream entityStream) throws WebApplicationException, IOException { - httpHeaders.add("Content-Type", mediaType.getType() + "/" + mediaType.getSubtype()); - if (messageBodyData == null) { - entityStream.write("{\"name\": \"test\"}".getBytes(StandardCharsets.UTF_8)); - } else { - entityStream.write(new JacksonSerializer().serialize(messageBodyData)); + if (messageBodyData.getName() == null) { + messageBodyData.setName("test-byBodyWriter"); } + httpHeaders.add("Content-Type", mediaType.getType() + "/" + mediaType.getSubtype()); + entityStream.write(new JacksonSerializer().serialize(messageBodyData)); } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/InterceptorResource.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/InterceptorResource.java index e7d33a22..56c75cfa 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/InterceptorResource.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/InterceptorResource.java @@ -27,7 +27,7 @@ public class InterceptorResource { @Interceptor @GET @Path("read") - public UserData read(@HeaderParam("interceptorName") String name) { + public UserData read(UserData userData, @HeaderParam("interceptorName") String name) { return UserData.Builder.anUserData() .name(name).build(); } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/MessageBodyResource.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/MessageBodyResource.java index 8e4617eb..47a009ee 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/MessageBodyResource.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/resources/MessageBodyResource.java @@ -35,6 +35,6 @@ public MessageBodyData reader(MessageBodyData messageBodyData) { @GET @Path("writer") public MessageBodyData writer() { - return null; + return MessageBodyData.Builder.aBodyMessageData().build(); } } diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/MessageBodyTest.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/MessageBodyTest.java index e2e4854e..2f7703e9 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/MessageBodyTest.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/MessageBodyTest.java @@ -34,6 +34,6 @@ public void testWriter() throws Exception { RestResponseBase responseBase = restClient.get(domain + "/message/body/writer") .contentType(MediaType.APPLICATION_JSON).execute().toCompletableFuture().get(); MessageBodyData messageBodyData = responseBase.bodyToEntity(MessageBodyData.class); - Assert.assertEquals("test", messageBodyData.getName()); + Assert.assertEquals("test-byBodyWriter", messageBodyData.getName()); } } From d5ffedc337bb21a6e8cdd8a84ec5855399ca9ba7 Mon Sep 17 00:00:00 2001 From: chenglu Date: Wed, 27 Apr 2022 16:16:43 +0800 Subject: [PATCH 11/13] [Integration Test] fix the ci problem in ValidationTest --- .../restlight/integration/jaxrs/test/ValidationTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ValidationTest.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ValidationTest.java index e70fbd86..80a18fb5 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ValidationTest.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/test/ValidationTest.java @@ -29,7 +29,7 @@ public void testRequestParam() throws Exception { Assert.assertEquals("test", userData.getName()); responseBase = restClient.get(domain + "/validation/request/param").execute().toCompletableFuture().get(); - Assert.assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.code(), responseBase.status()); + Assert.assertEquals(HttpStatus.BAD_REQUEST.code(), responseBase.status()); } @Test @@ -37,8 +37,7 @@ public void testRequestEntity() throws Exception { UserData entity = UserData.Builder.anUserData().build(); RestResponseBase responseBase = restClient.post(domain + "/validation/request/entity").entity(entity) .execute().toCompletableFuture().get(); - UserData userData = responseBase.bodyToEntity(UserData.class); - Assert.assertEquals("test", userData.getName()); + Assert.assertEquals(HttpStatus.BAD_REQUEST.code(), responseBase.status()); } @Test From a02f40482909fc9a46685e5416cf3ada3177e53a Mon Sep 17 00:00:00 2001 From: chenglu Date: Wed, 27 Apr 2022 17:13:20 +0800 Subject: [PATCH 12/13] [Integration Test] fix the ci problem in springmvc AnnotationTest --- .../controller/AnnotationController.java | 22 ++++++++++++++----- .../springmvc/test/AnnotationTest.java | 4 ++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/AnnotationController.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/AnnotationController.java index 15c6d193..468301b0 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/AnnotationController.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/cases/controller/AnnotationController.java @@ -20,8 +20,20 @@ import io.esastack.restlight.integration.springmvc.cases.annotation.CustomResponseBody; import io.esastack.restlight.integration.springmvc.entity.UserData; import org.springframework.http.HttpStatus; -import org.springframework.util.MultiValueMap; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.CookieValue; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.MatrixVariable; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestAttribute; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/annotation/") @@ -66,10 +78,10 @@ public UserData header(@RequestHeader String name) { .name(name).build(); } - @GetMapping("get/matrix") - public UserData matrix(@MatrixVariable MultiValueMap map) { + @GetMapping("get/matrix/{age}") + public UserData matrix(@PathVariable Integer age, @MatrixVariable String name) { return UserData.Builder.anUserData() - .name(map.getFirst("name")).build(); + .age(age).name(name).build(); } @GetMapping("get/attribute") diff --git a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/AnnotationTest.java b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/AnnotationTest.java index 49369de4..821019a6 100644 --- a/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/AnnotationTest.java +++ b/restlight-integration-test/springmvc-test/src/main/java/io/esastack/restlight/integration/springmvc/test/AnnotationTest.java @@ -88,11 +88,11 @@ public void testHeader() throws Exception { @Test public void testMatrix() throws Exception { - RestResponseBase response = restClient.get(domain + "/annotation/get/matrix") - .addParam("name", "test,test2").execute() + RestResponseBase response = restClient.get(domain + "/annotation/get/matrix/10;name=test").execute() .toCompletableFuture().get(); UserData userData = response.bodyToEntity(UserData.class); Assert.assertEquals("test", userData.getName()); + Assert.assertTrue(10 == userData.getAge()); } @Test From 3c1959f07ab8386cf8459a228a42a0e5e62f2f7c Mon Sep 17 00:00:00 2001 From: chenglu Date: Thu, 28 Apr 2022 11:06:08 +0800 Subject: [PATCH 13/13] [Integration Test] change the return value to true in StaticFeature --- .../integration/jaxrs/cases/providers/StaticFeature.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/StaticFeature.java b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/StaticFeature.java index a2059f50..26114a83 100644 --- a/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/StaticFeature.java +++ b/restlight-integration-test/jaxrs-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/StaticFeature.java @@ -27,6 +27,6 @@ public boolean configure(FeatureContext context) { context.register(RequestFilter.class); context.register(ResponseFilter.class); context.register(DynamicFeature.class); - return false; + return true; } }