blob: 897728efde183a9d0c26828f786b0ba7a5af8627 [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.runtime.itest.components;
20
21import java.util.HashMap;
22import java.util.Map;
23
24import org.apache.felix.dm.annotation.api.AdapterService;
25import org.apache.felix.dm.annotation.api.Component;
26import org.apache.felix.dm.annotation.api.Property;
27import org.apache.felix.dm.annotation.api.ServiceDependency;
28import org.apache.felix.dm.annotation.api.Start;
29import org.apache.felix.dm.itest.util.Ensure;
30
31/**
32 * This test validates that an adapter Service may specify some extra service properties
33 * from it's start callback.
34 *
35 * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
36 */
37@SuppressWarnings({"rawtypes", "serial"})
38public class ExtraAdapterServiceProperties {
39 public final static String ENSURE = "ExtraAdapterServiceProperties";
40
41 public interface Provider {
42 }
43
44 public interface Provider2 {
45 }
46
47 @Component(properties = {@Property(name = "foo", value = "bar")})
48 public static class ProviderImpl implements Provider {
49 }
50
51 @AdapterService(provides = Provider2.class, properties = {@Property(name = "foo2", value = "bar2")}, adapteeService = Provider.class)
52 public static class Provider2Impl implements Provider2 {
53 protected Provider m_adaptee;
54
55 @Start
56 Map<String, String> start() {
57 return new HashMap<String, String>() {
58 {
59 put("foo3", "bar3");
60 }
61 };
62 }
63 }
64
65 @Component
66 public static class Consumer {
67 @ServiceDependency(filter = "(name=" + ENSURE + ")")
68 volatile Ensure m_sequencer;
69
70 private volatile Map m_properties;
71
72 @ServiceDependency
73 void bind(Map properties, Provider2 provider2) {
74 m_properties = properties;
75 }
76
77 @Start
78 void start() {
79 System.out.println("provider2 service properties: " + m_properties);
80 if ("bar".equals(m_properties.get("foo"))) {
81 m_sequencer.step(1);
82 }
83
84 if ("bar2".equals(m_properties.get("foo2"))) {
85 m_sequencer.step(2);
86 }
87
88 if ("bar3".equals(m_properties.get("foo3"))) {
89 m_sequencer.step(3);
90 }
91 }
92 }
93}