TimePeriodQueryBuilder extends AbstractQueryBuilder<TimePeriod> { @Override protected BaseQueryBuilder build(final TimePeriod context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(PARENT_CONDITION, context.getParent()) .addAndCondition(TIMEPERIOD_CONDITION, context.getTimePeriodType()) .addAndCondition(NAME_CONDITION, context.getName()) .addAndCondition(NUMVALUE_CONDITION, context.getNumValue()) .addAndCondition(BEG_DATE_CONDITION, context.getBegDate()) .addAndCondition(END_DATE_CONDITION, context.getBegDate()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { TimePeriod context = new TimePeriod(); String expectedQuery = "SELECT e FROM TimePeriod e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<TimePeriod> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraint() throws Exception { unit.setActive(false); TimePeriod context = new TimePeriod(); String expectedQuery = "SELECT e FROM TimePeriod e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<TimePeriod> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraint() throws Exception { unit.setSecurity(false); TimePeriod context = new TimePeriod(); String expectedQuery = "SELECT e FROM TimePeriod e WHERE e.status=:status "; MultiplePagedSearch<TimePeriod> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { TimePeriodType timePeriodType = new TimePeriodType(); Integer numValue = 2; TimePeriod context = new TimePeriod(); context.setBegDate(new Date()); context.setTimePeriodType(timePeriodType); context.setNumValue(numValue); String expectedQuery = "SELECT e FROM TimePeriod e WHERE ( e.timePeriodType = :timePeriodType AND e.numValue = :numValue AND e.begDate <= :begDate AND e.endDate >= :endDate) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<TimePeriod> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersAndDisabledDefaultConstraints() throws Exception { unit.setActive(false); unit.setSecurity(false); TimePeriodType timePeriodType = new TimePeriodType(); Integer numValue = 2; TimePeriod context = new TimePeriod(); context.setBegDate(new Date()); context.setTimePeriodType(timePeriodType); context.setNumValue(numValue); String expectedQuery = "SELECT e FROM TimePeriod e WHERE ( e.timePeriodType = :timePeriodType AND e.numValue = :numValue AND e.begDate <= :begDate AND e.endDate >= :endDate) "; MultiplePagedSearch<TimePeriod> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }