001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 2002 The Apache Software Foundation. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "WSIF" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 2001, 2002, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057:
058: package async;
059:
060: import junit.framework.Test;
061: import junit.framework.TestCase;
062: import junit.framework.TestSuite;
063: import junit.textui.TestRunner;
064: import org.apache.wsif.WSIFCorrelationId;
065: import org.apache.wsif.WSIFCorrelationService;
066: import org.apache.wsif.WSIFException;
067: import org.apache.wsif.util.WSIFCorrelationServiceLocator;
068: import org.apache.wsif.util.jms.WSIFJMSCorrelationId;
069:
070: public class CorrelationServiceTest extends TestCase {
071:
072: public CorrelationServiceTest(String name) {
073: super (name);
074: }
075:
076: public static void main(String[] args) {
077: junit.textui.TestRunner.run(suite());
078: }
079:
080: public static Test suite() {
081: return new TestSuite(CorrelationServiceTest.class);
082: }
083:
084: public void setUp() {
085: }
086:
087: public void testIt() {
088:
089: System.out.println("Testing the WSIFCorrelationService...");
090:
091: WSIFCorrelationService cs = WSIFCorrelationServiceLocator
092: .getCorrelationService();
093:
094: WSIFCorrelationService cs2 = WSIFCorrelationServiceLocator
095: .getCorrelationService();
096: assertTrue(cs == cs2);
097:
098: try {
099:
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); // should have timed out
139:
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); // due to remove
150:
151: // test primative clasess
152: Class[] clss = new Class[] { int.class, float.class,
153: long.class, double.class, short.class, byte.class,
154: boolean.class, void.class };
155: Class[] clss2;
156: cid = new WSIFJMSCorrelationId("P1");
157: cs.put(cid, clss, (long) 0);
158: clss2 = (Class[]) cs.get(cid);
159: for (int i = 0; i < clss.length; i++) {
160: assertTrue("class " + clss[i] + " failed!!",
161: clss[i] == clss2[i]);
162: }
163:
164: System.out
165: .println("WSIFCorrealtionService tests complete.");
166: } catch (WSIFException ex) {
167: ex.printStackTrace();
168: assertTrue(false);
169: }
170:
171: }
172:
173: }
|