diff --git a/appveyor.yml b/appveyor.yml
index 40cdc56..b43f986 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -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:
diff --git a/pom.xml b/pom.xml
index 84234b0..85fe37e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -44,7 +44,7 @@
- 1.8
+ 17
UTF-8
1.0.0-SNAPSHOT
@@ -67,7 +67,7 @@
org.apache.tika
tika-core
- 2.9.4
+ 3.2.3
com.google.code.gson
@@ -94,7 +94,7 @@
org.apache.maven.plugins
maven-compiler-plugin
- 3.5
+ 3.11.0
${java.version}
${java.version}
diff --git a/src/main/java/com/aquaticinformatics/aquarius/sdk/timeseries/AquariusClient.java b/src/main/java/com/aquaticinformatics/aquarius/sdk/timeseries/AquariusClient.java
index 01f077f..7bc6de4 100644
--- a/src/main/java/com/aquaticinformatics/aquarius/sdk/timeseries/AquariusClient.java
+++ b/src/main/java/com/aquaticinformatics/aquarius/sdk/timeseries/AquariusClient.java
@@ -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;
@@ -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;
@@ -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);
@@ -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;
diff --git a/src/test/java/com/aquaticinformatics/aquarius/sdk/samples/SamplesClientTest.java b/src/test/java/com/aquaticinformatics/aquarius/sdk/samples/SamplesClientTest.java
index c884223..6c29334 100644
--- a/src/test/java/com/aquaticinformatics/aquarius/sdk/samples/SamplesClientTest.java
+++ b/src/test/java/com/aquaticinformatics/aquarius/sdk/samples/SamplesClientTest.java
@@ -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;
@@ -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 {
@@ -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;
+ }
}
diff --git a/src/test/resources/test-csv-attachment.csv b/src/test/resources/test-csv-attachment.csv
new file mode 100644
index 0000000..ffb5e18
--- /dev/null
+++ b/src/test/resources/test-csv-attachment.csv
@@ -0,0 +1,2 @@
+Header1,Header2
+a,b