2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package com.onap.sdnc.reports.controller;
22 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
23 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
25 import java.util.Arrays;
26 import java.util.Calendar;
27 import java.util.Date;
28 import java.util.List;
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;
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;
45 import static org.junit.Assert.assertNotNull;
46 import static org.mockito.Mockito.when;
48 @RunWith(SpringRunner.class)
49 @ContextConfiguration(classes = { Application.class })
50 @WebMvcTest(ReportController.class)
52 public class ReportControllerTest {
58 private IReportService reportService;
60 private Date startDate, endDate;
63 public void reportServiceAutoWireTest() {
64 assertNotNull("Due to Application Context Fail", reportService);
68 public void whenFindReportByDeviceName_thenReturnThis() throws Exception {
69 Calendar calendar = Calendar.getInstance();
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();
78 Calendar endDateCalendar = Calendar.getInstance();
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();
89 PreTestModel preTestModel = new PreTestModel(1, 1, "NetWorkTest", "Router", "Ping Got Successful", "Pass",
92 List<PreTestModel> allTests = Arrays.asList(preTestModel);
94 when(reportService.findReportByDeviceIP(startDate, endDate, "0.0.0.0")).thenReturn(allTests);
96 mvc.perform(get("/findReportByDeviceIP/{startDate}/{endDate}/{deviceIP}/", startDate, endDate, "0.0.0.0")
97 .contentType(MediaType.APPLICATION_JSON)).andExpect(status().is(400));