DepartmentSpecialtyQueryBuilder extends AbstractQueryBuilder<DepartmentSpecialty> { @Override protected BaseQueryBuilder build(final DepartmentSpecialty context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(DEPARTMENT_CONDITION, context.getDepartment()) .addAndCondition(SPECIALTY_CONDITION, context.getSpecialty()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { DepartmentSpecialty context = new DepartmentSpecialty(); String expectedQuery = "SELECT e FROM DepartmentSpecialty e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<DepartmentSpecialty> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithOrderBy() throws Exception { DepartmentSpecialty context = new DepartmentSpecialty(); OrderBy orderBy1 = new OrderBy("department", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("specialty", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expectedQuery = "SELECT e FROM DepartmentSpecialty e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.department ASC, e.specialty DESC"; MultiplePagedSearch<DepartmentSpecialty> 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); DepartmentSpecialty context = new DepartmentSpecialty(); String expectedQuery = "SELECT e FROM DepartmentSpecialty e WHERE e.status=:status "; MultiplePagedSearch<DepartmentSpecialty> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraintWithOrderBy() throws Exception { unit.setSecurity(false); DepartmentSpecialty context = new DepartmentSpecialty(); OrderBy orderBy1 = new OrderBy("department", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("specialty", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expectedQuery = "SELECT e FROM DepartmentSpecialty e WHERE e.status=:status ORDER BY e.department ASC, e.specialty DESC"; MultiplePagedSearch<DepartmentSpecialty> 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); DepartmentSpecialty context = new DepartmentSpecialty(); String expectedQuery = "SELECT e FROM DepartmentSpecialty e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<DepartmentSpecialty> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraintWithOrderBy() throws Exception { unit.setActive(false); DepartmentSpecialty context = new DepartmentSpecialty(); OrderBy orderBy1 = new OrderBy("department", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("specialty", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expectedQuery = "SELECT e FROM DepartmentSpecialty e WHERE e.crtUserGroup IN (:userGroups) ORDER BY e.department ASC, e.specialty DESC"; MultiplePagedSearch<DepartmentSpecialty> 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); DepartmentSpecialty context = new DepartmentSpecialty(); String expectedQuery = "SELECT e FROM DepartmentSpecialty e "; MultiplePagedSearch<DepartmentSpecialty> 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); DepartmentSpecialty context = new DepartmentSpecialty(); OrderBy orderBy1 = new OrderBy("department", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("specialty", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expectedQuery = "SELECT e FROM DepartmentSpecialty e ORDER BY e.department ASC, e.specialty DESC"; MultiplePagedSearch<DepartmentSpecialty> 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(); Specialty specialty = new Specialty(); DepartmentSpecialty context = new DepartmentSpecialty(); context.setDepartment(department); context.setSpecialty(specialty); String expectedQuery = "SELECT e FROM DepartmentSpecialty e WHERE ( e.department = :department AND e.specialty = :specialty ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<DepartmentSpecialty> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersWithOrderBy() throws Exception { Department department = new Department(); Specialty specialty = new Specialty(); DepartmentSpecialty context = new DepartmentSpecialty(); context.setDepartment(department); context.setSpecialty(specialty); OrderBy orderBy1 = new OrderBy("department", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("specialty", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expectedQuery = "SELECT e FROM DepartmentSpecialty e WHERE ( e.department = :department AND e.specialty = :specialty ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.department ASC, e.specialty DESC"; MultiplePagedSearch<DepartmentSpecialty> 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(); Specialty specialty = new Specialty(); DepartmentSpecialty context = new DepartmentSpecialty(); context.setDepartment(department); context.setSpecialty(specialty); String expectedQuery = "SELECT e FROM DepartmentSpecialty e WHERE ( e.department = :department AND e.specialty = :specialty ) "; MultiplePagedSearch<DepartmentSpecialty> 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(); Specialty specialty = new Specialty(); DepartmentSpecialty context = new DepartmentSpecialty(); context.setDepartment(department); context.setSpecialty(specialty); OrderBy orderBy1 = new OrderBy("department", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("specialty", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expectedQuery = "SELECT e FROM DepartmentSpecialty e WHERE ( e.department = :department AND e.specialty = :specialty ) ORDER BY e.department ASC, e.specialty DESC"; MultiplePagedSearch<DepartmentSpecialty> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }