Change in URI Versioning
[nonrtric.git] / test / servicestub / src / test / java / org / oransc / nonrtric / sample / rest / HelloWorldControllerTest.java
1 /*-\r
2  * ========================LICENSE_START=================================\r
3  * O-RAN-SC\r
4  * %%\r
5  * Copyright (C) 2023-2024 OpenInfra Foundation Europe.\r
6  * %%\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  *\r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ========================LICENSE_END===================================\r
19  */\r
20 \r
21 package org.oransc.nonrtric.sample.rest;\r
22 \r
23 import static org.junit.jupiter.api.Assertions.assertEquals;\r
24 \r
25 import org.junit.jupiter.api.Test;\r
26 import org.mockito.InjectMocks;\r
27 import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;\r
28 import org.springframework.mock.web.MockHttpServletRequest;\r
29 \r
30 @WebMvcTest(HelloWorldController.class)\r
31 public class HelloWorldControllerTest {\r
32 \r
33     @InjectMocks\r
34     private HelloWorldController helloWorldController;\r
35 \r
36     @Test\r
37     public void testHelloWorldEndpoint() {\r
38         MockHttpServletRequest request = new MockHttpServletRequest();\r
39         request.setRequestURI("/helloworld/v1");\r
40 \r
41         String result = helloWorldController.helloWorld(request);\r
42 \r
43         assertEquals("Hello from /helloworld/v1", result);\r
44     }\r
45 \r
46     @Test\r
47     public void testHelloWorldSubpathEndpoint() {\r
48         MockHttpServletRequest request = new MockHttpServletRequest();\r
49         request.setRequestURI("/helloworld/v1/subpath1");\r
50 \r
51         String result = helloWorldController.helloWorldSubpath1(request);\r
52 \r
53         assertEquals("Hello from /helloworld/v1/subpath1", result);\r
54     }\r
55 \r
56     @Test\r
57     public void testHelloWorld2Endpoint() {\r
58         MockHttpServletRequest request = new MockHttpServletRequest();\r
59         request.setRequestURI("/helloworld2/v1");\r
60 \r
61         String result = helloWorldController.helloWorld2(request);\r
62 \r
63         assertEquals("Hello from /helloworld2/v1", result);\r
64     }\r
65 \r
66     @Test\r
67     public void testHelloWorldEndpointV2() {\r
68         MockHttpServletRequest request = new MockHttpServletRequest();\r
69         request.setRequestURI("/helloworld/v2");\r
70 \r
71         String result = helloWorldController.helloWorldV2(request);\r
72 \r
73         assertEquals("Hello from /helloworld/v2", result);\r
74     }\r
75 \r
76     @Test\r
77     public void testHelloWorldSubpathEndpointV2() {\r
78         MockHttpServletRequest request = new MockHttpServletRequest();\r
79         request.setRequestURI("/helloworld/v2/subpath1");\r
80 \r
81         String result = helloWorldController.helloWorldSubpath1V2(request);\r
82 \r
83         assertEquals("Hello from /helloworld/v2/subpath1", result);\r
84     }\r
85 }\r