KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ca > commons > naming > DXAttributesTest


1 /**
2  *
3  *
4  * Author: Chris Betts
5  * Date: 5/06/2002 / 16:59:37
6  */

7 package com.ca.commons.naming;
8
9 import junit.framework.*;
10 import javax.naming.directory.BasicAttribute JavaDoc;
11 import javax.naming.directory.DirContext JavaDoc;
12
13 import com.ca.commons.jndi.*;
14
15 public class DXAttributesTest extends TestCase
16 {
17     private static final BasicAttribute JavaDoc attribute1 = new BasicAttribute JavaDoc("att1", "value1");
18     private static final BasicAttribute JavaDoc attribute2 = new BasicAttribute JavaDoc("att2", "value2");
19     private static final BasicAttribute JavaDoc attribute3 = new BasicAttribute JavaDoc("att3", "value3");
20     private static final BasicAttribute JavaDoc attribute4 = new BasicAttribute JavaDoc("att4", "value4");
21     private static final BasicAttribute JavaDoc attribute5 = new BasicAttribute JavaDoc("att5", "value5");
22     //private static final BasicAttribute empty1 = new BasicAttribute("att5", null);
23
//private static final BasicAttribute empty2 = new BasicAttribute("att5");
24
//private static final BasicAttribute empty3 = new BasicAttribute("att5", "");
25

26     public DXAttributesTest(String JavaDoc 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 JavaDoc[] 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 JavaDoc e)
91         {
92             System.out.println("unexpected exception in DXAttributesTest: " + e);
93             e.printStackTrace();
94         }
95     }
96
97     /**
98      * Tests the expand all attributes. DXAttribute
99      * has a set default schema - this uses that
100      * in the test b/c
101      * @throws Exception should not throw an
102      * exception.
103      */

104     //TODO - make this a system test. Currently it wont be run - to run remove the DONT from the method name.
105
public void DONTtestExpandAllAttributes1()
106         throws Exception JavaDoc
107     {
108         ConnectionData cData = new ConnectionData();
109         cData.setURL("ldap://betch01:19389");
110         DirContext JavaDoc ctx = BasicOps.openContext(cData);
111         //DirContext ctx = BasicOps.openContext("ldap://betch01:19389");
112
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 // DXAttributes.setDefaultSchema(schemaOps);
116
// DXAttribute.setDefaultSchema(schemaOps);
117
a.expandAllAttributes();
118     }
119
120     /**
121      * Tests the expand all attributes. DXAttribute
122      * has a set default schema - this uses that
123      * in the test b/c
124      * @throws Exception should not throw an
125      * exception.
126      */

127     //TODO - make this a system test. Currently it wont be run - to run remove the DONT from the method name.
128
public void DONTtestExpandAllAttributes2()
129         throws Exception JavaDoc
130     {
131         ConnectionData cData = new ConnectionData();
132         cData.setURL("ldap://betch01:19389");
133         DirContext JavaDoc ctx = BasicOps.openContext(cData);
134         //DirContext ctx = BasicOps.openContext("ldap://betch01:19389");
135
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 // DXAttribute.setDefaultSchema(schemaOps);
140
a.expandAllAttributes();
141     }
142     /**
143      * Tests the expand all attributes. DXAttribute
144      * has a set default schema - this uses that
145      * in the test b/c
146      * @throws Exception should not throw an
147      * exception.
148      */

149     //TODO - make this a system test. Currently it wont be run - to run remove the DONT from the method name.
150
public void DONTtestExpandAllAttributes3()
151         throws Exception JavaDoc
152     {
153         ConnectionData cData = new ConnectionData();
154         cData.setURL("ldap://betch01:19389");
155         DirContext JavaDoc ctx = BasicOps.openContext(cData);
156
157         //DirContext ctx = BasicOps.openContext("ldap://betch01:19389");
158
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 // DXAttributes.setDefaultSchema(schemaOps);
162
DXAttribute.setDefaultSchema(schemaOps);
163         a.expandAllAttributes();
164     }
165     /**
166      * Tests the expand all attributes. DXAttribute
167      * has a set default schema - this uses that
168      * in the test b/c
169      * @throws Exception should not throw an
170      * exception.
171      */

172     //TODO - make this a system test. Currently it wont be run - to run remove the DONT from the method name.
173
public void DONTtestExpandAllAttributes4()
174         throws Exception JavaDoc
175     {
176         ConnectionData cData = new ConnectionData();
177         cData.setURL("ldap://betch01:19389");
178         DirContext JavaDoc ctx = BasicOps.openContext(cData);
179         //DirContext ctx = BasicOps.openContext("ldap://betch01:19389");
180
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     /**
190      * Tests the expand all attributes. DXAttribute
191      * has a set default schema - this uses that
192      * in the test b/c
193      * @throws Exception should not throw an
194      * exception.
195      */

196     /*
197     public void testExpandAllAttributes()
198         throws Exception
199     {
200         DXAttributes atts = new DXAttributes();
201         atts.put(attribute1);
202         atts.put(attribute2);
203         atts.put(attribute3);
204         atts.put(attribute4);
205         atts.put(empty1);
206         atts.put(empty2);
207         atts.put(empty3);
208
209         SchemaOps schemaOps = new SchemaOps(null);
210         DXAttributes.setDefaultSchema(schemaOps);
211         atts.expandAllAttributes();
212     }
213     */

214 }
215
Popular Tags