### Question:
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext();  }### Answer:
@Test public void testSeaAdministratorCanSeeSectionAtSchool() { setContext(seaStaff, Arrays.asList(SecureRoleRightAccessImpl.SEA_ADMINISTRATOR)); Set<String> sectionIds = new HashSet<String>(); sectionIds.add(section1.getEntityId()); sectionIds.add(section2.getEntityId()); assertTrue(validator.validate(EntityNames.SECTION, sectionIds).equals(sectionIds)); }
@Test public void testLeaAdministratorCanSeeSectionAtSchool() { setContext(lea1Staff, Arrays.asList(SecureRoleRightAccessImpl.LEA_ADMINISTRATOR)); Set<String> sectionIds = new HashSet<String>(); sectionIds.add(section1.getEntityId()); assertTrue(validator.validate(EntityNames.SECTION, sectionIds).equals(sectionIds)); }
@Test public void testLeaAdministratorCanNotSeeSectionAtSchool() { setContext(lea2Staff, Arrays.asList(SecureRoleRightAccessImpl.LEA_ADMINISTRATOR)); Set<String> sectionIds = new HashSet<String>(); sectionIds.add(section1.getEntityId()); assertFalse(validator.validate(EntityNames.SECTION, sectionIds).equals(sectionIds)); }
@Test public void testSchoolAdministratorCanSeeSectionAtSchool() { setContext(school1Staff, Arrays.asList(SecureRoleRightAccessImpl.IT_ADMINISTRATOR)); Set<String> sectionIds = new HashSet<String>(); sectionIds.add(section1.getEntityId()); assertTrue(validator.validate(EntityNames.SECTION, sectionIds).equals(sectionIds)); }
@Test public void testSchoolAdministratorCanNotSeeSectionAtSchool() { setContext(school2Staff, Arrays.asList(SecureRoleRightAccessImpl.IT_ADMINISTRATOR)); Set<String> sectionIds = new HashSet<String>(); sectionIds.add(section1.getEntityId()); assertFalse(validator.validate(EntityNames.SECTION, sectionIds).equals(sectionIds)); }
@Test public void testEducatorCanSeeSectionAtSchool() { setContext(educator1, Arrays.asList(SecureRoleRightAccessImpl.EDUCATOR)); Set<String> sectionIds = new HashSet<String>(); sectionIds.add(section1.getEntityId()); assertTrue(validator.validate(EntityNames.SECTION, sectionIds).equals(sectionIds)); }
@Test public void testEducatorCanNotSeeSectionAtSchool() { setContext(educator2, Arrays.asList(SecureRoleRightAccessImpl.EDUCATOR)); Set<String> sectionIds = new HashSet<String>(); sectionIds.add(section2.getEntityId()); assertTrue(validator.validate(EntityNames.SECTION, sectionIds).equals(sectionIds)); sectionIds.add(section1.getEntityId()); assertFalse(validator.validate(EntityNames.SECTION, sectionIds).equals(sectionIds)); }