View Javadoc

1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.http.cookie;
29  
30  import org.junit.Assert;
31  import org.junit.Test;
32  
33  /**
34   * Test cases for {@link CookieOrigin}.
35   */
36  public class TestCookieOrigin {
37  
38      @Test
39      public void testConstructor() {
40          final CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "/", false);
41          Assert.assertEquals("www.apache.org", origin.getHost());
42          Assert.assertEquals(80, origin.getPort());
43          Assert.assertEquals("/", origin.getPath());
44          Assert.assertFalse(origin.isSecure());
45      }
46  
47      @SuppressWarnings("unused")
48      @Test(expected=IllegalArgumentException.class)
49      public void testNullHost() {
50          new CookieOrigin(null, 80, "/", false);
51      }
52  
53      @SuppressWarnings("unused")
54      @Test(expected=IllegalArgumentException.class)
55      public void testEmptyHost() {
56          new CookieOrigin("   ", 80, "/", false);
57      }
58  
59      @SuppressWarnings("unused")
60      @Test(expected=IllegalArgumentException.class)
61      public void testNegativePort() {
62          new CookieOrigin("www.apache.org", -80, "/", false);
63      }
64  
65      @SuppressWarnings("unused")
66      @Test(expected=IllegalArgumentException.class)
67      public void testNullPath() {
68          new CookieOrigin("www.apache.org", 80, null, false);
69      }
70  
71      @Test
72      public void testEmptyPath() {
73          final CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "", false);
74          Assert.assertEquals("www.apache.org", origin.getHost());
75          Assert.assertEquals(80, origin.getPort());
76          Assert.assertEquals("/", origin.getPath());
77          Assert.assertFalse(origin.isSecure());
78      }
79  
80  }
81