2 * ============LICENSE_START=======================================================
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
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;
28 import static org.mockito.Mockito.when;
30 import java.util.ArrayList;
31 import java.util.List;
33 import javax.script.SimpleBindings;
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;
45 public class PolicyControllerTest {
47 private static Logger logger = FlexLogger.getLogger(PolicyControllerTest.class);
48 private static CommonClassDao commonClassDao;
53 * @throws Exception Should not throw one
56 public void setUp() throws Exception {
57 logger.info("setUp: Entering");
58 commonClassDao = mock(CommonClassDao.class);
59 PolicyController.setCommonClassDao(commonClassDao);
60 String policyData = "";
62 ClassLoader classLoader = getClass().getClassLoader();
63 policyData = IOUtils.toString(classLoader.getResourceAsStream("Config_SampleTest1206.1.xml"));
64 } catch (Exception e1) {
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<>();
74 when(commonClassDao.getDataByQuery(
75 "FROM PolicyEntity where policyName = 'Config_SampleTest1206.1.xml' and scope ='com'",
76 new SimpleBindings())).thenReturn(data);
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);
90 public void testInit() {
91 PolicyController controller = new PolicyController();
92 PolicyController.setjUnit(true);
95 assertTrue(PolicyController.dropDownMap.size() > 0);
96 } catch (Exception e) {
97 logger.error("Exception Occured" + e);