Author: pderop
Date: Wed Jun 23 22:04:19 2010
New Revision: 957366
URL: http://svn.apache.org/viewvc?rev=957366&view=rev
Log:
added new test for annotated aspects based on dynamic proxies
Added:
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycledynamicproxy/
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycledynamicproxy/AspectLifecycleTest.java
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycledynamicproxy/ServiceInterface.java
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycledynamicproxy/ServiceProvider.java
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycledynamicproxy/ServiceProviderAspect.java
felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AspectLifecycleWithDynamicProxyAnnotationTest.java
Added:
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycledynamicproxy/AspectLifecycleTest.java
URL:
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycledynamicproxy/AspectLifecycleTest.java?rev=957366&view=auto
==============================================================================
---
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycledynamicproxy/AspectLifecycleTest.java
(added)
+++
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycledynamicproxy/AspectLifecycleTest.java
Wed Jun 23 22:04:19 2010
@@ -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.felix.dm.test.bundle.annotation.aspectlifecycledynamicproxy;
+
+import org.apache.felix.dm.annotation.api.Service;
+import org.apache.felix.dm.annotation.api.ServiceDependency;
+
+/**
+ * Tests an aspect service, and ensure that its lifecycle methods are properly
invoked (init/start/stop/destroy)
+ */
+...@service
+public class AspectLifecycleTest
+{
+ @ServiceDependency
+ void bind(ServiceInterface service)
+ {
+ service.run();
+ }
+
+}
Added:
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycledynamicproxy/ServiceInterface.java
URL:
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycledynamicproxy/ServiceInterface.java?rev=957366&view=auto
==============================================================================
---
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycledynamicproxy/ServiceInterface.java
(added)
+++
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycledynamicproxy/ServiceInterface.java
Wed Jun 23 22:04:19 2010
@@ -0,0 +1,24 @@
+/*
+ * 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.felix.dm.test.bundle.annotation.aspectlifecycledynamicproxy;
+
+public interface ServiceInterface
+{
+ public void run();
+}
Added:
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycledynamicproxy/ServiceProvider.java
URL:
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycledynamicproxy/ServiceProvider.java?rev=957366&view=auto
==============================================================================
---
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycledynamicproxy/ServiceProvider.java
(added)
+++
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycledynamicproxy/ServiceProvider.java
Wed Jun 23 22:04:19 2010
@@ -0,0 +1,35 @@
+/*
+ * 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.felix.dm.test.bundle.annotation.aspectlifecycledynamicproxy;
+
+import org.apache.felix.dm.annotation.api.Service;
+import org.apache.felix.dm.annotation.api.ServiceDependency;
+import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
+
+...@service
+public class ServiceProvider implements ServiceInterface
+{
+ @ServiceDependency(filter = "(test=aspectLifecycle.ServiceProvider)")
+ protected Sequencer m_sequencer;
+
+ public void run()
+ {
+ m_sequencer.step();
+ }
+}
Added:
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycledynamicproxy/ServiceProviderAspect.java
URL:
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycledynamicproxy/ServiceProviderAspect.java?rev=957366&view=auto
==============================================================================
---
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycledynamicproxy/ServiceProviderAspect.java
(added)
+++
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycledynamicproxy/ServiceProviderAspect.java
Wed Jun 23 22:04:19 2010
@@ -0,0 +1,94 @@
+/*
+ * 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.felix.dm.test.bundle.annotation.aspectlifecycledynamicproxy;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import org.apache.felix.dm.annotation.api.AspectService;
+import org.apache.felix.dm.annotation.api.Destroy;
+import org.apache.felix.dm.annotation.api.Init;
+import org.apache.felix.dm.annotation.api.ServiceDependency;
+import org.apache.felix.dm.annotation.api.Start;
+import org.apache.felix.dm.annotation.api.Stop;
+import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
+
+...@aspectservice(ranking = 10, service=ServiceInterface.class,
factoryMethod="create")
+public class ServiceProviderAspect implements InvocationHandler
+{
+ protected boolean m_initCalled;
+ protected Sequencer m_sequencer;
+
+ @ServiceDependency(filter = "(test=aspectLifecycle.ServiceProviderAspect)")
+ protected void bind(Sequencer sequencer)
+ {
+ m_sequencer = sequencer;
+ m_sequencer.step(2);
+ }
+
+ static Object create() {
+ return
Proxy.newProxyInstance(ServiceProviderAspect.class.getClassLoader(),
+ new Class[] { ServiceInterface.class },
+ new ServiceProviderAspect());
+ }
+
+ @Init
+ void init()
+ {
+ m_initCalled = true;
+ }
+
+ @Start
+ void start()
+ {
+ if (!m_initCalled)
+ {
+ throw new IllegalStateException("start method called, but init
method was not called");
+ }
+ m_sequencer.step(3);
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args) throws
Throwable {
+ if (method.getName().equals("toString"))
+ {
+ return "ServiceProviderAspect@" + System.identityHashCode(this);
+ }
+
+ if (! method.getName().equals("run"))
+ {
+ throw new IllegalStateException("wrong invoked method: " + method);
+ }
+ m_sequencer.step(4);
+ return null;
+ }
+
+ @Stop()
+ void stop()
+ {
+ // At this point, the AspectLifecycleTest class has been rebound to
the original ServiceProvider.
+ m_sequencer.step(6);
+ }
+
+ @Destroy
+ void destroy()
+ {
+ m_sequencer.step(7);
+ }
+}
Added:
felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AspectLifecycleWithDynamicProxyAnnotationTest.java
URL:
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AspectLifecycleWithDynamicProxyAnnotationTest.java?rev=957366&view=auto
==============================================================================
---
felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AspectLifecycleWithDynamicProxyAnnotationTest.java
(added)
+++
felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AspectLifecycleWithDynamicProxyAnnotationTest.java
Wed Jun 23 22:04:19 2010
@@ -0,0 +1,87 @@
+/*
+* 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.felix.dm.test.annotation;
+
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.provision;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.service.Service;
+import org.apache.felix.dm.test.BundleGenerator;
+import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+
+/**
+ * Use case: Tests an aspect service implemented as a dynamic proxy, and
ensure that its lifecycle methods are properly invoked
+ * (init/start/stop/destroy methods).
+ */
+...@runwith(JUnit4TestRunner.class)
+public class AspectLifecycleWithDynamicProxyAnnotationTest extends
AnnotationBase
+{
+ @Configuration
+ public static Option[] configuration()
+ {
+ return options(
+ systemProperty("dm.log").value( "true" ),
+ provision(
+
mavenBundle().groupId("org.osgi").artifactId("org.osgi.compendium").version("4.1.0"),
+
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.dependencymanager").versionAsInProject(),
+
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.dependencymanager.runtime").versionAsInProject()),
+ provision(
+ new BundleGenerator()
+ .set(Constants.BUNDLE_SYMBOLICNAME,
"AspectLifecycleDynamicProxyTest")
+ .set("Export-Package",
"org.apache.felix.dm.test.bundle.annotation.sequencer")
+ .set("Private-Package",
"org.apache.felix.dm.test.bundle.annotation.aspectlifecycledynamicproxy")
+ .set("Import-Package", "*")
+ .set("-plugin",
"org.apache.felix.dm.annotation.plugin.bnd.AnnotationPlugin")
+ .build()));
+ }
+
+ @Test
+ public void testAnnotatedAspect(BundleContext context)
+ {
+ DependencyManager m = new DependencyManager(context);
+ // Provide the Sequencer server to the ServiceProvider service
+ Dictionary props = new Hashtable() {{ put("test",
"aspectLifecycle.ServiceProvider"); }};
+
m.add(m.createService().setImplementation(this).setInterface(Sequencer.class.getName(),
props));
+ // Check if the ServiceProvider has been injected in the AspectTest
service.
+ m_ensure.waitForStep(1, 10000);
+ // Provide the Sequencer server to the ServiceProviderAspect service
+ props = new Hashtable() {{ put("test",
"aspectLifecycle.ServiceProviderAspect"); }};
+ Service seq =
m.createService().setImplementation(this).setInterface(Sequencer.class.getName(),
props);
+ m.add(seq);
+ // Check if the AspectTest has been injected with the aspect
+ m_ensure.waitForStep(3, 10000);
+ // Remove the ServiceProviderAspect service
+ m.remove(seq);
+ // And check if the aspect has been called in its stop/destroy methods.
+ m_ensure.waitForStep(7, 10000);
+ }
+}