SubjectQueryBuilder extends AbstractQueryBuilder<Subject> { @Override protected BaseQueryBuilder build(final Subject context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(NAME_CONDITION, context.getName()) .addAndCondition(SUBJECTTYPE_CONDITION, context.getSubjectType()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { Subject context = new Subject(); String expectedQuery = "SELECT e FROM Subject e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<Subject> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraint() throws Exception { unit.setSecurity(false); Subject context = new Subject(); String expectedQuery = "SELECT e FROM Subject e WHERE e.status=:status "; MultiplePagedSearch<Subject> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraint() throws Exception { unit.setActive(false); Subject context = new Subject(); String expectedQuery = "SELECT e FROM Subject e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<Subject> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledDefaultConstraints() throws Exception { Subject context = new Subject(); String expectedQuery = "SELECT e FROM Subject e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<Subject> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { Long subjectTypeId = 1L; SubjectType subjectType = new SubjectType(); subjectType.setId(subjectTypeId); String name = "name"; Subject context = new Subject(); context.setName(name); context.setSubjectType(subjectType); String expectedQuery = "SELECT e FROM Subject e WHERE ( e.name LIKE CONCAT('%',:name,'%') AND e.subjectType = :subjectType ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<Subject> 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); Long subjectTypeId = 1L; SubjectType subjectType = new SubjectType(); subjectType.setId(subjectTypeId); String name = "name"; Subject context = new Subject(); context.setName(name); context.setSubjectType(subjectType); String expectedQuery = "SELECT e FROM Subject e WHERE ( e.name LIKE CONCAT('%',:name,'%') AND e.subjectType = :subjectType ) "; MultiplePagedSearch<Subject> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }