掲示板
JUnit test case for Dynamic Query
7年前 に Alex Man によって更新されました。
JUnit test case for Dynamic Query
Junior Member 投稿: 70 参加年月日: 16/02/08 最新の投稿
I have a dynamic query like as given below
For the above code I have written a JUnit test cases like as shown below using mokito. I have followed this tutorial for achieving this
returnCollegeDetails() function
But I don't know how to cover the RestrictionsFactoryUtil, ProjectionFactoryUtil and OrderFactoryUtil.
Can anyone please tell me how to do this
DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(College.class, getClassLoader());
dynamicQuery.add(RestrictionsFactoryUtil.eq("collegeName", "SUT"));
dynamicQuery.add(RestrictionsFactoryUtil.eq("collegePlace", "Chennai"));
dynamicQuery.setProjection(ProjectionFactoryUtil.projectionList()
.add(ProjectionFactoryUtil.groupProperty("collegeName"), "collegeName"));
dynamicQuery.addOrder(OrderFactoryUtil.asc("collegeName"));
try {
List<string> collegeDetails = (List<string>)CollegeLocalServiceUtil.dynamicQuery(dynamicQuery, start, end);
} catch (SystemException e) {
e.printStackTrace();
}
</string></string>
For the above code I have written a JUnit test cases like as shown below using mokito. I have followed this tutorial for achieving this
BeanLocator beanLocator = mock(BeanLocator.class);
PortalBeanLocatorUtil.setBeanLocator(beanLocator);
CollegeLocalService collegeLocalService = mock(CollegeLocalService.class);
DynamicQuery dynamicQuery = mock(DynamicQuery.class);
when(beanLocator.locate(CollegeLocalService.class.getName())).thenReturn(collegeLocalService);
when((List<string>)CollegeLocalService.dynamicQuery(dynamicQuery)).thenReturn(returnCollegeDetails());
assertTrue(CollegeLocalService.dynamicQuery(dynamicQuery).size()>0);</string>
returnCollegeDetails() function
private List<string> returnCollegeDetails()
{
List<string> collegeDetails = new ArrayList<string>();
collegeDetails.add("ABC");
collegeDetails.add("DEC");
collegeDetails.add("XYZ");
return collegeDetails;
}</string></string></string>
But I don't know how to cover the RestrictionsFactoryUtil, ProjectionFactoryUtil and OrderFactoryUtil.
Can anyone please tell me how to do this
7年前 に Jignesh Thakkar によって更新されました。
RE: JUnit test case for Dynamic Query
Junior Member 投稿: 26 参加年月日: 10/05/10 最新の投稿
Hi Alex
Did you get solution for this, I am also facing the same problem.
Regards
Jignesh Thakkar
Did you get solution for this, I am also facing the same problem.
Regards
Jignesh Thakkar
7年前 に Alex Man によって更新されました。
RE: JUnit test case for Dynamic Query
Junior Member 投稿: 70 参加年月日: 16/02/08 最新の投稿Jignesh Thakkar:
Hi Alex
Did you get solution for this, I am also facing the same problem.
Regards
Jignesh Thakkar
Till date ...No Jignesh
Do you have any findings on this