blob: f5b3f41da31e3c2d194e1e904c0e04ff0ae19d45 [file] [log] [blame]
Pierre De Rop3a00a212015-03-01 09:27:46 +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.itest.api;
20//import static org.ops4j.pax.exam.CoreOptions.waitForFrameworkStartupFor;
21//import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption;
22
23import org.junit.Assert;
24
25import org.apache.felix.dm.Component;
26import org.apache.felix.dm.DependencyManager;
27import org.apache.felix.dm.itest.util.Ensure;
28import org.apache.felix.dm.itest.util.TestBase;
29import org.osgi.framework.Bundle;
30
31/**
32 * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
33 */
34public 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}