|
1 | 1 | package io.hyperfoil.tools.h5m.svc; |
2 | 2 |
|
| 3 | +import com.fasterxml.jackson.core.JsonProcessingException; |
3 | 4 | import com.fasterxml.jackson.databind.JsonNode; |
4 | 5 | import com.fasterxml.jackson.databind.ObjectMapper; |
5 | 6 | import com.fasterxml.jackson.databind.node.DoubleNode; |
|
21 | 22 | import java.io.IOException; |
22 | 23 | import java.nio.file.Files; |
23 | 24 | import java.util.*; |
| 25 | +import java.util.stream.Collectors; |
24 | 26 | import java.util.stream.Stream; |
25 | 27 |
|
26 | 28 | import static io.hyperfoil.tools.h5m.entity.NodeEntity.FQDN_SEPARATOR; |
@@ -582,6 +584,54 @@ public void calculateJqValues_multiple_sourceValues() throws IOException, Heuris |
582 | 584 | assertTrue(read.startsWith("["),"value should be an array: "+read); |
583 | 585 | assertTrue(read.endsWith("]"),"value should be an array: "+read); |
584 | 586 | } |
| 587 | + @Test |
| 588 | + public void calculateSourceValuePermutations_returns_non_null_on_length_mismatch() throws SystemException, NotSupportedException, HeuristicRollbackException, HeuristicMixedException, RollbackException, JsonProcessingException { |
| 589 | + tm.begin(); |
| 590 | + NodeEntity root = new RootNode(); |
| 591 | + root.persist(); |
| 592 | + |
| 593 | + // Create two source nodes that will produce different numbers of values |
| 594 | + NodeEntity firstNode = new JqNode("first","$.first[]",root); |
| 595 | + firstNode.persist(); |
| 596 | + NodeEntity secondNode = new JqNode("second","$.second[]",root); |
| 597 | + secondNode.persist(); |
| 598 | + |
| 599 | + // Create a combined node with Length multiType (default) and two sources |
| 600 | + NodeEntity combined = new JsNode("combined","obj=>Object.values(obj)", List.of(firstNode, secondNode)); |
| 601 | + combined.multiType = NodeEntity.MultiIterationType.Length; // Explicitly set to Length |
| 602 | + combined.persist(); |
| 603 | + |
| 604 | + // Root value with arrays of different lengths |
| 605 | + ValueEntity rootValue = new ValueEntity(null, root, new ObjectMapper().readTree(""" |
| 606 | + { |
| 607 | + "first": [1, 2, 3] |
| 608 | + } |
| 609 | + """)); |
| 610 | + rootValue.persist(); |
| 611 | + |
| 612 | + // First node produces 3 values |
| 613 | + ValueEntity firstValue1 = new ValueEntity(null, firstNode, new ObjectMapper().readTree("1")); |
| 614 | + firstValue1.idx=1; |
| 615 | + firstValue1.sources=List.of(rootValue); |
| 616 | + firstValue1.persist(); |
| 617 | + ValueEntity firstValue2 = new ValueEntity(null, firstNode, new ObjectMapper().readTree("2")); |
| 618 | + firstValue2.idx=2; |
| 619 | + firstValue2.sources=List.of(rootValue); |
| 620 | + firstValue2.persist(); |
| 621 | + ValueEntity firstValue3 = new ValueEntity(null, firstNode, new ObjectMapper().readTree("3")); |
| 622 | + firstValue3.idx=3; |
| 623 | + firstValue3.sources=List.of(rootValue); |
| 624 | + firstValue3.persist(); |
| 625 | + |
| 626 | + tm.commit(); |
| 627 | + |
| 628 | + // When multiType is Length and source nodes have mismatched value counts, |
| 629 | + // calculateSourceValuePermutations should return null |
| 630 | + List<Map<String, ValueEntity>> result = nodeService.calculateSourceValuePermutations(combined, rootValue); |
| 631 | + |
| 632 | + assertNotNull(result, "Expected not-null when Length multiType has mismatched source value counts:"); |
| 633 | + } |
| 634 | + |
585 | 635 | @Test |
586 | 636 | public void calculateJqValues_multiple_source_order() throws IOException, HeuristicRollbackException, SystemException, HeuristicMixedException, RollbackException, NotSupportedException { |
587 | 637 | tm.begin(); |
|
0 commit comments