UserGroupViewQueryBuilder extends AbstractQueryBuilder<List<Long>> { @Override protected BaseQueryBuilder build(final List<Long> context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(GROUP_CONDITION_CONDITION, context) .closeBracket(); }    }
@Test public void testBuild() throws Exception { Long group1 = 1L; Long group2 = 2L; List<Long> context = Arrays.asList(group1, group2); String expectedQuery = "SELECT e FROM UserGroupView e WHERE ( e.groupId IN (:groupIds)) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<List<Long>> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatus() throws Exception { unit.setActive(false); Long group1 = 1L; Long group2 = 2L; List<Long> context = Arrays.asList(group1, group2); String expectedQuery = "SELECT e FROM UserGroupView e WHERE ( e.groupId IN (:groupIds)) AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<List<Long>> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledDefaults() throws Exception { unit.setActive(false); unit.setSecurity(false); Long group1 = 1L; Long group2 = 2L; List<Long> context = Arrays.asList(group1, group2); String expectedQuery = "SELECT e FROM UserGroupView e WHERE ( e.groupId IN (:groupIds)) "; MultiplePagedSearch<List<Long>> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurity() throws Exception { unit.setSecurity(false); Long group1 = 1L; Long group2 = 2L; List<Long> context = Arrays.asList(group1, group2); String expectedQuery = "SELECT e FROM UserGroupView e WHERE ( e.groupId IN (:groupIds)) AND e.status=:status "; MultiplePagedSearch<List<Long>> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithEmptyContext() throws Exception { List<Long> context = Collections.emptyList(); String expectedQuery = "SELECT e FROM UserGroupView e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<List<Long>> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithNullContext() throws Exception { List<Long> context = null; String expectedQuery = "SELECT e FROM UserGroupView e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<List<Long>> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }