Author: musachy Date: Tue Apr 14 15:46:42 2009 New Revision: 764839 URL: http://svn.apache.org/viewvc?rev=764839&view=rev Log: Add a couple of tests
Added: struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/test/java/org/apache/struts2/osgi/interceptor/SomeAction.java Modified: struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/test/java/org/apache/struts2/osgi/interceptor/OsgiInterceptorTest.java Modified: struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/test/java/org/apache/struts2/osgi/interceptor/OsgiInterceptorTest.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/test/java/org/apache/struts2/osgi/interceptor/OsgiInterceptorTest.java?rev=764839&r1=764838&r2=764839&view=diff ============================================================================== --- struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/test/java/org/apache/struts2/osgi/interceptor/OsgiInterceptorTest.java (original) +++ struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/test/java/org/apache/struts2/osgi/interceptor/OsgiInterceptorTest.java Tue Apr 14 15:46:42 2009 @@ -3,12 +3,15 @@ import org.easymock.EasyMock; import org.apache.struts2.osgi.OsgiHost; import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; import javax.servlet.ServletContext; import com.opensymphony.xwork2.ActionInvocation; import junit.framework.TestCase; +import java.util.List; + public class OsgiInterceptorTest extends TestCase { public void testBundleContextAware() throws Exception { ServletContext servletContext = EasyMock.createStrictMock(ServletContext.class); @@ -50,4 +53,33 @@ EasyMock.verify(bundleContextAware); } + + public void testServiceAware() throws Exception { + ServletContext servletContext = EasyMock.createStrictMock(ServletContext.class); + BundleContext bundleContext = EasyMock.createStrictMock(BundleContext.class); + ActionInvocation actionInvocation = EasyMock.createStrictMock(ActionInvocation.class); + SomeAction someAction = new SomeAction(); + + //service refs + ServiceReference objectRef = EasyMock.createNiceMock(ServiceReference.class); + Object someObject = new Object(); + + EasyMock.expect(servletContext.getAttribute(OsgiHost.OSGI_BUNDLE_CONTEXT)).andReturn(bundleContext); + EasyMock.expect(actionInvocation.getAction()).andReturn(someAction); + EasyMock.expect(actionInvocation.invoke()).andReturn(""); + EasyMock.expect(bundleContext.getAllServiceReferences(Object.class.getName(), null)).andReturn(new ServiceReference[] {objectRef}); + EasyMock.expect(bundleContext.getService(objectRef)).andReturn(someObject); + + EasyMock.replay(bundleContext); + EasyMock.replay(servletContext); + EasyMock.replay(actionInvocation); + + OsgiInterceptor osgiInterceptor = new OsgiInterceptor(); + osgiInterceptor.setServletContext(servletContext); + osgiInterceptor.intercept(actionInvocation); + + List<Object> objects = someAction.getServices(); + assertNotNull(objects); + assertSame(someObject, objects.get(0)); + } } Added: struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/test/java/org/apache/struts2/osgi/interceptor/SomeAction.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/test/java/org/apache/struts2/osgi/interceptor/SomeAction.java?rev=764839&view=auto ============================================================================== --- struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/test/java/org/apache/struts2/osgi/interceptor/SomeAction.java (added) +++ struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/test/java/org/apache/struts2/osgi/interceptor/SomeAction.java Tue Apr 14 15:46:42 2009 @@ -0,0 +1,36 @@ +/* + * $Id$ + * + * 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.struts2.osgi.interceptor; + +import java.util.List; + +public class SomeAction implements ServiceAware<Object> { + private List<Object> services; + + + public List<Object> getServices() { + return services; + } + + public void setServices(List<Object> services) { + this.services = services; + } +}