// MMB-1889 public void testCreateRelationAndDeleteNode() { // Make a relation to an existing node. Then delete that node with the 'delete relations' // option'. Commit the transaction. // The new relations should not exist, since the node was deleted. // No errors. Cloud cloud = getCloud(); int urlCount = Queries.count(cloud.getNodeManager("urls").createQuery()); int relCount = Queries.count(cloud.getNodeManager("insrel").createQuery()); Node url = cloud.getNodeManager("urls").createNode(); url.commit(); Transaction t = cloud.getTransaction("relatedandelete"); Node turl = t.getNode(url.getNumber()); Node news = t.getNode(newNode); RelationManager rm = t.getRelationManager("urls", "news", "posrel"); Relation r = turl.createRelation(news, rm); r.commit(); turl.delete(true); t.commit(); int urlCountAfter = Queries.count(cloud.getNodeManager("urls").createQuery()); assertEquals(urlCount, urlCountAfter); int relCountAfter = Queries.count(cloud.getNodeManager("insrel").createQuery()); assertEquals(relCount, relCountAfter); }
public void testAlias() { Cloud cloud = getCloud(); { Node node = cloud.getNode(newNode2); node.setStringValue("title", "abcdef"); node.commit(); assertEquals("abcdef", node.getStringValue("title")); node = cloud.getNode("test.news." + seq); assertEquals("abcdef", node.getStringValue("title")); } { Transaction t = cloud.getTransaction("bar12"); Node node = t.getNode(newNode2); node.setStringValue("title", "abcdefg"); node.commit(); assertEquals("abcdefg", node.getStringValue("title")); t.commit(); assertEquals("abcdefg", node.getStringValue("title")); node = cloud.getNode("test.news." + seq); assertEquals("abcdefg", node.getStringValue("title")); node = cloud.getNode(newNode2); assertEquals("abcdefg", node.getStringValue("title")); } }
// MMB-1860 (4) public void testRelateAndDeleteRelation() { // Make a relation between two nodes. Delete the relation again. Commit the transaction. // Te relation shouldn't exist Cloud cloud = getCloud(); int urlCount = Queries.count(cloud.getNodeManager("urls").createQuery()); int relCount = Queries.count(cloud.getNodeManager("insrel").createQuery()); Node newUrl = cloud.getNodeManager("urls").createNode(); newUrl.commit(); Transaction t = cloud.getTransaction("testrelateandeleterelation"); Node news = t.getNode(newNode); Node url = t.getNode(newUrl.getNumber()); RelationManager rm = t.getRelationManager("urls", "news", "posrel"); Relation r = url.createRelation(news, rm); r.commit(); r.delete(); t.commit(); int urlCountAfter = Queries.count(cloud.getNodeManager("urls").createQuery()); assertEquals(urlCount + 1, urlCountAfter); // But the relation should not exist, because it was deleted angain int relCountAfter = Queries.count(cloud.getNodeManager("insrel").createQuery()); assertEquals(relCount, relCountAfter); }
// MMB-1893 public void testDeleteNodeWitRelationsAndCancel() { Cloud cloud = getCloud(); int urlCount0 = Queries.count(cloud.getNodeManager("urls").createQuery()); int relCount0 = Queries.count(cloud.getNodeManager("insrel").createQuery()); Node url = cloud.getNodeManager("urls").createNode(); url.commit(); Node news = cloud.getNode(newNode); RelationManager rm = cloud.getRelationManager("urls", "news", "posrel"); Relation r = url.createRelation(news, rm); r.commit(); int urlCount = Queries.count(cloud.getNodeManager("urls").createQuery()); int relCount = Queries.count(cloud.getNodeManager("insrel").createQuery()); assertEquals(urlCount0 + 1, urlCount); assertEquals(relCount0 + 1, relCount); Transaction t = cloud.getTransaction("deletewithrelationsandcancel"); Node turl = t.getNode(url.getNumber()); turl.delete(true); t.cancel(); int urlCountAfter = Queries.count(cloud.getNodeManager("urls").createQuery()); assertEquals(urlCount, urlCountAfter); int relCountAfter = Queries.count(cloud.getNodeManager("insrel").createQuery()); assertEquals(relCount, relCountAfter); // MMB-1893 }
// same case as above, only no changes are made to the node. public void testDeleteNodeOutsideTransactionNodeInTransactionButNotChanged() { Cloud cloud = getCloud(); Transaction t = cloud.getTransaction("bar11"); Node nodeInTransaction = t.getNode(newNode2); // nodeInTransaction.setStringValue("title", "foo2"); { // now delete the node Node nodeOutTransaction = cloud.getNode(newNode2); nodeOutTransaction.delete(); assertFalse(cloud.hasNode(newNode2)); } try { // make a relation to the (deleted) node, but in the transaction, where the node still // exists. // This demonstrate that there is an actual problem if the node ends up non-existing now. Node url = t.getNodeManager("urls").createNode(); RelationManager rm = t.getRelationManager("news", "urls", "posrel"); Relation r = nodeInTransaction.createRelation(url, rm); t.commit(); } catch (Exception e) { // should not give exception. MMB-1680 log.error(e.getMessage(), e); fail(e.getMessage()); } assertTrue(cloud.hasNode(newNode2)); assertEquals(1, cloud.getNode(newNode2).countRelations()); }
public void testCommitDelete() { Cloud cloud = getCloud(); Transaction t = cloud.getTransaction("bar6"); Node node = t.getNode(newNode); node.delete(); t.commit(); assertFalse(cloud.hasNode(newNode)); }
public void testCancelDelete() { Cloud cloud = getCloud(); Transaction t = cloud.getTransaction("bar5"); Node node = t.getNode(newNode); node.delete(); t.cancel(); assertTrue(cloud.hasNode(newNode)); }
// old node as argument public void testCreateRelationToNewNode2() { Cloud cloud = getCloud(); Transaction t = cloud.getTransaction("createrelationtrans"); Node n = t.getNode(newNode); NodeManager urls = t.getNodeManager("urls"); Node url = urls.createNode(); RelationManager rm = t.getRelationManager("urls", "news", "posrel"); Relation r = url.createRelation(n, rm); t.commit(); }
public void testCreateRelationBetweenNewNodes() { Cloud cloud = getCloud(); Transaction t = cloud.getTransaction("createrelationtrans"); NodeManager news = t.getNodeManager("news"); Node n = news.createNode(); NodeManager urls = t.getNodeManager("urls"); Node url = urls.createNode(); RelationManager rm = t.getRelationManager("news", "urls", "posrel"); Relation r = n.createRelation(url, rm); t.commit(); }
public void testCommit() { Cloud cloud = getCloud(); Transaction t = cloud.getTransaction("bar3"); Node node = t.getNode(newNode); node.setStringValue("title", "yyyyy"); node.commit(); t.commit(); node = cloud.getNode(newNode); assertEquals("yyyyy", node.getStringValue("title")); }
public void testCancel() { Cloud cloud = getCloud(); Transaction t = cloud.getTransaction("cancel1"); Node node = t.getNode(newNode); node.setStringValue("title", "xxxxx"); node.commit(); t.cancel(); node = cloud.getNode(newNode); assertEquals("foo", node.getStringValue("title")); }
public void testMMB1546() { Cloud cloud = getCloud(); Transaction t = cloud.getTransaction("test0"); Node nt = t.getNode(newNode); nt.setValue("title", "bla"); // t.cancel(); _DONT_ cancel Node nc = cloud.getNode(newNode); nc.setValue("title", "bloe"); nc.commit(); assertEquals("bloe", nc.getStringValue("title")); assertEquals("bloe", cloud.getNode(newNode).getStringValue("title")); t.cancel(); assertEquals("bloe", cloud.getNode(newNode).getStringValue("title")); }
public void testGetTransaction() { Cloud cloud = getCloud(); { Transaction t = cloud.getTransaction("gettransactiontest"); Node node = t.getNode(newNode); node.setStringValue("title", "xxxxx"); } { Transaction t = cloud.getTransaction("gettransactiontest"); Node node = t.getNode(newNode); assertEquals("xxxxx", node.getStringValue("title")); t.cancel(); } }
public void testGetNode() { // Create new node. Request the node again. // Should work Cloud cloud = getCloud(); int urlCount = Queries.count(cloud.getNodeManager("urls").createQuery()); Transaction t = cloud.getTransaction("testgetnode"); Node url = t.getNodeManager("urls").createNode(); url.setStringValue("url", "http://bla"); url.commit(); Node reurl = t.getNode(url.getNumber()); assertEquals("http://bla", reurl.getStringValue("url")); }
public void testEditNodeOutsideTransaction2() { Cloud cloud = getCloud(); Transaction t = cloud.getTransaction("bar10"); Node nodeInTransaction = t.getNode(newNode2); nodeInTransaction.setStringValue("title", "foo2"); Node nodeOutTransaction = cloud.getNode(newNode2); nodeOutTransaction.setStringValue("title", "bar2"); t.commit(); nodeOutTransaction.commit(); // transaction was committed _earlier_ so the commit of the node must have won assertEquals("bar2", cloud.getNode(newNode2).getStringValue("title")); // assertEquals("bar2", nodeInTransaction.getStringValue("title"));// not sure what this should // have done, but anyhow, it now fails assertEquals("bar2", nodeOutTransaction.getStringValue("title")); }
// Test for http://www.mmbase.org/jira/browse/MMB-1621 public void testGetValue() { Cloud cloud = getCloud(); String value = cloud.getNode(newNode).getStringValue("title"); assertFalse("zzzzz".equals(value)); Transaction t = cloud.getTransaction("bar4"); System.out.println("Transaction now " + t); Node node = t.getNode(newNode); assertEquals(1, t.getNodes().size()); node.setStringValue("title", "zzzzz"); assertEquals("zzzzz", node.getStringValue("title")); node.commit(); // committing inside transaction assertEquals("zzzzz", node.getStringValue("title")); assertEquals(value, cloud.getNode(newNode).getStringValue("title")); t.commit(); assertEquals("zzzzz", cloud.getNode(newNode).getStringValue("title")); }
public void testCreateAndDelete2() { // Create new node. Request the node again. Delete that. Commit the transaction. // The new node must not exist. Cloud cloud = getCloud(); int urlCount = Queries.count(cloud.getNodeManager("urls").createQuery()); Transaction t = cloud.getTransaction("testcreateandelete"); Node url = t.getNodeManager("urls").createNode(); url.commit(); assertEquals(1, t.getNodes().size()); Node reurl = t.getNode(url.getNumber()); reurl.delete(); assertEquals( 1, t.getNodes() .size()); // 0 would also be an option, but the node remaisn in the transaction as // 'NOLONGER' t.commit(); int urlCountAfter = Queries.count(cloud.getNodeManager("urls").createQuery()); assertEquals(urlCount, urlCountAfter); }
public void testReuseTransaction() { Cloud cloud = getCloud(); { Node node = cloud.getNode(newNode); node.setStringValue("title", "zzyyxx"); node.commit(); assertEquals("zzyyxx", cloud.getNode(newNode).getStringValue("title")); } { Transaction t = cloud.getTransaction("bar4"); assertEquals(0, t.getNodes().size()); Node node = t.getNode(newNode); assertEquals("zzyyxx", node.getStringValue("title")); assertEquals(1, t.getNodes().size()); node.setStringValue("title", "wwwwww"); node.commit(); assertEquals("wwwwww", node.getStringValue("title")); t.cancel(); assertEquals("zzyyxx", cloud.getNode(newNode).getStringValue("title")); } assertEquals("zzyyxx", cloud.getNode(newNode).getStringValue("title")); }
public void testDeleteNodeOutsideTransaction() { Cloud cloud = getCloud(); Transaction t = cloud.getTransaction("bar11"); Node nodeInTransaction = t.getNode(newNode2); nodeInTransaction.setStringValue("title", "foo2"); { // now delete the node Node nodeOutTransaction = cloud.getNode(newNode2); nodeOutTransaction.delete(); assertFalse(cloud.hasNode(newNode2)); } try { t.commit(); } catch (Exception e) { // should not give exception. MMB-1680 log.error(e.getMessage(), e); fail(e.getMessage()); } assertTrue(cloud.hasNode(newNode2)); }
// MMB-1860 (2) public void testCreateRelateAndDelete() { // Create new node. Make a relation to it. Delete the node again. Commit the transaction. // The new node must not exist, but the relation shouldn't have caused errors Cloud cloud = getCloud(); int urlCount = Queries.count(cloud.getNodeManager("urls").createQuery()); Transaction t = cloud.getTransaction("testcreateandelete"); Node news = t.getNode(newNode); Node url = t.getNodeManager("urls").createNode(); RelationManager rm = t.getRelationManager("urls", "news", "posrel"); Relation r = url.createRelation(news, rm); url.delete(true); t.commit(); int urlCountAfter = Queries.count(cloud.getNodeManager("urls").createQuery()); assertEquals(urlCount, urlCountAfter); }
public void testTransactionsAreEqual() { Cloud cloud = getCloud(); Transaction t1 = cloud.getTransaction("testequals"); Transaction t2 = cloud.getTransaction("testequals"); assertEquals(t1, t2); Node n = t1.getNode(newNode); NodeManager urls = t2.getNodeManager("urls"); Node url = urls.createNode(); RelationManager rm = t2.getRelationManager("urls", "news", "posrel"); Relation r = url.createRelation(n, rm); t2.commit(); assertTrue(t2.isCommitted()); assertTrue(t1.isCommitted()); // assertTrue(t1 == t2); // FAILS IN RMMCI. Perhaps we should simply implement .equals on // transactions }
public void testSetContextSubTransaction() { Cloud cloud = getCloud(); Transaction ot = cloud.getTransaction("bar8"); Transaction t = ot.getTransaction("bar9"); Node n = t.getNodeManager("news").createNode(); n.setContext("non_default"); assertEquals("non_default", n.getContext()); t.commit(); Node n2 = ot.getNode(n.getNumber()); assertEquals("non_default", n2.getContext()); ot.commit(); Node n3 = cloud.getNode(n.getNumber()); assertEquals("non_default", n3.getContext()); }
// MMB-1857 public void testGetNodes() { Cloud cloud = getCloud(); Transaction t = cloud.getTransaction("testgetnodes"); Node n = t.getNode(newNode); Node url = t.getNodeManager("urls").createNode(); RelationManager rm = t.getRelationManager("urls", "news", "posrel"); Relation r = url.createRelation(n, rm); { // should not give NPE's or so n.commit(); url.commit(); r.commit(); } assertEquals(3, t.getNodes().size()); // 2 nodes and one relation for (Node rn : t.getNodes()) { // should occur no exceptions rn.commit(); // should have little effect in trans } t.cancel(); }
public void testSetContext() { Cloud cloud = getCloud(); Transaction t = cloud.getTransaction("bar7"); Node n = t.getNodeManager("news").createNode(); assertEquals(1, t.getNodes().size()); n.setContext("non_default"); assertEquals(1, t.getNodes().size()); assertEquals("non_default", n.getStringValue("owner")); assertEquals("non_default", n.getContext()); assertEquals(1, t.getNodes().size()); t.commit(); Node n2 = cloud.getNode(n.getNumber()); assertEquals("non_default", n2.getStringValue("owner")); assertEquals("non_default", n2.getContext()); }