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