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.filter.JsonPathFilterPluginConfig;
27 import org.openecomp.dcae.apod.analytics.cdap.plugins.domain.config.filter.TestJsonPathFilterPluginConfig;
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: 3/3/2017.
36 public class JsonPathFilterPluginConfigValidatorTest extends BaseAnalyticsCDAPPluginsUnitTest {
38 private TestJsonPathFilterPluginConfig jsonPathFilterPluginConfig;
39 private JsonPathFilterPluginConfigValidator jsonPathFilterPluginConfigValidator;
42 public void before() {
43 jsonPathFilterPluginConfig = getJsonPathFilterPluginConfig();
44 jsonPathFilterPluginConfigValidator = new JsonPathFilterPluginConfigValidator();
49 public void testValidateAppSettingsWhenNoValidationErrors() throws Exception {
50 final GenericValidationResponse<JsonPathFilterPluginConfig> validationResponse =
51 jsonPathFilterPluginConfigValidator.validateAppSettings(jsonPathFilterPluginConfig);
52 assertFalse(validationResponse.hasErrors());
56 public void testValidateAppSettingsWhenFilterMappingsAreEmpty() throws Exception {
57 jsonPathFilterPluginConfig.setJsonFilterMappings("");
58 assertResponseHasErrors(jsonPathFilterPluginConfig, jsonPathFilterPluginConfigValidator);
62 public void testValidateAppSettingsWhenOutputSchemaIsNotPresent() throws Exception {
63 jsonPathFilterPluginConfig.setSchema(null);
64 assertResponseHasErrors(jsonPathFilterPluginConfig, jsonPathFilterPluginConfigValidator);
68 public void testValidateAppSettingsWhenOutputSchemaFilterMatchedFieldIsNotBoolean() throws Exception {
69 final String outputSchemaWithMatchedFieldNotBoolean =
70 "{\"type\":\"record\"," +
71 "\"name\":\"etlSchemaBody\",\"fields\":" +
73 "{\"name\":\"ts\",\"type\":\"long\"}," +
74 "{\"name\":\"filterMatched\",\"type\":[\"string\",\"null\"]}," +
75 "{\"name\":\"responseCode\",\"type\":\"int\"}," +
76 "{\"name\":\"responseMessage\",\"type\":\"string\"}," +
77 "{\"name\":\"message\",\"type\":\"string\"}" +
80 jsonPathFilterPluginConfig.setSchema(outputSchemaWithMatchedFieldNotBoolean);
81 assertResponseHasErrors(jsonPathFilterPluginConfig, jsonPathFilterPluginConfigValidator);
85 public void testValidateAppSettingsWhenOutputSchemaFilterMatchedFieldIsNotNullable() throws Exception {
86 final String outputSchemaWithMatchedFieldNotNullable =
87 "{\"type\":\"record\"," +
88 "\"name\":\"etlSchemaBody\",\"fields\":" +
90 "{\"name\":\"ts\",\"type\":\"long\"}," +
91 "{\"name\":\"filterMatched\",\"type\":\"boolean\"}," +
92 "{\"name\":\"responseCode\",\"type\":\"int\"}," +
93 "{\"name\":\"responseMessage\",\"type\":\"string\"}," +
94 "{\"name\":\"message\",\"type\":\"string\"}" +
97 jsonPathFilterPluginConfig.setSchema(outputSchemaWithMatchedFieldNotNullable);
98 assertResponseHasErrors(jsonPathFilterPluginConfig, jsonPathFilterPluginConfigValidator);
101 private static void assertResponseHasErrors(final TestJsonPathFilterPluginConfig jsonPluginConfig,
102 final JsonPathFilterPluginConfigValidator validator) {
103 final GenericValidationResponse validationResponse = validator.validateAppSettings(jsonPluginConfig);
104 assertTrue(validationResponse.hasErrors());