Ejemplo n.º 1
0
 @Test
 public void testCriteriaChain() {
   Criteria criteria =
       new Criteria("field_1").startsWith("start").endsWith("end").contains("contains").is("is");
   Assert.assertEquals("field_1", criteria.getField().getName());
   assertCriteriaEntry(criteria.getCriteriaEntries(), 0, OperationKey.STARTS_WITH, "start");
   assertCriteriaEntry(criteria.getCriteriaEntries(), 1, OperationKey.ENDS_WITH, "end");
   assertCriteriaEntry(criteria.getCriteriaEntries(), 2, OperationKey.CONTAINS, "contains");
   assertCriteriaEntry(criteria.getCriteriaEntries(), 3, OperationKey.EQUALS, "is");
 }
Ejemplo n.º 2
0
  @Test
  public void testInWithNestedCollection() {
    List<List<String>> enclosingList = new ArrayList<List<String>>();
    enclosingList.add(Arrays.asList("spring", "data"));
    enclosingList.add(Arrays.asList("solr"));
    Criteria criteria = new Criteria("field_1").in(enclosingList);

    assertCriteriaEntry(criteria.getCriteriaEntries(), 0, OperationKey.EQUALS, "spring");
    assertCriteriaEntry(criteria.getCriteriaEntries(), 1, OperationKey.EQUALS, "data");
    assertCriteriaEntry(criteria.getCriteriaEntries(), 2, OperationKey.EQUALS, "solr");
  }
Ejemplo n.º 3
0
 @Test
 public void testIn() {
   Criteria criteria = new Criteria("field_1").in(1, 2, 3, 5, 8, 13, 21);
   Assert.assertEquals("field_1", criteria.getField().getName());
   assertCriteriaEntry(criteria.getCriteriaEntries(), 0, OperationKey.EQUALS, 1);
   assertCriteriaEntry(criteria.getCriteriaEntries(), 1, OperationKey.EQUALS, 2);
   assertCriteriaEntry(criteria.getCriteriaEntries(), 2, OperationKey.EQUALS, 3);
   assertCriteriaEntry(criteria.getCriteriaEntries(), 3, OperationKey.EQUALS, 5);
   assertCriteriaEntry(criteria.getCriteriaEntries(), 4, OperationKey.EQUALS, 8);
   assertCriteriaEntry(criteria.getCriteriaEntries(), 5, OperationKey.EQUALS, 13);
   assertCriteriaEntry(criteria.getCriteriaEntries(), 6, OperationKey.EQUALS, 21);
 }
Ejemplo n.º 4
0
  @Test
  public void testStartsWith() {
    Criteria criteria = new Criteria("field_1").startsWith("start");

    Assert.assertEquals("field_1", criteria.getField().getName());
    assertCriteriaEntry(criteria.getCriteriaEntries(), 0, OperationKey.STARTS_WITH, "start");
  }
Ejemplo n.º 5
0
  @Test
  public void testEndsWith() {
    Criteria criteria = new Criteria("field_1").endsWith("end");

    Assert.assertEquals("field_1", criteria.getField().getName());
    assertCriteriaEntry(criteria.getCriteriaEntries(), 0, OperationKey.ENDS_WITH, "end");
  }
Ejemplo n.º 6
0
  @Test
  public void testContains() {
    Criteria criteria = new Criteria("field_1").contains("contains");

    Assert.assertEquals("field_1", criteria.getField().getName());
    assertCriteriaEntry(criteria.getCriteriaEntries(), 0, OperationKey.CONTAINS, "contains");
  }
Ejemplo n.º 7
0
  @Test
  public void testMultipleIs() {
    Criteria criteria = new Criteria("field_1").is("is").is("another is");
    Assert.assertEquals("field_1", criteria.getField().getName());

    assertCriteriaEntry(criteria.getCriteriaEntries(), 0, OperationKey.EQUALS, "is");
    assertCriteriaEntry(criteria.getCriteriaEntries(), 1, OperationKey.EQUALS, "another is");
  }
Ejemplo n.º 8
0
 @Test
 public void testWithin() {
   GeoLocation location = new GeoLocation(48.303056, 14.290556);
   Criteria criteria = new Criteria("field_1").within(location, new Distance(5));
   CriteriaEntry entry = getCriteriaEntryByPosition(criteria.getCriteriaEntries(), 0);
   Assert.assertEquals(OperationKey.WITHIN.getKey(), entry.getKey());
   Assert.assertEquals(location, ((Object[]) entry.getValue())[0]);
   Assert.assertEquals(5, ((Distance) ((Object[]) entry.getValue())[1]).getValue(), 0);
 }
Ejemplo n.º 9
0
 @Test
 public void testGreaterThanEqual() {
   Criteria criteria = new Criteria("field_1").greaterThanEqual(100);
   CriteriaEntry entry = getCriteriaEntryByPosition(criteria.getCriteriaEntries(), 0);
   Assert.assertEquals(OperationKey.BETWEEN.getKey(), entry.getKey());
   Assert.assertEquals(100, ((Object[]) entry.getValue())[0]);
   Assert.assertEquals(null, ((Object[]) entry.getValue())[1]);
   Assert.assertTrue(((Boolean) ((Object[]) entry.getValue())[2]).booleanValue());
   Assert.assertTrue(((Boolean) ((Object[]) entry.getValue())[3]).booleanValue());
 }
Ejemplo n.º 10
0
 @Test
 public void testBetweenExcludingUpperBound() {
   Criteria criteria = new Criteria("field_1").between(100, 200, true, false);
   CriteriaEntry entry = getCriteriaEntryByPosition(criteria.getCriteriaEntries(), 0);
   Assert.assertEquals(OperationKey.BETWEEN.getKey(), entry.getKey());
   Assert.assertEquals(100, ((Object[]) entry.getValue())[0]);
   Assert.assertEquals(200, ((Object[]) entry.getValue())[1]);
   Assert.assertTrue(((Boolean) ((Object[]) entry.getValue())[2]).booleanValue());
   Assert.assertFalse(((Boolean) ((Object[]) entry.getValue())[3]).booleanValue());
 }
Ejemplo n.º 11
0
 @Test
 public void testExpression() {
   Criteria criteria =
       new Criteria("field_1").expression("(have fun using +solr && expressions*)");
   assertCriteriaEntry(
       criteria.getCriteriaEntries(),
       0,
       OperationKey.EXPRESSION,
       "(have fun using +solr && expressions*)");
 }
Ejemplo n.º 12
0
 @Test
 public void testBoost() {
   Criteria criteria = new Criteria("field_1").is("value_1").boost(2f);
   assertCriteriaEntry(criteria.getCriteriaEntries(), 0, OperationKey.EQUALS, "value_1");
   Assert.assertEquals(2f, criteria.getBoost(), 0);
 }
Ejemplo n.º 13
0
 @Test
 public void testFuzzyWithDistance() {
   Criteria criteria = new Criteria("field_1").fuzzy("value_1", 0.5f);
   assertCriteriaEntry(criteria.getCriteriaEntries(), 0, "$fuzzy#0.5", "value_1");
 }
Ejemplo n.º 14
0
 @Test
 public void testFuzzy() {
   Criteria criteria = new Criteria("field_1").fuzzy("value_1");
   assertCriteriaEntry(criteria.getCriteriaEntries(), 0, "$fuzzy#NaN", "value_1");
 }
Ejemplo n.º 15
0
 @Test
 public void testIsNot() {
   Criteria criteria = new Criteria("field_1").is("value_1").not();
   Assert.assertTrue(criteria.isNegating());
   assertCriteriaEntry(criteria.getCriteriaEntries(), 0, OperationKey.EQUALS, "value_1");
 }