This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-samples.git
The following commit(s) were added to refs/heads/master by this push:
new f17d746c0 add rest jaxrs abnormal sample cases (#1162)
f17d746c0 is described below
commit f17d746c054905811102649278b056e708dd1f15
Author: fanlobu <[email protected]>
AuthorDate: Thu Aug 15 11:07:04 2024 +0800
add rest jaxrs abnormal sample cases (#1162)
---
.../rest/demo/routine/AbnormalRequestService.java | 50 ++++++++++++++
.../demo/routine/AbnormalRequestServiceImpl.java | 56 +++++++++++++++
.../rest/demo/test/AbnormalRequestServiceIT.java | 80 ++++++++++++++++++++++
3 files changed, 186 insertions(+)
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/routine/AbnormalRequestService.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/routine/AbnormalRequestService.java
new file mode 100644
index 000000000..2523c353e
--- /dev/null
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/routine/AbnormalRequestService.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.dubbo.rest.demo.routine;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+import java.time.ZonedDateTime;
+
+@Path("/abnormal")
+public interface AbnormalRequestService {
+
+ @GET
+ @Path("/notFound")
+ String testNotFound();
+
+ @GET
+ @Path("/noParam")
+ String testNoParam(@QueryParam("name") String name);
+
+ @GET
+ @Path("/paramConvertFail")
+ ZonedDateTime testParamConvertFai(@QueryParam("zonedDateTime")
ZonedDateTime date);
+
+ @GET
+ @Path("/pathRepeat")
+ String testPathRepeat1();
+
+// @GET
+// @Path("/pathRepeat")
+ String testPathRepeat2();
+
+ @GET
+ @Path("/throwException")
+ String test();
+}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/routine/AbnormalRequestServiceImpl.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/routine/AbnormalRequestServiceImpl.java
new file mode 100644
index 000000000..9167275ba
--- /dev/null
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/routine/AbnormalRequestServiceImpl.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.dubbo.rest.demo.routine;
+
+import org.apache.dubbo.config.annotation.DubboService;
+import javax.ws.rs.core.Application;
+import java.time.ZonedDateTime;
+
+@DubboService
+public class AbnormalRequestServiceImpl extends Application implements
AbnormalRequestService{
+ @Override
+ public String testNotFound() {
+ return null;
+ }
+
+ @Override
+ public String testNoParam(String name) {
+ return name;
+ }
+
+ @Override
+ public ZonedDateTime testParamConvertFai(ZonedDateTime date) {
+ return date;
+ }
+
+
+ @Override
+ public String testPathRepeat1() {
+ return "path repeat1";
+ }
+
+ @Override
+ public String testPathRepeat2() {
+ return "path repeat2";
+ }
+
+ @Override
+ public String test() {
+ throw new RuntimeException();
+ }
+
+}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/test/java/org/apache/dubbo/rest/demo/test/AbnormalRequestServiceIT.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/test/java/org/apache/dubbo/rest/demo/test/AbnormalRequestServiceIT.java
new file mode 100644
index 000000000..3a3cacdd4
--- /dev/null
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/test/java/org/apache/dubbo/rest/demo/test/AbnormalRequestServiceIT.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.dubbo.rest.demo.test;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.http.HttpStatus;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.web.client.RestClient;
+
+
+@SpringBootTest
+@RunWith(SpringRunner.class)
+public class AbnormalRequestServiceIT {
+
+ private static final String providerAddress =
System.getProperty("dubbo.address", "localhost");
+
+
+ @Test
+ public void testNotFound(){
+ RestClient.create().get()
+ .uri("http://" + providerAddress + ":50052/abnormal/not")
+ .header("Content-type", "application/json")
+ .exchange((request, response) -> {
+
Assert.assertEquals(HttpStatus.NOT_FOUND,response.getStatusCode());
+ return response;
+ });
+ }
+
+ @Test
+ public void testNoParam(){
+ RestClient.create().get()
+ .uri("http://" + providerAddress +
":50052/abnormal/notParam?name=1&a=1")
+ .header( "Content-type","application/json")
+ .exchange((request, response) -> {
+ System.out.println(response.getStatusCode());
+
Assert.assertEquals(HttpStatus.NOT_FOUND,response.getStatusCode());
+ return response;
+ });
+ }
+
+ @Test
+ public void testParamConvertFail(){
+ RestClient.create().get()
+ .uri("http://" + providerAddress +
":50052/abnormal/paramConvertFail?zonedDateTime=2023-03-08T10:15:30+08:00")
+ .header( "Content-type","application/json")
+ .exchange((request, response) -> {
+
Assert.assertEquals(HttpStatus.INTERNAL_SERVER_ERROR,response.getStatusCode());
+ return response;
+ });
+ }
+
+ @Test
+ public void testThrowException(){
+ RestClient.create().get()
+ .uri("http://" + providerAddress +
":50052/abnormal/throwException")
+ .header( "Content-type","application/json")
+ .exchange((request, response) -> {
+
Assert.assertEquals(HttpStatus.INTERNAL_SERVER_ERROR,response.getStatusCode());
+ return response;
+ });
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]