SpecOfferSubjectQueryBuilder extends AbstractQueryBuilder<SpecOfferSubject> { @Override protected BaseQueryBuilder build(final SpecOfferSubject context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(SPECOFFER_CONDITION, context.getSpecOffer()) .addAndCondition(ENROLMENTSUBJECT_CONDITION, context.getEnrolmentSubject()) .addAndCondition(MARK_CONDITION, context.getMark()) .addAndCondition(ISMAJOR_CONDITION, context.getIsMajor()) .addAndCondition(ALTERNATIVE_CONDITION, context.getAlternative()) .addAndCondition(WEIGHTSUBJECT_CONDITION, context.getWeightSubject()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { Boolean alternative = false; SpecOfferSubject context = new SpecOfferSubject(); context.setAlternative(alternative); String expected = "SELECT e FROM SpecOfferSubject e WHERE ( e.alternative = :alternative ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<SpecOfferSubject> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraint() throws Exception { unit.setSecurity(false); Boolean alternative = false; SpecOfferSubject context = new SpecOfferSubject(); context.setAlternative(alternative); String expected = "SELECT e FROM SpecOfferSubject e WHERE ( e.alternative = :alternative ) AND e.status=:status "; MultiplePagedSearch<SpecOfferSubject> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraint() throws Exception { unit.setActive(false); Boolean alternative = false; SpecOfferSubject context = new SpecOfferSubject(); context.setAlternative(alternative); String expected = "SELECT e FROM SpecOfferSubject e WHERE ( e.alternative = :alternative ) AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<SpecOfferSubject> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledDefaultConstraints() throws Exception { unit.setActive(false); unit.setSecurity(false); Boolean alternative = false; SpecOfferSubject context = new SpecOfferSubject(); context.setAlternative(alternative); String expected = "SELECT e FROM SpecOfferSubject e WHERE ( e.alternative = :alternative ) "; MultiplePagedSearch<SpecOfferSubject> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithAllParameters() throws Exception { SpecOffer specOffer = new SpecOffer(); EnrolmentSubject enrolmentSubject = new EnrolmentSubject(); Boolean isMajor = false; Double mark = 2.4; Boolean alternative = false; SpecOfferSubject context = new SpecOfferSubject(); context.setAlternative(alternative); context.setSpecOffer(specOffer); context.setEnrolmentSubject(enrolmentSubject); context.setIsMajor(isMajor); context.setMark(mark); String expected = "SELECT e FROM SpecOfferSubject e WHERE ( e.specOffer = :specOffer AND e.enrolmentSubject = :enrolmentSubject AND e.mark = :mark AND e.isMajor = :isMajor AND e.alternative = :alternative ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<SpecOfferSubject> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithAllParametersAndDisabledDefaultConstraints() throws Exception { unit.setActive(false); unit.setSecurity(false); SpecOffer specOffer = new SpecOffer(); EnrolmentSubject enrolmentSubject = new EnrolmentSubject(); Boolean isMajor = false; Double mark = 2.4; Boolean alternative = false; SpecOfferSubject context = new SpecOfferSubject(); context.setAlternative(alternative); context.setSpecOffer(specOffer); context.setEnrolmentSubject(enrolmentSubject); context.setIsMajor(isMajor); context.setMark(mark); String expected = "SELECT e FROM SpecOfferSubject e WHERE ( e.specOffer = :specOffer AND e.enrolmentSubject = :enrolmentSubject AND e.mark = :mark AND e.isMajor = :isMajor AND e.alternative = :alternative ) "; MultiplePagedSearch<SpecOfferSubject> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }