DepartmentTypeQueryBuilder extends AbstractQueryBuilder<DepartmentType> { @Override protected BaseQueryBuilder build(final DepartmentType context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(NAME_CONDITION, context.getName()) .addAndCondition(ABBR_NAME_CONDITION, context.getAbbrName()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { DepartmentType context = new DepartmentType(); String expected = "SELECT e FROM DepartmentType e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<DepartmentType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithOrderBy() throws Exception { DepartmentType context = new DepartmentType(); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("name", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expected = "SELECT e FROM DepartmentType e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.abbrName ASC, e.name DESC"; MultiplePagedSearch<DepartmentType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledSecuirtyConstraint() throws Exception { unit.setSecurity(false); DepartmentType context = new DepartmentType(); String expected = "SELECT e FROM DepartmentType e WHERE e.status=:status "; MultiplePagedSearch<DepartmentType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledSecuirtyConstraintWithOrderBy() throws Exception { unit.setSecurity(false); DepartmentType context = new DepartmentType(); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("name", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expected = "SELECT e FROM DepartmentType e WHERE e.status=:status ORDER BY e.abbrName ASC, e.name DESC"; MultiplePagedSearch<DepartmentType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledStautsConstaint() throws Exception { unit.setActive(false); DepartmentType context = new DepartmentType(); String expected = "SELECT e FROM DepartmentType e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<DepartmentType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledStautsConstaintWithOrderBy() throws Exception { unit.setActive(false); DepartmentType context = new DepartmentType(); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("name", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expected = "SELECT e FROM DepartmentType e WHERE e.crtUserGroup IN (:userGroups) ORDER BY e.abbrName ASC, e.name DESC"; MultiplePagedSearch<DepartmentType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledDefaultConstaitns() throws Exception { unit.setActive(false); unit.setSecurity(false); DepartmentType context = new DepartmentType(); String expected = "SELECT e FROM DepartmentType e "; MultiplePagedSearch<DepartmentType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledDefaultConstaitnsWithOrderBy() throws Exception { unit.setActive(false); unit.setSecurity(false); DepartmentType context = new DepartmentType(); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("name", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expected = "SELECT e FROM DepartmentType e ORDER BY e.abbrName ASC, e.name DESC"; MultiplePagedSearch<DepartmentType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { String name = "name"; String abbrName = "abbr name"; DepartmentType context = new DepartmentType(); context.setAbbrName(abbrName); context.setName(name); String expected = "SELECT e FROM DepartmentType e WHERE ( e.name LIKE CONCAT('%',:name,'%') AND e.abbrName LIKE CONCAT('%',:abbrName,'%') ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<DepartmentType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithParametersWithOrderBy() throws Exception { String name = "name"; String abbrName = "abbr name"; DepartmentType context = new DepartmentType(); context.setAbbrName(abbrName); context.setName(name); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("name", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expected = "SELECT e FROM DepartmentType 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"; MultiplePagedSearch<DepartmentType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithParametersAndDisabledDefaultConstaints() throws Exception { unit.setActive(false); unit.setSecurity(false); String name = "name"; String abbrName = "abbr name"; DepartmentType context = new DepartmentType(); context.setAbbrName(abbrName); context.setName(name); String expected = "SELECT e FROM DepartmentType e WHERE ( e.name LIKE CONCAT('%',:name,'%') AND e.abbrName LIKE CONCAT('%',:abbrName,'%') ) "; MultiplePagedSearch<DepartmentType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithParametersAndDisabledDefaultConstaintsWithOrderBy() throws Exception { unit.setActive(false); unit.setSecurity(false); String name = "name"; String abbrName = "abbr name"; DepartmentType context = new DepartmentType(); context.setAbbrName(abbrName); context.setName(name); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("name", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expected = "SELECT e FROM DepartmentType e WHERE ( e.name LIKE CONCAT('%',:name,'%') AND e.abbrName LIKE CONCAT('%',:abbrName,'%') ) ORDER BY e.abbrName ASC, e.name DESC"; MultiplePagedSearch<DepartmentType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }