private List<Group> createTestGroups(String namePrefix, int size) { List<Group> groups = new LinkedList<Group>(); for (int x = 0; x < size; x++) { Group group = mock(Group.class); when(group.getName()).thenReturn(namePrefix + x); groups.add(group); } return groups; }
@Test public void testSearchAll() { List<Group> groups = createTestGroups("group", 20); // First page. AbstractEntityManager.SearchRequest request = new SearchRequestImpl("", 1, 5); AbstractEntityManager.SearchResponse<Group> response = searchEngine.search(groups, request); assertNotNull(response); int total = response.getTotal(); assertEquals(total, 20); boolean hasNextPage = response.hasNextPage(); assertEquals(hasNextPage, true); List<Group> results = response.getResults(); assertEquals(results.size(), 5); Group g = results.get(0); assertEquals("group0", g.getName()); Group g4 = results.get(4); assertEquals("group4", g4.getName()); // Last page. request = new SearchRequestImpl("", 4, 5); response = searchEngine.search(groups, request); assertNotNull(response); total = response.getTotal(); assertEquals(total, 20); hasNextPage = response.hasNextPage(); assertEquals(hasNextPage, false); results = response.getResults(); assertEquals(results.size(), 5); Group g15 = results.get(0); assertEquals("group15", g15.getName()); Group g19 = results.get(4); assertEquals("group19", g19.getName()); }
@Test public void testSearchSingle() { List<Group> groups = createTestGroups("group", 20); AbstractEntityManager.SearchRequest request = new SearchRequestImpl("group18", 1, 5); AbstractEntityManager.SearchResponse<Group> response = searchEngine.search(groups, request); assertNotNull(response); int total = response.getTotal(); assertEquals(total, 1); boolean hasNextPage = response.hasNextPage(); assertEquals(hasNextPage, false); List<Group> results = response.getResults(); assertEquals(results.size(), 1); Group g = results.get(0); assertEquals("group18", g.getName()); }
/** * Generates a dataset filter depending of the user roles and the kind of dataset. <br> * In case of the adminDataset (isAdminDateset=true), retrieve the tasks that are accessible for * the user logged roles, without restriction over the task owner. <br> * In other cases, retrieve the tasks available for the user logged roles AND without * owner(claimed by the groups members) OR the user logged owned tasks * * @param isAdminDataset true if the filter to create is an adminDataSet * @return the dynamic filter to add, depeding on the user logged roles and the kind of dataset */ protected ColumnFilter getUserGroupFilters(boolean isAdminDataset) { Set<Group> groups = identity.getGroups(); List<ColumnFilter> condList = new ArrayList<ColumnFilter>(); for (Group g : groups) { condList.add(equalsTo(COLUMN_ORGANIZATIONAL_ENTITY, g.getName())); } condList.add(equalsTo(COLUMN_ORGANIZATIONAL_ENTITY, identity.getIdentifier())); ColumnFilter myGroupFilter; if (isAdminDataset) { return OR(COLUMN_ORGANIZATIONAL_ENTITY, condList); } else { myGroupFilter = AND(OR(condList), OR(equalsTo(COLUMN_ACTUAL_OWNER, ""), isNull(COLUMN_ACTUAL_OWNER))); return OR(myGroupFilter, equalsTo(COLUMN_ACTUAL_OWNER, identity.getIdentifier())); } }
@Test public void testSearchMultiple() { List<Group> groups = createTestGroups("group", 20); // First page. AbstractEntityManager.SearchRequest request = new SearchRequestImpl("group1", 1, 5); AbstractEntityManager.SearchResponse<Group> response = searchEngine.search(groups, request); assertNotNull(response); int total = response.getTotal(); assertEquals(total, 11); boolean hasNextPage = response.hasNextPage(); assertEquals(hasNextPage, true); List<Group> results = response.getResults(); assertEquals(results.size(), 5); Group g0 = results.get(0); assertEquals("group1", g0.getName()); Group g10 = results.get(1); assertEquals("group10", g10.getName()); Group g13 = results.get(4); assertEquals("group13", g13.getName()); // Second page. request = new SearchRequestImpl("group1", 2, 5); response = searchEngine.search(groups, request); assertNotNull(response); total = response.getTotal(); assertEquals(total, 11); hasNextPage = response.hasNextPage(); assertEquals(hasNextPage, true); results = response.getResults(); assertEquals(results.size(), 5); Group g14 = results.get(0); assertEquals("group14", g14.getName()); Group g15 = results.get(1); assertEquals("group15", g15.getName()); Group g18 = results.get(4); assertEquals("group18", g18.getName()); // Third page. request = new SearchRequestImpl("group1", 3, 5); response = searchEngine.search(groups, request); assertNotNull(response); total = response.getTotal(); assertEquals(total, 11); hasNextPage = response.hasNextPage(); assertEquals(hasNextPage, false); results = response.getResults(); assertEquals(results.size(), 1); Group g19 = results.get(0); assertEquals("group19", g19.getName()); }
private void assertGroup(Group group, String name) { assertNotNull(group); assertEquals(name, group.getName()); }