Pierre De Rop | 607609d | 2015-12-19 18:02:36 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 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 | */ |
| 19 | package org.apache.felix.dm.itest.api; |
| 20 | |
| 21 | import org.junit.Assert; |
| 22 | |
| 23 | import org.apache.felix.dm.Component; |
| 24 | import org.apache.felix.dm.DependencyManager; |
| 25 | import org.apache.felix.dm.itest.util.Ensure; |
| 26 | import org.apache.felix.dm.itest.util.TestBase; |
| 27 | import org.osgi.framework.Bundle; |
| 28 | |
| 29 | /** |
| 30 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
| 31 | */ |
| 32 | public class BundleAdapterWithCallbacksNotAutoConfiguredTest extends TestBase { |
| 33 | final Ensure m_e = new Ensure(); |
| 34 | |
| 35 | public void testBundleAdapterWithCallbacksNotAutoConfigured() { |
| 36 | DependencyManager m = getDM(); |
| 37 | // create a bundle adapter service (one is created for each bundle) |
| 38 | BundleAdapterWithCallback baWithCb = new BundleAdapterWithCallback(); |
| 39 | String bsn = "org.apache.felix.dependencymanager"; |
| 40 | String filter = "(Bundle-SymbolicName=" + bsn + ")"; |
| 41 | |
| 42 | Component adapter = m.createBundleAdapterService(Bundle.ACTIVE, filter, false, null, "add", null, null) |
| 43 | .setImplementation(baWithCb); |
| 44 | |
| 45 | // add the bundle adapter |
| 46 | m.add(adapter); |
| 47 | |
| 48 | // Check if adapter has not been auto configured (because it has callbacks defined). |
| 49 | m_e.waitForStep(1, 3000); |
| 50 | Assert.assertNull("bundle adapter must not be auto configured", baWithCb.getBundle()); |
| 51 | |
| 52 | // remove the bundle adapters |
| 53 | m.remove(adapter); |
| 54 | } |
| 55 | |
| 56 | class BundleAdapterWithCallback { |
| 57 | volatile Bundle m_bundle; // must not be auto configured because we are using callbacks. |
| 58 | |
| 59 | Bundle getBundle() { |
| 60 | return m_bundle; |
| 61 | } |
| 62 | |
| 63 | void add(Bundle b) { |
| 64 | Assert.assertNotNull(b); |
| 65 | Assert.assertEquals("org.apache.felix.dependencymanager", b.getSymbolicName()); |
| 66 | m_e.step(1); |
| 67 | } |
| 68 | } |
| 69 | } |