|
| 1 | +/* |
| 2 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | + * you may not use this file except in compliance with the License. |
| 4 | + * You may obtain a copy of the License at |
| 5 | + * |
| 6 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + * |
| 8 | + * Unless required by applicable law or agreed to in writing, software |
| 9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | + * See the License for the specific language governing permissions and |
| 12 | + * limitations under the License. |
| 13 | + */ |
| 14 | +package org.trellisldp.camel; |
| 15 | + |
| 16 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 17 | +import static org.junit.jupiter.api.Assertions.assertNull; |
| 18 | + |
| 19 | +import org.junit.jupiter.api.Test; |
| 20 | +import org.junit.platform.runner.JUnitPlatform; |
| 21 | +import org.junit.runner.RunWith; |
| 22 | + |
| 23 | +/** |
| 24 | + * @author acoburn |
| 25 | + */ |
| 26 | +@RunWith(JUnitPlatform.class) |
| 27 | +public class LinkTest { |
| 28 | + |
| 29 | + @Test |
| 30 | + public void testLinkWithParams() { |
| 31 | + final Link link = new Link("<http://www.w3.org/ns/ldp#Container>; rel=\"type\";" + |
| 32 | + "title=\"some title\"; type=\"text/turtle\"; other=\"param\""); |
| 33 | + assertEquals("http://www.w3.org/ns/ldp#Container", link.getUri()); |
| 34 | + assertEquals("type", link.getRel()); |
| 35 | + assertEquals("some title", link.getTitle()); |
| 36 | + assertEquals("text/turtle", link.getType()); |
| 37 | + assertEquals("param", link.getParams().get("other")); |
| 38 | + assertEquals(4L, link.getParams().size()); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + public void testLinkRelQuotes() { |
| 43 | + final Link link = new Link("<http://www.w3.org/ns/ldp#Container>; rel=\"type\""); |
| 44 | + assertEquals("http://www.w3.org/ns/ldp#Container", link.getUri()); |
| 45 | + assertEquals("type", link.getRel()); |
| 46 | + assertNull(link.getTitle()); |
| 47 | + assertNull(link.getType()); |
| 48 | + assertEquals(1L, link.getParams().size()); |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + public void testLinkRelNoQuotes() { |
| 53 | + final Link link = new Link("<http://www.w3.org/ns/ldp#Container>;rel=type"); |
| 54 | + assertEquals("http://www.w3.org/ns/ldp#Container", link.getUri()); |
| 55 | + assertEquals("type", link.getRel()); |
| 56 | + assertNull(link.getTitle()); |
| 57 | + assertNull(link.getType()); |
| 58 | + assertEquals(1L, link.getParams().size()); |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + public void testNoURI() { |
| 63 | + final Link link = new Link(""); |
| 64 | + assertNull(link.getUri()); |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + public void testBadURI() { |
| 69 | + final Link link = new Link("<blah"); |
| 70 | + assertNull(link.getUri()); |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + public void testBadParam() { |
| 75 | + final Link link = new Link("<uri>; rel"); |
| 76 | + assertNull(link.getRel()); |
| 77 | + } |
| 78 | + |
| 79 | + @Test |
| 80 | + public void testMultipleParams() { |
| 81 | + final Link link = new Link("<uri>; rel=one; rel=two; rel=three"); |
| 82 | + assertEquals("one", link.getRel()); |
| 83 | + } |
| 84 | +} |
0 commit comments