|
1 | 1 | /*
|
2 |
| - * Copyright 2021 Fabian Steeg, hbz |
| 2 | + * Copyright 2021, 2023 Fabian Steeg, hbz |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 the "License";
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 | 16 |
|
17 |
| -package org.metafacture.metafix; |
| 17 | +package org.metafacture.metafix; // checkstyle-disable-line JavaNCSS |
18 | 18 |
|
19 | 19 | import org.metafacture.framework.StreamReceiver;
|
20 | 20 | import org.metafacture.metamorph.api.MorphBuildException;
|
@@ -2721,6 +2721,138 @@ public void dontEmitEntityForSingleField() {
|
2721 | 2721 | );
|
2722 | 2722 | }
|
2723 | 2723 |
|
| 2724 | + @Test |
| 2725 | + public void setRepeatedFieldsToEntitiesAndSetEntityMemberName() { |
| 2726 | + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( |
| 2727 | + "nothing()" |
| 2728 | + ), |
| 2729 | + i -> { |
| 2730 | + i.setRepeatedFieldsToEntities(true); |
| 2731 | + i.setEntityMemberName("*"); |
| 2732 | + |
| 2733 | + i.startRecord("1"); |
| 2734 | + i.literal("name", "max"); |
| 2735 | + i.literal("name", "mo"); |
| 2736 | + i.endRecord(); |
| 2737 | + }, |
| 2738 | + o -> { |
| 2739 | + o.get().startRecord("1"); |
| 2740 | + o.get().startEntity("name"); |
| 2741 | + o.get().literal("*", "max"); |
| 2742 | + o.get().literal("*", "mo"); |
| 2743 | + o.get().endEntity(); |
| 2744 | + o.get().endRecord(); |
| 2745 | + } |
| 2746 | + ); |
| 2747 | + } |
| 2748 | + |
| 2749 | + @Test |
| 2750 | + public void setRepeatedFieldsToEntitiesAndSetEntityMemberNameWithNumericalSubfield() { |
| 2751 | + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( |
| 2752 | + "nothing()" |
| 2753 | + ), |
| 2754 | + i -> { |
| 2755 | + i.setRepeatedFieldsToEntities(true); |
| 2756 | + i.setEntityMemberName("*"); |
| 2757 | + |
| 2758 | + i.startRecord("1"); |
| 2759 | + i.startEntity("1001 "); |
| 2760 | + i.literal("1", "max"); |
| 2761 | + i.literal("1", "mo"); |
| 2762 | + i.endEntity(); |
| 2763 | + i.endRecord(); |
| 2764 | + }, |
| 2765 | + (o, f) -> { |
| 2766 | + o.get().startRecord("1"); |
| 2767 | + o.get().startEntity("1001 "); |
| 2768 | + o.get().startEntity("1"); |
| 2769 | + o.get().literal("*", "max"); |
| 2770 | + o.get().literal("*", "mo"); |
| 2771 | + f.apply(2).endEntity(); |
| 2772 | + o.get().endRecord(); |
| 2773 | + } |
| 2774 | + ); |
| 2775 | + } |
| 2776 | + |
| 2777 | + @Test |
| 2778 | + public void setRepeatedFieldsToEntitiesWithNumericalSubfields() { |
| 2779 | + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( |
| 2780 | + "nothing()" |
| 2781 | + ), |
| 2782 | + i -> { |
| 2783 | + i.setRepeatedFieldsToEntities(true); |
| 2784 | + |
| 2785 | + i.startRecord("1"); |
| 2786 | + i.startEntity("1001 "); |
| 2787 | + i.literal("1", "max"); |
| 2788 | + i.literal("1", "mo"); |
| 2789 | + i.endEntity(); |
| 2790 | + i.endRecord(); |
| 2791 | + }, |
| 2792 | + (o, f) -> { |
| 2793 | + o.get().startRecord("1"); |
| 2794 | + o.get().startEntity("1001 "); |
| 2795 | + o.get().startEntity("1"); |
| 2796 | + o.get().literal("1", "max"); |
| 2797 | + o.get().literal("2", "mo"); |
| 2798 | + f.apply(2).endEntity(); |
| 2799 | + o.get().endRecord(); |
| 2800 | + } |
| 2801 | + ); |
| 2802 | + } |
| 2803 | + |
| 2804 | + @Test |
| 2805 | + public void setEntityMemberNameNoArrayMarkerOrEntity() { |
| 2806 | + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( |
| 2807 | + "nothing()" |
| 2808 | + ), |
| 2809 | + i -> { |
| 2810 | + i.setEntityMemberName("*"); // no arrays or entities, no effect |
| 2811 | + |
| 2812 | + i.startRecord("1"); |
| 2813 | + i.startEntity("1001 "); |
| 2814 | + i.literal("1", "max"); |
| 2815 | + i.literal("1", "mo"); |
| 2816 | + i.endEntity(); |
| 2817 | + i.endRecord(); |
| 2818 | + }, |
| 2819 | + o -> { |
| 2820 | + o.get().startRecord("1"); |
| 2821 | + o.get().startEntity("1001 "); |
| 2822 | + o.get().literal("1", "max"); |
| 2823 | + o.get().literal("1", "mo"); |
| 2824 | + o.get().endEntity(); |
| 2825 | + o.get().endRecord(); |
| 2826 | + } |
| 2827 | + ); |
| 2828 | + } |
| 2829 | + |
| 2830 | + @Test |
| 2831 | + public void setEntityMemberNameWithArrayMarker() { |
| 2832 | + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( |
| 2833 | + "nothing()" |
| 2834 | + ), |
| 2835 | + i -> { |
| 2836 | + i.setEntityMemberName("*"); |
| 2837 | + |
| 2838 | + i.startRecord("1"); |
| 2839 | + i.startEntity("1001 []"); |
| 2840 | + i.literal("1", "max"); |
| 2841 | + i.literal("1", "mo"); |
| 2842 | + i.endEntity(); |
| 2843 | + i.endRecord(); |
| 2844 | + }, |
| 2845 | + o -> { |
| 2846 | + o.get().startRecord("1"); |
| 2847 | + o.get().startEntity("1001 []"); |
| 2848 | + o.get().literal("*", "max"); |
| 2849 | + o.get().literal("*", "mo"); |
| 2850 | + o.get().endEntity(); |
| 2851 | + o.get().endRecord(); |
| 2852 | + } |
| 2853 | + ); |
| 2854 | + } |
| 2855 | + |
2724 | 2856 | public void shouldNotAccessArrayImplicitly() {
|
2725 | 2857 | MetafixTestHelpers.assertExecutionException(IllegalStateException.class, "Expected String, got Array", () ->
|
2726 | 2858 | MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
|
|
0 commit comments