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
\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
-<?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
# ========================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.
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"
-
-response2=$(curl -s http://localhost:8080/v1/helloworld)
-echo "Response from the /v1/helloworld endpoint: "
-echo "$response2"
+++ /dev/null
-/*-\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
-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
-@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
- SpringApplication.run(HelloWorldApplication.class, args);\r
+ SpringApplication.run(ServiceStubApplication.class, args);\r
}\r
}\r
--- /dev/null
+/*-\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
+++ /dev/null
-/*-\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
--- /dev/null
+/*-\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