Package com.mysema.query.collections

Source Code of com.mysema.query.collections.DocumentTest

package com.mysema.query.collections;

import static org.junit.Assert.assertTrue;

import java.util.List;

import org.junit.Before;
import org.junit.Test;

import com.mysema.query.types.Predicate;

public class DocumentTest {

    private Document doc1, doc2, doc3;

    private QDocument qDoc = QDocument.document;

    @Before
    public void setUp() {
        doc1 = new Document();
        doc1.setId(1L);
        doc1.getMeshThesaurusTerms().add("x");

        doc2 = new Document();
        doc2.setId(2L);

        doc3 = new Document();
        doc3.setId(3L);
    }

    @Test
    public void test1() {
        Predicate crit = qDoc.id.eq(3L);
        List<Document> expResult = CollQueryFactory.from(qDoc, doc1, doc2, doc3).where(crit).list(qDoc);
        assertTrue(expResult.contains(doc3)); //ok
    }

    @Test
    public void test2() {
        Predicate crit = qDoc.meshThesaurusTerms.any().eq("x");
        List<Document> expResult = CollQueryFactory.from(qDoc, doc1, doc2, doc3).where(crit).list(qDoc);
        assertTrue(expResult.contains(doc1)); //ok
    }

    @Test
    public void test3() {
        Predicate crit = qDoc.meshThesaurusTerms.any().eq("x").or(qDoc.id.eq(3L));
        List<Document> expResult =  CollQueryFactory.from(qDoc, doc1, doc2, doc3).where(crit).list(qDoc);
        assertTrue(expResult.contains(doc1));
        assertTrue(expResult.contains(doc3)); //fails, expResult contains only doc1, but should contain doc1 and doc3!
    }

    @Test
    public void test4() {
        Predicate crit = qDoc.id.eq(3L).or(qDoc.meshThesaurusTerms.any().eq("x"));
        List<Document> expResult =  CollQueryFactory.from(qDoc, doc1, doc2, doc3).where(crit).list(qDoc);
        assertTrue(expResult.contains(doc1));
        assertTrue(expResult.contains(doc3)); //fails, expResult contains only doc1, but should contain doc1 and doc3!
    }

}
TOP

Related Classes of com.mysema.query.collections.DocumentTest

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.