2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.policy.controller;
22 import static org.junit.Assert.assertTrue;
23 import static org.junit.Assert.fail;
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.when;
27 import java.util.ArrayList;
28 import java.util.List;
30 import javax.script.SimpleBindings;
32 import org.apache.commons.io.IOUtils;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.onap.policy.common.logging.flexlogger.FlexLogger;
36 import org.onap.policy.common.logging.flexlogger.Logger;
37 import org.onap.policy.rest.dao.CommonClassDao;
38 import org.onap.policy.rest.jpa.Datatype;
39 import org.onap.policy.rest.jpa.FunctionDefinition;
40 import org.onap.policy.rest.jpa.PolicyEntity;
42 public class PolicyControllerTest {
44 private static Logger logger = FlexLogger.getLogger(PolicyControllerTest.class);
45 private static CommonClassDao commonClassDao;
48 public void setUp() throws Exception{
49 logger.info("setUp: Entering");
50 commonClassDao = mock(CommonClassDao.class);
51 PolicyController.setCommonClassDao(commonClassDao);
52 List<Object> data = new ArrayList<>();
53 String policyData = "";
55 ClassLoader classLoader = getClass().getClassLoader();
56 policyData = IOUtils.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("FROM PolicyEntity where policyName = 'Config_SampleTest1206.1.xml' and scope ='com'", new SimpleBindings())).thenReturn(data);
68 FunctionDefinition fnDefinition = new FunctionDefinition();
69 fnDefinition.setXacmlid("Test");
70 fnDefinition.setShortname("Test");
71 Datatype dataType = new Datatype();
72 dataType.setXacmlId("Test");
73 fnDefinition.setDatatypeBean(dataType);
74 List<Object> fnObjects = new ArrayList<>();
75 fnObjects.add(fnDefinition);
76 when(commonClassDao.getData(FunctionDefinition.class)).thenReturn(fnObjects);
80 public void testInit(){
81 PolicyController controller = new PolicyController();
82 PolicyController.setjUnit(true);
85 assertTrue(PolicyController.dropDownMap.size() > 0);
87 logger.error("Exception Occured"+e);