001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.bus.extension;
019:
020: import org.junit.Assert;
021: import org.junit.Test;
022:
023: public class ExtensionTest extends Assert {
024:
025: @Test
026: public void testMutators() {
027: Extension e = new Extension();
028:
029: String className = "org.apache.cxf.bindings.soap.SoapBinding";
030: e.setClassname(className);
031: assertEquals("Unexpected class name.", className, e
032: .getClassname());
033: assertNull("Unexpected interface name.", e.getInterfaceName());
034:
035: String interfaceName = "org.apache.cxf.bindings.Binding";
036: e.setInterfaceName(interfaceName);
037: assertEquals("Unexpected interface name.", interfaceName, e
038: .getInterfaceName());
039:
040: assertTrue("Extension is deferred.", !e.isDeferred());
041: e.setDeferred(true);
042: assertTrue("Extension is not deferred.", e.isDeferred());
043:
044: assertEquals("Unexpected size of namespace list.", 0, e
045: .getNamespaces().size());
046: }
047:
048: @Test
049: public void testLoad() throws ExtensionException {
050: Extension e = new Extension();
051: ClassLoader cl = Thread.currentThread().getContextClassLoader();
052: e.setClassname("no.such.Extension");
053: try {
054: e.load(cl);
055: } catch (ExtensionException ex) {
056: assertTrue(
057: "ExtensionException does not wrap ClassNotFoundException",
058: ex.getCause() instanceof ClassNotFoundException);
059: }
060:
061: e.setClassname("java.lang.System");
062: try {
063: e.load(cl);
064: } catch (ExtensionException ex) {
065: assertTrue(
066: "ExtensionException does not wrap IllegalAccessException",
067: ex.getCause() instanceof IllegalAccessException);
068: }
069: e.setClassname(MyServiceConstructorThrowsException.class
070: .getName());
071: try {
072: e.load(cl);
073: } catch (ExtensionException ex) {
074: assertTrue(
075: "ExtensionException does not wrap InstantiationException",
076: ex.getCause() instanceof InstantiationException);
077: }
078: e.setClassname("java.lang.String");
079: Object obj = e.load(cl);
080: assertTrue("Object is not type String", obj instanceof String);
081: }
082:
083: @Test
084: public void testLoadInterface() {
085: Extension e = new Extension();
086: ClassLoader cl = Thread.currentThread().getContextClassLoader();
087: e.setInterfaceName("no.such.Extension");
088: try {
089: e.loadInterface(cl);
090: } catch (ExtensionException ex) {
091: assertTrue(
092: "ExtensionException does not wrap ClassNotFoundException",
093: ex.getCause() instanceof ClassNotFoundException);
094: }
095:
096: e.setInterfaceName(Assert.class.getName());
097: Class<?> cls = e.loadInterface(cl);
098: assertTrue("Object is not type Class", cls instanceof Class);
099: }
100:
101: class MyServiceConstructorThrowsException {
102: public MyServiceConstructorThrowsException() {
103: throw new IllegalArgumentException();
104: }
105: }
106:
107: }
|