Skip to content

Commit

Permalink
Added a utilities class for connectivity assumptions. Based the Gitla…
Browse files Browse the repository at this point in the history
…bControllerTest on the assumption that the Hobbit gitlab instance is available.
  • Loading branch information
MichaelRoeder committed Jan 5, 2024
1 parent 8ee9416 commit 7188ad3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.apache.jena.rdf.model.impl.ResourceImpl;
import org.gitlab.api.GitlabAPI;
import org.gitlab.api.models.*;
import org.hobbit.controller.ConnectivityAssumptionUtils;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
Expand All @@ -37,6 +39,7 @@

/**
* Created by Timofey Ermilov on 17/10/2016.
* Updated by Michael Röder to run only if the test instance is available-
*/
public class GitlabControllerImplTest {
private static final String GITLAB_URL = "https://git.project-hobbit.eu/";
Expand All @@ -47,6 +50,7 @@ public class GitlabControllerImplTest {

@Before
public void init() throws InterruptedException {
ConnectivityAssumptionUtils.assumeConnectivity(GITLAB_URL);
gitlabProject = new GitlabProject();
gitlabProject.setId(526);
gitlabProject.setName("testing-benchmark");
Expand Down

0 comments on commit 7188ad3

Please sign in to comment.