Skip to content

Commit d50e312

Browse files
committed
another test
1 parent 539fcdf commit d50e312

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

src/test/java/org/folio/fqm/service/ResultSetServiceTest.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,55 @@ void shouldApplyDefaultValuesToNestedFields() {
253253
assertEquals(1, nonDefaultCount, "Should have exactly one element with non-default value");
254254
}
255255

256+
@Test
257+
void shouldSkipDefaultValuesForNonObjectArrayElements() {
258+
UUID entityTypeId = UUID.randomUUID();
259+
UUID contentId = UUID.randomUUID();
260+
String nestedFieldJson = """
261+
["not-an-object", 123, null]
262+
""";
263+
264+
EntityTypeColumn nestedColumn = new EntityTypeColumn()
265+
.name("field")
266+
.dataType(
267+
new ArrayType().itemDataType(
268+
new ObjectType().properties(List.of(
269+
new NestedObjectProperty()
270+
.name("nested_with_default")
271+
.property("nestedWithDefault")
272+
.defaultValue("default")
273+
))
274+
)
275+
);
276+
277+
EntityType entityType = new EntityType()
278+
.id(entityTypeId.toString())
279+
.columns(List.of(
280+
new EntityTypeColumn().name("id").isIdColumn(true),
281+
nestedColumn
282+
));
283+
284+
List<String> fields = List.of("id", "field");
285+
List<String> tenantIds = List.of("tenant_01");
286+
List<List<String>> listIds = List.of(List.of(contentId.toString()));
287+
288+
when(entityTypeFlatteningService.getFlattenedEntityType(entityTypeId, null, true)).thenReturn(entityType);
289+
when(entityTypeFlatteningService.getFlattenedEntityType(entityTypeId, "tenant_01", true)).thenReturn(entityType);
290+
when(resultSetRepository.getResultSet(entityTypeId, fields, listIds, tenantIds))
291+
.thenReturn(List.of(Map.of("id", contentId.toString(), "field", nestedFieldJson)));
292+
293+
List<Map<String, Object>> actual = service.getResultSet(entityTypeId, fields, listIds, tenantIds, false);
294+
String actualJson = (String) actual.getFirst().get("field");
295+
296+
// The array should remain unchanged since none of the elements are objects
297+
// Verify all original elements are still present
298+
assertEquals(true, actualJson.contains("\"not-an-object\""));
299+
assertEquals(true, actualJson.contains("123"));
300+
assertEquals(true, actualJson.contains("null"));
301+
// Verify no default values were added
302+
assertEquals(false, actualJson.contains("nestedWithDefault"));
303+
}
304+
256305
static List<Arguments> dateLocalizationTestCases() {
257306
return List.of(
258307
// (tz, date string, timestamp, offset date string, expected)

0 commit comments

Comments
 (0)