01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.configuration.spring;
19:
20: import java.util.Collection;
21: import java.util.Map;
22: import java.util.Map.Entry;
23: import java.util.Set;
24:
25: import javax.xml.namespace.QName;
26:
27: import org.apache.cxf.helpers.CastUtils;
28: import org.junit.Assert;
29: import org.junit.Test;
30: import org.springframework.context.support.ClassPathXmlApplicationContext;
31:
32: public class SpringBeanQNameMapTest extends Assert {
33:
34: @Test
35: public void testPersons() {
36: ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
37: "org/apache/cxf/configuration/spring/beanQNameMap.xml");
38:
39: Map<QName, Person> beans = CastUtils.cast((Map) context
40: .getBean("committers"));
41: assertNotNull(beans);
42:
43: assertEquals(2, PersonQNameImpl.getLoadCount());
44: assertEquals(4, beans.keySet().size());
45:
46: QName qn1 = new QName("http://cxf.apache.org", "anonymous");
47: Person p1 = beans.get(qn1);
48: assertNotNull(p1);
49: assertEquals(2, PersonQNameImpl.getLoadCount());
50:
51: QName qn2 = new QName("http://cxf.apache.org", "myself");
52: Person p2 = beans.get(qn2);
53: assertNotNull(p2);
54: assertEquals(3, PersonQNameImpl.getLoadCount());
55:
56: QName qn3 = new QName("http://cxf.apache.org", "other");
57: Person p3 = beans.get(qn3);
58: assertNotNull(p3);
59: assertEquals(3, PersonQNameImpl.getLoadCount());
60:
61: QName qn4 = new QName("http://x.y.z", "other");
62: Person p = beans.get(qn4);
63: assertNotNull(p);
64: assertSame(p3, p);
65: assertEquals(3, PersonQNameImpl.getLoadCount());
66:
67: Collection<Person> values = beans.values();
68: assertEquals(4, values.size());
69:
70: Set<Entry<QName, Person>> entries = beans.entrySet();
71: assertEquals(4, entries.size());
72:
73: QName qn5 = new QName("http://a.b.c", "foo");
74: Person p4 = new PersonQNameImpl();
75: beans.put(qn5, p4);
76:
77: p = beans.get(qn5);
78: assertEquals(p1, beans.get(qn1));
79: }
80:
81: }
|