PersonEducationQueryBuilder extends AbstractQueryBuilder<PersonEducation> { @Override protected BaseQueryBuilder build(final PersonEducation context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(PERSON_CONDITION, context.getPerson()) .addAndCondition(EDUCATIONTYPE_CONDITION, context.getEducationType()) .addAndCondition(PERSONPAPER_CONDITION, context.getPersonPaper()) .addAndCondition(BEGDATE_CONDITION, context.getBegDate()) .addAndCondition(ENDDATE_CONDITION, context.getEndDate()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { PersonEducation context = new PersonEducation(); String expectedQuery = "SELECT e FROM PersonEducation e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonEducation> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraint() throws Exception { unit.setSecurity(false); PersonEducation context = new PersonEducation(); String expectedQuery = "SELECT e FROM PersonEducation e WHERE e.status=:status "; MultiplePagedSearch<PersonEducation> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraint() throws Exception { unit.setActive(false); PersonEducation context = new PersonEducation(); String expectedQuery = "SELECT e FROM PersonEducation e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonEducation> 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); PersonEducation context = new PersonEducation(); String expectedQuery = "SELECT e FROM PersonEducation e "; MultiplePagedSearch<PersonEducation> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { Person person = new Person(); EducationType addressType = new EducationType(); PersonPaper personPaper = new PersonPaper(); Date begDate = new Date(); Date endDate = new Date(); PersonEducation context = new PersonEducation(); context.setPerson(person); context.setEducationType(addressType); context.setPersonPaper(personPaper); context.setBegDate(begDate); context.setEndDate(endDate); String expectedQuery = "SELECT e FROM PersonEducation e WHERE ( e.person = :person AND e.educationType = :educationType AND e.person = :person AND e.begDate <= :begDate AND e.endDate >= :endDate) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonEducation> 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(); EducationType addressType = new EducationType(); PersonPaper personPaper = new PersonPaper(); Date begDate = new Date(); Date endDate = new Date(); PersonEducation context = new PersonEducation(); context.setPerson(person); context.setEducationType(addressType); context.setPersonPaper(personPaper); context.setBegDate(begDate); context.setEndDate(endDate); String expectedQuery = "SELECT e FROM PersonEducation e WHERE ( e.person = :person AND e.educationType = :educationType AND e.person = :person AND e.begDate <= :begDate AND e.endDate >= :endDate) "; MultiplePagedSearch<PersonEducation> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }