PersonEnrolmentSubjectQueryBuilder extends AbstractQueryBuilder<PersonEnrolmentSubject> { @Override protected BaseQueryBuilder build(final PersonEnrolmentSubject context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(PERSON_CONDITION, context.getPerson()) .addAndCondition(PERSONPAPER_CONDITION, context.getPersonPaper()) .addAndCondition(ENROLMENTSUBJECT_CONDITION, context.getEnrolmentSubject()) .addAndCondition(MARK_CONDITION, context.getMark()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { PersonEnrolmentSubject context = new PersonEnrolmentSubject(); String expectedQuery = "SELECT e FROM PersonEnrolmentSubject e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonEnrolmentSubject> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraint() throws Exception { unit.setSecurity(false); PersonEnrolmentSubject context = new PersonEnrolmentSubject(); String expectedQuery = "SELECT e FROM PersonEnrolmentSubject e WHERE e.status=:status "; MultiplePagedSearch<PersonEnrolmentSubject> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraint() throws Exception { unit.setActive(false); PersonEnrolmentSubject context = new PersonEnrolmentSubject(); String expectedQuery = "SELECT e FROM PersonEnrolmentSubject e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonEnrolmentSubject> 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); PersonEnrolmentSubject context = new PersonEnrolmentSubject(); String expectedQuery = "SELECT e FROM PersonEnrolmentSubject e "; MultiplePagedSearch<PersonEnrolmentSubject> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { Person person = new Person(); PersonPaper personPaper = new PersonPaper(); EnrolmentSubject enrolmentSubject = new EnrolmentSubject(); Double mark = 4.5; PersonEnrolmentSubject context = new PersonEnrolmentSubject(); context.setPersonPaper(personPaper); context.setEnrolmentSubject(enrolmentSubject); context.setPerson(person); context.setMark(mark); String expectedQuery = "SELECT e FROM PersonEnrolmentSubject e WHERE ( e.person = :person AND e.personPaper = :personPaper AND e.enrolmentSubject = :enrolmentSubject AND e.mark = :mark ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonEnrolmentSubject> 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(); PersonPaper personPaper = new PersonPaper(); EnrolmentSubject enrolmentSubject = new EnrolmentSubject(); Double mark = 4.5; PersonEnrolmentSubject context = new PersonEnrolmentSubject(); context.setPersonPaper(personPaper); context.setEnrolmentSubject(enrolmentSubject); context.setPerson(person); context.setMark(mark); String expectedQuery = "SELECT e FROM PersonEnrolmentSubject e WHERE ( e.person = :person AND e.personPaper = :personPaper AND e.enrolmentSubject = :enrolmentSubject AND e.mark = :mark ) "; MultiplePagedSearch<PersonEnrolmentSubject> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }