blob: 2a55f03e324817a6826715f77f10d51316674fc7 [file] [log] [blame]
Pierre De Ropfaca2892016-01-31 23:27:05 +00001/*
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 */
19package org.apache.felix.dm.lambda.itest;
20
21import static org.apache.felix.dm.lambda.DependencyManagerActivator.bundleAdapter;
22
23import org.apache.felix.dm.Component;
24import org.apache.felix.dm.DependencyManager;
25import org.junit.Assert;
26import org.osgi.framework.Bundle;
27
28/**
29 * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
30 */
31public class BundleAdapterWithCallbacksNotAutoConfiguredTest extends TestBase {
32 final Ensure m_e = new Ensure();
33
34 public void testBundleAdapterWithCallbacksNotAutoConfigured() {
35 DependencyManager m = getDM();
36 // create a bundle adapter service (one is created for each bundle)
37 BundleAdapterWithCallback baWithCb = new BundleAdapterWithCallback();
38 String bsn = "org.apache.felix.dependencymanager";
39 String filter = "(Bundle-SymbolicName=" + bsn + ")";
40
Pierre De Rop11527502016-02-18 21:07:16 +000041 Component adapter = bundleAdapter(m).mask(Bundle.ACTIVE).filter(filter).add("add").impl(baWithCb).build();
Pierre De Ropfaca2892016-01-31 23:27:05 +000042
43 // add the bundle adapter
44 m.add(adapter);
45
46 // Check if adapter has not been auto configured (because it has callbacks defined).
47 m_e.waitForStep(1, 3000);
48 Assert.assertNull("bundle adapter must not be auto configured", baWithCb.getBundle());
49
50 // remove the bundle adapters
51 m.remove(adapter);
52 }
53
54 class BundleAdapterWithCallback {
55 volatile Bundle m_bundle; // must not be auto configured because we are using callbacks.
56
57 Bundle getBundle() {
58 return m_bundle;
59 }
60
61 void add(Bundle b) {
62 Assert.assertNotNull(b);
63 Assert.assertEquals("org.apache.felix.dependencymanager", b.getSymbolicName());
64 m_e.step(1);
65 }
66 }
67}