hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1665996 - in /httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http: auth/TestAuthScope.java impl/client/TestBasicCredentialsProvider.java
Date Wed, 11 Mar 2015 20:28:48 GMT
Author: olegk
Date: Wed Mar 11 20:28:47 2015
New Revision: 1665996

URL: http://svn.apache.org/r1665996
Log:
Test cases for AuthScope

Added:
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/auth/TestAuthScope.java
  (with props)
Modified:
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestBasicCredentialsProvider.java

Added: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/auth/TestAuthScope.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/auth/TestAuthScope.java?rev=1665996&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/auth/TestAuthScope.java
(added)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/auth/TestAuthScope.java
Wed Mar 11 20:28:47 2015
@@ -0,0 +1,168 @@
+/*
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.auth;
+
+import org.apache.http.HttpHost;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests for {@link org.apache.http.auth.AuthScope}.
+ */
+public class TestAuthScope {
+
+    @Test
+    public void testBasics() {
+        final AuthScope authscope = new AuthScope("somehost", 80, "somerealm", "somescheme");
+        Assert.assertEquals("SOMESCHEME", authscope.getScheme());
+        Assert.assertEquals("somehost", authscope.getHost());
+        Assert.assertEquals(80, authscope.getPort());
+        Assert.assertEquals("somerealm", authscope.getRealm());
+        Assert.assertEquals("SOMESCHEME 'somerealm'@somehost:80", authscope.toString());
+    }
+
+    @Test
+    public void testBasicsOptionalRealm() {
+        final AuthScope authscope = new AuthScope("somehost", 80, AuthScope.ANY_REALM, "somescheme");
+        Assert.assertEquals("SOMESCHEME", authscope.getScheme());
+        Assert.assertEquals("somehost", authscope.getHost());
+        Assert.assertEquals(80, authscope.getPort());
+        Assert.assertEquals(null, authscope.getRealm());
+        Assert.assertEquals("SOMESCHEME <any realm>@somehost:80", authscope.toString());
+    }
+
+    @Test
+    public void testBasicsOptionalScheme() {
+        final AuthScope authscope = new AuthScope("somehost", 80, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME);
+        Assert.assertEquals(null, authscope.getScheme());
+        Assert.assertEquals("somehost", authscope.getHost());
+        Assert.assertEquals(80, authscope.getPort());
+        Assert.assertEquals(null, authscope.getRealm());
+        Assert.assertEquals("<any realm>@somehost:80", authscope.toString());
+    }
+
+    @Test
+    public void testBasicsOptionalPort() {
+        final AuthScope authscope = new AuthScope("somehost", AuthScope.ANY_PORT, AuthScope.ANY_REALM,
AuthScope.ANY_SCHEME);
+        Assert.assertEquals(null, authscope.getScheme());
+        Assert.assertEquals("somehost", authscope.getHost());
+        Assert.assertEquals(-1, authscope.getPort());
+        Assert.assertEquals(null, authscope.getRealm());
+        Assert.assertEquals("<any realm>@somehost", authscope.toString());
+    }
+
+    @Test
+    public void testByOrigin() {
+        final HttpHost host = new HttpHost("somehost", 8080, "http");
+        final AuthScope authscope = new AuthScope(host);
+        Assert.assertEquals(null, authscope.getScheme());
+        Assert.assertEquals("somehost", authscope.getHost());
+        Assert.assertEquals(8080, authscope.getPort());
+        Assert.assertEquals(null, authscope.getRealm());
+        Assert.assertEquals(host, authscope.getOrigin());
+        Assert.assertEquals("<any realm>@somehost:8080", authscope.toString());
+    }
+
+    @Test
+    public void testBasicsOptionalHost() {
+        final AuthScope authscope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT,
AuthScope.ANY_REALM, AuthScope.ANY_SCHEME);
+        Assert.assertEquals(null, authscope.getScheme());
+        Assert.assertEquals(null, authscope.getHost());
+        Assert.assertEquals(-1, authscope.getPort());
+        Assert.assertEquals(null, authscope.getRealm());
+        Assert.assertEquals("<any realm>", authscope.toString());
+    }
+
+    @Test
+    public void testScopeMatching() {
+        final AuthScope authscope1 = new AuthScope("somehost", 80, "somerealm", "somescheme");
+        final AuthScope authscope2 = new AuthScope("someotherhost", 80, "somerealm", "somescheme");
+        Assert.assertTrue(authscope1.match(authscope2) < 0);
+
+        int m1 = authscope1.match(
+                new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM,
"somescheme"));
+        int m2 = authscope1.match(
+                new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, "somerealm", AuthScope.ANY_SCHEME));
+        Assert.assertTrue(m2 > m1);
+
+        m1 = authscope1.match(
+                new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM,
"somescheme"));
+        m2 = authscope1.match(
+                new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, "somerealm", AuthScope.ANY_SCHEME));
+        Assert.assertTrue(m2 > m1);
+
+        m1 = authscope1.match(
+                new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, "somerealm", "somescheme"));
+        m2 = authscope1.match(
+                new AuthScope(AuthScope.ANY_HOST, 80, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME));
+        Assert.assertTrue(m2 > m1);
+
+        m1 = authscope1.match(
+                new AuthScope(AuthScope.ANY_HOST, 80, "somerealm", "somescheme"));
+        m2 = authscope1.match(
+                new AuthScope("somehost", AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME));
+        Assert.assertTrue(m2 > m1);
+
+        m1 = authscope1.match(AuthScope.ANY);
+        m2 = authscope1.match(
+                new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM,
"somescheme"));
+        Assert.assertTrue(m2 > m1);
+    }
+
+    @Test
+    public void testEquals() {
+        final AuthScope authscope1 = new AuthScope("somehost", 80, "somerealm", "somescheme");
+        final AuthScope authscope2 = new AuthScope("someotherhost", 80, "somerealm", "somescheme");
+        final AuthScope authscope3 = new AuthScope("somehost", 80, "somerealm", "somescheme");
+        final AuthScope authscope4 = new AuthScope("somehost", 8080, "somerealm", "somescheme");
+        final AuthScope authscope5 = new AuthScope("somehost", 80, "someotherrealm", "somescheme");
+        final AuthScope authscope6 = new AuthScope("somehost", 80, "somerealm", "someotherscheme");
+        Assert.assertTrue(authscope1.equals(authscope1));
+        Assert.assertFalse(authscope1.equals(authscope2));
+        Assert.assertTrue(authscope1.equals(authscope3));
+        Assert.assertFalse(authscope1.equals(authscope4));
+        Assert.assertFalse(authscope1.equals(authscope5));
+        Assert.assertFalse(authscope1.equals(authscope6));
+    }
+
+    @Test
+    public void testHash() {
+        final AuthScope authscope1 = new AuthScope("somehost", 80, "somerealm", "somescheme");
+        final AuthScope authscope2 = new AuthScope("someotherhost", 80, "somerealm", "somescheme");
+        final AuthScope authscope3 = new AuthScope("somehost", 80, "somerealm", "somescheme");
+        final AuthScope authscope4 = new AuthScope("somehost", 8080, "somerealm", "somescheme");
+        final AuthScope authscope5 = new AuthScope("somehost", 80, "someotherrealm", "somescheme");
+        final AuthScope authscope6 = new AuthScope("somehost", 80, "somerealm", "someotherscheme");
+        Assert.assertTrue(authscope1.hashCode() == authscope1.hashCode());
+        Assert.assertFalse(authscope1.hashCode() == authscope2.hashCode());
+        Assert.assertTrue(authscope1.hashCode() == authscope3.hashCode());
+        Assert.assertFalse(authscope1.hashCode() == authscope4.hashCode());
+        Assert.assertFalse(authscope1.hashCode() == authscope5.hashCode());
+        Assert.assertFalse(authscope1.hashCode() == authscope6.hashCode());
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/auth/TestAuthScope.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/auth/TestAuthScope.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/auth/TestAuthScope.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestBasicCredentialsProvider.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestBasicCredentialsProvider.java?rev=1665996&r1=1665995&r2=1665996&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestBasicCredentialsProvider.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestBasicCredentialsProvider.java
Wed Mar 11 20:28:47 2015
@@ -125,42 +125,6 @@ public class TestBasicCredentialsProvide
     }
 
     @Test
-    public void testScopeMatching() {
-        final AuthScope authscope1 = new AuthScope("somehost", 80, "somerealm", "somescheme");
-        final AuthScope authscope2 = new AuthScope("someotherhost", 80, "somerealm", "somescheme");
-        Assert.assertTrue(authscope1.match(authscope2) < 0);
-
-        int m1 = authscope1.match(
-            new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, "somescheme"));
-        int m2 = authscope1.match(
-            new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, "somerealm", AuthScope.ANY_SCHEME));
-        Assert.assertTrue(m2 > m1);
-
-        m1 = authscope1.match(
-            new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, "somescheme"));
-        m2 = authscope1.match(
-            new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, "somerealm", AuthScope.ANY_SCHEME));
-        Assert.assertTrue(m2 > m1);
-
-        m1 = authscope1.match(
-            new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, "somerealm", "somescheme"));
-        m2 = authscope1.match(
-            new AuthScope(AuthScope.ANY_HOST, 80, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME));
-        Assert.assertTrue(m2 > m1);
-
-        m1 = authscope1.match(
-            new AuthScope(AuthScope.ANY_HOST, 80, "somerealm", "somescheme"));
-        m2 = authscope1.match(
-            new AuthScope("somehost", AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME));
-        Assert.assertTrue(m2 > m1);
-
-        m1 = authscope1.match(AuthScope.ANY);
-        m2 = authscope1.match(
-            new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, "somescheme"));
-        Assert.assertTrue(m2 > m1);
-    }
-
-    @Test
     public void testCredentialsMatching() {
         final Credentials creds1 = new UsernamePasswordCredentials("name1", "pass1");
         final Credentials creds2 = new UsernamePasswordCredentials("name2", "pass2");



Mime
View raw message