EnrolmentBenefitQueryBuilder extends AbstractQueryBuilder<EnrolmentBenefit> { @Override protected BaseQueryBuilder build(final EnrolmentBenefit context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(ENROLMENT_CONDITION, context.getEnrolment()) .addAndCondition(BENEFIT_CONDITION, context.getBenefit()) .addAndCondition(PERSONPAPER_CONDITION, context.getPersonPaper()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { EnrolmentBenefit context = new EnrolmentBenefit(); String expectedQuery = "SELECT e FROM EnrolmentBenefit e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<EnrolmentBenefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithOrderBy() throws Exception { EnrolmentBenefit context = new EnrolmentBenefit(); OrderBy orderBy1 = new OrderBy("enrolment", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("benefit", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("personPaper", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3); String expectedQuery = "SELECT e FROM EnrolmentBenefit e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.enrolment ASC, e.benefit DESC, e.personPaper ASC"; MultiplePagedSearch<EnrolmentBenefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraitns() throws Exception { unit.setSecurity(false); EnrolmentBenefit context = new EnrolmentBenefit(); String expectedQuery = "SELECT e FROM EnrolmentBenefit e WHERE e.status=:status "; MultiplePagedSearch<EnrolmentBenefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraitnsWithOrderBy() throws Exception { unit.setSecurity(false); EnrolmentBenefit context = new EnrolmentBenefit(); OrderBy orderBy1 = new OrderBy("enrolment", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("benefit", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("personPaper", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3); String expectedQuery = "SELECT e FROM EnrolmentBenefit e WHERE e.status=:status ORDER BY e.enrolment ASC, e.benefit DESC, e.personPaper ASC"; MultiplePagedSearch<EnrolmentBenefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraint() throws Exception { unit.setActive(false); EnrolmentBenefit context = new EnrolmentBenefit(); String expectedQuery = "SELECT e FROM EnrolmentBenefit e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<EnrolmentBenefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraintWithOrderBy() throws Exception { unit.setActive(false); EnrolmentBenefit context = new EnrolmentBenefit(); OrderBy orderBy1 = new OrderBy("enrolment", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("benefit", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("personPaper", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3); String expectedQuery = "SELECT e FROM EnrolmentBenefit e WHERE e.crtUserGroup IN (:userGroups) ORDER BY e.enrolment ASC, e.benefit DESC, e.personPaper ASC"; MultiplePagedSearch<EnrolmentBenefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledDefaultConstraints() throws Exception { unit.setActive(false); unit.setSecurity(false); EnrolmentBenefit context = new EnrolmentBenefit(); String expectedQuery = "SELECT e FROM EnrolmentBenefit e "; MultiplePagedSearch<EnrolmentBenefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledDefaultConstraintsWithOrderBy() throws Exception { unit.setActive(false); unit.setSecurity(false); EnrolmentBenefit context = new EnrolmentBenefit(); OrderBy orderBy1 = new OrderBy("enrolment", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("benefit", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("personPaper", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3); String expectedQuery = "SELECT e FROM EnrolmentBenefit e ORDER BY e.enrolment ASC, e.benefit DESC, e.personPaper ASC"; MultiplePagedSearch<EnrolmentBenefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { Enrolment enrolment = new Enrolment(); Benefit benefit = new Benefit(); PersonPaper personpaper = new PersonPaper(); EnrolmentBenefit context = new EnrolmentBenefit(); context.setEnrolment(enrolment); context.setBenefit(benefit); context.setPersonPaper(personpaper); String expectedQuery = "SELECT e FROM EnrolmentBenefit e WHERE ( e.enrolment = :enrolment AND e.benefit =:benefit AND e.personPaper =:personPaper ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<EnrolmentBenefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersWithOrderBy() throws Exception { Enrolment enrolment = new Enrolment(); Benefit benefit = new Benefit(); PersonPaper personpaper = new PersonPaper(); EnrolmentBenefit context = new EnrolmentBenefit(); context.setEnrolment(enrolment); context.setBenefit(benefit); context.setPersonPaper(personpaper); OrderBy orderBy1 = new OrderBy("enrolment", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("benefit", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("personPaper", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3); String expectedQuery = "SELECT e FROM EnrolmentBenefit e WHERE ( e.enrolment = :enrolment AND e.benefit =:benefit AND e.personPaper =:personPaper ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.enrolment ASC, e.benefit DESC, e.personPaper ASC"; MultiplePagedSearch<EnrolmentBenefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersAndDisabledDefaultConstraints() throws Exception { unit.setActive(false); unit.setSecurity(false); Enrolment enrolment = new Enrolment(); Benefit benefit = new Benefit(); PersonPaper personpaper = new PersonPaper(); EnrolmentBenefit context = new EnrolmentBenefit(); context.setEnrolment(enrolment); context.setBenefit(benefit); context.setPersonPaper(personpaper); String expectedQuery = "SELECT e FROM EnrolmentBenefit e WHERE ( e.enrolment = :enrolment AND e.benefit =:benefit AND e.personPaper =:personPaper ) "; MultiplePagedSearch<EnrolmentBenefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersAndDisabledDefaultConstraintsWithOrderBy() throws Exception { unit.setActive(false); unit.setSecurity(false); Enrolment enrolment = new Enrolment(); Benefit benefit = new Benefit(); PersonPaper personpaper = new PersonPaper(); EnrolmentBenefit context = new EnrolmentBenefit(); context.setEnrolment(enrolment); context.setBenefit(benefit); context.setPersonPaper(personpaper); OrderBy orderBy1 = new OrderBy("enrolment", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("benefit", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("personPaper", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3); String expectedQuery = "SELECT e FROM EnrolmentBenefit e WHERE ( e.enrolment = :enrolment AND e.benefit =:benefit AND e.personPaper =:personPaper ) ORDER BY e.enrolment ASC, e.benefit DESC, e.personPaper ASC"; MultiplePagedSearch<EnrolmentBenefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }