Author: ggrzybek
Date: Mon Aug 21 11:46:56 2017
New Revision: 1805621
URL: http://svn.apache.org/viewvc?rev=1805621&view=rev
Log:
[ARIES-1732] Adding tests related to cm:property-placeholder and CM interaction
Added:
aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/CmPropertiesTest.java
aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/CmPropertyPlaceholderTest.java
aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/CmPropertyPlaceholderTest.xml
- copied, changed from r1805057,
aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/CmPropertiesTest.xml
Modified:
aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/service/Foo.java
aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/service/FooInterface.java
aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/CmPropertiesTest.xml
Added:
aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/CmPropertiesTest.java
URL:
http://svn.apache.org/viewvc/aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/CmPropertiesTest.java?rev=1805621&view=auto
==============================================================================
---
aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/CmPropertiesTest.java
(added)
+++
aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/CmPropertiesTest.java
Mon Aug 21 11:46:56 2017
@@ -0,0 +1,127 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint.itests.cm;
+
+import java.io.InputStream;
+import java.util.Hashtable;
+import javax.inject.Inject;
+
+import org.apache.aries.blueprint.itests.AbstractBlueprintIntegrationTest;
+import org.apache.aries.blueprint.itests.Helper;
+import org.apache.aries.blueprint.itests.cm.service.Foo;
+import org.apache.aries.blueprint.itests.cm.service.FooFactory;
+import org.apache.aries.blueprint.itests.cm.service.FooInterface;
+import org.junit.Test;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.ProbeBuilder;
+import org.ops4j.pax.exam.TestProbeBuilder;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+import static org.junit.Assert.*;
+import static org.ops4j.pax.exam.CoreOptions.keepCaches;
+import static org.ops4j.pax.exam.CoreOptions.streamBundle;
+
+public class CmPropertiesTest extends AbstractBlueprintIntegrationTest {
+ private static final String TEST_BUNDLE =
"org.apache.aries.blueprint.cm.test.b1";
+
+ @Inject
+ ConfigurationAdmin ca;
+
+ @ProbeBuilder
+ public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
+ probe.setHeader(Constants.EXPORT_PACKAGE,
Foo.class.getPackage().getName());
+ probe.setHeader(Constants.IMPORT_PACKAGE,
Foo.class.getPackage().getName());
+ return probe;
+ }
+
+ @org.ops4j.pax.exam.Configuration
+ public Option[] config() {
+ return new Option[] {
+ baseOptions(),
+ Helper.blueprintBundles(),
+ keepCaches(),
+ streamBundle(testBundle())
+ };
+ }
+
+ protected InputStream testBundle() {
+ return TinyBundles.bundle() //
+ .add(FooInterface.class) //
+ .add(Foo.class) //
+ .add(FooFactory.class) //
+ .add("OSGI-INF/blueprint/context.xml",
getResource("CmPropertiesTest.xml"))
+ .set(Constants.BUNDLE_SYMBOLICNAME, TEST_BUNDLE) //
+ .set(Constants.EXPORT_PACKAGE, Foo.class.getPackage().getName()) //
+ .set(Constants.IMPORT_PACKAGE, Foo.class.getPackage().getName()) //
+ .build(TinyBundles.withBnd());
+ }
+
+ @Test
+ public void testProperties() throws Exception {
+ ServiceReference sr = getServiceRef(FooInterface.class, "(key=foo4)");
+ assertNotNull(sr);
+ FooInterface foo = (FooInterface)context().getService(sr);
+ assertNotNull(foo);
+ assertNotNull(foo.getProps());
+ assertTrue(foo.getProps().isEmpty());
+
+ Configuration cf =
ca.getConfiguration("blueprint-sample-properties.pid", null);
+ Hashtable<String,String> props = new Hashtable<String,String>();
+ props.put("a", "5");
+ cf.update(props);
+ Thread.sleep(500);
+ assertFalse(foo.getProps().isEmpty());
+ assertEquals("5", foo.getProps().getProperty("a"));
+
+ props.put("a", "6");
+ cf.update(props);
+ Thread.sleep(500);
+ assertFalse(foo.getProps().isEmpty());
+ assertEquals("6", foo.getProps().getProperty("a"));
+
+ cf.delete();
+ Thread.sleep(500);
+ assertNull(foo.getProps().getProperty("a"));
+ }
+
+ @SuppressWarnings("rawtypes")
+ private ServiceReference getServiceRef(Class serviceInterface, String
filter)
+ throws InvalidSyntaxException {
+ int tries = 0;
+ do {
+ ServiceReference[] srAr =
bundleContext.getServiceReferences(serviceInterface.getName(), filter);
+ if (srAr != null && srAr.length > 0) {
+ return srAr[0];
+ }
+ tries++;
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ // Ignore
+ }
+ } while (tries < 100);
+ throw new RuntimeException("Could not find service " +
serviceInterface.getName() + ", " + filter);
+ }
+
+}
Added:
aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/CmPropertyPlaceholderTest.java
URL:
http://svn.apache.org/viewvc/aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/CmPropertyPlaceholderTest.java?rev=1805621&view=auto
==============================================================================
---
aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/CmPropertyPlaceholderTest.java
(added)
+++
aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/CmPropertyPlaceholderTest.java
Mon Aug 21 11:46:56 2017
@@ -0,0 +1,124 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint.itests.cm;
+
+import java.io.InputStream;
+import java.util.Hashtable;
+import javax.inject.Inject;
+
+import org.apache.aries.blueprint.itests.AbstractBlueprintIntegrationTest;
+import org.apache.aries.blueprint.itests.Helper;
+import org.apache.aries.blueprint.itests.cm.service.Foo;
+import org.apache.aries.blueprint.itests.cm.service.FooFactory;
+import org.apache.aries.blueprint.itests.cm.service.FooInterface;
+import org.junit.Test;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.ProbeBuilder;
+import org.ops4j.pax.exam.TestProbeBuilder;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.*;
+import static org.ops4j.pax.exam.CoreOptions.keepCaches;
+import static org.ops4j.pax.exam.CoreOptions.streamBundle;
+
+public class CmPropertyPlaceholderTest extends
AbstractBlueprintIntegrationTest {
+ private static final String TEST_BUNDLE =
"org.apache.aries.blueprint.cm.test.b1";
+
+ @Inject
+ ConfigurationAdmin ca;
+
+ @ProbeBuilder
+ public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
+ probe.setHeader(Constants.EXPORT_PACKAGE,
Foo.class.getPackage().getName());
+ probe.setHeader(Constants.IMPORT_PACKAGE,
Foo.class.getPackage().getName());
+ return probe;
+ }
+
+ @org.ops4j.pax.exam.Configuration
+ public Option[] config() {
+ return new Option[] {
+ baseOptions(),
+ Helper.blueprintBundles(),
+ keepCaches(),
+ streamBundle(testBundle())
+ };
+ }
+
+ protected InputStream testBundle() {
+ return TinyBundles.bundle() //
+ .add(FooInterface.class) //
+ .add(Foo.class) //
+ .add(FooFactory.class) //
+ .add("OSGI-INF/blueprint/context.xml",
getResource("CmPropertyPlaceholderTest.xml"))
+ .set(Constants.BUNDLE_SYMBOLICNAME, TEST_BUNDLE) //
+ .set(Constants.EXPORT_PACKAGE, Foo.class.getPackage().getName()) //
+ .set(Constants.IMPORT_PACKAGE, Foo.class.getPackage().getName()) //
+ .build(TinyBundles.withBnd());
+ }
+
+ @Test
+ public void testProperties() throws Exception {
+ ServiceReference sr = getServiceRef(FooInterface.class, "(key=foo5)");
+ assertNotNull(sr);
+ FooInterface foo = (FooInterface)context().getService(sr);
+ assertNotNull(foo);
+ assertThat(foo.getB(), equalTo("42"));
+
+ Configuration cf =
ca.getConfiguration("blueprint-sample-properties.pid", null);
+ Hashtable<String,String> props = new Hashtable<String,String>();
+ props.put("pb", "43");
+ cf.update(props);
+ Thread.sleep(500);
+ sr = getServiceRef(FooInterface.class, "(key=foo5)");
+ foo = (FooInterface)context().getService(sr);
+ assertEquals("43", foo.getB());
+
+ cf.delete();
+ Thread.sleep(500);
+ sr = getServiceRef(FooInterface.class, "(key=foo5)");
+ foo = (FooInterface)context().getService(sr);
+ assertEquals(foo.getB(), "42");
+ }
+
+ @SuppressWarnings("rawtypes")
+ private ServiceReference getServiceRef(Class serviceInterface, String
filter)
+ throws InvalidSyntaxException {
+ int tries = 0;
+ do {
+ ServiceReference[] srAr =
bundleContext.getServiceReferences(serviceInterface.getName(), filter);
+ if (srAr != null && srAr.length > 0) {
+ return srAr[0];
+ }
+ tries++;
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ // Ignore
+ }
+ } while (tries < 100);
+ throw new RuntimeException("Could not find service " +
serviceInterface.getName() + ", " + filter);
+ }
+
+}
Modified:
aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/service/Foo.java
URL:
http://svn.apache.org/viewvc/aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/service/Foo.java?rev=1805621&r1=1805620&r2=1805621&view=diff
==============================================================================
---
aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/service/Foo.java
(original)
+++
aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/service/Foo.java
Mon Aug 21 11:46:56 2017
@@ -38,6 +38,7 @@ public class Foo implements FooInterface
a = i;
}
+ @Override
public String getB() {
return b;
}
Modified:
aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/service/FooInterface.java
URL:
http://svn.apache.org/viewvc/aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/service/FooInterface.java?rev=1805621&r1=1805620&r2=1805621&view=diff
==============================================================================
---
aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/service/FooInterface.java
(original)
+++
aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/service/FooInterface.java
Mon Aug 21 11:46:56 2017
@@ -22,6 +22,8 @@ import java.util.Properties;
public interface FooInterface {
+ String getB();
+
Properties getProps();
}
Modified:
aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/CmPropertiesTest.xml
URL:
http://svn.apache.org/viewvc/aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/CmPropertiesTest.xml?rev=1805621&r1=1805620&r2=1805621&view=diff
==============================================================================
---
aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/CmPropertiesTest.xml
(original)
+++
aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/CmPropertiesTest.xml
Mon Aug 21 11:46:56 2017
@@ -15,20 +15,17 @@
License.
-->
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
-
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.2.0"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.2.0">
<cm:cm-properties id="myProps"
persistent-id="blueprint-sample-properties.pid" />
- <service id="myService" auto-export="interfaces">
+ <bean id="foo" class="org.apache.aries.blueprint.itests.cm.service.Foo">
+ <property name="props" ref="myProps" />
+ </bean>
+ <service id="myService"
interface="org.apache.aries.blueprint.itests.cm.service.FooInterface" ref="foo">
<service-properties>
<entry key="key" value="foo4" />
- <!--<cm:cm-properties persistent-id="org.foo.bar" />-->
</service-properties>
- <bean class="org.apache.aries.blueprint.compendium.cm.Foo">
- <property name="props" ref="myProps" />
- </bean>
</service>
-
</blueprint>
Copied:
aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/CmPropertyPlaceholderTest.xml
(from r1805057,
aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/CmPropertiesTest.xml)
URL:
http://svn.apache.org/viewvc/aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/CmPropertyPlaceholderTest.xml?p2=aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/CmPropertyPlaceholderTest.xml&p1=aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/CmPropertiesTest.xml&r1=1805057&r2=1805621&rev=1805621&view=diff
==============================================================================
---
aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/CmPropertiesTest.xml
(original)
+++
aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/CmPropertyPlaceholderTest.xml
Mon Aug 21 11:46:56 2017
@@ -15,20 +15,21 @@
License.
-->
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
-
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.2.0"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.2.0">
- <cm:cm-properties id="myProps"
persistent-id="blueprint-sample-properties.pid" />
+ <cm:property-placeholder id="myProps"
persistent-id="blueprint-sample-properties.pid" update-strategy="reload">
+ <cm:default-properties>
+ <cm:property name="pb" value="42" />
+ </cm:default-properties>
+ </cm:property-placeholder>
- <service id="myService" auto-export="interfaces">
+ <bean id="foo" class="org.apache.aries.blueprint.itests.cm.service.Foo">
+ <property name="b" value="${pb}" />
+ </bean>
+ <service id="myService"
interface="org.apache.aries.blueprint.itests.cm.service.FooInterface" ref="foo">
<service-properties>
- <entry key="key" value="foo4" />
- <!--<cm:cm-properties persistent-id="org.foo.bar" />-->
+ <entry key="key" value="foo5" />
</service-properties>
- <bean class="org.apache.aries.blueprint.compendium.cm.Foo">
- <property name="props" ref="myProps" />
- </bean>
</service>
-
</blueprint>