2626import java .util .Map ;
2727import java .util .stream .Stream ;
2828
29+ import static java .util .Collections .singletonMap ;
2930import static java .util .stream .Collectors .toList ;
31+ import static java .util .stream .Collectors .toMap ;
3032import static org .hamcrest .Matchers .containsInAnyOrder ;
3133import static org .hamcrest .Matchers .equalTo ;
3234import static org .hamcrest .Matchers .hasSize ;
@@ -55,8 +57,10 @@ private static final String getDateStringForRow(int row) {
5557 private static final String BUSINESS_ID = "business_id" ;
5658 private static final String COUNT = "count" ;
5759 private static final String STARS = "stars" ;
60+ private static final String COMMENT = "comment" ;
5861
59- private static final Map <String , Object > row (String userId , String businessId , int count , int stars , String timestamp ) {
62+ private static final Map <String , Object > row (
63+ String userId , String businessId , int count , int stars , String timestamp , String comment ) {
6064 return new HashMap <String , Object >() {{
6165 if (userId != null ) {
6266 put (USER_ID , userId );
@@ -65,40 +69,43 @@ private static final Map<String, Object> row(String userId, String businessId, i
6569 put (COUNT , count );
6670 put (STARS , stars );
6771 put (TIMESTAMP , timestamp );
72+ put (COMMENT , comment );
73+ put ("regular_object" , singletonMap ("foo" , 42 ));
74+ put ("nested_object" , singletonMap ("bar" , 43 ));
6875 }};
6976 }
7077
7178 private static final Object [] EXPECTED_DEST_INDEX_ROWS =
7279 new Object [] {
73- row ("user_0" , "business_37" , 87 , 2 , "2017-04-04T12:30:00Z" ),
74- row ("user_1" , "business_38" , 88 , 3 , "2017-04-05T12:30:00Z" ),
75- row ("user_2" , "business_39" , 89 , 4 , "2017-04-06T12:30:00Z" ),
76- row ("user_3" , "business_40" , 90 , 0 , "2017-04-07T12:30:00Z" ),
77- row ("user_4" , "business_41" , 91 , 1 , "2017-04-08T12:30:00Z" ),
78- row ("user_5" , "business_42" , 92 , 2 , "2017-04-09T12:30:00Z" ),
79- row ("user_6" , "business_43" , 93 , 3 , "2017-04-10T12:30:00Z" ),
80- row ("user_7" , "business_44" , 94 , 4 , "2017-04-11T12:30:00Z" ),
81- row ("user_8" , "business_45" , 95 , 0 , "2017-04-12T12:30:00Z" ),
82- row ("user_9" , "business_46" , 96 , 1 , "2017-04-13T12:30:00Z" ),
83- row ("user_10" , "business_47" , 97 , 2 , "2017-04-14T12:30:00Z" ),
84- row ("user_11" , "business_48" , 98 , 3 , "2017-04-15T12:30:00Z" ),
85- row ("user_12" , "business_49" , 99 , 4 , "2017-04-16T12:30:00Z" ),
86- row ("user_13" , "business_21" , 71 , 1 , "2017-03-16T12:30:00Z" ),
87- row ("user_14" , "business_22" , 72 , 2 , "2017-03-17T12:30:00Z" ),
88- row ("user_15" , "business_23" , 73 , 3 , "2017-03-18T12:30:00Z" ),
89- row ("user_16" , "business_24" , 74 , 4 , "2017-03-19T12:30:00Z" ),
90- row ("user_17" , "business_25" , 75 , 0 , "2017-03-20T12:30:00Z" ),
91- row ("user_18" , "business_26" , 76 , 1 , "2017-03-21T12:30:00Z" ),
92- row ("user_19" , "business_27" , 77 , 2 , "2017-03-22T12:30:00Z" ),
93- row ("user_20" , "business_28" , 78 , 3 , "2017-03-23T12:30:00Z" ),
94- row ("user_21" , "business_29" , 79 , 4 , "2017-03-24T12:30:00Z" ),
95- row ("user_22" , "business_30" , 80 , 0 , "2017-03-25T12:30:00Z" ),
96- row ("user_23" , "business_31" , 81 , 1 , "2017-03-26T12:30:00Z" ),
97- row ("user_24" , "business_32" , 82 , 2 , "2017-03-27T12:30:00Z" ),
98- row ("user_25" , "business_33" , 83 , 3 , "2017-03-28T12:30:00Z" ),
99- row ("user_26" , "business_34" , 84 , 4 , "2017-04-01T12:30:00Z" ),
100- row ("user_27" , "business_35" , 85 , 0 , "2017-04-02T12:30:00Z" ),
101- row (null , "business_36" , 86 , 1 , "2017-04-03T12:30:00Z" )
80+ row ("user_0" , "business_37" , 87 , 2 , "2017-04-04T12:30:00Z" , "Great stuff, deserves 2 stars" ),
81+ row ("user_1" , "business_38" , 88 , 3 , "2017-04-05T12:30:00Z" , "Great stuff, deserves 3 stars" ),
82+ row ("user_2" , "business_39" , 89 , 4 , "2017-04-06T12:30:00Z" , "Great stuff, deserves 4 stars" ),
83+ row ("user_3" , "business_40" , 90 , 0 , "2017-04-07T12:30:00Z" , "Great stuff, deserves 0 stars" ),
84+ row ("user_4" , "business_41" , 91 , 1 , "2017-04-08T12:30:00Z" , "Great stuff, deserves 1 stars" ),
85+ row ("user_5" , "business_42" , 92 , 2 , "2017-04-09T12:30:00Z" , "Great stuff, deserves 2 stars" ),
86+ row ("user_6" , "business_43" , 93 , 3 , "2017-04-10T12:30:00Z" , "Great stuff, deserves 3 stars" ),
87+ row ("user_7" , "business_44" , 94 , 4 , "2017-04-11T12:30:00Z" , "Great stuff, deserves 4 stars" ),
88+ row ("user_8" , "business_45" , 95 , 0 , "2017-04-12T12:30:00Z" , "Great stuff, deserves 0 stars" ),
89+ row ("user_9" , "business_46" , 96 , 1 , "2017-04-13T12:30:00Z" , "Great stuff, deserves 1 stars" ),
90+ row ("user_10" , "business_47" , 97 , 2 , "2017-04-14T12:30:00Z" , "Great stuff, deserves 2 stars" ),
91+ row ("user_11" , "business_48" , 98 , 3 , "2017-04-15T12:30:00Z" , "Great stuff, deserves 3 stars" ),
92+ row ("user_12" , "business_49" , 99 , 4 , "2017-04-16T12:30:00Z" , "Great stuff, deserves 4 stars" ),
93+ row ("user_13" , "business_21" , 71 , 1 , "2017-03-16T12:30:00Z" , "Great stuff, deserves 1 stars" ),
94+ row ("user_14" , "business_22" , 72 , 2 , "2017-03-17T12:30:00Z" , "Great stuff, deserves 2 stars" ),
95+ row ("user_15" , "business_23" , 73 , 3 , "2017-03-18T12:30:00Z" , "Great stuff, deserves 3 stars" ),
96+ row ("user_16" , "business_24" , 74 , 4 , "2017-03-19T12:30:00Z" , "Great stuff, deserves 4 stars" ),
97+ row ("user_17" , "business_25" , 75 , 0 , "2017-03-20T12:30:00Z" , "Great stuff, deserves 0 stars" ),
98+ row ("user_18" , "business_26" , 76 , 1 , "2017-03-21T12:30:00Z" , "Great stuff, deserves 1 stars" ),
99+ row ("user_19" , "business_27" , 77 , 2 , "2017-03-22T12:30:00Z" , "Great stuff, deserves 2 stars" ),
100+ row ("user_20" , "business_28" , 78 , 3 , "2017-03-23T12:30:00Z" , "Great stuff, deserves 3 stars" ),
101+ row ("user_21" , "business_29" , 79 , 4 , "2017-03-24T12:30:00Z" , "Great stuff, deserves 4 stars" ),
102+ row ("user_22" , "business_30" , 80 , 0 , "2017-03-25T12:30:00Z" , "Great stuff, deserves 0 stars" ),
103+ row ("user_23" , "business_31" , 81 , 1 , "2017-03-26T12:30:00Z" , "Great stuff, deserves 1 stars" ),
104+ row ("user_24" , "business_32" , 82 , 2 , "2017-03-27T12:30:00Z" , "Great stuff, deserves 2 stars" ),
105+ row ("user_25" , "business_33" , 83 , 3 , "2017-03-28T12:30:00Z" , "Great stuff, deserves 3 stars" ),
106+ row ("user_26" , "business_34" , 84 , 4 , "2017-04-01T12:30:00Z" , "Great stuff, deserves 4 stars" ),
107+ row ("user_27" , "business_35" , 85 , 0 , "2017-04-02T12:30:00Z" , "Great stuff, deserves 0 stars" ),
108+ row (null , "business_36" , 86 , 1 , "2017-04-03T12:30:00Z" , "Great stuff, deserves 1 stars" )
102109 };
103110
104111 @ After
@@ -162,11 +169,24 @@ public void testLatestPreview() throws Exception {
162169 GetMappingsResponse sourceIndexMapping =
163170 restClient .indices ().getMapping (new GetMappingsRequest ().indices (SOURCE_INDEX_NAME ), RequestOptions .DEFAULT );
164171 assertThat (
165- previewResponse .getMappings ().get ("properties" ),
172+ // Mappings we get from preview sometimes contain redundant { "type": "object" } entries.
173+ // We clear them here to be able to compare with the GetMappingsAction output.
174+ clearDefaultObjectType (previewResponse .getMappings ().get ("properties" )),
166175 is (equalTo (sourceIndexMapping .mappings ().get (SOURCE_INDEX_NAME ).sourceAsMap ().get ("properties" ))));
167176 // Verify preview contents
168177 assertThat (previewResponse .getDocs (), hasSize (NUM_USERS + 1 ));
169178 assertThat (previewResponse .getDocs (), containsInAnyOrder (EXPECTED_DEST_INDEX_ROWS ));
170179 }
171180 }
181+
182+ private static Object clearDefaultObjectType (Object obj ) {
183+ if (obj instanceof Map == false ) {
184+ return obj ;
185+ }
186+ @ SuppressWarnings ("unchecked" )
187+ Map <String , Object > map = (Map <String , Object >) obj ;
188+ return map .entrySet ().stream ()
189+ .filter (entry -> (entry .getKey ().equals ("type" ) && entry .getValue ().equals ("object" )) == false )
190+ .collect (toMap (entry -> entry .getKey (), entry -> clearDefaultObjectType (entry .getValue ())));
191+ }
172192}
0 commit comments