PersonFamilyQueryBuilder extends AbstractQueryBuilder<PersonFamily> { @Override protected BaseQueryBuilder build(final PersonFamily context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(PERSON_CONDITION, context.getPerson()) .addAndCondition(FAMILYTYPE_CONDITION, context.getFamilyType()) .addAndCondition(NAME_CONDITION, context.getName()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { PersonFamily context = new PersonFamily(); String expectedQuery = "SELECT e FROM PersonFamily e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonFamily> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraint() throws Exception { unit.setSecurity(false); PersonFamily context = new PersonFamily(); String expectedQuery = "SELECT e FROM PersonFamily e WHERE e.status=:status "; MultiplePagedSearch<PersonFamily> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraint() throws Exception { unit.setActive(false); PersonFamily context = new PersonFamily(); String expectedQuery = "SELECT e FROM PersonFamily e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonFamily> 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); PersonFamily context = new PersonFamily(); String expectedQuery = "SELECT e FROM PersonFamily e "; MultiplePagedSearch<PersonFamily> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { Person person = new Person(); FamilyType addressType = new FamilyType(); String value = "fasd"; PersonFamily context = new PersonFamily(); context.setPerson(person); context.setFamilyType(addressType); context.setName(value); String expectedQuery = "SELECT e FROM PersonFamily e WHERE ( e.person = :person AND e.familyType = :familyType AND e.name LIKE CONCAT('%',:name,'%') ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonFamily> 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(); FamilyType addressType = new FamilyType(); String value = "fasd"; PersonFamily context = new PersonFamily(); context.setPerson(person); context.setFamilyType(addressType); context.setName(value); String expectedQuery = "SELECT e FROM PersonFamily e WHERE ( e.person = :person AND e.familyType = :familyType AND e.name LIKE CONCAT('%',:name,'%') ) "; MultiplePagedSearch<PersonFamily> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }