|
17 | 17 |
|
18 | 18 | import static org.hamcrest.Matchers.*;
|
19 | 19 | import static org.junit.Assert.*;
|
| 20 | +import static org.mockito.Mockito.*; |
20 | 21 |
|
21 | 22 | import java.util.Collections;
|
22 | 23 | import java.util.Date;
|
|
27 | 28 | import org.junit.runner.RunWith;
|
28 | 29 | import org.mockito.ArgumentCaptor;
|
29 | 30 | import org.mockito.Mock;
|
30 |
| -import org.mockito.Mockito; |
31 | 31 | import org.mockito.runners.MockitoJUnitRunner;
|
32 | 32 | import org.springframework.context.ApplicationContext;
|
33 | 33 | import org.springframework.data.geo.Point;
|
@@ -72,10 +72,10 @@ public void setUp() {
|
72 | 72 | optionsCaptor = ArgumentCaptor.forClass(DBObject.class);
|
73 | 73 | collectionCaptor = ArgumentCaptor.forClass(String.class);
|
74 | 74 |
|
75 |
| - Mockito.when(factory.getDb()).thenReturn(db); |
76 |
| - Mockito.when(db.getCollection(collectionCaptor.capture())).thenReturn(collection); |
| 75 | + when(factory.getDb()).thenReturn(db); |
| 76 | + when(db.getCollection(collectionCaptor.capture())).thenReturn(collection); |
77 | 77 |
|
78 |
| - Mockito.doNothing().when(collection).createIndex(keysCaptor.capture(), optionsCaptor.capture()); |
| 78 | + doNothing().when(collection).createIndex(keysCaptor.capture(), optionsCaptor.capture()); |
79 | 79 | }
|
80 | 80 |
|
81 | 81 | @Test
|
@@ -106,7 +106,7 @@ public void doesNotCreateIndexForEntityComingFromDifferentMappingContext() {
|
106 | 106 |
|
107 | 107 | creator.onApplicationEvent(event);
|
108 | 108 |
|
109 |
| - Mockito.verifyZeroInteractions(collection); |
| 109 | + verifyZeroInteractions(collection); |
110 | 110 | }
|
111 | 111 |
|
112 | 112 | /**
|
@@ -181,6 +181,36 @@ public void autoGeneratedIndexNameShouldGenerateNoName() {
|
181 | 181 | assertThat(optionsCaptor.getValue(), is(new BasicDBObjectBuilder().get()));
|
182 | 182 | }
|
183 | 183 |
|
| 184 | + /** |
| 185 | + * @see DATAMONGO-367 |
| 186 | + */ |
| 187 | + @Test |
| 188 | + public void indexCreationShouldNotCreateNewCollectionForNestedGeoSpatialIndexStructures() { |
| 189 | + |
| 190 | + MongoMappingContext mappingContext = prepareMappingContext(Wrapper.class); |
| 191 | + new MongoPersistentEntityIndexCreator(mappingContext, factory); |
| 192 | + |
| 193 | + ArgumentCaptor<String> collectionNameCapturer = ArgumentCaptor.forClass(String.class); |
| 194 | + |
| 195 | + verify(db, times(1)).getCollection(collectionNameCapturer.capture()); |
| 196 | + assertThat(collectionNameCapturer.getValue(), equalTo("wrapper")); |
| 197 | + } |
| 198 | + |
| 199 | + /** |
| 200 | + * @see DATAMONGO-367 |
| 201 | + */ |
| 202 | + @Test |
| 203 | + public void indexCreationShouldNotCreateNewCollectionForNestedIndexStructures() { |
| 204 | + |
| 205 | + MongoMappingContext mappingContext = prepareMappingContext(IndexedDocumentWrapper.class); |
| 206 | + new MongoPersistentEntityIndexCreator(mappingContext, factory); |
| 207 | + |
| 208 | + ArgumentCaptor<String> collectionNameCapturer = ArgumentCaptor.forClass(String.class); |
| 209 | + |
| 210 | + verify(db, times(1)).getCollection(collectionNameCapturer.capture()); |
| 211 | + assertThat(collectionNameCapturer.getValue(), equalTo("indexedDocumentWrapper")); |
| 212 | + } |
| 213 | + |
184 | 214 | private static MongoMappingContext prepareMappingContext(Class<?> type) {
|
185 | 215 |
|
186 | 216 | MongoMappingContext mappingContext = new MongoMappingContext();
|
@@ -233,6 +263,17 @@ static class Address {
|
233 | 263 | @GeoSpatialIndexed Point location;
|
234 | 264 | }
|
235 | 265 |
|
| 266 | + @Document |
| 267 | + static class IndexedDocumentWrapper { |
| 268 | + |
| 269 | + IndexedDocument indexedDocument; |
| 270 | + } |
| 271 | + |
| 272 | + static class IndexedDocument { |
| 273 | + |
| 274 | + @Indexed String indexedValue; |
| 275 | + } |
| 276 | + |
236 | 277 | @Document
|
237 | 278 | class EntityWithGeneratedIndexName {
|
238 | 279 |
|
|
0 commit comments