-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a utilities class for connectivity assumptions. Based the Gitla…
…bControllerTest on the assumption that the Hobbit gitlab instance is available.
- Loading branch information
1 parent
8ee9416
commit 7188ad3
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
platform-controller/src/test/java/org/hobbit/controller/ConnectivityAssumptionUtils.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,34 @@ | ||
package org.hobbit.controller; | ||
|
||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
|
||
import org.junit.Assume; | ||
|
||
/** | ||
* A simple class that offers utility methods to assume the connectivity within | ||
* JUnit tests. | ||
* | ||
* @author Michael Röder (michael.roeder@uni-paderborn.de) | ||
* | ||
*/ | ||
public class ConnectivityAssumptionUtils { | ||
|
||
public static void assumeConnectivity(String httpUrl) { | ||
try { | ||
URL pingUrl = new URL(httpUrl); | ||
HttpURLConnection connection = (HttpURLConnection) pingUrl.openConnection(); | ||
|
||
Assume.assumeTrue( | ||
"Got a wrong status (" + connection.getResponseCode() | ||
+ ") code while checking the connectivity to \"" + httpUrl | ||
+ "\". I will assume that I cannot connect to this endpoint.", | ||
connection.getResponseCode() < 400); | ||
} catch (Exception e) { | ||
Assume.assumeNoException( | ||
"Exception while checking connectivity to \"" + httpUrl | ||
+ "\". I will assume that I cannot connect to this endpoint. Exception: " + e.getMessage(), | ||
e); | ||
} | ||
} | ||
} |
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