001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.harmony.jndi.tests.javax.naming;
019:
020: import java.util.Hashtable;
021:
022: import javax.naming.CompositeName;
023: import javax.naming.Context;
024: import javax.naming.InitialContext;
025: import javax.naming.InvalidNameException;
026: import javax.naming.Name;
027: import javax.naming.NamingException;
028: import javax.naming.NoInitialContextException;
029:
030: import junit.framework.TestCase;
031: import org.apache.harmony.jndi.tests.javax.naming.spi.mock.DazzleActionController;
032: import org.apache.harmony.jndi.tests.javax.naming.spi.mock.InvokeRecord;
033: import org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockActionController;
034: import org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockContext;
035: import org.apache.harmony.jndi.tests.javax.naming.util.Log;
036: import org.apache.harmony.jndi.tests.javax.naming.util.Person;
037:
038: public class InitialContextMockTest extends TestCase {
039:
040: static Log log = new Log(InitialContextMockTest.class);
041:
042: private Context gContext;
043:
044: private final String urlSchema = "http";
045:
046: @Override
047: protected void setUp() throws Exception {
048: super .setUp();
049: Hashtable<String, String> env = new Hashtable<String, String>();
050: env
051: .put(Context.INITIAL_CONTEXT_FACTORY,
052: "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockContextFactory");
053: env.put(Context.URL_PKG_PREFIXES,
054: "org.apache.harmony.jndi.tests.javax.naming.spi.mock");
055: gContext = new InitialContext(env);
056:
057: }
058:
059: public void testAddToEnvironment() throws NamingException {
060: Object value = gContext.addToEnvironment(
061: Context.INITIAL_CONTEXT_FACTORY, "");
062:
063: assertEquals(
064: "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockContextFactory",
065: value);
066: assertEquals("", gContext.getEnvironment().get(
067: Context.INITIAL_CONTEXT_FACTORY));
068: }
069:
070: public void testAddToEnvironment_batchsize() throws NamingException {
071: Integer batchSize = new Integer(100);
072: gContext.addToEnvironment(Context.BATCHSIZE, batchSize);
073: assertEquals(batchSize, gContext.getEnvironment().get(
074: Context.BATCHSIZE));
075: }
076:
077: public void testAddToEnvironment_applet() throws NamingException {
078: log.setMethod("testAddToEnvironment_applet");
079:
080: String applet = "java.applet.Applet";
081: gContext.addToEnvironment(Context.APPLET, applet);
082: assertEquals(applet, gContext.getEnvironment().get(
083: Context.APPLET));
084: }
085:
086: public void testBind() throws NamingException {
087: Person person = Person.getInstance();
088: Name name = new CompositeName(person.getName());
089: gContext.bind(name, person);
090: assertTrue(InvokeRecord.equals(null, name, person));
091: }
092:
093: public void testBind_namenull() throws NamingException {
094: String strObj = "bind object";
095: try {
096: gContext.bind((Name) null, strObj);
097: fail("should throw NullPointerException!");
098: } catch (NullPointerException e) {
099: }
100: }
101:
102: public void testBind_objectnull() throws NamingException {
103: Name name = new CompositeName("bindname");
104: gContext.bind(name, null);
105: assertTrue(InvokeRecord.equals(null, name, null));
106: }
107:
108: public void testBind_url() throws NamingException {
109: Person person = Person.getInstance();
110: Name name = new CompositeName(
111: "'http://www.apache.org/foundation'");
112: gContext.bind(name, person);
113: assertTrue(InvokeRecord.equals(urlSchema, name, person));
114: }
115:
116: public void testBind_name_empty() throws NamingException {
117: log.setMethod("testBind_name_empty");
118: Person person = Person.getInstance();
119: Name name = new CompositeName("");
120: gContext.bind(name, person);
121: assertTrue(InvokeRecord.equals(null, name, person));
122: }
123:
124: public void testBind_runtimeException() throws NamingException {
125: log.setMethod("testBind_runtimeException");
126:
127: MockActionController actionController = new MockActionController();
128: actionController.addAction(
129: DazzleActionController.THROW_RUNTIMEEXCEPTION, "1");
130: MockContext.setActionController(actionController);
131:
132: Person person = Person.getInstance();
133: Name name = new CompositeName(person.getName());
134: try {
135: gContext.bind(name, person);
136: fail("Should throw RuntimeException.");
137: } catch (RuntimeException e) {
138: // log.log(e.getClass().getName());
139: // log.log(e.toString());
140: }
141: }
142:
143: public void testBind_nullPointerException() throws NamingException {
144: log.setMethod("testBind_nullPointerException");
145:
146: MockActionController actionController = new MockActionController();
147: actionController.addAction(
148: DazzleActionController.THROW_NULLPOINTEREXCEPTION, "1");
149: MockContext.setActionController(actionController);
150:
151: Person person = Person.getInstance();
152: Name name = new CompositeName(person.getName());
153: try {
154: gContext.bind(name, person);
155: fail("Should throw NullPointerException.");
156: } catch (NullPointerException e) {
157: // log.log(e.getClass().getName());
158: // log.log(e.toString());
159: }
160: }
161:
162: public void testComposeName_name_empty() throws NamingException {
163: log.setMethod("testComposeName_name_empty");
164: Name name = new CompositeName("hmy");
165: Name pfx = new CompositeName("");
166: gContext.composeName(name, pfx);
167: // assertFalse(InvokeRecord.equals(null, name, pfx));
168: }
169:
170: public void testComposeName_name_validName() throws NamingException {
171: log.setMethod("testComposeName_name_validName");
172: Name name = new CompositeName("validname");
173: Name pfx = new CompositeName("");
174: gContext.composeName(name, pfx);
175: // assertTrue(InvokeRecord.equals(null, name, pfx));
176: }
177:
178: public void testComposeName_name_InvalidName()
179: throws NamingException {
180: log.setMethod("testComposeName_name_InvalidName");
181: Name name = new CompositeName("Invalidname1");
182: Name pfx = new CompositeName("InvalidName2");
183: gContext.composeName(name, pfx);
184: // assertTrue(InvokeRecord.equals(null, name, pfx));
185: }
186:
187: public void testComposeName_name_pfx_null() throws NamingException {
188: log.setMethod("testComposeName_name_pfx_null");
189: Name name = new CompositeName("namepfxnull");
190: gContext.composeName(name, null);
191: // assertFalse(InvokeRecord.equals(null, name, null));
192: }
193:
194: /**
195: * @tests javax.naming.InitialContext#composeName(Name,Name)
196: */
197: public void testComposeNameLjavax_naming_NameLjavax_naming_Name()
198: throws NamingException {
199: log.setMethod("testComposeName_string_null"); //$NON-NLS-1$
200: InitialContext initialContext = new InitialContext();
201:
202: try {
203: initialContext.composeName((CompositeName) null,
204: (CompositeName) null);
205: fail("Should throw NullPointerException"); //$NON-NLS-1$
206: } catch (NullPointerException e) {
207: // expected
208: }
209:
210: try {
211: initialContext.composeName(null,
212: new CompositeName("prefix")); //$NON-NLS-1$
213: fail("Should throw NullPointerException"); //$NON-NLS-1$
214: } catch (NullPointerException e) {
215: // expected
216: }
217:
218: Name result = initialContext.composeName(new CompositeName(
219: "a/b/c"), (CompositeName) null); //$NON-NLS-1$
220: assertEquals("a/b/c", result.toString()); //$NON-NLS-1$
221:
222: result = initialContext.composeName(
223: new CompositeName("a/b/c"), new CompositeName("")); //$NON-NLS-1$//$NON-NLS-2$
224: assertEquals("a/b/c", result.toString()); //$NON-NLS-1$
225:
226: result = initialContext
227: .composeName(
228: new CompositeName("a/b/c"), new CompositeName("prefix")); //$NON-NLS-1$//$NON-NLS-2$
229: assertEquals("a/b/c", result.toString()); //$NON-NLS-1$
230:
231: result = initialContext.composeName(new CompositeName(
232: "testString"), new CompositeName("a/b/c/d")); //$NON-NLS-1$//$NON-NLS-2$
233: assertEquals("testString", result.toString()); //$NON-NLS-1$
234:
235: CompositeName cn = new CompositeName("a/b/c"); //$NON-NLS-1$
236: result = initialContext.composeName(cn, new CompositeName(
237: "prefix")); //$NON-NLS-1$
238: cn.add("/d"); //$NON-NLS-1$
239: assertEquals("a/b/c", result.toString()); //$NON-NLS-1$
240: }
241:
242: /**
243: * @tests javax.naming.InitialContext#composeName(String,String)
244: */
245: public void testComposeNameLjava_lang_StringLjava_lang_String()
246: throws NamingException {
247: log.setMethod("testComposeName_string_null"); //$NON-NLS-1$
248: InitialContext initialContext = new InitialContext();
249:
250: String result = initialContext.composeName((String) null,
251: (String) null);
252: assertNull(result);
253:
254: result = initialContext.composeName((String) null, ""); //$NON-NLS-1$
255: assertNull(result);
256:
257: result = initialContext.composeName("a/b/c", (String) null); //$NON-NLS-1$ //$NON-NLS-2$
258: assertEquals("a/b/c", result); //$NON-NLS-1$
259:
260: result = initialContext.composeName("a/b/c", ""); //$NON-NLS-1$ //$NON-NLS-2$
261: assertEquals("a/b/c", result); //$NON-NLS-1$
262:
263: result = initialContext.composeName("a/b/c", "prefix"); //$NON-NLS-1$ //$NON-NLS-2$
264: assertEquals("a/b/c", result); //$NON-NLS-1$
265:
266: result = initialContext.composeName("testString", "a/b/c/d"); //$NON-NLS-1$ //$NON-NLS-2$
267: assertEquals("testString", result); //$NON-NLS-1$
268: }
269:
270: public void testComposeName_string_pfx_null()
271: throws NamingException {
272: log.setMethod("testComposeName_string_pfx_null");
273: String name = "stringpfxnull";
274: String pfx = null;
275: gContext.composeName(name, pfx);
276: // assertFalse(InvokeRecord.equals(null, name, null));
277: }
278:
279: public void testComposeName_string_return() throws NamingException {
280: String name = "child_str";
281: String pfx = "parent_str";
282: String composeName = gContext.composeName(name, pfx);
283: assertNotNull(composeName);
284: }
285:
286: public void testComposeName_name_return() throws NamingException {
287: Name name = new CompositeName("child_name");
288: Name pfx = new CompositeName("parent_name");
289: Name composeName = gContext.composeName(name, pfx);
290: assertNotNull(composeName);
291: }
292:
293: public void testCreateSubcontext() throws NamingException {
294: Name name = new CompositeName("hmy");
295: gContext.createSubcontext(name);
296: assertTrue(InvokeRecord.equals(null, name));
297: }
298:
299: public void testCreateSubcontext_null() throws NamingException {
300: log.setMethod("testCreateSubcontext_null");
301: try {
302: gContext.createSubcontext((Name) null);
303: fail("Should throw NullPointerException.");
304: } catch (NullPointerException e) {
305: // log.log(e.toString());
306: }
307: // assertTrue(InvokeRecord.equals(null, null));
308: }
309:
310: public void testCreateSubcontext_url() throws NamingException {
311: String name = "http://www.apache.org/foundation";
312: gContext.createSubcontext(name);
313: assertTrue(InvokeRecord.equals(urlSchema, name));
314: }
315:
316: public void testCreateSubcontext_runtimeException()
317: throws NamingException {
318: log.setMethod("testCreateSubcontext_runtimeException");
319:
320: MockActionController actionController = new MockActionController();
321: actionController.addAction(
322: DazzleActionController.THROW_RUNTIMEEXCEPTION, "1");
323: MockContext.setActionController(actionController);
324:
325: Name name = new CompositeName("hmy");
326: try {
327: gContext.createSubcontext(name);
328: fail("Should throw RuntimeException.");
329: } catch (RuntimeException e) {
330: // log.log(e.getClass().getName());
331: // log.log(e.toString());
332: }
333: }
334:
335: public void testDestroySubcontext() throws NamingException {
336: Name name = new CompositeName("hmy");
337: gContext.destroySubcontext(name);
338: assertTrue(InvokeRecord.equals(null, name));
339: }
340:
341: public void testDestroySubcontext_null() throws NamingException {
342: log.setMethod("testDestroySubcontext_null");
343: try {
344: gContext.destroySubcontext((Name) null);
345: fail("Should throw NullPointerException.");
346: } catch (NullPointerException e) {
347: // log.log(e.toString());
348: }
349: // assertTrue(InvokeRecord.equals(null, null));
350: }
351:
352: public void testDestroySubcontext_string_null()
353: throws NamingException {
354: log.setMethod("testDestroySubcontext_string_null");
355: try {
356: gContext.destroySubcontext((String) null);
357: fail("Should throw NullPointerException.");
358: } catch (NullPointerException e) {
359: // log.log(e.toString());
360: }
361: // assertTrue(InvokeRecord.equals(null, null));
362: }
363:
364: public void testDestroySubcontext_url() throws NamingException {
365: String name = "http://ww.apache.org/foundation";
366: gContext.destroySubcontext(name);
367: assertTrue(InvokeRecord.equals(urlSchema, name));
368: }
369:
370: public void testGetNameInNamespace() throws NamingException {
371: MockActionController controller = new MockActionController();
372: controller.addAction(DazzleActionController.RETURN_NULL, "1");
373: MockContext.setActionController(controller);
374: String nameSpace = gContext.getNameInNamespace();
375: assertNull(nameSpace);
376: }
377:
378: public void testGetNameParser() throws NamingException {
379: Name name = new CompositeName("hmy");
380: gContext.getNameParser(name);
381: assertTrue(InvokeRecord.equals(null, name));
382: }
383:
384: public void testGetNameParser_null() throws NamingException {
385: log.setMethod("testGetNameParser_null");
386: try {
387: gContext.getNameParser((Name) null);
388: fail("Should throw NullPointerException.");
389: } catch (NullPointerException e) {
390: // log.log(e.toString());
391: }
392: // assertTrue(InvokeRecord.equals(null, null));
393: }
394:
395: public void testGetNameParser_url() throws NamingException {
396: String name = "http://www.apache.org/foundation";
397: gContext.getNameParser(name);
398: assertTrue(InvokeRecord.equals(urlSchema, name));
399: }
400:
401: public void testList() throws NamingException {
402: Name name = new CompositeName("hmy");
403: gContext.list(name);
404: assertTrue(InvokeRecord.equals(null, name));
405: }
406:
407: public void testList_null() throws NamingException {
408: log.setMethod("testList_null");
409: Name name = null;
410: try {
411: gContext.list(name);
412: fail("Should throw NullPointerException.");
413: } catch (NullPointerException e) {
414: // log.log(e.toString());
415: }
416: // assertTrue(InvokeRecord.equals(null, name));
417: }
418:
419: public void testList_url() throws NamingException {
420: Name name = new CompositeName(
421: "'http://www.apache.org/foundation'");
422: gContext.list(name);
423: assertTrue(InvokeRecord.equals(urlSchema, name));
424: }
425:
426: public void testListBindings() throws NamingException {
427: Name name = new CompositeName("hmy");
428: gContext.listBindings(name);
429: assertTrue(InvokeRecord.equals(null, name));
430: }
431:
432: public void testListBindings_stringnull() throws NamingException {
433: log.setMethod("testListBindings_stringnull");
434: String name = null;
435: try {
436: gContext.listBindings(name);
437: fail("Should throw NullPointerException.");
438: } catch (NullPointerException e) {
439: // log.log(e.toString());
440: }
441: // assertTrue(InvokeRecord.equals(null, name));
442: }
443:
444: public void testListBindings_url() throws NamingException {
445: Name name = new CompositeName(
446: "'http://www.apache.org/foundation'");
447: gContext.listBindings(name);
448: assertTrue(InvokeRecord.equals(urlSchema, name));
449: }
450:
451: public void testLookup() throws NamingException {
452: Name name = new CompositeName("hmy");
453: gContext.lookup(name);
454: assertTrue(InvokeRecord.equals(null, name));
455: }
456:
457: public void testLookup_null() throws NamingException {
458: log.setMethod("testLookup_null");
459:
460: Name name = null;
461: try {
462: gContext.lookup(name);
463: fail("Should throw NullPointerException.");
464: } catch (NullPointerException e) {
465: // log.log(e.toString());
466: }
467: // assertTrue(InvokeRecord.equals(null, name));
468: }
469:
470: public void testLookup_url() throws NamingException {
471: Name name = new CompositeName(
472: "'http://www.apache.org/foundation'");
473: gContext.lookup(name);
474: assertTrue(InvokeRecord.equals(urlSchema, name));
475: }
476:
477: public void testLookup_string_url() throws NamingException {
478: log.setMethod("testLookup_string_url");
479:
480: String name = "'http://www.apache.org/foundation'";
481: gContext.lookup(name);
482: assertTrue(InvokeRecord.equals(null, name));
483: }
484:
485: public void testLookup_string_empty() throws NamingException {
486: String name = "";
487: gContext.lookup(name);
488: assertTrue(InvokeRecord.equals(null, name));
489: }
490:
491: public void testLookupLink_url() throws NamingException {
492: Name name = new CompositeName(
493: "'http://www.apache.org/foundation'");
494: gContext.lookupLink(name);
495: assertTrue(InvokeRecord.equals(urlSchema, name));
496: }
497:
498: public void testLookupLink() throws NamingException {
499: String name = "hmy";
500: gContext.lookupLink(name);
501: assertTrue(InvokeRecord.equals(null, name));
502: }
503:
504: public void testLookupLink_null() throws NamingException {
505: log.setMethod("testLookupLink_null");
506:
507: String name = null;
508: try {
509: gContext.lookupLink(name);
510: fail("Should throw NullPointerException.");
511: } catch (NullPointerException e) {
512: // log.log(e.toString());
513: }
514: // assertTrue(InvokeRecord.equals(null, name));
515: }
516:
517: public void testRebind() throws NamingException {
518: Name name = new CompositeName("hmy");
519: Person person = Person.getInstance();
520: gContext.rebind(name, person);
521: assertTrue(InvokeRecord.equals(null, name, person));
522: }
523:
524: public void testRebind_objectnull() throws NamingException {
525: Name name = new CompositeName("hmy");
526: gContext.rebind(name, null);
527: assertTrue(InvokeRecord.equals(null, name, null));
528: }
529:
530: public void testRebind_namenull() throws NamingException {
531: log.setMethod("testRebind_namenull");
532: Name name = null;
533: Person person = Person.getInstance();
534: try {
535: gContext.rebind(name, person);
536: fail("Should throw NullPointerException.");
537: } catch (NullPointerException e) {
538: // log.log(e.toString());
539: }
540: // assertTrue(InvokeRecord.equals(null, name, person));
541: }
542:
543: public void testRebind_url() throws NamingException {
544: String name = "http://www.apache.org/foundation";
545: Person person = Person.getInstance();
546: gContext.rebind(name, person);
547: assertTrue(InvokeRecord.equals(urlSchema, name, person));
548: }
549:
550: public void testRemoveFromEnvironment() throws NamingException {
551: String name = Context.INITIAL_CONTEXT_FACTORY;
552: assertEquals(
553: "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockContextFactory",
554: gContext.removeFromEnvironment(name));
555:
556: }
557:
558: public void testReName() throws NamingException {
559: String oldName = "apache";
560: String newName = "harmony";
561: gContext.rename(oldName, newName);
562:
563: assertTrue(InvokeRecord.equals(null, oldName, newName));
564: }
565:
566: public void testReName_null() throws NamingException {
567: log.setMethod("testReName_null");
568: String oldName = null;
569: String newName = null;
570: try {
571: gContext.rename(oldName, newName);
572: fail("Should throw NullPointerException.");
573: } catch (NullPointerException e) {
574: // log.log(e.toString());
575: }
576: // assertTrue(InvokeRecord.equals(null, oldName, newName));
577: }
578:
579: public void testReName_url_oldName() throws NamingException {
580: Name oldName = new CompositeName(
581: "'http://www.apache.org/index.html'");
582: Name newName = new CompositeName("harmony");
583: gContext.rename(oldName, newName);
584: assertTrue(InvokeRecord.equals(urlSchema, oldName, newName));
585: }
586:
587: public void testReName_url_newName() throws NamingException {
588: log.setMethod("testReName_url_newName");
589: Name oldName = new CompositeName("harmony");
590: Name newName = new CompositeName(
591: "'http://www.apache.org/index.html'");
592: gContext.rename(oldName, newName);
593:
594: assertTrue(InvokeRecord.equals(null, oldName, newName));
595: }
596:
597: public void testReName_newname_empty() throws NamingException {
598: log.setMethod("testReName_newname_empty");
599: Name oldName = new CompositeName("hmy");
600: Name newName = new CompositeName("");
601: gContext.rename(oldName, newName);
602: assertTrue(InvokeRecord.equals(null, oldName, newName));
603: }
604:
605: public void testReName_oldname_empty() throws NamingException {
606: log.setMethod("testReName_oldname_empty");
607: Name oldName = new CompositeName("");
608: Name newName = new CompositeName("hmy");
609: gContext.rename(oldName, newName);
610: assertTrue(InvokeRecord.equals(null, oldName, newName));
611: }
612:
613: public void testUnbind() throws NamingException {
614: Name name = new CompositeName("hmy");
615: gContext.unbind(name);
616: assertTrue(InvokeRecord.equals(null, name));
617: }
618:
619: public void testUnbind_null() throws NamingException {
620: log.setMethod("testUnbind_null");
621: String name = null;
622: try {
623: gContext.unbind(name);
624: fail("Should throw NullPointerException.");
625: } catch (NullPointerException e) {
626: // log.log(e.toString());
627: }
628: // assertTrue(InvokeRecord.equals(null, name));
629: }
630:
631: public void testUnbind_url() throws NamingException {
632: Name name = new CompositeName("'http://www.apache.org'");
633: gContext.unbind(name);
634: assertTrue(InvokeRecord.equals(urlSchema, name));
635: }
636:
637: public void testGetNameParser_string() throws NamingException {
638: String name1 = "sub1";
639: gContext.createSubcontext(name1);
640:
641: String name = "";
642: gContext.getNameParser(name);
643: assertTrue(InvokeRecord.equals(null, name));
644:
645: gContext.getNameParser(name1);
646: assertTrue(InvokeRecord.equals(null, name1));
647: }
648:
649: public void testGetNameParser_string_url() throws NamingException {
650: gContext.createSubcontext("sub1");
651: String name = "http://www.apache.org";
652: gContext.getNameParser(name);
653: assertTrue(InvokeRecord.equals(urlSchema, name));
654: }
655:
656: public void testGetNameParser_name() throws NamingException {
657: Name name1 = new CompositeName("sub1");
658: gContext.createSubcontext(name1);
659: Name name = new CompositeName("");
660: gContext.getNameParser(name);
661: assertTrue(InvokeRecord.equals(null, name));
662:
663: gContext.getNameParser(name1);
664: assertTrue(InvokeRecord.equals(null, name1));
665: }
666:
667: public void testGetNameParser_name_url() throws NamingException {
668: gContext.createSubcontext("sub1");
669: Name name = new CompositeName("'http://www.apache.org'");
670: gContext.getNameParser(name);
671: assertTrue(InvokeRecord.equals(urlSchema, name));
672: }
673:
674: public void testInvalidFactory() throws NamingException {
675: log.setMethod("testInvalidFactory");
676:
677: Hashtable<String, String> env = new Hashtable<String, String>();
678: env
679: .put(Context.INITIAL_CONTEXT_FACTORY,
680: "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockContext");
681: try {
682: new InitialContext(env);
683: fail("Should throw NoInitialContextException");
684: } catch (NoInitialContextException e) {
685: }
686:
687: env
688: .put(Context.INITIAL_CONTEXT_FACTORY,
689: "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockContext12345");
690: try {
691: new InitialContext(env);
692: fail("Should throw NoInitialContextException");
693: } catch (NoInitialContextException e) {
694: }
695: }
696:
697: public void testDefaultConstructor() throws NamingException {
698: System
699: .setProperty(Context.INITIAL_CONTEXT_FACTORY,
700: "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockContextFactory");
701: InitialContext context = new InitialContext();
702: context.bind("name", "object");
703: assertTrue(InvokeRecord.equals(null, "name", "object"));
704: }
705:
706: public void testClose() throws NamingException {
707: gContext.close();
708: assertTrue(InvokeRecord.equals(null, "close"));
709: // regression test for HARMONY-1022
710: new InitialContext().close();
711: new InitialContext(null).close();
712: }
713: }
|