package org.datacite.mds.validation.constraints;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

public class URLTest extends AbstractContraintsTest {
    @URL
    String url;

    @Test
    public void test() {
        assertTrue(isValid(null));
        assertTrue(isValid(""));
        assertTrue(isValid("http://example.com"));
        assertTrue(isValid("http://example.com:8080/path?q=query&x#fragment"));
        assertFalse(isValid("http://example.com:-42"));
    }

    @Test
    public void testProtocol() {
        assertTrue(isValid("http://example.com"));
        assertTrue(isValid("https://example.com"));
        assertTrue(isValid("ftp://example.com"));
        assertFalse(isValid("file://example.com"));
    }

    boolean isValid(String url) {
        this.url = url;
        return super.isValid(this, "url");
    }

}

@@ -131,16 +131,60 @@
 tTrue;%0A%0A
+import org.apache.commons.lang.StringUtils;%0A
 import o
@@ -198,16 +198,16 @@
 t.Test;%0A
-
 %0Apublic 
@@ -572,24 +572,171 @@
 %22));%0A    %7D%0A%0A
+    @Test%0A    public void testLength() %7B%0A        assertTrue(isValid(urlWithLength(255)));%0A        assertFalse(isValid(urlWithLength(256)));%0A    %7D%0A%0A
     @Test%0A  
@@ -911,32 +911,32 @@
 example.com%22));%0A
-
         assertFa
@@ -974,24 +974,234 @@
 %22));%0A    %7D%0A%0A
+    String urlWithLength(int len) %7B%0A        return urlWithLength(len, %22http://example.com/%22);%0A    %7D%0A%0A    String urlWithLength(int len, String base) %7B%0A        return StringUtils.rightPad(base, len, 'x');%0A    %7D%0A%0A
     boolean 

add test for url length