@Test public void testFindInts_nullValue() { putTestEntity(null, 1); TestEntityCursor.INT_NULL_HACK = true; try { putTestEntities(3); } finally { TestEntityCursor.INT_NULL_HACK = false; } Query<TestEntity> query = box.query().equal(simpleLong, 1001).build(); int[] results = query.property(simpleInt).findInts(); assertEquals(1, results.length); assertEquals(1, results[0]); results = query.property(simpleInt).nullValue(-1977).findInts(); assertEquals(2, results.length); assertEquals(1, results[0]); assertEquals(-1977, results[1]); }
@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 testFindFloats() { putTestEntities(5); Query<TestEntity> query = box.query().greater(simpleInt, 2).build(); float[] result = query.property(simpleFloat).findFloats(); assertEquals(3, result.length); assertEquals(200.3f, result[0], 0.0001f); assertEquals(200.4f, result[1], 0.0001f); assertEquals(200.5f, result[2], 0.0001f); putTestEntity(null, 5); query = box.query().greater(simpleInt, 4).build(); assertEquals(2, query.property(simpleFloat).findFloats().length); assertEquals(1, query.property(simpleFloat).distinct().findFloats().length); }
@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 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 testFindBytes() { putTestEntities(5); Query<TestEntity> query = box.query().greater(simpleByte, 12).build(); byte[] result = query.property(simpleByte).findBytes(); assertEquals(3, result.length); assertEquals(13, result[0]); assertEquals(14, result[1]); assertEquals(15, result[2]); putTestEntity(null, 5); query = box.query().greater(simpleByte, 14).build(); assertEquals(2, query.property(simpleByte).findBytes().length); assertEquals(1, query.property(simpleByte).distinct().findBytes().length); }
@Test public void testFindInts() { putTestEntities(5); Query<TestEntity> query = box.query().greater(simpleInt, 2).build(); int[] result = query.property(simpleInt).findInts(); assertEquals(3, result.length); assertEquals(3, result[0]); assertEquals(4, result[1]); assertEquals(5, result[2]); putTestEntity(null, 5); query = box.query().greater(simpleInt, 4).build(); assertEquals(2, query.property(simpleInt).findInts().length); assertEquals(1, query.property(simpleInt).distinct().findInts().length); }
@Test public void testFindShorts() { putTestEntities(5); Query<TestEntity> query = box.query().greater(simpleInt, 2).build(); short[] result = query.property(simpleShort).findShorts(); assertEquals(3, result.length); assertEquals(103, result[0]); assertEquals(104, result[1]); assertEquals(105, result[2]); putTestEntity(null, 5); query = box.query().greater(simpleInt, 4).build(); assertEquals(2, query.property(simpleShort).findShorts().length); assertEquals(1, query.property(simpleShort).distinct().findShorts().length); }
@Test public void testFindDoubles() { putTestEntities(5); Query<TestEntity> query = box.query().greater(simpleInt, 2).build(); double[] result = query.property(simpleDouble).findDoubles(); assertEquals(3, result.length); assertEquals(2000.03, result[0], 0.0001); assertEquals(2000.04, result[1], 0.0001); assertEquals(2000.05, result[2], 0.0001); putTestEntity(null, 5); query = box.query().greater(simpleInt, 4).build(); assertEquals(2, query.property(simpleDouble).findDoubles().length); assertEquals(1, query.property(simpleDouble).distinct().findDoubles().length); }
@Test public void testFindLongs() { putTestEntities(5); Query<TestEntity> query = box.query().greater(simpleLong, 1002).build(); long[] result = query.property(simpleLong).findLongs(); assertEquals(3, result.length); assertEquals(1003, result[0]); assertEquals(1004, result[1]); assertEquals(1005, result[2]); putTestEntity(null, 5); query = box.query().greater(simpleLong, 1004).build(); assertEquals(2, query.property(simpleLong).findLongs().length); assertEquals(1, query.property(simpleLong).distinct().findLongs().length); }
@Test public void testFindInt() { Query<TestEntity> query = box.query().greater(simpleLong, 1002).build(); assertNull(query.property(simpleInt).findInt()); assertNull(query.property(simpleInt).unique().findInt()); putTestEntities(5); assertEquals(3, (int) query.property(simpleInt).findInt()); query = box.query().greater(simpleLong, 1004).build(); assertEquals(5, (int) query.property(simpleInt).distinct().unique().findInt()); TestEntityCursor.INT_NULL_HACK = true; try { putTestEntity(null, 6); } finally { TestEntityCursor.INT_NULL_HACK = false; } query.setParameter(simpleLong, 1005); assertEquals(-99, (int) query.property(simpleInt).nullValue(-99).unique().findInt()); }
@Test public void testFindString() { Query<TestEntity> query = box.query().greater(simpleLong, 1002).build(); PropertyQuery propertyQuery = query.property(simpleString); assertNull(propertyQuery.findString()); assertNull(propertyQuery.reset().unique().findString()); putTestEntities(5); assertEquals("foo3", propertyQuery.reset().findString()); query = box.query().greater(simpleLong, 1004).build(); propertyQuery = query.property(simpleString); assertEquals("foo5", propertyQuery.reset().unique().findString()); putTestEntity(null, 6); putTestEntity(null, 7); query.setParameter(simpleLong, 1005); assertEquals("nope", propertyQuery.reset().distinct().nullValue("nope").unique().findString()); }