@Override public void shutdown() throws Exception { super.shutdown(); this.graph.close(); }
public void testManipulateAndReopenGraph() throws Exception { if (! this.supportsPersistence()) return; Graph graph9 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-9"); makeGraph(graph9); graph9.close(); graph9 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-9"); manipulateGraph(graph9); graph9.close(); graph9 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-9"); testManipulatedGraph(graph9); graph9.close(); }
public void testReopenGraph() throws Exception { if (! this.supportsPersistence()) return; Graph graph2 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-2"); makeGraph(graph2); graph2.close(); graph2 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-2"); testGraph(graph2); graph2.close(); }
public void testMakeGraph() throws Exception { Graph graph1 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-1"); makeGraph(graph1); testGraph(graph1); graph1.close(); }
public void testManipulate() throws Exception { Graph graph8 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-8"); makeGraph(graph8); manipulateGraph(graph8); testManipulatedGraph(graph8); graph8.close(); }
public void testReadJson() throws Exception { Graph graph3 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-3"); XDIReader reader = XDIReaderRegistry.forFormat("XDI/JSON", null); reader.read(graph3, AbstractGraphTest.class.getResourceAsStream("test.json")).close(); testGraph(graph3); graph3.getRootContextNode().clear(); assertTrue(graph3.isEmpty()); graph3.close(); }
public void testGetOwnerXDIAddress() throws Exception { Graph graph = MemoryGraphFactory.getInstance().parseGraph(TEST_GRAPH_DEREFERENCE); assertEquals(GraphUtil.getOwnerPeerRootXDIArc(graph), XDIArc.fromComponent(TEST_CONTEXTNODE_1111)); graph.close(); }
public void testTimestampsOnContextNode() throws Exception { Graph graph = MemoryGraphFactory.getInstance().openGraph(); ContextNode contextNode = graph.getRootContextNode().setContextNode(XDIArc.create("=markus")); GregorianCalendar calendar = new GregorianCalendar(2010, 11, 22, 11, 22, 33); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); Date timestamp = calendar.getTime(); Timestamps.setTimestamp(XdiAbstractContext.fromContextNode(contextNode), timestamp); assertEquals(timestamp, Timestamps.getTimestamp(XdiAbstractContext.fromContextNode(contextNode))); graph.close(); } }
public void testPeerRoots() throws Exception { Graph graph = MemoryGraphFactory.getInstance().openGraph(); assertEquals(XdiCommonRoot.findCommonRoot(graph).getPeerRoot(XDIAddress.create("=!1111"), true).getContextNode().getXDIAddress(), XDIArc.create("(=!1111)")); graph.close(); }
public void testDeleteCyclicRelation() throws Exception { Graph graph31 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-31"); graph31.setStatement(XDIStatement.create("=a=b=c=d=e/+x/=a=b=c")); graph31.setStatement(XDIStatement.create("=m=n=o/+y/=a=b=c=d")); graph31.getDeepContextNode(XDIAddress.create("=a=b")).delete(); assertEquals(graph31.getRootContextNode().getAllContextNodeCount(), 4); assertEquals(graph31.getRootContextNode().getAllRelationCount(), 0); assertEquals(graph31.getRootContextNode().getAllStatementCount(), 4); graph31.close(); }
public void testNoExceptions() throws Exception { Graph graph17 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-17"); graph17.setStatement(XDIStatement.create("=markus<#email>/&/\"Markus Sabadello\"")); graph17.setStatement(XDIStatement.create("=markus/#friend/=neustar=les")); ContextNode root = graph17.getRootContextNode(); ContextNode markus = graph17.getDeepContextNode(XDIAddress.create("=markus")); ContextNode les = graph17.getDeepContextNode(XDIAddress.create("=neustar=les")); root.setContextNode(XDIArc.create("=markus")); markus.setDeepContextNode(XDIAddress.create("<#email>")).setLiteralNode("test"); markus.setRelation(XDIAddress.create("#friend"), les); graph17.close(); }
public void testNormalizedSerialization() throws Exception { Graph graph = MemoryGraphFactory.getInstance().openGraph(); graph.setStatement(XDIStatement.create("=markus<#email>/&/\"markus@projectdanube.org\"")); graph.setStatement(XDIStatement.create("=markus/#friend/=animesh")); ContextNode contextNode = graph.getDeepContextNode(XDIAddress.create("=markus")); String normalizedSerialization = "{\"/\":[\"=animesh\",\"=markus\"],\"=markus/\":[\"<#email>\"],\"=markus/#friend\":[\"=animesh\"],\"=markus<#email>/&\":\"markus@projectdanube.org\"}"; assertEquals(Normalization.serialize(contextNode, null), normalizedSerialization); graph.close(); } }
public void testCommonRoot() throws Exception { Graph graph = MemoryGraphFactory.getInstance().openGraph(); assertEquals(XdiCommonRoot.findCommonRoot(graph).getContextNode(), graph.getRootContextNode()); assertEquals(XdiCommonRoot.findCommonRoot(graph).getContextNode().getXDIAddress(), XDIConstants.XDI_ADD_ROOT); graph.close(); } }
public void testOwnsPeerRootXDIArc() throws Exception { Graph graph = MemoryGraphFactory.getInstance().parseGraph(TEST_GRAPH_DEREFERENCE); assertTrue(GraphUtil.ownsPeerRootXDIArc(graph, XDIArc.fromComponent(TEST_CONTEXTNODE_1111))); assertTrue(GraphUtil.ownsPeerRootXDIArc(graph, XDIArc.fromComponent(TEST_CONTEXTNODE_1a1a))); assertTrue(GraphUtil.ownsPeerRootXDIArc(graph, XDIArc.fromComponent(TEST_CONTEXTNODE_1b1b))); graph.close(); } }
public void testDeleteDeep() throws Exception { Graph graph12 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-12"); assertEquals(graph12.getRootContextNode(), graph12.getDeepContextNode(XDIConstants.XDI_ADD_ROOT)); assertEquals(graph12.getRootContextNode().getXDIAddress(), XDIConstants.XDI_ADD_ROOT); graph12.setDeepContextNode(XDIAddress.create("=markus")).setRelation(XDIAddress.create("#friend"), XDIAddress.create("=someone")); graph12.getDeepContextNode(XDIAddress.create("=markus")).delete(); graph12.setDeepContextNode(XDIAddress.create("=markus")); assertNull(graph12.getDeepContextNode(XDIAddress.create("=markus")).getRelation(XDIAddress.create("#friend"))); graph12.close(); }
public void testSubGraph() throws Exception { Graph graph = MemoryGraphFactory.getInstance().openGraph(); XdiCommonRoot localRoot = XdiCommonRoot.findCommonRoot(graph); XdiPeerRoot peerRoot = localRoot.getPeerRoot(XDIAddress.create("=!:uuid:91f28153-f600-ae24-91f2-8153f600ae24"), true); XdiInnerRoot innerRoot = peerRoot.getInnerRoot(XDIAddress.create("=!1111"), XDIAddress.create("$add"), true); assertTrue(XdiAbstractContext.fromContextNode(localRoot.getContextNode()) instanceof XdiCommonRoot); assertTrue(XdiAbstractContext.fromContextNode(peerRoot.getContextNode()) instanceof XdiPeerRoot); assertTrue(XdiAbstractContext.fromContextNode(innerRoot.getContextNode()) instanceof XdiInnerRoot); graph.close(); } }
public void testSelfPeerRoots() throws Exception { Graph graph = MemoryGraphFactory.getInstance().openGraph(); XdiCommonRoot.findCommonRoot(graph).setSelfPeerRoot(XDIAddress.create("=!1111")); XdiPeerRoot selfPeerRoot = XdiCommonRoot.findCommonRoot(graph).getSelfPeerRoot(); assertEquals(selfPeerRoot.getContextNode().getXDIAddress(), XDIAddress.create("(=!1111)")); assertEquals(XdiCommonRoot.findCommonRoot(graph).getPeerRoot(XDIAddress.create("=!1111"), false), selfPeerRoot); assertTrue(selfPeerRoot.isSelfPeerRoot()); graph.close(); } }
public void testLinkContractTemplate() throws Exception { XDIAddress XDIaddress = XDIAddress.create("=markus#registration{$contract}"); Graph graph = MemoryGraphFactory.getInstance().openGraph(); ContextNode contextNode = graph.setDeepContextNode(XDIaddress); LinkContractTemplate l1 = LinkContractTemplate.findLinkContractTemplate(graph, XDIAddress.create("=markus#registration"), false); assertNotNull(l1); assertEquals(l1.getTemplateAuthorityAndId(), XDIAddress.create("=markus#registration")); LinkContractTemplate l2 = LinkContractTemplate.fromXdiEntitySingletonVariable(XdiEntitySingleton.Variable.fromContextNode(contextNode)); assertNotNull(l2); assertEquals(l2.getTemplateAuthorityAndId(), XDIAddress.create("=markus#registration")); assertEquals(l1, l2); graph.close(); }
public void testLinkContracts() throws Exception { Graph graph = MemoryGraphFactory.getInstance().openGraph(); ContextNode contextNode1 = graph.setDeepContextNode(XDIAddress.create("(=alice/$public)$contract")); ContextNode contextNode2 = graph.setDeepContextNode(XDIAddress.create("(=alice/=alice)$contract")); assertTrue(LinkContract.isValid(XdiAbstractEntity.fromContextNode(contextNode1))); assertTrue(LinkContract.isValid(XdiAbstractEntity.fromContextNode(contextNode2))); LinkContract linkContract1 = LinkContract.fromXdiEntity(XdiAbstractEntity.fromContextNode(contextNode1)); LinkContract linkContract2 = LinkContract.fromXdiEntity(XdiAbstractEntity.fromContextNode(contextNode2)); assertTrue(new IteratorContains<LinkContract> (LinkContracts.getAllLinkContracts(graph), linkContract1).contains()); assertTrue(new IteratorContains<LinkContract> (LinkContracts.getAllLinkContracts(graph), linkContract2).contains()); graph.close(); }
public void testConnectLinkContract() throws Exception { Graph graph = MemoryGraphFactory.getInstance().openGraph(); GraphUtil.setOwnerXDIAddress(graph, XDIAddress.create("=markus")); assertEquals(GraphUtil.getOwnerXDIAddress(graph), XDIAddress.create("=markus")); ConnectLinkContract l = ConnectLinkContract.findConnectLinkContract(graph, true); assertNotNull(l); assertEquals(l.getXdiEntity().getXDIAddress(), XDIAddress.create("(=markus/$connect)$contract")); assertNotNull(ConnectLinkContract.findConnectLinkContract(graph, false)); assertTrue(LinkContract.fromXdiEntity(l.getXdiEntity()) instanceof ConnectLinkContract); assertEquals(l.getRequestingAuthority(), XDILinkContractConstants.XDI_ADD_CONNECT); assertEquals(l.getAuthorizingAuthority(), XDIAddress.create("=markus")); assertNull(l.getTemplateAuthorityAndId()); graph.close(); }