Example #1
0
        public virtual void UriResolverTest06()
        {
            UriResolver resolver     = new UriResolver("../test/folder/index.html");
            String      parentFolder = new Uri(Directory.GetParent(Directory.GetCurrentDirectory()).FullName).ToExternalForm() + "/";

            TestPaths(parentFolder, resolver);
        }
Example #2
0
        public virtual void UriResolverTest03()
        {
            UriResolver resolver   = new UriResolver("/test/folder/index.html");
            String      rootFolder = new Uri(new Uri("file://"), Path.GetPathRoot(Directory.GetCurrentDirectory())).ToExternalForm();

            TestPaths(rootFolder, resolver);
        }
Example #3
0
        public void UriResolverPercentSignTest()
        {
            String      absolutePathRoot = new Uri(new Uri("file://"), Path.GetPathRoot(Directory.GetCurrentDirectory())).ToString();
            UriResolver resolver         = new UriResolver(absolutePathRoot + "%homepath%");

            NUnit.Framework.Assert.AreEqual(absolutePathRoot + "%25homepath%25", resolver.GetBaseUri());
        }
Example #4
0
        private void TestPaths(String absolutePathRoot, UriResolver resolver)
        {
            NUnit.Framework.Assert.AreEqual(absolutePathRoot + "test/folder/index.html", resolver.GetBaseUri());
            NUnit.Framework.Assert.AreEqual(absolutePathRoot + "test/folder/innerTest", resolver.ResolveAgainstBaseUri
                                                ("innerTest").ToExternalForm());
            NUnit.Framework.Assert.AreEqual(absolutePathRoot + "test/folder2/innerTest2", resolver.ResolveAgainstBaseUri
                                                ("../folder2/innerTest2").ToExternalForm());

            /*
             *  Resolving relative paths like "/folder" works correct on Linux and .NET, but fails on Java because of strong
             *  corresponding with URI standard RFC3986.
             *
             *  Look to this memo for specifying "file" URI scheme:
             *  https://tools.ietf.org/id/draft-ietf-appsawg-file-scheme-12.html
             *
             *  Expected results after resolving "/folder2/innerTest2":
             *      - .NET: "file:///C:/folder2/innerTest2"
             *      - Java (Windows): "file:/folder2/innerTest2" - incorrect
             *      - Java (Linux): "file:/folder2/innerTest2" - correct
             */

//            NUnit.Framework.Assert.AreEqual(absolutePathRoot + "test/folder/folder2/innerTest2", resolver.ResolveAgainstBaseUri
//                ("/folder2/innerTest2").ToExternalForm());
//            NUnit.Framework.Assert.AreEqual(absolutePathRoot + "test/folder/folder2/innerTest2", resolver.ResolveAgainstBaseUri
//                ("//folder2/innerTest2").ToExternalForm());
        }
Example #5
0
        public virtual void UriResolverTest02()
        {
            UriResolver resolver  = new UriResolver("test/folder/index.html");
            String      runFolder = new Uri(Path.GetFullPath(Directory.GetCurrentDirectory() + "/")).ToExternalForm();

            TestPaths(runFolder, resolver);
        }
Example #6
0
        public virtual void UriResolverTest10F()
        {
            String      absolutePathRoot = new Uri(new Uri("file://"), Path.GetPathRoot(Directory.GetCurrentDirectory())).ToExternalForm();
            UriResolver resolver         = new UriResolver(absolutePathRoot + "path%2520with%2520spaces/test/folder/index.html");
            String      malformedPath    = absolutePathRoot + "path%2520with%2520spaces/";

            TestPaths(malformedPath, resolver);
        }
Example #7
0
        public virtual void UriResolverTest01A()
        {
            String      absolutePathRoot = new Uri(new Uri("file://"), Path.GetPathRoot(Directory.GetCurrentDirectory())).ToExternalForm();
            String      absoluteBaseUri  = absolutePathRoot + "test/folder/index.html";
            UriResolver resolver         = new UriResolver(absoluteBaseUri);

            TestPaths(absolutePathRoot, resolver);
        }
Example #8
0
        public virtual void UriResolverTest18()
        {
            String      absolutePathRoot = "http://";
            String      absoluteBaseUri  = absolutePathRoot + "test/fol ders/wi@th/diffe#rent/$characters/index.html\t\t\t\t\t\t";
            UriResolver resolver         = new UriResolver(absoluteBaseUri);

            NUnit.Framework.Assert.IsFalse(resolver.IsLocalBaseUri());
        }
Example #9
0
        public virtual void ResourceResolverConstructorTest()
        {
            ResourceResolver rr    = new ResourceResolver(null);
            UriResolver      ur    = new UriResolver("");
            String           rrUrl = rr.ResolveAgainstBaseUri("").ToString();
            String           urUrl = ur.ResolveAgainstBaseUri("").ToString();

            NUnit.Framework.Assert.AreEqual(rrUrl, urUrl);
        }
Example #10
0
        public virtual void UriResolverTest16()
        {
            String      absolutePathRoot    = new Uri(new Uri("file://"), Path.GetPathRoot(Directory.GetCurrentDirectory())).ToString();
            String      absoluteBaseUri     = new Uri(absolutePathRoot + "test/folder/index.html").ToString();
            UriResolver resolver            = new UriResolver(absoluteBaseUri);
            String      singleSlashRootPath = absolutePathRoot;

            TestPaths(singleSlashRootPath, resolver);
        }
Example #11
0
        public void quoteInPercentsBasePath()
        {
            String      expectedUrl  = "https://he.wikipedia.org/wiki%27/%D7%90%D7%91%D7%92%D7%93";
            String      baseUri      = "https://he.wikipedia.org/wiki%27/";
            String      relativePath = "%D7%90%D7%91%D7%92%D7%93";
            UriResolver resolver     = new UriResolver(baseUri);

            NUnit.Framework.Assert.AreEqual(expectedUrl, resolver.ResolveAgainstBaseUri(relativePath).ToExternalForm());
        }
Example #12
0
 // TODO provide a way to configure capacity, manually reset or disable the image cache?
 /// <summary>
 /// Creates
 /// <see cref="ResourceResolver"/>
 /// instance.
 /// </summary>
 /// <remarks>
 /// Creates
 /// <see cref="ResourceResolver"/>
 /// instance. If
 /// <paramref name="baseUri"/>
 /// is a string that represents an absolute URI with any schema
 /// except "file" - resources url values will be resolved exactly as "new URL(baseUrl, uriString)". Otherwise base URI
 /// will be handled as path in local file system.
 /// <para />
 /// If empty string or relative URI string is passed as base URI, then it will be resolved against current working
 /// directory of this application instance.
 /// </remarks>
 /// <param name="baseUri">base URI against which all relative resource URIs will be resolved.</param>
 public ResourceResolver(String baseUri)
 {
     if (baseUri == null)
     {
         baseUri = "";
     }
     this.uriResolver = new UriResolver(baseUri);
     this.imageCache  = new SimpleImageCache();
 }
Example #13
0
        public virtual void UriResolverTest09()
        {
            Uri         absoluteBaseUri       = new Uri(new Uri("file://"), Path.GetPathRoot(Directory.GetCurrentDirectory()) + "test/folder/index.html");
            String      absoluteBaseUriString = absoluteBaseUri.ToString();
            UriResolver resolver = new UriResolver(absoluteBaseUriString);
            String      uriRoot  = new Uri(new Uri("file://"), Path.GetPathRoot(Directory.GetCurrentDirectory())).ToExternalForm();

            TestPaths(uriRoot, resolver);
        }
Example #14
0
        public virtual void ConstructorWithBaseUriAndResourceRetrieverTest()
        {
            ResourceResolver resolver = new ResourceResolver("folder", new CustomResourceRetriever());

            UriResolver uriResolver = new UriResolver("folder");
            String      resolveUrl  = resolver.ResolveAgainstBaseUri("").ToString();
            String      expectedUrl = uriResolver.ResolveAgainstBaseUri("").ToString();

            Assert.AreEqual(resolveUrl, expectedUrl);
            Assert.AreEqual(typeof(CustomResourceRetriever), resolver.GetRetriever().GetType());
        }
Example #15
0
 /// <summary>
 /// Creates
 /// <see cref="ResourceResolver"/>
 /// instance. If
 /// <paramref name="baseUri"/>
 /// is a string that represents an absolute URI with any schema
 /// except "file" - resources url values will be resolved exactly as "new URL(baseUrl, uriString)". Otherwise base URI
 /// will be handled as path in local file system.
 /// <p>
 /// If empty string or relative URI string is passed as base URI, then it will be resolved against current working
 /// directory of this application instance.
 /// </p>
 /// </summary>
 /// <param name="baseUri">base URI against which all relative resource URIs will be resolved.</param>
 public ResourceResolver(String baseUri)
 {
     // TODO handle <base href=".."> tag?
     // TODO provide a way to configure capacity, manually reset or disable the image cache?
     if (baseUri == null)
     {
         baseUri = "";
     }
     this.uriResolver = new UriResolver(baseUri);
     this.imageCache  = new SimpleImageCache();
 }
Example #16
0
        public virtual void ReadingByteArrayWithOffsetAfterFileReadingTest()
        {
            UriResolver uriResolver = new UriResolver(baseUri);
            Uri         url         = uriResolver.ResolveAgainstBaseUri("retrieveStyleSheetTest.css.dat");
            // retrieveStyleSheetTest.css.dat size is 89 bytes
            Stream stream = new LimitedInputStream(UrlUtil.OpenStream(url), 100);

            // The user can call the reading methods as many times as he want, and if the
            // stream has been read, then should not throw an ReadingByteLimitException exception
            stream.JRead(new byte[100], 0, 100);
            stream.JRead(new byte[1], 0, 1);
        }
Example #17
0
        public virtual void UriResolverTest08()
        {
            UriResolver resolver = new UriResolver("http://itextpdf.com/itext7/");

            NUnit.Framework.Assert.AreEqual("http://itextpdf.com/itext7/", resolver.GetBaseUri());
            NUnit.Framework.Assert.AreEqual("http://itextpdf.com/itext7/innerTest", resolver.ResolveAgainstBaseUri("innerTest"
                                                                                                                   ).ToExternalForm());
            NUnit.Framework.Assert.AreEqual("http://itextpdf.com/folder2/innerTest2", resolver.ResolveAgainstBaseUri("/folder2/innerTest2"
                                                                                                                     ).ToExternalForm());
            NUnit.Framework.Assert.AreEqual("http://folder2.com/innerTest2", resolver.ResolveAgainstBaseUri("//folder2.com/innerTest2"
                                                                                                            ).ToExternalForm());
        }
Example #18
0
        public virtual void UriResolverTest14()
        {
            UriResolver resolver  = new UriResolver("base/uri/index.html");
            String      runFolder = new Uri(Path.GetFullPath(Directory.GetCurrentDirectory())).ToExternalForm() + "/";

            NUnit.Framework.Assert.AreEqual(runFolder + "base/uri/index.html", resolver.GetBaseUri());
            NUnit.Framework.Assert.AreEqual("file:///c:/test/folder/img.txt", resolver.ResolveAgainstBaseUri("file:/c:/test/folder/img.txt"
                                                                                                             ).ToExternalForm());
            NUnit.Framework.Assert.AreEqual("file:///c:/test/folder/img.txt", resolver.ResolveAgainstBaseUri("file://c:/test/folder/img.txt"
                                                                                                             ).ToExternalForm());
            NUnit.Framework.Assert.AreEqual("file:///c:/test/folder/data.jpg", resolver.ResolveAgainstBaseUri("file:///c:/test/folder/data.jpg"
                                                                                                              ).ToExternalForm());
        }
Example #19
0
        public virtual void ReadingByteArrayWithOffsetAndBigBufferTest()
        {
            UriResolver uriResolver = new UriResolver(baseUri);
            Uri         url         = uriResolver.ResolveAgainstBaseUri("retrieveStyleSheetTest.css.dat");
            // retrieveStyleSheetTest.css.dat size is 89 bytes
            Stream stream = new LimitedInputStream(UrlUtil.OpenStream(url), 89);

            byte[] bytes = new byte[100];
            NUnit.Framework.Assert.AreEqual(89, stream.JRead(bytes, 0, 100));
            byte[] tempBytes = (byte[])bytes.Clone();
            NUnit.Framework.Assert.AreEqual(-1, stream.JRead(bytes, 0, 100));
            // Check that the array has not changed when we have read the entire LimitedInputStream
            NUnit.Framework.Assert.AreEqual(tempBytes, bytes);
        }
Example #20
0
        public virtual void ByteArrayOverwritingTest()
        {
            UriResolver uriResolver = new UriResolver(baseUri);
            Uri         url         = uriResolver.ResolveAgainstBaseUri("retrieveStyleSheetTest.css.dat");
            // retrieveStyleSheetTest.css.dat size is 89 bytes
            Stream stream = new LimitedInputStream(UrlUtil.OpenStream(url), 90);

            byte[] bytes = new byte[100];
            bytes[89] = 13;
            NUnit.Framework.Assert.AreEqual(89, stream.Read(bytes));
            // Check that when calling the read(byte[]) method, as many bytes were copied into
            // the original array as were read, and not all bytes from the auxiliary array.
            NUnit.Framework.Assert.AreEqual(13, bytes[89]);
        }
Example #21
0
        public virtual void UriResolverTest04()
        {
            UriResolver resolver  = new UriResolver("index.html");
            String      runFolder = new Uri(Path.GetFullPath(Directory.GetCurrentDirectory() + "/")).ToExternalForm();

            NUnit.Framework.Assert.AreEqual(runFolder + "index.html", resolver.GetBaseUri());
            NUnit.Framework.Assert.AreEqual(runFolder + "innerTest", resolver.ResolveAgainstBaseUri("innerTest").ToExternalForm
                                                ());

// Look to commentary below in TestPaths() method
//            NUnit.Framework.Assert.AreEqual(runFolder + "folder2/innerTest2", resolver.ResolveAgainstBaseUri("/folder2/innerTest2"
//                ).ToExternalForm());
//            NUnit.Framework.Assert.AreEqual(runFolder + "folder2/innerTest2", resolver.ResolveAgainstBaseUri("//folder2/innerTest2"
//                ).ToExternalForm());
        }
Example #22
0
        public virtual void UriResolverTest07B()
        {
            String      absolutePathRoot = new Uri(new Uri("file://"), Path.GetPathRoot(Directory.GetCurrentDirectory())).ToExternalForm();
            UriResolver resolver         = new UriResolver(absolutePathRoot + "#r%e%25s@o%urces/folder/index.html");
            String      malformedPath    = absolutePathRoot;

            NUnit.Framework.Assert.AreEqual(malformedPath + "#r%25e%25s@o%25urces/folder/index.html", resolver.GetBaseUri());
            NUnit.Framework.Assert.AreEqual(malformedPath + "test/folder/innerTest", resolver.ResolveAgainstBaseUri
                                                ("test/folder/innerTest").ToExternalForm());
// Look to commentary below in TestPaths() method
//            NUnit.Framework.Assert.AreEqual(malformedPath + "folder2/innerTest2", resolver.ResolveAgainstBaseUri
//              ("/folder2/innerTest2").ToExternalForm());
//            NUnit.Framework.Assert.AreEqual(malformedPath + "folder2/innerTest2", resolver.ResolveAgainstBaseUri
//                ("//folder2/innerTest2").ToExternalForm());
        }
Example #23
0
        public virtual void UriResolverTest16D()
        {
            String      absolutePathRoot = new Uri(new Uri("file://"), Path.GetPathRoot(Directory.GetCurrentDirectory())).ToExternalForm();
            UriResolver resolver         = new UriResolver(absolutePathRoot + "path%25252Fwith%25252Fspaces/test/folder/index.html");
            String      malformedPath    = absolutePathRoot + "path%25252Fwith%25252Fspaces/";

            NUnit.Framework.Assert.AreEqual(malformedPath + "test/folder/innerTest", resolver.ResolveAgainstBaseUri
                                                ("innerTest").ToExternalForm());
            NUnit.Framework.Assert.AreEqual(malformedPath + "test/folder2/innerTest2", resolver.ResolveAgainstBaseUri
                                                ("../folder2/innerTest2").ToExternalForm());
// Look to commentary in TestPaths() method
//            NUnit.Framework.Assert.AreEqual(malformedPath + "test/folder/folder2/innerTest2", resolver.ResolveAgainstBaseUri
//                ("/folder2/innerTest2").ToExternalForm());
//            NUnit.Framework.Assert.AreEqual(malformedPath + "test/folder/folder2/innerTest2", resolver.ResolveAgainstBaseUri
//                ("//folder2/innerTest2").ToExternalForm());
        }
Example #24
0
        public virtual void UriResolverTest17()
        {
            String      absolutePathRoot = new Uri(new Uri("file://"), Path.GetPathRoot(Directory.GetCurrentDirectory())).ToString();
            String      absoluteBaseUri  = absolutePathRoot + "test/fol ders/wi@th/diffe#rent/$characters/test/folder/index.html\t\t\t\t\t\t";
            UriResolver resolver         = new UriResolver(absoluteBaseUri);
            String      malformedPath    = absolutePathRoot + "test/fol%20ders/wi@th/diffe#rent/$characters/";

            NUnit.Framework.Assert.AreNotEqual(malformedPath + "test/folder/innerTest", resolver.ResolveAgainstBaseUri
                                                   ("innerTest").ToExternalForm());
            NUnit.Framework.Assert.AreNotEqual(malformedPath + "test/folder2/innerTest2", resolver.ResolveAgainstBaseUri
                                                   ("../folder2/innerTest2").ToExternalForm());
// Look to commentary in TestPaths() method
//            NUnit.Framework.Assert.AreNotEqual(malformedPath + "test/folder/folder2/innerTest2", resolver.ResolveAgainstBaseUri
//                ("/folder2/innerTest2").ToExternalForm());
//            NUnit.Framework.Assert.AreNotEqual(malformedPath + "test/folder/folder2/innerTest2", resolver.ResolveAgainstBaseUri
//                ("//folder2/innerTest2").ToExternalForm());
        }
Example #25
0
 /// <summary>
 /// Creates a new
 /// <see cref="ResourceResolver"/>
 /// instance.
 /// </summary>
 /// <remarks>
 /// Creates a new
 /// <see cref="ResourceResolver"/>
 /// instance.
 /// If
 /// <paramref name="baseUri"/>
 /// is a string that represents an absolute URI with any schema except "file" - resources
 /// url values will be resolved exactly as "new URL(baseUrl, uriString)". Otherwise base URI will be handled
 /// as path in local file system.
 /// <para />
 /// If empty string or relative URI string is passed as base URI, then it will be resolved against current
 /// working directory of this application instance.
 /// </remarks>
 /// <param name="baseUri">base URI against which all relative resource URIs will be resolved</param>
 /// <param name="retriever">the resource retriever with the help of which data from resources will be retrieved
 ///     </param>
 public ResourceResolver(String baseUri, IResourceRetriever retriever)
 {
     if (baseUri == null)
     {
         baseUri = "";
     }
     this.uriResolver = new UriResolver(baseUri);
     this.imageCache  = new SimpleImageCache();
     if (retriever == null)
     {
         this.retriever = new DefaultResourceRetriever();
     }
     else
     {
         this.retriever = retriever;
     }
 }
Example #26
0
        public virtual void ReadingByteWithLimitOfOneLessThenFileSizeTest()
        {
            UriResolver uriResolver = new UriResolver(baseUri);
            Uri         url         = uriResolver.ResolveAgainstBaseUri("retrieveStyleSheetTest.css.dat");
            // retrieveStyleSheetTest.css.dat size is 89 bytes
            Stream stream = new LimitedInputStream(UrlUtil.OpenStream(url), 88);

            for (int i = 0; i < 88; i++)
            {
                NUnit.Framework.Assert.AreNotEqual(-1, stream.Read());
            }
            NUnit.Framework.Assert.That(() => {
                stream.Read();
            }
                                        , NUnit.Framework.Throws.InstanceOf <ReadingByteLimitException>())
            ;
        }
Example #27
0
            public override Stream GetInputStreamByUrl(Uri url)
            {
                Stream stream = null;

                try {
                    stream = base.GetInputStreamByUrl(url);
                }
                catch (Exception ignored) {
                }

                if (stream == null)
                {
                    Uri newUrl = new UriResolver(this.baseUri).ResolveAgainstBaseUri("retrieveStyleSheetTest.css");
                    stream = base.GetInputStreamByUrl(newUrl);
                }

                return(stream);
            }
Example #28
0
        public virtual void ReadingByteArrayWithLimitOfOneLessThenFileSizeTest()
        {
            UriResolver uriResolver = new UriResolver(baseUri);
            Uri         url         = uriResolver.ResolveAgainstBaseUri("retrieveStyleSheetTest.css.dat");
            // retrieveStyleSheetTest.css.dat size is 89 bytes
            Stream stream = new LimitedInputStream(UrlUtil.OpenStream(url), 88);

            byte[] bytes          = new byte[100];
            int    numOfReadBytes = stream.Read(bytes);

            NUnit.Framework.Assert.AreEqual(88, numOfReadBytes);
            NUnit.Framework.Assert.AreEqual(10, bytes[87]);
            NUnit.Framework.Assert.AreEqual(0, bytes[88]);
            NUnit.Framework.Assert.That(() => {
                stream.Read(new byte[1]);
            }
                                        , NUnit.Framework.Throws.InstanceOf <ReadingByteLimitException>())
            ;
        }
Example #29
0
        public virtual void ReadingByteArrayWithSmallBufferTest()
        {
            UriResolver uriResolver = new UriResolver(baseUri);
            Uri         url         = uriResolver.ResolveAgainstBaseUri("retrieveStyleSheetTest.css.dat");
            // retrieveStyleSheetTest.css.dat size is 89 bytes
            Stream stream = new LimitedInputStream(UrlUtil.OpenStream(url), 89);

            byte[]       bytes  = new byte[20];
            MemoryStream output = new MemoryStream();

            while (true)
            {
                int read = stream.Read(bytes);
                if (read < 1)
                {
                    break;
                }
                output.Write(bytes, 0, read);
            }
            NUnit.Framework.Assert.AreEqual(89, output.Length);
            output.Dispose();
        }