15
15
*/
16
16
package org .springframework .data .mongodb .core .aggregation ;
17
17
18
- import static org .hamcrest . core . Is .*;
19
- import static org . junit . Assert .*;
20
- import static org . springframework . data . mongodb . test . util .IsBsonObject .* ;
18
+ import static org .springframework . data . mongodb . test . util . Assertions .*;
19
+
20
+ import java . util .Arrays ;
21
21
22
22
import org .bson .Document ;
23
23
import org .junit .Test ;
@@ -50,8 +50,7 @@ public void shouldRenderCorrectly() {
50
50
.as ("reportingHierarchy" );
51
51
52
52
Document document = graphLookupOperation .toDocument (Aggregation .DEFAULT_CONTEXT );
53
- assertThat (document ,
54
- isBsonObject ().containing ("$graphLookup.depthField" , "depth" ).containing ("$graphLookup.maxDepth" , 42L ));
53
+ assertThat (document ).containsEntry ("$graphLookup.depthField" , "depth" ).containsEntry ("$graphLookup.maxDepth" , 42L );
55
54
}
56
55
57
56
@ Test // DATAMONGO-1551
@@ -66,8 +65,7 @@ public void shouldRenderCriteriaCorrectly() {
66
65
.as ("reportingHierarchy" );
67
66
68
67
Document document = graphLookupOperation .toDocument (Aggregation .DEFAULT_CONTEXT );
69
- assertThat (document ,
70
- isBsonObject ().containing ("$graphLookup.restrictSearchWithMatch" , new Document ("key" , "value" )));
68
+ assertThat (document ).containsEntry ("$graphLookup.restrictSearchWithMatch" , new Document ("key" , "value" ));
71
69
}
72
70
73
71
@ Test // DATAMONGO-1551
@@ -82,9 +80,9 @@ public void shouldRenderArrayOfStartsWithCorrectly() {
82
80
83
81
Document document = graphLookupOperation .toDocument (Aggregation .DEFAULT_CONTEXT );
84
82
85
- assertThat (document ,
86
- is (Document .parse ("{ $graphLookup : { from: \" employees\" , startWith: [\" $reportsTo\" , \" $boss\" ], "
87
- + "connectFromField: \" reportsTo\" , connectToField: \" name\" , as: \" reportingHierarchy\" } }" ))) ;
83
+ assertThat (document )
84
+ . isEqualTo (Document .parse ("{ $graphLookup : { from: \" employees\" , startWith: [\" $reportsTo\" , \" $boss\" ], "
85
+ + "connectFromField: \" reportsTo\" , connectToField: \" name\" , as: \" reportingHierarchy\" } }" ));
88
86
}
89
87
90
88
@ Test // DATAMONGO-1551
@@ -99,10 +97,8 @@ public void shouldRenderMixedArrayOfStartsWithCorrectly() {
99
97
100
98
Document document = graphLookupOperation .toDocument (Aggregation .DEFAULT_CONTEXT );
101
99
102
- assertThat (document ,
103
- is (Document
104
- .parse ("{ $graphLookup : { from: \" employees\" , startWith: [\" $reportsTo\" , { $literal: \" $boss\" }], "
105
- + "connectFromField: \" reportsTo\" , connectToField: \" name\" , as: \" reportingHierarchy\" } }" )));
100
+ assertThat (document ).containsEntry ("$graphLookup.startWith" ,
101
+ Arrays .asList ("$reportsTo" , new Document ("$literal" , "$boss" )));
106
102
}
107
103
108
104
@ Test (expected = IllegalArgumentException .class ) // DATAMONGO-1551
@@ -128,8 +124,7 @@ public void shouldRenderStartWithAggregationExpressions() {
128
124
129
125
Document document = graphLookupOperation .toDocument (Aggregation .DEFAULT_CONTEXT );
130
126
131
- assertThat (document , is (Document .parse ("{ $graphLookup : { from: \" employees\" , startWith: { $literal: \" hello\" }, "
132
- + "connectFromField: \" reportsTo\" , connectToField: \" name\" , as: \" reportingHierarchy\" } }" )));
127
+ assertThat (document ).containsEntry ("$graphLookup.startWith" , new Document ("$literal" , "hello" ));
133
128
}
134
129
135
130
@ Test // DATAMONGO-2096
@@ -140,8 +135,7 @@ public void connectFromShouldUseTargetFieldInsteadOfAlias() {
140
135
141
136
Document document = graphLookupOperation .toDocument (Aggregation .DEFAULT_CONTEXT );
142
137
143
- assertThat (document , is (Document .parse (
144
- "{ \" $graphLookup\" : { \" from\" : \" user\" , \" startWith\" : \" $contacts.userId\" , \" connectFromField\" : \" contacts.userId\" , \" connectToField\" : \" _id\" , \" as\" : \" connections\" , \" depthField\" : \" numConnections\" } }" )));
138
+ assertThat (document ).containsEntry ("$graphLookup.startWith" , "$contacts.userId" );
145
139
}
146
140
147
141
@ Test // DATAMONGO-2096
@@ -152,8 +146,7 @@ public void connectToShouldUseTargetFieldInsteadOfAlias() {
152
146
153
147
Document document = graphLookupOperation .toDocument (Aggregation .DEFAULT_CONTEXT );
154
148
155
- assertThat (document , is (Document .parse (
156
- "{ \" $graphLookup\" : { \" from\" : \" user\" , \" startWith\" : \" $contacts.userId\" , \" connectFromField\" : \" userId\" , \" connectToField\" : \" connectto.field\" , \" as\" : \" connections\" , \" depthField\" : \" numConnections\" } }" )));
149
+ assertThat (document ).containsEntry ("$graphLookup.connectToField" , "connectto.field" );
157
150
}
158
151
159
152
@ Test // DATAMONGO-2096
@@ -164,7 +157,6 @@ public void depthFieldShouldUseTargetFieldInsteadOfAlias() {
164
157
165
158
Document document = graphLookupOperation .toDocument (Aggregation .DEFAULT_CONTEXT );
166
159
167
- assertThat (document , is (Document .parse (
168
- "{ \" $graphLookup\" : { \" from\" : \" user\" , \" startWith\" : \" $contacts.userId\" , \" connectFromField\" : \" contacts.userId\" , \" connectToField\" : \" _id\" , \" as\" : \" connections\" , \" depthField\" : \" foo.bar\" } }" )));
160
+ assertThat (document ).containsEntry ("$graphLookup.depthField" , "foo.bar" );
169
161
}
170
162
}
0 commit comments