@Test public void testFindLong() { Query<TestEntity> query = box.query().greater(simpleLong, 1002).build(); assertNull(query.property(simpleLong).findLong()); assertNull(query.property(simpleLong).findLong()); putTestEntities(5); assertEquals(1003, (long) query.property(simpleLong).findLong()); query = box.query().greater(simpleLong, 1004).build(); assertEquals(1005, (long) query.property(simpleLong).distinct().findLong()); }
@Test public void testFindShort() { Query<TestEntity> query = box.query().greater(simpleLong, 1002).build(); assertNull(query.property(simpleShort).findShort()); assertNull(query.property(simpleShort).unique().findShort()); putTestEntities(5); assertEquals(103, (short) query.property(simpleShort).findShort()); query = box.query().greater(simpleLong, 1004).build(); assertEquals(105, (short) query.property(simpleShort).distinct().unique().findShort()); }
@Test public void testFindBoolean() { Query<TestEntity> query = box.query().greater(simpleLong, 1002).build(); assertNull(query.property(simpleBoolean).findBoolean()); assertNull(query.property(simpleBoolean).unique().findBoolean()); putTestEntities(5); assertFalse(query.property(simpleBoolean).findBoolean()); query = box.query().greater(simpleLong, 1004).build(); assertFalse(query.property(simpleBoolean).distinct().unique().findBoolean()); }
@Test public void testFindFloat() { Query<TestEntity> query = box.query().greater(simpleLong, 1002).build(); assertNull(query.property(simpleFloat).findFloat()); assertNull(query.property(simpleFloat).unique().findFloat()); putTestEntities(5); assertEquals(200.3f, query.property(simpleFloat).findFloat(), 0.001f); query = box.query().greater(simpleLong, 1004).build(); assertEquals(200.5f, query.property(simpleFloat).distinct().unique().findFloat(), 0.001f); }
@Test public void testFindDouble() { Query<TestEntity> query = box.query().greater(simpleLong, 1002).build(); assertNull(query.property(simpleDouble).findDouble()); assertNull(query.property(simpleDouble).unique().findDouble()); putTestEntities(5); assertEquals(2000.03, query.property(simpleDouble).findDouble(), 0.001); query = box.query().greater(simpleLong, 1004).build(); assertEquals(2000.05, query.property(simpleDouble).distinct().unique().findDouble(), 0.001); }
@Test public void testFindByte() { Query<TestEntity> query = box.query().greater(simpleLong, 1002).build(); assertNull(query.property(simpleByte).findByte()); assertNull(query.property(simpleByte).unique().findByte()); putTestEntities(5); assertEquals((byte) 13, (byte) query.property(simpleByte).findByte()); query = box.query().greater(simpleLong, 1004).build(); assertEquals((byte) 15, (byte) query.property(simpleByte).distinct().unique().findByte()); }
@Test(expected = IllegalArgumentException.class) public void testFindInts_wrongPropertyType() { putTestEntitiesStrings(); box.query().build().property(simpleLong).findInts(); }
@Test(expected = IllegalArgumentException.class) public void testFindStrings_wrongPropertyType() { putTestEntitiesStrings(); box.query().build().property(simpleInt).findStrings(); }
@Test(expected = IllegalArgumentException.class) public void testFindLongs_wrongPropertyType() { putTestEntitiesStrings(); box.query().build().property(simpleInt).findLongs(); }
@Test(expected = IllegalArgumentException.class) public void testFindShorts_wrongPropertyType() { putTestEntitiesStrings(); box.query().build().property(simpleInt).findShorts(); }
@Test(expected = DbException.class) public void testFindInt_uniqueFails() { putTestEntity(null, 1); putTestEntity(null, 1); box.query().build().property(simpleInt).unique().findInt(); }
@Test(expected = DbException.class) public void testFindString_uniqueFails() { putTestEntity("foo", 1); putTestEntity("foo", 2); box.query().build().property(simpleString).unique().findString(); }
@Test(expected = DbException.class) public void testFindByte_uniqueFails() { putTestEntity(null, 1); putTestEntity(null, 1); box.query().build().property(simpleByte).unique().findByte(); }
@Test(expected = DbException.class) public void testFindShort_uniqueFails() { putTestEntity(null, 1); putTestEntity(null, 1); box.query().build().property(simpleShort).unique().findShort(); }
@Test(expected = DbException.class) public void testFindBoolean_uniqueFails() { putTestEntity(null, 1); putTestEntity(null, 1); box.query().build().property(simpleBoolean).unique().findBoolean(); }
@Test(expected = DbException.class) public void testFindFloat_uniqueFails() { putTestEntity(null, 1); putTestEntity(null, 1); box.query().build().property(simpleFloat).unique().findFloat(); }
@Test(expected = DbException.class) public void testFindDouble_uniqueFails() { putTestEntity(null, 1); putTestEntity(null, 1); box.query().build().property(simpleDouble).unique().findDouble(); }
@Test(expected = DbException.class) public void testFindLong_uniqueFails() { putTestEntity(null, 1); putTestEntity(null, 1); box.query().build().property(simpleLong).unique().findLong(); }
@Test public void testSumDoubleOfFloats() { TestEntity entity = new TestEntity(); entity.setSimpleFloat(0); TestEntity entity2 = new TestEntity(); entity2.setSimpleFloat(-2.05f); box.put(entity, entity2); double sum = box.query().build().property(simpleFloat).sumDouble(); assertEquals(-2.05, sum, 0.0001); }
@Test public void testCount() { putTestEntity(null, 1000); putTestEntity("BAR", 100); putTestEntitiesStrings(); putTestEntity("banana", 101); Query<TestEntity> query = box.query().build(); PropertyQuery stringQuery = query.property(simpleString); assertEquals(8, query.count()); assertEquals(7, stringQuery.count()); assertEquals(6, stringQuery.distinct().count()); }