exceptionfactory commented on a change in pull request #5530: URL: https://github.com/apache/nifi/pull/5530#discussion_r791996926
########## File path: nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/cef/CEFSchemaUtil.java ########## @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +package org.apache.nifi.cef; + +import org.apache.nifi.serialization.record.DataType; +import org.apache.nifi.serialization.record.RecordField; +import org.apache.nifi.serialization.record.RecordFieldType; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +final class CEFSchemaUtil { + + private static final List<RecordField> HEADER_FIELDS = new ArrayList<>(); + + static { + // Reference states that severity might be represented by integer values (0-10) and string values (like High) too + HEADER_FIELDS.add(new RecordField("version", RecordFieldType.INT.getDataType())); + HEADER_FIELDS.add(new RecordField("deviceVendor", RecordFieldType.STRING.getDataType())); + HEADER_FIELDS.add(new RecordField("deviceProduct", RecordFieldType.STRING.getDataType())); + HEADER_FIELDS.add(new RecordField("deviceVersion", RecordFieldType.STRING.getDataType())); + HEADER_FIELDS.add(new RecordField("deviceEventClassId", RecordFieldType.STRING.getDataType())); + HEADER_FIELDS.add(new RecordField("name", RecordFieldType.STRING.getDataType())); + HEADER_FIELDS.add(new RecordField("severity", RecordFieldType.STRING.getDataType())); + } + + // Fields known by the CEF Extension Dictionary in version 23 + private static final Set<String> EXTENSIONS_STRING = new HashSet<>(Arrays.asList("act", "app", "c6a1Label", "c6a2Label", "c6a3Label", Review comment: It would be very helpful to declare these values one per line, ideally alphabetized. Although it would take some effort, it would make it much easier to maintain. On the other hand, would it be better to make String the default fallback type and avoid having to declare all of these fields? ########## File path: nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/cef/ValidateLocale.java ########## @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +package org.apache.nifi.cef; + +import org.apache.nifi.components.ValidationContext; +import org.apache.nifi.components.ValidationResult; +import org.apache.nifi.components.Validator; + +import java.util.Locale; + +/** + * This class is identical to {@code org.apache.nifi.processors.standard.ParseCEF.ValidateLocale}. Review comment: In light of this comment, did you consider creating a new module under `nifi-commons` to avoid duplicating this Validator class? ########## File path: nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/cef/TestCEFReader.java ########## @@ -0,0 +1,376 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +package org.apache.nifi.cef; + +import org.apache.nifi.components.AllowableValue; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.flowfile.FlowFile; +import org.apache.nifi.processor.AbstractProcessor; +import org.apache.nifi.processor.ProcessContext; +import org.apache.nifi.processor.ProcessSession; +import org.apache.nifi.processor.Relationship; +import org.apache.nifi.processor.exception.ProcessException; +import org.apache.nifi.reporting.InitializationException; +import org.apache.nifi.schema.access.SchemaAccessUtils; +import org.apache.nifi.schema.inference.SchemaInferenceUtil; +import org.apache.nifi.serialization.RecordReader; +import org.apache.nifi.serialization.RecordReaderFactory; +import org.apache.nifi.serialization.SimpleRecordSchema; +import org.apache.nifi.serialization.record.MockSchemaRegistry; +import org.apache.nifi.serialization.record.Record; +import org.apache.nifi.serialization.record.RecordField; +import org.apache.nifi.util.TestRunner; +import org.apache.nifi.util.TestRunners; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class TestCEFReader { + private TestRunner runner; + private TestCEFProcessor processor; + private CEFReader reader; + + @Before + public void setUp() { + runner = null; + processor = null; + reader = null; + } + + @Test + public void testValidatingReaderWhenRawFieldValueIsInvalid() throws Exception { + // given + givenReaderSetUp(); + givenRawFieldIs("dst"); // Invalid because there is an extension with the same name + givenSchemaIsInferred(CEFReader.HEADERS_ONLY); + + // when & then + thenAssertInvalid(); Review comment: The method naming does not follow the usual test code conventions. Although the quality and style of current tests varies widely, we should avoid introducing more `given / when / then` comments and method names. Having reusable test methods for setup and higher level assertions is helpful, but the names should avoid the behavior-driven naming. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@nifi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org