PersonPaperQueryBuilder extends AbstractQueryBuilder<PersonPaper> { @Override protected BaseQueryBuilder build(final PersonPaper context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(PERSON_CONDITION, context.getPerson()) .addAndCondition(PAPERTYPE_CONDITION, context.getPaperType()) .addAndCondition(HONORS_TYPE, context.getHonorsType()) .addAndCondition(DOC_DATE_CONDITION, context.getDocDate()) .addAndCondition(DOCSERIES_CONDITION, context.getDocSeries()) .addAndCondition(DOCNUM_CONDITION, context.getDocNum()) .addAndCondition(DOCISSUED_CONDITION, context.getDocIssued()) .addAndCondition(DOCPIN_CONDITION, context.getDocPin()) .addAndCondition(MARK_CONDITION, context.getMark()) .addAndCondition(ISCHECKED_CONDITION, context.getIsChecked()) .addAndCondition(ISFOREIGN_CONDITION, context.getIsForeign()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { PersonPaper context = new PersonPaper(); String expectedQuery = "SELECT e FROM PersonPaper e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonPaper> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraint() throws Exception { unit.setSecurity(false); PersonPaper context = new PersonPaper(); String expectedQuery = "SELECT e FROM PersonPaper e WHERE e.status=:status "; MultiplePagedSearch<PersonPaper> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraint() throws Exception { unit.setActive(false); PersonPaper context = new PersonPaper(); String expectedQuery = "SELECT e FROM PersonPaper e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonPaper> 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); PersonPaper context = new PersonPaper(); String expectedQuery = "SELECT e FROM PersonPaper e "; MultiplePagedSearch<PersonPaper> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { Person person = new Person(); PaperType paperType = new PaperType(); HonorType honorsType = new HonorType(); Date docDate = new Date(); String docSeries = "dfds"; String docNum = "fdssd"; String docIssued = "fdssd"; String docPin = "asfas xc"; Integer isChecked = 1; Integer isForeign = 2; Double mark = 4.5; PersonPaper context = new PersonPaper(); context.setPerson(person); context.setPaperType(paperType); context.setHonorsType(honorsType); context.setDocDate(docDate); context.setDocSeries(docSeries); context.setDocNum(docNum); context.setDocIssued(docIssued); context.setDocPin(docPin); context.setMark(mark); context.setIsChecked(isChecked); context.setIsForeign(isForeign); String expectedQuery = "SELECT e FROM PersonPaper e WHERE ( e.person = :person AND e.paperType = :paperType AND e.honorsType = :honorsType AND e.docDate = :docDate AND e.docSeries LIKE CONCAT('%',:docSeries,'%') AND e.docNum LIKE CONCAT('%',:docNum,'%') AND e.docIssued = :docIssued AND e.docPin = :docPin AND e.mark = :mark AND e.isChecked = :isChecked AND e.isForeign = :isForeign ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonPaper> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersWithDisabledDEfaultConstraints() throws Exception { unit.setActive(false); unit.setSecurity(false); Person person = new Person(); PaperType paperType = new PaperType(); HonorType honorsType = new HonorType(); Date docDate = new Date(); String docSeries = "dfds"; String docNum = "fdssd"; String docIssued = "fdssd"; String docPin = "asfas xc"; Integer isChecked = 1; Integer isForeign = 2; Double mark = 4.5; PersonPaper context = new PersonPaper(); context.setPerson(person); context.setPaperType(paperType); context.setHonorsType(honorsType); context.setDocDate(docDate); context.setDocSeries(docSeries); context.setDocNum(docNum); context.setDocIssued(docIssued); context.setDocPin(docPin); context.setMark(mark); context.setIsChecked(isChecked); context.setIsForeign(isForeign); String expectedQuery = "SELECT e FROM PersonPaper e WHERE ( e.person = :person AND e.paperType = :paperType AND e.honorsType = :honorsType AND e.docDate = :docDate AND e.docSeries LIKE CONCAT('%',:docSeries,'%') AND e.docNum LIKE CONCAT('%',:docNum,'%') AND e.docIssued = :docIssued AND e.docPin = :docPin AND e.mark = :mark AND e.isChecked = :isChecked AND e.isForeign = :isForeign ) "; MultiplePagedSearch<PersonPaper> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }