TCA: Replace any openecomp reference by onap
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-tca / src / test / java / org / onap / dcae / apod / analytics / cdap / tca / BaseAnalyticsCDAPTCAIT.java
1 /*
2  * ===============================LICENSE_START======================================
3  *  dcae-analytics
4  * ================================================================================
5  *    Copyright © 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
10  *
11  *          http://www.apache.org/licenses/LICENSE-2.0
12  *
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===========================================
19  */
20
21 package org.onap.dcae.apod.analytics.cdap.tca;
22
23 import com.fasterxml.jackson.core.JsonProcessingException;
24 import com.fasterxml.jackson.databind.ObjectMapper;
25 import com.fasterxml.jackson.databind.SerializationFeature;
26 import com.google.common.base.Suppliers;
27 import org.junit.BeforeClass;
28 import org.onap.dcae.apod.analytics.cdap.tca.settings.TCATestAppConfig;
29 import org.onap.dcae.apod.analytics.cdap.tca.settings.TCATestAppPreferences;
30 import org.onap.dcae.apod.analytics.model.util.AnalyticsModelIOUtils;
31 import org.onap.dcae.apod.analytics.model.util.json.AnalyticsModelObjectMapperSupplier;
32 import org.onap.dcae.apod.analytics.test.BaseDCAEAnalyticsIT;
33
34 import java.util.Map;
35 import java.util.Properties;
36 import java.util.TreeMap;
37
38 /**
39  *
40  * @author Rajiv Singla . Creation Date: 10/25/2016.
41  */
42 public abstract class BaseAnalyticsCDAPTCAIT extends BaseDCAEAnalyticsIT {
43
44     protected static ObjectMapper objectMapper;
45
46     @BeforeClass
47     public static void beforeClass() {
48         final AnalyticsModelObjectMapperSupplier analyticsModelObjectMapperSupplier =
49                 new AnalyticsModelObjectMapperSupplier();
50         objectMapper = Suppliers.memoize(analyticsModelObjectMapperSupplier).get();
51         objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
52     }
53
54     protected static final String TCA_CONTROLLER_POLICY_FILE_LOCATION =
55             "data/properties/tca_controller_policy.properties";
56
57     // App Settings
58     protected static final String DCAE_ANALYTICS_TCA_TEST_APP_NAME = "dcae-tca";
59     protected static final String DCAE_ANALYTICS_TCA_TEST_APP_DESC =
60             "DCAE Analytics Threshold Crossing Alert Application";
61     
62
63     protected static TCATestAppConfig getTCATestAppConfig() {
64         final TCATestAppConfig tcaTestAppConfig = new TCATestAppConfig();
65         tcaTestAppConfig.setAppName(DCAE_ANALYTICS_TCA_TEST_APP_NAME);
66         tcaTestAppConfig.setAppDescription(DCAE_ANALYTICS_TCA_TEST_APP_DESC);
67         return tcaTestAppConfig;
68     }
69
70     protected static TCATestAppPreferences getTCATestAppPreferences() {
71         final TCATestAppPreferences tcaTestAppPreferences = new TCATestAppPreferences(getTCAPolicyPreferences());
72         tcaTestAppPreferences.setSubscriberPollingInterval(null);
73         tcaTestAppPreferences.setPublisherMaxBatchSize(null);
74         tcaTestAppPreferences.setPublisherMaxRecoveryQueueSize(null);
75         tcaTestAppPreferences.setEnableAlertCEFFormat(null);
76         tcaTestAppPreferences.setPublisherPollingInterval(null);
77         return tcaTestAppPreferences;
78     }
79
80
81     protected static Map<String, String> getTCAPolicyPreferences() {
82         final Map<String, String> policyPreferences = new TreeMap<>();
83         final Properties policyPreferencesProps =
84                 AnalyticsModelIOUtils.loadPropertiesFile(TCA_CONTROLLER_POLICY_FILE_LOCATION, new Properties());
85         for (Map.Entry<Object, Object> propEntry : policyPreferencesProps.entrySet()) {
86             policyPreferences.put(propEntry.getKey().toString(), propEntry.getValue().toString());
87         }
88
89         return policyPreferences;
90     }
91
92     protected static String serializeModelToJson(Object model) throws JsonProcessingException {
93         return objectMapper.writeValueAsString(model);
94     }
95 }