PersonPensionQueryBuilder extends AbstractQueryBuilder<PersonPension> { @Override protected BaseQueryBuilder build(final PersonPension context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(PERSON_CONDITION, context.getPerson()) .addAndCondition(CONTACTTYPE_CONDITION, context.getPensionType()) .addAndCondition(BEGDATE_CONDITION, context.getBegDate()) .addAndCondition(ENDDATE_CONDITION, context.getEndDate()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { PersonPension context = new PersonPension(); String expectedQuery = "SELECT e FROM PersonPension e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonPension> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraint() throws Exception { unit.setSecurity(false); PersonPension context = new PersonPension(); String expectedQuery = "SELECT e FROM PersonPension e WHERE e.status=:status "; MultiplePagedSearch<PersonPension> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraint() throws Exception { unit.setActive(false); PersonPension context = new PersonPension(); String expectedQuery = "SELECT e FROM PersonPension e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonPension> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledDefaultConstraint() throws Exception { unit.setActive(false); unit.setSecurity(false); PersonPension context = new PersonPension(); String expectedQuery = "SELECT e FROM PersonPension e "; MultiplePagedSearch<PersonPension> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { Person person = new Person(); PensionType addressType = new PensionType(); Date begDate = new Date(); Date endDate = new Date(); PersonPension context = new PersonPension(); context.setPerson(person); context.setPensionType(addressType); context.setBegDate(begDate); context.setEndDate(endDate); String expectedQuery = "SELECT e FROM PersonPension e WHERE ( e.person = :person AND e.contactType = :addressType AND e.begDate <= :begDate AND e.endDate >= :endDate) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonPension> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersAndDisabledDefaults() throws Exception { unit.setActive(false); unit.setSecurity(false); Person person = new Person(); PensionType addressType = new PensionType(); Date begDate = new Date(); Date endDate = new Date(); PersonPension context = new PersonPension(); context.setPerson(person); context.setPensionType(addressType); context.setBegDate(begDate); context.setEndDate(endDate); String expectedQuery = "SELECT e FROM PersonPension e WHERE ( e.person = :person AND e.contactType = :addressType AND e.begDate <= :begDate AND e.endDate >= :endDate) "; MultiplePagedSearch<PersonPension> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }