1 19 20 package org.netbeans.api.nodes2looks; 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 import java.util.Collection ; 25 import java.util.Iterator ; 26 27 import org.openide.nodes.*; 28 import org.netbeans.junit.*; 29 import org.openide.util.Lookup; 30 31 import org.netbeans.spi.looks.*; 32 33 36 public class NodeLookValuesTest extends TestBaseValues { 37 38 Node delegate; 39 40 42 public NodeLookValuesTest(java.lang.String testName) { 43 super(testName); 44 } 45 46 public static void main(java.lang.String [] args) { 47 junit.textui.TestRunner.run(suite()); 48 } 49 50 public static NbTest suite() { 51 NbTestSuite suite = new NbTestSuite( NodeLookValuesTest.class ); 52 return suite; 53 } 54 55 protected void setUp() throws Exception { 56 57 Look look = new SampleLook( "NodeLookValuesTestLook" ); 58 LookSelector selector = Selectors.selector( new SampleProvider( look ) ); 59 GoldenValue[] goldenValues = GoldenValue.createGoldenValues(); 60 SampleRepObject ro = new SampleRepObject( goldenValues ); 61 delegate = Nodes.node( ro, look, selector ); 62 Node node = Nodes.node( delegate, Nodes.nodeLook(), selector ); 63 64 setTarget( node, ro, 1 ); 65 setGoldenValues( goldenValues ); 66 67 super.setUp(); 68 } 69 70 protected void tearDown() throws Exception { 71 super.tearDown(); 72 } 73 74 75 77 83 85 public void testGetLookupValues() { 86 87 Lookup lookup = node.getLookup(); 88 Lookup.Result result = lookup.lookup( new Lookup.Template( Object .class ) ); 89 Collection items = new ArrayList ( result.allItems() ); 91 93 for( int i = 0; i < 2; i++ ) { 94 Object nodeItself = null; 95 96 for( Iterator it = items.iterator(); it.hasNext(); ) { 97 Lookup.Item item = (Lookup.Item)it.next(); 98 99 if ( item.getInstance() == ( i == 0 ? node : delegate ) ) { 100 nodeItself = item; 101 break; 102 } 103 } 104 105 assertNotNull( "Lookup should contain the node itself. Run " + i +".", nodeItself ); 106 items.remove( nodeItself ); 107 } 108 109 assertTrue ( MSSG_UNEXPECTED_VALUE_RETURNED, 110 GoldenValue.isOK( 111 ProxyLook.GET_LOOKUP_ITEMS, 112 items, 113 goldenValues ) ); 114 } 115 116 public void testGetChildObjects() { 117 Node[] nodes = node.getChildren().getNodes(); 118 List gv = (List )GoldenValue.get( ProxyLook.GET_CHILD_OBJECTS, goldenValues ); 119 120 if ( gv == null ) { 121 fail( "Golden value is invalid" ); 122 } 123 if ( gv.size() != nodes.length ) { 124 fail( MSSG_UNEXPECTED_VALUE_RETURNED ); 125 } 126 127 for( int i = 0; i < nodes.length; i++ ) { 128 129 Node n = nodes[i]; 130 131 Object o = TestUtil.getRepresentedObject( n ); 132 assertTrue("o is a Node: " + o.getClass().getName(), o instanceof Node); 133 Node delegate = (Node)o; 134 135 if ( TestUtil.getRepresentedObject( delegate ) != gv.get(i) && 136 !TestUtil.getRepresentedObject( delegate ).equals( gv.get(i) ) ) { 137 fail( MSSG_UNEXPECTED_VALUE_RETURNED + "on index : " + i ); 138 } 139 } 140 } 141 142 144 public void testGetRepresentedObject() { 145 Object ro = TestUtil.getRepresentedObject( node ); 146 if ( ro != delegate ) { 147 fail("Bad represented object."); 148 } 149 if ( TestUtil.getRepresentedObject( (Node)ro ) != representedObject ) { 150 fail("Bad represented delegate."); 151 } 152 } 153 154 public void testGetLook() { 155 Look look = ((LookNode)node).getLook(); 156 if ( look != Nodes.nodeLook() ) { 157 fail("Bad or no look on node"); 158 } 159 } 160 161 public void testGetCookie() { 162 Class c = org.openide.cookies.SaveCookie.class; 163 Node.Cookie cookie = node.getCookie( c ); 164 165 Collection items = (Collection )representedObject.getValue( ProxyLook.GET_LOOKUP_ITEMS ); 166 Node.Cookie gc = null; 167 168 for( Iterator it = items.iterator(); it.hasNext(); ) { 169 Lookup.Item item = (Lookup.Item)it.next(); 170 if ( c.isInstance( item.getInstance() ) ) { 171 gc = (Node.Cookie)item.getInstance(); 172 } 173 } 174 175 if ( cookie != gc ) { 176 fail("Bad cookie." + cookie + " instad of " + gc ); 177 } 178 } 179 180 } 181 182 183 | Popular Tags |