2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 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=========================================================
22 package org.onap.policy.controller;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
26 import static org.mockito.Mockito.mock;
27 import java.io.UnsupportedEncodingException;
28 import java.nio.file.Path;
29 import java.nio.file.Paths;
30 import javax.servlet.http.HttpServletRequest;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.mockito.Mockito;
34 import org.onap.policy.common.logging.flexlogger.FlexLogger;
35 import org.onap.policy.common.logging.flexlogger.Logger;
36 import org.onap.policy.dao.SystemLogDbDao;
37 import org.onap.policy.rest.dao.CommonClassDao;
38 import org.onap.policy.xacml.std.pap.StdEngine;
39 import org.springframework.mock.web.MockHttpServletResponse;
41 public class DashboardControllerTest {
42 private static Logger logger = FlexLogger.getLogger(DashboardControllerTest.class);
44 private static CommonClassDao commonClassDao;
45 private static SystemLogDbDao systemDAO;
46 private static PolicyController ctrl = null;
47 private HttpServletRequest request = null;
48 private DashboardController controller = null;
49 private MockHttpServletResponse response = null;
51 StdEngine engine = null;
54 public void setUp() throws Exception {
55 logger.info("setUp: Entering");
56 controller = new DashboardController();
57 commonClassDao = Mockito.mock(CommonClassDao.class);
58 systemDAO = Mockito.mock(SystemLogDbDao.class);
59 controller.setSystemLogDbDao(systemDAO);
60 controller.setCommonClassDao(commonClassDao);
61 request = mock(HttpServletRequest.class);
62 response = new MockHttpServletResponse();
63 repo = Paths.get("src/test/resources/pdps");
64 engine = new StdEngine(repo);
65 ctrl = new PolicyController();
66 PolicyController.setPapEngine(engine);
67 controller.setPolicyController(ctrl);
68 logger.info("setUp: exit");
72 public void testGetData() {
74 controller.getData(request, response);
75 assertTrue(response.getContentAsString() != null
76 && response.getContentAsString().contains("availableLoggingDatas"));
77 } catch (UnsupportedEncodingException e) {
78 logger.error("Exception Occured" + e);
84 public void testGetPAPStatusData() {
86 controller.getPAPStatusData(request, response);
87 assertTrue(response.getContentAsString() != null
88 && response.getContentAsString().contains("papTableDatas"));
89 } catch (UnsupportedEncodingException e) {
90 logger.error("Exception Occured" + e);
96 public void testGetPDPStatusData() {
98 controller.getPDPStatusData(request, response);
99 assertTrue(response.getContentAsString() != null
100 && response.getContentAsString().contains("pdpTableDatas"));
101 } catch (UnsupportedEncodingException e) {
102 logger.error("Exception Occured" + e);
108 public void testGetPolicyActivityData() {
110 controller.getPolicyActivityData(request, response);
111 assertTrue(response.getContentAsString() != null
112 && response.getContentAsString().contains("policyActivityTableDatas"));
113 } catch (UnsupportedEncodingException e) {
114 logger.error("Exception Occured" + e);
120 public void testGetSystemAlertData() {
122 controller.getSystemAlertData(request, response);
123 assertTrue(response.getContentAsString() != null
124 && response.getContentAsString().contains("systemAlertsTableDatas"));
125 } catch (UnsupportedEncodingException e) {
126 logger.error("Exception Occured" + e);