1 10 package org.mmbase.bridge; 11 12 import org.mmbase.tests.*; 13 18 public class RelationTest extends BridgeTest { 19 20 public RelationTest(String name) { 21 super(name); 22 } 23 24 public void testCreateRelations() { 25 Cloud cloud = getCloud(); 27 28 Node aaFirstNode = cloud.getNodeManager("aa").createNode(); 29 aaFirstNode.setStringValue("stringfield", "aaFirstNode"); 30 aaFirstNode.commit(); 31 32 Node bbNode = cloud.getNodeManager("bb").createNode(); 33 bbNode.setStringValue("stringfield", "bbNode"); 34 bbNode.commit(); 35 36 Node aaSecondNode = cloud.getNodeManager("aa").createNode(); 37 aaSecondNode.setStringValue("stringfield", "aaSecondNode"); 38 aaSecondNode.commit(); 39 40 RelationManager relatedRelationManager = cloud.getRelationManager("related"); 41 42 Relation related1 = aaFirstNode.createRelation(bbNode, relatedRelationManager); 44 related1.commit(); 45 46 Relation related2 = bbNode.createRelation(aaSecondNode, relatedRelationManager); 48 related2.commit(); 49 50 55 58 { 60 NodeList aaRelatedList = aaFirstNode.getRelatedNodes("bb", "related", "destination"); 62 assertTrue("related list has size " + aaRelatedList.size() + " but should be 1", aaRelatedList.size() == 1); 63 if (aaRelatedList.size() > 0) { 64 Node theOtherNode = aaRelatedList.getNode(0); 65 assertTrue("expected the bb node but got " + theOtherNode, theOtherNode.getNumber() == bbNode.getNumber()); 66 } 67 } 68 69 { 70 NodeList aaRelatedList = aaFirstNode.getRelatedNodes("bb", "related", "source"); 72 assertTrue("related list has size " + aaRelatedList.size() + " but should be 0", aaRelatedList.size() == 0); 73 RelationList aaRelationList = aaFirstNode.getRelations("related", cloud.getNodeManager("bb"), "source"); 74 assertTrue("relation list has size " + aaRelationList.size() + " but should be 0", aaRelationList.size() == 0); 75 } 76 77 { 78 NodeList bbRelatedListSource = bbNode.getRelatedNodes("aa", "related", "source"); 80 assertTrue("relation count should be 1 but is " + bbRelatedListSource.size() + " mmbase relations dont' work", bbRelatedListSource.size() == 1); 81 if (bbRelatedListSource.size() > 0) { 82 Node sourceNode = bbRelatedListSource.getNode(0); 83 assertTrue("expected the first aa node but got " + sourceNode, sourceNode.getNumber() == aaFirstNode.getNumber()); 84 } 85 RelationList bbRelationListSource = bbNode.getRelations("related", cloud.getNodeManager("aa"), "source"); 86 assertTrue("relation list has size " + bbRelationListSource.size() + " but should be 1", bbRelationListSource.size() == 1); 87 88 } 89 90 { 91 NodeList bbRelatedListDestination = bbNode.getRelatedNodes("aa", "related", "destination"); 93 assertTrue("relation count should be 1 but is " + bbRelatedListDestination.size() + " mmbase relations dont' work", bbRelatedListDestination.size() == 1); 94 if (bbRelatedListDestination.size() > 0) { 95 Node sourceNode = bbRelatedListDestination.getNode(0); 96 assertTrue("expected the first aa node but got " + sourceNode, sourceNode.getNumber() == aaSecondNode.getNumber()); 97 } 98 RelationList bbRelationListDestination = bbNode.getRelations("related", cloud.getNodeManager("aa"), "destination"); 99 assertTrue("relation count should be 1 but is " + bbRelationListDestination.size() + " mmbase relations dont' work", bbRelationListDestination.size() == 1); 100 } 101 102 { 103 NodeList bbRelatedListBoth = bbNode.getRelatedNodes("aa", "related", "both"); 105 assertTrue("relation count should be 2 but is " + bbRelatedListBoth.size() + " mmbase relatednodes(BOTH) does not work", bbRelatedListBoth.size() == 2); 106 RelationList bbRelationListBoth = bbNode.getRelations("related", cloud.getNodeManager("aa"), "both"); 107 assertTrue("relation count should be 2 but is " + bbRelationListBoth.size() + " mmbase relatednodes(BOTH) does not work", bbRelationListBoth.size() == 2); 108 109 } 110 111 { 112 NodeList bbRelatedListNull = bbNode.getRelatedNodes("aa", "related", null); 114 assertTrue("relation count should be 2 but is " + bbRelatedListNull.size() + " mmbase relatednodes() does not work", bbRelatedListNull.size() == 2); 115 NodeList bbRelationListNull = bbNode.getRelations("related", cloud.getNodeManager("aa"), null); 116 assertTrue("relation count should be 2 but is " + bbRelationListNull.size() + " mmbase relatednodes() does not work", bbRelationListNull.size() == 2); 117 118 } 119 { 120 try { 121 aaFirstNode.delete(); 122 fail("Should raise a BridgeException"); 123 } catch (BridgeException e) {}; 124 125 try { 126 aaSecondNode.delete(); 127 fail("Should raise a BridgeException"); 128 } catch (BridgeException e) {}; 129 aaSecondNode.delete(true); 130 aaFirstNode.delete(true); 131 bbNode.delete(); 132 } 133 } 134 } 135 | Popular Tags |