TCA: Support for VES/A&AI enrichment
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-plugins / src / test / java / org / openecomp / dcae / apod / analytics / cdap / plugins / validator / SimpleTCAPluginConfigValidatorTest.java
index 07dfe45..3641c79 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.cdap.plugins.validator;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.openecomp.dcae.apod.analytics.cdap.plugins.BaseAnalyticsCDAPPluginsUnitTest;
-import org.openecomp.dcae.apod.analytics.cdap.plugins.domain.config.tca.SimpleTCAPluginConfig;
-import org.openecomp.dcae.apod.analytics.cdap.plugins.domain.config.tca.TestSimpleTCAPluginConfig;
-import org.openecomp.dcae.apod.analytics.common.validation.GenericValidationResponse;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-/**
- * @author Rajiv Singla . Creation Date: 2/21/2017.
- */
-public class SimpleTCAPluginConfigValidatorTest extends BaseAnalyticsCDAPPluginsUnitTest {
-
-    private TestSimpleTCAPluginConfig testSimpleTCAPluginConfig;
-    private SimpleTCAPluginConfigValidator simpleTCAPluginConfigValidator;
-
-    @Before
-    public void before() {
-        testSimpleTCAPluginConfig = getTestSimpleTCAPluginConfig();
-        simpleTCAPluginConfigValidator = new SimpleTCAPluginConfigValidator();
-    }
-
-    @Test
-    public void testValidateAppSettingsWhenAllSettingsAreValid() throws Exception {
-        final GenericValidationResponse<SimpleTCAPluginConfig> validationResponse =
-                simpleTCAPluginConfigValidator.validateAppSettings(testSimpleTCAPluginConfig);
-        assertFalse(validationResponse.hasErrors());
-    }
-
-    @Test
-    public void testValidateAppSettingsWhenVESMessageFieldNameIsMissing() throws Exception {
-        testSimpleTCAPluginConfig.setVesMessageFieldName(null);
-        assertResponseHasErrors(testSimpleTCAPluginConfig, simpleTCAPluginConfigValidator);
-    }
-
-    @Test
-    public void testValidateAppSettingsWhenPolicyJsonIsMissing() throws Exception {
-        testSimpleTCAPluginConfig.setPolicyJson(null);
-        assertResponseHasErrors(testSimpleTCAPluginConfig, simpleTCAPluginConfigValidator);
-    }
-
-    @Test
-    public void testValidateAppSettingsWhenAlertFieldNameIsMissing() throws Exception {
-        testSimpleTCAPluginConfig.setAlertFieldName(null);
-        assertResponseHasErrors(testSimpleTCAPluginConfig, simpleTCAPluginConfigValidator);
-    }
-
-    @Test
-    public void testValidateAppSettingsWhenOutputSchemaIsNull() throws Exception {
-        testSimpleTCAPluginConfig.setSchema(null);
-        assertResponseHasErrors(testSimpleTCAPluginConfig, simpleTCAPluginConfigValidator);
-    }
-
-    @Test
-    public void testValidateAppSettingsWhenMessageTypeFieldNameIsMissing() throws Exception {
-        testSimpleTCAPluginConfig.setMessageTypeFieldName(null);
-        assertResponseHasErrors(testSimpleTCAPluginConfig, simpleTCAPluginConfigValidator);
-    }
-
-    @Test
-    public void testValidateAppSettingsWhenAlertFieldIsNullableInOutputSchema() throws Exception {
-        testSimpleTCAPluginConfig.setSchema(
-                "{\"type\":\"record\"," +
-                        "\"name\":\"etlSchemaBody\"," +
-                        "\"fields\":[" +
-                            "{\"name\":\"ts\",\"type\":\"long\"}," +
-                            "{\"name\":\"responseCode\",\"type\":\"int\"}," +
-                            "{\"name\":\"responseMessage\",\"type\":\"string\"}," +
-                            "{\"name\":\"message\",\"type\":\"string\"}," +
-                            "{\"name\":\"alert\",\"type\":[\"string\",\"null\"]}," +
-                            "{\"name\":\"tcaMessageType\",\"type\":\"string\"}]}");
-        final GenericValidationResponse<SimpleTCAPluginConfig> validationResponse =
-                simpleTCAPluginConfigValidator.validateAppSettings(testSimpleTCAPluginConfig);
-        assertFalse(validationResponse.hasErrors());
-
-    }
-
-    @Test
-    public void testValidateAppSettingsWhenAlertFieldIsNotPresentInOutputSchema() throws Exception {
-        testSimpleTCAPluginConfig.setSchema(
-                "{\"type\":\"record\"," +
-                        "\"name\":\"etlSchemaBody\"," +
-                        "\"fields\":[" +
-                        "{\"name\":\"ts\",\"type\":\"long\"}," +
-                        "{\"name\":\"responseCode\",\"type\":\"int\"}," +
-                        "{\"name\":\"responseMessage\",\"type\":\"string\"}," +
-                        "{\"name\":\"message\",\"type\":\"string\"}," +
-                        "{\"name\":\"tcaMessageType\",\"type\":\"string\"}]}");
-        final GenericValidationResponse<SimpleTCAPluginConfig> validationResponse =
-                simpleTCAPluginConfigValidator.validateAppSettings(testSimpleTCAPluginConfig);
-        assertFalse(validationResponse.hasErrors());
-
-    }
-
-    @Test
-    public void testValidateAppSettingsWhenAlertFieldIsNullableButNotStringTypeInOutputSchema() throws Exception {
-        testSimpleTCAPluginConfig.setSchema(
-                "{\"type\":\"record\"," +
-                        "\"name\":\"etlSchemaBody\"," +
-                        "\"fields\":[" +
-                        "{\"name\":\"ts\",\"type\":\"long\"}," +
-                        "{\"name\":\"responseCode\",\"type\":\"int\"}," +
-                        "{\"name\":\"responseMessage\",\"type\":\"string\"}," +
-                        "{\"name\":\"message\",\"type\":\"string\"}," +
-                        "{\"name\":\"alert\",\"type\":[\"int\",\"null\"]}," +
-                        "{\"name\":\"tcaMessageType\",\"type\":\"string\"}]}");
-        assertResponseHasErrors(testSimpleTCAPluginConfig, simpleTCAPluginConfigValidator);
-    }
-
-    @Test
-    public void testValidateAppSettingsWhenAlertFieldNameIsNotNullableInOutputSchema() throws Exception {
-        testSimpleTCAPluginConfig.setSchema(
-                "{\"type\":\"record\"," +
-                        "\"name\":\"etlSchemaBody\"," +
-                        "\"fields\":[" +
-                        "{\"name\":\"ts\",\"type\":\"long\"}," +
-                        "{\"name\":\"responseCode\",\"type\":\"int\"}," +
-                        "{\"name\":\"responseMessage\",\"type\":\"string\"}," +
-                        "{\"name\":\"message\",\"type\":\"string\"}," +
-                        "{\"name\":\"alert\",\"type\":\"string\"}," +
-                        "{\"name\":\"tcaMessageType\",\"type\":\"string\"}]}");
-        assertResponseHasErrors(testSimpleTCAPluginConfig, simpleTCAPluginConfigValidator);
-    }
-
-
-
-    private static void assertResponseHasErrors(final TestSimpleTCAPluginConfig pluginConfig,
-                                                final SimpleTCAPluginConfigValidator validator) {
-        final GenericValidationResponse validationResponse = validator.validateAppSettings(pluginConfig);
-        assertTrue(validationResponse.hasErrors());
-        LOG.debug("Validation Error Message: {}", validationResponse.getAllErrorMessage());
-    }
-}
+/*\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.cdap.plugins.validator;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.openecomp.dcae.apod.analytics.cdap.plugins.BaseAnalyticsCDAPPluginsUnitTest;\r
+import org.openecomp.dcae.apod.analytics.cdap.plugins.domain.config.tca.SimpleTCAPluginConfig;\r
+import org.openecomp.dcae.apod.analytics.cdap.plugins.domain.config.tca.TestSimpleTCAPluginConfig;\r
+import org.openecomp.dcae.apod.analytics.common.validation.GenericValidationResponse;\r
+\r
+import static org.junit.Assert.assertFalse;\r
+import static org.junit.Assert.assertTrue;\r
+\r
+/**\r
+ * @author Rajiv Singla . Creation Date: 2/21/2017.\r
+ */\r
+public class SimpleTCAPluginConfigValidatorTest extends BaseAnalyticsCDAPPluginsUnitTest {\r
+\r
+    private TestSimpleTCAPluginConfig testSimpleTCAPluginConfig;\r
+    private SimpleTCAPluginConfigValidator simpleTCAPluginConfigValidator;\r
+\r
+    @Before\r
+    public void before() {\r
+        testSimpleTCAPluginConfig = getTestSimpleTCAPluginConfig();\r
+        simpleTCAPluginConfigValidator = new SimpleTCAPluginConfigValidator();\r
+    }\r
+\r
+    @Test\r
+    public void testValidateAppSettingsWhenAllSettingsAreValid() throws Exception {\r
+        final GenericValidationResponse<SimpleTCAPluginConfig> validationResponse =\r
+                simpleTCAPluginConfigValidator.validateAppSettings(testSimpleTCAPluginConfig);\r
+        assertFalse(validationResponse.hasErrors());\r
+    }\r
+\r
+    @Test\r
+    public void testValidateAppSettingsWhenVESMessageFieldNameIsMissing() throws Exception {\r
+        testSimpleTCAPluginConfig.setVesMessageFieldName(null);\r
+        assertResponseHasErrors(testSimpleTCAPluginConfig, simpleTCAPluginConfigValidator);\r
+    }\r
+\r
+    @Test\r
+    public void testValidateAppSettingsWhenPolicyJsonIsMissing() throws Exception {\r
+        testSimpleTCAPluginConfig.setPolicyJson(null);\r
+        assertResponseHasErrors(testSimpleTCAPluginConfig, simpleTCAPluginConfigValidator);\r
+    }\r
+\r
+    @Test\r
+    public void testValidateAppSettingsWhenAlertFieldNameIsMissing() throws Exception {\r
+        testSimpleTCAPluginConfig.setAlertFieldName(null);\r
+        assertResponseHasErrors(testSimpleTCAPluginConfig, simpleTCAPluginConfigValidator);\r
+    }\r
+\r
+    @Test\r
+    public void testValidateAppSettingsWhenOutputSchemaIsNull() throws Exception {\r
+        testSimpleTCAPluginConfig.setSchema(null);\r
+        assertResponseHasErrors(testSimpleTCAPluginConfig, simpleTCAPluginConfigValidator);\r
+    }\r
+\r
+    @Test\r
+    public void testValidateAppSettingsWhenMessageTypeFieldNameIsMissing() throws Exception {\r
+        testSimpleTCAPluginConfig.setMessageTypeFieldName(null);\r
+        assertResponseHasErrors(testSimpleTCAPluginConfig, simpleTCAPluginConfigValidator);\r
+    }\r
+\r
+    @Test\r
+    public void testValidateAppSettingsWhenAlertFieldIsNullableInOutputSchema() throws Exception {\r
+        testSimpleTCAPluginConfig.setSchema(\r
+                "{\"type\":\"record\"," +\r
+                        "\"name\":\"etlSchemaBody\"," +\r
+                        "\"fields\":[" +\r
+                            "{\"name\":\"ts\",\"type\":\"long\"}," +\r
+                            "{\"name\":\"responseCode\",\"type\":\"int\"}," +\r
+                            "{\"name\":\"responseMessage\",\"type\":\"string\"}," +\r
+                            "{\"name\":\"message\",\"type\":\"string\"}," +\r
+                            "{\"name\":\"alert\",\"type\":[\"string\",\"null\"]}," +\r
+                            "{\"name\":\"tcaMessageType\",\"type\":\"string\"}]}");\r
+        final GenericValidationResponse<SimpleTCAPluginConfig> validationResponse =\r
+                simpleTCAPluginConfigValidator.validateAppSettings(testSimpleTCAPluginConfig);\r
+        assertFalse(validationResponse.hasErrors());\r
+\r
+    }\r
+\r
+    @Test\r
+    public void testValidateAppSettingsWhenAlertFieldIsNotPresentInOutputSchema() throws Exception {\r
+        testSimpleTCAPluginConfig.setSchema(\r
+                "{\"type\":\"record\"," +\r
+                        "\"name\":\"etlSchemaBody\"," +\r
+                        "\"fields\":[" +\r
+                        "{\"name\":\"ts\",\"type\":\"long\"}," +\r
+                        "{\"name\":\"responseCode\",\"type\":\"int\"}," +\r
+                        "{\"name\":\"responseMessage\",\"type\":\"string\"}," +\r
+                        "{\"name\":\"message\",\"type\":\"string\"}," +\r
+                        "{\"name\":\"tcaMessageType\",\"type\":\"string\"}]}");\r
+        final GenericValidationResponse<SimpleTCAPluginConfig> validationResponse =\r
+                simpleTCAPluginConfigValidator.validateAppSettings(testSimpleTCAPluginConfig);\r
+        assertFalse(validationResponse.hasErrors());\r
+\r
+    }\r
+\r
+    @Test\r
+    public void testValidateAppSettingsWhenAlertFieldIsNullableButNotStringTypeInOutputSchema() throws Exception {\r
+        testSimpleTCAPluginConfig.setSchema(\r
+                "{\"type\":\"record\"," +\r
+                        "\"name\":\"etlSchemaBody\"," +\r
+                        "\"fields\":[" +\r
+                        "{\"name\":\"ts\",\"type\":\"long\"}," +\r
+                        "{\"name\":\"responseCode\",\"type\":\"int\"}," +\r
+                        "{\"name\":\"responseMessage\",\"type\":\"string\"}," +\r
+                        "{\"name\":\"message\",\"type\":\"string\"}," +\r
+                        "{\"name\":\"alert\",\"type\":[\"int\",\"null\"]}," +\r
+                        "{\"name\":\"tcaMessageType\",\"type\":\"string\"}]}");\r
+        assertResponseHasErrors(testSimpleTCAPluginConfig, simpleTCAPluginConfigValidator);\r
+    }\r
+\r
+    @Test\r
+    public void testValidateAppSettingsWhenAlertFieldNameIsNotNullableInOutputSchema() throws Exception {\r
+        testSimpleTCAPluginConfig.setSchema(\r
+                "{\"type\":\"record\"," +\r
+                        "\"name\":\"etlSchemaBody\"," +\r
+                        "\"fields\":[" +\r
+                        "{\"name\":\"ts\",\"type\":\"long\"}," +\r
+                        "{\"name\":\"responseCode\",\"type\":\"int\"}," +\r
+                        "{\"name\":\"responseMessage\",\"type\":\"string\"}," +\r
+                        "{\"name\":\"message\",\"type\":\"string\"}," +\r
+                        "{\"name\":\"alert\",\"type\":\"string\"}," +\r
+                        "{\"name\":\"tcaMessageType\",\"type\":\"string\"}]}");\r
+        assertResponseHasErrors(testSimpleTCAPluginConfig, simpleTCAPluginConfigValidator);\r
+    }\r
+\r
+\r
+\r
+    private static void assertResponseHasErrors(final TestSimpleTCAPluginConfig pluginConfig,\r
+                                                final SimpleTCAPluginConfigValidator validator) {\r
+        final GenericValidationResponse validationResponse = validator.validateAppSettings(pluginConfig);\r
+        assertTrue(validationResponse.hasErrors());\r
+        LOG.debug("Validation Error Message: {}", validationResponse.getAllErrorMessage());\r
+    }\r
+}\r