Class |
Line # |
Actions |
|||||
---|---|---|---|---|---|---|---|
URIToolTest | 28 | 46 | 0% | 10 | 0 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one | |
3 | * or more contributor license agreements. See the NOTICE file | |
4 | * distributed with this work for additional information | |
5 | * regarding copyright ownership. The ASF licenses this file | |
6 | * to you under the Apache License, Version 2.0 (the | |
7 | * "License"); you may not use this file except in compliance | |
8 | * with the License. You may obtain a copy of the License at | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
12 | * Unless required by applicable law or agreed to in writing, | |
13 | * software distributed under the License is distributed on an | |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
15 | * KIND, either express or implied. See the License for the | |
16 | * specific language governing permissions and limitations | |
17 | * under the License. | |
18 | */ | |
19 | package org.devacfr.maven.skins.reflow; | |
20 | ||
21 | import java.io.IOException; | |
22 | import java.net.URI; | |
23 | ||
24 | import org.devacfr.maven.skins.reflow.URITool.URLRebaser; | |
25 | import org.devacfr.testing.jupiter.TestCase; | |
26 | import org.junit.jupiter.api.Test; | |
27 | ||
28 | public class URIToolTest extends TestCase { | |
29 | ||
30 | 1 | @Test |
31 | public void shouldRelativizeLinkAccetupNullBase() throws IOException { | |
32 | 1 | final String actual = URITool.relativizeLink(null, "link"); |
33 | 1 | assertEquals("link", actual); |
34 | } | |
35 | ||
36 | 1 | @Test |
37 | public void shouldRelativizeLinkAcceptsAbsoluteBaseUri() throws IOException { | |
38 | 1 | final String actual = URITool.relativizeLink("reflow-maven-skin", "link"); |
39 | 1 | assertEquals("link", actual); |
40 | } | |
41 | ||
42 | 1 | @Test |
43 | public void relativeRootLink() throws IOException { | |
44 | 1 | final String absoluteResourceURL = "https://devacfr.github.io/reflow-maven-skin"; |
45 | 1 | final String currentFilename = "index.html"; |
46 | 1 | final String projectUrl = "https://devacfr.github.io/reflow-maven-skin/"; |
47 | ||
48 | 1 | final String currentFileDir = URITool.toURI(projectUrl).resolve(currentFilename).resolve(".").toString(); |
49 | 1 | final String actual = URITool.relativizeLink(currentFileDir, absoluteResourceURL); |
50 | 1 | assertEquals(".", actual); |
51 | } | |
52 | ||
53 | 1 | @Test |
54 | public void relativeSubModuleLink() throws IOException { | |
55 | 1 | final String absoluteResourceURL = "https://devacfr.github.io/reflow-maven-skin"; |
56 | 1 | final String currentFilename = "index.html"; |
57 | 1 | final String projectUrl = "https://devacfr.github.io/reflow-maven-skin/skin/"; |
58 | ||
59 | 1 | final String currentFileDir = URITool.toURI(projectUrl).resolve(currentFilename).resolve(".").toString(); |
60 | 1 | final String actual = URITool.relativizeLink(currentFileDir, absoluteResourceURL); |
61 | 1 | assertEquals("..", actual); |
62 | } | |
63 | ||
64 | 1 | @Test |
65 | public void relativeSubFolderLink() throws IOException { | |
66 | 1 | final String absoluteResourceURL = "https://devacfr.github.io/reflow-maven-skin"; |
67 | 1 | final String currentFilename = "themes/index.html"; |
68 | 1 | final String projectUrl = "https://devacfr.github.io/reflow-maven-skin/skin/"; |
69 | ||
70 | 1 | final String currentFileDir = URITool.toURI(projectUrl).resolve(currentFilename).resolve(".").toString(); |
71 | 1 | final String actual = URITool.relativizeLink(currentFileDir, absoluteResourceURL); |
72 | 1 | assertEquals("../..", actual); |
73 | } | |
74 | ||
75 | 1 | @Test |
76 | public void shouldNormalisedBaseUrlAcceptNullParameter() { | |
77 | 1 | assertNull(URITool.normalisedBaseUrl(null)); |
78 | } | |
79 | ||
80 | 1 | @Test |
81 | public void rebaseUrlNonInterpolate() { | |
82 | 1 | assertThrows(IllegalArgumentException.class, () -> { |
83 | 1 | final String childBaseUrl = "https://devacfr.github.io/reflow-maven-skin/"; |
84 | 1 | final String relativePath = "."; |
85 | 1 | final URI parent = URI.create(childBaseUrl); |
86 | 1 | final String parentBaseUrl = parent.resolve(relativePath).normalize().toString(); |
87 | 1 | final URLRebaser rebaser = URITool.createURLRebaser(parentBaseUrl, childBaseUrl); |
88 | 1 | rebaser.rebaseLink("${project.path}/reflow.png"); |
89 | }); | |
90 | } | |
91 | ||
92 | 1 | @Test |
93 | public void rebaseUrlOnRootProject() { | |
94 | 1 | final String childBaseUrl = "https://devacfr.github.io/reflow-maven-skin/"; |
95 | 1 | final String relativePath = "."; |
96 | 1 | final URI parent = URI.create(childBaseUrl); |
97 | 1 | final String parentBaseUrl = parent.resolve(relativePath).normalize().toString(); |
98 | 1 | final URLRebaser rebaser = URITool.createURLRebaser(parentBaseUrl, childBaseUrl); |
99 | 1 | assertEquals("images/reflow.png", rebaser.rebaseLink("images/reflow.png")); |
100 | } | |
101 | ||
102 | 1 | @Test |
103 | public void rebaseUrlOnChildProject() { | |
104 | 1 | final String childBaseUrl = "https://devacfr.github.io/reflow-maven-skin/skin/"; |
105 | 1 | final String relativePath = ".."; |
106 | 1 | final URI parent = URI.create(childBaseUrl); |
107 | 1 | final String parentBaseUrl = parent.resolve(relativePath).normalize().toString(); |
108 | 1 | final URLRebaser rebaser = new URLRebaser(parentBaseUrl, childBaseUrl); |
109 | 1 | assertEquals("../images/reflow.png", rebaser.rebaseLink("images/reflow.png")); |
110 | } | |
111 | ||
112 | 1 | @Test |
113 | public void rebaseUrlWithParentNullValue() { | |
114 | 1 | final String childBaseUrl = null; |
115 | 1 | final String parentBaseUrl = null; |
116 | ||
117 | 1 | final URLRebaser rebaser = new URLRebaser(parentBaseUrl, childBaseUrl); |
118 | 1 | assertEquals("images/reflow.png", rebaser.rebaseLink("images/reflow.png")); |
119 | } | |
120 | } |