cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1568603 - in /cayenne/main/trunk/cayenne-server/src: main/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilder.java test/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilderTest.java
Date Sat, 15 Feb 2014 10:17:50 GMT
Author: aadamchik
Date: Sat Feb 15 10:17:50 2014
New Revision: 1568603

URL: http://svn.apache.org/r1568603
Log:
CAY-1899 ServerRuntimeBuilder

Added:
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilder.java
    cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilderTest.java

Added: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilder.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilder.java?rev=1568603&view=auto
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilder.java
(added)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilder.java
Sat Feb 15 10:17:50 2014
@@ -0,0 +1,72 @@
+/*****************************************************************
+ *   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.server;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+
+import org.apache.cayenne.di.Module;
+
+/**
+ * A convenience class to assemble custom ServerRuntime.
+ * 
+ * @since 3.2
+ */
+public class ServerRuntimeBuilder {
+
+    private Collection<String> configs;
+    private Collection<Module> modules;
+
+    public ServerRuntimeBuilder() {
+        this.configs = new LinkedHashSet<String>();
+        this.modules = new ArrayList<Module>();
+    }
+
+    public ServerRuntimeBuilder(String configurationLocation) {
+        this();
+        addConfig(configurationLocation);
+    }
+
+    public ServerRuntimeBuilder addConfig(String configurationLocation) {
+        configs.add(configurationLocation);
+        return this;
+    }
+
+    public ServerRuntimeBuilder addConfigs(Collection<String> configurationLocations)
{
+        configs.addAll(configurationLocations);
+        return this;
+    }
+
+    public ServerRuntimeBuilder addModule(Module module) {
+        modules.add(module);
+        return this;
+    }
+
+    public ServerRuntimeBuilder addMoudles(Collection<Module> modules) {
+        this.modules.addAll(modules);
+        return this;
+    }
+
+    public ServerRuntime build() {
+        String[] configs = this.configs.toArray(new String[this.configs.size()]);
+        Module[] modules = this.modules.toArray(new Module[this.modules.size()]);
+        return new ServerRuntime(configs, modules);
+    }
+}

Added: cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilderTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilderTest.java?rev=1568603&view=auto
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilderTest.java
(added)
+++ cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilderTest.java
Sat Feb 15 10:17:50 2014
@@ -0,0 +1,76 @@
+/*****************************************************************
+ *   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.server;
+
+import static org.mockito.Mockito.mock;
+
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.cayenne.configuration.Constants;
+import org.apache.cayenne.di.Key;
+import org.apache.cayenne.di.Module;
+
+public class ServerRuntimeBuilderTest extends TestCase {
+
+    public void test_SingleLocation() {
+
+        ServerRuntime runtime = new ServerRuntimeBuilder("xxxx").build();
+
+        List<?> locations = runtime.getInjector().getInstance(
+                Key.get(List.class, Constants.SERVER_PROJECT_LOCATIONS_LIST));
+
+        assertEquals(Arrays.asList("xxxx"), locations);
+
+        assertEquals(1, runtime.getModules().length);
+
+        Module m0 = runtime.getModules()[0];
+        assertTrue(m0 instanceof ServerModule);
+    }
+
+    public void test_MultipleLocations() {
+
+        ServerRuntime runtime = new ServerRuntimeBuilder("xxxx").addConfig("yyyy").build();
+
+        List<?> locations = runtime.getInjector().getInstance(
+                Key.get(List.class, Constants.SERVER_PROJECT_LOCATIONS_LIST));
+
+        assertEquals(Arrays.asList("xxxx", "yyyy"), locations);
+
+        assertEquals(1, runtime.getModules().length);
+
+        Module m0 = runtime.getModules()[0];
+        assertTrue(m0 instanceof ServerModule);
+    }
+
+    public void test_ExtraModules() {
+
+        Module m = mock(Module.class);
+
+        ServerRuntime runtime = new ServerRuntimeBuilder("xxxx").addModule(m).build();
+
+        assertEquals(2, runtime.getModules().length);
+
+        assertTrue(runtime.getModules()[0] instanceof ServerModule);
+        assertSame(m, runtime.getModules()[1]);
+    }
+
+}



Mime
View raw message