2 * ===============================LICENSE_START======================================
\r
4 * ================================================================================
\r
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============================LICENSE_END===========================================
\r
21 package org.openecomp.dcae.apod.analytics.cdap.tca;
\r
23 import com.fasterxml.jackson.core.JsonProcessingException;
\r
24 import com.fasterxml.jackson.databind.ObjectMapper;
\r
25 import com.fasterxml.jackson.databind.SerializationFeature;
\r
26 import com.google.common.base.Suppliers;
\r
27 import org.junit.BeforeClass;
\r
28 import org.openecomp.dcae.apod.analytics.cdap.tca.settings.TCATestAppConfig;
\r
29 import org.openecomp.dcae.apod.analytics.cdap.tca.settings.TCATestAppPreferences;
\r
30 import org.openecomp.dcae.apod.analytics.model.util.AnalyticsModelIOUtils;
\r
31 import org.openecomp.dcae.apod.analytics.model.util.json.AnalyticsModelObjectMapperSupplier;
\r
32 import org.openecomp.dcae.apod.analytics.test.BaseDCAEAnalyticsIT;
\r
34 import java.util.Map;
\r
35 import java.util.Properties;
\r
36 import java.util.TreeMap;
\r
40 * @author Rajiv Singla . Creation Date: 10/25/2016.
\r
42 public abstract class BaseAnalyticsCDAPTCAIT extends BaseDCAEAnalyticsIT {
\r
44 protected static ObjectMapper objectMapper;
\r
47 public static void beforeClass() {
\r
48 final AnalyticsModelObjectMapperSupplier analyticsModelObjectMapperSupplier =
\r
49 new AnalyticsModelObjectMapperSupplier();
\r
50 objectMapper = Suppliers.memoize(analyticsModelObjectMapperSupplier).get();
\r
51 objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
\r
54 protected static final String TCA_CONTROLLER_POLICY_FILE_LOCATION =
\r
55 "data/properties/tca_controller_policy.properties";
\r
58 protected static final String DCAE_ANALYTICS_TCA_TEST_APP_NAME = "dcae-tca";
\r
59 protected static final String DCAE_ANALYTICS_TCA_TEST_APP_DESC =
\r
60 "DCAE Analytics Threshold Crossing Alert Application";
\r
63 protected static TCATestAppConfig getTCATestAppConfig() {
\r
64 final TCATestAppConfig tcaTestAppConfig = new TCATestAppConfig();
\r
65 tcaTestAppConfig.setAppName(DCAE_ANALYTICS_TCA_TEST_APP_NAME);
\r
66 tcaTestAppConfig.setAppDescription(DCAE_ANALYTICS_TCA_TEST_APP_DESC);
\r
67 return tcaTestAppConfig;
\r
70 protected static TCATestAppPreferences getTCATestAppPreferences() {
\r
71 final TCATestAppPreferences tcaTestAppPreferences = new TCATestAppPreferences(getTCAPolicyPreferences());
\r
72 tcaTestAppPreferences.setSubscriberPollingInterval(null);
\r
73 tcaTestAppPreferences.setPublisherMaxBatchSize(null);
\r
74 tcaTestAppPreferences.setPublisherMaxRecoveryQueueSize(null);
\r
75 tcaTestAppPreferences.setEnableAlertCEFFormat(null);
\r
76 tcaTestAppPreferences.setPublisherPollingInterval(null);
\r
77 return tcaTestAppPreferences;
\r
81 protected static Map<String, String> getTCAPolicyPreferences() {
\r
82 final Map<String, String> policyPreferences = new TreeMap<>();
\r
83 final Properties policyPreferencesProps =
\r
84 AnalyticsModelIOUtils.loadPropertiesFile(TCA_CONTROLLER_POLICY_FILE_LOCATION, new Properties());
\r
85 for (Map.Entry<Object, Object> propEntry : policyPreferencesProps.entrySet()) {
\r
86 policyPreferences.put(propEntry.getKey().toString(), propEntry.getValue().toString());
\r
89 return policyPreferences;
\r
92 protected static String serializeModelToJson(Object model) throws JsonProcessingException {
\r
93 return objectMapper.writeValueAsString(model);
\r