|
24 | 24 | import org.springframework.data.mongodb.core.Person;
|
25 | 25 | import org.springframework.data.mongodb.core.query.Criteria;
|
26 | 26 |
|
27 |
| -import com.mongodb.BasicDBObject; |
28 |
| -import com.mongodb.DBObject; |
29 |
| -import com.mongodb.util.JSON; |
30 |
| - |
31 | 27 | /**
|
32 | 28 | * Unit tests for {@link GraphLookupOperation}.
|
33 | 29 | *
|
@@ -104,8 +100,9 @@ public void shouldRenderMixedArrayOfStartsWithCorrectly() {
|
104 | 100 | Document document = graphLookupOperation.toDocument(Aggregation.DEFAULT_CONTEXT);
|
105 | 101 |
|
106 | 102 | assertThat(document,
|
107 |
| - is(Document.parse("{ $graphLookup : { from: \"employees\", startWith: [\"$reportsTo\", { $literal: \"$boss\"}], " |
108 |
| - + "connectFromField: \"reportsTo\", connectToField: \"name\", as: \"reportingHierarchy\" } }"))); |
| 103 | + is(Document |
| 104 | + .parse("{ $graphLookup : { from: \"employees\", startWith: [\"$reportsTo\", { $literal: \"$boss\"}], " |
| 105 | + + "connectFromField: \"reportsTo\", connectToField: \"name\", as: \"reportingHierarchy\" } }"))); |
109 | 106 | }
|
110 | 107 |
|
111 | 108 | @Test(expected = IllegalArgumentException.class) // DATAMONGO-1551
|
@@ -134,4 +131,40 @@ public void shouldRenderStartWithAggregationExpressions() {
|
134 | 131 | assertThat(document, is(Document.parse("{ $graphLookup : { from: \"employees\", startWith: { $literal: \"hello\"}, "
|
135 | 132 | + "connectFromField: \"reportsTo\", connectToField: \"name\", as: \"reportingHierarchy\" } }")));
|
136 | 133 | }
|
| 134 | + |
| 135 | + @Test // DATAMONGO-2096 |
| 136 | + public void connectFromShouldUseTargetFieldInsteadOfAlias() { |
| 137 | + |
| 138 | + AggregationOperation graphLookupOperation = Aggregation.graphLookup("user").startWith("contacts.userId") |
| 139 | + .connectFrom("contacts.userId").connectTo("_id").depthField("numConnections").as("connections"); |
| 140 | + |
| 141 | + Document document = graphLookupOperation.toDocument(Aggregation.DEFAULT_CONTEXT); |
| 142 | + |
| 143 | + assertThat(document, is(Document.parse( |
| 144 | + "{ \"$graphLookup\" : { \"from\" : \"user\", \"startWith\" : \"$contacts.userId\", \"connectFromField\" : \"contacts.userId\", \"connectToField\" : \"_id\", \"as\" : \"connections\", \"depthField\" : \"numConnections\" } }"))); |
| 145 | + } |
| 146 | + |
| 147 | + @Test // DATAMONGO-2096 |
| 148 | + public void connectToShouldUseTargetFieldInsteadOfAlias() { |
| 149 | + |
| 150 | + AggregationOperation graphLookupOperation = Aggregation.graphLookup("user").startWith("contacts.userId") |
| 151 | + .connectFrom("userId").connectTo("connectto.field").depthField("numConnections").as("connections"); |
| 152 | + |
| 153 | + Document document = graphLookupOperation.toDocument(Aggregation.DEFAULT_CONTEXT); |
| 154 | + |
| 155 | + assertThat(document, is(Document.parse( |
| 156 | + "{ \"$graphLookup\" : { \"from\" : \"user\", \"startWith\" : \"$contacts.userId\", \"connectFromField\" : \"userId\", \"connectToField\" : \"connectto.field\", \"as\" : \"connections\", \"depthField\" : \"numConnections\" } }"))); |
| 157 | + } |
| 158 | + |
| 159 | + @Test // DATAMONGO-2096 |
| 160 | + public void depthFieldShouldUseTargetFieldInsteadOfAlias() { |
| 161 | + |
| 162 | + AggregationOperation graphLookupOperation = Aggregation.graphLookup("user").startWith("contacts.userId") |
| 163 | + .connectFrom("contacts.userId").connectTo("_id").depthField("foo.bar").as("connections"); |
| 164 | + |
| 165 | + Document document = graphLookupOperation.toDocument(Aggregation.DEFAULT_CONTEXT); |
| 166 | + |
| 167 | + assertThat(document, is(Document.parse( |
| 168 | + "{ \"$graphLookup\" : { \"from\" : \"user\", \"startWith\" : \"$contacts.userId\", \"connectFromField\" : \"contacts.userId\", \"connectToField\" : \"_id\", \"as\" : \"connections\", \"depthField\" : \"foo.bar\" } }"))); |
| 169 | + } |
137 | 170 | }
|
0 commit comments