Skip to content

Commit 2dc1d39

Browse files
Verdenttomas-langer
authored andcommitted
SetCookie test for parse method
Signed-off-by: David Kral <david.k.kral@oracle.com>
1 parent 61e157e commit 2dc1d39

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

common/http/src/main/java/io/helidon/common/http/SetCookie.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public static SetCookie parse(String setCookie) {
9696
break;
9797
case "max-age":
9898
hasValue(partName, partValue);
99-
builder.maxAge(Duration.parse(partValue));
99+
builder.maxAge(Duration.ofSeconds(Long.parseLong(partValue)));
100100
break;
101101
case "domain":
102102
hasValue(partName, partValue);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2020 Oracle and/or its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.helidon.common.http;
17+
18+
import org.junit.jupiter.api.Test;
19+
20+
import static org.hamcrest.MatcherAssert.assertThat;
21+
import static org.hamcrest.Matchers.is;
22+
import static org.junit.jupiter.api.Assertions.assertThrows;
23+
24+
/**
25+
* Unit tests for verification of {@link SetCookie} proper parsing from String.
26+
*/
27+
public class SetCookieTest {
28+
29+
@Test
30+
public void testSetCookiesFromString() {
31+
String template = "some-cookie=some-cookie-value; "
32+
+ "Expires=Thu, 22 Oct 2015 07:28:00 GMT; "
33+
+ "Max-Age=2592000; "
34+
+ "Domain=domain.value; "
35+
+ "Path=/; "
36+
+ "Secure; "
37+
+ "HttpOnly";
38+
SetCookie setCookie = SetCookie.parse(template);
39+
assertThat(setCookie.toString(), is(template));
40+
}
41+
42+
@Test
43+
public void testSetCookiesInvalidValue() {
44+
String template = "some-cookie=some-cookie-value; "
45+
+ "Invalid=value";
46+
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
47+
() -> SetCookie.parse(template));
48+
assertThat(ex.getMessage(), is("Unexpected Set-Cookie part: Invalid"));
49+
}
50+
51+
}

0 commit comments

Comments
 (0)