2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
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 org.onap.policy.controller;
22 import static org.junit.Assert.assertTrue;
23 import static org.junit.Assert.fail;
24 import static org.mockito.Mockito.mock;
26 import java.io.UnsupportedEncodingException;
27 import java.nio.file.Path;
28 import java.nio.file.Paths;
30 import javax.servlet.http.HttpServletRequest;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.mockito.Mockito;
35 import org.onap.policy.common.logging.flexlogger.FlexLogger;
36 import org.onap.policy.common.logging.flexlogger.Logger;
37 import org.onap.policy.dao.SystemLogDbDao;
38 import org.onap.policy.rest.dao.CommonClassDao;
39 import org.onap.policy.xacml.std.pap.StdEngine;
40 import org.springframework.mock.web.MockHttpServletResponse;
42 public class DashboardControllerTest{
43 private static Logger logger = FlexLogger.getLogger(DashboardControllerTest.class);
45 private static CommonClassDao commonClassDao;
46 private static SystemLogDbDao systemDAO;
47 private static PolicyController ctrl = null;
48 private HttpServletRequest request = null;
49 private DashboardController controller = null;
50 private MockHttpServletResponse response = null;
52 StdEngine engine = null;
55 public void setUp() throws Exception {
56 logger.info("setUp: Entering");
57 controller = new DashboardController();
58 commonClassDao = Mockito.mock(CommonClassDao.class);
59 systemDAO = Mockito.mock(SystemLogDbDao.class);
60 controller.setSystemLogDbDao(systemDAO);
61 controller.setCommonClassDao(commonClassDao);
62 request = mock(HttpServletRequest.class);
63 response = new MockHttpServletResponse();
64 repo = Paths.get("src/test/resources/pdps");
65 engine = new StdEngine(repo);
66 ctrl = new PolicyController();
67 PolicyController.setPapEngine(engine);
68 controller.setPolicyController(ctrl);
69 logger.info("setUp: exit");
73 public void testGetData() {
75 controller.getData(request, response);
76 assertTrue(response.getContentAsString() != null && 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 && response.getContentAsString().contains("papTableDatas"));
88 } catch (UnsupportedEncodingException e) {
89 logger.error("Exception Occured"+e);
95 public void testGetPDPStatusData() {
97 controller.getPDPStatusData(request, response);
98 assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("pdpTableDatas"));
99 } catch (UnsupportedEncodingException e) {
100 logger.error("Exception Occured"+e);
106 public void testGetPolicyActivityData() {
108 controller.getPolicyActivityData(request, response);
109 assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("policyActivityTableDatas"));
110 } catch (UnsupportedEncodingException e) {
111 logger.error("Exception Occured"+e);
117 public void testGetSystemAlertData() {
119 controller.getSystemAlertData(request, response);
120 assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("systemAlertsTableDatas"));
121 } catch (UnsupportedEncodingException e) {
122 logger.error("Exception Occured"+e);