1 57 58 package async; 59 60 import junit.framework.Test; 61 import junit.framework.TestCase; 62 import junit.framework.TestSuite; 63 import junit.textui.TestRunner; 64 import org.apache.wsif.WSIFCorrelationId; 65 import org.apache.wsif.WSIFCorrelationService; 66 import org.apache.wsif.WSIFException; 67 import org.apache.wsif.util.WSIFCorrelationServiceLocator; 68 import org.apache.wsif.util.jms.WSIFJMSCorrelationId; 69 70 public class CorrelationServiceTest extends TestCase { 71 72 public CorrelationServiceTest(String name) { 73 super(name); 74 } 75 76 public static void main(String [] args) { 77 junit.textui.TestRunner.run(suite()); 78 } 79 80 public static Test suite() { 81 return new TestSuite(CorrelationServiceTest.class); 82 } 83 84 public void setUp() { 85 } 86 87 public void testIt() { 88 89 System.out.println("Testing the WSIFCorrelationService..."); 90 91 WSIFCorrelationService cs = 92 WSIFCorrelationServiceLocator.getCorrelationService(); 93 94 WSIFCorrelationService cs2 = 95 WSIFCorrelationServiceLocator.getCorrelationService(); 96 assertTrue(cs == cs2); 97 98 try { 99 100 WSIFCorrelationId cid = new WSIFJMSCorrelationId("1"); 101 cs.put(cid, "petra", (long) 0); 102 103 cid = new WSIFJMSCorrelationId("2"); 104 cs.put(cid, "ant", (long) 0); 105 106 cid = new WSIFJMSCorrelationId("3"); 107 cs2.put(cid, "tanya", 3000); 108 109 cid = new WSIFJMSCorrelationId("1"); 110 String s = (String ) cs.get(cid); 111 assertTrue(s.equals("petra")); 112 113 cid = new WSIFJMSCorrelationId("2"); 114 s = (String ) cs.get(cid); 115 assertTrue(s.equals("ant")); 116 117 cid = new WSIFJMSCorrelationId("3"); 118 s = (String ) cs.get(cid); 119 assertTrue(s.equals("tanya")); 120 121 System.out.println("\nwaiting for timeouts..."); 122 try { 123 Thread.sleep(10000); 124 } catch (Exception ex) { 125 System.out.println("interupted early"); 126 } 127 128 cid = new WSIFJMSCorrelationId("1"); 129 s = (String ) cs.get(cid); 130 assertTrue(s.equals("petra")); 131 132 cid = new WSIFJMSCorrelationId("2"); 133 s = (String ) cs.get(cid); 134 assertTrue(s.equals("ant")); 135 136 cid = new WSIFJMSCorrelationId("3"); 137 s = (String ) cs.get(cid); 138 assertTrue(s == null); 140 cid = new WSIFJMSCorrelationId("2"); 141 cs.remove(cid); 142 143 cid = new WSIFJMSCorrelationId("1"); 144 s = (String ) cs.get(cid); 145 assertTrue(s.equals("petra")); 146 147 cid = new WSIFJMSCorrelationId("2"); 148 s = (String ) cs.get(cid); 149 assertTrue(s == null); 151 Class [] clss = 153 new Class [] { 154 int.class, 155 float.class, 156 long.class, 157 double.class, 158 short.class, 159 byte.class, 160 boolean.class, 161 void.class }; 162 Class [] clss2; 163 cid = new WSIFJMSCorrelationId("P1"); 164 cs.put(cid, clss, (long) 0); 165 clss2 = (Class []) cs.get(cid); 166 for (int i = 0; i < clss.length; i++) { 167 assertTrue( 168 "class " + clss[i] + " failed!!", 169 clss[i] == clss2[i]); 170 } 171 172 System.out.println("WSIFCorrealtionService tests complete."); 173 } catch (WSIFException ex) { 174 ex.printStackTrace(); 175 assertTrue(false); 176 } 177 178 } 179 180 } 181 | Popular Tags |