Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ init:
skip_tags: true

environment:
JAVA_HOME: C:\Program Files\Java\jdk1.8.0
JAVA_HOME: C:\Program Files\Java\jdk17
M2: $(USERPROFILE)\.m2

install:
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</developers>

<properties>
<java.version>1.8</java.version>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<revision>1.0.0-SNAPSHOT</revision>
</properties>
Expand All @@ -67,7 +67,7 @@
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>2.9.4</version>
<version>3.2.3</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand All @@ -94,7 +94,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<version>3.11.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.xml.sax.InputSource;

import javax.crypto.Cipher;
import javax.xml.bind.DatatypeConverter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
Expand All @@ -25,6 +24,7 @@
import java.security.spec.RSAPublicKeySpec;
import java.time.Duration;
import java.time.Instant;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -142,8 +142,8 @@ private String getEncryptedPassword(String plaintextPassword) {
String modulusText = xpath.evaluate("/RSAKeyValue/Modulus", document);
String exponentText = xpath.evaluate("/RSAKeyValue/Exponent", document);

byte[] modulusByes = DatatypeConverter.parseBase64Binary(modulusText);
byte[] exponentBytes = DatatypeConverter.parseBase64Binary(exponentText);
byte[] modulusByes = Base64.getDecoder().decode(modulusText);
byte[] exponentBytes = Base64.getDecoder().decode(exponentText);

BigInteger modulus = new BigInteger(1, modulusByes);
BigInteger exponent = new BigInteger(1, exponentBytes);
Expand All @@ -159,7 +159,7 @@ private String getEncryptedPassword(String plaintextPassword) {

// And finally, you can transform the blob into a base-64 string to assign the to
// the EncryptedPassword property of the login DTO:
return DatatypeConverter.printBase64Binary(encryptedPasswordBlob);
return Base64.getEncoder().encodeToString(encryptedPasswordBlob);
}
catch(Exception e) {
return plaintextPassword;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.aquaticinformatics.aquarius.sdk.samples;

import java.io.File;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

import junitparams.JUnitParamsRunner;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
Expand All @@ -10,6 +15,9 @@
import org.junit.runner.RunWith;
import org.junit.experimental.categories.Category;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

@Category(TestRequiresCredentials.class)
@RunWith(JUnitParamsRunner.class)
public class SamplesClientTest {
Expand Down Expand Up @@ -47,4 +55,56 @@ public void GetLabs_ConnectedClient_ReturnsSearchResultLaboratory() {
System.out.printf("Found %d laboratories\n", searchResultLaboratory.TotalCount);
}


@Test
public void PostLocation_ConnectedClient_IsSuccessful() {
ServiceModel.PostSamplingLocation request = new ServiceModel.PostSamplingLocation();
String locationId = "location customId" + UUID.randomUUID();
request.CustomId = locationId;
ServiceModel.SamplingLocation post = client.Api.post(request);
assertEquals(post.getCustomId(), locationId);
}


@Test
public void PostUploadAttachment_WithCsvFile_IsSuccessfulAndSetsCorrectMimeType() {
ServiceModel.PostUploadAttachment postUploadAttachment = new ServiceModel.PostUploadAttachment();
File file = new File("src/test/resources/test-csv-attachment.csv");
ServiceModel.AttachmentRepresentation attachmentRepresentation = client.postFileWithRequest(file, postUploadAttachment);

assertEquals(true, attachmentRepresentation.Success);
assertEquals("text/csv", attachmentRepresentation.ContentType);
assertEquals("test-csv-attachment.csv", attachmentRepresentation.FileName);
}

@Test
public void PostLocationAttachment_WithAttachment_IsSuccessful() {
ServiceModel.PostUploadAttachment postUploadAttachment = new ServiceModel.PostUploadAttachment();
File file = new File("src/test/resources/test-csv-attachment.csv");
ServiceModel.AttachmentRepresentation attachmentRepresentation = client.postFileWithRequest(file, postUploadAttachment);

ServiceModel.PostSamplingLocation postSamplingLocation = new ServiceModel.PostSamplingLocation();
postSamplingLocation.CustomId = UUID.randomUUID().toString();
ServiceModel.DomainObjectAttachment e1 = mapToDomainObjectAttachment(attachmentRepresentation);
postSamplingLocation.Attachments = List.of(e1);
ServiceModel.SamplingLocation post = client.Api.post(postSamplingLocation);
assertEquals(1, post.Attachments.size());
ServiceModel.Attachment firstAttachment = post.getAttachments().get(0).getAttachment();
assertEquals("test-csv-attachment.csv", firstAttachment.FileName);

}

private static ServiceModel.DomainObjectAttachment mapToDomainObjectAttachment(ServiceModel.AttachmentRepresentation from) {
ServiceModel.DomainObjectAttachment e1 =
new ServiceModel.DomainObjectAttachment();
e1.Id = from.getId();
ServiceModel.Attachment to = new ServiceModel.Attachment();
to.setId(from.getId());
to.setFileSize(from.getFileSize());
to.setFileName(from.getFileName());
to.setContentType(from.getContentType());
to.setFileSize(from.getFileSize());
e1.Attachment = to;
return e1;
}
}
2 changes: 2 additions & 0 deletions src/test/resources/test-csv-attachment.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Header1,Header2
a,b