EnrolmentTypeQueryBuilder extends AbstractQueryBuilder<EnrolmentType> { @Override protected BaseQueryBuilder build(final EnrolmentType context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(PARENT_CONDITION, context.getParent()) .addAndCondition(NAME_CONDITION, context.getName()) .addAndCondition(ABBRNAME_CONDITION, context.getAbbrName()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { EnrolmentType context = new EnrolmentType(); String expectedQuery = "SELECT e FROM EnrolmentType e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<EnrolmentType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithOrderBy() throws Exception { EnrolmentType context = new EnrolmentType(); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("name", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("enrolmentType", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3); String expectedQuery = "SELECT e FROM EnrolmentType e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.abbrName ASC, e.name DESC, e.enrolmentType ASC"; MultiplePagedSearch<EnrolmentType> 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); EnrolmentType context = new EnrolmentType(); String expectedQuery = "SELECT e FROM EnrolmentType e WHERE e.status=:status "; MultiplePagedSearch<EnrolmentType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraintWithOrderBy() throws Exception { unit.setSecurity(false); EnrolmentType context = new EnrolmentType(); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("name", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("enrolmentType", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3); String expectedQuery = "SELECT e FROM EnrolmentType e WHERE e.status=:status ORDER BY e.abbrName ASC, e.name DESC, e.enrolmentType ASC"; MultiplePagedSearch<EnrolmentType> 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); EnrolmentType context = new EnrolmentType(); String expectedQuery = "SELECT e FROM EnrolmentType e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<EnrolmentType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraintWithOrderBy() throws Exception { unit.setActive(false); EnrolmentType context = new EnrolmentType(); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("name", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("enrolmentType", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3); String expectedQuery = "SELECT e FROM EnrolmentType e WHERE e.crtUserGroup IN (:userGroups) ORDER BY e.abbrName ASC, e.name DESC, e.enrolmentType ASC"; MultiplePagedSearch<EnrolmentType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledDefaultConstraints() throws Exception { unit.setActive(false); unit.setSecurity(false); EnrolmentType context = new EnrolmentType(); String expectedQuery = "SELECT e FROM EnrolmentType e "; MultiplePagedSearch<EnrolmentType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledDefaultConstraintsWithOrderBy() throws Exception { unit.setActive(false); unit.setSecurity(false); EnrolmentType context = new EnrolmentType(); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("name", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("enrolmentType", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3); String expectedQuery = "SELECT e FROM EnrolmentType e ORDER BY e.abbrName ASC, e.name DESC, e.enrolmentType ASC"; MultiplePagedSearch<EnrolmentType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithOneParameter() throws Exception { String name = "name"; EnrolmentType context = new EnrolmentType(); context.setName(name); String expectedQuery = "SELECT e FROM EnrolmentType e WHERE ( e.name LIKE CONCAT('%',:name,'%') ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<EnrolmentType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithOneParameterWithOrderBy() throws Exception { String name = "name"; EnrolmentType context = new EnrolmentType(); context.setName(name); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("name", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("enrolmentType", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3); String expectedQuery = "SELECT e FROM EnrolmentType e WHERE ( e.name LIKE CONCAT('%',:name,'%') ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.abbrName ASC, e.name DESC, e.enrolmentType ASC"; MultiplePagedSearch<EnrolmentType> 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 = "fsfds"; String name = "name"; EnrolmentType parent = new EnrolmentType(); EnrolmentType context = new EnrolmentType(); context.setName(name); context.setAbbrName(abbrname); context.setParent(parent); String expectedQuery = "SELECT e FROM EnrolmentType e WHERE ( e.parent = :parent AND e.name LIKE CONCAT('%',:name,'%') AND e.abbrName LIKE CONCAT('%',:abbrName,'%') ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<EnrolmentType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersWithOrderBy() throws Exception { String abbrname = "fsfds"; String name = "name"; EnrolmentType context = new EnrolmentType(); context.setName(name); context.setAbbrName(abbrname); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("name", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("enrolmentType", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3); String expectedQuery = "SELECT e FROM EnrolmentType e WHERE ( e.name LIKE CONCAT('%',:name,'%') AND e.abbrName LIKE CONCAT('%',:abbrName,'%') ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.abbrName ASC, e.name DESC, e.enrolmentType ASC"; MultiplePagedSearch<EnrolmentType> 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 = "fsfds"; String name = "name"; EnrolmentType context = new EnrolmentType(); context.setName(name); context.setAbbrName(abbrname); String expectedQuery = "SELECT e FROM EnrolmentType e WHERE ( e.name LIKE CONCAT('%',:name,'%') AND e.abbrName LIKE CONCAT('%',:abbrName,'%') ) "; MultiplePagedSearch<EnrolmentType> 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 = "fsfds"; String name = "name"; EnrolmentType context = new EnrolmentType(); context.setName(name); context.setAbbrName(abbrname); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("name", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("enrolmentType", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3); String expectedQuery = "SELECT e FROM EnrolmentType e WHERE ( e.name LIKE CONCAT('%',:name,'%') AND e.abbrName LIKE CONCAT('%',:abbrName,'%') ) ORDER BY e.abbrName ASC, e.name DESC, e.enrolmentType ASC"; MultiplePagedSearch<EnrolmentType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }