You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by zo...@apache.org on 2011/02/27 21:50:51 UTC
svn commit: r1075143 [21/23] - in /aries/tags/blueprint-0.2.1: ./
blueprint-annotation-api/ blueprint-annotation-api/src/
blueprint-annotation-api/src/main/ blueprint-annotation-api/src/main/java/
blueprint-annotation-api/src/main/java/org/ blueprint-a...
Added: aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/AbstractMultiBundleTest.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/AbstractMultiBundleTest.java?rev=1075143&view=auto
==============================================================================
--- aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/AbstractMultiBundleTest.java (added)
+++ aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/AbstractMultiBundleTest.java Sun Feb 27 20:50:38 2011
@@ -0,0 +1,189 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.aries.blueprint.BeanProcessor;
+import org.apache.aries.blueprint.testbundlea.NSHandlerOne;
+import org.apache.aries.blueprint.testbundlea.NSHandlerTwo;
+import org.apache.aries.blueprint.testbundlea.ProcessableBean;
+import org.apache.aries.blueprint.testbundlea.ProcessableBean.Phase;
+import org.apache.aries.blueprint.testbundleb.TestBean;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Bundle;
+import org.osgi.service.blueprint.container.BlueprintContainer;
+
+public class AbstractMultiBundleTest extends AbstractIntegrationTest{
+
+ private void checkInterceptorLog(String []expected, List<String> log){
+ assertNotNull("interceptor log should not be null",log);
+ System.out.println("Log:");
+ for(String entry: log){
+ System.out.println(""+entry);
+ }
+ assertEquals("interceptor log size does not match expected size",expected.length,log.size());
+
+ List<String> extra=new ArrayList<String>();
+ boolean[] found = new boolean[expected.length];
+ for(String s : log){
+ boolean used=false;
+ for(int i=0; i<expected.length; i++){
+ if(s.startsWith(expected[i])){
+ found[i]=true;
+ used=true;
+ }
+ }
+ if(!used){
+ extra.add(s);
+ }
+ }
+ if(extra.size()!=0){
+ String extraFormatted="{";
+ for(String e:extra){
+ extraFormatted+=e+" ";
+ }
+ extraFormatted+="}";
+ fail("surplus interceptor invocations present in invocation log "+extraFormatted);
+ }
+ for(int i=0; i<found.length; i++){
+ assertTrue("interceptor invocation "+expected[i]+" not found",found[i]);
+ }
+ }
+
+ protected void doCommonMultiBundleTest() throws Exception {
+
+ //bundlea provides the ns handlers, bean processors, interceptors etc for this test.
+ Bundle bundlea = getInstalledBundle("org.apache.aries.blueprint.testbundlea");
+ assertNotNull(bundlea);
+ bundlea.start();
+
+ //bundleb makes use of the extensions provided by bundlea
+ Bundle bundleb = getInstalledBundle("org.apache.aries.blueprint.testbundleb");
+ assertNotNull(bundleb);
+ bundleb.start();
+
+ //bundleb's container will hold the beans we need to query to check the function
+ //provided by bundlea functioned as expected
+ BlueprintContainer beanContainer =
+ getBlueprintContainerForBundle( bundleContext , "org.apache.aries.blueprint.testbundleb", 5000);
+ assertNotNull(beanContainer);
+
+ //TestBeanA should have the values below, no interference should be present from other sources.
+ Object obj1 = beanContainer.getComponentInstance("TestBeanA");
+ assertTrue(obj1 instanceof TestBean);
+ TestBean testBeanA = (TestBean)obj1;
+ org.junit.Assert.assertEquals("RED", testBeanA.getRed());
+ org.junit.Assert.assertEquals("GREEN", testBeanA.getGreen());
+ org.junit.Assert.assertEquals("BLUE", testBeanA.getBlue());
+
+ //TestBeanB tests that a custom ns handler is able to inject custom components to the blueprint,
+ //and modify existing components, and use injected components as modifications.
+ Object obj2 = beanContainer.getComponentInstance("TestBeanB");
+ assertTrue(obj2 instanceof TestBean);
+ TestBean testBeanB = (TestBean)obj2;
+ //value should be set in via the added passthroughmetadata via the nshandler.
+ org.junit.Assert.assertEquals("ONE_VALUE", testBeanB.getRed());
+ org.junit.Assert.assertEquals("GREEN", testBeanB.getGreen());
+ org.junit.Assert.assertEquals("BLUE", testBeanB.getBlue());
+
+ //TestBeanC tests that custom ns handlers can add interceptors to beans.
+ Object obj3 = beanContainer.getComponentInstance("TestBeanC");
+ assertTrue(obj3 instanceof TestBean);
+ TestBean testBeanC = (TestBean)obj3;
+
+ //handlers are in bundlea, with its own container.
+ BlueprintContainer handlerContainer =
+ getBlueprintContainerForBundle( bundleContext , "org.apache.aries.blueprint.testbundlea", 5000);
+ assertNotNull(handlerContainer);
+
+ Object ns1 = handlerContainer.getComponentInstance("NSHandlerOne");
+ assertTrue(ns1 instanceof NSHandlerOne);
+
+ Object ns2 = handlerContainer.getComponentInstance("NSHandlerTwo");
+ assertTrue(ns2 instanceof NSHandlerTwo);
+ NSHandlerTwo nstwo = (NSHandlerTwo)ns2;
+
+ //now we have a handle to the nshandler2, we can query what it 'saw', and ensure
+ //that the interceptors are functioning as expected.
+ List<String> log = nstwo.getLog();
+
+ //TestBeanC has the interceptor configured, and is injected to OtherBeanA & OtherBeanB
+ //which then uses the injected bean during their init method call, to invoke a method
+ checkInterceptorLog(new String[] {
+ "PRECALL:TestBeanC:methodToInvoke:[RED]:",
+ "POSTCALL[true]:TestBeanC:methodToInvoke:[RED]:",
+ "PRECALL:TestBeanC:methodToInvoke:[BLUE]:",
+ "POSTCALL[false]:TestBeanC:methodToInvoke:[BLUE]:"
+ }, log);
+
+ //invoking GREEN is hardwired to cause an exception response, we do this
+ //from here to ensure the exception occurs and is visible as expected
+ RuntimeException re=null;
+ try{
+ testBeanC.methodToInvoke("GREEN");
+ }catch(RuntimeException e){
+ re=e;
+ }
+ assertNotNull("invocation of Green did not cause an exception as expected",re);
+
+ //Exception responses should be intercepted too, test for the POSTCALLWITHEXCEPTION log entry.
+ log = nstwo.getLog();
+ checkInterceptorLog(new String[] {
+ "PRECALL:TestBeanC:methodToInvoke:[RED]:",
+ "POSTCALL[true]:TestBeanC:methodToInvoke:[RED]:",
+ "PRECALL:TestBeanC:methodToInvoke:[BLUE]:",
+ "POSTCALL[false]:TestBeanC:methodToInvoke:[BLUE]:",
+ "PRECALL:TestBeanC:methodToInvoke:[GREEN]:",
+ "POSTCALLEXCEPTION[java.lang.RuntimeException: MATCHED ON GREEN (GREEN)]:TestBeanC:methodToInvoke:[GREEN]:"
+ }, log);
+
+ //ProcessedBean is a test to ensure that BeanProcessors are called..
+ //The test has the BeanProcessor look for ProcessableBeans, and log itself with them
+ Object obj4 = beanContainer.getComponentInstance("ProcessedBean");
+ assertTrue(obj4 instanceof ProcessableBean);
+ ProcessableBean pb = (ProcessableBean)obj4;
+
+ //Note, the BeanProcessor exists in the same container as the beans it processes!!
+ Object bp = beanContainer.getComponentInstance("http://ns.handler.three/BeanProcessor");
+ assertNotNull(bp);
+ assertTrue(bp instanceof BeanProcessor);
+ assertEquals(1,pb.getProcessedBy().size());
+ //check we were invoked..
+ assertEquals(pb.getProcessedBy().get(0),bp);
+ //check invocation for each phase.
+ assertEquals(pb.getProcessedBy(Phase.BEFORE_INIT).get(0),bp);
+ assertEquals(pb.getProcessedBy(Phase.AFTER_INIT).get(0),bp);
+ //destroy invocation will only occur at tear down.. TODO, how to test after teardown.
+ //assertEquals(pb.getProcessedBy(Phase.BEFORE_DESTROY).get(0),bp);
+ //assertEquals(pb.getProcessedBy(Phase.AFTER_DESTROY).get(0),bp);
+ }
+}
Added: aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainer2BTCustomizerTest.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainer2BTCustomizerTest.java?rev=1075143&view=auto
==============================================================================
--- aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainer2BTCustomizerTest.java (added)
+++ aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainer2BTCustomizerTest.java Sun Feb 27 20:50:38 2011
@@ -0,0 +1,142 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertNotNull;
+import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.framework.CompositeBundle;
+import org.osgi.service.framework.CompositeBundleFactory;
+
+/**
+ * This test is based on the BlueprintContainerBTCustomizerTest. but this test starts the
+ * blueprint sample before the blueprint bundle is started so going a slightly
+ * different code path
+ *
+ */
+@RunWith(JUnit4TestRunner.class)
+public class BlueprintContainer2BTCustomizerTest extends AbstractIntegrationTest {
+
+ @Test
+ public void test() throws Exception {
+ // Create a config to check the property placeholder
+ ConfigurationAdmin ca = getOsgiService(ConfigurationAdmin.class);
+ Configuration cf = ca.getConfiguration("blueprint-sample-placeholder", null);
+ Hashtable props = new Hashtable();
+ props.put("key.b", "10");
+ cf.update(props);
+
+
+ ServiceReference sr = bundleContext.getServiceReference("org.osgi.service.framework.CompositeBundleFactory");
+ if (sr != null) {
+ // install blueprint.sample into the composite context
+ CompositeBundleFactory cbf = (CompositeBundleFactory)bundleContext.getService(sr);
+
+ Map<String, String> frameworkConfig = new HashMap<String, String>();
+ // turn on the line below to enable telnet localhost 10000 to the child framework osgi console
+ // frameworkConfig.put("osgi.console", "10000");
+
+ // construct composite bundle information
+ Map<String, String> compositeManifest = new HashMap<String, String>();
+ compositeManifest.put(Constants.BUNDLE_SYMBOLICNAME, "test-composite");
+ compositeManifest.put(Constants.BUNDLE_VERSION, "1.0.0");
+ // this import-package is used by the blueprint.sample
+ compositeManifest.put(Constants.IMPORT_PACKAGE, "org.osgi.service.blueprint;version=\"[1.0.0,2.0.0)\", org.osgi.service.blueprint.container;version=1.0");
+ // this export-package is used by pax junit runner as it needs to see the blueprint sample package
+ // for the test after the blueprint sample is started.
+ compositeManifest.put(Constants.EXPORT_PACKAGE, "org.apache.aries.blueprint.sample");
+
+ CompositeBundle cb = cbf.installCompositeBundle(frameworkConfig, "test-composite", compositeManifest);
+
+ BundleContext compositeBundleContext = cb.getCompositeFramework().getBundleContext();
+ // install the blueprint sample onto the framework associated with the composite bundle
+ MavenArtifactProvisionOption mapo = mavenBundleInTest("org.apache.aries.blueprint", "org.apache.aries.blueprint.sample");
+ // let's use input stream to avoid invoking mvn url handler which isn't avail in the child framework.
+ InputStream is = new URL(mapo.getURL()).openStream();
+ Bundle bundle = compositeBundleContext.installBundle(mapo.getURL(), is);
+ assertNotNull(bundle);
+
+ // start the composite bundle then the blueprint sample
+ cb.start();
+ bundle.start();
+
+ // start the blueprint bundle and it should detect the previously started blueprint sample
+ Bundle blueprintBundle = getInstalledBundle("org.apache.aries.blueprint");
+ blueprintBundle.start();
+ Thread.sleep(2000);
+
+ // do the test
+ testBlueprintContainer(compositeBundleContext, bundle);
+
+ // unget the service
+ bundleContext.ungetService(sr);
+ }
+ }
+
+ @org.ops4j.pax.exam.junit.Configuration
+ public static Option[] configuration() {
+ Option[] options = options(
+ // Log
+ mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
+ mavenBundle("org.ops4j.pax.logging", "pax-logging-service"),
+ // Felix Config Admin
+ mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
+ // Felix mvn url handler
+ mavenBundle("org.ops4j.pax.url", "pax-url-mvn"),
+
+
+ // this is how you set the default log level when using pax logging (logProfile)
+ systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
+
+ // Bundles
+ mavenBundle("org.apache.aries", "org.apache.aries.util"),
+ mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint").noStart(),
+ // don't install the blueprint sample here as it will be installed onto the same framework as the blueprint core bundle
+ // mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint.sample").noStart(),
+ mavenBundle("org.osgi", "org.osgi.compendium"),
+// org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
+
+ equinox().version("3.5.0")
+ );
+
+ options = updateOptions(options);
+ return options;
+ }
+
+}
Added: aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainer2Test.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainer2Test.java?rev=1075143&view=auto
==============================================================================
--- aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainer2Test.java (added)
+++ aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainer2Test.java Sun Feb 27 20:50:38 2011
@@ -0,0 +1,93 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertNotNull;
+import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+
+import java.util.Hashtable;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Bundle;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+/**
+ * this test is based on blueprint container test, but this test starts the
+ * blueprint sample before the blueprint bundle is started so going a slightly
+ * different code path
+ *
+ */
+@RunWith(JUnit4TestRunner.class)
+public class BlueprintContainer2Test extends AbstractIntegrationTest {
+
+ @Test
+ public void test() throws Exception {
+ // Create a config to check the property placeholder
+ ConfigurationAdmin ca = getOsgiService(ConfigurationAdmin.class);
+ Configuration cf = ca.getConfiguration("blueprint-sample-placeholder", null);
+ Hashtable props = new Hashtable();
+ props.put("key.b", "10");
+ cf.update(props);
+
+ Bundle bundle = getInstalledBundle("org.apache.aries.blueprint.sample");
+ Bundle blueprintBundle = getInstalledBundle("org.apache.aries.blueprint");
+ assertNotNull(bundle);
+
+ bundle.start();
+ blueprintBundle.start();
+
+ // do the test
+ testBlueprintContainer(bundle);
+ }
+
+ @org.ops4j.pax.exam.junit.Configuration
+ public static Option[] configuration() {
+ Option[] options = options(
+ // Log
+ mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
+ mavenBundle("org.ops4j.pax.logging", "pax-logging-service"),
+ // Felix Config Admin
+ mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
+ // Felix mvn url handler
+ mavenBundle("org.ops4j.pax.url", "pax-url-mvn"),
+
+
+ // this is how you set the default log level when using pax logging (logProfile)
+ systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
+
+ // Bundles
+ mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint.sample").noStart(),
+ mavenBundle("org.apache.aries", "org.apache.aries.util"),
+ mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint").noStart(),
+ mavenBundle("org.osgi", "org.osgi.compendium"),
+// org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
+
+ equinox().version("3.5.0")
+ );
+ options = updateOptions(options);
+ return options;
+ }
+
+}
Added: aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainerBTCustomizerTest.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainerBTCustomizerTest.java?rev=1075143&view=auto
==============================================================================
--- aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainerBTCustomizerTest.java (added)
+++ aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainerBTCustomizerTest.java Sun Feb 27 20:50:38 2011
@@ -0,0 +1,149 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertNotNull;
+import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+import static org.ops4j.pax.exam.CoreOptions.waitForFrameworkStartup;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.framework.CompositeBundle;
+import org.osgi.service.framework.CompositeBundleFactory;
+
+/**
+ * This test is based on the BlueprintContainerTest. The difference is that in this test,
+ * the blueprint sample is installed into a child framework that is associated with a composite
+ * bundle created from CompositeBundleFactory. This test only runs when the CompositeBundleFactory
+ * service is avail in the OSGi service registry.
+ *
+ */
+@RunWith(JUnit4TestRunner.class)
+public class BlueprintContainerBTCustomizerTest extends AbstractIntegrationTest {
+
+ @Test
+ public void test() throws Exception {
+ // Create a config to check the property placeholder
+ ConfigurationAdmin ca = getOsgiService(ConfigurationAdmin.class);
+ Configuration cf = ca.getConfiguration("blueprint-sample-placeholder", null);
+ Hashtable props = new Hashtable();
+ props.put("key.b", "10");
+ cf.update(props);
+
+
+ ServiceReference sr = bundleContext.getServiceReference("org.osgi.service.framework.CompositeBundleFactory");
+ if (sr != null) {
+ // install blueprint.sample into the composite context
+ CompositeBundleFactory cbf = (CompositeBundleFactory)bundleContext.getService(sr);
+
+ Map<String, String> frameworkConfig = new HashMap<String, String>();
+ // turn on the line below to enable telnet localhost 10000 to the child framework osgi console
+ // frameworkConfig.put("osgi.console", "10000");
+
+ // construct composite bundle information
+ Map<String, String> compositeManifest = new HashMap<String, String>();
+ compositeManifest.put(Constants.BUNDLE_SYMBOLICNAME, "test-composite");
+ compositeManifest.put(Constants.BUNDLE_VERSION, "1.0.0");
+ // this import-package is used by the blueprint.sample
+ compositeManifest.put(Constants.IMPORT_PACKAGE, "org.osgi.service.blueprint;version=\"[1.0.0,2.0.0)\", org.osgi.service.blueprint.container;version=1.0");
+ // this export-package is used by pax junit runner as it needs to see the blueprint sample package
+ // for the test after the blueprint sample is started.
+ compositeManifest.put(Constants.EXPORT_PACKAGE, "org.apache.aries.blueprint.sample");
+
+ CompositeBundle cb = cbf.installCompositeBundle(frameworkConfig, "test-composite", compositeManifest);
+
+ BundleContext compositeBundleContext = cb.getCompositeFramework().getBundleContext();
+ // install the blueprint sample onto the framework associated with the composite bundle
+ MavenArtifactProvisionOption mapo = mavenBundleInTest("org.apache.aries.blueprint", "org.apache.aries.blueprint.sample");
+ // let's use input stream to avoid invoking mvn url handler which isn't avail in the child framework.
+ InputStream is = new URL(mapo.getURL()).openStream();
+ Bundle bundle = compositeBundleContext.installBundle(mapo.getURL(), is);
+ assertNotNull(bundle);
+
+ // start the composite bundle then the blueprint sample
+ cb.start();
+ bundle.start();
+
+ // do the test
+ testBlueprintContainer(compositeBundleContext, bundle);
+
+ // unget the service
+ bundleContext.ungetService(sr);
+
+ }
+ }
+
+ @org.ops4j.pax.exam.junit.Configuration
+ public static Option[] configuration() {
+ Option[] options = options(
+ // Log
+ mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
+ mavenBundle("org.ops4j.pax.logging", "pax-logging-service"),
+ // Felix Config Admin
+ mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
+ // Felix mvn url handler
+ mavenBundle("org.ops4j.pax.url", "pax-url-mvn"),
+
+
+ // this is how you set the default log level when using pax logging (logProfile)
+ systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
+
+ // Bundles
+ mavenBundle("org.apache.aries", "org.apache.aries.util"),
+ mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint"),
+ // don't install the blueprint sample here as it will be installed onto the same framework as the blueprint core bundle
+ //mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint.sample").noStart(),
+ mavenBundle("org.osgi", "org.osgi.compendium"),
+// org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
+
+ /* For debugging, uncomment the next two lines */
+// vmOption ("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=7777"),
+// waitForFrameworkStartup(),
+
+ /* For debugging, uncomment the next two lines
+ and add these imports:
+ import static org.ops4j.pax.exam.CoreOptions.waitForFrameworkStartup;
+ import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption;
+ */
+ equinox().version("3.5.1")
+ );
+ options = updateOptions(options);
+ return options;
+ }
+
+}
Added: aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainerTest.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainerTest.java?rev=1075143&view=auto
==============================================================================
--- aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainerTest.java (added)
+++ aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainerTest.java Sun Feb 27 20:50:38 2011
@@ -0,0 +1,110 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+
+import java.text.SimpleDateFormat;
+import java.util.Currency;
+import java.util.Hashtable;
+import java.util.HashSet;
+
+import org.apache.aries.blueprint.sample.Bar;
+import org.apache.aries.blueprint.sample.Foo;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Bundle;
+import org.osgi.service.blueprint.container.BlueprintContainer;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+@RunWith(JUnit4TestRunner.class)
+public class BlueprintContainerTest extends AbstractIntegrationTest {
+
+ @Test
+ public void test() throws Exception {
+ // Create a config to check the property placeholder
+ ConfigurationAdmin ca = getOsgiService(ConfigurationAdmin.class);
+ Configuration cf = ca.getConfiguration("blueprint-sample-placeholder", null);
+ Hashtable props = new Hashtable();
+ props.put("key.b", "10");
+ cf.update(props);
+
+ Bundle bundle = getInstalledBundle("org.apache.aries.blueprint.sample");
+ assertNotNull(bundle);
+
+ bundle.start();
+
+ // do the test
+ testBlueprintContainer(bundle);
+ }
+
+ @Test
+ public void testDeadlock() throws Exception {
+ bundleContext.registerService("java.util.Set",new HashSet<Object>(), null);
+
+ Bundle bundle = getInstalledBundle("org.apache.aries.blueprint.sample");
+ assertNotNull(bundle);
+
+ bundle.start();
+
+ getBlueprintContainerForBundle(bundleContext, "org.apache.aries.blueprint.sample",5000);
+
+ // no actual assertions, we just don't want to deadlock
+ }
+
+ @org.ops4j.pax.exam.junit.Configuration
+ public static Option[] configuration() {
+ Option[] options = options(
+ // Log
+ mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
+ mavenBundle("org.ops4j.pax.logging", "pax-logging-service"),
+ // Felix Config Admin
+ mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
+ // Felix mvn url handler
+ mavenBundle("org.ops4j.pax.url", "pax-url-mvn"),
+
+
+ // this is how you set the default log level when using pax logging (logProfile)
+ systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
+
+ // Bundles
+ mavenBundle("org.apache.aries", "org.apache.aries.util"),
+ mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint"),
+ mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint.sample").noStart(),
+ mavenBundle("org.osgi", "org.osgi.compendium"),
+ //org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
+
+ equinox().version("3.5.0")
+ );
+ options = updateOptions(options);
+ return options;
+ }
+
+}
Added: aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/MultiBundleWithAsmTest.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/MultiBundleWithAsmTest.java?rev=1075143&view=auto
==============================================================================
--- aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/MultiBundleWithAsmTest.java (added)
+++ aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/MultiBundleWithAsmTest.java Sun Feb 27 20:50:38 2011
@@ -0,0 +1,66 @@
+/*
+ * 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;
+
+import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+
+@RunWith(JUnit4TestRunner.class)
+public class MultiBundleWithAsmTest extends AbstractMultiBundleTest{
+ @Test
+ public void doMultiBundleAsmTest() throws Exception{
+ doCommonMultiBundleTest();
+ }
+
+ @org.ops4j.pax.exam.junit.Configuration
+ public static Option[] configuration() {
+ Option[] options = options(
+ // Log
+ mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
+ mavenBundle("org.ops4j.pax.logging", "pax-logging-service"),
+ // Felix Config Admin
+ mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
+ // Felix mvn url handler
+ mavenBundle("org.ops4j.pax.url", "pax-url-mvn"),
+
+ // this is how you set the default log level when using pax logging (logProfile)
+ systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
+
+ // Bundles
+ mavenBundle("org.apache.aries", "org.apache.aries.util"),
+ mavenBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.cglib"),
+ mavenBundle("asm","asm-all"),
+ mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint"),
+ mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint.testbundlea").noStart(),
+ mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint.testbundleb").noStart(),
+ mavenBundle("org.osgi", "org.osgi.compendium"),
+ // org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
+
+ equinox().version("3.5.0")
+ );
+ options = updateOptions(options);
+ return options;
+ }
+}
Added: aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/MultiBundleWithCgLibTest.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/MultiBundleWithCgLibTest.java?rev=1075143&view=auto
==============================================================================
--- aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/MultiBundleWithCgLibTest.java (added)
+++ aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/MultiBundleWithCgLibTest.java Sun Feb 27 20:50:38 2011
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+
+@RunWith(JUnit4TestRunner.class)
+public class MultiBundleWithCgLibTest extends AbstractMultiBundleTest{
+ @Test
+ public void doMultiBundleCgLibTest() throws Exception{
+ doCommonMultiBundleTest();
+ }
+
+ @org.ops4j.pax.exam.junit.Configuration
+ public static Option[] configuration() {
+ Option[] options = options(
+ // Log
+ mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
+ mavenBundle("org.ops4j.pax.logging", "pax-logging-service"),
+ // Felix Config Admin
+ mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
+ // Felix mvn url handler
+ mavenBundle("org.ops4j.pax.url", "pax-url-mvn"),
+
+ // this is how you set the default log level when using pax logging (logProfile)
+ systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
+
+ // Bundles
+ mavenBundle("org.apache.aries", "org.apache.aries.util"),
+ mavenBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.cglib"),
+ mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint"),
+ mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint.testbundlea").noStart(),
+ mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint.testbundleb").noStart(),
+ mavenBundle("org.osgi", "org.osgi.compendium"),
+ // org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
+
+ equinox().version("3.5.0")
+ );
+ options = updateOptions(options);
+ return options;
+ }
+}
Added: aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestConfigAdmin.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestConfigAdmin.java?rev=1075143&view=auto
==============================================================================
--- aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestConfigAdmin.java (added)
+++ aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestConfigAdmin.java Sun Feb 27 20:50:38 2011
@@ -0,0 +1,193 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+
+import java.util.Currency;
+import java.util.Hashtable;
+
+import org.apache.aries.blueprint.sample.Foo;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Bundle;
+import org.osgi.service.blueprint.container.BlueprintContainer;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+@RunWith(JUnit4TestRunner.class)
+public class TestConfigAdmin extends AbstractIntegrationTest {
+
+ @Test
+ public void testStrategyNone() throws Exception {
+ ConfigurationAdmin ca = getOsgiService(ConfigurationAdmin.class);
+ Configuration cf = ca.getConfiguration("blueprint-sample-managed.none", null);
+ Hashtable<String,String> props = new Hashtable<String,String>();
+ props.put("a", "5");
+ props.put("currency", "PLN");
+ cf.update(props);
+
+ Bundle bundle = getInstalledBundle("org.apache.aries.blueprint.sample");
+ assertNotNull(bundle);
+ bundle.start();
+
+ BlueprintContainer blueprintContainer = getBlueprintContainerForBundle("org.apache.aries.blueprint.sample", 5000);
+ assertNotNull(blueprintContainer);
+
+ Foo foo = (Foo) blueprintContainer.getComponentInstance("none-managed");
+ assertNotNull(foo);
+
+ assertEquals(5, foo.getA());
+ assertEquals(Currency.getInstance("PLN"), foo.getCurrency());
+
+ props = new Hashtable<String,String>();
+ props.put("a", "10");
+ props.put("currency", "USD");
+ cf = ca.getConfiguration("blueprint-sample-managed.none", null);
+ cf.update(props);
+
+ Thread.sleep(100);
+
+ assertEquals(5, foo.getA());
+ assertEquals(Currency.getInstance("PLN"), foo.getCurrency());
+ }
+
+ @Test
+ public void testStrategyContainer() throws Exception {
+ ConfigurationAdmin ca = getOsgiService(ConfigurationAdmin.class);
+ Configuration cf = ca.getConfiguration("blueprint-sample-managed.container", null);
+ Hashtable<String,String> props = new Hashtable<String,String>();
+ props.put("a", "5");
+ props.put("currency", "PLN");
+ cf.update(props);
+
+ Bundle bundle = getInstalledBundle("org.apache.aries.blueprint.sample");
+ assertNotNull(bundle);
+ bundle.start();
+
+ BlueprintContainer blueprintContainer = getBlueprintContainerForBundle("org.apache.aries.blueprint.sample", 5000);
+ assertNotNull(blueprintContainer);
+
+ Foo foo = (Foo) blueprintContainer.getComponentInstance("container-managed");
+ assertNotNull(foo);
+
+ assertEquals(5, foo.getA());
+ assertEquals(Currency.getInstance("PLN"), foo.getCurrency());
+
+ props = new Hashtable<String,String>();
+ props.put("a", "10");
+ props.put("currency", "USD");
+ cf.update(props);
+
+ Thread.sleep(100);
+
+ assertEquals(10, foo.getA());
+ assertEquals(Currency.getInstance("USD"), foo.getCurrency());
+ }
+
+ @Test
+ public void testStrategyComponent() throws Exception {
+ ConfigurationAdmin ca = getOsgiService(ConfigurationAdmin.class);
+ Configuration cf = ca.getConfiguration("blueprint-sample-managed.component", null);
+ Hashtable<String,String> props = new Hashtable<String,String>();
+ props.put("a", "5");
+ props.put("currency", "PLN");
+ cf.update(props);
+
+ Bundle bundle = getInstalledBundle("org.apache.aries.blueprint.sample");
+ assertNotNull(bundle);
+ bundle.start();
+
+ BlueprintContainer blueprintContainer = getBlueprintContainerForBundle("org.apache.aries.blueprint.sample", 5000);
+ assertNotNull(blueprintContainer);
+
+ Foo foo = (Foo) blueprintContainer.getComponentInstance("component-managed");
+ assertNotNull(foo);
+
+ assertEquals(5, foo.getA());
+ assertEquals(Currency.getInstance("PLN"), foo.getCurrency());
+
+ props = new Hashtable<String,String>();
+ props.put("a", "10");
+ props.put("currency", "USD");
+ cf.update(props);
+
+ Thread.sleep(100);
+
+ assertEquals(5, foo.getA());
+ assertEquals(Currency.getInstance("PLN"), foo.getCurrency());
+ assertNotNull(foo.getProps());
+ assertEquals("10", foo.getProps().get("a"));
+ assertEquals("USD", foo.getProps().get("currency"));
+ }
+
+ @Test
+ public void testManagedServiceFactory() throws Exception {
+ ConfigurationAdmin ca = getOsgiService(ConfigurationAdmin.class);
+ Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory", null);
+ Hashtable<String,String> props = new Hashtable<String,String>();
+ props.put("a", "5");
+ props.put("currency", "PLN");
+ cf.update(props);
+
+ Bundle bundle = getInstalledBundle("org.apache.aries.blueprint.sample");
+ assertNotNull(bundle);
+ bundle.start();
+
+ BlueprintContainer blueprintContainer = getBlueprintContainerForBundle("org.apache.aries.blueprint.sample", 5000);
+ assertNotNull(blueprintContainer);
+
+ Thread.sleep(5000);
+ }
+
+ @org.ops4j.pax.exam.junit.Configuration
+ public static Option[] configuration() {
+ Option[] options = options(
+ // Log
+ mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
+ mavenBundle("org.ops4j.pax.logging", "pax-logging-service"),
+ // Felix Config Admin
+ mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
+ // Felix mvn url handler
+ mavenBundle("org.ops4j.pax.url", "pax-url-mvn"),
+
+
+ // this is how you set the default log level when using pax logging (logProfile)
+ systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
+
+ // Bundles
+ mavenBundle("org.apache.aries", "org.apache.aries.util"),
+ mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint"),
+ mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint.sample").noStart(),
+ mavenBundle("org.osgi","org.osgi.compendium"),
+// org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
+
+ equinox().version("3.5.0")
+ );
+ options = updateOptions(options);
+ return options;
+ }
+
+}
Added: aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestReferences.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestReferences.java?rev=1075143&view=auto
==============================================================================
--- aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestReferences.java (added)
+++ aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestReferences.java Sun Feb 27 20:50:38 2011
@@ -0,0 +1,156 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+
+import java.util.Hashtable;
+import java.util.List;
+
+import org.apache.aries.blueprint.sample.BindingListener;
+import org.apache.aries.blueprint.sample.InterfaceA;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.blueprint.container.BlueprintContainer;
+import org.osgi.service.blueprint.container.ServiceUnavailableException;
+
+@RunWith(JUnit4TestRunner.class)
+public class TestReferences extends AbstractIntegrationTest {
+
+ @Test
+ public void testUnaryReference() throws Exception {
+ BlueprintContainer blueprintContainer = getBlueprintContainerForBundle("org.apache.aries.blueprint.sample");
+ assertNotNull(blueprintContainer);
+
+ BindingListener listener = (BindingListener) blueprintContainer.getComponentInstance("bindingListener");
+ assertNull(listener.getA());
+ assertNull(listener.getReference());
+
+ InterfaceA a = (InterfaceA) blueprintContainer.getComponentInstance("ref2");
+ try {
+ a.hello("world");
+ fail("A ServiceUnavailableException should have been thrown");
+ } catch (ServiceUnavailableException e) {
+ // Ignore, expected
+ }
+
+ ServiceRegistration reg1 = bundleContext.registerService(InterfaceA.class.getName(), new InterfaceA() {
+ public String hello(String msg) {
+ return "Hello " + msg + "!";
+ }
+ }, null);
+ assertNotNull(listener.getA());
+ assertNotNull(listener.getReference());
+ assertEquals("Hello world!", a.hello("world"));
+
+ Hashtable props = new Hashtable();
+ props.put(Constants.SERVICE_RANKING, Integer.valueOf(1));
+ ServiceRegistration reg2 = bundleContext.registerService(InterfaceA.class.getName(), new InterfaceA() {
+ public String hello(String msg) {
+ return "Good morning " + msg + "!";
+ }
+ }, props);
+
+ assertNotNull(listener.getA());
+ assertNotNull(listener.getReference());
+ assertEquals("Hello world!", a.hello("world"));
+
+ reg1.unregister();
+ assertNotNull(listener.getA());
+ assertNotNull(listener.getReference());
+ assertEquals("Good morning world!", a.hello("world"));
+
+ reg2.unregister();
+ assertNull(listener.getA());
+ assertNull(listener.getReference());
+ try {
+ a.hello("world");
+ fail("A ServiceUnavailableException should have been thrown");
+ } catch (ServiceUnavailableException e) {
+ // Ignore, expected
+ }
+ }
+
+ @Test
+ public void testListReferences() throws Exception {
+ BlueprintContainer blueprintContainer = getBlueprintContainerForBundle("org.apache.aries.blueprint.sample");
+ assertNotNull(blueprintContainer);
+
+ BindingListener listener = (BindingListener) blueprintContainer.getComponentInstance("listBindingListener");
+ assertNull(listener.getA());
+ assertNull(listener.getReference());
+
+ List refs = (List) blueprintContainer.getComponentInstance("ref-list");
+ assertNotNull(refs);
+ assertTrue(refs.isEmpty());
+
+ ServiceRegistration reg1 = bundleContext.registerService(InterfaceA.class.getName(), new InterfaceA() {
+ public String hello(String msg) {
+ return "Hello " + msg + "!";
+ }
+ }, null);
+ assertNotNull(listener.getA());
+ assertNotNull(listener.getReference());
+ assertEquals(1, refs.size());
+ InterfaceA a = (InterfaceA) refs.get(0);
+ assertNotNull(a);
+ assertEquals("Hello world!", a.hello("world"));
+
+ }
+
+ @org.ops4j.pax.exam.junit.Configuration
+ public static Option[] configuration() {
+ Option[] options = options(
+ // Log
+ mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
+ mavenBundle("org.ops4j.pax.logging", "pax-logging-service"),
+ // Felix Config Admin
+ mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
+ // Felix mvn url handler
+ mavenBundle("org.ops4j.pax.url", "pax-url-mvn"),
+
+ // this is how you set the default log level when using pax logging (logProfile)
+ systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
+
+ // Bundles
+ mavenBundle("org.apache.aries", "org.apache.aries.util"),
+ mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint"),
+ mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint.sample"),
+ mavenBundle("org.osgi", "org.osgi.compendium"),
+
+// org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
+
+ equinox().version("3.5.0")
+ );
+ options = updateOptions(options);
+ return options;
+ }
+
+}
Added: aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestRegistrationListener.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestRegistrationListener.java?rev=1075143&view=auto
==============================================================================
--- aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestRegistrationListener.java (added)
+++ aries/tags/blueprint-0.2.1/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestRegistrationListener.java Sun Feb 27 20:50:38 2011
@@ -0,0 +1,97 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+
+import java.util.Map;
+
+import org.apache.aries.blueprint.BlueprintConstants;
+import org.apache.aries.blueprint.sample.Foo;
+import org.apache.aries.blueprint.sample.FooRegistrationListener;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.service.blueprint.container.BlueprintContainer;
+
+@RunWith(JUnit4TestRunner.class)
+public class TestRegistrationListener extends AbstractIntegrationTest {
+
+ @Test
+ public void testWithAutoExportEnabled() throws Exception {
+
+ BlueprintContainer blueprintContainer = getBlueprintContainerForBundle("org.apache.aries.blueprint.sample");
+ assertNotNull(blueprintContainer);
+
+ Foo foo = getOsgiService(Foo.class, "(" + BlueprintConstants.COMPONENT_NAME_PROPERTY + "=foo)", DEFAULT_TIMEOUT);
+ assertEquals(5, foo.getA());
+
+ FooRegistrationListener listener =
+ (FooRegistrationListener) blueprintContainer.getComponentInstance("fooRegistrationListener");
+
+ // If registration listener works fine, the registration method should
+ // have already been called and properties that were passed to this
+ // method should have been not null
+
+ Map props = listener.getProperties();
+ assertNotNull(props);
+
+ assertTrue(props.containsKey(BlueprintConstants.COMPONENT_NAME_PROPERTY));
+ assertEquals("foo", props.get(BlueprintConstants.COMPONENT_NAME_PROPERTY));
+
+ assertTrue(props.containsKey("key"));
+ assertEquals("value", props.get("key"));
+
+ }
+
+ @org.ops4j.pax.exam.junit.Configuration
+ public static Option[] configuration() {
+ Option[] options = options(
+ // Log
+ mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
+ mavenBundle("org.ops4j.pax.logging", "pax-logging-service"),
+ // Felix Config Admin
+ mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
+ // Felix mvn url handler
+ mavenBundle("org.ops4j.pax.url", "pax-url-mvn"),
+
+ // this is how you set the default log level when using pax
+ // logging (logProfile)
+ systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
+
+ // Bundles
+ mavenBundle("org.apache.aries", "org.apache.aries.util"),
+ mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint"),
+ mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint.sample"),
+ mavenBundle("org.osgi", "org.osgi.compendium"),
+
+ // org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
+
+ equinox().version("3.5.0"));
+ options = updateOptions(options);
+ return options;
+ }
+
+}
Added: aries/tags/blueprint-0.2.1/blueprint-itests/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.2.1/blueprint-itests/src/test/resources/log4j.properties?rev=1075143&view=auto
==============================================================================
--- aries/tags/blueprint-0.2.1/blueprint-itests/src/test/resources/log4j.properties (added)
+++ aries/tags/blueprint-0.2.1/blueprint-itests/src/test/resources/log4j.properties Sun Feb 27 20:50:38 2011
@@ -0,0 +1,33 @@
+################################################################################
+#
+# 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.
+#
+################################################################################
+
+# Root logger
+log4j.rootLogger=DEBUG, stdout
+
+# CONSOLE appender not used by default
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p | %-16.16t | %-32.32c{1} | %-32.32C %4L | %m%n
+
+# File appender
+log4j.appender.out=org.apache.log4j.FileAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p | %-16.16t | %-32.32c{1} | %-32.32C %4L | %m%n
+log4j.appender.out.file=${karaf.base}/data/log/karaf.log
+log4j.appender.out.append=true
Added: aries/tags/blueprint-0.2.1/blueprint-sample-annotation/pom.xml
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.2.1/blueprint-sample-annotation/pom.xml?rev=1075143&view=auto
==============================================================================
--- aries/tags/blueprint-0.2.1/blueprint-sample-annotation/pom.xml (added)
+++ aries/tags/blueprint-0.2.1/blueprint-sample-annotation/pom.xml Sun Feb 27 20:50:38 2011
@@ -0,0 +1,86 @@
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.aries.blueprint</groupId>
+ <artifactId>blueprint</artifactId>
+ <version>0.2.1</version>
+ </parent>
+
+ <artifactId>org.apache.aries.blueprint.sample-annotation</artifactId>
+ <name>Apache Aries Blueprint Sample for Testing Annotation</name>
+ <packaging>bundle</packaging>
+ <description>
+ Example blueprint application, mostly used for annotation tests.
+ </description>
+
+ <properties>
+ <aries.osgi.export>
+ org.apache.aries.blueprint.sample;-noimport:=true
+ </aries.osgi.export>
+ <aries.osgi.activator>
+ org.apache.aries.blueprint.sample.Activator
+ </aries.osgi.activator>
+ <aries.osgi.import>
+ org.apache.aries.blueprint.annotation,
+ *
+ </aries.osgi.import>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.eclipse</groupId>
+ <artifactId>osgi</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.blueprint</groupId>
+ <artifactId>org.apache.aries.blueprint.api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.blueprint</groupId>
+ <artifactId>org.apache.aries.blueprint.annotation.api</artifactId>
+ <version>${version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <inherited>true</inherited>
+ <configuration>
+ <excludeDependencies>${aries.osgi.exclude.dependencies}</excludeDependencies>
+ <instructions>
+ <Bundle-Blueprint-Annotation>true</Bundle-Blueprint-Annotation>
+ </instructions>
+ <versions>
+ <aries.osgi.version.clean>${project.version}</aries.osgi.version.clean>
+ </versions>
+ </configuration>
+ </plugin>
+
+ </plugins>
+ </pluginManagement>
+ </build>
+
+
+</project>
Added: aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/Account.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/Account.java?rev=1075143&view=auto
==============================================================================
--- aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/Account.java (added)
+++ aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/Account.java Sun Feb 27 20:50:38 2011
@@ -0,0 +1,38 @@
+/**
+ * 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.sample;
+
+import org.apache.aries.blueprint.annotation.Arg;
+import org.apache.aries.blueprint.annotation.Bean;
+
+@Bean(id="accountOne", args=@Arg(value="1"))
+public class Account {
+
+ private long accountNumber;
+
+ public Account(long number) {
+ this.accountNumber = number;
+ }
+
+ public long getAccountNumber() {
+ return this.accountNumber;
+ }
+
+ public void setAccountNumber(long number) {
+ this.accountNumber = number;
+ }
+}
Added: aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/AccountFactory.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/AccountFactory.java?rev=1075143&view=auto
==============================================================================
--- aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/AccountFactory.java (added)
+++ aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/AccountFactory.java Sun Feb 27 20:50:38 2011
@@ -0,0 +1,38 @@
+/**
+ * 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.sample;
+
+import org.apache.aries.blueprint.annotation.Bean;
+import org.apache.aries.blueprint.annotation.Arg;
+
+@Bean(id="accountFactory", args=@Arg(value="account factory"))
+public class AccountFactory {
+ private String factoryName;
+
+ public AccountFactory(String factoryName) {
+ this.factoryName = factoryName;
+ }
+
+ public NewAccount createAccount(long number) {
+ return new NewAccount(number);
+ }
+
+ public String getFactoryName() {
+ return this.factoryName;
+ }
+
+}
Added: aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/Activator.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/Activator.java?rev=1075143&view=auto
==============================================================================
--- aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/Activator.java (added)
+++ aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/Activator.java Sun Feb 27 20:50:38 2011
@@ -0,0 +1,32 @@
+/**
+ * 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.sample;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class Activator implements BundleActivator {
+
+ public void start(BundleContext context) {
+ System.out.println("Bundle start");
+ }
+
+ public void stop(BundleContext context) {
+ System.out.println("Bundle stop");
+ }
+
+}
Added: aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/Bar.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/Bar.java?rev=1075143&view=auto
==============================================================================
--- aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/Bar.java (added)
+++ aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/Bar.java Sun Feb 27 20:50:38 2011
@@ -0,0 +1,73 @@
+/**
+ * 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.sample;
+
+import java.util.List;
+
+import org.osgi.framework.BundleContext;
+import org.apache.aries.blueprint.annotation.Blueprint;
+import org.apache.aries.blueprint.annotation.Bean;
+import org.apache.aries.blueprint.annotation.Inject;
+import org.apache.aries.blueprint.annotation.Element;
+import org.apache.aries.blueprint.annotation.Element.ElementType;
+
+@Blueprint(defaultActivation="eager", defaultTimeout=300, defaultAvailability="optional")
+@Bean(id="bar")
+public class Bar {
+
+ @Inject(value="Hello FooBar")
+ private String value;
+
+ @Inject(ref="blueprintBundleContext")
+ private BundleContext context;
+
+ /*@Inject
+ @org.apache.aries.blueprint.annotation.List ({
+ @Element(value="a list element"),
+ @Element(value="5", type=ElementType.INTEGER)
+ })*/
+ private List list;
+
+ public BundleContext getContext() {
+ return context;
+ }
+
+ public void setContext(BundleContext ctx) {
+ context = ctx;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String s) {
+ value = s;
+ }
+
+ public List getList() {
+ return list;
+ }
+
+ public void setList(List l) {
+ list = l;
+ }
+
+ public String toString() {
+ return hashCode() + ": " + value + " " + context + " " + list;
+ }
+
+}
Added: aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/BindingListener.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/BindingListener.java?rev=1075143&view=auto
==============================================================================
--- aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/BindingListener.java (added)
+++ aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/BindingListener.java Sun Feb 27 20:50:38 2011
@@ -0,0 +1,88 @@
+/**
+ * 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.sample;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.aries.blueprint.annotation.Bean;
+import org.apache.aries.blueprint.annotation.Bind;
+import org.apache.aries.blueprint.annotation.Init;
+import org.apache.aries.blueprint.annotation.Inject;
+import org.apache.aries.blueprint.annotation.Reference;
+import org.apache.aries.blueprint.annotation.ReferenceListener;
+import org.apache.aries.blueprint.annotation.Unbind;
+import org.osgi.framework.ServiceReference;
+
+@Bean(id="bindingListener")
+@ReferenceListener
+public class BindingListener {
+
+ @Inject @Reference (id="ref2",
+ serviceInterface = InterfaceA.class,
+ timeout=100, referenceListeners=@ReferenceListener(ref="bindingListener"))
+ private InterfaceA a;
+ private Map props;
+ private ServiceReference reference;
+ private List list;
+
+ public InterfaceA getA() {
+ return a;
+ }
+
+ public Map getProps() {
+ return props;
+ }
+
+ public ServiceReference getReference() {
+ return reference;
+ }
+
+ public List getList() {
+ return list;
+ }
+
+ public void setList(List list) {
+ this.list = list;
+ }
+
+ @Init
+ public void init() {
+ }
+
+ @Bind
+ public void bind(InterfaceA a, Map props) {
+ this.a = a;
+ this.props = props;
+ }
+
+ @Bind
+ public void bind(ServiceReference ref) {
+ this.reference = ref;
+ }
+
+ @Unbind
+ public void unbind(InterfaceA a, Map props) {
+ this.a = null;
+ this.props = null;
+ }
+
+ @Unbind
+ public void unbind(ServiceReference ref) {
+ this.reference = null;
+ }
+}
Added: aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/CurrencyTypeConverter.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/CurrencyTypeConverter.java?rev=1075143&view=auto
==============================================================================
--- aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/CurrencyTypeConverter.java (added)
+++ aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/CurrencyTypeConverter.java Sun Feb 27 20:50:38 2011
@@ -0,0 +1,36 @@
+/**
+ * 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.sample;
+
+import java.util.Currency;
+
+import org.apache.aries.blueprint.annotation.Bean;
+import org.osgi.service.blueprint.container.Converter;
+import org.osgi.service.blueprint.container.ReifiedType;
+
+@Bean(id="converter2")
+public class CurrencyTypeConverter implements Converter {
+
+ public boolean canConvert(Object fromValue, ReifiedType toType) {
+ return Currency.class.isAssignableFrom(toType.getRawClass());
+ }
+
+ public Object convert(Object source, ReifiedType toType) throws Exception {
+ return Currency.getInstance(source.toString());
+ }
+
+}
Added: aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/DateTypeConverter.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/DateTypeConverter.java?rev=1075143&view=auto
==============================================================================
--- aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/DateTypeConverter.java (added)
+++ aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/DateTypeConverter.java Sun Feb 27 20:50:38 2011
@@ -0,0 +1,46 @@
+/**
+ * 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.sample;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.apache.aries.blueprint.annotation.Bean;
+import org.apache.aries.blueprint.annotation.Inject;
+import org.osgi.service.blueprint.container.Converter;
+import org.osgi.service.blueprint.container.ReifiedType;
+
+@Bean(id="converter1")
+public class DateTypeConverter implements Converter {
+
+ @Inject(name="format", value="yyyy.MM.dd")
+ DateFormat dateFormat;
+
+ public void setFormat(String format) {
+ this.dateFormat = new SimpleDateFormat(format);
+ }
+
+ public Object convert(Object source, ReifiedType toType) throws Exception {
+ return this.dateFormat.parse(source.toString());
+ }
+
+ public boolean canConvert(Object fromValue, ReifiedType toType) {
+ return Date.class.isAssignableFrom(toType.getRawClass());
+ }
+
+}
Added: aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/Foo.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/Foo.java?rev=1075143&view=auto
==============================================================================
--- aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/Foo.java (added)
+++ aries/tags/blueprint-0.2.1/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/Foo.java Sun Feb 27 20:50:38 2011
@@ -0,0 +1,131 @@
+/**
+ * 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.sample;
+
+import java.io.Serializable;
+import java.util.Currency;
+import java.util.Date;
+import java.util.Map;
+
+import org.apache.aries.blueprint.annotation.Bean;
+import org.apache.aries.blueprint.annotation.Destroy;
+import org.apache.aries.blueprint.annotation.Init;
+import org.apache.aries.blueprint.annotation.Inject;
+import org.apache.aries.blueprint.annotation.RegistrationListener;
+import org.apache.aries.blueprint.annotation.Service;
+import org.apache.aries.blueprint.annotation.ServiceProperty;
+
+@Bean(id="foo")
+@Service(autoExport="all-classes",
+ serviceProperties = @ServiceProperty(key="blueprint.annotation.sample", value="true"),
+ registerationListeners = @RegistrationListener(ref="fooRegistrationListener"),
+ ranking=0)
+public class Foo implements Serializable {
+
+ @Inject(value="5")
+ private int a;
+
+ //@Inject(value="${key.b}")
+ private int b;
+
+ //@Inject(ref="bar")
+ private Bar bar;
+
+ @Inject(value="PLN")
+ private Currency currency;
+
+ @Inject(value="2009.04.17")
+ private Date date;
+
+ public boolean initialized;
+ public boolean destroyed;
+ private Map<String, Object> props;
+
+ public int getA() {
+ return a;
+ }
+
+ public void setA(int i) {
+ a = i;
+ }
+
+ public int getB() {
+ return b;
+ }
+
+ public void setB(int i) {
+ b = i;
+ }
+
+ public Bar getBar() {
+ return bar;
+ }
+
+ @Inject(ref="bar")
+ public void setBar(Bar b) {
+ bar = b;
+ }
+
+ public Currency getCurrency() {
+ return currency;
+ }
+
+ public void setCurrency(Currency c) {
+ currency = c;
+ }
+
+ public Date getDate() {
+ return date;
+ }
+
+ public void setDate(Date d) {
+ date = d;
+ }
+
+ public String toString() {
+ return a + " " + b + " " + bar + " " + currency + " " + date;
+ }
+
+ @Init
+ public void init() {
+ System.out.println("======== Initializing Foo =========");
+ initialized = true;
+ }
+
+ @Destroy
+ public void destroy() {
+ System.out.println("======== Destroying Foo =========");
+ destroyed = true;
+ }
+
+ public boolean isInitialized() {
+ return initialized;
+ }
+
+ public boolean isDestroyed() {
+ return destroyed;
+ }
+
+ public void update(Map<String,Object> props) {
+ this.props = props;
+ }
+
+ public Map<String, Object> getProps() {
+ return props;
+ }
+}
+