dan-s1 commented on code in PR #9379:
URL: https://github.com/apache/nifi/pull/9379#discussion_r1799834038
##########
nifi-extension-bundles/nifi-poi-bundle/nifi-poi-services/src/test/java/org/apache/nifi/excel/TestExcelSchemaInference.java:
##########
@@ -50,69 +45,54 @@ public class TestExcelSchemaInference {
private static final String EXPECTED_SECOND_FIELD_NAME =
ExcelUtils.FIELD_NAME_PREFIX + "1";
private static final String EXPECTED_THIRD_FIELD_NAME =
ExcelUtils.FIELD_NAME_PREFIX + "2";
private static final String EXPECTED_FOURTH_FIELD_NAME =
ExcelUtils.FIELD_NAME_PREFIX + "3";
+
+ private static final String SIMPLE_FORMATTING_PATH =
"/excel/simpleDataFormatting.xlsx";
+
private final TimeValueInference timestampInference = new
TimeValueInference("MM/dd/yyyy", "HH:mm:ss.SSS", "yyyy/MM/dd/ HH:mm");
@Mock
ComponentLog logger;
- @ParameterizedTest
- @MethodSource("getLocales")
- public void testInferenceAgainstDifferentLocales(Locale locale) throws
IOException {
- final Map<PropertyDescriptor, String> properties = new HashMap<>();
- new ExcelReader().getSupportedPropertyDescriptors().forEach(prop ->
properties.put(prop, prop.getDefaultValue()));
- final PropertyContext context = new
MockConfigurationContext(properties, null, null);
-
- try (final InputStream inputStream =
getResourceStream("/excel/numbers.xlsx")) {
- final InferSchemaAccessStrategy<?> accessStrategy = new
InferSchemaAccessStrategy<>(
- (variables, content) -> new ExcelRecordSource(content,
context, variables, logger),
- new ExcelSchemaInference(timestampInference, locale),
logger);
- final RecordSchema schema = accessStrategy.getSchema(null,
inputStream, null);
- final List<String> fieldNames = schema.getFieldNames();
- assertEquals(Collections.singletonList(EXPECTED_FIRST_FIELD_NAME),
fieldNames);
-
- if (Locale.FRENCH.equals(locale)) {
- assertEquals(RecordFieldType.STRING,
schema.getDataType(EXPECTED_FIRST_FIELD_NAME).get().getFieldType());
- } else {
-
assertEquals(RecordFieldType.CHOICE.getChoiceDataType(RecordFieldType.FLOAT.getDataType(),
RecordFieldType.STRING.getDataType()),
- schema.getDataType(EXPECTED_FIRST_FIELD_NAME).get());
- }
- }
- }
-
- private static Stream<Arguments> getLocales() {
- Locale hindi = Locale.of("hin");
- return Stream.of(
- Arguments.of(Locale.ENGLISH),
- Arguments.of(hindi),
- Arguments.of(Locale.JAPANESE),
- Arguments.of(Locale.FRENCH)
- );
- }
-
@Test
public void testInferenceIncludesAllRecords() throws IOException {
final Map<PropertyDescriptor, String> properties = new HashMap<>();
new ExcelReader().getSupportedPropertyDescriptors().forEach(prop ->
properties.put(prop, prop.getDefaultValue()));
final PropertyContext context = new
MockConfigurationContext(properties, null, null);
final RecordSchema schema;
- try (final InputStream inputStream =
getResourceStream("/excel/simpleDataFormatting.xlsx")) {
+ try (final InputStream inputStream = getResourceStream()) {
final InferSchemaAccessStrategy<?> accessStrategy = new
InferSchemaAccessStrategy<>(
(variables, content) -> new ExcelRecordSource(content,
context, variables, logger),
new ExcelSchemaInference(timestampInference),
Mockito.mock(ComponentLog.class));
schema = accessStrategy.getSchema(null, inputStream, null);
}
- final List<String> fieldNames = schema.getFieldNames();
- assertEquals(Arrays.asList(EXPECTED_FIRST_FIELD_NAME,
EXPECTED_SECOND_FIELD_NAME,
- EXPECTED_THIRD_FIELD_NAME, EXPECTED_FOURTH_FIELD_NAME),
fieldNames);
-
assertEquals(RecordFieldType.CHOICE.getChoiceDataType(RecordFieldType.INT.getDataType(),
- RecordFieldType.STRING.getDataType()),
schema.getDataType(EXPECTED_FIRST_FIELD_NAME).get());
-
assertEquals(RecordFieldType.CHOICE.getChoiceDataType(RecordFieldType.TIMESTAMP.getDataType("yyyy/MM/dd/
HH:mm"), RecordFieldType.STRING.getDataType()),
- schema.getDataType(EXPECTED_SECOND_FIELD_NAME).get());
- assertEquals(RecordFieldType.STRING,
schema.getDataType(EXPECTED_THIRD_FIELD_NAME).get().getFieldType());
-
assertEquals(RecordFieldType.CHOICE.getChoiceDataType(RecordFieldType.BOOLEAN.getDataType(),
- RecordFieldType.STRING.getDataType()),
schema.getDataType(EXPECTED_FOURTH_FIELD_NAME).get());
+ assertFieldNamesFound(schema);
+ assertFieldDataTypeEquals(schema, EXPECTED_FIRST_FIELD_NAME,
+ RecordFieldType.CHOICE.getChoiceDataType(
+ RecordFieldType.LONG.getDataType(),
+ RecordFieldType.STRING.getDataType()
+ )
+ );
+ assertFieldDataTypeEquals(schema, EXPECTED_SECOND_FIELD_NAME,
+ RecordFieldType.CHOICE.getChoiceDataType(
+ // Assert Timestamp Data Type with standard Date and
Time Pattern
Review Comment:
As I mentioned previously, this unit test is not exercising this as we could
mock the `TimeValueInference` and not have any patterns.
--
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]