Change in URI Versioning 04/12404/2
authorambrishest <ambrish.singh@est.tech>
Mon, 8 Jan 2024 12:13:16 +0000 (12:13 +0000)
committerambrishest <ambrish.singh@est.tech>
Tue, 9 Jan 2024 11:38:42 +0000 (11:38 +0000)
Issue-ID: NONRTRIC-944
Change-Id: I669f230a0fbc0d735f84ebfe2f016341524ee560
Signed-off-by: ambrishest <ambrish.singh@est.tech>
test/servicestub/README.md
test/servicestub/pom.xml
test/servicestub/service-stub-build-start.sh
test/servicestub/src/main/java/org/oran/helloworld/rest/HelloWorldController.java [deleted file]
test/servicestub/src/main/java/org/oransc/nonrtric/sample/ServiceStubApplication.java [moved from test/servicestub/src/main/java/org/oran/helloworld/HelloWorldApplication.java with 79% similarity]
test/servicestub/src/main/java/org/oransc/nonrtric/sample/rest/HelloWorldController.java [new file with mode: 0644]
test/servicestub/src/test/java/org/oran/helloworld/rest/HelloWorldControllerTest.java [deleted file]
test/servicestub/src/test/java/org/oransc/nonrtric/sample/rest/HelloWorldControllerTest.java [new file with mode: 0644]

index 601e52a..b4aa791 100644 (file)
@@ -19,8 +19,8 @@ wait for a few seconds to ensure the Spring Boot application is fully initialize
 Hello World endpoint and display the response:\r
 \r
 ```bash\r
 Hello World endpoint and display the response:\r
 \r
 ```bash\r
-  response=$(curl -s http://localhost:8080/helloworld/sme)\r
-  echo "Response from the Hello World endpoint:"\r
+  response=$(curl -s http://localhost:8080/helloworld/v1/sme)\r
+  echo "Response from the Hello World SME endpoint:"\r
   echo "$response"\r
 ```\r
 \r
   echo "$response"\r
 ```\r
 \r
@@ -33,5 +33,5 @@ To stop and remove the Docker container:
 \r
 ## Additional Information\r
 \r
 \r
 ## Additional Information\r
 \r
-- The Hello World endpoint is available at http://localhost:8080/helloworld/sme.\r
+- The Hello World SME endpoint is available at http://localhost:8080/helloworld/v1/sme.\r
 \r
 \r
index be7a791..e46ae58 100644 (file)
@@ -1,72 +1,72 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
-* ========================LICENSE_START=================================
-* O-RAN-SC
-* %%
-* Copyright (C) 2023 OpenInfra Foundation Europe.
-* %%
-* 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.
-* ========================LICENSE_END===================================
--->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-
-    <groupId>org.o-ran-sc.nonrtric.plt</groupId>
-    <artifactId>hello-world</artifactId>
-    <version>0.1.0</version>
-
-    <properties>
-        <maven.compiler.source>17</maven.compiler.source>
-        <maven.compiler.target>17</maven.compiler.target>
-        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-    </properties>
-
-    <parent>
-        <groupId>org.springframework.boot</groupId>
-        <artifactId>spring-boot-starter-parent</artifactId>
-        <version>3.1.0</version>
-    </parent>
-
-    <dependencies>
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-web</artifactId>
-        </dependency>
-
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-test</artifactId>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.mockito</groupId>
-            <artifactId>mockito-core</artifactId>
-            <scope>test</scope>
-        </dependency>
-    </dependencies>
-
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.springframework.boot</groupId>
-                <artifactId>spring-boot-maven-plugin</artifactId>
-            </plugin>
-        </plugins>
-    </build>
-
+<?xml version="1.0" encoding="UTF-8"?>\r
+\r
+<!--\r
+* ========================LICENSE_START=================================\r
+* O-RAN-SC\r
+* %%\r
+* Copyright (C) 2023 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
+<project xmlns="http://maven.apache.org/POM/4.0.0"\r
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">\r
+    <modelVersion>4.0.0</modelVersion>\r
+\r
+    <parent>\r
+        <groupId>org.springframework.boot</groupId>\r
+        <artifactId>spring-boot-starter-parent</artifactId>\r
+        <version>3.2.1</version>\r
+    </parent>\r
+\r
+    <groupId>org.o-ran-sc.nonrtric.plt</groupId>\r
+    <artifactId>hello-world</artifactId>\r
+    <version>0.1.0</version>\r
+\r
+    <properties>\r
+        <maven.compiler.source>17</maven.compiler.source>\r
+        <maven.compiler.target>17</maven.compiler.target>\r
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>\r
+    </properties>\r
+\r
+    <dependencies>\r
+        <dependency>\r
+            <groupId>org.springframework.boot</groupId>\r
+            <artifactId>spring-boot-starter-web</artifactId>\r
+        </dependency>\r
+\r
+        <dependency>\r
+            <groupId>org.springframework.boot</groupId>\r
+            <artifactId>spring-boot-starter-test</artifactId>\r
+            <scope>test</scope>\r
+        </dependency>\r
+\r
+        <dependency>\r
+            <groupId>org.mockito</groupId>\r
+            <artifactId>mockito-core</artifactId>\r
+            <scope>test</scope>\r
+        </dependency>\r
+    </dependencies>\r
+\r
+    <build>\r
+        <plugins>\r
+            <plugin>\r
+                <groupId>org.springframework.boot</groupId>\r
+                <artifactId>spring-boot-maven-plugin</artifactId>\r
+            </plugin>\r
+        </plugins>\r
+    </build>\r
+\r
 </project>
\ No newline at end of file
 </project>
\ No newline at end of file
index 885bd77..de64167 100644 (file)
@@ -4,7 +4,7 @@
 #   ========================LICENSE_START=================================
 #   O-RAN-SC
 #   %%
 #   ========================LICENSE_START=================================
 #   O-RAN-SC
 #   %%
-#   Copyright (C) 2023: OpenInfra Foundation Europe.
+#   Copyright (C) 2023-2024: OpenInfra Foundation Europe.
 #   %%
 #   Licensed under the Apache License, Version 2.0 (the "License");
 #   you may not use this file except in compliance with the License.
 #   %%
 #   Licensed under the Apache License, Version 2.0 (the "License");
 #   you may not use this file except in compliance with the License.
@@ -30,11 +30,6 @@ docker run --rm -d -p 8080:8080 --name $NAME $IMAGE_NAME
 sleep 10
 
 echo "Make an HTTP request to the Hello World endpoint and display the response"
 sleep 10
 
 echo "Make an HTTP request to the Hello World endpoint and display the response"
-response=$(curl -s http://localhost:8080/v1/helloworld/sme)
-
-echo "Response from the /v1/helloworld/sme endpoint: "
+response=$(curl -s http://localhost:8080/helloworld/v1)
+echo "Response from the /helloworld/v1 endpoint: "
 echo "$response"
 echo "$response"
-
-response2=$(curl -s http://localhost:8080/v1/helloworld)
-echo "Response from the /v1/helloworld endpoint: "
-echo "$response2"
diff --git a/test/servicestub/src/main/java/org/oran/helloworld/rest/HelloWorldController.java b/test/servicestub/src/main/java/org/oran/helloworld/rest/HelloWorldController.java
deleted file mode 100644 (file)
index 057191e..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*-\r
- * ========================LICENSE_START=================================\r
- * O-RAN-SC\r
- * %%\r
- * Copyright (C) 2023 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.oran.helloworld.rest;\r
-\r
-import org.springframework.web.bind.annotation.RequestMapping;\r
-import org.springframework.web.bind.annotation.RestController;\r
-\r
-@RestController\r
-@RequestMapping("/v1/helloworld")\r
-public class HelloWorldController {\r
-\r
-    @RequestMapping("")\r
-    public String helloWorld() {\r
-        return "Hello World from service stub\n";\r
-    }\r
-    @RequestMapping("/sme")\r
-    public String helloWorldSme() {\r
-        return "Hello World from SME\n";\r
-    }\r
-}\r
  * ========================LICENSE_END===================================\r
  */\r
 \r
  * ========================LICENSE_END===================================\r
  */\r
 \r
-package org.oran.helloworld;\r
+package org.oransc.nonrtric.sample;\r
 \r
 import org.springframework.boot.SpringApplication;\r
 import org.springframework.boot.autoconfigure.SpringBootApplication;\r
 \r
 \r
 import org.springframework.boot.SpringApplication;\r
 import org.springframework.boot.autoconfigure.SpringBootApplication;\r
 \r
-@SpringBootApplication(scanBasePackages = "org.oran.helloworld")\r
-public class HelloWorldApplication {\r
+@SpringBootApplication(scanBasePackages = "org.oransc.nonrtric.sample")\r
+public class ServiceStubApplication {\r
     public static void main(String[] args) {\r
     public static void main(String[] args) {\r
-        SpringApplication.run(HelloWorldApplication.class, args);\r
+        SpringApplication.run(ServiceStubApplication.class, args);\r
     }\r
 }\r
     }\r
 }\r
diff --git a/test/servicestub/src/main/java/org/oransc/nonrtric/sample/rest/HelloWorldController.java b/test/servicestub/src/main/java/org/oransc/nonrtric/sample/rest/HelloWorldController.java
new file mode 100644 (file)
index 0000000..8ea37c0
--- /dev/null
@@ -0,0 +1,69 @@
+/*-\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 jakarta.servlet.http.HttpServletRequest;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+import org.springframework.web.bind.annotation.RequestMapping;\r
+import org.springframework.web.bind.annotation.RestController;\r
+\r
+@RestController\r
+public class HelloWorldController {\r
+\r
+    private static final Logger logger = LoggerFactory.getLogger(HelloWorldController.class);\r
+\r
+    @RequestMapping("/helloworld/v1")\r
+    public String helloWorld(HttpServletRequest request) {\r
+        String path = logRequestPath(request);\r
+        return "Hello from "+path;\r
+    }\r
+\r
+    @RequestMapping("/helloworld/v1/subpath1")\r
+    public String helloWorldSubpath1(HttpServletRequest request) {\r
+        String path = logRequestPath(request);\r
+        return "Hello from "+path;\r
+    }\r
+\r
+    @RequestMapping("/helloworld2/v1")\r
+    public String helloWorld2(HttpServletRequest request) {\r
+        String path = logRequestPath(request);\r
+        return "Hello from "+path;\r
+    }\r
+\r
+    @RequestMapping("/helloworld/v2")\r
+    public String helloWorldV2(HttpServletRequest request) {\r
+        String path = logRequestPath(request);\r
+        return "Hello from "+path;\r
+    }\r
+\r
+    @RequestMapping("/helloworld/v2/subpath1")\r
+    public String helloWorldSubpath1V2(HttpServletRequest request) {\r
+        String path = logRequestPath(request);\r
+        return "Hello from "+path;\r
+    }\r
+\r
+    private String logRequestPath(HttpServletRequest request) {\r
+        String path = request.getRequestURI();\r
+        logger.info("Received request for path: {}", path);\r
+        return path;\r
+    }\r
+}\r
diff --git a/test/servicestub/src/test/java/org/oran/helloworld/rest/HelloWorldControllerTest.java b/test/servicestub/src/test/java/org/oran/helloworld/rest/HelloWorldControllerTest.java
deleted file mode 100644 (file)
index 36f335f..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*-\r
- * ========================LICENSE_START=================================\r
- * O-RAN-SC\r
- * %%\r
- * Copyright (C) 2023 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.oran.helloworld.rest;\r
-\r
-import org.junit.jupiter.api.Test;\r
-import org.springframework.beans.factory.annotation.Autowired;\r
-import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;\r
-import org.springframework.boot.test.mock.mockito.MockBean;\r
-import org.springframework.test.web.servlet.MockMvc;\r
-\r
-import static org.mockito.Mockito.when;\r
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;\r
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;\r
-\r
-@WebMvcTest(HelloWorldController.class)\r
-public class HelloWorldControllerTest {\r
-\r
-    @Autowired\r
-    private MockMvc mockMvc;\r
-\r
-    @MockBean\r
-    private HelloWorldController helloWorldController;\r
-\r
-    @Test\r
-    public void testHelloWorldEndpoint() throws Exception {\r
-        when(helloWorldController.helloWorld()).thenReturn("Hello World from service stub\n");\r
-\r
-        mockMvc.perform(get("/v1/helloworld"))\r
-            .andExpect(status().isOk())\r
-            .andExpect(content().string("Hello World from service stub\n"));\r
-    }\r
-\r
-    @Test\r
-    public void testHelloWorldSmeEndpoint() throws Exception {\r
-        when(helloWorldController.helloWorldSme()).thenReturn("Hello World from SME\n");\r
-\r
-        mockMvc.perform(get("/v1/helloworld/sme"))\r
-            .andExpect(status().isOk())\r
-            .andExpect(content().string("Hello World from SME\n"));\r
-    }\r
-}\r
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