tests for 2 previous commits
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/98029f73 Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/98029f73 Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/98029f73 Branch: refs/heads/master Commit: 98029f7374edea604347e1c0a5f598fb793a65e6 Parents: 10280fa Author: Romain Manni-Bucau <rmannibu...@apache.org> Authored: Tue May 5 09:50:02 2015 +0200 Committer: Romain Manni-Bucau <rmannibu...@apache.org> Committed: Tue May 5 09:50:02 2015 +0200 ---------------------------------------------------------------------- .../server/httpd/HttpRequestImplTest.java | 50 ++++++++++++++ .../server/httpd/HttpSessionImplTest.java | 68 ++++++++++++++++++++ 2 files changed, 118 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tomee/blob/98029f73/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpRequestImplTest.java ---------------------------------------------------------------------- diff --git a/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpRequestImplTest.java b/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpRequestImplTest.java new file mode 100644 index 0000000..54b7373 --- /dev/null +++ b/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpRequestImplTest.java @@ -0,0 +1,50 @@ +/** + * 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.openejb.server.httpd; + +import org.apache.openejb.loader.SystemInstance; +import org.apache.openejb.server.httpd.session.SessionManager; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.net.URI; +import java.net.URISyntaxException; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +public class HttpRequestImplTest { + @Before + public void init() { + SystemInstance.get().setComponent(SessionManager.class, new SessionManager()); + } + + @After + public void reset() { + SystemInstance.reset(); + } + + @Test + public void run() throws URISyntaxException { + final HttpRequest req = new HttpRequestImpl(new URI("http://localhost:1234/foo")); + final javax.servlet.http.HttpSession session = req.getSession(); + assertNotNull(session); + session.invalidate(); + assertNull(req.getSession(false)); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/98029f73/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpSessionImplTest.java ---------------------------------------------------------------------- diff --git a/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpSessionImplTest.java b/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpSessionImplTest.java new file mode 100644 index 0000000..990d48e --- /dev/null +++ b/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpSessionImplTest.java @@ -0,0 +1,68 @@ +/* + * 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.openejb.server.httpd; + +import org.apache.openejb.loader.SystemInstance; +import org.apache.openejb.server.httpd.session.SessionManager; +import org.apache.openejb.util.reflection.Reflections; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Collections; +import javax.servlet.http.HttpSessionEvent; +import javax.servlet.http.HttpSessionListener; + +import static org.junit.Assert.assertEquals; + +public class HttpSessionImplTest { + @Before + public void init() { + SystemInstance.get().setComponent(SessionManager.class, new SessionManager()); + } + + @After + public void reset() { + SystemInstance.reset(); + } + + @Test + public void run() throws URISyntaxException { + final HttpRequest req = new HttpRequestImpl(new URI("http://localhost:1234/foo")); + final javax.servlet.http.HttpSession session = req.getSession(); + Reflections.set(session, "listeners", Collections.<Object>singletonList(new HttpSessionListener() { + private int count = 0; + + @Override + public void sessionCreated(final HttpSessionEvent se) { + // no-op + } + + @Override + public void sessionDestroyed(final HttpSessionEvent se) { + se.getSession().setAttribute("seen", ++count); + } + })); + session.invalidate(); + final long c1 = Integer.class.cast(session.getAttribute("seen")); + session.invalidate(); + final long c2 = Integer.class.cast(session.getAttribute("seen")); + assertEquals(c1, c2); + } +}