@Test public void testComplex() { existingSection.getBody().put(ParameterConstants.SCHOOL_ID, ED_ORG_B); String GRADEBOOK_ID = "gradebook-id"; Entity gradebookEntity = new MongoEntity(EntityNames.GRADEBOOK_ENTRY, GRADEBOOK_ID, new HashMap<String, Object>(), null); gradebookEntity.getBody().put(ParameterConstants.SECTION_ID, SECTION_ID); when(repo.findById(EntityNames.GRADEBOOK_ENTRY, GRADEBOOK_ID)).thenReturn(gradebookEntity); final List<PathSegment> path = createPathSegmentsFromStrings(PathConstants.V1, ResourceNames.GRADEBOOK_ENTRIES, GRADEBOOK_ID); when(uriInfo.getPathSegments()).thenReturn(path); writeValidator.validateWriteRequest(null, uriInfo, principal); { existingSection.getBody().put(ParameterConstants.SCHOOL_ID, UN_ASSOCIATED_ED_ORG); boolean threw = false; try { writeValidator.validateWriteRequest(null, uriInfo, principal); } catch (AccessDeniedException e) { threw = true; } Assert.assertTrue("should fail validation and throw error", threw); } }
public void validateWriteRequest(EntityBody entityBody, UriInfo uriInfo, SLIPrincipal principal) { targetEdOrgIds = new HashSet<String>(); if (isWriteValidationEnabled && !isValidForEdOrgWrite(entityBody, uriInfo, principal)) { throw new APIAccessDeniedException("Invalid reference. No association to referenced entity.", targetEdOrgIds); } }
WriteValidator { public void validateWriteRequest(EntityBody entityBody, UriInfo uriInfo, SLIPrincipal principal) { targetEdOrgIds = new HashSet<String>(); if (isWriteValidationEnabled && !isValidForEdOrgWrite(entityBody, uriInfo, principal)) { throw new APIAccessDeniedException("Invalid reference. No association to referenced entity.", targetEdOrgIds); } } }
WriteValidator { public void validateWriteRequest(EntityBody entityBody, UriInfo uriInfo, SLIPrincipal principal) { targetEdOrgIds = new HashSet<String>(); if (isWriteValidationEnabled && !isValidForEdOrgWrite(entityBody, uriInfo, principal)) { throw new APIAccessDeniedException("Invalid reference. No association to referenced entity.", targetEdOrgIds); } }  }
WriteValidator { public void validateWriteRequest(EntityBody entityBody, UriInfo uriInfo, SLIPrincipal principal) { targetEdOrgIds = new HashSet<String>(); if (isWriteValidationEnabled && !isValidForEdOrgWrite(entityBody, uriInfo, principal)) { throw new APIAccessDeniedException("Invalid reference. No association to referenced entity.", targetEdOrgIds); } }  void validateWriteRequest(EntityBody entityBody, UriInfo uriInfo, SLIPrincipal principal); void setRepo(PagingRepositoryDelegate<Entity> repo); }
WriteValidator { public void validateWriteRequest(EntityBody entityBody, UriInfo uriInfo, SLIPrincipal principal) { targetEdOrgIds = new HashSet<String>(); if (isWriteValidationEnabled && !isValidForEdOrgWrite(entityBody, uriInfo, principal)) { throw new APIAccessDeniedException("Invalid reference. No association to referenced entity.", targetEdOrgIds); } }  void validateWriteRequest(EntityBody entityBody, UriInfo uriInfo, SLIPrincipal principal); void setRepo(PagingRepositoryDelegate<Entity> repo);  }