19
19
import static org .hamcrest .Matchers .*;
20
20
import static org .junit .Assert .assertThat ;
21
21
22
+ import java .net .UnknownHostException ;
22
23
import java .util .Collection ;
23
24
import java .util .List ;
24
25
25
26
import org .apache .commons .logging .Log ;
26
27
import org .apache .commons .logging .LogFactory ;
28
+ import org .junit .After ;
27
29
import org .junit .Before ;
28
30
import org .junit .Ignore ;
29
31
import org .junit .Test ;
30
- import org .junit .runner .RunWith ;
31
- import org .springframework .beans .factory .annotation .Autowired ;
32
32
import org .springframework .context .ApplicationContext ;
33
33
import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
34
- import org .springframework .context .support .ClassPathXmlApplicationContext ;
35
34
import org .springframework .dao .DataAccessException ;
36
35
import org .springframework .data .document .mongodb .geo .Box ;
37
36
import org .springframework .data .document .mongodb .geo .Circle ;
42
41
import org .springframework .data .document .mongodb .query .Query ;
43
42
import org .springframework .expression .ExpressionParser ;
44
43
import org .springframework .expression .spel .standard .SpelExpressionParser ;
45
- import org .springframework .test .context .ContextConfiguration ;
46
- import org .springframework .test .context .junit4 .SpringJUnit4ClassRunner ;
47
44
48
45
import com .mongodb .DB ;
49
46
import com .mongodb .DBCollection ;
61
58
public class GeoSpatialTests {
62
59
63
60
private static final Log LOGGER = LogFactory .getLog (GeoSpatialTests .class );
64
- private final String [] collectionsToDrop = new String [] { "newyork" };
61
+ private final String [] collectionsToDrop = new String [] { "newyork" , "Person" };
65
62
66
63
ApplicationContext applicationContext ;
67
64
MongoTemplate template ;
@@ -71,12 +68,7 @@ public class GeoSpatialTests {
71
68
72
69
@ Before
73
70
public void setUp () throws Exception {
74
- Mongo mongo = new Mongo ();
75
- serverInfo = new ServerInfo (mongo );
76
- DB db = mongo .getDB ("geospatial" );
77
- for (String coll : collectionsToDrop ) {
78
- db .getCollection (coll ).drop ();
79
- }
71
+ cleanDb ();
80
72
applicationContext = new AnnotationConfigApplicationContext (GeoSpatialAppConfig .class );
81
73
template = applicationContext .getBean (MongoTemplate .class );
82
74
template .setWriteConcern (WriteConcern .FSYNC_SAFE );
@@ -86,6 +78,20 @@ public void setUp() throws Exception {
86
78
parser = new SpelExpressionParser ();
87
79
}
88
80
81
+ @ After
82
+ public void cleanUp () throws Exception {
83
+ cleanDb ();
84
+ }
85
+
86
+ private void cleanDb () throws UnknownHostException {
87
+ Mongo mongo = new Mongo ();
88
+ serverInfo = new ServerInfo (mongo );
89
+ DB db = mongo .getDB ("database" );
90
+ for (String coll : collectionsToDrop ) {
91
+ db .getCollection (coll ).drop ();
92
+ }
93
+ }
94
+
89
95
private void addVenues () {
90
96
91
97
template .insert (new Venue ("Penn Station" , -73.99408 , 40.75057 ));
@@ -168,7 +174,7 @@ public void indexCreated() {
168
174
LOGGER .debug (indexInfo );
169
175
assertThat (indexInfo .size (), equalTo (2 ));
170
176
assertThat (indexInfo .get (1 ).get ("name" ).toString (), equalTo ("location_2d" ));
171
- assertThat (indexInfo .get (1 ).get ("ns" ).toString (), equalTo ("geospatial .newyork" ));
177
+ assertThat (indexInfo .get (1 ).get ("ns" ).toString (), equalTo ("database .newyork" ));
172
178
}
173
179
174
180
// TODO move to MongoAdmin
0 commit comments