NonRT-RIC A1 Northbound API
[nonrtric.git] / sdnc-a1-controller / oam / SdncReports / SdncReportsApi / src / test / java / com / onap / sdnc / reports / controller / ReportControllerTest.java
1 /*
2 * ============LICENSE_START=======================================================
3 * ONAP : SDNC-FEATURES
4 * ================================================================================
5 * Copyright 2018 TechMahindra
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 package com.onap.sdnc.reports.controller;
21
22 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
23 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
24
25 import java.util.Arrays;
26 import java.util.Calendar;
27 import java.util.Date;
28 import java.util.List;
29
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
34 import org.springframework.boot.test.mock.mockito.MockBean;
35 import org.springframework.http.MediaType;
36 import org.springframework.test.context.ContextConfiguration;
37 import org.springframework.test.context.junit4.SpringRunner;
38 import org.springframework.test.web.servlet.MockMvc;
39
40 import com.onap.sdnc.reports.Application;
41 import com.onap.sdnc.reports.controller.ReportController;
42 import com.onap.sdnc.reports.rest.model.PreTestModel;
43 import com.onap.sdnc.reports.service.IReportService;
44
45 import static org.junit.Assert.assertNotNull;
46 import static org.mockito.Mockito.when;
47
48 @RunWith(SpringRunner.class)
49 @ContextConfiguration(classes = { Application.class })
50 @WebMvcTest(ReportController.class)
51
52 public class ReportControllerTest {
53
54         @Autowired
55         private MockMvc mvc;
56
57         @MockBean
58         private IReportService reportService;
59
60         private Date startDate, endDate;
61
62         @Test
63         public void reportServiceAutoWireTest() {
64                 assertNotNull("Due to Application Context Fail", reportService);
65         }
66
67         @Test
68         public void whenFindReportByDeviceName_thenReturnThis() throws Exception {
69                 Calendar calendar = Calendar.getInstance();
70
71                 calendar.add(Calendar.DATE, -7);
72                 calendar.add(Calendar.HOUR_OF_DAY, 00);
73                 calendar.add(Calendar.MINUTE, 00);
74                 calendar.add(Calendar.SECOND, 00);
75                 calendar.add(Calendar.MILLISECOND, 00);
76                 startDate = calendar.getTime();
77
78                 Calendar endDateCalendar = Calendar.getInstance();
79
80                 endDateCalendar.add(Calendar.HOUR_OF_DAY, 23);
81                 endDateCalendar.add(Calendar.MINUTE, 59);
82                 calendar.add(Calendar.SECOND, 00);
83                 endDateCalendar.add(Calendar.MILLISECOND, 00);
84                 endDate = endDateCalendar.getTime();
85
86                 Date d = new Date();
87                 startDate = d;
88                 endDate = d;
89                 PreTestModel preTestModel = new PreTestModel(1, 1, "NetWorkTest", "Router", "Ping Got Successful", "Pass",
90                                 endDate);
91
92                 List<PreTestModel> allTests = Arrays.asList(preTestModel);
93
94                 when(reportService.findReportByDeviceIP(startDate, endDate, "0.0.0.0")).thenReturn(allTests);
95
96                 mvc.perform(get("/findReportByDeviceIP/{startDate}/{endDate}/{deviceIP}/", startDate, endDate, "0.0.0.0")
97                                 .contentType(MediaType.APPLICATION_JSON)).andExpect(status().is(400));
98
99         }
100 }