PersonAddressQueryBuilder extends AbstractQueryBuilder<PersonAddress> { @Override protected BaseQueryBuilder build(final PersonAddress context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(PERSON_CONDITION, context.getPerson()) .addAndCondition(ADRESS_TYPE_CONDITION, context.getAddressType()) .addAndCondition(ADMINUNIT_CONDITION, context.getAdminUnit()) .addAndCondition(STREETTYPE_CONDITION, context.getStreetType()) .addAndCondition(ASSET_CONDITION, context.getAsset()) .addAndCondition(ZIPCODE_CONDITION, context.getZipCode()) .addAndCondition(STREET_CONDITION, context.getStreet()) .addAndCondition(HOUSE_CONDITION, context.getHouse()) .addAndCondition(APARTMENT_CONDITION, context.getApartment()) .addAndCondition(BEGDATE_CONDITION, context.getBegDate()) .addAndCondition(ENDDATE_CONDITION, context.getEndDate()) .closeBracket(); }    }
@Test public void testBuildWithParameters() throws Exception { Person person = new Person(); AddressType addressType = new AddressType(); AdminUnit adminUnit = new AdminUnit(); StreetType streetType = new StreetType(); Date begDate = new Date(); Date endDate = new Date(); PersonAddress context = new PersonAddress(); context.setPerson(person); context.setAddressType(addressType); context.setAdminUnit(adminUnit); context.setStreetType(streetType); context.setBegDate(begDate); context.setEndDate(endDate); String expectedQuery = "SELECT e FROM PersonAddress e WHERE ( e.person = :person AND e.addressType = :addressType AND e.adminUnit = :adminUnit AND e.streetType =:streetType AND e.begDate <= :begDate AND e.endDate >= :endDate ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonAddress> 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); Person person = new Person(); AddressType addressType = new AddressType(); AdminUnit adminUnit = new AdminUnit(); StreetType streetType = new StreetType(); Date begDate = new Date(); Date endDate = new Date(); PersonAddress context = new PersonAddress(); context.setPerson(person); context.setAddressType(addressType); context.setAdminUnit(adminUnit); context.setStreetType(streetType); context.setBegDate(begDate); context.setEndDate(endDate); String expectedQuery = "SELECT e FROM PersonAddress e WHERE ( e.person = :person AND e.addressType = :addressType AND e.adminUnit = :adminUnit AND e.streetType =:streetType AND e.begDate <= :begDate AND e.endDate >= :endDate ) "; MultiplePagedSearch<PersonAddress> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuild() throws Exception { PersonAddress context = new PersonAddress(); String expectedQuery = "SELECT e FROM PersonAddress e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonAddress> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraint() throws Exception { unit.setSecurity(false); PersonAddress context = new PersonAddress(); String expectedQuery = "SELECT e FROM PersonAddress e WHERE e.status=:status "; MultiplePagedSearch<PersonAddress> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraint() throws Exception { unit.setActive(false); PersonAddress context = new PersonAddress(); String expectedQuery = "SELECT e FROM PersonAddress e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonAddress> 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); PersonAddress context = new PersonAddress(); String expectedQuery = "SELECT e FROM PersonAddress e "; MultiplePagedSearch<PersonAddress> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }