2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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=========================================================
22 package org.onap.policy.controller;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.when;
28 import java.util.ArrayList;
29 import java.util.List;
30 import javax.script.SimpleBindings;
31 import org.apache.commons.io.IOUtils;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.onap.policy.common.logging.flexlogger.FlexLogger;
35 import org.onap.policy.common.logging.flexlogger.Logger;
36 import org.onap.policy.rest.dao.CommonClassDao;
37 import org.onap.policy.rest.jpa.Datatype;
38 import org.onap.policy.rest.jpa.FunctionDefinition;
39 import org.onap.policy.rest.jpa.PolicyEntity;
41 public class PolicyControllerTest {
43 private static Logger logger = FlexLogger.getLogger(PolicyControllerTest.class);
44 private static CommonClassDao commonClassDao;
47 public void setUp() throws Exception {
48 logger.info("setUp: Entering");
49 commonClassDao = mock(CommonClassDao.class);
50 PolicyController.setCommonClassDao(commonClassDao);
51 List<Object> data = new ArrayList<>();
52 String policyData = "";
54 ClassLoader classLoader = getClass().getClassLoader();
56 .toString(classLoader.getResourceAsStream("Config_SampleTest1206.1.xml"));
57 } catch (Exception e1) {
60 PolicyEntity entity = new PolicyEntity();
61 entity.setPolicyName("Config_SampleTest.1.xml");
62 entity.setPolicyData(policyData);
63 entity.setScope("com");
66 when(commonClassDao.getDataByQuery(
67 "FROM PolicyEntity where policyName = 'Config_SampleTest1206.1.xml' and scope ='com'",
68 new SimpleBindings())).thenReturn(data);
70 FunctionDefinition fnDefinition = new FunctionDefinition();
71 fnDefinition.setXacmlid("Test");
72 fnDefinition.setShortname("Test");
73 Datatype dataType = new Datatype();
74 dataType.setXacmlId("Test");
75 fnDefinition.setDatatypeBean(dataType);
76 List<Object> fnObjects = new ArrayList<>();
77 fnObjects.add(fnDefinition);
78 when(commonClassDao.getData(FunctionDefinition.class)).thenReturn(fnObjects);
82 public void testInit() {
83 PolicyController controller = new PolicyController();
84 PolicyController.setjUnit(true);
87 assertTrue(PolicyController.dropDownMap.size() > 0);
88 } catch (Exception e) {
89 logger.error("Exception Occured" + e);