PublicActivityAwardQueryBuilder extends AbstractQueryBuilder<PublicActivityAward> { @Override protected BaseQueryBuilder build(final PublicActivityAward context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(PUBLICACTIVITY_CONDITION, context.getPublicActivity()) .addAndCondition(ENROLMENTSUBJECT_CONDITION, context.getEnrolmentSubject()) .addAndCondition(AWARDNAME_CONDITION, context.getAwardName()) .addAndCondition(BEGDATE_CONDITION, context.getBegDate()) .addAndCondition(ENDDATE_CONDITION, context.getEndDate()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { PublicActivityAward context = new PublicActivityAward(); String expectedQuery = "SELECT e FROM PublicActivityAward e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PublicActivityAward> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityCOnstraint() throws Exception { unit.setSecurity(false); PublicActivityAward context = new PublicActivityAward(); String expectedQuery = "SELECT e FROM PublicActivityAward e WHERE e.status=:status "; MultiplePagedSearch<PublicActivityAward> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusCosntraint() throws Exception { unit.setActive(false); PublicActivityAward context = new PublicActivityAward(); String expectedQuery = "SELECT e FROM PublicActivityAward e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PublicActivityAward> 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); PublicActivityAward context = new PublicActivityAward(); String expectedQuery = "SELECT e FROM PublicActivityAward e "; MultiplePagedSearch<PublicActivityAward> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { PublicActivity publicActivity = new PublicActivity(); EnrolmentSubject enrolmentSubject = new EnrolmentSubject(); String awardName = "awatd name"; Date begDate = new Date(); Date endDate = new Date(); PublicActivityAward context = new PublicActivityAward(); context.setBegDate(begDate); context.setEndDate(endDate); context.setAwardName(awardName); context.setEnrolmentSubject(enrolmentSubject); context.setPublicActivity(publicActivity); String expectedQuery = "SELECT e FROM PublicActivityAward e WHERE ( e.publicActivity=:publicActivity AND e.enrolmentSubject=:enrolmentSubject AND e.awardName LIKE CONCAT('%',:awardName,'%') AND e.begDate <= :begDate AND e.endDate >= :endDate) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PublicActivityAward> 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); PublicActivity publicActivity = new PublicActivity(); EnrolmentSubject enrolmentSubject = new EnrolmentSubject(); String awardName = "awatd name"; Date begDate = new Date(); Date endDate = new Date(); PublicActivityAward context = new PublicActivityAward(); context.setBegDate(begDate); context.setEndDate(endDate); context.setAwardName(awardName); context.setEnrolmentSubject(enrolmentSubject); context.setPublicActivity(publicActivity); String expectedQuery = "SELECT e FROM PublicActivityAward e WHERE ( e.publicActivity=:publicActivity AND e.enrolmentSubject=:enrolmentSubject AND e.awardName LIKE CONCAT('%',:awardName,'%') AND e.begDate <= :begDate AND e.endDate >= :endDate) "; MultiplePagedSearch<PublicActivityAward> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }