KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > components > cache > CacheTest


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.components.cache;
18
19 import javax.xml.namespace.QName JavaDoc;
20 import javax.xml.transform.Source JavaDoc;
21 import javax.xml.transform.dom.DOMSource JavaDoc;
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 JavaDoc;
27 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
28
29 /**
30  * @version $Revision: 426415 $
31  */

32 public class CacheTest extends TestSupport {
33     public void testCache() throws Exception JavaDoc {
34         EndpointResolver cachedService = client.createResolverForService(new QName JavaDoc("http://servicemix.org/cheese/", "myService"));
35         EndpointResolver service = client.createResolverForService(new QName JavaDoc("http://servicemix.org/cheese/", "myServiceImpl"));
36
37         Object JavaDoc object = client.request(cachedService, null, null, "<foo id='123'/>");
38         if (object instanceof Node JavaDoc) {
39             object = new DOMSource JavaDoc((Node JavaDoc) object);
40         }
41         String JavaDoc text = transformer.toString((Source JavaDoc) 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 JavaDoc) {
47             object = new DOMSource JavaDoc((Node JavaDoc) object);
48         }
49         String JavaDoc text2 = transformer.toString((Source JavaDoc) object);
50
51         System.out.println("Cache: Received response: " + text2);
52
53         assertEquals("Responses should be equal", text, text2);
54
55
56         // now lets try the underlying service to check we get different results each time
57
object = client.request(service, null, null, "<foo id='123'/>");
58         if (object instanceof Node JavaDoc) {
59             object = new DOMSource JavaDoc((Node JavaDoc) object);
60         }
61         text = transformer.toString((Source JavaDoc) 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 JavaDoc) {
67             object = new DOMSource JavaDoc((Node JavaDoc) object);
68         }
69         text2 = transformer.toString((Source JavaDoc) 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