|
15 | 15 | */
|
16 | 16 | package org.springframework.data.mongodb.core.aggregation;
|
17 | 17 |
|
18 |
| -import static org.assertj.core.api.Assertions.*; |
19 |
| -import static org.mockito.Mockito.*; |
| 18 | +import static org.assertj.core.api.Assertions.assertThat; |
| 19 | +import static org.mockito.Mockito.eq; |
| 20 | +import static org.mockito.Mockito.mock; |
| 21 | +import static org.mockito.Mockito.verify; |
| 22 | +import static org.mockito.Mockito.when; |
| 23 | +import static org.springframework.data.domain.Sort.Direction.DESC; |
| 24 | +import static org.springframework.data.mongodb.core.aggregation.Aggregation.project; |
| 25 | +import static org.springframework.data.mongodb.core.aggregation.Aggregation.sort; |
20 | 26 |
|
21 | 27 | import java.util.List;
|
22 | 28 |
|
23 | 29 | import org.assertj.core.api.InstanceOfAssertFactories;
|
24 | 30 | import org.junit.jupiter.api.Test;
|
25 | 31 | import org.mockito.ArgumentCaptor;
|
| 32 | +import org.springframework.data.annotation.Id; |
26 | 33 | import org.springframework.data.mongodb.core.aggregation.FieldsExposingAggregationOperation.InheritsFieldsAggregationOperation;
|
| 34 | +import org.springframework.data.mongodb.core.convert.MappingMongoConverter; |
| 35 | +import org.springframework.data.mongodb.core.convert.NoOpDbRefResolver; |
| 36 | +import org.springframework.data.mongodb.core.convert.QueryMapper; |
| 37 | +import org.springframework.data.mongodb.test.util.MongoTestMappingContext; |
27 | 38 |
|
28 | 39 | /**
|
29 | 40 | * @author Christoph Strobl
|
@@ -115,4 +126,34 @@ void inheritingFieldsExposingAggregationOperationForcesNewContextForNextStageKee
|
115 | 126 | .extracting("previousContext").isSameAs(captor.getAllValues().get(1));
|
116 | 127 | }
|
117 | 128 |
|
| 129 | + |
| 130 | + |
| 131 | + record TestRecord(@Id String field1, String field2, LayerOne layerOne) { |
| 132 | + record LayerOne(List<LayerTwo> layerTwo) { |
| 133 | + } |
| 134 | + |
| 135 | + record LayerTwo(LayerThree layerThree) { |
| 136 | + } |
| 137 | + |
| 138 | + record LayerThree(int fieldA, int fieldB) |
| 139 | + {} |
| 140 | + } |
| 141 | + |
| 142 | + @Test |
| 143 | + void xxx() { |
| 144 | + |
| 145 | + MongoTestMappingContext ctx = new MongoTestMappingContext(cfg -> { |
| 146 | + cfg.initialEntitySet(TestRecord.class); |
| 147 | + }); |
| 148 | + |
| 149 | + MappingMongoConverter mongoConverter = new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, ctx); |
| 150 | + |
| 151 | + Aggregation agg = Aggregation.newAggregation( |
| 152 | + Aggregation.unwind("layerOne.layerTwo"), |
| 153 | + project().and("layerOne.layerTwo.layerThree").as("layerOne.layerThree"), |
| 154 | + sort(DESC, "layerOne.layerThree.fieldA") |
| 155 | + ); |
| 156 | + |
| 157 | + AggregationOperationRenderer.toDocument(agg.getPipeline().getOperations(), new RelaxedTypeBasedAggregationOperationContext(TestRecord.class, ctx, new QueryMapper(mongoConverter))); |
| 158 | + } |
118 | 159 | }
|
0 commit comments