2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 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.pap.xacml.rest.elk;
22 import static org.junit.Assert.assertTrue;
24 import java.io.IOException;
25 import java.sql.SQLException;
26 import java.util.Date;
28 import javax.servlet.ServletException;
30 import org.apache.commons.io.IOUtils;
31 import org.junit.After;
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.pap.test.XACMLPAPTest;
37 import org.onap.policy.pap.xacml.rest.daoimpl.CommonClassDaoImpl;
38 import org.onap.policy.pap.xacml.rest.elk.client.ElasticSearchPolicyUpdate;
39 import org.onap.policy.rest.jpa.ConfigurationDataEntity;
40 import org.onap.policy.rest.jpa.PolicyEntity;
42 public class ElasticSearchPolicyUpdateTest {
44 private static Logger logger = FlexLogger.getLogger(ElasticSearchPolicyUpdateTest.class);
45 private Object policyContent = "";
46 private XACMLPAPTest papTest;
49 public void setUp() throws IOException, ServletException, SQLException{
50 // Set the system property temporarily
51 System.setProperty("PROPERTY_FILE", "src/test/resources/policyelk.properties");
53 ClassLoader classLoader = getClass().getClassLoader();
54 policyContent = IOUtils.toString(classLoader.getResourceAsStream("Config_SampleTest1206.1.xml"));
55 } catch (Exception e1) {
56 logger.error("Exception Occured"+e1);
58 papTest = new XACMLPAPTest();
63 public void testElasticSearchMainFunction() throws SQLException{
64 ConfigurationDataEntity configurationEntity = new ConfigurationDataEntity();
65 configurationEntity.setConfigBody("Sample Test");
66 configurationEntity.setConfigType("OTHER");
67 configurationEntity.setConfigurationName("com.Config_SampleTest1206.1.txt");
68 configurationEntity.setDescription("test");
69 configurationEntity.setModifiedBy("Test");
70 configurationEntity.setModifiedDate(new Date());
73 PolicyEntity entity = new PolicyEntity();
74 entity.setPolicyName("Config_SampleTest.1.xml");
75 entity.setPolicyData(policyContent.toString());
76 entity.setScope("com");
77 entity.setCreatedBy("Test");
78 entity.setDeleted(false);
79 entity.setDescription("Test");
80 entity.setModifiedBy("Test");
81 entity.setConfigurationData(configurationEntity);
83 CommonClassDaoImpl dao = new CommonClassDaoImpl();
84 dao.save(configurationEntity);
86 dao.delete(dao.getEntityItem(PolicyEntity.class, "policyName", "Config_SampleTest.1.xml"));
87 ElasticSearchPolicyUpdate.main(null);
88 StringBuilder policyDataString = new StringBuilder();
89 ElasticSearchPolicyUpdate.constructPolicyData(policyContent, policyDataString);
90 assertTrue(policyDataString.toString().contains("onapName"));
95 System.clearProperty("PROPERTY_FILE");