Skip to content

Commit bce6e2c

Browse files
committed
DATAMONGO-1163 - Polishing.
Fixed indentation changes in IndexingIntegrationTests. Separated test cases from each other. Original pull request: #325.
1 parent b5ea0ec commit bce6e2c

File tree

2 files changed

+47
-22
lines changed

2 files changed

+47
-22
lines changed

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/IndexingIntegrationTests.java

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011-2014 by the original author(s).
2+
* Copyright 2011-2015 by the original author(s).
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,65 +15,88 @@
1515
*/
1616
package org.springframework.data.mongodb.core.index;
1717

18-
import com.mongodb.DBCollection;
19-
import com.mongodb.DBObject;
20-
import com.mongodb.MongoException;
18+
import static org.hamcrest.CoreMatchers.*;
19+
import static org.junit.Assert.*;
20+
2121
import java.lang.annotation.ElementType;
2222
import java.lang.annotation.Retention;
2323
import java.lang.annotation.RetentionPolicy;
2424
import java.lang.annotation.Target;
25-
import static org.hamcrest.CoreMatchers.*;
25+
2626
import org.junit.After;
27-
import static org.junit.Assert.*;
2827
import org.junit.Test;
2928
import org.junit.runner.RunWith;
3029
import org.springframework.beans.factory.annotation.Autowired;
30+
import org.springframework.context.ConfigurableApplicationContext;
3131
import org.springframework.dao.DataAccessException;
32+
import org.springframework.data.mongodb.MongoDbFactory;
3233
import org.springframework.data.mongodb.core.CollectionCallback;
3334
import org.springframework.data.mongodb.core.MongoOperations;
3435
import org.springframework.data.mongodb.core.mapping.Document;
3536
import org.springframework.data.mongodb.core.mapping.Field;
37+
import org.springframework.test.annotation.DirtiesContext;
3638
import org.springframework.test.context.ContextConfiguration;
3739
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
3840

41+
import com.mongodb.DBCollection;
42+
import com.mongodb.DBObject;
43+
import com.mongodb.MongoException;
44+
3945
/**
4046
* Integration tests for index handling.
4147
*
4248
* @author Oliver Gierke
4349
* @author Christoph Strobl
50+
* @author Jordi Llach
4451
*/
4552
@RunWith(SpringJUnit4ClassRunner.class)
4653
@ContextConfiguration("classpath:infrastructure.xml")
4754
public class IndexingIntegrationTests {
4855

4956
@Autowired MongoOperations operations;
50-
51-
@After
57+
@Autowired MongoDbFactory mongoDbFactory;
58+
@Autowired ConfigurableApplicationContext context;
59+
60+
@After
5261
public void tearDown() {
53-
operations.dropCollection(IndexedPerson.class);
62+
operations.dropCollection(IndexedPerson.class);
5463
}
55-
56-
/**
57-
* @see DATADOC-237
58-
* @see DATAMONGO-1163
64+
65+
/**
66+
* @see DATAMONGO-237
5967
*/
6068
@Test
69+
@DirtiesContext
6170
public void createsIndexWithFieldName() {
62-
operations.save(new IndexedPerson());
71+
72+
operations.getConverter().getMappingContext().getPersistentEntity(IndexedPerson.class);
73+
6374
assertThat(hasIndex("_firstname", IndexedPerson.class), is(true));
64-
assertThat(hasIndex("_lastname", IndexedPerson.class), is(true));
6575
}
6676

67-
@Target({ElementType.FIELD})
68-
@Retention(RetentionPolicy.RUNTIME)
69-
@Indexed
70-
@interface IndexedFieldAnnotation {}
71-
77+
/**
78+
* @see DATAMONGO-1163
79+
*/
80+
@Test
81+
@DirtiesContext
82+
public void createsIndexFromMetaAnnotation() {
83+
84+
operations.getConverter().getMappingContext().getPersistentEntity(IndexedPerson.class);
85+
86+
assertThat(hasIndex("_lastname", IndexedPerson.class), is(true));
87+
}
88+
89+
@Target({ ElementType.FIELD })
90+
@Retention(RetentionPolicy.RUNTIME)
91+
@Indexed
92+
@interface IndexedFieldAnnotation {
93+
}
94+
7295
@Document
7396
class IndexedPerson {
7497

7598
@Field("_firstname") @Indexed String firstname;
76-
@Field("_lastname") @IndexedFieldAnnotation String lastname;
99+
@Field("_lastname") @IndexedFieldAnnotation String lastname;
77100
}
78101

79102
/**
@@ -96,4 +119,4 @@ public Boolean doInCollection(DBCollection collection) throws MongoException, Da
96119
}
97120
});
98121
}
99-
}
122+
}

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexResolverUnitTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,10 @@ public void resolvesIndexOnDbrefWhenDefinedOnNestedElement() {
186186
*/
187187
@Test
188188
public void resolveIndexDefinitionInMetaAnnotatedFields() {
189+
189190
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
190191
IndexOnMetaAnnotatedField.class);
192+
191193
assertThat(indexDefinitions, hasSize(1));
192194
assertThat(indexDefinitions.get(0).getCollection(), equalTo("indexOnMetaAnnotatedField"));
193195
assertThat(indexDefinitions.get(0).getIndexOptions(),

0 commit comments

Comments
 (0)