cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r953778 - in /cayenne/main/trunk/framework: cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/mock/ cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/spi/ cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configu...
Date Fri, 11 Jun 2010 17:17:10 GMT
Author: aadamchik
Date: Fri Jun 11 17:17:09 2010
New Revision: 953778

URL: http://svn.apache.org/viewvc?rev=953778&view=rev
Log:
removing scope handling code from DataDomainProvider

+ unit tests showing that provider binding works with scopes

Added:
    cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/mock/MockImplementation1_Provider.java
Modified:
    cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/spi/DefaultInjectorScopeTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/DataDomainProviderTest.java

Added: cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/mock/MockImplementation1_Provider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/mock/MockImplementation1_Provider.java?rev=953778&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/mock/MockImplementation1_Provider.java
(added)
+++ cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/mock/MockImplementation1_Provider.java
Fri Jun 11 17:17:09 2010
@@ -0,0 +1,29 @@
+/*****************************************************************
+ *   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.cayenne.di.mock;
+
+import org.apache.cayenne.ConfigurationException;
+import org.apache.cayenne.di.Provider;
+
+public class MockImplementation1_Provider implements Provider<MockInterface1> {
+
+    public MockInterface1 get() throws ConfigurationException {
+        return new MockImplementation1();
+    }
+}

Modified: cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/spi/DefaultInjectorScopeTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/spi/DefaultInjectorScopeTest.java?rev=953778&r1=953777&r2=953778&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/spi/DefaultInjectorScopeTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/spi/DefaultInjectorScopeTest.java
Fri Jun 11 17:17:09 2010
@@ -25,11 +25,12 @@ import org.apache.cayenne.di.Module;
 import org.apache.cayenne.di.OnScopeEnd;
 import org.apache.cayenne.di.mock.MockImplementation1;
 import org.apache.cayenne.di.mock.MockImplementation1_EventAnnotations;
+import org.apache.cayenne.di.mock.MockImplementation1_Provider;
 import org.apache.cayenne.di.mock.MockInterface1;
 
 public class DefaultInjectorScopeTest extends TestCase {
 
-    public void testDefaultScope() {
+    public void testDefaultScope_IsSingleton() {
 
         Module module = new Module() {
 
@@ -131,6 +132,53 @@ public class DefaultInjectorScopeTest ex
         assertTrue(MockImplementation1_EventAnnotations.shutdown1);
         assertTrue(MockImplementation1_EventAnnotations.shutdown2);
         assertTrue(MockImplementation1_EventAnnotations.shutdown3);
+    }
+
+    public void testSingletonScope_WithProvider() {
+
+        Module module = new Module() {
 
+            public void configure(Binder binder) {
+                binder.bind(MockInterface1.class).toProvider(
+                        MockImplementation1_Provider.class).inSingletonScope();
+            }
+        };
+
+        DefaultInjector injector = new DefaultInjector(module);
+
+        MockInterface1 instance1 = injector.getInstance(MockInterface1.class);
+        MockInterface1 instance2 = injector.getInstance(MockInterface1.class);
+        MockInterface1 instance3 = injector.getInstance(MockInterface1.class);
+
+        assertNotNull(instance1);
+        assertNotNull(instance2);
+        assertNotNull(instance3);
+
+        assertSame(instance1, instance2);
+        assertSame(instance2, instance3);
+    }
+
+    public void testNoScope_WithProvider() {
+
+        Module module = new Module() {
+
+            public void configure(Binder binder) {
+                binder.bind(MockInterface1.class).toProvider(
+                        MockImplementation1_Provider.class).withoutScope();
+            }
+        };
+
+        DefaultInjector injector = new DefaultInjector(module);
+
+        MockInterface1 instance1 = injector.getInstance(MockInterface1.class);
+        MockInterface1 instance2 = injector.getInstance(MockInterface1.class);
+        MockInterface1 instance3 = injector.getInstance(MockInterface1.class);
+
+        assertNotNull(instance1);
+        assertNotNull(instance2);
+        assertNotNull(instance3);
+
+        assertNotSame(instance1, instance2);
+        assertNotSame(instance2, instance3);
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java?rev=953778&r1=953777&r2=953778&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java
Fri Jun 11 17:17:09 2010
@@ -76,34 +76,21 @@ public class DataDomainProvider implemen
     @Inject
     protected Injector injector;
 
-    protected volatile DataDomain dataDomain;
-
     public DataDomain get() throws ConfigurationException {
 
-        if (dataDomain == null) {
-            synchronized (this) {
-                if (dataDomain == null) {
-
-                    try {
-                        createDataChannel();
-                    }
-                    catch (ConfigurationException e) {
-                        throw e;
-                    }
-                    catch (Exception e) {
-                        throw new DataDomainLoadException(
-                                "Error loading DataChannel: '%s'",
-                                e,
-                                e.getMessage());
-                    }
-                }
-            }
+        try {
+            return createDataDomain();
+        }
+        catch (ConfigurationException e) {
+            throw e;
+        }
+        catch (Exception e) {
+            throw new DataDomainLoadException("Error loading DataChannel: '%s'", e, e
+                    .getMessage());
         }
-
-        return dataDomain;
     }
 
-    protected void createDataChannel() throws Exception {
+    protected DataDomain createDataDomain() throws Exception {
         String configurationLocation = configurationProperties
                 .get(RuntimeProperties.CONFIGURATION_LOCATION);
 
@@ -208,6 +195,6 @@ public class DataDomainProvider implemen
             dataDomain.addNode(dataNode);
         }
 
-        this.dataDomain = dataDomain;
+        return dataDomain;
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/DataDomainProviderTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/DataDomainProviderTest.java?rev=953778&r1=953777&r2=953778&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/DataDomainProviderTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/DataDomainProviderTest.java
Fri Jun 11 17:17:09 2010
@@ -110,7 +110,7 @@ public class DataDomainProviderTest exte
                 Collections.singletonMap(
                         RuntimeProperties.CONFIGURATION_LOCATION,
                         testConfigName));
-        
+
         final EventManager eventManager = new MockEventManager();
 
         Module testModule = new Module() {
@@ -156,11 +156,6 @@ public class DataDomainProviderTest exte
 
         assertTrue(channel instanceof DataDomain);
 
-        assertSame(
-                "DataDomainProvider must return the same instance of DataChannel on subsequent
calls",
-                channel,
-                provider.get());
-
         DataDomain domain = (DataDomain) channel;
         assertSame(eventManager, domain.getEventManager());
         assertEquals(2, domain.getDataMaps().size());



Mime
View raw message