X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Fservicestub%2Fsrc%2Ftest%2Fjava%2Forg%2Foransc%2Fnonrtric%2Fsample%2Frest%2FHelloWorldControllerTest.java;fp=test%2Fservicestub%2Fsrc%2Ftest%2Fjava%2Forg%2Foransc%2Fnonrtric%2Fsample%2Frest%2FHelloWorldControllerTest.java;h=7b7abb07b80f30a110721bb4639ffa4ad109a193;hb=b94b48f2cad1b161a0ece13a4100ccf4b7d0c503;hp=0000000000000000000000000000000000000000;hpb=3c504be356d2ac9fc5195eb45692e1b756caa9f3;p=nonrtric.git 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 index 00000000..7b7abb07 --- /dev/null +++ b/test/servicestub/src/test/java/org/oransc/nonrtric/sample/rest/HelloWorldControllerTest.java @@ -0,0 +1,85 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * 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. + * 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=================================== + */ + +package org.oransc.nonrtric.sample.rest; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.mock.web.MockHttpServletRequest; + +@WebMvcTest(HelloWorldController.class) +public class HelloWorldControllerTest { + + @InjectMocks + private HelloWorldController helloWorldController; + + @Test + public void testHelloWorldEndpoint() { + MockHttpServletRequest request = new MockHttpServletRequest(); + request.setRequestURI("/helloworld/v1"); + + String result = helloWorldController.helloWorld(request); + + assertEquals("Hello from /helloworld/v1", result); + } + + @Test + public void testHelloWorldSubpathEndpoint() { + MockHttpServletRequest request = new MockHttpServletRequest(); + request.setRequestURI("/helloworld/v1/subpath1"); + + String result = helloWorldController.helloWorldSubpath1(request); + + assertEquals("Hello from /helloworld/v1/subpath1", result); + } + + @Test + public void testHelloWorld2Endpoint() { + MockHttpServletRequest request = new MockHttpServletRequest(); + request.setRequestURI("/helloworld2/v1"); + + String result = helloWorldController.helloWorld2(request); + + assertEquals("Hello from /helloworld2/v1", result); + } + + @Test + public void testHelloWorldEndpointV2() { + MockHttpServletRequest request = new MockHttpServletRequest(); + request.setRequestURI("/helloworld/v2"); + + String result = helloWorldController.helloWorldV2(request); + + assertEquals("Hello from /helloworld/v2", result); + } + + @Test + public void testHelloWorldSubpathEndpointV2() { + MockHttpServletRequest request = new MockHttpServletRequest(); + request.setRequestURI("/helloworld/v2/subpath1"); + + String result = helloWorldController.helloWorldSubpath1V2(request); + + assertEquals("Hello from /helloworld/v2/subpath1", result); + } +}