summaryrefslogtreecommitdiffstats
path: root/server/src/test/java/org/onap/usecaseui/server/controller/AlarmControllerTest.java
blob: ecda53541eadb986a207ddfe874658f5c30046fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
 * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.onap.usecaseui.server.controller;

import org.junit.Test;
import org.junit.Before;
import org.junit.After;
import org.onap.usecaseui.server.bean.AlarmsHeader;
import org.onap.usecaseui.server.bean.AlarmsInformation;
import org.onap.usecaseui.server.service.AlarmsHeaderService;
import org.onap.usecaseui.server.service.AlarmsInformationService;
import org.onap.usecaseui.server.util.DateUtils;
import org.onap.usecaseui.server.util.Page;

import java.util.*;

import mockit.Mock;
import mockit.MockUp;

public class AlarmControllerTest {

	AlarmController controller = null;

	@Before
	public void before() throws Exception {
		controller = new AlarmController();

		new MockUp<AlarmsHeaderService>() {
			@Mock
			public Page<AlarmsHeader> queryAlarmsHeader(AlarmsHeader alarmsHeader, int currentPage, int pageSize) {
				AlarmsHeader ah = new AlarmsHeader("sourceId");
				List<AlarmsHeader> list = new ArrayList<>();
				list.add(ah);
				Page<AlarmsHeader> resultPage = new Page<AlarmsHeader>();
				resultPage.setList(list);
				return resultPage;
			}
			@Mock
			public List<AlarmsHeader> queryId(String[] id) {
				AlarmsHeader ah = new AlarmsHeader();
				return Arrays.asList(ah);
			}
		};
		new MockUp<AlarmsInformationService>() {
			@Mock
			public Page<AlarmsInformation> queryAlarmsInformation(AlarmsInformation alarmsInformation, int currentPage, int pageSize) {
				return new Page<AlarmsInformation>();
			}
			@Mock
			public List<Map<String,String>> queryDateBetween(String sourceId, String startTime, String endTime) {
				Map<String,String> map = new HashMap<String,String>();
				map.put("name", "value");
				List<Map<String,String>> resultList = new ArrayList<>();
				resultList.add(map);
				return resultList;
			}
		};
	}

	@After
	public void after() throws Exception {
	}

	@Test
	public void testIndex() throws Exception {
		controller.index();
	}

	@Test
	public void testGetAlarmData() throws Exception {
		try {
			controller.getAlarmData("sourceId", "sourceName", "priority", "startTime", "endTime", "vfStatus", 1, 10);
			controller.getAlarmData(null, null, null, null, null, null, 1, 10);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Test
	public void testGetSourceId() throws Exception {
		try {
			controller.getSourceId();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Test
	public void testGenDiagram() throws Exception {
		try {
			controller.diagram("sourceId", "startTime", "endTime","format");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}