Pierre De Rop | 3a00a21 | 2015-03-01 09:27:46 +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 | //import static org.ops4j.pax.exam.CoreOptions.waitForFrameworkStartupFor; |
| 21 | //import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption; |
| 22 | |
| 23 | import org.junit.Assert; |
| 24 | |
| 25 | import org.apache.felix.dm.Component; |
| 26 | import org.apache.felix.dm.DependencyManager; |
| 27 | import org.apache.felix.dm.itest.util.Ensure; |
| 28 | import org.apache.felix.dm.itest.util.TestBase; |
| 29 | import org.osgi.framework.Bundle; |
| 30 | |
| 31 | /** |
| 32 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
| 33 | */ |
| 34 | public class FELIX3008_FilterIndexStartupTest extends TestBase { |
| 35 | public void testNormalStart() throws Exception { |
| 36 | System.setProperty("org.apache.felix.dependencymanager.filterindex", "objectClass"); |
| 37 | DependencyManager m = getDM(); |
| 38 | // helper class that ensures certain steps get executed in sequence |
| 39 | Ensure e = new Ensure(); |
| 40 | // create a provider |
| 41 | Provider provider = new Provider(); |
| 42 | // activate it |
| 43 | Component p = m.createComponent() |
| 44 | .setInterface(Service.class.getName(), null) |
| 45 | .setImplementation(provider); |
| 46 | |
| 47 | Consumer consumer = new Consumer(e); |
| 48 | Component c = m.createComponent() |
| 49 | .setImplementation(consumer) |
| 50 | .add(m.createServiceDependency() |
| 51 | .setService(Service.class) |
| 52 | .setRequired(true) |
| 53 | ); |
| 54 | |
| 55 | m.add(p); |
| 56 | m.add(c); |
| 57 | e.waitForStep(1, 5000); |
| 58 | m.remove(p); |
| 59 | e.waitForStep(2, 5000); |
| 60 | m.remove(c); |
| 61 | |
| 62 | Assert.assertEquals("Dependency manager bundle should be active.", Bundle.ACTIVE, context.getBundle().getState()); |
| 63 | } |
| 64 | |
| 65 | public static class Consumer { |
| 66 | volatile Service m_service; |
| 67 | private final Ensure m_ensure; |
| 68 | |
| 69 | public Consumer(Ensure e) { |
| 70 | m_ensure = e; |
| 71 | } |
| 72 | |
| 73 | public void start() { |
| 74 | System.out.println("start"); |
| 75 | m_ensure.step(1); |
| 76 | } |
| 77 | |
| 78 | public void stop() { |
| 79 | System.out.println("stop"); |
| 80 | m_ensure.step(2); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | public static interface Service { |
| 85 | } |
| 86 | |
| 87 | public static class Provider implements Service { |
| 88 | } |
| 89 | } |