// Path: component/src/main/java/org/apache/camel/osgi/service/util/BundleDelegatingClassLoader.java
// public class BundleDelegatingClassLoader extends ClassLoader {
//     private final Bundle bundle;
//     private final ClassLoader classLoader;
// 
//     public BundleDelegatingClassLoader(Bundle bundle) {
//         this(bundle, null);
//     }
// 
//     public BundleDelegatingClassLoader(Bundle bundle, ClassLoader classLoader) {
//         if (bundle == null) {
//             throw new IllegalArgumentException("bundle: null");
//         }
//         this.bundle = bundle;
//         this.classLoader = classLoader;
//     }
// 
//     protected Class<?> findClass(String name) throws ClassNotFoundException {
//         return bundle.loadClass(name);
//     }
// 
//     protected URL findResource(String name) {
//         URL resource = bundle.getResource(name);
//         if (classLoader != null && resource == null) {
//             resource = classLoader.getResource(name);
//         }
//         return resource;
//     }
// 
//     @SuppressWarnings("unchecked")
//     protected Enumeration findResources(String name) throws IOException {
//         Enumeration resources = bundle.getResources(name);
//         if (classLoader != null && (resources == null || !resources.hasMoreElements())) {
//             resources = classLoader.getResources(name);
//         }
//         return resources;
//     }
// 
//     protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
//         Class<?> clazz;
//         try {
//             clazz = findClass(name);
//         } catch (ClassNotFoundException cnfe) {
//             if (classLoader != null) {
//                 try {
//                     clazz = classLoader.loadClass(name);
//                 } catch (ClassNotFoundException e) {
//                     throw new ClassNotFoundException(String.format("[%s] from bundle [%s] (%s)",
//                         name, bundle.getBundleId(), bundle.getSymbolicName()));
//                 }
//             } else {
//                 throw new ClassNotFoundException(String.format("[%s] from bundle [%s] (%s)",
//                     name, bundle.getBundleId(), bundle.getSymbolicName()));
//             }
//         }
//         if (resolve) {
//             resolveClass(clazz);
//         }
//         return clazz;
//     }
// 
//     public Bundle getBundle() {
//         return bundle;
//     }
// 
//     @Override
//     public String toString() {
//         return String.format("BundleDelegatingClassLoader(%s)", bundle);
//     }
// }


import org.apache.camel.CamelContext;
import org.apache.camel.Component;
import org.apache.camel.Processor;
import org.apache.camel.osgi.service.util.BundleDelegatingClassLoader;
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleReference;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.withSettings;
/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.camel.osgi.service;




public class OsgiDefaultEndpointTest {

    @Test
    public void testCreateClassLoaderHasGetBundle() throws Exception {
        Bundle bundle = mock(Bundle.class);
        ClassLoader classLoader = new BundleDelegatingClassLoader(bundle, getClass().getClassLoader());

        CamelContext camelContext = mock(CamelContext.class);
        when(camelContext.getApplicationContextClassLoader()).thenReturn(classLoader);

        Component component = mock(Component.class);
        when(component.getCamelContext()).thenReturn(camelContext);

        new OsgiDefaultEndpoint("osgi:test", component);
    }

    @Test(expected = IllegalArgumentException.class)
    public void testCreateClassLoaderNoGetBundle() throws Exception {
// Path: component/src/main/java/org/apache/camel/osgi/service/util/BundleDelegatingClassLoader.java
// public class BundleDelegatingClassLoader extends ClassLoader {
//     private final Bundle bundle;
//     private final ClassLoader classLoader;
// 
//     public BundleDelegatingClassLoader(Bundle bundle) {
//         this(bundle, null);
//     }
// 
//     public BundleDelegatingClassLoader(Bundle bundle, ClassLoader classLoader) {
//         if (bundle == null) {
//             throw new IllegalArgumentException("bundle: null");
//         }
//         this.bundle = bundle;
//         this.classLoader = classLoader;
//     }
// 
//     protected Class<?> findClass(String name) throws ClassNotFoundException {
//         return bundle.loadClass(name);
//     }
// 
//     protected URL findResource(String name) {
//         URL resource = bundle.getResource(name);
//         if (classLoader != null && resource == null) {
//             resource = classLoader.getResource(name);
//         }
//         return resource;
//     }
// 
//     @SuppressWarnings("unchecked")
//     protected Enumeration findResources(String name) throws IOException {
//         Enumeration resources = bundle.getResources(name);
//         if (classLoader != null && (resources == null || !resources.hasMoreElements())) {
//             resources = classLoader.getResources(name);
//         }
//         return resources;
//     }
// 
//     protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
//         Class<?> clazz;
//         try {
//             clazz = findClass(name);
//         } catch (ClassNotFoundException cnfe) {
//             if (classLoader != null) {
//                 try {
//                     clazz = classLoader.loadClass(name);
//                 } catch (ClassNotFoundException e) {
//                     throw new ClassNotFoundException(String.format("[%s] from bundle [%s] (%s)",
//                         name, bundle.getBundleId(), bundle.getSymbolicName()));
//                 }
//             } else {
//                 throw new ClassNotFoundException(String.format("[%s] from bundle [%s] (%s)",
//                     name, bundle.getBundleId(), bundle.getSymbolicName()));
//             }
//         }
//         if (resolve) {
//             resolveClass(clazz);
//         }
//         return clazz;
//     }
// 
//     public Bundle getBundle() {
//         return bundle;
//     }
// 
//     @Override
//     public String toString() {
//         return String.format("BundleDelegatingClassLoader(%s)", bundle);
//     }
// }


// Path: component/src/test/java/org/apache/camel/osgi/service/OsgiDefaultEndpointTest.java
import org.apache.camel.CamelContext;
import org.apache.camel.Component;
import org.apache.camel.Processor;
import org.apache.camel.osgi.service.util.BundleDelegatingClassLoader;
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleReference;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.withSettings;

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.camel.osgi.service;




public class OsgiDefaultEndpointTest {

    @Test
    public void testCreateClassLoaderHasGetBundle() throws Exception {
        Bundle bundle = mock(Bundle.class);
        ClassLoader classLoader = new BundleDelegatingClassLoader(bundle, getClass().getClassLoader());

        CamelContext camelContext = mock(CamelContext.class);
        when(camelContext.getApplicationContextClassLoader()).thenReturn(classLoader);

        Component component = mock(Component.class);
        when(component.getCamelContext()).thenReturn(camelContext);

        new OsgiDefaultEndpoint("osgi:test", component);
    }

    @Test(expected = IllegalArgumentException.class)
    public void testCreateClassLoaderNoGetBundle() throws Exception {
        CamelContext camelContext = mock(CamelContext.class);