56c53a72e8e037f5a8c57a0df0a6c06ee51a130b
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SO
4  * ================================================================================
5  * Copyright (C) 2019 Samsung. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.adapters.vevnfm.controller;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.springframework.test.web.client.match.MockRestRequestMatchers.anything;
25 import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.onap.so.adapters.vevnfm.configuration.StartupConfiguration;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.beans.factory.annotation.Value;
32 import org.springframework.boot.test.context.SpringBootTest;
33 import org.springframework.http.HttpStatus;
34 import org.springframework.http.MediaType;
35 import org.springframework.mock.web.MockHttpServletResponse;
36 import org.springframework.test.context.ActiveProfiles;
37 import org.springframework.test.context.junit4.SpringRunner;
38 import org.springframework.test.web.client.MockRestServiceServer;
39 import org.springframework.test.web.servlet.MockMvc;
40 import org.springframework.test.web.servlet.MvcResult;
41 import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
42 import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
43 import org.springframework.test.web.servlet.setup.MockMvcBuilders;
44 import org.springframework.web.client.RestTemplate;
45 import org.springframework.web.context.WebApplicationContext;
46
47 @SpringBootTest
48 @RunWith(SpringRunner.class)
49 @ActiveProfiles(StartupConfiguration.TEST_PROFILE)
50 public class NotificationControllerTest {
51
52     private static final String MINIMAL_JSON_CONTENT = "{}";
53     private static final int ZERO = 0;
54
55     @Value("${vnfm.notification}")
56     private String notification;
57
58     @Autowired
59     private WebApplicationContext webApplicationContext;
60
61     @Autowired
62     private RestTemplate restTemplate;
63
64     private MockMvc mvc;
65     private MockRestServiceServer mockRestServer;
66
67     @Before
68     public void init() {
69         mvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
70         mockRestServer = MockRestServiceServer.bindTo(restTemplate).build();
71     }
72
73     @Test
74     public void testReceiveNotification() throws Exception {
75         // given
76         final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(notification)
77                 .contentType(MediaType.APPLICATION_JSON).content(MINIMAL_JSON_CONTENT);
78
79         mockRestServer.expect(anything()).andRespond(withSuccess());
80
81         // when
82         final MvcResult mvcResult = mvc.perform(request).andReturn();
83
84         // then
85         final MockHttpServletResponse response = mvcResult.getResponse();
86         assertEquals(HttpStatus.OK.value(), response.getStatus());
87         assertEquals(ZERO, response.getContentLength());
88         mockRestServer.verify();
89     }
90 }