http://git-wip-us.apache.org/repos/asf/cayenne/blob/37dac62d/cayenne-web/src/test/java/org/apache/cayenne/web/CayenneFilterTest.java ---------------------------------------------------------------------- diff --git a/cayenne-web/src/test/java/org/apache/cayenne/web/CayenneFilterTest.java b/cayenne-web/src/test/java/org/apache/cayenne/web/CayenneFilterTest.java index f27ec88..d0f28d5 100644 --- a/cayenne-web/src/test/java/org/apache/cayenne/web/CayenneFilterTest.java +++ b/cayenne-web/src/test/java/org/apache/cayenne/web/CayenneFilterTest.java @@ -101,11 +101,10 @@ public class CayenneFilterTest { Collection<Module> modules = runtime.getModules(); assertEquals(3, modules.size()); -// Was removed because now it is not in correct order. ServerModule and WebModule can change there positioins. -// Object[] marray = modules.toArray(); -// assertTrue(marray[0] instanceof ServerModule); -// // [2] is an inner class -// assertTrue(marray[1] instanceof WebModule); +// Now we dont correct order. +/* Object[] marray = modules.toArray(); + assertTrue(marray[0] instanceof WebModule); + assertTrue(marray[1] instanceof ServerModule);*/ RequestHandler handler = runtime.getInjector().getInstance(RequestHandler.class); assertTrue(handler instanceof SessionContextRequestHandler); @@ -131,13 +130,12 @@ public class CayenneFilterTest { Collection<Module> modules = runtime.getModules(); assertEquals(5, modules.size()); -// Was removed because now it is not in correct order. ServerModule and WebModule can change there positioins. -// Object[] marray = modules.toArray(); -// assertTrue(marray[0] instanceof ServerModule); -// // [4] is an inner class -// assertTrue(marray[1] instanceof WebModule); -// assertTrue(marray[2] instanceof MockModule1); -// assertTrue(marray[3] instanceof MockModule2); +// Now we dont know correct order. + /*Object[] marray = modules.toArray(); + assertTrue(marray[0] instanceof WebModule); + assertTrue(marray[1] instanceof ServerModule); + assertTrue(marray[2] instanceof MockModule1); + assertTrue(marray[3] instanceof MockModule2);*/ RequestHandler handler = runtime.getInjector().getInstance(RequestHandler.class); assertTrue(handler instanceof MockRequestHandler); @@ -165,9 +163,9 @@ public class CayenneFilterTest { 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()); } }
http://git-wip-us.apache.org/repos/asf/cayenne/blob/37dac62d/cayenne-web/src/test/java/org/apache/cayenne/web/ServletContextHandlerTest.java ---------------------------------------------------------------------- diff --git a/cayenne-web/src/test/java/org/apache/cayenne/web/ServletContextHandlerTest.java b/cayenne-web/src/test/java/org/apache/cayenne/web/ServletContextHandlerTest.java index a37a192..fe1d3d0 100644 --- a/cayenne-web/src/test/java/org/apache/cayenne/web/ServletContextHandlerTest.java +++ b/cayenne-web/src/test/java/org/apache/cayenne/web/ServletContextHandlerTest.java @@ -1,124 +1,124 @@ -///***************************************************************** -// * 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.web; -// -//import com.mockrunner.mock.web.MockHttpServletRequest; -//import com.mockrunner.mock.web.MockHttpServletResponse; -//import com.mockrunner.mock.web.MockHttpSession; -//import org.apache.cayenne.BaseContext; -//import org.apache.cayenne.DataChannel; -//import org.apache.cayenne.MockDataChannel; -//import org.apache.cayenne.ObjectContext; -//import org.apache.cayenne.configuration.ObjectContextFactory; -//import org.apache.cayenne.di.DIBootstrap; -//import org.apache.cayenne.di.Injector; -//import org.apache.cayenne.di.Module; -//import org.junit.Test; -// -//import static org.junit.Assert.*; -//import static org.mockito.Mockito.mock; -// -//public class ServletContextHandlerTest { -// -// @Test -// public void testRequestStart_bindContext() { -// -// Module module = binder -> { -// -// binder.bind(DataChannel.class).to(MockDataChannel.class); -// binder.bind(ObjectContextFactory.class).toInstance( -// new ObjectContextFactory() { -// -// public ObjectContext createContext(DataChannel parent) { -// return mock(ObjectContext.class); -// } -// -// public ObjectContext createContext() { -// return mock(ObjectContext.class); -// } -// }); -// }; -// Injector injector = DIBootstrap.createInjector(module); -// SessionContextRequestHandler handler = new SessionContextRequestHandler(); -// injector.injectMembers(handler); -// -// MockHttpSession session = new MockHttpSession(); -// -// BaseContext.bindThreadObjectContext(null); -// -// try { -// -// MockHttpServletRequest request1 = new MockHttpServletRequest(); -// MockHttpServletResponse response1 = new MockHttpServletResponse(); -// request1.setSession(session); -// handler.requestStart(request1, response1); -// -// ObjectContext c1 = BaseContext.getThreadObjectContext(); -// assertNotNull(c1); -// -// handler.requestEnd(request1, response1); -// -// try { -// BaseContext.getThreadObjectContext(); -// fail("thread context not null"); -// } -// catch (IllegalStateException e) { -// // expected -// } -// -// MockHttpServletRequest request2 = new MockHttpServletRequest(); -// MockHttpServletResponse response2 = new MockHttpServletResponse(); -// request2.setSession(session); -// handler.requestStart(request2, response2); -// -// ObjectContext c2 = BaseContext.getThreadObjectContext(); -// assertSame(c1, c2); -// -// handler.requestEnd(request2, response2); -// try { -// BaseContext.getThreadObjectContext(); -// fail("thread context not null"); -// } -// catch (IllegalStateException e) { -// // expected -// } -// -// MockHttpServletRequest request3 = new MockHttpServletRequest(); -// MockHttpServletResponse response3 = new MockHttpServletResponse(); -// request3.setSession(new MockHttpSession()); -// handler.requestStart(request3, response3); -// -// ObjectContext c3 = BaseContext.getThreadObjectContext(); -// assertNotNull(c3); -// assertNotSame(c1, c3); -// -// handler.requestEnd(request3, response3); -// try { -// BaseContext.getThreadObjectContext(); -// fail("thread context not null"); -// } -// catch (IllegalStateException e) { -// // expected -// } -// } -// finally { -// BaseContext.bindThreadObjectContext(null); -// } -// } -//} +/***************************************************************** + * 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.web; + +import com.mockrunner.mock.web.MockHttpServletRequest; +import com.mockrunner.mock.web.MockHttpServletResponse; +import com.mockrunner.mock.web.MockHttpSession; +import org.apache.cayenne.BaseContext; +import org.apache.cayenne.DataChannel; +import org.apache.cayenne.MockDataChannel; +import org.apache.cayenne.ObjectContext; +import org.apache.cayenne.configuration.ObjectContextFactory; +import org.apache.cayenne.di.DIBootstrap; +import org.apache.cayenne.di.Injector; +import org.apache.cayenne.di.Module; +import org.junit.Test; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; + +public class ServletContextHandlerTest { + + @Test + public void testRequestStart_bindContext() { + + Module module = binder -> { + + binder.bind(DataChannel.class).to(MockDataChannel.class); + binder.bind(ObjectContextFactory.class).toInstance( + new ObjectContextFactory() { + + public ObjectContext createContext(DataChannel parent) { + return mock(ObjectContext.class); + } + + public ObjectContext createContext() { + return mock(ObjectContext.class); + } + }); + }; + Injector injector = DIBootstrap.createInjector(module); + SessionContextRequestHandler handler = new SessionContextRequestHandler(); + injector.injectMembers(handler); + + MockHttpSession session = new MockHttpSession(); + + BaseContext.bindThreadObjectContext(null); + + try { + + MockHttpServletRequest request1 = new MockHttpServletRequest(); + MockHttpServletResponse response1 = new MockHttpServletResponse(); + request1.setSession(session); + handler.requestStart(request1, response1); + + ObjectContext c1 = BaseContext.getThreadObjectContext(); + assertNotNull(c1); + + handler.requestEnd(request1, response1); + + try { + BaseContext.getThreadObjectContext(); + fail("thread context not null"); + } + catch (IllegalStateException e) { + // expected + } + + MockHttpServletRequest request2 = new MockHttpServletRequest(); + MockHttpServletResponse response2 = new MockHttpServletResponse(); + request2.setSession(session); + handler.requestStart(request2, response2); + + ObjectContext c2 = BaseContext.getThreadObjectContext(); + assertSame(c1, c2); + + handler.requestEnd(request2, response2); + try { + BaseContext.getThreadObjectContext(); + fail("thread context not null"); + } + catch (IllegalStateException e) { + // expected + } + + MockHttpServletRequest request3 = new MockHttpServletRequest(); + MockHttpServletResponse response3 = new MockHttpServletResponse(); + request3.setSession(new MockHttpSession()); + handler.requestStart(request3, response3); + + ObjectContext c3 = BaseContext.getThreadObjectContext(); + assertNotNull(c3); + assertNotSame(c1, c3); + + handler.requestEnd(request3, response3); + try { + BaseContext.getThreadObjectContext(); + fail("thread context not null"); + } + catch (IllegalStateException e) { + // expected + } + } + finally { + BaseContext.bindThreadObjectContext(null); + } + } +} http://git-wip-us.apache.org/repos/asf/cayenne/blob/37dac62d/tutorials/tutorial/pom.xml ---------------------------------------------------------------------- diff --git a/tutorials/tutorial/pom.xml b/tutorials/tutorial/pom.xml index d9e2f28..ee39e05 100644 --- a/tutorials/tutorial/pom.xml +++ b/tutorials/tutorial/pom.xml @@ -32,13 +32,25 @@ </dependency> <dependency> <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> + <artifactId>javax.servlet-api</artifactId> + <version>3.1.0</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.cayenne</groupId> + <artifactId>cayenne-web</artifactId> + <version>${project.version}</version> </dependency> <dependency> <groupId>org.apache.derby</groupId> <artifactId>derby</artifactId> <scope>compile</scope> </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + <scope>compile</scope> + </dependency> </dependencies> <build> http://git-wip-us.apache.org/repos/asf/cayenne/blob/37dac62d/tutorials/tutorial/src/main/webapp/WEB-INF/web.xml ---------------------------------------------------------------------- diff --git a/tutorials/tutorial/src/main/webapp/WEB-INF/web.xml b/tutorials/tutorial/src/main/webapp/WEB-INF/web.xml index eabc196..4a5778a 100644 --- a/tutorials/tutorial/src/main/webapp/WEB-INF/web.xml +++ b/tutorials/tutorial/src/main/webapp/WEB-INF/web.xml @@ -29,7 +29,7 @@ --> <filter> <filter-name>cayenne-project</filter-name> - <filter-class>org.apache.cayenne.configuration.web.CayenneFilter</filter-class> + <filter-class>org.apache.cayenne.web.CayenneFilter</filter-class> </filter> <filter-mapping> <filter-name>cayenne-project</filter-name>