2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (C) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.controller;
25 import static org.junit.Assert.assertTrue;
26 import static org.junit.Assert.fail;
27 import static org.mockito.Mockito.mock;
29 import java.io.UnsupportedEncodingException;
30 import java.nio.file.Path;
31 import java.nio.file.Paths;
33 import javax.servlet.http.HttpServletRequest;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.mockito.Mockito;
38 import org.onap.policy.common.logging.flexlogger.FlexLogger;
39 import org.onap.policy.common.logging.flexlogger.Logger;
40 import org.onap.policy.dao.SystemLogDbDao;
41 import org.onap.policy.rest.dao.CommonClassDao;
42 import org.onap.policy.xacml.std.pap.StdEngine;
43 import org.springframework.mock.web.MockHttpServletResponse;
45 public class DashboardControllerTest {
46 private static Logger logger = FlexLogger.getLogger(DashboardControllerTest.class);
48 private static CommonClassDao commonClassDao;
49 private static SystemLogDbDao systemDAO;
50 private static PolicyController ctrl = null;
51 private HttpServletRequest request = null;
52 private DashboardController controller = null;
53 private MockHttpServletResponse response = null;
55 StdEngine engine = null;
60 * @throws Exception should not get one
63 public void setUp() throws Exception {
64 logger.info("setUp: Entering");
65 controller = new DashboardController();
66 commonClassDao = Mockito.mock(CommonClassDao.class);
67 systemDAO = Mockito.mock(SystemLogDbDao.class);
68 controller.setSystemLogDbDao(systemDAO);
69 controller.setCommonClassDao(commonClassDao);
70 request = mock(HttpServletRequest.class);
71 response = new MockHttpServletResponse();
72 repo = Paths.get("src/test/resources/pdps");
73 engine = new StdEngine(repo);
74 ctrl = new PolicyController();
75 PolicyController.setPapEngine(engine);
76 controller.setPolicyController(ctrl);
77 logger.info("setUp: exit");
81 public void testGetData() {
83 controller.getData(request, response);
84 assertTrue(response.getContentAsString() != null
85 && response.getContentAsString().contains("availableLoggingDatas"));
86 } catch (UnsupportedEncodingException e) {
87 logger.error("Exception Occured" + e);
93 public void testGetPAPStatusData() {
95 controller.getPAPStatusData(request, response);
97 response.getContentAsString() != null && response.getContentAsString().contains("papTableDatas"));
98 } catch (UnsupportedEncodingException e) {
99 logger.error("Exception Occured" + e);
105 public void testGetPDPStatusData() {
107 controller.getPDPStatusData(request, response);
109 response.getContentAsString() != null && response.getContentAsString().contains("pdpTableDatas"));
110 } catch (UnsupportedEncodingException e) {
111 logger.error("Exception Occured" + e);
117 public void testGetPolicyActivityData() {
119 controller.getPolicyActivityData(request, response);
120 assertTrue(response.getContentAsString() != null
121 && response.getContentAsString().contains("policyActivityTableDatas"));
122 } catch (UnsupportedEncodingException e) {
123 logger.error("Exception Occured" + e);
129 public void testGetSystemAlertData() {
131 controller.getSystemAlertData(request, response);
132 assertTrue(response.getContentAsString() != null
133 && response.getContentAsString().contains("systemAlertsTableDatas"));
134 } catch (UnsupportedEncodingException e) {
135 logger.error("Exception Occured" + e);