9406b299ea9424f12fa337740b235fd4dd04b3bf
[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 org.junit.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.onap.so.adapters.vevnfm.configuration.ConfigProperties;
28 import org.onap.so.adapters.vevnfm.configuration.StartupConfiguration;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.boot.test.context.SpringBootTest;
31 import org.springframework.http.HttpStatus;
32 import org.springframework.http.MediaType;
33 import org.springframework.mock.web.MockHttpServletResponse;
34 import org.springframework.test.context.ActiveProfiles;
35 import org.springframework.test.context.junit4.SpringRunner;
36 import org.springframework.test.web.servlet.MockMvc;
37 import org.springframework.test.web.servlet.MvcResult;
38 import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
39 import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
40 import org.springframework.test.web.servlet.setup.MockMvcBuilders;
41 import org.springframework.web.context.WebApplicationContext;
42
43 @SpringBootTest
44 @RunWith(SpringRunner.class)
45 @ActiveProfiles(StartupConfiguration.TEST_PROFILE)
46 public class NotificationControllerTest {
47
48     private static final String JSON = "{\"_links\":{\"vnfInstance\":{\"href\":null}}}";
49
50     private static final int ZERO = 0;
51
52     @Autowired
53     private ConfigProperties configProperties;
54
55     @Autowired
56     private WebApplicationContext webApplicationContext;
57
58     private String notification;
59     private MockMvc mvc;
60
61     @Before
62     public void init() {
63         notification = configProperties.getVnfmNotification();
64         mvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
65     }
66
67     @Test
68     public void testReceiveNotification() throws Exception {
69         // given
70         final MockHttpServletRequestBuilder request =
71                 MockMvcRequestBuilders.post(notification).contentType(MediaType.APPLICATION_JSON).content(JSON);
72
73         // when
74         final MvcResult mvcResult = mvc.perform(request).andReturn();
75
76         // then
77         final MockHttpServletResponse response = mvcResult.getResponse();
78         assertEquals(HttpStatus.OK.value(), response.getStatus());
79         assertEquals(ZERO, response.getContentLength());
80     }
81 }