cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject cayenne git commit: Javadocs + additional tests
Date Tue, 08 May 2018 09:50:21 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master 0a0f98dfb -> bcbec5159


Javadocs + additional tests


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

Branch: refs/heads/master
Commit: bcbec5159c5204bc42f28d8a273bf35a923f1f6d
Parents: 0a0f98d
Author: Nikita Timofeev <stariy95@gmail.com>
Authored: Tue May 8 12:48:52 2018 +0300
Committer: Nikita Timofeev <stariy95@gmail.com>
Committed: Tue May 8 12:48:52 2018 +0300

----------------------------------------------------------------------
 .../configuration/web/WebConfiguration.java     |  11 +-
 .../configuration/web/CayenneFilterTest.java    | 237 +++++++++++--------
 2 files changed, 146 insertions(+), 102 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/bcbec515/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/WebConfiguration.java
----------------------------------------------------------------------
diff --git a/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/WebConfiguration.java
b/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/WebConfiguration.java
index a65d913..1edce29 100644
--- a/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/WebConfiguration.java
+++ b/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/WebConfiguration.java
@@ -47,6 +47,10 @@ public class WebConfiguration {
 
     static final String CONFIGURATION_LOCATION_PARAMETER = "configuration-location";
     static final String EXTRA_MODULES_PARAMETER = "extra-modules";
+
+    /**
+     * @since 4.1
+     */
     static final String DATA_DOMAIN_NAME_PARAMETER = "data-domain-name";
 
     private FilterConfig configuration;
@@ -105,14 +109,13 @@ public class WebConfiguration {
     /**
      * If you are using multiple configuration files (cayenne-*.xml) this allows you
      * to specify a name for the data domain other than the default name "cayenne" 
-     * (see {@value ServerRuntimeBuilder}).
+     * (see {@link ServerRuntimeBuilder}).
      * A specific data domain name is useful if you are setting database connection info

      * using properties via {@link PropertyDataSourceFactory}.
-     * @return
+     * @since 4.1
      */
     public String getDataDomainName() {
-        String name = configuration.getInitParameter(DATA_DOMAIN_NAME_PARAMETER);
-        return name;
+        return configuration.getInitParameter(DATA_DOMAIN_NAME_PARAMETER);
     }
     
     /**

http://git-wip-us.apache.org/repos/asf/cayenne/blob/bcbec515/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/CayenneFilterTest.java
----------------------------------------------------------------------
diff --git a/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/CayenneFilterTest.java
b/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/CayenneFilterTest.java
index 3c7df86..45fd27a 100644
--- a/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/CayenneFilterTest.java
+++ b/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/CayenneFilterTest.java
@@ -32,6 +32,7 @@ import org.junit.Test;
 
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 
 import static org.junit.Assert.assertEquals;
@@ -42,145 +43,185 @@ import static org.junit.Assert.assertTrue;
 public class CayenneFilterTest {
 
     @Test
-	public void testInitWithFilterName() throws Exception {
+    public void testInitWithFilterName() throws Exception {
 
-		MockFilterConfig config = new MockFilterConfig();
-		config.setFilterName("abc");
+        MockFilterConfig config = new MockFilterConfig();
+        config.setFilterName("abc");
 
-		MockServletContext context = new MockServletContext();
-		config.setupServletContext(context);
+        MockServletContext context = new MockServletContext();
+        config.setupServletContext(context);
 
-		CayenneFilter filter = new CayenneFilter();
+        CayenneFilter filter = new CayenneFilter();
 
-		assertNull(WebUtil.getCayenneRuntime(context));
-		filter.init(config);
+        assertNull(WebUtil.getCayenneRuntime(context));
+        filter.init(config);
 
-		CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
-		assertNotNull(runtime);
+        CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
+        assertNotNull(runtime);
 
-		List<String> locations = runtime.getInjector().getInstance(
-				Key.getListOf(String.class, Constants.SERVER_PROJECT_LOCATIONS_LIST));
+        List<String> locations = runtime.getInjector()
+                .getInstance(Key.getListOf(String.class, Constants.SERVER_PROJECT_LOCATIONS_LIST));
 
-		assertEquals(Arrays.asList("abc.xml"), locations);
-	}
+        assertEquals(Collections.singletonList("abc.xml"), locations);
+    }
 
     @Test
-	public void testInitWithLocation() throws Exception {
+    public void testInitWithLocation() throws Exception {
 
-		MockFilterConfig config = new MockFilterConfig();
-		config.setFilterName("abc");
-		config.setInitParameter(WebConfiguration.CONFIGURATION_LOCATION_PARAMETER, "xyz");
+        MockFilterConfig config = new MockFilterConfig();
+        config.setFilterName("abc");
+        config.setInitParameter(WebConfiguration.CONFIGURATION_LOCATION_PARAMETER, "xyz");
 
-		MockServletContext context = new MockServletContext();
-		config.setupServletContext(context);
+        MockServletContext context = new MockServletContext();
+        config.setupServletContext(context);
 
-		CayenneFilter filter = new CayenneFilter();
-		filter.init(config);
+        CayenneFilter filter = new CayenneFilter();
+        filter.init(config);
 
-		CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
-		assertNotNull(runtime);
-		List<String> locations = runtime.getInjector().getInstance(
-				Key.getListOf(String.class, Constants.SERVER_PROJECT_LOCATIONS_LIST));
+        CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
+        assertNotNull(runtime);
+        List<String> locations = runtime.getInjector()
+                .getInstance(Key.getListOf(String.class, Constants.SERVER_PROJECT_LOCATIONS_LIST));
 
-		assertEquals(Arrays.asList("xyz"), locations);
-	}
+        assertEquals(Collections.singletonList("xyz"), locations);
+    }
 
     @Test
-	public void testInitWithStandardModules() throws Exception {
+    public void testInitWithMultipleLocations() throws Exception {
 
-		MockFilterConfig config = new MockFilterConfig();
-		config.setFilterName("cayenne-abc");
+        MockFilterConfig config = new MockFilterConfig();
+        config.setFilterName("abc");
+        config.setInitParameter(WebConfiguration.CONFIGURATION_LOCATION_PARAMETER, "xyz,abc,\tdef,
\n ghi");
 
-		MockServletContext context = new MockServletContext();
-		config.setupServletContext(context);
+        MockServletContext context = new MockServletContext();
+        config.setupServletContext(context);
 
-		CayenneFilter filter = new CayenneFilter();
+        CayenneFilter filter = new CayenneFilter();
+        filter.init(config);
 
-		assertNull(WebUtil.getCayenneRuntime(context));
-		filter.init(config);
+        CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
+        assertNotNull(runtime);
+        List<String> locations = runtime.getInjector()
+                .getInstance(Key.getListOf(String.class, Constants.SERVER_PROJECT_LOCATIONS_LIST));
 
-		CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
-		assertNotNull(runtime);
-		List<String> locations = runtime.getInjector().getInstance(
-				Key.getListOf(String.class, Constants.SERVER_PROJECT_LOCATIONS_LIST));
+        assertEquals(Arrays.asList("xyz", "abc", "def", "ghi"), locations);
+    }
 
-		assertEquals(Arrays.asList("cayenne-abc.xml"), locations);
-		Collection<Module> modules = runtime.getModules();
-		assertEquals(3, modules.size());
+    @Test
+    public void testInitWithCustomDomainName() throws Exception {
+        MockFilterConfig config = new MockFilterConfig();
+        config.setFilterName("abc");
+        config.setInitParameter(WebConfiguration.DATA_DOMAIN_NAME_PARAMETER, "custom");
+
+        MockServletContext context = new MockServletContext();
+        config.setupServletContext(context);
+
+        CayenneFilter filter = new CayenneFilter();
+        filter.init(config);
+
+        CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
+        assertNotNull(runtime);
+
+        String domainName = runtime.getInjector()
+                .getInstance(Key.getMapOf(String.class, String.class, Constants.PROPERTIES_MAP))
+                .get(Constants.SERVER_DOMAIN_NAME_PROPERTY);
+        assertEquals("custom", domainName);
+    }
+
+    @Test
+    public void testInitWithStandardModules() throws Exception {
+
+        MockFilterConfig config = new MockFilterConfig();
+        config.setFilterName("cayenne-abc");
+
+        MockServletContext context = new MockServletContext();
+        config.setupServletContext(context);
+
+        CayenneFilter filter = new CayenneFilter();
+
+        assertNull(WebUtil.getCayenneRuntime(context));
+        filter.init(config);
+
+        CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
+        assertNotNull(runtime);
+        List<String> locations = runtime.getInjector()
+                .getInstance(Key.getListOf(String.class, Constants.SERVER_PROJECT_LOCATIONS_LIST));
+
+        assertEquals(Collections.singletonList("cayenne-abc.xml"), locations);
+        Collection<Module> modules = runtime.getModules();
+        assertEquals(3, modules.size());
 
-		Object[] marray = modules.toArray();
+        Object[] marray = modules.toArray();
 
-		if(marray[0] instanceof ServerModule){
-			assertTrue(marray[1] instanceof WebModule);
-		}
-		else{
-			assertTrue(marray[0] instanceof WebModule);
-		}
+        if (marray[0] instanceof ServerModule) {
+            assertTrue(marray[1] instanceof WebModule);
+        } else {
+            assertTrue(marray[0] instanceof WebModule);
+        }
 
-		RequestHandler handler = runtime.getInjector().getInstance(RequestHandler.class);
-		assertTrue(handler instanceof SessionContextRequestHandler);
-	}
+        RequestHandler handler = runtime.getInjector().getInstance(RequestHandler.class);
+        assertTrue(handler instanceof SessionContextRequestHandler);
+    }
 
     @Test
-	public void testInitWithExtraModules() throws Exception {
+    public void testInitWithExtraModules() throws Exception {
 
-		MockFilterConfig config = new MockFilterConfig();
-		config.setFilterName("abc");
-		config.setInitParameter(WebConfiguration.EXTRA_MODULES_PARAMETER, MockModule1.class.getName()
+ ","
-				+ MockModule2.class.getName());
+        MockFilterConfig config = new MockFilterConfig();
+        config.setFilterName("abc");
+        config.setInitParameter(WebConfiguration.EXTRA_MODULES_PARAMETER,
+                MockModule1.class.getName() + "," + MockModule2.class.getName());
 
-		MockServletContext context = new MockServletContext();
-		config.setupServletContext(context);
+        MockServletContext context = new MockServletContext();
+        config.setupServletContext(context);
 
-		CayenneFilter filter = new CayenneFilter();
-		filter.init(config);
+        CayenneFilter filter = new CayenneFilter();
+        filter.init(config);
 
-		CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
-		assertNotNull(runtime);
+        CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
+        assertNotNull(runtime);
 
-		Collection<Module> modules = runtime.getModules();
-		assertEquals(5, modules.size());
+        Collection<Module> modules = runtime.getModules();
+        assertEquals(5, modules.size());
 
 
-		Object[] marray = modules.toArray();
-		if(marray[0] instanceof ServerModule){
-			assertTrue(marray[1] instanceof WebModule);
-		}
-		else{
-			assertTrue(marray[0] instanceof WebModule);
-		}
-		assertTrue(marray[2] instanceof MockModule1);
-		assertTrue(marray[3] instanceof MockModule2);
+        Object[] marray = modules.toArray();
+        if (marray[0] instanceof ServerModule) {
+            assertTrue(marray[1] instanceof WebModule);
+        } else {
+            assertTrue(marray[0] instanceof WebModule);
+        }
+        assertTrue(marray[2] instanceof MockModule1);
+        assertTrue(marray[3] instanceof MockModule2);
 
-		RequestHandler handler = runtime.getInjector().getInstance(RequestHandler.class);
-		assertTrue(handler instanceof MockRequestHandler);
-	}
+        RequestHandler handler = runtime.getInjector().getInstance(RequestHandler.class);
+        assertTrue(handler instanceof MockRequestHandler);
+    }
 
     @Test
-	public void testDoFilter() throws Exception {
-		MockFilterConfig config = new MockFilterConfig();
-		config.setFilterName("abc");
-		config.setInitParameter(WebConfiguration.EXTRA_MODULES_PARAMETER, CayenneFilter_DispatchModule.class.getName());
+    public void testDoFilter() throws Exception {
+        MockFilterConfig config = new MockFilterConfig();
+        config.setFilterName("abc");
+        config.setInitParameter(WebConfiguration.EXTRA_MODULES_PARAMETER, CayenneFilter_DispatchModule.class.getName());
 
-		MockServletContext context = new MockServletContext();
-		config.setupServletContext(context);
+        MockServletContext context = new MockServletContext();
+        config.setupServletContext(context);
 
-		CayenneFilter filter = new CayenneFilter();
-		filter.init(config);
+        CayenneFilter filter = new CayenneFilter();
+        filter.init(config);
 
-		CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
-		CayenneFilter_DispatchRequestHandler handler = (CayenneFilter_DispatchRequestHandler) runtime.getInjector()
-				.getInstance(RequestHandler.class);
+        CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
+        CayenneFilter_DispatchRequestHandler handler = (CayenneFilter_DispatchRequestHandler)
runtime.getInjector()
+                .getInstance(RequestHandler.class);
 
-		assertEquals(0, handler.getStarted());
-		assertEquals(0, handler.getEnded());
+        assertEquals(0, handler.getStarted());
+        assertEquals(0, handler.getEnded());
 
-		filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain());
-		assertEquals(1, handler.getStarted());
-		assertEquals(1, handler.getEnded());
+        filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new
MockFilterChain());
+        assertEquals(1, handler.getStarted());
+        assertEquals(1, handler.getEnded());
 
-		filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain());
-		assertEquals(2, handler.getStarted());
-		assertEquals(2, handler.getEnded());
-	}
+        filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new
MockFilterChain());
+        assertEquals(2, handler.getStarted());
+        assertEquals(2, handler.getEnded());
+    }
 }


Mime
View raw message