| Home >> All >> org >> media >> naming >> [ test Javadoc ] |
Source code: org/media/naming/test/AllNamingTestCase.java
1 /* 2 * $COPYRIGHT$ 3 * $Id: AllNamingTestCase.java,v 1.5 2002/07/04 21:56:31 neuro Exp $ 4 * 5 * Date Author Changes 6 * May 10 2001 Remus Pereni Created 7 */ 8 package org.media.naming.test; 9 10 import junit.framework.*; 11 import javax.naming.Context; 12 import javax.naming.InitialContext; 13 import javax.naming.NamingException; 14 import javax.naming.NameClassPair; 15 import javax.naming.NamingEnumeration; 16 import java.util.Hashtable; 17 import org.media.naming.*; 18 19 /** 20 * Class meant to run all the Test Cases related to mn8 naming package. 21 * @author <a href="mailto:remus@nolimits.ro">Remus Pereni</a> 22 * @version $Revision: 1.5 $ $Date: 2002/07/04 21:56:31 $ 23 */ 24 public class AllNamingTestCase extends TestCase { 25 26 private Context _initContext; 27 28 29 public AllNamingTestCase (String name){ 30 super (name); 31 } 32 33 protected void setUp () { 34 Hashtable env = new Hashtable(); 35 env.put(Context.INITIAL_CONTEXT_FACTORY, 36 "org.media.naming.MemoryContextFactory"); 37 env.put(Context.PROVIDER_URL, 38 "env:/"); 39 40 try { 41 _initContext = new InitialContext(env); 42 } catch (NamingException nex) { 43 nex.printStackTrace(); 44 } 45 46 } 47 48 public static Test suite () { 49 TestSuite suite = new TestSuite(); 50 suite.addTest(new AllNamingTestCase("memoryContextCreate")); 51 suite.addTest(new AllNamingTestCase("memoryContextCreateSubcontext")); 52 suite.addTest(new AllNamingTestCase("memoryContextDestroySubcontext")); 53 suite.addTest(new AllNamingTestCase("memoryContextBind")); 54 suite.addTest(new AllNamingTestCase("memoryContextLookup")); 55 suite.addTest(new AllNamingTestCase("memoryContextRebind")); 56 suite.addTest(new AllNamingTestCase("memoryContextRename")); 57 suite.addTest(new AllNamingTestCase("memoryContextList")); 58 suite.addTest(new AllNamingTestCase("memoryContextUnbind")); 59 suite.addTest(new AllNamingTestCase("memoryContextClose")); 60 return suite; 61 } 62 63 public void memoryContextCreate () { 64 if (_initContext != null) assertTrue(true); 65 else assertTrue(false); 66 } 67 68 69 public void memoryContextCreateSubcontext () { 70 try { 71 Context sctx = _initContext.createSubcontext("test"); 72 if ( sctx!= null ) assertTrue (true); 73 else assertTrue (false); 74 } catch (NamingException nex) { 75 nex.printStackTrace(); 76 assertTrue (false); 77 } 78 } 79 80 public void memoryContextDestroySubcontext () { 81 try { 82 _initContext.destroySubcontext("test"); 83 assertTrue (true); 84 } catch (Exception ex) { 85 ex.printStackTrace(); 86 assertTrue (false); 87 } 88 } 89 90 public void memoryContextBind () { 91 try { 92 _initContext.bind("test", "TEST_VALUE"); 93 assertTrue (true); 94 } catch (Exception ex) { 95 ex.printStackTrace(); 96 assertTrue (false); 97 } 98 } 99 100 public void memoryContextLookup () { 101 try { 102 String value = (String) _initContext.lookup("test"); 103 if (value.equals("TEST_VALUE")) 104 assertTrue (true); 105 else 106 assertTrue (false); 107 } catch (Exception ex) { 108 ex.printStackTrace(); 109 assertTrue (false); 110 } 111 } 112 113 114 public void memoryContextRebind () { 115 try { 116 _initContext.rebind("test", "NEW_TEST_VALUE"); 117 String value = (String) _initContext.lookup("test"); 118 if (value.equals("NEW_TEST_VALUE")) 119 assertTrue (true); 120 else 121 assertTrue (false); 122 123 } catch (Exception ex) { 124 ex.printStackTrace(); 125 assertTrue (false); 126 } 127 } 128 129 public void memoryContextRename () { 130 try { 131 _initContext.rename("test", "new_name"); 132 String value = (String) _initContext.lookup("new_name"); 133 if (value.equals("NEW_TEST_VALUE")) 134 assertTrue (true); 135 else 136 assertTrue (false); 137 138 } catch (Exception ex) { 139 ex.printStackTrace(); 140 assertTrue (false); 141 } 142 } 143 144 145 public void memoryContextList () { 146 try { 147 NamingEnumeration nen = _initContext.list(""); 148 while ( nen.hasMore() ) { 149 String name = ((NameClassPair) nen.next()).getName(); 150 if (name.equals("new_name")) 151 assertTrue (true); 152 else 153 assertTrue (false); 154 } 155 } catch (Exception ex) { 156 ex.printStackTrace(); 157 assertTrue (false); 158 } 159 } 160 161 162 public void memoryContextUnbind () { 163 try { 164 _initContext.unbind( "new_name"); 165 NamingEnumeration nen = _initContext.list(""); 166 while ( nen.hasMore() ) 167 assertTrue (false); 168 assertTrue (true); 169 } catch (Exception ex) { 170 ex.printStackTrace(); 171 assertTrue (false); 172 } 173 } 174 175 176 177 public void memoryContextClose () { 178 try { 179 _initContext.close(); 180 assertTrue (true); 181 } catch (Exception ex) { 182 ex.printStackTrace(); 183 assertTrue (false); 184 } 185 } 186 187 188 189 190 public static void main (String[] args) { 191 junit.textui.TestRunner.run (suite()); 192 } 193 194 }