private TestEntity putEntity(Cursor<TestEntity> cursor, String text, int number) { TestEntity entity = new TestEntity(); entity.setSimpleString(text); entity.setSimpleInt(number); cursor.put(entity); return entity; }
protected TestEntity createTestEntity(@Nullable String simpleString, int nr) { TestEntity entity = new TestEntity(); entity.setSimpleString(simpleString); entity.setSimpleInt(nr); entity.setSimpleByte((byte) (10 + nr)); entity.setSimpleBoolean(nr % 2 == 0); entity.setSimpleShort((short) (100 + nr)); entity.setSimpleLong(1000 + nr); entity.setSimpleFloat(200 + nr / 10f); entity.setSimpleDouble(2000 + nr / 100f); entity.setSimpleByteArray(new byte[]{1, 2, (byte) nr}); return entity; }
@Test public void testPutGetUpdateGetRemove() { // create an entity TestEntity entity = new TestEntity(); entity.setSimpleInt(1977); entity.setSimpleLong(54321); String value1 = "lulu321"; entity.setSimpleString(value1); long key = box.put(entity); // get it TestEntity entityRead = box.get(key); assertNotNull(entityRead); assertEquals(1977, entityRead.getSimpleInt()); assertEquals(54321, entityRead.getSimpleLong()); assertEquals(value1, entityRead.getSimpleString()); // put with changed values String value2 = "lala123"; entityRead.setSimpleString(value2); entityRead.setSimpleLong(12345); box.put(entityRead); // get the changed entity entityRead = box.get(key); assertNotNull(entityRead); assertEquals(1977, entityRead.getSimpleInt()); assertEquals(12345, entityRead.getSimpleLong()); assertEquals(value2, entityRead.getSimpleString()); // and remove it box.remove(key); assertNull(box.get(key)); }
@Test public void testPutSameIndexValue() { TestEntity entity = new TestEntity(); String value = "lulu321"; entity.setSimpleString(value); Transaction transaction = store.beginTx(); TestEntity read; try { Cursor<TestEntity> cursor = transaction.createCursor(TestEntity.class); long key = cursor.put(entity); // And again entity.setSimpleInt(1977); cursor.put(entity); assertEquals(key, cursor.lookupKeyUsingIndex(9, value)); read = cursor.get(key); cursor.close(); } finally { transaction.close(); } assertEquals(1977, read.getSimpleInt()); assertEquals(value, read.getSimpleString()); }
entity.setSimpleLong(54321); String value1 = "lulu321"; entity.setSimpleString(value1); Transaction transaction = store.beginTx(); Cursor<TestEntity> cursor = transaction.createCursor(TestEntity.class); entityRead.setSimpleString(value2); entityRead.setSimpleLong(12345);
@Test public void testPutAndGet() { TestEntity entity = new TestEntity(); entity.setSimpleInt(1977); entity.setSimpleBoolean(true); entity.setSimpleByte((byte) 42); byte[] bytes = {77, 78}; entity.setSimpleByteArray(bytes); entity.setSimpleDouble(3.141); entity.setSimpleFloat(3.14f); entity.setSimpleLong(789437444354L); entity.setSimpleShort((short) 233); entity.setSimpleString("foo"); long key = box.put(entity); TestEntity entityRead = box.get(key); assertNotNull(entityRead); assertTrue(entityRead.noArgsConstructorCalled); assertEquals(1977, entityRead.getSimpleInt()); assertTrue(entityRead.getSimpleBoolean()); assertEquals(42, entityRead.getSimpleByte()); assertEquals(233, entityRead.getSimpleShort()); assertEquals(789437444354L, entityRead.getSimpleLong()); assertEquals(3.14f, entityRead.getSimpleFloat(), 0.000001f); assertEquals(3.141f, entityRead.getSimpleDouble(), 0.000001); assertTrue(Arrays.equals(bytes, entityRead.getSimpleByteArray())); assertEquals("foo", entityRead.getSimpleString()); }