PersonNameQueryBuilder extends AbstractQueryBuilder<PersonName> { @Override protected BaseQueryBuilder build(final PersonName context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(PERSON_CONDITION, context.getPerson()) .addAndCondition(LANGUAGE_CONDITION, context.getLanguage()) .addAndCondition(NAME_CONDITION, context.getName()) .addAndCondition(FIRSTNAME_CONDITION, context.getFirstName()) .addAndCondition(LASTNAME_CONDITION, context.getFatherName()) .addAndCondition(SURNAME_CONDITION, context.getSurname()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { PersonName context = new PersonName(); String expected = "SELECT e FROM PersonName e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonName> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraint() throws Exception { unit.setSecurity(false); PersonName context = new PersonName(); String expected = "SELECT e FROM PersonName e WHERE e.status=:status "; MultiplePagedSearch<PersonName> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraint() throws Exception { unit.setActive(false); PersonName context = new PersonName(); String expected = "SELECT e FROM PersonName e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonName> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledDefaultConstraints() throws Exception { unit.setActive(false); unit.setSecurity(false); PersonName context = new PersonName(); String expected = "SELECT e FROM PersonName e "; MultiplePagedSearch<PersonName> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { Person person = new Person(); Language language = new Language(); String name = "fdsfds"; String firstName = "fdsfds"; String fatherName = "rewrtewt"; String surname = "cvdfgfdh"; PersonName context = new PersonName(); context.setPerson(person); context.setLanguage(language); context.setName(name); context.setFirstName(firstName); context.setFatherName(fatherName); context.setSurname(surname); String expected = "SELECT e FROM PersonName e WHERE ( e.person = :person AND .language = :language AND e.name LIKE CONCAT('%',:name,'%') AND e.firstName LIKE CONCAT('%',:name,'%') AND e.fatherName LIKE CONCAT('%',:fatherName,'%') AND e.surname LIKE CONCAT('%',:surname,'%') ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonName> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithParametersAndDisabledDefaultConstraints() throws Exception { unit.setActive(false); unit.setSecurity(false); Person person = new Person(); Language language = new Language(); String name = "fdsfds"; String firstName = "fdsfds"; String fatherName = "rewrtewt"; String surname = "cvdfgfdh"; PersonName context = new PersonName(); context.setPerson(person); context.setLanguage(language); context.setName(name); context.setFirstName(firstName); context.setFatherName(fatherName); context.setSurname(surname); String expected = "SELECT e FROM PersonName e WHERE ( e.person = :person AND .language = :language AND e.name LIKE CONCAT('%',:name,'%') AND e.firstName LIKE CONCAT('%',:name,'%') AND e.fatherName LIKE CONCAT('%',:fatherName,'%') AND e.surname LIKE CONCAT('%',:surname,'%') ) "; MultiplePagedSearch<PersonName> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }