SpecOfferWaveQueryBuilder extends AbstractQueryBuilder<SpecOfferWave> { @Override protected BaseQueryBuilder build(final SpecOfferWave context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(SPECOFFER_CONDITION, context.getSpecOffer()) .addAndCondition(WAVETYPE_CONDITION, context.getWaveType()) .addAndCondition(LICCOUNT_CONDITION, context.getLicCount()) .addAndCondition(STATECOUNT_CONDITION, context.getStateCount()) .addAndCondition(BENEFITCOUNT_CONDITION, context.getBenefitCount()) .addAndCondition(TARGETCOUNT_CONDITION, context.getTargetCount()) .addAndCondition(BEGINDATE_CONDITION, context.getBeginDate()) .addAndCondition(ENDDATE_CONDITION, context.getEndDate()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { SpecOfferWave context = new SpecOfferWave(); String expectedQuery = "SELECT e FROM SpecOfferWave e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<SpecOfferWave> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraint() throws Exception { unit.setSecurity(false); SpecOfferWave context = new SpecOfferWave(); String expectedQuery = "SELECT e FROM SpecOfferWave e WHERE e.status=:status "; MultiplePagedSearch<SpecOfferWave> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraint() throws Exception { unit.setActive(false); SpecOfferWave context = new SpecOfferWave(); String expectedQuery = "SELECT e FROM SpecOfferWave e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<SpecOfferWave> 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); SpecOfferWave context = new SpecOfferWave(); String expectedQuery = "SELECT e FROM SpecOfferWave e "; MultiplePagedSearch<SpecOfferWave> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildEmptyParameters() throws Exception { SpecOffer specOffer = new SpecOffer(); WaveType waveType = new WaveType(); Integer licCount = 1; Integer stateCount = 2; Integer targetCount = 3; Integer benefitCount = 4; Date date = new Date(); SpecOfferWave context = new SpecOfferWave(); context.setSpecOffer(specOffer); context.setWaveType(waveType); context.setLicCount(licCount); context.setStateCount(stateCount); context.setTargetCount(targetCount); context.setBenefitCount(benefitCount); context.setBeginDate(date); context.setEndDate(date); String expectedQuery = "SELECT e FROM SpecOfferWave e WHERE ( e.specOffer = :specOffer AND e.waveType = :waveType AND e.licCount =:licCount AND e.stateCount =:stateCount AND e.benefitCount =:benefitCount AND e.targetCount =:targetCount AND e.beginDate >=:beginDate AND e.endDate <=:endDate ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<SpecOfferWave> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildEmptyParametersWithDisabledDefaultConstraints() throws Exception { unit.setActive(false); unit.setSecurity(false); SpecOffer specOffer = new SpecOffer(); WaveType waveType = new WaveType(); Integer licCount = 1; Integer stateCount = 2; Integer targetCount = 3; Integer benefitCount = 4; Date date = new Date(); SpecOfferWave context = new SpecOfferWave(); context.setSpecOffer(specOffer); context.setWaveType(waveType); context.setLicCount(licCount); context.setStateCount(stateCount); context.setTargetCount(targetCount); context.setBenefitCount(benefitCount); context.setBeginDate(date); context.setEndDate(date); String expectedQuery = "SELECT e FROM SpecOfferWave e WHERE ( e.specOffer = :specOffer AND e.waveType = :waveType AND e.licCount =:licCount AND e.stateCount =:stateCount AND e.benefitCount =:benefitCount AND e.targetCount =:targetCount AND e.beginDate >=:beginDate AND e.endDate <=:endDate ) "; MultiplePagedSearch<SpecOfferWave> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }