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