1 7 package com.ca.commons.naming; 8 9 import junit.framework.*; 10 import javax.naming.directory.BasicAttribute ; 11 import javax.naming.directory.DirContext ; 12 13 import com.ca.commons.jndi.*; 14 15 public class DXAttributesTest extends TestCase 16 { 17 private static final BasicAttribute attribute1 = new BasicAttribute ("att1", "value1"); 18 private static final BasicAttribute attribute2 = new BasicAttribute ("att2", "value2"); 19 private static final BasicAttribute attribute3 = new BasicAttribute ("att3", "value3"); 20 private static final BasicAttribute attribute4 = new BasicAttribute ("att4", "value4"); 21 private static final BasicAttribute attribute5 = new BasicAttribute ("att5", "value5"); 22 26 public DXAttributesTest(String name) 27 { 28 super(name); 29 } 30 31 public static Test suite() 32 { 33 return new TestSuite(DXAttributesTest.class); 34 } 35 36 public static void main (String [] args) 37 { 38 junit.textui.TestRunner.run(suite()); 39 } 40 41 public void testEmptyConstructor() 42 { 43 DXAttributes bloop = new DXAttributes(); 44 assertEquals(bloop.size(), 0); 45 } 46 47 public void testEquality() 48 { 49 try 50 { 51 DXAttributes empty = new DXAttributes(); 52 53 DXAttributes atts1 = new DXAttributes(); 54 atts1.put(attribute1); 55 atts1.put(attribute2); 56 atts1.put(attribute3); 57 atts1.put(attribute4); 58 59 DXAttributes atts2 = new DXAttributes(); 60 atts2.put(attribute4); 61 atts2.put(attribute3); 62 atts2.put(attribute1); 63 atts2.put(attribute2); 64 65 assertEquals("chack that DXAttributes containing the same unordered list of attribute objects are equal", 66 atts1, atts2); 67 68 atts2.remove("att2"); 69 assertTrue("check that DXAttributes with different sizes aren't equal", 70 !atts1.equals(atts2)); 71 72 atts2.put(attribute5); 73 assertTrue("check that DXAttributes with same sizes but different att objects aren't equal", 74 !atts1.equals(atts2)); 75 76 assertTrue("check null not equal...", 77 !empty.equals(null)); 78 79 atts2.remove("att1"); 80 atts2.remove("att3"); 81 atts2.remove("att4"); 82 atts2.remove("att5"); 83 assertEquals("check empty atts always equal...", 84 empty, atts2); 85 86 assertTrue(DXAttributes.attributesEqual(null, null)); 87 assertTrue(!DXAttributes.attributesEqual(null, new DXAttributes())); 88 assertTrue(!DXAttributes.attributesEqual(new DXAttributes(), null)); 89 } 90 catch (Exception e) 91 { 92 System.out.println("unexpected exception in DXAttributesTest: " + e); 93 e.printStackTrace(); 94 } 95 } 96 97 104 public void DONTtestExpandAllAttributes1() 106 throws Exception 107 { 108 ConnectionData cData = new ConnectionData(); 109 cData.setURL("ldap://betch01:19389"); 110 DirContext ctx = BasicOps.openContext(cData); 111 DXAttributes a = new DXAttributes(ctx.getAttributes("ou=Manufacturing,o=DEMOCORP,c=AU")); 113 SchemaOps schemaOps = new SchemaOps(ctx); 114 ctx.addToEnvironment("java.naming.ldap.attributes.binary", schemaOps.getNewBinaryAttributes()); 115 a.expandAllAttributes(); 118 } 119 120 127 public void DONTtestExpandAllAttributes2() 129 throws Exception 130 { 131 ConnectionData cData = new ConnectionData(); 132 cData.setURL("ldap://betch01:19389"); 133 DirContext ctx = BasicOps.openContext(cData); 134 DXAttributes a = new DXAttributes(ctx.getAttributes("ou=Manufacturing,o=DEMOCORP,c=AU")); 136 SchemaOps schemaOps = new SchemaOps(ctx); 137 ctx.addToEnvironment("java.naming.ldap.attributes.binary", schemaOps.getNewBinaryAttributes()); 138 DXAttributes.setDefaultSchema(schemaOps); 139 a.expandAllAttributes(); 141 } 142 149 public void DONTtestExpandAllAttributes3() 151 throws Exception 152 { 153 ConnectionData cData = new ConnectionData(); 154 cData.setURL("ldap://betch01:19389"); 155 DirContext ctx = BasicOps.openContext(cData); 156 157 DXAttributes a = new DXAttributes(ctx.getAttributes("ou=Manufacturing,o=DEMOCORP,c=AU")); 159 SchemaOps schemaOps = new SchemaOps(ctx); 160 ctx.addToEnvironment("java.naming.ldap.attributes.binary", schemaOps.getNewBinaryAttributes()); 161 DXAttribute.setDefaultSchema(schemaOps); 163 a.expandAllAttributes(); 164 } 165 172 public void DONTtestExpandAllAttributes4() 174 throws Exception 175 { 176 ConnectionData cData = new ConnectionData(); 177 cData.setURL("ldap://betch01:19389"); 178 DirContext ctx = BasicOps.openContext(cData); 179 DXAttributes a = new DXAttributes(ctx.getAttributes("ou=Manufacturing,o=DEMOCORP,c=AU")); 181 SchemaOps schemaOps = new SchemaOps(ctx); 182 ctx.addToEnvironment("java.naming.ldap.attributes.binary", schemaOps.getNewBinaryAttributes()); 183 DXAttributes.setDefaultSchema(schemaOps); 184 DXAttribute.setDefaultSchema(schemaOps); 185 a.expandAllAttributes(); 186 } 187 188 189 196 214 } 215 | Popular Tags |