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();
}
}
}
}
}
Aggregations