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;
51 public void setUp() throws Exception {
52 logger.info("setUp: Entering");
53 commonClassDao = mock(CommonClassDao.class);
54 PolicyController.setCommonClassDao(commonClassDao);
55 List<Object> data = new ArrayList<>();
56 String policyData = "";
58 ClassLoader classLoader = getClass().getClassLoader();
59 policyData = IOUtils.toString(classLoader.getResourceAsStream("Config_SampleTest1206.1.xml"));
60 } catch (Exception e1) {
63 PolicyEntity entity = new PolicyEntity();
64 entity.setPolicyName("Config_SampleTest.1.xml");
65 entity.setPolicyData(policyData);
66 entity.setScope("com");
69 when(commonClassDao.getDataByQuery(
70 "FROM PolicyEntity where policyName = 'Config_SampleTest1206.1.xml' and scope ='com'",
71 new SimpleBindings())).thenReturn(data);
73 FunctionDefinition fnDefinition = new FunctionDefinition();
74 fnDefinition.setXacmlid("Test");
75 fnDefinition.setShortname("Test");
76 Datatype dataType = new Datatype();
77 dataType.setXacmlId("Test");
78 fnDefinition.setDatatypeBean(dataType);
79 List<Object> fnObjects = new ArrayList<>();
80 fnObjects.add(fnDefinition);
81 when(commonClassDao.getData(FunctionDefinition.class)).thenReturn(fnObjects);
85 public void testInit() {
86 PolicyController controller = new PolicyController();
87 PolicyController.setjUnit(true);
90 assertTrue(PolicyController.dropDownMap.size() > 0);
91 } catch (Exception e) {
92 logger.error("Exception Occured" + e);