// Path: http/src/main/java/org/kaazing/netx/http/internal/auth/RealmUtils.java
// public final class RealmUtils {
// 
//     private RealmUtils() {
//         // prevent object creation
//     }
// 
//     private static final String REALM_REGEX = "(.*)\\s?(?i:realm=)(\"(.*)\")(.*)";
//     private static final Pattern REALM_PATTERN = Pattern.compile(REALM_REGEX);
// 
//     /**
//      * A realm parameter is a valid authentication parameter for all authentication schemes
//      * according to <a href="http://tools.ietf.org/html/rfc2617#section-2.1">RFC 2617 Section 2.1"</a>.
//      *
//      * {@code}
//      *     The realm directive (case-insensitive) is required for all
//      *     authentication schemes that issue a challenge. The realm value
//      *     (case-sensitive), in combination with the canonical root URL (the
//      *     absoluteURI for the server whose abs_path is empty) of the server
//      *     being accessed, defines the protection space.
//      * {@code}
//      *
//      * @param challengeRequest the challenge request to extract a realm from
//      *
//      * @return the unquoted realm parameter value if present, or {@code null} if no such parameter exists.
//      */
//     public static String getRealm(ChallengeRequest challengeRequest) {
//         String authenticationParameters = challengeRequest.getAuthenticationParameters();
//         if (authenticationParameters == null) {
//             return null;
//         }
//         Matcher m = REALM_PATTERN.matcher(authenticationParameters);
//         if (m.matches() && m.groupCount() >= 3) {
//             return m.group(3);
//         }
//         return null;
//     }
// }


import org.junit.Assert;
import org.junit.Test;
import org.kaazing.netx.http.internal.auth.RealmUtils;
        ChallengeRequest challengeRequest = new ChallengeRequest(DEFAULT_LOCATION, null);
        Assert.assertNull(challengeRequest.getAuthenticationScheme());
        Assert.assertNull(challengeRequest.getAuthenticationParameters());
    }

    @Test
    public void testEmptyChallenge() throws Exception {
        ChallengeRequest challengeRequest = new ChallengeRequest(DEFAULT_LOCATION, "");
        Assert.assertNull(challengeRequest.getAuthenticationScheme());
        Assert.assertNull(challengeRequest.getAuthenticationParameters());
    }

    @Test
    public void testBasicChallenge() throws Exception {
        ChallengeRequest challengeRequest = new ChallengeRequest(DEFAULT_LOCATION, "Application Basic");
        Assert.assertEquals("Application Basic", challengeRequest.getAuthenticationScheme());
        Assert.assertNull(challengeRequest.getAuthenticationParameters());

        challengeRequest = new ChallengeRequest(DEFAULT_LOCATION, "Application Basic ");
        Assert.assertEquals("Application Basic", challengeRequest.getAuthenticationScheme());
        Assert.assertNull(challengeRequest.getAuthenticationParameters());

        challengeRequest = new ChallengeRequest(DEFAULT_LOCATION, "Application Basic AuthData");
        Assert.assertEquals("Application Basic", challengeRequest.getAuthenticationScheme());
        Assert.assertEquals("AuthData", challengeRequest.getAuthenticationParameters());
    }

    @Test
    public void testRealmParameter() throws Exception {
        ChallengeRequest challengeRequest = new ChallengeRequest(DEFAULT_LOCATION, "Application Basic");

// Path: http/src/main/java/org/kaazing/netx/http/internal/auth/RealmUtils.java
// public final class RealmUtils {
// 
//     private RealmUtils() {
//         // prevent object creation
//     }
// 
//     private static final String REALM_REGEX = "(.*)\\s?(?i:realm=)(\"(.*)\")(.*)";
//     private static final Pattern REALM_PATTERN = Pattern.compile(REALM_REGEX);
// 
//     /**
//      * A realm parameter is a valid authentication parameter for all authentication schemes
//      * according to <a href="http://tools.ietf.org/html/rfc2617#section-2.1">RFC 2617 Section 2.1"</a>.
//      *
//      * {@code}
//      *     The realm directive (case-insensitive) is required for all
//      *     authentication schemes that issue a challenge. The realm value
//      *     (case-sensitive), in combination with the canonical root URL (the
//      *     absoluteURI for the server whose abs_path is empty) of the server
//      *     being accessed, defines the protection space.
//      * {@code}
//      *
//      * @param challengeRequest the challenge request to extract a realm from
//      *
//      * @return the unquoted realm parameter value if present, or {@code null} if no such parameter exists.
//      */
//     public static String getRealm(ChallengeRequest challengeRequest) {
//         String authenticationParameters = challengeRequest.getAuthenticationParameters();
//         if (authenticationParameters == null) {
//             return null;
//         }
//         Matcher m = REALM_PATTERN.matcher(authenticationParameters);
//         if (m.matches() && m.groupCount() >= 3) {
//             return m.group(3);
//         }
//         return null;
//     }
// }


// Path: http/src/test/java/org/kaazing/netx/http/auth/ChallengeRequestTest.java
import org.junit.Assert;
import org.junit.Test;
import org.kaazing.netx.http.internal.auth.RealmUtils;

        ChallengeRequest challengeRequest = new ChallengeRequest(DEFAULT_LOCATION, null);
        Assert.assertNull(challengeRequest.getAuthenticationScheme());
        Assert.assertNull(challengeRequest.getAuthenticationParameters());
    }

    @Test
    public void testEmptyChallenge() throws Exception {
        ChallengeRequest challengeRequest = new ChallengeRequest(DEFAULT_LOCATION, "");
        Assert.assertNull(challengeRequest.getAuthenticationScheme());
        Assert.assertNull(challengeRequest.getAuthenticationParameters());
    }

    @Test
    public void testBasicChallenge() throws Exception {
        ChallengeRequest challengeRequest = new ChallengeRequest(DEFAULT_LOCATION, "Application Basic");
        Assert.assertEquals("Application Basic", challengeRequest.getAuthenticationScheme());
        Assert.assertNull(challengeRequest.getAuthenticationParameters());

        challengeRequest = new ChallengeRequest(DEFAULT_LOCATION, "Application Basic ");
        Assert.assertEquals("Application Basic", challengeRequest.getAuthenticationScheme());
        Assert.assertNull(challengeRequest.getAuthenticationParameters());

        challengeRequest = new ChallengeRequest(DEFAULT_LOCATION, "Application Basic AuthData");
        Assert.assertEquals("Application Basic", challengeRequest.getAuthenticationScheme());
        Assert.assertEquals("AuthData", challengeRequest.getAuthenticationParameters());
    }

    @Test
    public void testRealmParameter() throws Exception {
        ChallengeRequest challengeRequest = new ChallengeRequest(DEFAULT_LOCATION, "Application Basic");

        Assert.assertNull(RealmUtils.getRealm(challengeRequest));
