2 * ===============================LICENSE_START======================================
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
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===========================================
21 package org.onap.dcae.apod.analytics.cdap.tca;
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;
35 import java.util.Properties;
36 import java.util.TreeMap;
40 * @author Rajiv Singla . Creation Date: 10/25/2016.
42 public abstract class BaseAnalyticsCDAPTCAIT extends BaseDCAEAnalyticsIT {
44 protected static ObjectMapper objectMapper;
47 public static void beforeClass() {
48 final AnalyticsModelObjectMapperSupplier analyticsModelObjectMapperSupplier =
49 new AnalyticsModelObjectMapperSupplier();
50 objectMapper = Suppliers.memoize(analyticsModelObjectMapperSupplier).get();
51 objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
54 protected static final String TCA_CONTROLLER_POLICY_FILE_LOCATION =
55 "data/properties/tca_controller_policy.properties";
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";
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;
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;
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());
89 return policyPreferences;
92 protected static String serializeModelToJson(Object model) throws JsonProcessingException {
93 return objectMapper.writeValueAsString(model);