Change in URI Versioning
[nonrtric.git] / test / servicestub / src / test / java / org / oransc / nonrtric / sample / rest / HelloWorldControllerTest.java
diff --git a/test/servicestub/src/test/java/org/oransc/nonrtric/sample/rest/HelloWorldControllerTest.java b/test/servicestub/src/test/java/org/oransc/nonrtric/sample/rest/HelloWorldControllerTest.java
new file mode 100644 (file)
index 0000000..7b7abb0
--- /dev/null
@@ -0,0 +1,85 @@
+/*-\r
+ * ========================LICENSE_START=================================\r
+ * O-RAN-SC\r
+ * %%\r
+ * Copyright (C) 2023-2024 OpenInfra Foundation Europe.\r
+ * %%\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ========================LICENSE_END===================================\r
+ */\r
+\r
+package org.oransc.nonrtric.sample.rest;\r
+\r
+import static org.junit.jupiter.api.Assertions.assertEquals;\r
+\r
+import org.junit.jupiter.api.Test;\r
+import org.mockito.InjectMocks;\r
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;\r
+import org.springframework.mock.web.MockHttpServletRequest;\r
+\r
+@WebMvcTest(HelloWorldController.class)\r
+public class HelloWorldControllerTest {\r
+\r
+    @InjectMocks\r
+    private HelloWorldController helloWorldController;\r
+\r
+    @Test\r
+    public void testHelloWorldEndpoint() {\r
+        MockHttpServletRequest request = new MockHttpServletRequest();\r
+        request.setRequestURI("/helloworld/v1");\r
+\r
+        String result = helloWorldController.helloWorld(request);\r
+\r
+        assertEquals("Hello from /helloworld/v1", result);\r
+    }\r
+\r
+    @Test\r
+    public void testHelloWorldSubpathEndpoint() {\r
+        MockHttpServletRequest request = new MockHttpServletRequest();\r
+        request.setRequestURI("/helloworld/v1/subpath1");\r
+\r
+        String result = helloWorldController.helloWorldSubpath1(request);\r
+\r
+        assertEquals("Hello from /helloworld/v1/subpath1", result);\r
+    }\r
+\r
+    @Test\r
+    public void testHelloWorld2Endpoint() {\r
+        MockHttpServletRequest request = new MockHttpServletRequest();\r
+        request.setRequestURI("/helloworld2/v1");\r
+\r
+        String result = helloWorldController.helloWorld2(request);\r
+\r
+        assertEquals("Hello from /helloworld2/v1", result);\r
+    }\r
+\r
+    @Test\r
+    public void testHelloWorldEndpointV2() {\r
+        MockHttpServletRequest request = new MockHttpServletRequest();\r
+        request.setRequestURI("/helloworld/v2");\r
+\r
+        String result = helloWorldController.helloWorldV2(request);\r
+\r
+        assertEquals("Hello from /helloworld/v2", result);\r
+    }\r
+\r
+    @Test\r
+    public void testHelloWorldSubpathEndpointV2() {\r
+        MockHttpServletRequest request = new MockHttpServletRequest();\r
+        request.setRequestURI("/helloworld/v2/subpath1");\r
+\r
+        String result = helloWorldController.helloWorldSubpath1V2(request);\r
+\r
+        assertEquals("Hello from /helloworld/v2/subpath1", result);\r
+    }\r
+}\r