Format java POLICY-SDK-APP
[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-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
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
23 package org.onap.policy.controller;
24
25 import static org.junit.Assert.assertTrue;
26 import static org.junit.Assert.fail;
27 import static org.mockito.Mockito.mock;
28
29 import java.io.UnsupportedEncodingException;
30 import java.nio.file.Path;
31 import java.nio.file.Paths;
32
33 import javax.servlet.http.HttpServletRequest;
34
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;
44
45 public class DashboardControllerTest {
46     private static Logger logger = FlexLogger.getLogger(DashboardControllerTest.class);
47
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;
54     private Path repo;
55     StdEngine engine = null;
56
57     @Before
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");
73     }
74
75     @Test
76     public void testGetData() {
77         try {
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);
83             fail();
84         }
85     }
86
87     @Test
88     public void testGetPAPStatusData() {
89         try {
90             controller.getPAPStatusData(request, response);
91             assertTrue(
92                     response.getContentAsString() != null && response.getContentAsString().contains("papTableDatas"));
93         } catch (UnsupportedEncodingException e) {
94             logger.error("Exception Occured" + e);
95             fail();
96         }
97     }
98
99     @Test
100     public void testGetPDPStatusData() {
101         try {
102             controller.getPDPStatusData(request, response);
103             assertTrue(
104                     response.getContentAsString() != null && response.getContentAsString().contains("pdpTableDatas"));
105         } catch (UnsupportedEncodingException e) {
106             logger.error("Exception Occured" + e);
107             fail();
108         }
109     }
110
111     @Test
112     public void testGetPolicyActivityData() {
113         try {
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);
119             fail();
120         }
121     }
122
123     @Test
124     public void testGetSystemAlertData() {
125         try {
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);
131             fail();
132         }
133     }
134 }