/**
   * Test case to show the usage of the geo-spatial APIs to lookup people within a given distance of
   * a reference point.
   */
  @Test
  public void exposesGeoSpatialFunctionality() {

    GeospatialIndex indexDefinition = new GeospatialIndex("address.location");
    indexDefinition.getIndexOptions().put("min", -180);
    indexDefinition.getIndexOptions().put("max", 180);

    operations.indexOps(Customer.class).ensureIndex(indexDefinition);

    Customer ollie = new Customer("Oliver", "Gierke");
    ollie.setAddress(new Address(new Point(52.52548, 13.41477)));
    ollie = repository.save(ollie);

    Point referenceLocation = new Point(52.51790, 13.41239);
    Distance oneKilometer = new Distance(1, Metrics.KILOMETERS);

    GeoResults<Customer> result =
        repository.findByAddressLocationNear(referenceLocation, oneKilometer);

    assertThat(result.getContent(), hasSize(1));

    Distance distanceToFirstStore = result.getContent().get(0).getDistance();
    assertThat(distanceToFirstStore.getMetric(), is(Metrics.KILOMETERS));
    assertThat(distanceToFirstStore.getValue(), closeTo(0.862, 0.001));
  }
 public static void initializeDatabase(MongoOperations mongoTemplate) {
   if (!mongoTemplate.collectionExists(Rider.class)) mongoTemplate.createCollection(Rider.class);
   if (!mongoTemplate.collectionExists(Hub.class)) mongoTemplate.createCollection(Hub.class);
   if (!mongoTemplate.collectionExists(RideRequest.class))
     mongoTemplate.createCollection(RideRequest.class);
   if (!mongoTemplate.collectionExists(RideBooking.class))
     mongoTemplate.createCollection(RideBooking.class);
   mongoTemplate.indexOps(RideBooking.class).ensureIndex(new GeospatialIndex("itinerary.origin"));
   mongoTemplate
       .indexOps(RideBooking.class)
       .ensureIndex(new GeospatialIndex("itinerary.destination"));
   if (!mongoTemplate.collectionExists(RideProposal.class))
     mongoTemplate.createCollection(RideProposal.class);
   mongoTemplate.indexOps(RideProposal.class).ensureIndex(new GeospatialIndex("itinerary.origin"));
   mongoTemplate
       .indexOps(RideProposal.class)
       .ensureIndex(new GeospatialIndex("itinerary.destination"));
 }