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;
58 public void setUp() throws Exception {
59 logger.info("setUp: Entering");
60 controller = new DashboardController();
61 commonClassDao = Mockito.mock(CommonClassDao.class);
62 systemDAO = Mockito.mock(SystemLogDbDao.class);
63 controller.setSystemLogDbDao(systemDAO);
64 controller.setCommonClassDao(commonClassDao);
65 request = mock(HttpServletRequest.class);
66 response = new MockHttpServletResponse();
67 repo = Paths.get("src/test/resources/pdps");
68 engine = new StdEngine(repo);
69 ctrl = new PolicyController();
70 PolicyController.setPapEngine(engine);
71 controller.setPolicyController(ctrl);
72 logger.info("setUp: exit");
76 public void testGetData() {
78 controller.getData(request, response);
79 assertTrue(response.getContentAsString() != null
80 && response.getContentAsString().contains("availableLoggingDatas"));
81 } catch (UnsupportedEncodingException e) {
82 logger.error("Exception Occured" + e);
88 public void testGetPAPStatusData() {
90 controller.getPAPStatusData(request, response);
92 response.getContentAsString() != null && response.getContentAsString().contains("papTableDatas"));
93 } catch (UnsupportedEncodingException e) {
94 logger.error("Exception Occured" + e);
100 public void testGetPDPStatusData() {
102 controller.getPDPStatusData(request, response);
104 response.getContentAsString() != null && response.getContentAsString().contains("pdpTableDatas"));
105 } catch (UnsupportedEncodingException e) {
106 logger.error("Exception Occured" + e);
112 public void testGetPolicyActivityData() {
114 controller.getPolicyActivityData(request, response);
115 assertTrue(response.getContentAsString() != null
116 && response.getContentAsString().contains("policyActivityTableDatas"));
117 } catch (UnsupportedEncodingException e) {
118 logger.error("Exception Occured" + e);
124 public void testGetSystemAlertData() {
126 controller.getSystemAlertData(request, response);
127 assertTrue(response.getContentAsString() != null
128 && response.getContentAsString().contains("systemAlertsTableDatas"));
129 } catch (UnsupportedEncodingException e) {
130 logger.error("Exception Occured" + e);