You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by da...@apache.org on 2007/09/30 23:03:40 UTC
svn commit: r580788 - in
/cocoon/whiteboard/osgi/core/cocoon-spring-osgi/cocoon-spring-osgi-integration-test/src/test:
java/org/apache/cocoon/springosgi/test/FactoryExportTest.java
resources/org/apache/cocoon/springosgi/test/simple-service.MF
Author: danielf
Date: Sun Sep 30 14:03:40 2007
New Revision: 580788
URL: http://svn.apache.org/viewvc?rev=580788&view=rev
Log:
Test cases for the factory export. All tests succeeds.
Added:
cocoon/whiteboard/osgi/core/cocoon-spring-osgi/cocoon-spring-osgi-integration-test/src/test/java/org/apache/cocoon/springosgi/test/FactoryExportTest.java (with props)
Modified:
cocoon/whiteboard/osgi/core/cocoon-spring-osgi/cocoon-spring-osgi-integration-test/src/test/resources/org/apache/cocoon/springosgi/test/simple-service.MF
Added: cocoon/whiteboard/osgi/core/cocoon-spring-osgi/cocoon-spring-osgi-integration-test/src/test/java/org/apache/cocoon/springosgi/test/FactoryExportTest.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/osgi/core/cocoon-spring-osgi/cocoon-spring-osgi-integration-test/src/test/java/org/apache/cocoon/springosgi/test/FactoryExportTest.java?rev=580788&view=auto
==============================================================================
--- cocoon/whiteboard/osgi/core/cocoon-spring-osgi/cocoon-spring-osgi-integration-test/src/test/java/org/apache/cocoon/springosgi/test/FactoryExportTest.java (added)
+++ cocoon/whiteboard/osgi/core/cocoon-spring-osgi/cocoon-spring-osgi-integration-test/src/test/java/org/apache/cocoon/springosgi/test/FactoryExportTest.java Sun Sep 30 14:03:40 2007
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2006 the original author or authors.
+ *
+ * Licensed 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.cocoon.springosgi.test;
+
+import org.apache.cocoon.springosgi.simpleservice.SimpleService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.springframework.beans.factory.SmartFactoryBean;
+import org.springframework.osgi.test.AbstractConfigurableBundleCreatorTests;
+
+/**
+ * @version $Id$
+ */
+public class FactoryExportTest extends AbstractConfigurableBundleCreatorTests {
+
+ private String[] configLocations = new String[]{"classpath:org/apache/cocoon/springosgi/test/factory-import.xml"};
+
+ /* (non-Javadoc)
+ * @see org.springframework.test.AbstractSingleSpringContextTests#getConfigLocations()
+ */
+// protected String[] getConfigLocations() {
+// return this.configLocations;
+// }
+
+ protected String getManifestLocation() {
+ return "classpath:org/apache/cocoon/springosgi/test/simple-service.MF";
+ }
+
+ protected String[] getBundles() {
+ return new String[] {
+ localMavenArtifact("org.apache.cocoon", "cocoon-spring-osgi-simple-service","1.0.0-SNAPSHOT"),
+ localMavenArtifact("org.apache.cocoon", "cocoon-spring-osgi-impl","1.0.0-SNAPSHOT")
+ };
+ }
+
+ public void testOSGiStartedOk() {
+ BundleContext bundleContext = getBundleContext();
+ assertNotNull(bundleContext);
+ }
+
+ public void testFactoryExport() throws Exception {
+ waitOnContextCreation("org.apache.cocoon.cocoon-spring-osgi-simple-service");
+ BundleContext context = getBundleContext();
+ ServiceReference[] refs =
+ context.getServiceReferences(SmartFactoryBean.class.getName(), "(org.springframework.osgi.beanname=simpleService.fe1)");
+ assertNotNull("Service References is null", refs);
+ assertEquals(1, refs.length);
+ ServiceReference ref = refs[0];
+ logger.error(ref.toString());
+ try {
+ SmartFactoryBean factoryBean = (SmartFactoryBean) context.getService(ref);
+ assertNotNull("Cannot find the service", factoryBean);
+ assertEquals(true, factoryBean.isSingleton());
+ assertEquals(false, factoryBean.isPrototype());
+ SimpleService service = (SimpleService) factoryBean.getObject();
+ assertNotNull("Cannot create the bean", service);
+ assertEquals("fe1", service.stringValue());
+ } finally {
+ context.ungetService(ref);
+ }
+ }
+
+ public void testPrototypeFactoryExport() throws Exception {
+ waitOnContextCreation("org.apache.cocoon.cocoon-spring-osgi-simple-service");
+ BundleContext context = getBundleContext();
+ ServiceReference[] refs =
+ context.getServiceReferences(SmartFactoryBean.class.getName(), "(org.springframework.osgi.beanname=simpleService.fe2)");
+ assertNotNull("Service References is null", refs);
+ assertEquals(1, refs.length);
+ ServiceReference ref = refs[0];
+ logger.error(ref.toString());
+ try {
+ SmartFactoryBean factoryBean = (SmartFactoryBean) context.getService(ref);
+ assertNotNull("Cannot find the service", factoryBean);
+ assertEquals(false, factoryBean.isSingleton());
+ assertEquals(true, factoryBean.isPrototype());
+ SimpleService service = (SimpleService) factoryBean.getObject();
+ assertNotNull("Cannot create the bean", service);
+ assertEquals("fe2", service.stringValue());
+ SimpleService service2 = (SimpleService) factoryBean.getObject();
+ assertNotNull("Cannot create the bean", service2);
+ assertEquals("fe2", service2.stringValue());
+ assertNotSame(service, service2);
+ } finally {
+ context.ungetService(ref);
+ }
+ }
+
+}
Propchange: cocoon/whiteboard/osgi/core/cocoon-spring-osgi/cocoon-spring-osgi-integration-test/src/test/java/org/apache/cocoon/springosgi/test/FactoryExportTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/whiteboard/osgi/core/cocoon-spring-osgi/cocoon-spring-osgi-integration-test/src/test/java/org/apache/cocoon/springosgi/test/FactoryExportTest.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: cocoon/whiteboard/osgi/core/cocoon-spring-osgi/cocoon-spring-osgi-integration-test/src/test/resources/org/apache/cocoon/springosgi/test/simple-service.MF
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/osgi/core/cocoon-spring-osgi/cocoon-spring-osgi-integration-test/src/test/resources/org/apache/cocoon/springosgi/test/simple-service.MF?rev=580788&r1=580787&r2=580788&view=diff
==============================================================================
--- cocoon/whiteboard/osgi/core/cocoon-spring-osgi/cocoon-spring-osgi-integration-test/src/test/resources/org/apache/cocoon/springosgi/test/simple-service.MF (original)
+++ cocoon/whiteboard/osgi/core/cocoon-spring-osgi/cocoon-spring-osgi-integration-test/src/test/resources/org/apache/cocoon/springosgi/test/simple-service.MF Sun Sep 30 14:03:40 2007
@@ -6,6 +6,7 @@
Import-Package: junit.framework,
org.apache.commons.logging,
org.osgi.framework,
+ org.springframework.beans.factory,
org.springframework.context,
org.springframework.core.io,
org.springframework.osgi.test,