コード例 #1
0
  @Test
  public void settingMetricRecalculatesMaxDistance() {

    NearQuery query = NearQuery.near(2.5, 2.5, Metrics.KILOMETERS).maxDistance(150);

    query.inMiles();
    assertThat(query.getMetric(), is((Metric) Metrics.MILES));
  }
コード例 #2
0
  @Test
  public void settingUpNearWithMetricRecalculatesDistance() {

    NearQuery query = NearQuery.near(2.5, 2.5, Metrics.KILOMETERS).maxDistance(150);

    assertThat(query.getMaxDistance(), is(ONE_FIFTY_KILOMETERS));
    assertThat(query.getMetric(), is((Metric) Metrics.KILOMETERS));
    assertThat(query.isSpherical(), is(true));
  }
コード例 #3
0
  /** @see DATAMONGO-445 */
  @Test
  public void shouldTakeSkipAndLimitSettingsFromGivenPageable() {

    Pageable pageable = new PageRequest(3, 5);
    NearQuery query = NearQuery.near(new Point(1, 1)).with(pageable);

    assertThat(query.getSkip(), is(pageable.getPageNumber() * pageable.getPageSize()));
    assertThat(
        (Integer) query.toDBObject().get("num"),
        is((pageable.getPageNumber() + 1) * pageable.getPageSize()));
  }
コード例 #4
0
  /** @see DATAMONGO-445 */
  @Test
  public void shouldTakeSkipAndLimitSettingsFromGivenQuery() {

    int limit = 10;
    int skip = 5;
    NearQuery query =
        NearQuery.near(new Point(1, 1))
            .query(Query.query(Criteria.where("foo").is("bar")).limit(limit).skip(skip));

    assertThat(query.getSkip(), is(skip));
    assertThat((Integer) query.toDBObject().get("num"), is(limit));
  }
コード例 #5
0
  /** @see DATAMONGO-445 */
  @Test
  public void shouldTakeSkipAndLimitSettingsFromPageableEvenIfItWasSpecifiedOnQuery() {

    int limit = 10;
    int skip = 5;
    Pageable pageable = new PageRequest(3, 5);
    NearQuery query =
        NearQuery.near(new Point(1, 1))
            .query(Query.query(Criteria.where("foo").is("bar")).limit(limit).skip(skip))
            .with(pageable);

    assertThat(query.getSkip(), is(pageable.getPageNumber() * pageable.getPageSize()));
    assertThat(
        (Integer) query.toDBObject().get("num"),
        is((pageable.getPageNumber() + 1) * pageable.getPageSize()));
  }
コード例 #6
0
  @Test
  public void configuresResultMetricCorrectly() {

    NearQuery query = NearQuery.near(2.5, 2.1);
    assertThat(query.getMetric(), is((Metric) Metrics.NEUTRAL));

    query = query.maxDistance(ONE_FIFTY_KILOMETERS);
    assertThat(query.getMetric(), is((Metric) Metrics.KILOMETERS));
    assertThat(query.getMaxDistance(), is(ONE_FIFTY_KILOMETERS));
    assertThat(query.isSpherical(), is(true));

    query = query.in(Metrics.MILES);
    assertThat(query.getMetric(), is((Metric) Metrics.MILES));
    assertThat(query.getMaxDistance(), is(ONE_FIFTY_KILOMETERS));
    assertThat(query.isSpherical(), is(true));

    query = query.maxDistance(new Distance(200, Metrics.KILOMETERS));
    assertThat(query.getMetric(), is((Metric) Metrics.MILES));
  }
コード例 #7
0
 @Test(expected = IllegalArgumentException.class)
 public void rejectsNullPoint() {
   NearQuery.near(null);
 }