-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5f6ce9
commit 8917204
Showing
2 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
maven-confluence-reporting-plugin/src/test/java/org/bsc/maven/plugin/test/Issue133Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package org.bsc.maven.plugin.test; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URISyntaxException; | ||
import okhttp3.HttpUrl; | ||
import org.hamcrest.core.Is; | ||
import org.hamcrest.core.IsEqual; | ||
import org.junit.Assert; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
/** | ||
* | ||
* @author softphone | ||
*/ | ||
public class Issue133Test { | ||
|
||
@Test @Ignore | ||
public void dummy() {} | ||
|
||
|
||
@Test(expected = java.lang.IllegalArgumentException.class) | ||
public void htttpUrlBuilderWithoutPort() throws MalformedURLException { | ||
|
||
final java.net.URL endpoint = new java.net.URL("http://localhost/confluence"); | ||
|
||
Assert.assertThat( endpoint.getPort(), Is.is(-1)); | ||
|
||
final HttpUrl.Builder builder = new HttpUrl.Builder() | ||
.scheme(endpoint.getProtocol()) | ||
.host(endpoint.getHost()) | ||
.port(endpoint.getPort()) | ||
.addPathSegments("rest/api") | ||
; | ||
|
||
} | ||
|
||
@Test | ||
public void htttpUrlBuilderWithoutPortSafe() throws MalformedURLException { | ||
|
||
final java.net.URL endpoint = new java.net.URL("http://localhost/confluence"); | ||
|
||
Assert.assertThat( endpoint.getPort(), Is.is(-1)); | ||
|
||
int port = endpoint.getPort(); | ||
port = (port > -1 ) ? port : endpoint.getDefaultPort(); | ||
|
||
String path = endpoint.getPath(); | ||
path = (path.startsWith("/")) ? path.substring(1) : path; | ||
|
||
final HttpUrl.Builder builder = new HttpUrl.Builder() | ||
.scheme(endpoint.getProtocol()) | ||
.host(endpoint.getHost()) | ||
.port( port ) | ||
; | ||
Assert.assertThat(path, IsEqual.equalTo("confluence")); | ||
|
||
final HttpUrl url = | ||
builder | ||
.addPathSegments(path) | ||
//.addPathSegments("rest/api") | ||
.build(); | ||
|
||
Assert.assertThat( url.url(), IsEqual.equalTo(endpoint)); | ||
|
||
} | ||
|
||
@Test | ||
public void htttpUrlBuilderWithoutPortSafe2() throws MalformedURLException, URISyntaxException { | ||
|
||
final java.net.URL endpoint = new java.net.URL("http://localhost/"); | ||
|
||
Assert.assertThat( endpoint.getPort(), Is.is(-1)); | ||
|
||
int port = endpoint.getPort(); | ||
port = (port > -1 ) ? port : endpoint.getDefaultPort(); | ||
|
||
String path = endpoint.getPath(); | ||
path = (path.startsWith("/")) ? path.substring(1) : path; | ||
|
||
final HttpUrl.Builder builder = new HttpUrl.Builder() | ||
.scheme(endpoint.getProtocol()) | ||
.host(endpoint.getHost()) | ||
.port( port ) | ||
; | ||
|
||
Assert.assertThat( path, IsEqual.equalTo("")); | ||
|
||
final HttpUrl url = | ||
builder | ||
.addPathSegments(path) | ||
//.addPathSegments("rest/api") | ||
.build(); | ||
|
||
Assert.assertThat( url.url(), IsEqual.equalTo(endpoint)); | ||
; | ||
|
||
} | ||
} |