1 package org.jacorb.trading.test; 2 3 import org.omg.CosTrading.*; 4 import org.omg.CosTrading.RegisterPackage.*; 5 import org.omg.CosTrading.LookupPackage.*; 6 import org.omg.CosTrading.LinkPackage.*; 7 import org.omg.CosTradingRepos.*; 8 import org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.*; 9 import org.omg.CORBA.*; 10 import java.io.*; 11 12 18 public class ExceptionTest{ 19 public static void main(String [] args) { 20 if (args.length == 0){ 21 System.out.println("Usage: ExceptionTest <ior-file>"); 22 System.exit(0); 23 } 24 25 int _correct_results = 0; 26 int _incorrect_results = 0; 27 28 try{ 29 30 Runtime _rt = Runtime.getRuntime(); 32 new OutputForwarder(_rt.exec("ts " + args[0] + " -d db"), "Trader"); 33 34 System.out.println("Press any key when Trader is ready"); 35 System.in.read(); 36 37 org.omg.CORBA.ORB _orb = org.omg.CORBA.ORB.init(args, null); 39 40 BufferedReader _ior_in = new BufferedReader(new FileReader(new File(args[0]))); 42 String _ior_str = _ior_in.readLine(); 43 _ior_in.close(); 44 45 Lookup _lookup = LookupHelper.narrow(_orb.string_to_object(_ior_str)); 47 48 if( _lookup == null ){ 49 System.out.println("No lookup!"); 50 System.exit(1); 51 } 52 53 Link _link = LinkHelper.narrow(_lookup.link_if()); 54 55 if( _link == null ) 56 { 57 System.out.println("No link!"); 58 System.exit(1); 59 } 60 61 System.out.println("********** Testing exceptions **********"); 62 63 64 try{ 66 System.out.println("\nExpecting IllegalLinkName"); 67 _link.add_link("", _lookup, FollowOption.if_no_local, FollowOption.if_no_local); 68 }catch(Exception _e){ 69 System.out.println("Caught " + _e.toString()); 70 if (_e instanceof IllegalLinkName){ 71 System.out.println("Test passed"); 72 _correct_results++; 73 } 74 else{ 75 System.out.println("Test failed"); 76 _incorrect_results++; 77 } 78 } 79 80 try{ 82 _link.add_link("link", _lookup, FollowOption.if_no_local, FollowOption.if_no_local); 83 System.out.println("\nExpecting DuplicateLinkName"); 84 _link.add_link("link", _lookup, FollowOption.if_no_local, FollowOption.if_no_local); 85 }catch(Exception _e){ 86 System.out.println("Caught " + _e.toString()); 87 if (_e instanceof DuplicateLinkName){ 88 System.out.println("Test passed"); 89 _correct_results++; 90 } 91 else{ 92 System.out.println("Test failed"); 93 _incorrect_results++; 94 } 95 } 96 97 try{ 99 System.out.println("\nExpecting InvalidLookupRef"); 100 _link.add_link("link2", null, FollowOption.if_no_local, FollowOption.if_no_local); 101 }catch(Exception _e){ 102 System.out.println("Caught " + _e.toString()); 103 if (_e instanceof InvalidLookupRef){ 104 System.out.println("Test passed"); 105 _correct_results++; 106 } 107 else{ 108 System.out.println("Test failed"); 109 _incorrect_results++; 110 } 111 } 112 113 try{ 115 System.out.println("\nExpecting DefaultFollowTooPermissive"); 116 _link.add_link("link3", _lookup, FollowOption.if_no_local, FollowOption.local_only); 117 }catch(Exception _e){ 118 System.out.println("Caught " + _e.toString()); 119 if (_e instanceof DefaultFollowTooPermissive){ 120 System.out.println("Test passed"); 121 _correct_results++; 122 } 123 else{ 124 System.out.println("Test failed"); 125 _incorrect_results++; 126 } 127 } 128 129 try{ 131 System.out.println("\nExpecting LimitingFollowTooPermissive"); 132 _link.add_link("link4", _lookup, FollowOption.if_no_local, FollowOption.always); 133 }catch(Exception _e){ 134 System.out.println("Caught " + _e.toString()); 135 if (_e instanceof LimitingFollowTooPermissive){ 136 System.out.println("Test passed"); 137 _correct_results++; 138 } 139 else{ 140 System.out.println("Test failed"); 141 _incorrect_results++; 142 } 143 } 144 145 try{ 147 _link.add_link("link5", _lookup, FollowOption.if_no_local, FollowOption.if_no_local); 148 _link.modify_link("link5", FollowOption.local_only, FollowOption.local_only); 149 }catch(Exception e){ 150 e.printStackTrace(); 151 } 152 153 154 System.out.println("\n********** Testing link modification **********"); 155 156 LinkInfo _info = _link.describe_link("link5"); 157 if (_info.def_pass_on_follow_rule.value() == FollowOption.local_only.value() && 158 _info.limiting_follow_rule.value() == FollowOption.local_only.value()){ 159 System.out.println("Test passed"); 160 _correct_results++; 161 } 162 else{ 163 System.out.println("Test failed"); 164 _incorrect_results++; 165 } 166 167 System.out.println("\n********** Testing link removing **********"); 168 try{ 170 _link.add_link("link6", _lookup, FollowOption.if_no_local, FollowOption.if_no_local); 171 _link.remove_link("link"); 172 }catch(Exception e){ 173 e.printStackTrace(); 174 } 175 176 String [] _links_names = _link.list_links(); 177 boolean _failed = false; 178 179 for (int i = 0; i < _links_names.length; i++){ 180 if (_links_names[i].equals("link")) 181 _failed = true; 182 } 183 184 if (! _failed){ 185 System.out.println("Test passed"); 186 _correct_results++; 187 } 188 else{ 189 System.out.println("Test failed"); 190 _incorrect_results++; 191 } 192 } 193 catch (Exception e){ 194 e.printStackTrace(); 195 } 196 System.out.println("\n********** Testing finished **********"); 197 System.out.println("Total tests: " + (_correct_results + _incorrect_results)); 198 System.out.println("Correct results: " + _correct_results); 199 System.out.println("Incorrect results: " + _incorrect_results); 200 201 System.exit(0); 202 } 203 } 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | Popular Tags |