PersonWorkQueryBuilder extends AbstractQueryBuilder<PersonWork> { @Override protected BaseQueryBuilder build(final PersonWork context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(PERSON_CONDITION, context.getPerson()) .addAndCondition(JOBTYPE_CONDITION, context.getJobType()) .addAndCondition(SPECSTAGETYPE_CONDITION, context.getSpecStageType()) .addAndCondition(ORGANIZATIONNAME_CONDITION, context.getOrganizationName()) .addAndCondition(POSTNAME_CONDITION, context.getPostName()) .addAndCondition(DESCRIPTION_CONDITION, context.getDescription()) .addAndCondition(BEGDATE_CONDITION, context.getBegDate()) .addAndCondition(ENDDATE_CONDITION, context.getEndDate()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { PersonWork context = new PersonWork(); String expectedQuery = "SELECT e FROM PersonWork e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonWork> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraint() throws Exception { unit.setSecurity(false); PersonWork context = new PersonWork(); String expectedQuery = "SELECT e FROM PersonWork e WHERE e.status=:status "; MultiplePagedSearch<PersonWork> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraint() throws Exception { unit.setActive(false); PersonWork context = new PersonWork(); String expectedQuery = "SELECT e FROM PersonWork e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonWork> 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); PersonWork context = new PersonWork(); String expectedQuery = "SELECT e FROM PersonWork e "; MultiplePagedSearch<PersonWork> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { Person person = new Person(); JobType jobType = new JobType(); SpecStageType specStageType = new SpecStageType(); String organizationName = "organization name"; String postName = "post name"; String description = "post name"; Date begDate = new Date(); Date endDate = new Date(); PersonWork context = new PersonWork(); context.setPerson(person); context.setJobType(jobType); context.setSpecStageType(specStageType); context.setOrganizationName(organizationName); context.setPostName(postName); context.setDescription(description); context.setBegDate(begDate); context.setEndDate(endDate); String expectedQuery = "SELECT e FROM PersonWork e WHERE ( e.person = :person AND e.jobType = :jobType AND e.specStageType = :specStageType AND e.organizationName LIKE CONCAT('%',:organizationName,'%') AND e.postName LIKE CONCAT('%',:postName,'%') AND e.description LIKE CONCAT('%',:description,'%') AND e.begDate <= :begDate AND e.endDate >= :endDate) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonWork> 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(); JobType jobType = new JobType(); SpecStageType specStageType = new SpecStageType(); String organizationName = "organization name"; String postName = "post name"; String description = "post name"; Date begDate = new Date(); Date endDate = new Date(); PersonWork context = new PersonWork(); context.setPerson(person); context.setJobType(jobType); context.setSpecStageType(specStageType); context.setOrganizationName(organizationName); context.setPostName(postName); context.setDescription(description); context.setBegDate(begDate); context.setEndDate(endDate); String expectedQuery = "SELECT e FROM PersonWork e WHERE ( e.person = :person AND e.jobType = :jobType AND e.specStageType = :specStageType AND e.organizationName LIKE CONCAT('%',:organizationName,'%') AND e.postName LIKE CONCAT('%',:postName,'%') AND e.description LIKE CONCAT('%',:description,'%') AND e.begDate <= :begDate AND e.endDate >= :endDate) "; MultiplePagedSearch<PersonWork> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }