use of org.datanucleus.api.jpa.JPAEntityGraph in project tests by datanucleus.
the class EntityGraphTest method testNamedGraphSpecification.
/**
* Test of specification and registering of a named EntityGraph.
*/
public void testNamedGraphSpecification() {
try {
Set<String> graphNames = ((JPAEntityManagerFactory) emf).getEntityGraphNames();
assertNotNull(graphNames);
assertEquals("Number of EntityGraphs is wrong", 1, graphNames.size());
JPAEntityGraph eg = (JPAEntityGraph) ((JPAEntityManagerFactory) emf).getNamedEntityGraph(graphNames.iterator().next());
assertEquals("baseGraph", eg.getName());
assertEquals(GraphBase.class, eg.getClassType());
assertFalse(eg.getIncludeAllAttributes());
List<AttributeNode<?>> egNodes = eg.getAttributeNodes();
assertNotNull(egNodes);
assertEquals(3, egNodes.size());
boolean idPresent = false;
boolean namePresent = false;
boolean relationPresent = false;
for (AttributeNode node : egNodes) {
if (node.getAttributeName().equals("id")) {
idPresent = true;
} else if (node.getAttributeName().equals("name")) {
namePresent = true;
} else if (node.getAttributeName().equals("relation")) {
relationPresent = true;
Map<Class, Subgraph> subgraphsByClass = node.getSubgraphs();
assertNotNull(subgraphsByClass);
assertEquals(1, subgraphsByClass.size());
Map.Entry<Class, Subgraph> subgraphEntry = subgraphsByClass.entrySet().iterator().next();
assertEquals(GraphRelated.class, subgraphEntry.getKey());
Subgraph subgraph = subgraphEntry.getValue();
List<AttributeNode<?>> subNodes = subgraph.getAttributeNodes();
assertNotNull(subNodes);
assertEquals(1, subNodes.size());
AttributeNode subNode = subNodes.iterator().next();
assertEquals("id", subNode.getAttributeName());
}
}
assertTrue("id not present", idPresent);
assertTrue("name not present", namePresent);
assertTrue("relation not present", relationPresent);
// Should have been registered as dynamic FetchGroups
PersistenceNucleusContext nucCtx = emf.unwrap(PersistenceNucleusContext.class);
Set<FetchGroup> fgs = nucCtx.getFetchGroupManager().getFetchGroupsWithName("baseGraph");
assertEquals(2, fgs.size());
} finally {
}
}
Aggregations