TCA: Support for VES/A&AI enrichment
[dcaegen2/analytics/tca.git] / dcae-analytics-tca / src / test / java / org / openecomp / dcae / apod / analytics / tca / BaseAnalyticsTCAUnitTest.java
index 8bdeee5..ba3b6bb 100644 (file)
-/*
- * ===============================LICENSE_START======================================
- *  dcae-analytics
- * ================================================================================
- *    Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *   You may obtain a copy of the License at
- *
- *          http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *  ============================LICENSE_END===========================================
- */
-
-package org.openecomp.dcae.apod.analytics.tca;
-
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.common.base.Suppliers;
-import org.openecomp.dcae.apod.analytics.model.domain.cef.EventListener;
-import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.ControlLoopEventStatus;
-import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.Direction;
-import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.TCAPolicy;
-import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.Threshold;
-import org.openecomp.dcae.apod.analytics.model.util.AnalyticsModelIOUtils;
-import org.openecomp.dcae.apod.analytics.model.util.json.AnalyticsModelObjectMapperSupplier;
-import org.openecomp.dcae.apod.analytics.test.BaseDCAEAnalyticsUnitTest;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-/**
- * @author Rajiv Singla . Creation Date: 10/25/2016.
- */
-public abstract class BaseAnalyticsTCAUnitTest extends BaseDCAEAnalyticsUnitTest {
-
-    /**
-     * Object mapper to be used for all TCA Json Parsing
-     */
-    protected static final ObjectMapper ANALYTICS_MODEL_OBJECT_MAPPER =
-            Suppliers.memoize(new AnalyticsModelObjectMapperSupplier()).get();
-
-    protected static final String TCA_POLICY_JSON_FILE_LOCATION = "data/json/policy/tca_policy.json";
-    protected static final String CEF_MESSAGES_JSON_FILE_LOCATION = "data/json/cef/cef_messages.json";
-    protected static final String CEF_MESSAGE_JSON_FILE_LOCATION = "data/json/cef/cef_message.json";
-    protected static final String CEF_MESSAGE_WITH_THRESHOLD_VIOLATION_JSON_FILE_LOCATION =
-            "data/json/cef/cef_message_with_threshold_violation.json";
-
-    protected static final String TCA_CONTROLLER_POLICY_FILE_LOCATION =
-            "data/properties/tca_controller_policy.properties";
-
-    protected static final String TCA_TEST_APP_CONFIG_NAME = "testTCAAppName";
-    protected static final String TCA_TEST_APP_CONFIG_DESCRIPTION = "testTCAAppDescription";
-    protected static final String TCA_TEST_APP_CONFIG_SUBSCRIBER_OUTPUT_STREAM_NAME =
-            "testTcaSubscriberOutputStreamName";
-    protected static final String TCA_TEST_APP_CONFIG_VES_ALERT_TABLE_NAME = "testTcaVESAlertsTableName";
-    protected static final String TCA_TEST_APP_CONFIG_VES_MESSAGE_STATUS_TABLE_NAME =
-            "testTcaVESMessageStatusTableName";
-
-
-    /**
-     * Provides TCA Policy that can be used for testing
-     *
-     * @return test TCA Policy Object
-     */
-    protected TCAPolicy getSampleTCAPolicy() {
-        try {
-            return ANALYTICS_MODEL_OBJECT_MAPPER.readValue(fromStream(TCA_POLICY_JSON_FILE_LOCATION), TCAPolicy.class);
-        } catch (IOException e) {
-            LOG.error("Error while parsing policy: {}", e);
-            throw new RuntimeException("Error while parsing policy", e);
-        }
-    }
-
-    /**
-     * Provides list containing 350 CEF messages
-     *
-     * @return CEF Test Message
-     * @throws Exception Exception
-     */
-    protected List<EventListener> getCEFMessages() throws Exception {
-        final String cefMessageAsString = fromStream(CEF_MESSAGES_JSON_FILE_LOCATION);
-        final TypeReference<List<EventListener>> eventListenerListTypeReference =
-                new TypeReference<List<EventListener>>() {
-                };
-        return ANALYTICS_MODEL_OBJECT_MAPPER.readValue(cefMessageAsString, eventListenerListTypeReference);
-    }
-
-    /**
-     * Provides 1 valid CEF messages which does not violate Threshold as String
-     *
-     * @return CEF Test Message String
-     * @throws Exception Exception
-     */
-    protected String getValidCEFMessage() throws Exception {
-        return fromStream(CEF_MESSAGE_JSON_FILE_LOCATION);
-    }
-
-
-    /**
-     * Provides single CEF Test Message
-     *
-     * @return CEF Test Message
-     * @throws Exception Exception
-     */
-    protected EventListener getCEFEventListener() throws Exception {
-        final String cefMessageAsString = fromStream(CEF_MESSAGE_JSON_FILE_LOCATION);
-        return ANALYTICS_MODEL_OBJECT_MAPPER.readValue(cefMessageAsString, EventListener.class);
-    }
-
-    protected static List<Threshold> getThresholds() {
-        Threshold majorThreshold = new Threshold();
-        majorThreshold.setClosedLoopControlName("CL-LBAL-LOW-TRAFFIC-SIG-FB480F95-A453-6F24-B767-FD703241AB1A");
-        majorThreshold.setFieldPath("$.event.measurementsForVfScalingFields.vNicUsageArray[*].packetsIn");
-        majorThreshold.setVersion("Test Version");
-        majorThreshold.setThresholdValue(500L);
-        majorThreshold.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
-        majorThreshold.setDirection(Direction.LESS_OR_EQUAL);
-
-        Threshold criticalThreshold = new Threshold();
-        criticalThreshold.setClosedLoopControlName("CL-LBAL-LOW-TRAFFIC-SIG-FB480F95-A453-6F24-B767-FD703241AB1A");
-        criticalThreshold.setThresholdValue(5000L);
-        criticalThreshold.setFieldPath("$.event.measurementsForVfScalingFields.vNicUsageArray[*].packetsIn");
-        criticalThreshold.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
-        criticalThreshold.setDirection(Direction.GREATER_OR_EQUAL);
-        return Arrays.asList(majorThreshold, criticalThreshold);
-    }
-
-    protected static Threshold getCriticalThreshold() {
-        Threshold criticalThreshold = new Threshold();
-        criticalThreshold.setClosedLoopControlName("CL-LBAL-LOW-TRAFFIC-SIG-FB480F95-A453-6F24-B767-FD703241AB1A");
-        criticalThreshold.setThresholdValue(5000L);
-        criticalThreshold.setFieldPath("$.event.measurementsForVfScalingFields.vNicUsageArray[*].packetsIn");
-        criticalThreshold.setDirection(Direction.GREATER_OR_EQUAL);
-        return criticalThreshold;
-    }
-
-    protected static Map<String, String> getControllerRuntimeArguments() {
-        final Properties controllerProperties =
-                AnalyticsModelIOUtils.loadPropertiesFile(TCA_CONTROLLER_POLICY_FILE_LOCATION, new Properties());
-
-        final Map<String, String> runtimeArgs = new LinkedHashMap<>();
-        for (Map.Entry<Object, Object> property : controllerProperties.entrySet()) {
-            runtimeArgs.put(property.getKey().toString(), property.getValue().toString());
-        }
-
-        return runtimeArgs;
-    }
-
-}
+/*\r
+ * ===============================LICENSE_START======================================\r
+ *  dcae-analytics\r
+ * ================================================================================\r
+ *    Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * ================================================================================\r
+ *  Licensed under the Apache License, Version 2.0 (the "License");\r
+ *  you may not use this file except in compliance with the License.\r
+ *   You may obtain a copy of the License at\r
+ *\r
+ *          http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *  Unless required by applicable law or agreed to in writing, software\r
+ *  distributed under the License is distributed on an "AS IS" BASIS,\r
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *  See the License for the specific language governing permissions and\r
+ *  limitations under the License.\r
+ *  ============================LICENSE_END===========================================\r
+ */\r
+\r
+package org.openecomp.dcae.apod.analytics.tca;\r
+\r
+import com.fasterxml.jackson.core.type.TypeReference;\r
+import com.fasterxml.jackson.databind.ObjectMapper;\r
+import com.google.common.base.Suppliers;\r
+import org.openecomp.dcae.apod.analytics.model.domain.cef.EventListener;\r
+import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.ClosedLoopEventStatus;\r
+import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.Direction;\r
+import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.TCAPolicy;\r
+import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.Threshold;\r
+import org.openecomp.dcae.apod.analytics.model.util.AnalyticsModelIOUtils;\r
+import org.openecomp.dcae.apod.analytics.model.util.json.AnalyticsModelObjectMapperSupplier;\r
+import org.openecomp.dcae.apod.analytics.test.BaseDCAEAnalyticsUnitTest;\r
+\r
+import java.io.IOException;\r
+import java.util.Arrays;\r
+import java.util.LinkedHashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Properties;\r
+\r
+/**\r
+ * @author Rajiv Singla . Creation Date: 10/25/2016.\r
+ */\r
+public abstract class BaseAnalyticsTCAUnitTest extends BaseDCAEAnalyticsUnitTest {\r
+\r
+    /**\r
+     * Object mapper to be used for all TCA Json Parsing\r
+     */\r
+    protected static final ObjectMapper ANALYTICS_MODEL_OBJECT_MAPPER =\r
+            Suppliers.memoize(new AnalyticsModelObjectMapperSupplier()).get();\r
+\r
+    protected static final String TCA_POLICY_JSON_FILE_LOCATION = "data/json/policy/tca_policy.json";\r
+    protected static final String CEF_MESSAGES_JSON_FILE_LOCATION = "data/json/cef/cef_messages.json";\r
+    protected static final String CEF_MESSAGE_JSON_FILE_LOCATION = "data/json/cef/cef_message.json";\r
+    protected static final String CEF_MESSAGE_WITH_THRESHOLD_VIOLATION_JSON_FILE_LOCATION =\r
+            "data/json/cef/cef_message_with_threshold_violation.json";\r
+\r
+    protected static final String TCA_CONTROLLER_POLICY_FILE_LOCATION =\r
+            "data/properties/tca_controller_policy.properties";\r
+\r
+    protected static final String TCA_AAI_VNF_ENRICHMENT_FILE_LOCATION = "data/json/aai/aai_vnf_enrichment.json";\r
+\r
+    protected static final String TCA_TEST_APP_CONFIG_NAME = "testTCAAppName";\r
+    protected static final String TCA_TEST_APP_CONFIG_DESCRIPTION = "testTCAAppDescription";\r
+    protected static final String TCA_TEST_APP_CONFIG_SUBSCRIBER_OUTPUT_STREAM_NAME =\r
+            "testTcaSubscriberOutputStreamName";\r
+    protected static final String TCA_TEST_APP_CONFIG_VES_ALERT_TABLE_NAME = "testTcaVESAlertsTableName";\r
+    protected static final String TCA_TEST_APP_CONFIG_VES_MESSAGE_STATUS_TABLE_NAME =\r
+            "testTcaVESMessageStatusTableName";\r
+\r
+\r
+    /**\r
+     * Provides TCA Policy that can be used for testing\r
+     *\r
+     * @return test TCA Policy Object\r
+     */\r
+    protected TCAPolicy getSampleTCAPolicy() {\r
+        try {\r
+            return ANALYTICS_MODEL_OBJECT_MAPPER.readValue(fromStream(TCA_POLICY_JSON_FILE_LOCATION), TCAPolicy.class);\r
+        } catch (IOException e) {\r
+            LOG.error("Error while parsing policy: {}", e);\r
+            throw new RuntimeException("Error while parsing policy", e);\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Provides list containing 350 CEF messages\r
+     *\r
+     * @return CEF Test Message\r
+     * @throws Exception Exception\r
+     */\r
+    protected List<EventListener> getCEFMessages() throws Exception {\r
+        final String cefMessageAsString = fromStream(CEF_MESSAGES_JSON_FILE_LOCATION);\r
+        final TypeReference<List<EventListener>> eventListenerListTypeReference =\r
+                new TypeReference<List<EventListener>>() {\r
+                };\r
+        return ANALYTICS_MODEL_OBJECT_MAPPER.readValue(cefMessageAsString, eventListenerListTypeReference);\r
+    }\r
+\r
+    /**\r
+     * Provides 1 valid CEF messages which does not violate Threshold as String\r
+     *\r
+     * @return CEF Test Message String\r
+     * @throws Exception Exception\r
+     */\r
+    protected String getValidCEFMessage() throws Exception {\r
+        return fromStream(CEF_MESSAGE_JSON_FILE_LOCATION);\r
+    }\r
+\r
+\r
+    /**\r
+     * Provides single CEF Test Message\r
+     *\r
+     * @return CEF Test Message\r
+     * @throws Exception Exception\r
+     */\r
+    protected EventListener getCEFEventListener() throws Exception {\r
+        final String cefMessageAsString = fromStream(CEF_MESSAGE_JSON_FILE_LOCATION);\r
+        return ANALYTICS_MODEL_OBJECT_MAPPER.readValue(cefMessageAsString, EventListener.class);\r
+    }\r
+\r
+    protected static List<Threshold> getThresholds() {\r
+        Threshold majorThreshold = new Threshold();\r
+        majorThreshold.setClosedLoopControlName("CL-LBAL-LOW-TRAFFIC-SIG-FB480F95-A453-6F24-B767-FD703241AB1A");\r
+        majorThreshold.setFieldPath("$.event.measurementsForVfScalingFields.vNicUsageArray[*].packetsIn");\r
+        majorThreshold.setVersion("Test Version");\r
+        majorThreshold.setThresholdValue(500L);\r
+        majorThreshold.setClosedLoopEventStatus(ClosedLoopEventStatus.ONSET);\r
+        majorThreshold.setDirection(Direction.LESS_OR_EQUAL);\r
+\r
+        Threshold criticalThreshold = new Threshold();\r
+        criticalThreshold.setClosedLoopControlName("CL-LBAL-LOW-TRAFFIC-SIG-FB480F95-A453-6F24-B767-FD703241AB1A");\r
+        criticalThreshold.setThresholdValue(5000L);\r
+        criticalThreshold.setFieldPath("$.event.measurementsForVfScalingFields.vNicUsageArray[*].packetsIn");\r
+        criticalThreshold.setClosedLoopEventStatus(ClosedLoopEventStatus.ONSET);\r
+        criticalThreshold.setDirection(Direction.GREATER_OR_EQUAL);\r
+        return Arrays.asList(majorThreshold, criticalThreshold);\r
+    }\r
+\r
+    protected static Threshold getCriticalThreshold() {\r
+        Threshold criticalThreshold = new Threshold();\r
+        criticalThreshold.setClosedLoopControlName("CL-LBAL-LOW-TRAFFIC-SIG-FB480F95-A453-6F24-B767-FD703241AB1A");\r
+        criticalThreshold.setThresholdValue(5000L);\r
+        criticalThreshold.setFieldPath("$.event.measurementsForVfScalingFields.vNicUsageArray[*].packetsIn");\r
+        criticalThreshold.setDirection(Direction.GREATER_OR_EQUAL);\r
+        return criticalThreshold;\r
+    }\r
+\r
+    protected static Map<String, String> getControllerRuntimeArguments() {\r
+        final Properties controllerProperties =\r
+                AnalyticsModelIOUtils.loadPropertiesFile(TCA_CONTROLLER_POLICY_FILE_LOCATION, new Properties());\r
+\r
+        final Map<String, String> runtimeArgs = new LinkedHashMap<>();\r
+        for (Map.Entry<Object, Object> property : controllerProperties.entrySet()) {\r
+            runtimeArgs.put(property.getKey().toString(), property.getValue().toString());\r
+        }\r
+\r
+        return runtimeArgs;\r
+    }\r
+\r
+}\r