|
Java example source code file (ServerCookieDecoderTest.java)
The ServerCookieDecoderTest.java Java example source code/* * Copyright 2014 The Netty Project * * The Netty Project 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 io.netty.handler.codec.http.cookie; import org.junit.Test; import io.netty.handler.codec.http.HttpHeaderDateFormat; import java.util.Date; import java.util.Iterator; import java.util.Set; import static org.junit.Assert.*; public class ServerCookieDecoderTest { @Test public void testDecodingSingleCookie() { String cookieString = "myCookie=myValue"; cookieString = cookieString.replace("XXX", HttpHeaderDateFormat.get().format(new Date(System.currentTimeMillis() + 50000))); Set<Cookie> cookies = ServerCookieDecoder.STRICT.decode(cookieString); assertEquals(1, cookies.size()); Cookie cookie = cookies.iterator().next(); assertNotNull(cookie); assertEquals("myValue", cookie.value()); } @Test public void testDecodingMultipleCookies() { String c1 = "myCookie=myValue;"; String c2 = "myCookie2=myValue2;"; String c3 = "myCookie3=myValue3;"; Set<Cookie> cookies = ServerCookieDecoder.STRICT.decode(c1 + c2 + c3); assertEquals(3, cookies.size()); Iterator<Cookie> it = cookies.iterator(); Cookie cookie = it.next(); assertNotNull(cookie); assertEquals("myValue", cookie.value()); cookie = it.next(); assertNotNull(cookie); assertEquals("myValue2", cookie.value()); cookie = it.next(); assertNotNull(cookie); assertEquals("myValue3", cookie.value()); } @Test public void testDecodingGoogleAnalyticsCookie() { String source = "ARPT=LWUKQPSWRTUN04CKKJI; " + "kw-2E343B92-B097-442c-BFA5-BE371E0325A2=unfinished_furniture; " + "__utma=48461872.1094088325.1258140131.1258140131.1258140131.1; " + "__utmb=48461872.13.10.1258140131; __utmc=48461872; " + "__utmz=48461872.1258140131.1.1.utmcsr=overstock.com|utmccn=(referral)|" + "utmcmd=referral|utmcct=/Home-Garden/Furniture/Clearance/clearance/32/dept.html"; Set<Cookie> cookies = ServerCookieDecoder.STRICT.decode(source); Iterator<Cookie> it = cookies.iterator(); Cookie c; c = it.next(); assertEquals("__utma", c.name()); assertEquals("48461872.1094088325.1258140131.1258140131.1258140131.1", c.value()); c = it.next(); assertEquals("__utmb", c.name()); assertEquals("48461872.13.10.1258140131", c.value()); c = it.next(); assertEquals("__utmc", c.name()); assertEquals("48461872", c.value()); c = it.next(); assertEquals("__utmz", c.name()); assertEquals("48461872.1258140131.1.1.utmcsr=overstock.com|" + "utmccn=(referral)|utmcmd=referral|utmcct=/Home-Garden/Furniture/Clearance/clearance/32/dept.html", c.value()); c = it.next(); assertEquals("ARPT", c.name()); assertEquals("LWUKQPSWRTUN04CKKJI", c.value()); c = it.next(); assertEquals("kw-2E343B92-B097-442c-BFA5-BE371E0325A2", c.name()); assertEquals("unfinished_furniture", c.value()); assertFalse(it.hasNext()); } @Test public void testDecodingLongValue() { String longValue = "b___$Q__$ha__<NC=MN(F__%#4__ Other Java examples (source code examples)Here is a short list of links related to this Java ServerCookieDecoderTest.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.