cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [1/2] cayenne git commit: Tests for ClientRuntimeBuilder + minor fix for uninitialized properties
Date Fri, 28 Apr 2017 07:46:47 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master 3b22b4757 -> 87c9c8f4b


Tests for ClientRuntimeBuilder + minor fix for uninitialized properties


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/231069ac
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/231069ac
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/231069ac

Branch: refs/heads/master
Commit: 231069ac975775a6caaa1567cc4930e5738a1faa
Parents: 3b22b47
Author: Nikita Timofeev <stariy95@gmail.com>
Authored: Fri Apr 28 10:36:12 2017 +0300
Committer: Nikita Timofeev <stariy95@gmail.com>
Committed: Fri Apr 28 10:36:12 2017 +0300

----------------------------------------------------------------------
 .../rop/client/ClientLocalRuntime.java          |   2 +-
 .../configuration/rop/client/ClientModule.java  |   7 +-
 .../rop/client/ClientRuntimeBuilder.java        |   2 +-
 .../rop/client/ClientRuntimeBuilderTest.java    | 101 +++++++++++++++++++
 4 files changed, 108 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/231069ac/cayenne-client/src/main/java/org/apache/cayenne/configuration/rop/client/ClientLocalRuntime.java
----------------------------------------------------------------------
diff --git a/cayenne-client/src/main/java/org/apache/cayenne/configuration/rop/client/ClientLocalRuntime.java
b/cayenne-client/src/main/java/org/apache/cayenne/configuration/rop/client/ClientLocalRuntime.java
index af1ddd5..27cf9b6 100644
--- a/cayenne-client/src/main/java/org/apache/cayenne/configuration/rop/client/ClientLocalRuntime.java
+++ b/cayenne-client/src/main/java/org/apache/cayenne/configuration/rop/client/ClientLocalRuntime.java
@@ -43,7 +43,7 @@ import static java.util.Arrays.asList;
 public class ClientLocalRuntime extends ClientRuntime {
 
     /**
-     * Moved to {@link ClientRuntime#CLIENT_SERVER_CHANNEL_KEY}
+     * @since 4.0 moved to {@link ClientRuntime#CLIENT_SERVER_CHANNEL_KEY}
      */
     public static final String CLIENT_SERVER_CHANNEL_KEY = "client-server-channel";
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/231069ac/cayenne-client/src/main/java/org/apache/cayenne/configuration/rop/client/ClientModule.java
----------------------------------------------------------------------
diff --git a/cayenne-client/src/main/java/org/apache/cayenne/configuration/rop/client/ClientModule.java
b/cayenne-client/src/main/java/org/apache/cayenne/configuration/rop/client/ClientModule.java
index efae1c8..690ed2c 100644
--- a/cayenne-client/src/main/java/org/apache/cayenne/configuration/rop/client/ClientModule.java
+++ b/cayenne-client/src/main/java/org/apache/cayenne/configuration/rop/client/ClientModule.java
@@ -23,12 +23,12 @@ import java.util.Map;
 import org.apache.cayenne.DataChannel;
 import org.apache.cayenne.cache.MapQueryCacheProvider;
 import org.apache.cayenne.cache.QueryCache;
-import org.apache.cayenne.configuration.Constants;
 import org.apache.cayenne.configuration.DefaultRuntimeProperties;
 import org.apache.cayenne.configuration.ObjectContextFactory;
 import org.apache.cayenne.configuration.RuntimeProperties;
 import org.apache.cayenne.configuration.server.ServerModule;
 import org.apache.cayenne.di.Binder;
+import org.apache.cayenne.di.MapBuilder;
 import org.apache.cayenne.di.Module;
 import org.apache.cayenne.event.DefaultEventManager;
 import org.apache.cayenne.event.EventManager;
@@ -74,10 +74,13 @@ public class ClientModule implements Module {
     @SuppressWarnings("deprecation")
     public void configure(Binder binder) {
 
+        // Contribute always to create binding
+        MapBuilder<String> propertiesBuilder = ServerModule.contributeProperties(binder);
+
         // expose user-provided ROP properties as the main properties map
         // binding here is left only for backward compatibility, should go away with the
deprecated code.
         if(properties != null) {
-            ServerModule.contributeProperties(binder).putAll(properties);
+            propertiesBuilder.putAll(properties);
         }
 
         binder.bind(ObjectContextFactory.class).to(CayenneContextFactory.class);

http://git-wip-us.apache.org/repos/asf/cayenne/blob/231069ac/cayenne-client/src/main/java/org/apache/cayenne/configuration/rop/client/ClientRuntimeBuilder.java
----------------------------------------------------------------------
diff --git a/cayenne-client/src/main/java/org/apache/cayenne/configuration/rop/client/ClientRuntimeBuilder.java
b/cayenne-client/src/main/java/org/apache/cayenne/configuration/rop/client/ClientRuntimeBuilder.java
index 743da78..d8c2aef 100644
--- a/cayenne-client/src/main/java/org/apache/cayenne/configuration/rop/client/ClientRuntimeBuilder.java
+++ b/cayenne-client/src/main/java/org/apache/cayenne/configuration/rop/client/ClientRuntimeBuilder.java
@@ -63,7 +63,7 @@ public class ClientRuntimeBuilder {
 
     /**
      * Disables DI module auto-loading. By default auto-loading is enabled based on
-     * {@link org.apache.cayenne.di.spi.ModuleLoader} service provider interface.
+     * {@link CayenneClientModuleProvider} service provider interface.
      * If you decide to disable auto-loading, make sure you provide all the modules that
you need.
      *
      * @return this builder instance.

http://git-wip-us.apache.org/repos/asf/cayenne/blob/231069ac/cayenne-client/src/test/java/org/apache/cayenne/configuration/rop/client/ClientRuntimeBuilderTest.java
----------------------------------------------------------------------
diff --git a/cayenne-client/src/test/java/org/apache/cayenne/configuration/rop/client/ClientRuntimeBuilderTest.java
b/cayenne-client/src/test/java/org/apache/cayenne/configuration/rop/client/ClientRuntimeBuilderTest.java
new file mode 100644
index 0000000..c324ead
--- /dev/null
+++ b/cayenne-client/src/test/java/org/apache/cayenne/configuration/rop/client/ClientRuntimeBuilderTest.java
@@ -0,0 +1,101 @@
+/*****************************************************************
+ *   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.configuration.rop.client;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+
+import org.apache.cayenne.configuration.Constants;
+import org.apache.cayenne.di.Key;
+import org.apache.cayenne.di.Module;
+import org.junit.After;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
+
+/**
+ * @since 4.0
+ */
+public class ClientRuntimeBuilderTest {
+
+    private ClientRuntime runtime;
+
+    @After
+    public void stopRuntime() {
+        if (runtime != null) {
+            runtime.shutdown();
+        }
+    }
+
+    @Test
+    public void testDefaultBuild() {
+        runtime = new ClientRuntimeBuilder().build();
+
+        Map<String, String> properties = runtime.getInjector()
+                .getInstance(Key.getMapOf(String.class, String.class, Constants.PROPERTIES_MAP));
+        assertTrue(properties.isEmpty());
+
+        Collection<Module> modules = runtime.getModules();
+        assertEquals(1, modules.size());
+        assertThat(modules.iterator().next(), instanceOf(ClientModule.class));
+    }
+
+    @Test
+    public void testNoAutoLoading() {
+        runtime = new ClientRuntimeBuilder().disableModulesAutoLoading().build();
+
+        Map<String, String> properties = runtime.getInjector()
+                .getInstance(Key.getMapOf(String.class, String.class, Constants.PROPERTIES_MAP));
+        assertTrue(properties.isEmpty());
+
+        Collection<Module> modules = runtime.getModules();
+        assertEquals(1, modules.size());
+        assertThat(modules.iterator().next(), instanceOf(ClientModule.class));
+    }
+
+    @Test
+    public void testExtraModules() {
+
+        Module m = mock(Module.class);
+
+        runtime = new ClientRuntimeBuilder().addModule(m).build();
+
+        Collection<Module> modules = runtime.getModules();
+        assertEquals(2, modules.size());
+        Module[] array = modules.toArray(new Module[2]);
+        assertThat(array[0], instanceOf(ClientModule.class));
+        assertSame(m, array[1]);
+    }
+
+    @Test
+    public void testProperties() {
+        Map<String, String> properties = Collections.singletonMap("test", "test_value");
+
+        runtime = new ClientRuntimeBuilder().properties(properties).build();
+
+        Map<String, String> injectedProperties = runtime.getInjector()
+                .getInstance(Key.getMapOf(String.class, String.class, Constants.PROPERTIES_MAP));
+        assertEquals(properties, injectedProperties);
+    }
+
+}
\ No newline at end of file


Mime
View raw message