DepartmentContactQueryBuilder extends AbstractQueryBuilder<DepartmentContact> { @Override protected BaseQueryBuilder build(final DepartmentContact context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(DEPARTMENT_CONDITION, context.getDepartment()) .addAndCondition(CONTACTTYPE_CONDITION, context.getContactType()) .addAndCondition(VALUE_CONDITION, context.getValue()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { DepartmentContact context = new DepartmentContact(); String expectedQuery = "SELECT e FROM DepartmentContact e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<DepartmentContact> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithOrderBy() throws Exception { DepartmentContact context = new DepartmentContact(); OrderBy orderBy1 = new OrderBy("department", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("contactType", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("value", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3); String expectedQuery = "SELECT e FROM DepartmentContact e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.department ASC, e.contactType DESC, e.value ASC"; MultiplePagedSearch<DepartmentContact> 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); DepartmentContact context = new DepartmentContact(); String expectedQuery = "SELECT e FROM DepartmentContact e WHERE e.status=:status "; MultiplePagedSearch<DepartmentContact> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraintWithOrderBy() throws Exception { unit.setSecurity(false); DepartmentContact context = new DepartmentContact(); OrderBy orderBy1 = new OrderBy("department", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("contactType", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("value", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3); String expectedQuery = "SELECT e FROM DepartmentContact e WHERE e.status=:status ORDER BY e.department ASC, e.contactType DESC, e.value ASC"; MultiplePagedSearch<DepartmentContact> 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); DepartmentContact context = new DepartmentContact(); String expectedQuery = "SELECT e FROM DepartmentContact e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<DepartmentContact> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraintWithOrderBy() throws Exception { unit.setActive(false); DepartmentContact context = new DepartmentContact(); OrderBy orderBy1 = new OrderBy("department", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("contactType", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("value", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3); String expectedQuery = "SELECT e FROM DepartmentContact e WHERE e.crtUserGroup IN (:userGroups) ORDER BY e.department ASC, e.contactType DESC, e.value ASC"; MultiplePagedSearch<DepartmentContact> 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); DepartmentContact context = new DepartmentContact(); String expectedQuery = "SELECT e FROM DepartmentContact e "; MultiplePagedSearch<DepartmentContact> 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); DepartmentContact context = new DepartmentContact(); OrderBy orderBy1 = new OrderBy("department", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("contactType", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("value", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3); String expectedQuery = "SELECT e FROM DepartmentContact e ORDER BY e.department ASC, e.contactType DESC, e.value ASC"; MultiplePagedSearch<DepartmentContact> 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(); ContactType addressType = new ContactType(); String value = "fasd"; DepartmentContact context = new DepartmentContact(); context.setDepartment(department); context.setContactType(addressType); context.setValue(value); String expectedQuery = "SELECT e FROM DepartmentContact e WHERE ( e.department = :department AND e.contactType = :addressType AND e.value LIKE CONCAT('%',:value,'%') ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<DepartmentContact> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersWithOrderBy() throws Exception { Department department = new Department(); ContactType addressType = new ContactType(); String value = "fasd"; DepartmentContact context = new DepartmentContact(); context.setDepartment(department); context.setContactType(addressType); context.setValue(value); OrderBy orderBy1 = new OrderBy("department", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("contactType", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("value", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3); String expectedQuery = "SELECT e FROM DepartmentContact e WHERE ( e.department = :department AND e.contactType = :addressType AND e.value LIKE CONCAT('%',:value,'%') ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.department ASC, e.contactType DESC, e.value ASC"; MultiplePagedSearch<DepartmentContact> 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(); ContactType addressType = new ContactType(); String value = "fasd"; DepartmentContact context = new DepartmentContact(); context.setDepartment(department); context.setContactType(addressType); context.setValue(value); String expectedQuery = "SELECT e FROM DepartmentContact e WHERE ( e.department = :department AND e.contactType = :addressType AND e.value LIKE CONCAT('%',:value,'%') ) "; MultiplePagedSearch<DepartmentContact> 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(); ContactType addressType = new ContactType(); String value = "fasd"; DepartmentContact context = new DepartmentContact(); context.setDepartment(department); context.setContactType(addressType); context.setValue(value); OrderBy orderBy1 = new OrderBy("department", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("contactType", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("value", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3); String expectedQuery = "SELECT e FROM DepartmentContact e WHERE ( e.department = :department AND e.contactType = :addressType AND e.value LIKE CONCAT('%',:value,'%') ) ORDER BY e.department ASC, e.contactType DESC, e.value ASC"; MultiplePagedSearch<DepartmentContact> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }