incubator-heraldry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ket...@apache.org
Subject svn commit: r463013 [8/8] - in /incubator/heraldry/libraries/java: ./ trunk/ trunk/META-INF/ trunk/bin/ trunk/bin/com/ trunk/bin/com/janrain/ trunk/bin/com/janrain/openid/ trunk/bin/com/janrain/openid/consumer/ trunk/bin/com/janrain/openid/store/ trunk...
Date Wed, 11 Oct 2006 22:33:11 GMT
Added: incubator/heraldry/libraries/java/trunk/test/src/com/janrain/url/UrlConnectionFetcherTest.java
URL: http://svn.apache.org/viewvc/incubator/heraldry/libraries/java/trunk/test/src/com/janrain/url/UrlConnectionFetcherTest.java?view=auto&rev=463013
==============================================================================
--- incubator/heraldry/libraries/java/trunk/test/src/com/janrain/url/UrlConnectionFetcherTest.java
(added)
+++ incubator/heraldry/libraries/java/trunk/test/src/com/janrain/url/UrlConnectionFetcherTest.java
Wed Oct 11 15:33:04 2006
@@ -0,0 +1,376 @@
+/*
+ * UrlConnectionFetcherTest.java JUnit based test Created on December 15, 2005,
+ * 1:55 PM
+ */
+
+package com.janrain.url;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * @author JanRain, Inc.
+ */
+public class UrlConnectionFetcherTest extends TestCase
+{
+    private static InetAddress host;
+
+    private static int port = 9111;
+
+    private static String base;
+
+    static
+    {
+        try
+        {
+            host = InetAddress.getByName("localhost");
+        }
+        catch (UnknownHostException e)
+        {
+            // I suppose this could possibly happen on a windows machine
+            // without TCP/IP installed.
+        }
+
+        base = "http://localhost:" + port;
+        Logger.getLogger("com.janrain.openid").setLevel(Level.SEVERE);
+    }
+
+    public UrlConnectionFetcherTest(String testName)
+    {
+        super(testName);
+    }
+
+    HTTPFetcher oidFetch;
+
+    Thread t;
+
+    protected void setUp() throws Exception
+    {
+        oidFetch = HTTPFetcher.getFetcher();
+        t = new Thread(new FakeHTTPServer());
+        t.setDaemon(true);
+        t.start();
+        synchronized (this)
+        {
+            try
+            {
+                this.wait();
+            }
+            catch (InterruptedException e)
+            {
+                // ignore
+            }
+        }
+    }
+
+    protected void tearDown() throws Exception
+    {
+    }
+
+    private class FakeHTTPServer implements Runnable
+    {
+        boolean accepting = true;
+
+        public void run()
+        {
+            try
+            {
+                ServerSocket ss = new ServerSocket(port, -1, host);
+                synchronized (UrlConnectionFetcherTest.this)
+                {
+                    UrlConnectionFetcherTest.this.notify();
+                }
+                while (accepting)
+                {
+                    accepting = false;
+                    Socket s = ss.accept();
+
+                    BufferedReader r = new BufferedReader(
+                            new InputStreamReader(s.getInputStream(), "UTF-8"));
+                    String request = r.readLine();
+
+                    int contentLength = 0;
+                    StringBuffer headers = new StringBuffer();
+                    for (String l = r.readLine(); !l.equals(""); l = r
+                            .readLine())
+                    {
+                        if (l.startsWith("Content-Length: "))
+                        {
+                            contentLength = Integer.parseInt(l.substring(16));
+                        }
+                        headers.append(l);
+                        headers.append("\r\n");
+                    }
+                    StringBuffer body = new StringBuffer();
+
+                    char [] c = new char[1024];
+                    while (contentLength > 0)
+                    {
+                        int read = r.read(c, 0, Math.min(contentLength,
+                                c.length));
+                        if (read == -1) break;
+
+                        body.append(c, 0, read);
+                        contentLength -= read;
+                    }
+
+                    String response = getResponse(request, headers.toString(),
+                            body.toString());
+                    Writer w = new OutputStreamWriter(s.getOutputStream(),
+                            "UTF-8");
+                    w.write(response);
+                    w.flush();
+
+                    s.close();
+                }
+                ss.close();
+            }
+            catch (IOException e)
+            {
+                // nothing really can be done, other than yelling about it.
+                e.printStackTrace();
+            }
+        }
+
+        private String getResponse(String request, String headers, String body)
+        {
+            String [] parts = request.split(" ");
+
+            String method = parts[0];
+            String path = parts[1];
+
+            if (path.equals("/closed"))
+            {
+                return "";
+            }
+
+            // all other requests should be for /number
+            StringBuffer result = new StringBuffer("HTTP/1.1 ");
+
+            result.append(path.substring(1));
+            result.append(" CALLOO CALLAY\r\n");
+
+            if (method.equals("GET"))
+            {
+                if (path.charAt(1) == '3')
+                {
+                    result.append("Location: ");
+                    result.append(base);
+                    result.append("/200\r\n");
+                    accepting = true;
+                }
+
+                result
+                        .append("Content-Type: text/plain; charset=utf-8\r\n\r\n");
+
+                result.append("This is the world's most boring content.\r\n");
+
+            }
+            else if (method.equals("POST"))
+            {
+                result.append("Content-Type: text/plain\r\n\r\n");
+
+                result.append("This is what you posted:\r\n");
+                result.append(body);
+            }
+            return result.toString();
+        }
+    }
+
+    public static Test suite()
+    {
+        TestSuite suite = new TestSuite(UrlConnectionFetcherTest.class);
+
+        return suite;
+    }
+
+    public void testGet200()
+    {
+        System.out.println("testGet200");
+        FetchResponse f = oidFetch.fetch(base + "/200");
+        assertEquals("text/plain; charset=utf-8", ((List)f.getHeaders().get(
+                "Content-Type")).get(0));
+        assertEquals(200, f.getStatusCode());
+        assertEquals(base + "/200", f.getFinalUrl());
+        assertEquals("This is the world's most boring content.\r\n", f
+                .getContent());
+    }
+
+    public void testGet301()
+    {
+        System.out.println("testGet301");
+        FetchResponse f = oidFetch.fetch(base + "/301");
+        assertEquals(200, f.getStatusCode());
+        assertEquals(base + "/200", f.getFinalUrl());
+        assertEquals("This is the world's most boring content.\r\n", f
+                .getContent());
+    }
+
+    public void testGet302()
+    {
+        System.out.println("testGet302");
+        FetchResponse f = oidFetch.fetch(base + "/302");
+        assertEquals(200, f.getStatusCode());
+        assertEquals(base + "/200", f.getFinalUrl());
+        assertEquals("This is the world's most boring content.\r\n", f
+                .getContent());
+    }
+
+    public void testGet303()
+    {
+        System.out.println("testGet303");
+        FetchResponse f = oidFetch.fetch(base + "/303");
+        assertEquals(200, f.getStatusCode());
+        assertEquals(base + "/200", f.getFinalUrl());
+        assertEquals("This is the world's most boring content.\r\n", f
+                .getContent());
+    }
+
+    public void testGet307()
+    {
+        System.out.println("testGet307");
+        FetchResponse f = oidFetch.fetch(base + "/307");
+        assertEquals(200, f.getStatusCode());
+        assertEquals(base + "/200", f.getFinalUrl());
+        assertEquals("This is the world's most boring content.\r\n", f
+                .getContent());
+    }
+
+    public void testGet400()
+    {
+        System.out.println("testGet400");
+        FetchResponse f = oidFetch.fetch(base + "/400");
+        assertEquals(400, f.getStatusCode());
+        assertEquals(base + "/400", f.getFinalUrl());
+        assertEquals("This is the world's most boring content.\r\n", f
+                .getContent());
+    }
+
+    public void testGet403()
+    {
+        System.out.println("testGet403");
+        FetchResponse f = oidFetch.fetch(base + "/403");
+        assertEquals(403, f.getStatusCode());
+        assertEquals(base + "/403", f.getFinalUrl());
+        assertEquals("This is the world's most boring content.\r\n", f
+                .getContent());
+    }
+
+    public void testGet404()
+    {
+        System.out.println("testGet404");
+        FetchResponse f = oidFetch.fetch(base + "/404");
+        assertEquals(404, f.getStatusCode());
+        assertEquals(base + "/404", f.getFinalUrl());
+        assertEquals("This is the world's most boring content.\r\n", f
+                .getContent());
+    }
+
+    public void testGet500()
+    {
+        System.out.println("testGet500");
+        FetchResponse f = oidFetch.fetch(base + "/500");
+        assertEquals(500, f.getStatusCode());
+        assertEquals(base + "/500", f.getFinalUrl());
+        assertEquals("This is the world's most boring content.\r\n", f
+                .getContent());
+    }
+
+    public void testGet503()
+    {
+        System.out.println("testGet503");
+        FetchResponse f = oidFetch.fetch(base + "/503");
+        assertEquals(503, f.getStatusCode());
+        assertEquals(base + "/503", f.getFinalUrl());
+        assertEquals("This is the world's most boring content.\r\n", f
+                .getContent());
+    }
+
+    public void testGetInvalid()
+    {
+        System.out.println("testGetInvalid");
+        assertNull(oidFetch.fetch(base + "/closed"));
+        assertNull(oidFetch.fetch("http://invalid.janrain.com"));
+        assertNull(oidFetch.fetch("not:a/url"));
+        assertNull(oidFetch.fetch("ftp://janrain.com/pub/"));
+    }
+
+    public void testPost200()
+    {
+        System.out.println("testPost200");
+        FetchResponse f = oidFetch.fetch(base + "/200", "one fish, two fish");
+        assertEquals(200, f.getStatusCode());
+        assertEquals(base + "/200", f.getFinalUrl());
+        assertEquals("This is what you posted:\r\none fish, two fish", f
+                .getContent());
+    }
+
+    public void testPost400()
+    {
+        System.out.println("testPost400");
+        FetchResponse f = oidFetch.fetch(base + "/400", "red fish, blue fish");
+        assertEquals(400, f.getStatusCode());
+        assertEquals(base + "/400", f.getFinalUrl());
+        assertEquals("This is what you posted:\r\nred fish, blue fish", f
+                .getContent());
+    }
+
+    public void testPost403()
+    {
+        System.out.println("testPost403");
+        FetchResponse f = oidFetch.fetch(base + "/403", "bob");
+        assertEquals(403, f.getStatusCode());
+        assertEquals(base + "/403", f.getFinalUrl());
+        assertEquals("This is what you posted:\r\nbob", f.getContent());
+    }
+
+    public void testPost404()
+    {
+        System.out.println("testPost404");
+        FetchResponse f = oidFetch.fetch(base + "/404", "a=b&c=d");
+        assertEquals(404, f.getStatusCode());
+        assertEquals(base + "/404", f.getFinalUrl());
+        assertEquals("This is what you posted:\r\na=b&c=d", f.getContent());
+    }
+
+    public void testPost500()
+    {
+        System.out.println("testPost500");
+        FetchResponse f = oidFetch.fetch(base + "/500", "la brea");
+        assertEquals(500, f.getStatusCode());
+        assertEquals(base + "/500", f.getFinalUrl());
+        assertEquals("This is what you posted:\r\nla brea", f.getContent());
+    }
+
+    public void testPost503()
+    {
+        System.out.println("testPost503");
+        FetchResponse f = oidFetch.fetch(base + "/503", "Me!");
+        assertEquals(503, f.getStatusCode());
+        assertEquals(base + "/503", f.getFinalUrl());
+        assertEquals("This is what you posted:\r\nMe!", f.getContent());
+    }
+
+    public void testPostInvalid()
+    {
+        System.out.println("testPostInvalid");
+        assertNull(oidFetch.fetch(base + "/closed", ""));
+        assertNull(oidFetch.fetch("http://invalid.janrain.com", ""));
+        assertNull(oidFetch.fetch("not:a/url", ""));
+        assertNull(oidFetch.fetch("ftp://janrain.com/pub/", ""));
+    }
+}

Added: incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/DiscoveryResultTest.java
URL: http://svn.apache.org/viewvc/incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/DiscoveryResultTest.java?view=auto&rev=463013
==============================================================================
--- incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/DiscoveryResultTest.java
(added)
+++ incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/DiscoveryResultTest.java
Wed Oct 11 15:33:04 2006
@@ -0,0 +1,330 @@
+package com.janrain.yadis;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import com.janrain.url.FetchResponse;
+import com.janrain.url.HTTPFetcher;
+
+public class DiscoveryResultTest extends TestCase
+{
+    public static Test suite()
+    {
+        TestSuite suite = new TestSuite();
+        suite.addTest(new SecondGetTester());
+
+        DiscoveryTest [] tests = {
+                new DiscoveryTest(true, "equiv", "equiv", "xrds"),
+                new DiscoveryTest(true, "header", "header", "xrds"),
+                new DiscoveryTest(true, "lowercase_header", "lowercase_header",
+                        "xrds"),
+                new DiscoveryTest(true, "xrds", "xrds", "xrds"),
+                new DiscoveryTest(true, "xrds_ctparam", "xrds_ctparam",
+                        "xrds_ctparam"),
+                new DiscoveryTest(true, "xrds_ctcase", "xrds_ctcase",
+                        "xrds_ctcase"),
+                new DiscoveryTest(false, "xrds_html", "xrds_html", "xrds_html"),
+                new DiscoveryTest(true, "redir_equiv", "equiv", "xrds"),
+                new DiscoveryTest(true, "redir_header", "header", "xrds"),
+                new DiscoveryTest(true, "redir_xrds", "xrds", "xrds"),
+                new DiscoveryTest(false, "redir_xrds_html", "xrds_html",
+                        "xrds_html"),
+                new DiscoveryTest(true, "redir_redir_equiv", "equiv", "xrds"),
+                new DiscoveryTest(false, "404_server_response", null, null),
+                new DiscoveryTest(false, "404_with_header", null, null),
+                new DiscoveryTest(false, "404_with_meta", null, null),
+                new DiscoveryTest(false, "201_server_response", null, null),
+                new DiscoveryTest(false, "500_server_response", null, null)};
+
+        for (int i = 0; i < tests.length; i++)
+        {
+            suite.addTest(tests[i]);
+        }
+
+        return suite;
+    }
+
+    private static class SecondGetTester extends TestCase
+    {
+        public SecondGetTester()
+        {
+            super("testSecondGet");
+        }
+
+        class Fetcher extends HTTPFetcher
+        {
+            private int count = 0;
+
+            public FetchResponse fetch(String url, String body, Map headers)
+            {
+                if (++count == 1)
+                {
+                    Map rh = new HashMap();
+                    rh.put("X-XRDS-Location".toLowerCase(),
+                            "http://unittest/404");
+                    return new FetchResponse(200, url, new byte[0], "UTF-8", rh);
+                }
+                else
+                {
+                    return new FetchResponse(404, url, new byte[0], "UTF-8",
+                            null);
+                }
+            }
+        }
+
+        public void runTest()
+        {
+            HTTPFetcher old = HTTPFetcher.getFetcher();
+            HTTPFetcher.setFetcher(new Fetcher());
+
+            String uri = "http://something.unittest/";
+            try
+            {
+                DiscoveryResult.fromURI(uri);
+                fail("DiscoveryFailure wasn't thrown");
+            }
+            catch (DiscoveryFailure d)
+            {
+                // this is the expected case
+            }
+
+            HTTPFetcher.setFetcher(old);
+        }
+    }
+
+    private static class DiscoveryTest extends TestCase
+    {
+        private static final String baseUrl = "http://invalid.unittest/";
+
+        private static String exampleXrds = read("example-xrds.xml");
+        private static String testData = read("test1-discover.txt");
+        private static Map parsedTests = new HashMap();
+        private static int count = 1;
+
+        private static String read(String resourceName)
+        {
+            InputStream is = null;
+            try
+            {
+                is = DiscoveryTest.class.getResourceAsStream(resourceName);
+                BufferedReader br = new BufferedReader(new InputStreamReader(
+                        is, "UTF-8"));
+
+                char [] buf = new char[1024];
+                StringBuffer result = new StringBuffer();
+                int c;
+                while ((c = br.read(buf)) >= 0)
+                {
+                    result.append(buf, 0, c);
+                }
+                return result.toString();
+            }
+            catch (IOException e)
+            {
+                throw new RuntimeException(e);
+            }
+            finally
+            {
+                try
+                {
+                    if (is != null) is.close();
+                }
+                catch (IOException e)
+                {
+                    // ignore
+                }
+            }
+        }
+
+        private static String getData(String name) throws IOException
+        {
+            if (parsedTests.isEmpty())
+            {
+                String [] cases = testData.split("\f\n");
+                for (int i = 0; i < cases.length; i++)
+                {
+                    String [] dat = cases[i].split("\n", 2);
+                    parsedTests.put(dat[0], dat[1]);
+                }
+            }
+            return (String)parsedTests.get(name);
+        }
+
+        private String inputName;
+        private String idName;
+        private String resultName;
+        private boolean success;
+
+        private HTTPFetcher old;
+        private String inputUrl;
+        private DiscoveryResult expected;
+
+        class Fetcher extends HTTPFetcher
+        {
+            private Pattern statusHeaderPat = Pattern.compile(
+                    "Status: (\\d+) .*?$", Pattern.MULTILINE);
+
+            private FetchResponse makeResponse(String finalUrl, String data)
+            {
+                Matcher m = statusHeaderPat.matcher(data);
+                String [] parts = data.split("\n\n", 2);
+                Map headers = new HashMap();
+                String [] hlines = parts[0].split("\n");
+                for (int i = 0; i < hlines.length; i++)
+                {
+                    String [] kv = hlines[i].split(":", 2);
+                    String k = kv[0].toLowerCase().trim();
+                    String v = kv[1].trim();
+                    headers.put(k, v);
+                }
+                m.find();
+                int status = Integer.parseInt(m.group(1));
+                try
+                {
+                    return new FetchResponse(status, finalUrl, parts[1]
+                            .getBytes("UTF-8"), "UTF-8", headers);
+                }
+                catch (UnsupportedEncodingException e)
+                {
+                    throw new RuntimeException("This won't happen");
+                }
+            }
+
+            public FetchResponse fetch(String url, String body, Map headers)
+            {
+                try
+                {
+                    Pattern p = Pattern.compile(".*?//.*?/(.*)");
+                    String currentUrl = url;
+                    while (true)
+                    {
+                        Matcher m = p.matcher(currentUrl);
+                        m.matches();
+                        String path = m.group(1);
+                        String data = generateSample(path);
+                        if (data == null)
+                        {
+                            return new FetchResponse(404, currentUrl,
+                                    new byte[0], "UTF-8", new HashMap());
+                        }
+                        FetchResponse response = makeResponse(currentUrl, data);
+                        int status = response.getStatusCode();
+                        if (status == 301 || status == 302 || status == 303
+                                || status == 307)
+                        {
+                            currentUrl = (String)response.getHeaders().get(
+                                    "location");
+                        }
+                        else
+                        {
+                            return response;
+                        }
+                    }
+                }
+                catch (IOException e)
+                {
+                    return null;
+                }
+            }
+        }
+
+        public DiscoveryTest(boolean success, String inputName, String idName,
+                             String resultName)
+        {
+            super("DiscoveryTest " + ++count + ": " + inputName);
+            this.inputName = inputName;
+            this.idName = idName;
+            this.resultName = resultName;
+            this.success = success;
+        }
+
+        private static String generateSample(String sampleName)
+                throws IOException
+        {
+            String template = getData(sampleName);
+
+            String mangledExample = exampleXrds.replaceAll("\\$", "\\\\\\$");
+
+            template = template.replaceAll("URL_BASE/", baseUrl);
+            template = template.replaceAll("<XRDS Content>", mangledExample);
+            template = template.replaceAll("YADIS_HEADER",
+                    Constants.HEADER_NAME);
+            template = template.replaceAll("NAME", sampleName);
+
+            return template;
+        }
+
+        protected void setUp() throws Exception
+        {
+            old = HTTPFetcher.getFetcher();
+            HTTPFetcher.setFetcher(new Fetcher());
+
+            inputUrl = baseUrl + inputName;
+            if (idName == null)
+            {
+                assertNull(resultName);
+                return;
+            }
+            String sample = generateSample(resultName);
+            String [] parts = sample.split("\n\n", 2);
+            String [] headerLines = parts[0].split("\n");
+
+            String ctype = null;
+            for (int i = 0; i < headerLines.length; i++)
+            {
+                if (headerLines[i].startsWith("Content-Type:"))
+                {
+                    ctype = headerLines[i].split(":", 2)[1].trim();
+                    break;
+                }
+            }
+            expected = new DiscoveryResult(inputUrl);
+            expected.normalizedUri = baseUrl + idName;
+            if (success)
+            {
+                expected.xrdsUri = baseUrl + resultName;
+            }
+            expected.contentType = ctype;
+            expected.content = parts[1].getBytes("UTF-8");
+            expected.encoding = "UTF-8";
+        }
+
+        protected void tearDown() throws Exception
+        {
+            HTTPFetcher.setFetcher(old);
+        }
+
+        protected void runTest() throws Throwable
+        {
+            if (expected == null)
+            {
+                try
+                {
+                    DiscoveryResult.fromURI(inputUrl);
+                    fail("Should have thrown a discovery error");
+                }
+                catch (DiscoveryFailure d)
+                {
+                    // expected
+                }
+            }
+            else
+            {
+                DiscoveryResult result = DiscoveryResult.fromURI(inputUrl);
+                assertEquals(inputUrl, result.getRequestUri());
+                assertEquals(expected, result);
+            }
+        }
+    }
+}

Added: incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/ParseHTMLTest.java
URL: http://svn.apache.org/viewvc/incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/ParseHTMLTest.java?view=auto&rev=463013
==============================================================================
--- incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/ParseHTMLTest.java
(added)
+++ incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/ParseHTMLTest.java
Wed Oct 11 15:33:04 2006
@@ -0,0 +1,117 @@
+package com.janrain.yadis;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+
+import com.janrain.url.FetchResponse;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class ParseHTMLTest extends TestCase
+{
+    private String expected;
+
+    private FetchResponse in;
+
+    public ParseHTMLTest(String testname, String expected, String input)
+    {
+        super(testname);
+        String e = "UTF-8";
+        try
+        {
+            in = new FetchResponse(-1, null, input.getBytes(e), e, null);
+        }
+        catch (UnsupportedEncodingException ue)
+        {
+            // won't happen
+        }
+
+        this.expected = expected;
+    }
+
+    public void runTest()
+    {
+        String actual = ParseHTML.findHTMLMeta(in);
+        if (actual == null)
+        {
+            boolean passed = expected.equals("EOF") || expected.equals("None");
+            assertTrue(expected + " isn't null", passed);
+        }
+        else
+        {
+            assertEquals(expected, actual);
+        }
+    }
+
+    public static Test suite()
+    {
+        TestSuite suite = new TestSuite();
+
+        InputStream is = null;
+        try
+        {
+            is = ParseHTMLTest.class.getResourceAsStream("test1-parsehtml.txt");
+            Reader r = new InputStreamReader(is, "UTF-8");
+            BufferedReader br = new BufferedReader(r);
+
+            int num = 0;
+            boolean eof = false;
+            while (!eof)
+            {
+                num++;
+                StringBuffer c = new StringBuffer();
+
+                while (true)
+                {
+                    String s = br.readLine();
+
+                    if (s == null)
+                    {
+                        eof = true;
+                        break;
+                    }
+
+                    if (s.equals("\f"))
+                    {
+                        break;
+                    }
+
+                    c.append(s);
+                    c.append('\n');
+                }
+                if (!eof)
+                {
+                    String [] parts = c.toString().split("\n", 2);
+                    suite.addTest(new ParseHTMLTest("case " + num, parts[0],
+                            parts[1]));
+                }
+            }
+        }
+        catch (IOException e)
+        {
+            throw new RuntimeException(e);
+        }
+        finally
+        {
+            try
+            {
+                if (is != null)
+                {
+                    is.close();
+                }
+            }
+            catch (IOException e)
+            {
+                // nothing to do
+            }
+        }
+
+        return suite;
+    }
+}

Added: incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/accept.txt
URL: http://svn.apache.org/viewvc/incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/accept.txt?view=auto&rev=463013
==============================================================================
--- incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/accept.txt (added)
+++ incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/accept.txt Wed Oct
11 15:33:04 2006
@@ -0,0 +1,118 @@
+# Accept: [Accept: header value from RFC2616,
+#     http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html]
+# Available: [whitespace-separated content types]
+# Expected: [Accept-header like list, containing the available content
+#     types with their q-values]
+
+Accept: */*
+Available: text/plain
+Expected: text/plain; q=1.0
+
+Accept: */*
+Available: text/plain, text/html
+Expected: text/plain; q=1.0, text/html; q=1.0
+
+# The order matters
+Accept: */*
+Available: text/html, text/plain
+Expected: text/html; q=1.0, text/plain; q=1.0
+
+Accept: text/*, */*; q=0.9
+Available: text/plain, image/jpeg
+Expected: text/plain; q=1.0, image/jpeg; q=0.9
+
+Accept: text/*, */*; q=0.9
+Available: image/jpeg, text/plain
+Expected: text/plain; q=1.0, image/jpeg; q=0.9
+
+# wildcard subtypes still reject differing main types
+Accept: text/*
+Available: image/jpeg, text/plain
+Expected: text/plain; q=1.0
+
+Accept: text/html
+Available: text/html
+Expected: text/html; q=1.0
+
+Accept: text/html, text/*
+Available: text/html
+Expected: text/html; q=1.0
+
+Accept: text/html, text/*
+Available: text/plain, text/html
+Expected: text/plain; q=1.0, text/html; q=1.0
+
+Accept: text/html, text/*; q=0.9
+Available: text/plain, text/html
+Expected: text/html; q=1.0, text/plain; q=0.9
+
+# If a more specific type has a higher q-value, then the higher value wins
+Accept: text/*; q=0.9, text/html
+Available: text/plain, text/html
+Expected: text/html; q=1.0, text/plain; q=0.9
+
+Accept: */*, text/*; q=0.9, text/html; q=0.1
+Available: text/plain, text/html, image/monkeys
+Expected: image/monkeys; q=1.0, text/plain; q=0.9, text/html; q=0.1
+
+Accept: text/*, text/html; q=0
+Available: text/html
+Expected:
+
+Accept: text/*, text/html; q=0
+Available: text/html, text/plain
+Expected: text/plain; q=1.0
+
+Accept: text/html
+Available: text/plain
+Expected:
+
+Accept: application/xrds+xml, text/html; q=0.9
+Available: application/xrds+xml, text/html
+Expected: application/xrds+xml; q=1.0, text/html; q=0.9
+
+Accept: application/xrds+xml, */*; q=0.9
+Available: application/xrds+xml, text/html
+Expected: application/xrds+xml; q=1.0, text/html; q=0.9
+
+Accept: application/xrds+xml, application/xhtml+xml; q=0.9, text/html; q=0.8, text/xml; q=0.7
+Available: application/xrds+xml, text/html
+Expected: application/xrds+xml; q=1.0, text/html; q=0.8
+
+# See http://www.rfc-editor.org/rfc/rfc3023.txt, section A.13
+Accept: application/xrds
+Available: application/xrds+xml
+Expected:
+
+Accept: application/xrds+xml
+Available: application/xrds
+Expected:
+
+Accept: application/xml
+Available: application/xrds+xml
+Expected:
+
+Available: application/xrds+xml
+Accept: application/xml
+Expected:
+
+
+
+#################################################
+# The tests below this line are documentation of how this library
+# works. If the implementation changes, it's acceptable to change the
+# test to reflect that. These are specified so that we can make sure
+# that the current implementation actually works the way that we
+# expect it to given these inputs.
+
+Accept: text/html;level=1
+Available: text/html
+Expected: text/html; q=1.0
+
+Accept: text/html; level=1, text/html; level=9; q=0.1
+Available: text/html
+Expected: text/html; q=1.0
+
+Accept: text/html; level=9; q=0.1, text/html; level=1
+Available: text/html
+Expected: text/html; q=1.0

Added: incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/example-xrds.xml
URL: http://svn.apache.org/viewvc/incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/example-xrds.xml?view=auto&rev=463013
==============================================================================
--- incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/example-xrds.xml (added)
+++ incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/example-xrds.xml Wed
Oct 11 15:33:04 2006
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Sample XRDS file at: NAME -->
+<xrds:XRDS
+    xmlns:xrds="xri://$xrds"
+    xmlns="xri://$xrd*($v*2.0)">
+  <XRD>
+
+    <Service priority="0">
+      <Type>http://example.com/</Type>
+      <URI>http://www.openidenabled.com/</URI>
+    </Service>
+
+  </XRD>
+</xrds:XRDS>

Added: incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/no-xrd.xml
URL: http://svn.apache.org/viewvc/incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/no-xrd.xml?view=auto&rev=463013
==============================================================================
--- incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/no-xrd.xml (added)
+++ incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/no-xrd.xml Wed Oct
11 15:33:04 2006
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xrds:XRDS
+    xmlns:xrds="xri://$xrds"
+    xmlns:openid="http://openid.net/xmlns/1.0"
+    xmlns:typekey="http://typekey.com/xmlns/1.0"
+    xmlns="xri://$xrd*($v*2.0)">
+</xrds:XRDS>

Added: incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/not-xrds.xml
URL: http://svn.apache.org/viewvc/incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/not-xrds.xml?view=auto&rev=463013
==============================================================================
--- incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/not-xrds.xml (added)
+++ incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/not-xrds.xml Wed Oct
11 15:33:04 2006
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<x></x>

Added: incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/test1-discover.txt
URL: http://svn.apache.org/viewvc/incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/test1-discover.txt?view=auto&rev=463013
==============================================================================
--- incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/test1-discover.txt
(added)
+++ incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/test1-discover.txt
Wed Oct 11 15:33:04 2006
@@ -0,0 +1,137 @@
+equiv
+Status: 200 OK
+Content-Type: text/html
+
+<html>
+<head>
+<meta http-equiv="YADIS_HEADER" content="URL_BASE/xrds">
+<title>Joe Schmoe's Homepage</title>
+</head>
+<body>
+<h1>Joe Schmoe's Homepage</h1>
+<p>Blah blah blah blah blah blah blah</p>
+</body>
+</html>
+
+header
+Status: 200 OK
+Content-Type: text/html
+YADIS_HEADER: URL_BASE/xrds
+
+<html>
+<head>
+<title>Joe Schmoe's Homepage</title>
+</head>
+<body>
+<h1>Joe Schmoe's Homepage</h1>
+<p>Blah blah blah blah blah blah blah</p>
+</body>
+
+xrds
+Status: 200 OK
+Content-Type: application/xrds+xml
+
+<XRDS Content>
+
+xrds_ctparam
+Status: 200 OK
+Content-Type: application/xrds+xml; charset=UTF8
+
+<XRDS Content>
+
+xrds_ctcase
+Status: 200 OK
+Content-Type: appliCATION/XRDS+xml
+
+<XRDS Content>
+
+xrds_html
+Status: 200 OK
+Content-Type: text/html
+
+<XRDS Content>
+
+redir_equiv
+Status: 302 Found
+Content-Type: text/plain
+Location: URL_BASE/equiv
+
+You are presently being redirected.
+
+redir_header
+Status: 302 Found
+Content-Type: text/plain
+Location: URL_BASE/header
+
+You are presently being redirected.
+
+redir_xrds
+Status: 302 Found
+Content-Type: application/xrds+xml
+Location: URL_BASE/xrds
+
+<XRDS Content>
+
+redir_xrds_html
+Status: 302 Found
+Content-Type: text/plain
+Location: URL_BASE/xrds_html
+
+You are presently being redirected.
+
+redir_redir_equiv
+Status: 302 Found
+Content-Type: text/plain
+Location: URL_BASE/redir_equiv
+
+You are presently being redirected.
+
+lowercase_header
+Status: 200 OK
+Content-Type: text/html
+x-xrds-location: URL_BASE/xrds
+
+<html>
+<head>
+<title>Joe Schmoe's Homepage</title>
+</head>
+<body>
+<h1>Joe Schmoe's Homepage</h1>
+<p>Blah blah blah blah blah blah blah</p>
+</body>
+
+404_server_response
+Status: 404 Not Found
+
+EEk!
+
+500_server_response
+Status: 500 Server error
+
+EEk!
+
+201_server_response
+Status: 201 Created
+
+EEk!
+
+404_with_header
+Status: 404 Not Found
+YADIS_HEADER: URL_BASE/xrds
+
+EEk!
+
+404_with_meta
+Status: 404 Not Found
+Content-Type: text/html
+
+<html>
+<head>
+<meta http-equiv="YADIS_HEADER" content="URL_BASE/xrds">
+<title>Joe Schmoe's Homepage</title>
+</head>
+<body>
+<h1>Joe Schmoe's Homepage</h1>
+<p>Blah blah blah blah blah blah blah</p>
+</body>
+</html>

Added: incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/test1-parsehtml.txt
URL: http://svn.apache.org/viewvc/incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/test1-parsehtml.txt?view=auto&rev=463013
==============================================================================
--- incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/test1-parsehtml.txt
(added)
+++ incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/test1-parsehtml.txt
Wed Oct 11 15:33:04 2006
@@ -0,0 +1,128 @@
+found
+<!-- minimal well-formed success case -->
+<html><head><meta http-equiv="X-XRDS-Location" content="found"></head></html>
+
+found
+<!-- minimal success case -->
+<html><head><meta http-equiv="X-XRDS-Location" content="found">
+
+found
+<!-- ignore bogus top-level tags -->
+</porky><html><head><meta http-equiv="X-XRDS-Location" content="found">
+
+found
+<!-- Case folding for header name -->
+<html><head><meta http-equiv="x-xrds-location" content="found">
+
+found
+<!-- missing <html> tag -->
+<head><meta http-equiv="X-XRDS-Location" content="found">
+
+found
+<!-- case folding for tag names -->
+<html><head><META http-equiv="X-XRDS-Location" content="found">
+
+found
+<!-- Stop after first one found -->
+<html><head>
+<meta http-equiv="x-xrds-location" content="found">
+<meta http-equiv="x-xrds-location" content="not-found">
+
+&
+<!-- standard entity -->
+<head><meta http-equiv="X-XRDS-Location" content="&amp;">
+
+found
+<!-- hex entity -->
+<html>
+  <head>
+    <meta http-equiv="X-XRDS-Location" content="&#x66;ound">
+  </head>
+</html>
+
+found
+<!-- decimal entity -->
+<html>
+  <head>
+    <meta http-equiv="X-XRDS-Location" content="&#102;ound">
+  </head>
+</html>
+
+/
+<!-- hex entity -->
+<html>
+  <head>
+    <meta http-equiv="X-XRDS-Location" content="&#x2f;">
+  </head>
+</html>
+
+
+<!-- empty string -->
+<html><head><meta http-equiv="X-XRDS-Location" content="">
+
+EOF
+<!-- No markup, except this comment -->
+
+None
+<!-- No meta, just standard HTML -->
+<html>
+  <head>
+    <title>A boring document</title>
+  </head>
+  <body>
+    <h1>A boring document</h1>
+    <p>There's really nothing interesting about this</p>
+  </body>
+</html>
+
+EOF
+<!-- No <html> or <head> -->
+<meta http-equiv="X-XRDS-Location" content="found">
+
+EOF
+<!-- No <head> tag -->
+<html><meta http-equiv="X-XRDS-Location" content="found">
+
+None
+<!-- No <html> or <head> and a <body> -->
+<body><meta http-equiv="X-XRDS-Location" content="found">
+
+None
+<!-- <head> and <html> reversed -->
+<head><html><meta http-equiv="X-XRDS-Location" content="found">
+
+None
+<!-- <meta> is inside of <body> -->
+<html><head><body><meta http-equiv="X-XRDS-Location" content="found">
+
+None
+<!-- <meta> is inside of <body> -->
+<html>
+  <head>
+    <title>Someone's blog</title>
+  </head>
+  <body>
+    <h1>My blog</h1>
+    <p>This is my blog</p>
+    <h2>Comments</h2>
+    <p><meta http-equiv="X-XRDS-Location" content="found"></p>
+  </body>
+</html>
+
+None
+<!-- short head tag -->
+<html><head/>
+<meta http-equiv="X-XRDS-Location" content="found">
+
+None
+<!-- <body> comes first -->
+<body><html><head>
+<meta http-equiv="X-XRDS-Location" content="found">
+
+None
+<!-- </body> comes first -->
+</body><html><head>
+<meta http-equiv="X-XRDS-Location" content="found">
+
+None
+<!bad processing instruction!>

Added: incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/test1-xrd.xml
URL: http://svn.apache.org/viewvc/incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/test1-xrd.xml?view=auto&rev=463013
==============================================================================
--- incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/test1-xrd.xml (added)
+++ incubator/heraldry/libraries/java/trunk/test/src/com/janrain/yadis/test1-xrd.xml Wed Oct
11 15:33:04 2006
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xrds:XRDS
+    xmlns:xrds="xri://$xrds"
+    xmlns:openid="http://openid.net/xmlns/1.0"
+    xmlns:typekey="http://typekey.com/xmlns/1.0"
+    xmlns="xri://$xrd*($v*2.0)">
+  <XRD>
+
+    <Service priority="0">
+      <Type>http://openid.net/signon/1.0</Type>
+      <URI>http://www.myopenid.com/server</URI>
+      <openid:Delegate>http://josh.myopenid.com/</openid:Delegate>
+    </Service>
+
+    <Service priority="20">
+      <Type>http://lid.netmesh.org/sso/2.0b5</Type>
+      <Type>http://lid.netmesh.org/2.0b5</Type>
+      <URI>http://mylid.net/josh</URI>
+    </Service>
+
+    <Service priority="10">
+      <Type>http://openid.net/signon/1.0</Type>
+      <URI>http://www.livejournal.com/openid/server.bml</URI>
+      <openid:Delegate>http://www.livejournal.com/users/nedthealpaca/</openid:Delegate>
+    </Service>
+
+    <Service priority="15">
+      <Type>http://typekey.com/services/1.0</Type>
+      <typekey:MemberName>joshhoyt</typekey:MemberName>
+    </Service>
+
+    <Service priority="5">
+      <Type>http://openid.net/signon/1.0</Type>
+      <URI>http://www.schtuff.com/openid</URI>
+      <openid:Delegate>http://users.schtuff.com/josh</openid:Delegate>
+    </Service>
+
+  </XRD>
+</xrds:XRDS>



Mime
View raw message