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.plugins.validator;
\r
23 import org.junit.Before;
\r
24 import org.junit.Test;
\r
25 import org.openecomp.dcae.apod.analytics.cdap.plugins.BaseAnalyticsCDAPPluginsUnitTest;
\r
26 import org.openecomp.dcae.apod.analytics.cdap.plugins.domain.config.tca.SimpleTCAPluginConfig;
\r
27 import org.openecomp.dcae.apod.analytics.cdap.plugins.domain.config.tca.TestSimpleTCAPluginConfig;
\r
28 import org.openecomp.dcae.apod.analytics.common.validation.GenericValidationResponse;
\r
30 import static org.junit.Assert.assertFalse;
\r
31 import static org.junit.Assert.assertTrue;
\r
34 * @author Rajiv Singla . Creation Date: 2/21/2017.
\r
36 public class SimpleTCAPluginConfigValidatorTest extends BaseAnalyticsCDAPPluginsUnitTest {
\r
38 private TestSimpleTCAPluginConfig testSimpleTCAPluginConfig;
\r
39 private SimpleTCAPluginConfigValidator simpleTCAPluginConfigValidator;
\r
42 public void before() {
\r
43 testSimpleTCAPluginConfig = getTestSimpleTCAPluginConfig();
\r
44 simpleTCAPluginConfigValidator = new SimpleTCAPluginConfigValidator();
\r
48 public void testValidateAppSettingsWhenAllSettingsAreValid() throws Exception {
\r
49 final GenericValidationResponse<SimpleTCAPluginConfig> validationResponse =
\r
50 simpleTCAPluginConfigValidator.validateAppSettings(testSimpleTCAPluginConfig);
\r
51 assertFalse(validationResponse.hasErrors());
\r
55 public void testValidateAppSettingsWhenVESMessageFieldNameIsMissing() throws Exception {
\r
56 testSimpleTCAPluginConfig.setVesMessageFieldName(null);
\r
57 assertResponseHasErrors(testSimpleTCAPluginConfig, simpleTCAPluginConfigValidator);
\r
61 public void testValidateAppSettingsWhenPolicyJsonIsMissing() throws Exception {
\r
62 testSimpleTCAPluginConfig.setPolicyJson(null);
\r
63 assertResponseHasErrors(testSimpleTCAPluginConfig, simpleTCAPluginConfigValidator);
\r
67 public void testValidateAppSettingsWhenAlertFieldNameIsMissing() throws Exception {
\r
68 testSimpleTCAPluginConfig.setAlertFieldName(null);
\r
69 assertResponseHasErrors(testSimpleTCAPluginConfig, simpleTCAPluginConfigValidator);
\r
73 public void testValidateAppSettingsWhenOutputSchemaIsNull() throws Exception {
\r
74 testSimpleTCAPluginConfig.setSchema(null);
\r
75 assertResponseHasErrors(testSimpleTCAPluginConfig, simpleTCAPluginConfigValidator);
\r
79 public void testValidateAppSettingsWhenMessageTypeFieldNameIsMissing() throws Exception {
\r
80 testSimpleTCAPluginConfig.setMessageTypeFieldName(null);
\r
81 assertResponseHasErrors(testSimpleTCAPluginConfig, simpleTCAPluginConfigValidator);
\r
85 public void testValidateAppSettingsWhenAlertFieldIsNullableInOutputSchema() throws Exception {
\r
86 testSimpleTCAPluginConfig.setSchema(
\r
87 "{\"type\":\"record\"," +
\r
88 "\"name\":\"etlSchemaBody\"," +
\r
90 "{\"name\":\"ts\",\"type\":\"long\"}," +
\r
91 "{\"name\":\"responseCode\",\"type\":\"int\"}," +
\r
92 "{\"name\":\"responseMessage\",\"type\":\"string\"}," +
\r
93 "{\"name\":\"message\",\"type\":\"string\"}," +
\r
94 "{\"name\":\"alert\",\"type\":[\"string\",\"null\"]}," +
\r
95 "{\"name\":\"tcaMessageType\",\"type\":\"string\"}]}");
\r
96 final GenericValidationResponse<SimpleTCAPluginConfig> validationResponse =
\r
97 simpleTCAPluginConfigValidator.validateAppSettings(testSimpleTCAPluginConfig);
\r
98 assertFalse(validationResponse.hasErrors());
\r
103 public void testValidateAppSettingsWhenAlertFieldIsNotPresentInOutputSchema() throws Exception {
\r
104 testSimpleTCAPluginConfig.setSchema(
\r
105 "{\"type\":\"record\"," +
\r
106 "\"name\":\"etlSchemaBody\"," +
\r
108 "{\"name\":\"ts\",\"type\":\"long\"}," +
\r
109 "{\"name\":\"responseCode\",\"type\":\"int\"}," +
\r
110 "{\"name\":\"responseMessage\",\"type\":\"string\"}," +
\r
111 "{\"name\":\"message\",\"type\":\"string\"}," +
\r
112 "{\"name\":\"tcaMessageType\",\"type\":\"string\"}]}");
\r
113 final GenericValidationResponse<SimpleTCAPluginConfig> validationResponse =
\r
114 simpleTCAPluginConfigValidator.validateAppSettings(testSimpleTCAPluginConfig);
\r
115 assertFalse(validationResponse.hasErrors());
\r
120 public void testValidateAppSettingsWhenAlertFieldIsNullableButNotStringTypeInOutputSchema() throws Exception {
\r
121 testSimpleTCAPluginConfig.setSchema(
\r
122 "{\"type\":\"record\"," +
\r
123 "\"name\":\"etlSchemaBody\"," +
\r
125 "{\"name\":\"ts\",\"type\":\"long\"}," +
\r
126 "{\"name\":\"responseCode\",\"type\":\"int\"}," +
\r
127 "{\"name\":\"responseMessage\",\"type\":\"string\"}," +
\r
128 "{\"name\":\"message\",\"type\":\"string\"}," +
\r
129 "{\"name\":\"alert\",\"type\":[\"int\",\"null\"]}," +
\r
130 "{\"name\":\"tcaMessageType\",\"type\":\"string\"}]}");
\r
131 assertResponseHasErrors(testSimpleTCAPluginConfig, simpleTCAPluginConfigValidator);
\r
135 public void testValidateAppSettingsWhenAlertFieldNameIsNotNullableInOutputSchema() throws Exception {
\r
136 testSimpleTCAPluginConfig.setSchema(
\r
137 "{\"type\":\"record\"," +
\r
138 "\"name\":\"etlSchemaBody\"," +
\r
140 "{\"name\":\"ts\",\"type\":\"long\"}," +
\r
141 "{\"name\":\"responseCode\",\"type\":\"int\"}," +
\r
142 "{\"name\":\"responseMessage\",\"type\":\"string\"}," +
\r
143 "{\"name\":\"message\",\"type\":\"string\"}," +
\r
144 "{\"name\":\"alert\",\"type\":\"string\"}," +
\r
145 "{\"name\":\"tcaMessageType\",\"type\":\"string\"}]}");
\r
146 assertResponseHasErrors(testSimpleTCAPluginConfig, simpleTCAPluginConfigValidator);
\r
151 private static void assertResponseHasErrors(final TestSimpleTCAPluginConfig pluginConfig,
\r
152 final SimpleTCAPluginConfigValidator validator) {
\r
153 final GenericValidationResponse validationResponse = validator.validateAppSettings(pluginConfig);
\r
154 assertTrue(validationResponse.hasErrors());
\r
155 LOG.debug("Validation Error Message: {}", validationResponse.getAllErrorMessage());
\r