You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2005/11/16 00:11:06 UTC

svn commit: r344466 - in /jakarta/jmeter/branches/rel-2-1: src/protocol/http/org/apache/jmeter/protocol/http/control/CookieManager.java test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java

Author: sebb
Date: Tue Nov 15 15:10:58 2005
New Revision: 344466

URL: http://svn.apache.org/viewcvs?rev=344466&view=rev
Log:
Add duplicate cookie test; move test code to test tree

Added:
    jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java
Modified:
    jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/control/CookieManager.java

Modified: jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/control/CookieManager.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/control/CookieManager.java?rev=344466&r1=344465&r2=344466&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/control/CookieManager.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/control/CookieManager.java Tue Nov 15 15:10:58 2005
@@ -35,18 +35,14 @@
 import java.util.TimeZone;
 import java.util.Vector;
 
-import junit.framework.TestCase;
 
 import org.apache.jmeter.config.ConfigTestElement;
 import org.apache.jmeter.engine.event.LoopIterationEvent;
-import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
-import org.apache.jmeter.protocol.http.sampler.HTTPNullSampler;
 import org.apache.jmeter.testelement.TestListener;
 import org.apache.jmeter.testelement.property.BooleanProperty;
 import org.apache.jmeter.testelement.property.CollectionProperty;
 import org.apache.jmeter.testelement.property.PropertyIterator;
 import org.apache.jmeter.threads.JMeterContext;
-import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jmeter.util.JMeterUtils;
 import org.apache.jorphan.logging.LoggingManager;
 import org.apache.jorphan.util.JOrphanUtils;
@@ -460,95 +456,5 @@
 	public void testIterationStart(LoopIterationEvent event) {
 		if (getClearEachIteration())
 			clear();
-	}
-    
-    ///////////////////////////////////////////// TEST CASES ////////////////////////////////////
-
-	public static class Test extends TestCase {
-		CookieManager man = null;
-
-		public Test(String name) {
-			super(name);
-		}
-
-		private JMeterContext jmctx = null;
-
-		public void setUp() {
-			jmctx = JMeterContextService.getContext();
-			man = new CookieManager();
-			man.setThreadContext(jmctx);
-		}
-
-		public void testRemoveCookie() throws Exception {
-			man.setThreadContext(jmctx);
-			man.add(new Cookie("id", "me", "127.0.0.1", "/", false, 0));
-			man.removeCookieNamed("id");
-			assertEquals(0, man.getCookieCount());
-		}
-
-		public void testSendCookie() throws Exception {
-			man.add(new Cookie("id", "value", "jakarta.apache.org", "/", false, 9999999999L));
-			HTTPSamplerBase sampler = new HTTPNullSampler();
-			sampler.setDomain("jakarta.apache.org");
-			sampler.setPath("/index.html");
-			sampler.setMethod(HTTPSamplerBase.GET);
-			assertNotNull(man.getCookieHeaderForURL(sampler.getUrl()));
-		}
-
-		public void testSendCookie2() throws Exception {
-			man.add(new Cookie("id", "value", ".apache.org", "/", false, 9999999999L));
-			HTTPSamplerBase sampler = new HTTPNullSampler();
-			sampler.setDomain("jakarta.apache.org");
-			sampler.setPath("/index.html");
-			sampler.setMethod(HTTPSamplerBase.GET);
-			assertNotNull(man.getCookieHeaderForURL(sampler.getUrl()));
-		}
-
-		/**
-		 * Test that the cookie domain field is actually handled as browsers do
-		 * (i.e.: host X matches domain .X):
-		 */
-		public void testDomainHandling() throws Exception {
-			URL url = new URL("http://jakarta.apache.org/");
-			man.addCookieFromHeader("test=1;domain=.jakarta.apache.org", url);
-			assertNotNull(man.getCookieHeaderForURL(url));
-		}
-
-		/**
-		 * Test that we won't be tricked by similar host names (this was a past
-		 * bug, although it never got reported in the bug database):
-		 */
-		public void testSimilarHostNames() throws Exception {
-			URL url = new URL("http://ache.org/");
-			man.addCookieFromHeader("test=1", url);
-			url = new URL("http://jakarta.apache.org/");
-			assertNull(man.getCookieHeaderForURL(url));
-		}
-
-		// Test session cookie is returned
-		public void testSessionCookie() throws Exception {
-			URL url = new URL("http://a.b.c/");
-			man.addCookieFromHeader("test=1", url);
-			String s = man.getCookieHeaderForURL(url);
-			assertNotNull(s);
-			assertEquals("test=1", s);
-		}
-
-		// Test Old cookie is not returned
-		public void testOldCookie() throws Exception {
-			URL url = new URL("http://a.b.c/");
-			man.addCookieFromHeader("test=1; expires=Mon, 01-Jan-1990 00:00:00 GMT", url);
-			String s = man.getCookieHeaderForURL(url);
-			assertNull(s);
-		}
-
-		// Test New cookie is returned
-		public void testNewCookie() throws Exception {
-			URL url = new URL("http://a.b.c/");
-			man.addCookieFromHeader("test=1; expires=Mon, 01-Jan-2990 00:00:00 GMT", url);
-			String s = man.getCookieHeaderForURL(url);
-			assertNotNull(s);
-			assertEquals("test=1", s);
-		}
 	}
 }

Added: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java?rev=344466&view=auto
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java (added)
+++ jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java Tue Nov 15 15:10:58 2005
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.jmeter.protocol.http.control;
+
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.apache.jmeter.protocol.http.sampler.HTTPNullSampler;
+import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
+import org.apache.jmeter.threads.JMeterContext;
+import org.apache.jmeter.threads.JMeterContextService;
+
+public class TestCookieManager extends TestCase {
+        private CookieManager man = null;
+
+        public TestCookieManager(String name) {
+            super(name);
+        }
+
+        private JMeterContext jmctx = null;
+
+        public void setUp() throws Exception {
+            super.setUp();
+            jmctx = JMeterContextService.getContext();
+            man = new CookieManager();
+            man.setThreadContext(jmctx);
+        }
+
+        public void testRemoveCookie() throws Exception {
+            man.setThreadContext(jmctx);
+            man.add(new Cookie("id", "me", "127.0.0.1", "/", false, 0));
+            man.removeCookieNamed("id");
+            assertEquals(0, man.getCookieCount());
+        }
+
+        public void testSendCookie() throws Exception {
+            man.add(new Cookie("id", "value", "jakarta.apache.org", "/", false, 9999999999L));
+            HTTPSamplerBase sampler = new HTTPNullSampler();
+            sampler.setDomain("jakarta.apache.org");
+            sampler.setPath("/index.html");
+            sampler.setMethod(HTTPSamplerBase.GET);
+            assertNotNull(man.getCookieHeaderForURL(sampler.getUrl()));
+        }
+
+        public void testSendCookie2() throws Exception {
+            man.add(new Cookie("id", "value", ".apache.org", "/", false, 9999999999L));
+            HTTPSamplerBase sampler = new HTTPNullSampler();
+            sampler.setDomain("jakarta.apache.org");
+            sampler.setPath("/index.html");
+            sampler.setMethod(HTTPSamplerBase.GET);
+            assertNotNull(man.getCookieHeaderForURL(sampler.getUrl()));
+        }
+
+        /**
+         * Test that the cookie domain field is actually handled as browsers do
+         * (i.e.: host X matches domain .X):
+         */
+        public void testDomainHandling() throws Exception {
+            URL url = new URL("http://jakarta.apache.org/");
+            man.addCookieFromHeader("test=1;domain=.jakarta.apache.org", url);
+            assertNotNull(man.getCookieHeaderForURL(url));
+        }
+
+        /**
+         * Test that we won't be tricked by similar host names (this was a past
+         * bug, although it never got reported in the bug database):
+         */
+        public void testSimilarHostNames() throws Exception {
+            URL url = new URL("http://ache.org/");
+            man.addCookieFromHeader("test=1", url);
+            url = new URL("http://jakarta.apache.org/");
+            assertNull(man.getCookieHeaderForURL(url));
+        }
+
+        // Test session cookie is returned
+        public void testSessionCookie() throws Exception {
+            URL url = new URL("http://a.b.c/");
+            man.addCookieFromHeader("test=1", url);
+            String s = man.getCookieHeaderForURL(url);
+            assertNotNull(s);
+            assertEquals("test=1", s);
+        }
+
+        // Test Old cookie is not returned
+        public void testOldCookie() throws Exception {
+            URL url = new URL("http://a.b.c/");
+            man.addCookieFromHeader("test=1; expires=Mon, 01-Jan-1990 00:00:00 GMT", url);
+            String s = man.getCookieHeaderForURL(url);
+            assertNull(s);
+        }
+
+        // Test New cookie is returned
+        public void testNewCookie() throws Exception {
+            URL url = new URL("http://a.b.c/");
+            man.addCookieFromHeader("test=1; expires=Mon, 01-Jan-2990 00:00:00 GMT", url);
+            String s = man.getCookieHeaderForURL(url);
+            assertNotNull(s);
+            assertEquals("test=1", s);
+        }
+
+        // Test duplicate cookie handling
+        public void testDuplicateCookie() throws Exception {
+            URL url = new URL("http://a.b.c/");
+            man.addCookieFromHeader("test=1", url);
+            String s = man.getCookieHeaderForURL(url);
+            assertNotNull(s);
+            assertEquals("test=1", s);
+            man.addCookieFromHeader("test=2", url);
+            s = man.getCookieHeaderForURL(url);
+            assertNotNull(s);
+            assertEquals("test=2", s);
+        }
+        public void testDuplicateCookie2() throws Exception {
+            URL url = new URL("http://a.b.c/");
+            man.addCookieFromHeader("test=1", url);
+            man.addCookieFromHeader("test2=a", url);
+            String s = man.getCookieHeaderForURL(url);
+            assertNotNull(s);
+            assertEquals("test=1; test2=a", s); // Assumes some kind of list is used
+            man.addCookieFromHeader("test=2", url);
+            man.addCookieFromHeader("test3=b", url);
+            s = man.getCookieHeaderForURL(url);
+            assertNotNull(s);
+            assertEquals("test2=a; test=2; test3=b", s);// Assumes some kind of list is use
+            // If not using a list that retains the order, then the asserts would need to change
+        }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org