Update css file name in conf.py
[policy/engine.git] / POLICY-SDK-APP / src / test / java / org / onap / policy / controller / PolicyControllerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2017, 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 import static org.mockito.Mockito.when;
29
30 import java.util.ArrayList;
31 import java.util.List;
32
33 import javax.script.SimpleBindings;
34
35 import org.apache.commons.io.IOUtils;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.onap.policy.common.logging.flexlogger.FlexLogger;
39 import org.onap.policy.common.logging.flexlogger.Logger;
40 import org.onap.policy.rest.dao.CommonClassDao;
41 import org.onap.policy.rest.jpa.Datatype;
42 import org.onap.policy.rest.jpa.FunctionDefinition;
43 import org.onap.policy.rest.jpa.PolicyEntity;
44
45 public class PolicyControllerTest {
46
47     private static Logger logger = FlexLogger.getLogger(PolicyControllerTest.class);
48     private static CommonClassDao commonClassDao;
49
50     /**
51      * setUp.
52      *
53      * @throws Exception Should not throw one
54      */
55     @Before
56     public void setUp() throws Exception {
57         logger.info("setUp: Entering");
58         commonClassDao = mock(CommonClassDao.class);
59         PolicyController.setCommonClassDao(commonClassDao);
60         String policyData = "";
61         try {
62             ClassLoader classLoader = getClass().getClassLoader();
63             policyData = IOUtils.toString(classLoader.getResourceAsStream("Config_SampleTest1206.1.xml"));
64         } catch (Exception e1) {
65             e1.printStackTrace();
66         }
67         PolicyEntity entity = new PolicyEntity();
68         entity.setPolicyName("Config_SampleTest.1.xml");
69         entity.setPolicyData(policyData);
70         entity.setScope("com");
71         List<Object> data = new ArrayList<>();
72         data.add(entity);
73
74         when(commonClassDao.getDataByQuery(
75                 "FROM PolicyEntity where policyName = 'Config_SampleTest1206.1.xml' and scope ='com'",
76                 new SimpleBindings())).thenReturn(data);
77
78         FunctionDefinition fnDefinition = new FunctionDefinition();
79         fnDefinition.setXacmlid("Test");
80         fnDefinition.setShortname("Test");
81         Datatype dataType = new Datatype();
82         dataType.setXacmlId("Test");
83         fnDefinition.setDatatypeBean(dataType);
84         List<Object> fnObjects = new ArrayList<>();
85         fnObjects.add(fnDefinition);
86         when(commonClassDao.getData(FunctionDefinition.class)).thenReturn(fnObjects);
87     }
88
89     @Test
90     public void testInit() {
91         PolicyController controller = new PolicyController();
92         PolicyController.setjUnit(true);
93         controller.init();
94         try {
95             assertTrue(PolicyController.dropDownMap.size() > 0);
96         } catch (Exception e) {
97             logger.error("Exception Occured" + e);
98             fail();
99         }
100     }
101 }