Package ru.dreamteam.couch.query

Source Code of ru.dreamteam.couch.query.TestQuery

package ru.dreamteam.couch.query;

import static org.junit.Assert.*;

import java.util.List;

import org.junit.Test;

import ru.dreamteam.couch.BaseTest;
import ru.dreamteam.couch.Db;
import ru.dreamteam.couch.TestEntity;
import ru.dreamteam.couch.query.Query;
import junit.framework.Assert;

/**
* Test {@link Query} with options
* @author dooman
*/
public class TestQuery extends BaseTest {

    private Db db;

    @Override
    public void setUp() throws Exception {
        super.setUp();
        this.db = couch.getDb(testDbName);
        createTestEntity("a");
        createTestEntity("c");
        createTestEntity("d");
        createTestEntity("x");
    }

    private void createTestEntity(String s) {
        TestEntity entity = new TestEntity();
        entity.setText(s);
        db.save(entity);
    }

    @Test
    public void testKeyQuery() {
        List<TestEntity> result = db.query("testview", "byText", TestEntity.class).key("c").list();
        Assert.assertEquals(1, result.size());
    }
   
    @Test
    public void testStartEndKey() {
        List<TestEntity> result = db.query("testview", "byText", TestEntity.class)
                .startKey("c")
                .endKey("s").list();
        Assert.assertEquals(2, result.size());
        Assert.assertEquals("c", result.get(0).getText());
        Assert.assertEquals("d", result.get(1).getText());
    }

    @Test
    public void testCount() throws Exception {
        int count = db.query("testview", "byText", TestEntity.class).count();
        assertEquals(4, count);
    }

    @Test
    public void testCountWithStartKey() throws Exception {
        int count = db.query("testview", "byText", TestEntity.class).startKey("d").count();
        assertEquals(2, count);
    }
}
TOP

Related Classes of ru.dreamteam.couch.query.TestQuery

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.