Search in sources :

Example 1 with StructSet

use of org.apache.geode.cache.query.internal.StructSet in project geode by apache.

the class StructMemberAccessJUnitTest method testResultComposition.

@Test
public void testResultComposition() throws Exception {
    String[] queries = { "select distinct p from /Portfolios p where p.ID > 0", "select distinct p.getID from /Portfolios p where p.ID > 0 ", "select distinct p.getID as secID from /Portfolios p where p.ID > 0 " };
    for (int i = 0; i < queries.length; i++) {
        Query q = CacheUtils.getQueryService().newQuery(queries[i]);
        Object o = q.execute();
        if (o instanceof SelectResults) {
            SelectResults sr = (SelectResults) o;
            if (sr instanceof StructSet && i != 2)
                fail(" StructMemberAccess::testResultComposition: Got StrcutSet when expecting ResultSet");
            CollectionType ct = sr.getCollectionType();
            CacheUtils.log("***Elememt Type of Colelction = " + ct.getElementType());
            CacheUtils.log((sr.getCollectionType()).getElementType().getSimpleClassName());
            List ls = sr.asList();
            for (int j = 0; j < ls.size(); ++j) CacheUtils.log("Object in the resultset = " + ls.get(j).getClass());
            switch(i) {
                case 0:
                    if (ct.getElementType().getSimpleClassName().equals("Portfolio")) {
                        assertTrue(true);
                    } else {
                        System.out.println("StructMemberAcessJUnitTest::testResultComposition:Colelction Element's class=" + ct.getElementType().getSimpleClassName());
                        fail();
                    }
                    break;
                case 1:
                    if (ct.getElementType().getSimpleClassName().equals("int")) {
                        assertTrue(true);
                    } else {
                        System.out.println("StructMemberAcessJUnitTest::testResultComposition:Colelction Element's class=" + ct.getElementType().getSimpleClassName());
                        fail();
                    }
                    break;
                case 2:
                    if (ct.getElementType().getSimpleClassName().equals("Struct")) {
                        assertTrue(true);
                    } else {
                        System.out.println("StructMemberAcessJUnitTest::testResultComposition:Colelction Element's class=" + ct.getElementType().getSimpleClassName());
                        fail();
                    }
            }
        }
    }
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) StructSet(org.apache.geode.cache.query.internal.StructSet) Query(org.apache.geode.cache.query.Query) CollectionType(org.apache.geode.cache.query.types.CollectionType) List(java.util.List) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

List (java.util.List)1 Query (org.apache.geode.cache.query.Query)1 SelectResults (org.apache.geode.cache.query.SelectResults)1 StructSet (org.apache.geode.cache.query.internal.StructSet)1 CollectionType (org.apache.geode.cache.query.types.CollectionType)1 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)1 Test (org.junit.Test)1