DepartmentNameQueryBuilder extends AbstractQueryBuilder<DepartmentName> { @Override protected BaseQueryBuilder build(final DepartmentName context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(DEPARTMENT_CONDITION, context.getDepartment()) .addAndCondition(LANGUAGE_CONDITION, context.getLanguage()) .addAndCondition(ABBRNAME_CONDITION, context.getAbbrName()) .addAndCondition(NAME_CONDITION, context.getName()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { DepartmentName context = new DepartmentName(); String expectedQuery = "SELECT e FROM DepartmentName e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<DepartmentName> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithOrderBy() throws Exception { DepartmentName context = new DepartmentName(); OrderBy orderBy1 = new OrderBy("department", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("language", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy4 = new OrderBy("name", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3, orderBy4); String expectedQuery = "SELECT e FROM DepartmentName e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.department ASC, e.language DESC, e.abbrName ASC, e.name DESC"; MultiplePagedSearch<DepartmentName> 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); DepartmentName context = new DepartmentName(); String expectedQuery = "SELECT e FROM DepartmentName e WHERE e.status=:status "; MultiplePagedSearch<DepartmentName> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraintWithOrderBy() throws Exception { unit.setSecurity(false); DepartmentName context = new DepartmentName(); OrderBy orderBy1 = new OrderBy("department", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("language", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy4 = new OrderBy("name", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3, orderBy4); String expectedQuery = "SELECT e FROM DepartmentName e WHERE e.status=:status ORDER BY e.department ASC, e.language DESC, e.abbrName ASC, e.name DESC"; MultiplePagedSearch<DepartmentName> 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); DepartmentName context = new DepartmentName(); String expectedQuery = "SELECT e FROM DepartmentName e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<DepartmentName> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraintWithOrderBy() throws Exception { unit.setActive(false); DepartmentName context = new DepartmentName(); OrderBy orderBy1 = new OrderBy("department", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("language", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy4 = new OrderBy("name", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3, orderBy4); String expectedQuery = "SELECT e FROM DepartmentName e WHERE e.crtUserGroup IN (:userGroups) ORDER BY e.department ASC, e.language DESC, e.abbrName ASC, e.name DESC"; MultiplePagedSearch<DepartmentName> 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); DepartmentName context = new DepartmentName(); String expectedQuery = "SELECT e FROM DepartmentName e "; MultiplePagedSearch<DepartmentName> 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); DepartmentName context = new DepartmentName(); OrderBy orderBy1 = new OrderBy("department", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("language", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy4 = new OrderBy("name", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3, orderBy4); String expectedQuery = "SELECT e FROM DepartmentName e ORDER BY e.department ASC, e.language DESC, e.abbrName ASC, e.name DESC"; MultiplePagedSearch<DepartmentName> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { Department department = new Department(); Language language = new Language(); String name = "fdfds"; String abbrName = "asfasf"; DepartmentName context = new DepartmentName(); context.setDepartment(department); context.setLanguage(language); context.setAbbrName(abbrName); context.setName(name); String expectedQuery = "SELECT e FROM DepartmentName e WHERE ( e.department = :department AND e.language = :language AND e.abbrName LIKE CONCAT('%',:abbrName,'%') AND e.name LIKE CONCAT('%',:name,'%') ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<DepartmentName> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersWithOrderBy() throws Exception { Department department = new Department(); Language language = new Language(); String name = "fdfds"; String abbrName = "asfasf"; DepartmentName context = new DepartmentName(); context.setDepartment(department); context.setLanguage(language); context.setAbbrName(abbrName); context.setName(name); OrderBy orderBy1 = new OrderBy("department", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("language", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy4 = new OrderBy("name", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3, orderBy4); String expectedQuery = "SELECT e FROM DepartmentName e WHERE ( e.department = :department AND e.language = :language AND e.abbrName LIKE CONCAT('%',:abbrName,'%') AND e.name LIKE CONCAT('%',:name,'%') ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.department ASC, e.language DESC, e.abbrName ASC, e.name DESC"; MultiplePagedSearch<DepartmentName> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersAndDisabledDefaults() throws Exception { unit.setActive(false); unit.setSecurity(false); Department department = new Department(); Language language = new Language(); String name = "fdfds"; String abbrName = "asfasf"; DepartmentName context = new DepartmentName(); context.setDepartment(department); context.setLanguage(language); context.setAbbrName(abbrName); context.setName(name); String expectedQuery = "SELECT e FROM DepartmentName e WHERE ( e.department = :department AND e.language = :language AND e.abbrName LIKE CONCAT('%',:abbrName,'%') AND e.name LIKE CONCAT('%',:name,'%') ) "; MultiplePagedSearch<DepartmentName> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersAndDisabledDefaultsWithOrderBy() throws Exception { unit.setActive(false); unit.setSecurity(false); Department department = new Department(); Language language = new Language(); String name = "fdfds"; String abbrName = "asfasf"; DepartmentName context = new DepartmentName(); context.setDepartment(department); context.setLanguage(language); context.setAbbrName(abbrName); context.setName(name); OrderBy orderBy1 = new OrderBy("department", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("language", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy4 = new OrderBy("name", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3, orderBy4); String expectedQuery = "SELECT e FROM DepartmentName e WHERE ( e.department = :department AND e.language = :language AND e.abbrName LIKE CONCAT('%',:abbrName,'%') AND e.name LIKE CONCAT('%',:name,'%') ) ORDER BY e.department ASC, e.language DESC, e.abbrName ASC, e.name DESC"; MultiplePagedSearch<DepartmentName> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }