Reformat POLICY-SDK-APP test cases
[policy/engine.git] / POLICY-SDK-APP / src / test / java / org / onap / policy / controller / DashboardControllerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * POLICY-SDK-APP
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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=========================================================
21  */
22 package org.onap.policy.controller;
23
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;
40
41 public class DashboardControllerTest {
42     private static Logger logger = FlexLogger.getLogger(DashboardControllerTest.class);
43
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;
50     private Path repo;
51     StdEngine engine = null;
52
53     @Before
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");
69     }
70
71     @Test
72     public void testGetData() {
73         try {
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);
79             fail();
80         }
81     }
82
83     @Test
84     public void testGetPAPStatusData() {
85         try {
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);
91             fail();
92         }
93     }
94
95     @Test
96     public void testGetPDPStatusData() {
97         try {
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);
103             fail();
104         }
105     }
106
107     @Test
108     public void testGetPolicyActivityData() {
109         try {
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);
115             fail();
116         }
117     }
118
119     @Test
120     public void testGetSystemAlertData() {
121         try {
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);
127             fail();
128         }
129     }
130 }