SpecOfferQueryBuilder extends AbstractQueryBuilder<SpecOffer> { @Override protected BaseQueryBuilder build(final SpecOffer context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(PARENT_CONDITION, context.getParent()) .addAndCondition(SPECIALTY_CONDITION, context.getSpecialty()) .addAndCondition(DEPARTMENT_CONDITION, context.getDepartment()) .addAndCondition(TIMEPERIOD_CONDITION, context.getTimePeriod()) .addAndCondition(TIMEPERIODCOURSE_CONDITION, context.getTimePeriodCourse()) .addAndCondition(EDUFORMTYPE_CONDITION, context.getEducationFormType()) .addAndCondition(SPECOFFERTYPE_CONDITION, context.getSpecOfferType()) .addAndCondition(DOCSERIES_CONDITION, context.getDocSeries()) .addAndCondition(DOCNUM_CONDITION, context.getDocNum()) .addAndCondition(LICCOUNT_CONDITION, context.getLicCount()) .addAndCondition(STATECOUNT_CONDITION, context.getStateCount()) .addAndCondition(BEGDATE_CONDITION, context.getBegDate()) .addAndCondition(ENDDATE_CONDITION, context.getEndDate()) .addAndCondition(DURATION_CONDITION, context.getDuration()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { Specialty specialty = new Specialty(); TimePeriod timePeriod = new TimePeriod(); TimePeriod timePeriodCourse = new TimePeriod(); SpecOffer parent = new SpecOffer(); SpecOfferType specOfferType = new SpecOfferType(); EducationFormType educationFormType = new EducationFormType(); Department department = new Department(); String docSeries = "docSeries"; String docNum = "docNum"; Integer licCount = 2; Integer stateCount = 45; SpecOffer context = new SpecOffer(); context.setBegDate(new Date()); context.setEndDate(new Date()); context.setDepartment(department); context.setDocNum(docNum); context.setDocSeries(docSeries); context.setEducationFormType(educationFormType); context.setLicCount(licCount); context.setParent(parent); context.setSpecialty(specialty); context.setSpecOfferType(specOfferType); context.setStateCount(stateCount); context.setTimePeriod(timePeriod); context.setTimePeriodCourse(timePeriodCourse); String expectedQuery = "SELECT e FROM SpecOffer e WHERE ( e.parent = :parent AND e.specialty = :specialty AND e.department = :department AND e.timePeriod = :timePeriod AND e.timePeriodCourse = :timePeriodCourse AND e.educationFormType = :educationFormType AND e.specOfferType :specOfferType AND e.docSeries LIKE CONCAT('%',:docSeries,'%') AND e.docNum LIKE CONCAT('%',:docNum,'%') AND e.licCount = :licCount AND e.stateCount = :stateCount AND e.begDate <= :begDate AND e.endDate >= :endDate ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<SpecOffer> 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); Specialty specialty = new Specialty(); TimePeriod timePeriod = new TimePeriod(); TimePeriod timePeriodCourse = new TimePeriod(); SpecOffer parent = new SpecOffer(); SpecOfferType specOfferType = new SpecOfferType(); EducationFormType educationFormType = new EducationFormType(); Department department = new Department(); String docSeries = "docSeries"; String docNum = "docNum"; Integer licCount = 2; Integer stateCount = 45; String duration = "123123"; SpecOffer context = new SpecOffer(); context.setBegDate(new Date()); context.setEndDate(new Date()); context.setDepartment(department); context.setDocNum(docNum); context.setDocSeries(docSeries); context.setEducationFormType(educationFormType); context.setLicCount(licCount); context.setParent(parent); context.setSpecialty(specialty); context.setSpecOfferType(specOfferType); context.setStateCount(stateCount); context.setTimePeriod(timePeriod); context.setTimePeriodCourse(timePeriodCourse); context.setDuration(duration); String expectedQuery = "SELECT e FROM SpecOffer e WHERE ( e.parent = :parent AND e.specialty = :specialty AND e.department = :department AND e.timePeriod = :timePeriod AND e.timePeriodCourse = :timePeriodCourse AND e.educationFormType = :educationFormType AND e.specOfferType :specOfferType AND e.docSeries LIKE CONCAT('%',:docSeries,'%') AND e.docNum LIKE CONCAT('%',:docNum,'%') AND e.licCount = :licCount AND e.stateCount = :stateCount AND e.begDate <= :begDate AND e.endDate >= :endDate AND e.duration = :duration ) "; MultiplePagedSearch<SpecOffer> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithOneParameter() throws Exception { SpecOffer parent = new SpecOffer(); SpecOffer context = new SpecOffer(); context.setParent(parent); String expectedQuery = "SELECT e FROM SpecOffer e WHERE ( e.parent = :parent ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<SpecOffer> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithExmptyParameters() throws Exception { SpecOffer context = new SpecOffer(); String expectedQuery = "SELECT e FROM SpecOffer e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<SpecOffer> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithExmptyParametersAndDisabledSecurityConstraint() throws Exception { unit.setSecurity(false); SpecOffer context = new SpecOffer(); String expectedQuery = "SELECT e FROM SpecOffer e WHERE e.status=:status "; MultiplePagedSearch<SpecOffer> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithExmptyParametersAndDisabledStatusConstraint() throws Exception { unit.setActive(false); SpecOffer context = new SpecOffer(); String expectedQuery = "SELECT e FROM SpecOffer e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<SpecOffer> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithExmptyParametersAndDisabledDefaultConstraint() throws Exception { unit.setActive(false); unit.setSecurity(false); SpecOffer context = new SpecOffer(); String expectedQuery = "SELECT e FROM SpecOffer e "; MultiplePagedSearch<SpecOffer> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }