PersonContactQueryBuilder extends AbstractQueryBuilder<PersonContact> { @Override protected BaseQueryBuilder build(final PersonContact context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(PERSON_CONDITION, context.getPerson()) .addAndCondition(CONTACTTYPE_CONDITION, context.getContactType()) .addAndCondition(VALUE_CONDITION, context.getValue()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { PersonContact context = new PersonContact(); String expectedQuery = "SELECT e FROM PersonContact e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonContact> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraint() throws Exception { unit.setSecurity(false); PersonContact context = new PersonContact(); String expectedQuery = "SELECT e FROM PersonContact e WHERE e.status=:status "; MultiplePagedSearch<PersonContact> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraint() throws Exception { unit.setActive(false); PersonContact context = new PersonContact(); String expectedQuery = "SELECT e FROM PersonContact e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonContact> 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); PersonContact context = new PersonContact(); String expectedQuery = "SELECT e FROM PersonContact e "; MultiplePagedSearch<PersonContact> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { Person person = new Person(); ContactType addressType = new ContactType(); String value = "fasd"; PersonContact context = new PersonContact(); context.setPerson(person); context.setContactType(addressType); context.setValue(value); String expectedQuery = "SELECT e FROM PersonContact e WHERE ( e.person = :person AND e.contactType = :addressType AND e.value LIKE CONCAT('%',:value,'%') ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonContact> 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(); ContactType addressType = new ContactType(); String value = "fasd"; PersonContact context = new PersonContact(); context.setPerson(person); context.setContactType(addressType); context.setValue(value); String expectedQuery = "SELECT e FROM PersonContact e WHERE ( e.person = :person AND e.contactType = :addressType AND e.value LIKE CONCAT('%',:value,'%') ) "; MultiplePagedSearch<PersonContact> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }