blob: b4ab1438f5846d32c5c20de1fdefc51936165f52 [file] [log] [blame]
Pierre De Ropc40d93f2015-05-04 20:25:57 +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
21import org.apache.felix.dm.Component;
22import org.apache.felix.dm.DependencyManager;
23import org.apache.felix.dm.itest.util.Ensure;
24import org.apache.felix.dm.itest.util.TestBase;
25import org.junit.Assert;
26
27/**
28 * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
29 */
30public class FELIX4614_FactoryWithComponentInCreateParam extends TestBase {
31 private final static Ensure m_ensure = new Ensure();
32
33 public void testSimpleFactory() {
34 DependencyManager manager = getDM();
35
36 Component service = manager.createComponent()
37 .setFactory(Factory.class, "create")
38 .setInterface(Service.class.getName(), null);
39
40 Component client = manager.createComponent()
41 .setImplementation(Client.class)
42 .add(manager.createServiceDependency().setService(Service.class).setRequired(true));
43
44 manager.add(client);
45 manager.add(service);
46 m_ensure.waitForStep(3, 5000);
47 manager.clear();
48 }
49
50 public static class Factory {
51 public Object create(Component c) {
52 m_ensure.step(1);
53 Assert.assertNotNull(c);
54 m_ensure.step(2);
55 return new ServiceImpl();
56 }
57 }
58
59 public static interface Service {
60 }
61
62 public static class ServiceImpl implements Service {
63 }
64
65 public static class Client {
66 volatile Service m_service;
67
68 void start() {
69 Assert.assertNotNull(m_service);
70 m_ensure.step(3);
71 }
72 }
73}
74