1 17 package org.apache.servicemix.components.cache; 18 19 import javax.xml.namespace.QName ; 20 import javax.xml.transform.Source ; 21 import javax.xml.transform.dom.DOMSource ; 22 23 import org.apache.servicemix.jbi.resolver.EndpointResolver; 24 import org.apache.servicemix.tck.TestSupport; 25 import org.springframework.context.support.AbstractXmlApplicationContext; 26 import org.w3c.dom.Node ; 27 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext; 28 29 32 public class CacheTest extends TestSupport { 33 public void testCache() throws Exception { 34 EndpointResolver cachedService = client.createResolverForService(new QName ("http://servicemix.org/cheese/", "myService")); 35 EndpointResolver service = client.createResolverForService(new QName ("http://servicemix.org/cheese/", "myServiceImpl")); 36 37 Object object = client.request(cachedService, null, null, "<foo id='123'/>"); 38 if (object instanceof Node ) { 39 object = new DOMSource ((Node ) object); 40 } 41 String text = transformer.toString((Source ) object); 42 43 System.out.println("Cache: Received response: " + text); 44 45 object = client.request(cachedService, null, null, "<foo id='123'/>"); 46 if (object instanceof Node ) { 47 object = new DOMSource ((Node ) object); 48 } 49 String text2 = transformer.toString((Source ) object); 50 51 System.out.println("Cache: Received response: " + text2); 52 53 assertEquals("Responses should be equal", text, text2); 54 55 56 object = client.request(service, null, null, "<foo id='123'/>"); 58 if (object instanceof Node ) { 59 object = new DOMSource ((Node ) object); 60 } 61 text = transformer.toString((Source ) object); 62 63 System.out.println("ServiceImpl: Received response: " + text); 64 65 object = client.request(service, null, null, "<foo id='123'/>"); 66 if (object instanceof Node ) { 67 object = new DOMSource ((Node ) object); 68 } 69 text2 = transformer.toString((Source ) object); 70 71 System.out.println("ServiceImpl: Received response: " + text2); 72 73 assertTrue("Responses should be different but were both: " + text, !text.equals(text2)); 74 75 } 76 77 protected AbstractXmlApplicationContext createBeanFactory() { 78 return new ClassPathXmlApplicationContext("org/apache/servicemix/components/cache/example.xml"); 79 } 80 } 81 | Popular Tags |