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 18:47:18 UTC
svn commit: r1075094 [16/17] - in /aries/tags/blueprint-0.1-incubating: ./
blueprint-api/ blueprint-api/src/ blueprint-api/src/main/
blueprint-api/src/main/appended-resources/
blueprint-api/src/main/appended-resources/META-INF/
blueprint-api/src/main/j...
Added: aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/resources/test-wiring.xml
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/resources/test-wiring.xml?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/resources/test-wiring.xml (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/resources/test-wiring.xml Sun Feb 27 17:47:08 2011
@@ -0,0 +1,135 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
+ default-availability="mandatory" >
+
+ <type-converters>
+ <bean id="converter1" class="org.apache.aries.blueprint.pojos.ConverterA">
+ <property name="bundle" ref="blueprintBundleContext" />
+ </bean>
+ </type-converters>
+
+ <service id="service1" ref="pojoB" interface="org.apache.aries.blueprint.pojos.PojoB">
+ <service-properties>
+ <entry key="key1" value="value1"/>
+ <entry key="key2" value="value2"/>
+ </service-properties>
+ </service>
+
+ <bean id="pojoC" class="org.apache.aries.blueprint.pojos.PojoB" scope = "prototype">
+ <property name="uri" value="urn:myuri" />
+ <property name="objects">
+ <list>
+ <value>list value</value>
+ </list>
+ </property>
+ </bean>
+
+ <bean id="pojoB" class="org.apache.aries.blueprint.pojos.PojoB" init-method = "init" destroy-method = "destroy" >
+ <property name="uri" value="urn:myuri" />
+ </bean>
+
+ <bean id="pojoA" class="org.apache.aries.blueprint.pojos.PojoA">
+ <property name="pojob" ref="pojoB"/>
+ <property name="map">
+ <map>
+ <entry key="key" value="val"/>
+ <entry key-ref="pojoB" value-ref="pojoB" />
+ <entry>
+ <key><value type="java.lang.Integer">5</value></key>
+ <value type="java.net.URI">http://geronimo.apache.org</value>
+ </entry>
+ </map>
+ </property>
+ <property name="set">
+ <set value-type="java.net.URI">
+ <value type="java.lang.String">set value</value>
+ <ref component-id="pojoB" />
+ <value>http://geronimo.apache.org</value>
+ </set>
+ </property>
+ <property name="list">
+ <list>
+ <value>list value</value>
+ <ref component-id="pojoC" />
+ <value type="java.lang.Integer">55</value>
+ <value type="java.net.URI">http://geronimo.apache.org</value>
+ <ref component-id="pojoC" />
+ </list>
+ </property>
+ <property name="props">
+ <props>
+ <prop key="key1" value="value1" />
+ <prop key="2" value="value2" />
+ <prop key="foo">bar</prop>
+ </props>
+ </property>
+ <property name="array">
+ <array>
+ <value>list value</value>
+ <ref component-id="pojoB" />
+ <value type="java.lang.Integer">55</value>
+ <value type="java.net.URI">http://geronimo.apache.org</value>
+ </array>
+ </property>
+ <property name="intArray">
+ <array>
+ <value>1</value>
+ <value>50</value>
+ <value>100</value>
+ </array>
+ </property>
+ <property name="numberArray">
+ <array>
+ <value type="int">1</value>
+ <value type="java.math.BigInteger">50</value>
+ <value type="java.lang.Long">100</value>
+ <value type="int">200</value>
+ </array>
+ </property>
+ <property name="number">
+ <value type="java.math.BigInteger">10</value>
+ </property>
+ </bean>
+
+ <bean id="compound" class="org.apache.aries.blueprint.pojos.PojoB">
+ <property name="bean.name" value="hello bean property" />
+ </bean>
+
+ <bean id="goodIdRef" class="org.apache.aries.blueprint.pojos.BeanD">
+ <property name="name">
+ <idref component-id="pojoA"/>
+ </property>
+ </bean>
+
+ <bean id="FITestBean" ext:field-injection="true" class="org.apache.aries.blueprint.pojos.FITestBean">
+ <property name="attr" value="value" />
+ <property name="upperCaseAttr" value="is_lower" />
+ <property name="bean.name" value="aName" />
+ </bean>
+
+ <bean id="FIFailureTestBean" class="org.apache.aries.blueprint.pojos.FITestBean">
+ <property name="attr" value="value" />
+ </bean>
+
+ <bean id="FIFailureTest2Bean" class="org.apache.aries.blueprint.pojos.FITestBean" ext:field-injection="false">
+ <property name="attr" value="value" />
+ </bean>
+
+</blueprint>
\ No newline at end of file
Added: aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/resources/test.xml
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/resources/test.xml?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/resources/test.xml (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/resources/test.xml Sun Feb 27 17:47:08 2011
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ default-availability="mandatory">
+
+ <description>
+ This is a parsing test application
+ </description>
+
+ <type-converters>
+ <bean class="org.apache.aries.blueprint.pojos.ConverterA"/>
+ <ref component-id="converterB"/>
+ </type-converters>
+
+ <bean id="pojoA" class="org.apache.aries.blueprint.pojos.PojoA">
+ <property name="pojob" ref="pojoB"/>
+ </bean>
+
+ <bean id="pojoAcns" class="org.apache.aries.blueprint.pojos.PojoA">
+ <argument ref="pojoB"/>
+ </bean>
+
+ <bean id="pojoB" class="org.apache.aries.blueprint.pojos.PojoB">
+ <property name="uri" value="urn:myuri"/>
+ </bean>
+
+ <bean id="pojoBcns" class="org.apache.aries.blueprint.pojos.PojoB">
+ <argument value="urn:myuri"/>
+ </bean>
+
+ <bean id="converterB" class="org.apache.aries.blueprint.pojos.ConverterB"/>
+
+ <reference id="refA" filter="(key=prop)" interface="org.apache.aries.blueprint.pojos.InterfaceA"/>
+
+ <reference id="refB" availability="optional">
+ <interfaces>
+ <value>org.apache.aries.blueprint.pojos.InterfaceA</value>
+ </interfaces>
+ <listener ref="listenerA" bind-method="bind" unbind-method="unbind"/>
+ </reference>
+
+ <service interface="org.apache.aries.blueprint.pojos.InterfaceA" ref="pojoA"/>
+
+ <bean id="listenerA" class="org.apache.aries.blueprint.pojos.ListenerA"/>
+
+ <reference-list availability="optional" member-type="service-object"/>
+
+</blueprint>
\ No newline at end of file
Added: aries/tags/blueprint-0.1-incubating/blueprint-itests/pom.xml
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-itests/pom.xml?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-itests/pom.xml (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-itests/pom.xml Sun Feb 27 17:47:08 2011
@@ -0,0 +1,198 @@
+<!--
+ 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.1-incubating</version>
+ </parent>
+
+ <artifactId>org.apache.aries.blueprint.itests</artifactId>
+ <name>Apache Aries Blueprint iTests</name>
+ <description>
+ Integration tests using the standalone blueprint-bundle for the implementation
+ and blueprint-sample for the blueprint application to be tested.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse</groupId>
+ <artifactId>osgi</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.blueprint</groupId>
+ <artifactId>org.apache.aries.blueprint</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries</groupId>
+ <artifactId>org.apache.aries.util</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.blueprint</groupId>
+ <artifactId>org.apache.aries.blueprint.sample</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.blueprint</groupId>
+ <artifactId>org.apache.aries.blueprint.testbundlea</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.blueprint</groupId>
+ <artifactId>org.apache.aries.blueprint.testbundleb</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-container-default</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-junit-extender-impl</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.runner</groupId>
+ <artifactId>pax-runner-no-jcl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.configadmin</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.logging</groupId>
+ <artifactId>pax-logging-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.logging</groupId>
+ <artifactId>pax-logging-service</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.url</groupId>
+ <artifactId>pax-url-mvn</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicemix.bundles</groupId>
+ <artifactId>org.apache.servicemix.bundles.cglib</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>asm</groupId>
+ <artifactId>asm-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <forkMode>pertest</forkMode>
+ <excludes>
+ <exclude>**/*$*</exclude>
+ <exclude>**/Abstract*.java</exclude>
+ </excludes>
+ <includes>
+ <include>**/Test*.java</include>
+ <include>**/*Test.java</include>
+ </includes>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>maven-paxexam-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate-config</id>
+ <goals>
+ <goal>generate-depends-file</goal>
+ </goals>
+ <configuration>
+ <outputFile>${project.build.directory}/test-classes/META-INF/maven/dependencies.properties</outputFile>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>ci-build-profile</id>
+ <activation>
+ <property>
+ <name>maven.repo.local</name>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <!--
+ when the local repo location has been specified, we need to pass
+ on this information to PAX mvn url
+ -->
+ <argLine>-Dorg.ops4j.pax.url.mvn.localRepository=${maven.repo.local}</argLine>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+</project>
Added: aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/AbstractIntegrationTest.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/AbstractIntegrationTest.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/AbstractIntegrationTest.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/AbstractIntegrationTest.java Sun Feb 27 17:47:08 2011
@@ -0,0 +1,278 @@
+/*
+ * 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 java.io.*;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Currency;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.aries.blueprint.sample.Bar;
+import org.apache.aries.blueprint.sample.Foo;
+import org.junit.After;
+import org.junit.Before;
+import org.ops4j.pax.exam.CoreOptions;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
+import org.ops4j.pax.exam.Inject;
+import org.ops4j.pax.exam.Option;
+import static org.ops4j.pax.exam.OptionUtils.combine;
+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.Filter;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.service.blueprint.container.BlueprintContainer;
+import org.osgi.util.tracker.ServiceTracker;
+
+public abstract class AbstractIntegrationTest {
+
+ public static final long DEFAULT_TIMEOUT = 30000;
+
+ private List<ServiceTracker> srs;
+
+ @Before
+ public void setUp() {
+ srs = new ArrayList<ServiceTracker>();
+ }
+
+ @After
+ public void tearDown() throws Exception{
+ for (ServiceTracker st : srs) {
+ if (st != null) {
+ st.close();
+ }
+ }
+ }
+
+ @Inject
+ protected BundleContext bundleContext;
+
+ protected BlueprintContainer getBlueprintContainerForBundle(String symbolicName) throws Exception {
+ return getBlueprintContainerForBundle(symbolicName, DEFAULT_TIMEOUT);
+ }
+
+ protected BlueprintContainer getBlueprintContainerForBundle(String symbolicName, long timeout) throws Exception {
+ return getOsgiService(BlueprintContainer.class, "(osgi.blueprint.container.symbolicname=" + symbolicName + ")", timeout);
+ }
+
+ protected BlueprintContainer getBlueprintContainerForBundle(BundleContext bc, String symbolicName, long timeout) throws Exception {
+ return getOsgiService(bc, BlueprintContainer.class, "(osgi.blueprint.container.symbolicname=" + symbolicName + ")", timeout);
+ }
+
+ protected <T> T getOsgiService(Class<T> type, long timeout) {
+ return getOsgiService(type, null, timeout);
+ }
+
+ protected <T> T getOsgiService(Class<T> type) {
+ return getOsgiService(type, null, DEFAULT_TIMEOUT);
+ }
+
+ protected <T> T getOsgiService(BundleContext bc, Class<T> type, String filter, long timeout) {
+ ServiceTracker tracker = null;
+ try {
+ String flt;
+ if (filter != null) {
+ if (filter.startsWith("(")) {
+ flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")" + filter + ")";
+ } else {
+ flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")(" + filter + "))";
+ }
+ } else {
+ flt = "(" + Constants.OBJECTCLASS + "=" + type.getName() + ")";
+ }
+ Filter osgiFilter = FrameworkUtil.createFilter(flt);
+ tracker = new ServiceTracker(bc == null ? bundleContext : bc, osgiFilter, null);
+ tracker.open();
+
+ // add tracker to the list of trackers we close at tear down
+ srs.add(tracker);
+ Object svc = type.cast(tracker.waitForService(timeout));
+ if (svc == null) {
+ throw new RuntimeException("Gave up waiting for service " + flt);
+ }
+ return type.cast(svc);
+ } catch (InvalidSyntaxException e) {
+ throw new IllegalArgumentException("Invalid filter", e);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ protected <T> T getOsgiService(Class<T> type, String filter, long timeout) {
+ return getOsgiService(null, type, filter, timeout);
+ }
+
+ protected Bundle installBundle(String groupId, String artifactId) throws Exception {
+ MavenArtifactProvisionOption mvnUrl = mavenBundle(groupId, artifactId);
+ return bundleContext.installBundle(mvnUrl.getURL());
+ }
+
+ protected Bundle getInstalledBundle(String symbolicName) {
+ for (Bundle b : bundleContext.getBundles()) {
+ if (b.getSymbolicName().equals(symbolicName)) {
+ return b;
+ }
+ }
+ return null;
+ }
+
+ public static MavenArtifactProvisionOption mavenBundle(String groupId, String artifactId) {
+ return CoreOptions.mavenBundle().groupId(groupId).artifactId(artifactId).versionAsInProject();
+ }
+
+ public static MavenArtifactProvisionOption mavenBundleInTest(String groupId, String artifactId) {
+ return CoreOptions.mavenBundle().groupId(groupId).artifactId(artifactId).version(getArtifactVersion(groupId, artifactId));
+ }
+
+ //TODO getArtifactVersion and getFileFromClasspath are borrowed and modified from pax-exam. They should be moved back ASAP.
+ public static String getArtifactVersion( final String groupId,
+ final String artifactId )
+ {
+ final Properties dependencies = new Properties();
+ try
+ {
+ InputStream in = getFileFromClasspath("META-INF/maven/dependencies.properties");
+ try {
+ dependencies.load(in);
+ } finally {
+ in.close();
+ }
+ final String version = dependencies.getProperty( groupId + "/" + artifactId + "/version" );
+ if( version == null )
+ {
+ throw new RuntimeException(
+ "Could not resolve version. Do you have a dependency for " + groupId + "/" + artifactId
+ + " in your maven project?"
+ );
+ }
+ return version;
+ }
+ catch( IOException e )
+ {
+ // TODO throw a better exception
+ throw new RuntimeException(
+ "Could not resolve version. Did you configured the plugin in your maven project?"
+ + "Or maybe you did not run the maven build and you are using an IDE?"
+ );
+ }
+ }
+
+ private static InputStream getFileFromClasspath( final String filePath )
+ throws FileNotFoundException
+ {
+ try
+ {
+ URL fileURL = AbstractIntegrationTest.class.getClassLoader().getResource( filePath );
+ if( fileURL == null )
+ {
+ throw new FileNotFoundException( "File [" + filePath + "] could not be found in classpath" );
+ }
+ return fileURL.openStream();
+ }
+ catch (IOException e)
+ {
+ throw new FileNotFoundException( "File [" + filePath + "] could not be found: " + e.getMessage() );
+ }
+ }
+
+
+ protected static Option[] updateOptions(Option[] options) {
+ // We need to add pax-exam-junit here when running with the ibm
+ // jdk to avoid the following exception during the test run:
+ // ClassNotFoundException: org.ops4j.pax.exam.junit.Configuration
+ if ("IBM Corporation".equals(System.getProperty("java.vendor"))) {
+ Option[] ibmOptions = options(
+ wrappedBundle(mavenBundle("org.ops4j.pax.exam", "pax-exam-junit"))
+ );
+ options = combine(ibmOptions, options);
+ }
+
+ return options;
+ }
+
+ protected void testBlueprintContainer(Bundle bundle) throws Exception {
+ testBlueprintContainer(bundleContext, bundle);
+ }
+
+
+ protected void testBlueprintContainer(BundleContext bc, Bundle bundle) throws Exception {
+ BlueprintContainer blueprintContainer = getBlueprintContainerForBundle(
+ bc == null ? bundleContext : bc, "org.apache.aries.blueprint.sample",
+ 5000);
+ assertNotNull(blueprintContainer);
+
+ Object obj = blueprintContainer.getComponentInstance("bar");
+ assertNotNull(obj);
+ assertEquals(Bar.class, obj.getClass());
+ Bar bar = (Bar) obj;
+ assertNotNull(bar.getContext());
+ assertEquals("Hello FooBar", bar.getValue());
+ assertNotNull(bar.getList());
+ assertEquals(2, bar.getList().size());
+ assertEquals("a list element", bar.getList().get(0));
+ assertEquals(Integer.valueOf(5), bar.getList().get(1));
+ obj = blueprintContainer.getComponentInstance("foo");
+ assertNotNull(obj);
+ assertEquals(Foo.class, obj.getClass());
+ Foo foo = (Foo) obj;
+ assertEquals(5, foo.getA());
+ assertEquals(10, foo.getB());
+ assertSame(bar, foo.getBar());
+ assertEquals(Currency.getInstance("PLN"), foo.getCurrency());
+ assertEquals(new SimpleDateFormat("yyyy.MM.dd").parse("2009.04.17"),
+ foo.getDate());
+
+ assertTrue(foo.isInitialized());
+ assertFalse(foo.isDestroyed());
+
+ obj = getOsgiService(bc == null ? bundleContext : bc, Foo.class, null, 5000);
+ assertNotNull(obj);
+ assertSame(foo, obj);
+
+ bundle.stop();
+
+ Thread.sleep(1000);
+
+ try {
+ blueprintContainer = getBlueprintContainerForBundle(bc == null ? bundleContext : bc,
+ "org.apache.aries.blueprint.sample", 1);
+ fail("BlueprintContainer should have been unregistered");
+ } catch (Exception e) {
+ // Expected, as the module container should have been unregistered
+ }
+
+ assertTrue(foo.isInitialized());
+ assertTrue(foo.isDestroyed());
+ }
+
+}
Added: aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/AbstractMultiBundleTest.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/AbstractMultiBundleTest.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/AbstractMultiBundleTest.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/AbstractMultiBundleTest.java Sun Feb 27 17:47:08 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.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainer2BTCustomizerTest.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainer2BTCustomizerTest.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainer2BTCustomizerTest.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainer2BTCustomizerTest.java Sun Feb 27 17:47:08 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.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainer2Test.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainer2Test.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainer2Test.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainer2Test.java Sun Feb 27 17:47:08 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.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainerBTCustomizerTest.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainerBTCustomizerTest.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainerBTCustomizerTest.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainerBTCustomizerTest.java Sun Feb 27 17:47:08 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.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainerTest.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainerTest.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainerTest.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainerTest.java Sun Feb 27 17:47:08 2011
@@ -0,0 +1,95 @@
+/*
+ * 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 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);
+ }
+
+ @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.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/MultiBundleWithAsmTest.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/MultiBundleWithAsmTest.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/MultiBundleWithAsmTest.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/MultiBundleWithAsmTest.java Sun Feb 27 17:47:08 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.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/MultiBundleWithCgLibTest.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/MultiBundleWithCgLibTest.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/MultiBundleWithCgLibTest.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/MultiBundleWithCgLibTest.java Sun Feb 27 17:47:08 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.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestConfigAdmin.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestConfigAdmin.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestConfigAdmin.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestConfigAdmin.java Sun Feb 27 17:47:08 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.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestReferences.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestReferences.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestReferences.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestReferences.java Sun Feb 27 17:47:08 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.1-incubating/blueprint-itests/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/resources/log4j.properties?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/resources/log4j.properties (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-itests/src/test/resources/log4j.properties Sun Feb 27 17:47:08 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