Lehel44 commented on code in PR #7644:
URL: https://github.com/apache/nifi/pull/7644#discussion_r1308044680


##########
nifi-nar-bundles/nifi-zendesk-bundle/nifi-zendesk-processors/src/test/java/org/apache/nifi/commons/zendesk/ZendeskRecordPathUtilsTest.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.commons.zendesk;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.serialization.SimpleRecordSchema;
+import org.apache.nifi.serialization.record.MapRecord;
+import org.apache.nifi.serialization.record.Record;
+import org.apache.nifi.serialization.record.RecordField;
+import org.apache.nifi.serialization.record.RecordFieldType;
+import org.apache.nifi.serialization.record.RecordSchema;
+import org.apache.nifi.serialization.record.type.ArrayDataType;
+import org.apache.nifi.serialization.record.type.RecordDataType;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static 
org.apache.nifi.commons.zendesk.ZendeskRecordPathUtils.resolveFieldValue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class ZendeskRecordPathUtilsTest {
+
+    private final ObjectMapper mapper = new ObjectMapper();
+
+    @Test
+    public void testFieldValueEvaluation() {
+        ObjectNode testNode;
+        Record record = initRecord();
+
+        testNode = mapper.createObjectNode();
+        resolveFieldValue("/a/b", "%{/field1}", testNode, record);
+        assertEquals("{\"a\":{\"b\":\"value1\"}}", testNode.toString());
+
+        testNode = mapper.createObjectNode();
+        resolveFieldValue("/a/b/c", "constant", testNode, record);
+        assertEquals("{\"a\":{\"b\":{\"c\":\"constant\"}}}", 
testNode.toString());
+
+        ProcessException e1 = assertThrows(ProcessException.class, () -> 
resolveFieldValue("/a", "%{/field2}", mapper.createObjectNode(), record));
+        assertEquals(e1.getMessage(), "The provided RecordPath [/field2] 
points to a [ARRAY] type value");
+
+        ProcessException e2 = assertThrows(ProcessException.class, () -> 
resolveFieldValue("/a", "%{/field3}", mapper.createObjectNode(), record));
+        assertEquals(e2.getMessage(), "The provided RecordPath [/field3] 
points to a [RECORD] type value");
+
+        ProcessException e3 = assertThrows(ProcessException.class, () -> 
resolveFieldValue("/a", "%{/field4}", mapper.createObjectNode(), record));
+        assertEquals(e3.getMessage(), "The provided RecordPath [/field4] 
points to a [CHOICE] type value with Record subtype");
+    }
+
+    private Record initRecord() {

Review Comment:
   Minor: Most of these values can be extracted into a static block.



-- 
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

Reply via email to