Skip to content

Commit

Permalink
Merge pull request #269 from neicnordic/Junit-migration
Browse files Browse the repository at this point in the history
migrate from junit 4 to 5
  • Loading branch information
kjellp authored Mar 18, 2024
2 parents 5d4afc3 + 7548a4c commit 110b185
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 36 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.junit.Assert;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;

Expand All @@ -40,7 +38,6 @@
import java.util.UUID;

@Slf4j
@RunWith(JUnit4.class)
class LocalEGADOAApplicationTests {

private static String validToken;
Expand Down Expand Up @@ -91,85 +88,85 @@ public void tearDown() {
@Test
void testMetadataDatasetsNoToken() {
int status = Unirest.get("http://localhost:8080/metadata/datasets").asJson().getStatus();
Assert.assertEquals(HttpStatus.UNAUTHORIZED.value(), status);
Assertions.assertEquals(HttpStatus.UNAUTHORIZED.value(), status);
}

@Test
void testMetadataDatasetsInvalidToken() {
int status = Unirest.get("http://localhost:8080/metadata/datasets").header(HttpHeaders.AUTHORIZATION, "Bearer " + invalidToken).asJson().getStatus();
Assert.assertEquals(HttpStatus.UNAUTHORIZED.value(), status);
Assertions.assertEquals(HttpStatus.UNAUTHORIZED.value(), status);
}

@Test
void testMetadataDatasetsValidToken() {
HttpResponse<JsonNode> response = Unirest.get("http://localhost:8080/metadata/datasets").header(HttpHeaders.AUTHORIZATION, "Bearer " + validToken).asJson();
int status = response.getStatus();
Assert.assertEquals(HttpStatus.OK.value(), status);
Assertions.assertEquals(HttpStatus.OK.value(), status);
JSONArray datasets = response.getBody().getArray();
Assert.assertEquals(1, datasets.length());
Assert.assertEquals("EGAD00010000919", datasets.getString(0));
Assertions.assertEquals(1, datasets.length());
Assertions.assertEquals("EGAD00010000919", datasets.getString(0));
}

@Test
void testMetadataFilesNoToken() {
int status = Unirest.get("http://localhost:8080/metadata/datasets/EGAD00010000919/files").asJson().getStatus();
Assert.assertEquals(HttpStatus.UNAUTHORIZED.value(), status);
Assertions.assertEquals(HttpStatus.UNAUTHORIZED.value(), status);
}

@Test
void testMetadataFilesInvalidToken() {
int status = Unirest.get("http://localhost:8080/metadata/datasets/EGAD00010000919/files").header(HttpHeaders.AUTHORIZATION, "Bearer " + invalidToken).asJson().getStatus();
Assert.assertEquals(HttpStatus.UNAUTHORIZED.value(), status);
Assertions.assertEquals(HttpStatus.UNAUTHORIZED.value(), status);
}

@Test
void testMetadataFilesValidTokenInvalidDataset() {
HttpResponse<JsonNode> response = Unirest.get("http://localhost:8080/metadata/datasets/EGAD00010000920/files").header(HttpHeaders.AUTHORIZATION, "Bearer " + validToken).asJson();
int status = response.getStatus();
Assert.assertEquals(HttpStatus.FORBIDDEN.value(), status);
Assertions.assertEquals(HttpStatus.FORBIDDEN.value(), status);
}

@Test
void testMetadataFilesValidTokenValidDataset() {
HttpResponse<JsonNode> response = Unirest.get("http://localhost:8080/metadata/datasets/EGAD00010000919/files").header(HttpHeaders.AUTHORIZATION, "Bearer " + validToken).asJson();
int status = response.getStatus();
Assert.assertEquals(HttpStatus.OK.value(), status);
Assert.assertEquals("[{\"fileId\":\"EGAF00000000014\",\"datasetId\":\"EGAD00010000919\",\"displayFileName\":\"body.enc\",\"fileName\":\"test/body.enc\",\"fileSize\":null,\"unencryptedChecksum\":null,\"unencryptedChecksumType\":null,\"decryptedFileSize\":null,\"decryptedFileChecksum\":null,\"decryptedFileChecksumType\":null,\"fileStatus\":\"READY\"}]", response.getBody().toString());
Assertions.assertEquals(HttpStatus.OK.value(), status);
Assertions.assertEquals("[{\"fileId\":\"EGAF00000000014\",\"datasetId\":\"EGAD00010000919\",\"displayFileName\":\"body.enc\",\"fileName\":\"test/body.enc\",\"fileSize\":null,\"unencryptedChecksum\":null,\"unencryptedChecksumType\":null,\"decryptedFileSize\":null,\"decryptedFileChecksum\":null,\"decryptedFileChecksumType\":null,\"fileStatus\":\"READY\"}]", response.getBody().toString());
}

@Test
void testStreamingNoToken() {
int status = Unirest.get("http://localhost:8080/files/EGAF00000000014").asJson().getStatus();
Assert.assertEquals(HttpStatus.UNAUTHORIZED.value(), status);
Assertions.assertEquals(HttpStatus.UNAUTHORIZED.value(), status);
}

@Test
void testStreamingInvalidToken() {
int status = Unirest.get("http://localhost:8080/files/EGAF00000000014").header(HttpHeaders.AUTHORIZATION, "Bearer " + invalidToken).asJson().getStatus();
Assert.assertEquals(HttpStatus.UNAUTHORIZED.value(), status);
Assertions.assertEquals(HttpStatus.UNAUTHORIZED.value(), status);
}

@Test
void testStreamingValidTokenInvalidFile() {
HttpResponse<JsonNode> response = Unirest.get("http://localhost:8080/files/EGAF00000000015").header(HttpHeaders.AUTHORIZATION, "Bearer " + validToken).asJson();
int status = response.getStatus();
Assert.assertEquals(HttpStatus.FORBIDDEN.value(), status);
Assertions.assertEquals(HttpStatus.FORBIDDEN.value(), status);
}

@Test
void testStreamingValidTokenValidFileFullPlain() {
HttpResponse<byte[]> response = Unirest.get("http://localhost:8080/files/EGAF00000000014").header(HttpHeaders.AUTHORIZATION, "Bearer " + validToken).asBytes();
int status = response.getStatus();
Assert.assertEquals(HttpStatus.OK.value(), status);
Assert.assertEquals("2aef808fb42fa7b1ba76cb16644773f9902a3fdc2569e8fdc049f38280c4577e", DigestUtils.sha256Hex(response.getBody()));
Assertions.assertEquals(HttpStatus.OK.value(), status);
Assertions.assertEquals("2aef808fb42fa7b1ba76cb16644773f9902a3fdc2569e8fdc049f38280c4577e", DigestUtils.sha256Hex(response.getBody()));
}

@Test
void testStreamingValidTokenValidFileRangePlain() {
HttpResponse<byte[]> response = Unirest.get("http://localhost:8080/files/EGAF00000000014?startCoordinate=100&endCoordinate=200").header(HttpHeaders.AUTHORIZATION, "Bearer " + validToken).asBytes();
int status = response.getStatus();
Assert.assertEquals(HttpStatus.OK.value(), status);
Assert.assertEquals("09fbeae7cce2cd410b471b0a1a265fb53dc54c66c4c7c3111b8b9b95ac0e956f", DigestUtils.sha256Hex(response.getBody()));
Assertions.assertEquals(HttpStatus.OK.value(), status);
Assertions.assertEquals("09fbeae7cce2cd410b471b0a1a265fb53dc54c66c4c7c3111b8b9b95ac0e956f", DigestUtils.sha256Hex(response.getBody()));
}

@SneakyThrows
Expand All @@ -179,11 +176,11 @@ void testStreamingValidTokenValidFileFullEncrypted() {
PrivateKey privateKey = KeyUtils.getInstance().readPrivateKey(new File("test/crypt4gh.sec.pem"), "password".toCharArray());
HttpResponse<byte[]> response = Unirest.get("http://localhost:8080/files/EGAF00000000014?destinationFormat=crypt4gh").header(HttpHeaders.AUTHORIZATION, "Bearer " + validToken).header("Public-Key", publicKey).asBytes();
int status = response.getStatus();
Assert.assertEquals(HttpStatus.OK.value(), status);
Assertions.assertEquals(HttpStatus.OK.value(), status);
try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(response.getBody());
Crypt4GHInputStream crypt4GHInputStream = new Crypt4GHInputStream(byteArrayInputStream, privateKey)) {
byte[] bytes = IOUtils.toByteArray(crypt4GHInputStream);
Assert.assertEquals("2aef808fb42fa7b1ba76cb16644773f9902a3fdc2569e8fdc049f38280c4577e", DigestUtils.sha256Hex(bytes));
Assertions.assertEquals("2aef808fb42fa7b1ba76cb16644773f9902a3fdc2569e8fdc049f38280c4577e", DigestUtils.sha256Hex(bytes));
}
}

Expand All @@ -194,75 +191,75 @@ void testStreamingValidTokenValidFileRangeEncrypted() {
PrivateKey privateKey = KeyUtils.getInstance().readPrivateKey(new File("test/crypt4gh.sec.pem"), "password".toCharArray());
HttpResponse<byte[]> response = Unirest.get("http://localhost:8080/files/EGAF00000000014?startCoordinate=100&endCoordinate=200&destinationFormat=crypt4gh").header(HttpHeaders.AUTHORIZATION, "Bearer " + validToken).header("Public-Key", publicKey).asBytes();
int status = response.getStatus();
Assert.assertEquals(HttpStatus.OK.value(), status);
Assertions.assertEquals(HttpStatus.OK.value(), status);
try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(response.getBody());
Crypt4GHInputStream crypt4GHInputStream = new Crypt4GHInputStream(byteArrayInputStream, privateKey)) {
byte[] bytes = IOUtils.toByteArray(crypt4GHInputStream);
Assert.assertEquals("09fbeae7cce2cd410b471b0a1a265fb53dc54c66c4c7c3111b8b9b95ac0e956f", DigestUtils.sha256Hex(bytes));
Assertions.assertEquals("09fbeae7cce2cd410b471b0a1a265fb53dc54c66c4c7c3111b8b9b95ac0e956f", DigestUtils.sha256Hex(bytes));
}
}

@SneakyThrows
@Test
void testPOSIXExportRequestFileValidToken() {
if (System.getenv("OUTBOX_TYPE").equals("S3")) {
Assert.assertTrue(true);
Assertions.assertTrue(true);
return;
}
export("EGAF00000000014", false);
PrivateKey privateKey = KeyUtils.getInstance().readPrivateKey(new File("test/my.sec.pem"), "passw0rd".toCharArray());
try (InputStream byteArrayInputStream = new FileInputStream("[email protected]/files/body.enc");
Crypt4GHInputStream crypt4GHInputStream = new Crypt4GHInputStream(byteArrayInputStream, privateKey)) {
byte[] bytes = IOUtils.toByteArray(crypt4GHInputStream);
Assert.assertEquals("2aef808fb42fa7b1ba76cb16644773f9902a3fdc2569e8fdc049f38280c4577e", DigestUtils.sha256Hex(bytes));
Assertions.assertEquals("2aef808fb42fa7b1ba76cb16644773f9902a3fdc2569e8fdc049f38280c4577e", DigestUtils.sha256Hex(bytes));
}
}

@SneakyThrows
@Test
void testPOSIXExportRequestDatasetValidToken() {
if (System.getenv("OUTBOX_TYPE").equals("S3")) {
Assert.assertTrue(true);
Assertions.assertTrue(true);
return;
}
export("EGAD00010000919", true);
PrivateKey privateKey = KeyUtils.getInstance().readPrivateKey(new File("test/my.sec.pem"), "passw0rd".toCharArray());
try (InputStream byteArrayInputStream = new FileInputStream("[email protected]/files/body.enc");
Crypt4GHInputStream crypt4GHInputStream = new Crypt4GHInputStream(byteArrayInputStream, privateKey)) {
byte[] bytes = IOUtils.toByteArray(crypt4GHInputStream);
Assert.assertEquals("2aef808fb42fa7b1ba76cb16644773f9902a3fdc2569e8fdc049f38280c4577e", DigestUtils.sha256Hex(bytes));
Assertions.assertEquals("2aef808fb42fa7b1ba76cb16644773f9902a3fdc2569e8fdc049f38280c4577e", DigestUtils.sha256Hex(bytes));
}
}

@SneakyThrows
@Test
void testS3ExportRequestFileValidToken() {
if (System.getenv("OUTBOX_TYPE").equals("POSIX")) {
Assert.assertTrue(true);
Assertions.assertTrue(true);
return;
}
export("EGAF00000000014", false);
PrivateKey privateKey = KeyUtils.getInstance().readPrivateKey(new File("test/my.sec.pem"), "passw0rd".toCharArray());
try (InputStream byteArrayInputStream = getMinioClient().getObject(GetObjectArgs.builder().bucket("lega").object("[email protected]/body.enc").build());
Crypt4GHInputStream crypt4GHInputStream = new Crypt4GHInputStream(byteArrayInputStream, privateKey)) {
byte[] bytes = IOUtils.toByteArray(crypt4GHInputStream);
Assert.assertEquals("2aef808fb42fa7b1ba76cb16644773f9902a3fdc2569e8fdc049f38280c4577e", DigestUtils.sha256Hex(bytes));
Assertions.assertEquals("2aef808fb42fa7b1ba76cb16644773f9902a3fdc2569e8fdc049f38280c4577e", DigestUtils.sha256Hex(bytes));
}
}

@SneakyThrows
@Test
void testS3ExportRequestDatasetValidToken() {
if (System.getenv("OUTBOX_TYPE").equals("POSIX")) {
Assert.assertTrue(true);
Assertions.assertTrue(true);
return;
}
export("EGAD00010000919", true);
PrivateKey privateKey = KeyUtils.getInstance().readPrivateKey(new File("test/my.sec.pem"), "passw0rd".toCharArray());
try (InputStream byteArrayInputStream = getMinioClient().getObject(GetObjectArgs.builder().bucket("lega").object("[email protected]/body.enc").build());
Crypt4GHInputStream crypt4GHInputStream = new Crypt4GHInputStream(byteArrayInputStream, privateKey)) {
byte[] bytes = IOUtils.toByteArray(crypt4GHInputStream);
Assert.assertEquals("2aef808fb42fa7b1ba76cb16644773f9902a3fdc2569e8fdc049f38280c4577e", DigestUtils.sha256Hex(bytes));
Assertions.assertEquals("2aef808fb42fa7b1ba76cb16644773f9902a3fdc2569e8fdc049f38280c4577e", DigestUtils.sha256Hex(bytes));
}
}

Expand Down

0 comments on commit 110b185

Please sign in to comment.