PersistentResource implements com.yahoo.elide.security.PersistentResource<T> { public static Object getValue(Object target, String fieldName, RequestScope requestScope) { EntityDictionary dictionary = requestScope.getDictionary(); return dictionary.getValue(target, fieldName, requestScope); } PersistentResource(@NonNull T obj, PersistentResource parent, String id, @NonNull RequestScope scope); @Override String toString(); static PersistentResource<T> createObject(
            PersistentResource<?> parent,
            Class<T> entityClass,
            RequestScope requestScope,
            Optional<String> uuid); @Override boolean matchesId(String checkId); @SuppressWarnings("resource") @NonNull static PersistentResource<T> loadRecord(
            Class<T> loadClass, String id, RequestScope requestScope); static Set<PersistentResource> loadRecords(
            Class<?> loadClass,
            List<String> ids,
            Optional<FilterExpression> filter,
            Optional<Sorting> sorting,
            Optional<Pagination> pagination,
            RequestScope requestScope); boolean updateAttribute(String fieldName, Object newVal); boolean updateRelation(String fieldName, Set<PersistentResource> resourceIdentifiers); boolean clearRelation(String relationName); void removeRelation(String fieldName, PersistentResource removeResource); boolean relationshipAlreadyExists(String fieldName, PersistentResource toAdd); void addRelation(String fieldName, PersistentResource newRelation); void deleteResource(); @Override String getId(); void setId(String id); boolean isIdGenerated(); @Override Optional<String> getUUID(); PersistentResource getRelation(String relation, String id); Set<PersistentResource> getRelation(String relation,
            List<String> ids,
            Optional<FilterExpression> filter,
            Optional<Sorting> sorting,
            Optional<Pagination> pagination); Set<PersistentResource> getRelationCheckedFiltered(String relationName,
            Optional<FilterExpression> filterExpression,
            Optional<Sorting> sorting,
            Optional<Pagination> pagination); RelationshipType getRelationshipType(String relation); Object getAttribute(String attr); @Override T getObject(); void setObject(T obj); @Override @JsonIgnore Class<T> getResourceClass(); @Override String getType(); @Override int hashCode(); @Override boolean equals(Object obj); ResourceLineage getLineage(); EntityDictionary getDictionary(); @Override RequestScope getRequestScope(); Resource toResource(); Resource toResourceWithSortingAndPagination(); Resource toResource(final Supplier<Map<String, Relationship>> relationshipSupplier,
                               final Supplier<Map<String, Object>> attributeSupplier); static Object getValue(Object target, String fieldName, RequestScope requestScope);  }
@Test public void testGetValue() throws Exception { FunWithPermissions fun = new FunWithPermissions(); fun.setField3("testValue"); String result; result = (String) getValue(fun, "field3", getRequestScope()); assertEquals("testValue", result, "getValue should set the appropriate value in the resource"); fun.setField1("testValue2"); result = (String) getValue(fun, "field1", getRequestScope()); assertEquals(result, "testValue2", "getValue should set the appropriate value in the resource"); Child testChild = newChild(3); fun.setRelation1(Sets.newHashSet(testChild)); @SuppressWarnings("unchecked") Set<Child> children = (Set<Child>) getValue(fun, "relation1", getRequestScope()); assertTrue(children.contains(testChild), "getValue should set the correct relation."); assertEquals(1, children.size(), "getValue should set the relation with the correct number of elements"); ComputedBean computedBean = new ComputedBean(); String computedTest1 = (String) getValue(computedBean, "test", getRequestScope()); String computedTest2 = (String) getValue(computedBean, "testWithScope", getRequestScope()); String computedTest3 = (String) getValue(computedBean, "testWithSecurityScope", getRequestScope()); assertEquals("test1", computedTest1); assertEquals("test2", computedTest2); assertEquals("test3", computedTest3); assertThrows( InvalidAttributeException.class, () -> getValue(computedBean, "NonComputedWithScope", getRequestScope()), "Getting a bad relation should throw an InvalidAttributeException."); assertThrows( InvalidAttributeException.class, () -> setValue("badRelation", "badValue"), "Getting a bad relation should throw an InvalidAttributeException."); }