use of com.yahoo.elide.annotation.Include in project elide by yahoo.
the class NamespacePackageTest method testAnnotations.
@Test
void testAnnotations() throws Exception {
NamespaceConfig testNamespace = NamespaceConfig.builder().description("A test Namespace").name("Test").build();
NamespacePackage namespace = new NamespacePackage(testNamespace);
ReadPermission readPermission = namespace.getDeclaredAnnotation(ReadPermission.class);
assertEquals("Prefab.Role.All", readPermission.expression());
Include meta = namespace.getDeclaredAnnotation(Include.class);
assertEquals("A test Namespace", meta.description());
assertNull(meta.friendlyName());
ApiVersion apiVersion = namespace.getDeclaredAnnotation(ApiVersion.class);
assertEquals("", apiVersion.version());
}
use of com.yahoo.elide.annotation.Include in project elide by yahoo.
the class RequestScopeTest method testNewObjectsForInheritedTypes.
@Test
public void testNewObjectsForInheritedTypes() throws Exception {
@Entity
@Include(rootLevel = false)
class MyBaseClass {
@Id
public long id;
}
@Entity
@Include(rootLevel = false)
class MyInheritedClass extends MyBaseClass {
public String myField;
}
EntityDictionary dictionary = EntityDictionary.builder().build();
dictionary.bindEntity(MyBaseClass.class);
dictionary.bindEntity(MyInheritedClass.class);
RequestScope requestScope = new RequestScope(null, "/", NO_VERSION, null, null, null, null, null, UUID.randomUUID(), new ElideSettingsBuilder(null).withEntityDictionary(dictionary).build());
String myId = "myId";
// Test that a new inherited class is counted for base type
requestScope.setUUIDForObject(ClassType.of(MyInheritedClass.class), myId, new MyInheritedClass());
assertNotNull(requestScope.getObjectById(ClassType.of(MyBaseClass.class), myId));
}
use of com.yahoo.elide.annotation.Include in project elide by yahoo.
the class EntityDictionaryTest method testGetFirstAnnotation.
@Test
public void testGetFirstAnnotation() {
@Exclude
class Foo {
}
@Include(rootLevel = false)
class Bar extends Foo {
}
class Baz extends Bar {
}
Annotation first = getFirstAnnotation(ClassType.of(Baz.class), Arrays.asList(Exclude.class, Include.class));
assertTrue(first instanceof Include);
}
use of com.yahoo.elide.annotation.Include in project elide by yahoo.
the class EntityDictionaryTest method testSerdeId.
@Test
public void testSerdeId() {
@Include(rootLevel = false)
class EntityWithDateId {
@Id
private Date id;
}
EntityDictionary testDictionary = new EntityDictionary(new HashMap<>(), null, DEFAULT_INJECTOR, unused -> new ISO8601DateSerde(), Collections.emptySet(), DefaultClassScanner.getInstance());
testDictionary.bindEntity(EntityWithDateId.class);
EntityWithDateId testModel = new EntityWithDateId();
testModel.id = new Date(0);
assertEquals("1970-01-01T00:00Z", testDictionary.getId(testModel));
}
use of com.yahoo.elide.annotation.Include in project elide by yahoo.
the class EntityDictionary method bindEntity.
/**
* Add given Entity bean to dictionary.
*
* @param cls Entity bean class
* @param isFieldHidden Function which determines if a given field should be in the dictionary but not exposed.
*/
public void bindEntity(Type<?> cls, Predicate<AccessibleObject> isFieldHidden) {
Type<?> declaredClass = lookupIncludeClass(cls);
if (entitiesToExclude.contains(declaredClass)) {
// Exclude Entity
return;
}
if (declaredClass == null) {
log.trace("Missing include or excluded class {}", cls.getName());
return;
}
if (isClassBound(declaredClass)) {
// Ignore duplicate bindings.
return;
}
String type = getEntityName(declaredClass);
String version = getModelVersion(declaredClass);
bindJsonApiToEntity.put(Pair.of(type, version), declaredClass);
apiVersions.add(version);
EntityBinding binding = new EntityBinding(injector, declaredClass, type, version, isFieldHidden);
entityBindings.put(declaredClass, binding);
Include include = (Include) getFirstAnnotation(declaredClass, Arrays.asList(Include.class));
if (include != null && include.rootLevel()) {
bindEntityRoots.add(declaredClass);
}
bindLegacyHooks(binding);
discoverEmbeddedTypeBindings(declaredClass);
}
Aggregations