bamaer commented on code in PR #9450: URL: https://github.com/apache/hop/pull/9450#discussion_r4555333696
########## plugins/transforms/json/src/test/java/org/apache/hop/pipeline/transforms/jsoninput/reader/RowOutputConverterNumberTest.java: ########## @@ -0,0 +1,230 @@ +/* + * 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.hop.pipeline.transforms.jsoninput.reader; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.fasterxml.jackson.databind.node.BigIntegerNode; +import com.fasterxml.jackson.databind.node.DecimalNode; +import com.fasterxml.jackson.databind.node.DoubleNode; +import com.fasterxml.jackson.databind.node.FloatNode; +import com.fasterxml.jackson.databind.node.IntNode; +import com.fasterxml.jackson.databind.node.LongNode; +import com.fasterxml.jackson.databind.node.TextNode; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.BitSet; +import java.util.List; +import org.apache.hop.core.HopEnvironment; +import org.apache.hop.core.exception.HopException; +import org.apache.hop.core.logging.ILogChannel; +import org.apache.hop.core.row.IValueMeta; +import org.apache.hop.core.row.RowMeta; +import org.apache.hop.core.row.value.ValueMetaFactory; +import org.apache.hop.pipeline.transforms.jsoninput.JsonInputData; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * A JSON number is a number: it goes into a numeric field as the value it is, whatever the format + * and the symbols of the field are. Those are for showing the field and for parsing a JSON string. + * The value has to be what parsing the number's text with a dot as decimal symbol gives, and the + * debug message of the failed cast tells whether a value took the old route. + */ +class RowOutputConverterNumberTest { + + @BeforeAll + static void initHop() throws HopException { + HopEnvironment.init(); Review Comment: **Blocker:** this fails with "Unable to locate value meta plugin of type (id) 6" when `JsonInputMetaTest` runs first in the same JVM. That test registers only String, Integer, Date, Number and Json, and `HopEnvironment.init()` does not add BigNumber afterwards. Surefire runs classes in filesystem order, so CI passes but a local `./mvnw install` can fail. Registering the types this test uses fixes it, after `HopEnvironment.init()`: ```java PluginRegistry registry = PluginRegistry.getInstance(); for (Class<?> c : List.of(ValueMetaString.class, ValueMetaInteger.class, ValueMetaNumber.class, ValueMetaBigNumber.class)) { registry.registerPluginClass(c.getName(), ValueMetaPluginType.class, ValueMetaPlugin.class); } ``` With that, `-Dtest=JsonInputMetaTest,RowOutputConverterNumberTest` passes 9/9. ########## plugins/transforms/json/src/main/java/org/apache/hop/pipeline/transforms/jsonnormalize/JsonNormalizeInput.java: ########## @@ -154,7 +154,11 @@ protected void prepareToRowProcessing(boolean errorIgnored) data.inputRowMeta = getInputRowMeta(); if (!meta.isInFields() && data.inputRowMeta == null) { data.outputRowMeta = new RowMeta(); - if (!meta.isDoNotFailIfNoFile() && (data.files == null || data.files.nrOfFiles() == 0)) { + if (data.files == null) { Review Comment: **Should fix:** #9448 asks for an integration test with "Do not fail if no file" off. `integration-tests/json/0008`–`0011` all have it on, which is what hid this bug. Setting `<doNotFailIfNoFile>N</doNotFailIfNoFile>` in `0009-json-normalize-root-array.hpl` covers it. I tried it: on main `main-0009` fails with "No file(s) specified! Stop processing.", and with this PR it passes. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
