PublicActivityQueryBuilder extends AbstractQueryBuilder<PublicActivity> { @Override protected BaseQueryBuilder build(final PublicActivity context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(PUBLICACTIVITYTYPE_CONDITION, context.getPublicActivityTypeType()) .addAndCondition(TIMEPERIOD_CONDITION, context.getTimePeriod()) .addAndCondition(NAME_CONDITION, context.getName()) .addAndCondition(BEGDATE_CONDITION, context.getBegDate()) .addAndCondition(ENDDATE_CONDITION, context.getEndDate()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { PublicActivity context = new PublicActivity(); String expectedQuery = "SELECT e FROM PublicActivity e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PublicActivity> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityCOnstraint() throws Exception { unit.setSecurity(false); PublicActivity context = new PublicActivity(); String expectedQuery = "SELECT e FROM PublicActivity e WHERE e.status=:status "; MultiplePagedSearch<PublicActivity> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusCosntraint() throws Exception { unit.setActive(false); PublicActivity context = new PublicActivity(); String expectedQuery = "SELECT e FROM PublicActivity e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PublicActivity> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledDefaultConstraints() throws Exception { unit.setActive(false); unit.setSecurity(false); PublicActivity context = new PublicActivity(); String expectedQuery = "SELECT e FROM PublicActivity e "; MultiplePagedSearch<PublicActivity> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { String name = "fdsfds"; Date begDate = new Date(); Date endDate = new Date(); TimePeriod timePeriod = new TimePeriod(); PublicActivityType publicActiveType = new PublicActivityType(); PublicActivity context = new PublicActivity(); context.setName(name); context.setBegDate(begDate); context.setEndDate(endDate); context.setTimePeriod(timePeriod); context.setPublicActivityType(publicActiveType); String expectedQuery = "SELECT e FROM PublicActivity e WHERE ( e.publicActivityType=:publicActivityType AND e.timePeriod=:timePeriod AND e.name LIKE CONCAT('%',:name,'%') AND e.begDate <= :begDate AND e.endDate >= :endDate) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PublicActivity> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersWithDisabledDefaultConstraints() throws Exception { unit.setActive(false); unit.setSecurity(false); String name = "fdsfds"; Date begDate = new Date(); Date endDate = new Date(); TimePeriod timePeriod = new TimePeriod(); PublicActivityType publicActiveType = new PublicActivityType(); PublicActivity context = new PublicActivity(); context.setName(name); context.setBegDate(begDate); context.setEndDate(endDate); context.setTimePeriod(timePeriod); context.setPublicActivityType(publicActiveType); String expectedQuery = "SELECT e FROM PublicActivity e WHERE ( e.publicActivityType=:publicActivityType AND e.timePeriod=:timePeriod AND e.name LIKE CONCAT('%',:name,'%') AND e.begDate <= :begDate AND e.endDate >= :endDate) "; MultiplePagedSearch<PublicActivity> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }