EnrolmentSubjectQueryBuilder extends AbstractQueryBuilder<EnrolmentSubject> { @Override protected BaseQueryBuilder build(final EnrolmentSubject context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(PARENT_CONDITION, context.getParent()) .addAndCondition(ABBRNAME_CONDITION, context.getAbbrName()) .addAndCondition(NAME_CONDITION, context.getName()) .addAndCondition(ISTESTING_CONDITION, context.getIsTesting()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { EnrolmentSubject context = new EnrolmentSubject(); String expectedQuery = "SELECT e FROM EnrolmentSubject e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<EnrolmentSubject> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithOrderBy() throws Exception { EnrolmentSubject context = new EnrolmentSubject(); OrderBy orderBy1 = new OrderBy("parent", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("abbrName", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("name", OrderByType.ASC); OrderBy orderBy4 = new OrderBy("isTesting", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3, orderBy4); String expectedQuery = "SELECT e FROM EnrolmentSubject e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.parent ASC, e.abbrName DESC, e.name ASC, e.isTesting DESC"; MultiplePagedSearch<EnrolmentSubject> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraint() throws Exception { unit.setSecurity(false); EnrolmentSubject context = new EnrolmentSubject(); String expectedQuery = "SELECT e FROM EnrolmentSubject e WHERE e.status=:status "; MultiplePagedSearch<EnrolmentSubject> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraintWithOrderBy() throws Exception { unit.setSecurity(false); EnrolmentSubject context = new EnrolmentSubject(); OrderBy orderBy1 = new OrderBy("parent", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("abbrName", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("name", OrderByType.ASC); OrderBy orderBy4 = new OrderBy("isTesting", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3, orderBy4); String expectedQuery = "SELECT e FROM EnrolmentSubject e WHERE e.status=:status ORDER BY e.parent ASC, e.abbrName DESC, e.name ASC, e.isTesting DESC"; MultiplePagedSearch<EnrolmentSubject> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraint() throws Exception { unit.setActive(false); EnrolmentSubject context = new EnrolmentSubject(); String expectedQuery = "SELECT e FROM EnrolmentSubject e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<EnrolmentSubject> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraintWithOrderBy() throws Exception { unit.setActive(false); EnrolmentSubject context = new EnrolmentSubject(); OrderBy orderBy1 = new OrderBy("parent", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("abbrName", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("name", OrderByType.ASC); OrderBy orderBy4 = new OrderBy("isTesting", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3, orderBy4); String expectedQuery = "SELECT e FROM EnrolmentSubject e WHERE e.crtUserGroup IN (:userGroups) ORDER BY e.parent ASC, e.abbrName DESC, e.name ASC, e.isTesting DESC"; MultiplePagedSearch<EnrolmentSubject> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledDefaultConstraint() throws Exception { unit.setActive(false); unit.setSecurity(false); EnrolmentSubject context = new EnrolmentSubject(); String expectedQuery = "SELECT e FROM EnrolmentSubject e "; MultiplePagedSearch<EnrolmentSubject> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledDefaultConstraintWithOrderBy() throws Exception { unit.setActive(false); unit.setSecurity(false); EnrolmentSubject context = new EnrolmentSubject(); OrderBy orderBy1 = new OrderBy("parent", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("abbrName", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("name", OrderByType.ASC); OrderBy orderBy4 = new OrderBy("isTesting", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3, orderBy4); String expectedQuery = "SELECT e FROM EnrolmentSubject e ORDER BY e.parent ASC, e.abbrName DESC, e.name ASC, e.isTesting DESC"; MultiplePagedSearch<EnrolmentSubject> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { String abbrName = "abbrname"; String name = "fgdsfds"; EnrolmentSubject context = new EnrolmentSubject(); context.setAbbrName(abbrName); context.setName(name); String expectedQuery = "SELECT e FROM EnrolmentSubject e WHERE ( e.abbrName LIKE CONCAT('%',:abbrName,'%') AND e.name LIKE CONCAT('%',:name,'%') ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<EnrolmentSubject> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersWithOrderBy() throws Exception { String abbrName = "abbrname"; String name = "fgdsfds"; EnrolmentSubject context = new EnrolmentSubject(); context.setAbbrName(abbrName); context.setName(name); OrderBy orderBy1 = new OrderBy("parent", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("abbrName", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("name", OrderByType.ASC); OrderBy orderBy4 = new OrderBy("isTesting", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3, orderBy4); String expectedQuery = "SELECT e FROM EnrolmentSubject e WHERE ( e.abbrName LIKE CONCAT('%',:abbrName,'%') AND e.name LIKE CONCAT('%',:name,'%') ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.parent ASC, e.abbrName DESC, e.name ASC, e.isTesting DESC"; MultiplePagedSearch<EnrolmentSubject> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersAndDisabledDefaultConstraints() throws Exception { unit.setActive(false); unit.setSecurity(false); String abbrName = "abbrname"; String name = "fgdsfds"; EnrolmentSubject context = new EnrolmentSubject(); context.setAbbrName(abbrName); context.setName(name); String expectedQuery = "SELECT e FROM EnrolmentSubject e WHERE ( e.abbrName LIKE CONCAT('%',:abbrName,'%') AND e.name LIKE CONCAT('%',:name,'%') ) "; MultiplePagedSearch<EnrolmentSubject> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersAndDisabledDefaultConstraintsWithOrderBy() throws Exception { unit.setActive(false); unit.setSecurity(false); String abbrName = "abbrname"; String name = "fgdsfds"; EnrolmentSubject context = new EnrolmentSubject(); context.setAbbrName(abbrName); context.setName(name); OrderBy orderBy1 = new OrderBy("parent", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("abbrName", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("name", OrderByType.ASC); OrderBy orderBy4 = new OrderBy("isTesting", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3, orderBy4); String expectedQuery = "SELECT e FROM EnrolmentSubject e WHERE ( e.abbrName LIKE CONCAT('%',:abbrName,'%') AND e.name LIKE CONCAT('%',:name,'%') ) ORDER BY e.parent ASC, e.abbrName DESC, e.name ASC, e.isTesting DESC"; MultiplePagedSearch<EnrolmentSubject> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }