1 2 package org.quilt.cl; 3 4 import java.io.*; 5 import java.lang.Class ; 6 import java.lang.reflect.*; 7 import java.net.*; 8 import junit.framework.*; 9 10 16 public class TestQCLJars extends TestCase { 17 18 private URL [] cp = null; 19 20 private String [] delegating = { 21 }; 23 private String [] include = { 24 }; 26 private String [] exclude = { 27 "AnonymousClass", "AnonymousClass2Catches", 28 "InnerClass", "NestedTryBlocks", 29 "PrivateClass", "SuperClass", 30 "Wimple" 31 }; 32 private QuiltClassLoader qLoader = null; 33 34 public TestQCLJars (String name) { 35 super(name); 36 } 37 38 public void setUp () { 39 File sam1 = new File ("target/test-data.jar"); 41 String fullPath1 = sam1.getAbsolutePath(); 42 43 File sam2 = new File ("target/classes"); 44 String fullPath2 = sam2.getAbsolutePath() + "/"; 45 File sam3 = new File ("target/test-classes"); 46 String fullPath3 = sam3.getAbsolutePath() + "/"; 47 try { 48 URL [] samples = { 51 new URL ( "file://" + fullPath1), 52 new URL ( "file://" + fullPath2), 53 new URL ( "file://" + fullPath3) 54 }; 55 cp = samples; 56 } catch (MalformedURLException e) { 57 e.printStackTrace(); 58 fail ("problem creating class path"); 59 } 60 qLoader = new QuiltClassLoader( 61 cp, 62 null, delegating, include, exclude); } 67 public void testLoader() { 72 Class a1 = null; 73 Class a2 = null; 74 try { 75 a1 = qLoader.loadClass("AnonymousClass"); 76 } catch (ClassNotFoundException e) { 77 e.printStackTrace(); 78 fail ("Error loading AnonymousClass using loadClass"); 79 } 80 try { 81 a2 = qLoader.loadClass("AnonymousClass"); 82 } catch (ClassNotFoundException e) { 83 fail ("Error loading AnonymousClass using loadClass"); 84 } 85 assertNotNull("qLoader returned null", a1); 86 assertNotNull("qLoader returned null", a2); 87 assertEquals ("second load returned a different class", 88 (Object )a1, (Object )a2); 89 } 90 91 public void testInvokeTestData() { 92 Class a1 = null; 93 Class a2 = null; 94 try { 95 a1 = qLoader.loadClass("AnonymousClass"); 96 } catch (ClassNotFoundException e) { 97 e.printStackTrace(); 98 fail ("Error loading AnonymousClass using loadClass"); 99 } 100 try { 101 a2 = qLoader.loadClass("BasicLoad"); 102 } catch (ClassNotFoundException e) { 103 fail ("Error loading BasicLoad using loadClass"); 104 } 105 RunTest rt = null; 106 try { 108 rt = (RunTest) a1.newInstance(); 109 } catch ( InstantiationException e ) { 110 fail ("error instantiating loaded AnonymousClass"); 111 } catch ( IllegalAccessException e ) { 112 fail ("error instantiating loaded AnonymousClass"); 113 } 114 assertEquals ("AnonymousClass isn't working", 47, rt.runTest(47)); 116 117 try { 119 rt = (RunTest) a2.newInstance(); 120 } catch ( InstantiationException e ) { 121 fail ("error instantiating loaded BasicLoad"); 122 } catch ( IllegalAccessException e ) { 123 fail ("error instantiating loaded BasicLoad"); 124 } 125 assertEquals ("BasicLoad isn't working", 49, rt.runTest(7)); 127 } 128 } 129 | Popular Tags |