Skip to content

Commit

Permalink
chore: Updates deps (#10)
Browse files Browse the repository at this point in the history
* chore: upgrade to apache httpclient5

* chore: upgrade to maven-antrun-plugin v3

* chore: update dependancies

* chore: use working izpack version

* chore: cleanup deps

* perf: drop Hamcrest to Assertj
  • Loading branch information
jy95 authored Sep 7, 2023
1 parent d772df9 commit 33adff1
Show file tree
Hide file tree
Showing 12 changed files with 423 additions and 472 deletions.
8 changes: 4 additions & 4 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.14</version>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
Expand All @@ -102,7 +102,7 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.18.1</version>
<version>3.24.2</version>
</dependency>

</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.config.ConnectionConfig;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
import org.apache.hc.core5.http.io.entity.EntityUtils;
//import org.apache.logging.log4j.LogManager;
//import org.apache.logging.log4j.Logger;
import org.imec.ivlab.core.exceptions.ExternalConnectionException;
import org.imec.ivlab.core.exceptions.RemoteVersionCheckFailedException;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

public class RemoteVersionReader {

Expand All @@ -24,8 +26,9 @@ public class RemoteVersionReader {
private final static String OWNER = "smals-jy"; // Replace with your GitHub username or organization name
private final static String REPO_NAME = "evs"; // Replace with your repository name
private final static String LATEST_RELEASE_PATH = "/releases/latest";
private final static int CONNECTION_TIMEOUT = 2000;
private final static int SOCKET_TIMEOUT = 2000;
private final static int CONNECTION_TIMEOUT = 2;
private final static int SOCKET_TIMEOUT = 2;
private final static TimeUnit TIMEOUT_UNIT = TimeUnit.SECONDS;

protected static String getRemoteVersion() throws RemoteVersionCheckFailedException {
GitHubRelease latesGitHubRelease = getLatestGitHubRelease();
Expand All @@ -49,14 +52,28 @@ private static GitHubRelease getLatestGitHubRelease() throws RemoteVersionCheckF
private static String sendGetRequest(String url) throws ExternalConnectionException {

try {
RequestConfig.Builder requestBuilder = RequestConfig.custom().setConnectTimeout(CONNECTION_TIMEOUT).setSocketTimeout(SOCKET_TIMEOUT);
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
httpClientBuilder.setDefaultRequestConfig(requestBuilder.build());
CloseableHttpClient httpClient = httpClientBuilder.build();

ConnectionConfig connectionConfig = ConnectionConfig
.custom()
.setConnectTimeout(CONNECTION_TIMEOUT, TIMEOUT_UNIT)
.setSocketTimeout(SOCKET_TIMEOUT, TIMEOUT_UNIT)
.build();

CloseableHttpClient httpClient = HttpClientBuilder
.create()
.setConnectionManager(
PoolingHttpClientConnectionManagerBuilder
.create()
.setDefaultConnectionConfig(connectionConfig)
.build()
)
.build();
HttpGet request = new HttpGet(url);
request.addHeader("Accept", "application/vnd.github.v3+json"); // Specify GitHub API version
CloseableHttpResponse result = httpClient.execute(request);
return EntityUtils.toString(result.getEntity(), "UTF-8");
return httpClient.execute(request, response -> {
response.getEntity();
return EntityUtils.toString(response.getEntity(), "UTF-8");
});
} catch (IOException e) {
throw new ExternalConnectionException(e);
}
Expand Down
52 changes: 25 additions & 27 deletions core/src/test/java/org/imec/ivlab/core/RangeCheckerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,47 @@
import org.imec.ivlab.core.model.internal.mapper.medication.Suspension;
import org.imec.ivlab.core.model.internal.mapper.medication.TimeUnit;
import org.imec.ivlab.core.model.internal.mapper.medication.Weekday;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import org.joda.time.LocalDate;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
import static org.assertj.core.api.Assertions.assertThat;

import org.testng.Assert;
import org.testng.annotations.Test;

@org.testng.annotations.Test
@Test
public class RangeCheckerTest {

@org.testng.annotations.Test
@Test
public void calculateActivePeriodsMedicationWithEndmomentAndStopped() {
MedicationEntry medicationEntry = createMedicationEntry(new LocalDate(2017, 5, 15), new LocalDate(2020, 10, 20));
medicationEntry.setSuspensions(createSuspensionsWithLastOneStopped());

RangeChecker rangeChecker = new RangeChecker();
List<Period> periods = rangeChecker.calculateActivePeriods(medicationEntry);

assertThat(periods, hasSize(3));
assertThat(periods, contains( new Period(new LocalDate(2017, 5, 15), new LocalDate(2017, 7, 12)),
assertThat(periods).hasSize(3);
assertThat(periods).containsExactly( new Period(new LocalDate(2017, 5, 15), new LocalDate(2017, 7, 12)),
new Period(new LocalDate(2017, 9, 14), new LocalDate(2017, 9, 14)),
new Period(new LocalDate(2017, 9, 20), new LocalDate(2020, 10, 17))));
new Period(new LocalDate(2017, 9, 20), new LocalDate(2020, 10, 17)));

}

@org.testng.annotations.Test
@Test
public void calculateActivePeriodsMedicationWithoutEndmomentAndStopped() {
MedicationEntry medicationEntry = createMedicationEntry(new LocalDate(2017, 5, 15), null);
medicationEntry.setSuspensions(createSuspensionsWithLastOneStopped());

RangeChecker rangeChecker = new RangeChecker();
List<Period> periods = rangeChecker.calculateActivePeriods(medicationEntry);

assertThat(periods, hasSize(3));
assertThat(periods, contains( new Period(new LocalDate(2017, 5, 15), new LocalDate(2017, 7, 12)),
assertThat(periods).hasSize(3);
assertThat(periods).containsExactly( new Period(new LocalDate(2017, 5, 15), new LocalDate(2017, 7, 12)),
new Period(new LocalDate(2017, 9, 14), new LocalDate(2017, 9, 14)),
new Period(new LocalDate(2017, 9, 20), new LocalDate(2020, 10, 17))));
new Period(new LocalDate(2017, 9, 20), new LocalDate(2020, 10, 17)));

}

Expand All @@ -63,35 +61,35 @@ private MedicationEntry createMedicationEntry(LocalDate beginmoment, LocalDate e

}

@org.testng.annotations.Test
@Test
public void calculateActivePeriodsMedicationWithEndmomentAndSuspended() {
MedicationEntry medicationEntry = createMedicationEntry(new LocalDate(2017, 5, 15), new LocalDate(2020, 10, 20));
medicationEntry.setSuspensions(createSuspensionsWithLastSuspended());

RangeChecker rangeChecker = new RangeChecker();
List<Period> periods = rangeChecker.calculateActivePeriods(medicationEntry);

assertThat(periods, hasSize(4));
assertThat(periods, contains( new Period(new LocalDate(2017, 5, 15), new LocalDate(2017, 7, 12)),
assertThat(periods).hasSize(4);
assertThat(periods).containsExactly( new Period(new LocalDate(2017, 5, 15), new LocalDate(2017, 7, 12)),
new Period(new LocalDate(2017, 9, 14), new LocalDate(2017, 9, 14)),
new Period(new LocalDate(2017, 9, 20), new LocalDate(2020, 10, 17)),
new Period(new LocalDate(2020, 10, 20), new LocalDate(2020, 10, 20))));
new Period(new LocalDate(2020, 10, 20), new LocalDate(2020, 10, 20)));

}

@org.testng.annotations.Test
@Test
public void calculateActivePeriodsMedicationWithoutEndmomentAndSuspended() {
MedicationEntry medicationEntry = createMedicationEntry(new LocalDate(2017, 5, 15), null);
medicationEntry.setSuspensions(createSuspensionsWithLastSuspended());

RangeChecker rangeChecker = new RangeChecker();
List<Period> periods = rangeChecker.calculateActivePeriods(medicationEntry);

assertThat(periods, hasSize(4));
assertThat(periods, contains( new Period(new LocalDate(2017, 5, 15), new LocalDate(2017, 7, 12)),
assertThat(periods).hasSize(4);
assertThat(periods).containsExactly( new Period(new LocalDate(2017, 5, 15), new LocalDate(2017, 7, 12)),
new Period(new LocalDate(2017, 9, 14), new LocalDate(2017, 9, 14)),
new Period(new LocalDate(2017, 9, 20), new LocalDate(2020, 10, 17)),
new Period(new LocalDate(2020, 10, 20), null)));
new Period(new LocalDate(2020, 10, 20), null));

}

Expand Down Expand Up @@ -181,7 +179,7 @@ private List<Suspension> createSuspensionsWithLastSuspended() {

}

@org.testng.annotations.Test
@Test
public void testIsActiveByDayNumberAndDailyFrequency() throws Exception {

LocalDate medicationBeginDate = new LocalDate(2017, 3, 2);
Expand All @@ -200,7 +198,7 @@ public void testIsActiveByDayNumberAndDailyFrequency() throws Exception {

}

@org.testng.annotations.Test
@Test
public void testIsActiveByDayNumberAndWeeklyFrequency() throws Exception {

LocalDate medicationBeginDate = new LocalDate(2017, 3, 2);
Expand Down Expand Up @@ -235,7 +233,7 @@ public void testIsActiveByDayNumberAndWeeklyFrequency() throws Exception {

}

@org.testng.annotations.Test
@Test
public void testIsActiveByWeekday() throws Exception {

LocalDate medicationBeginDate = new LocalDate(2017, 3, 2); // = THURSDAY
Expand All @@ -262,7 +260,7 @@ public void testIsActiveByWeekday() throws Exception {
}


@org.testng.annotations.Test
@Test
public void testIsActiveByDateForMonthlyFrequencies() throws Exception {

LocalDate medicationBeginDate = new LocalDate(2017, 3, 2);
Expand Down Expand Up @@ -300,7 +298,7 @@ public void testIsActiveByDateForMonthlyFrequencies() throws Exception {

}

@org.testng.annotations.Test
@Test
public void testIsActiveByDateForYearlyFrequencies() throws Exception {

LocalDate medicationBeginDate = new LocalDate(2017, 3, 2);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.imec.ivlab.core.model.internal.parser.sumehr.SumehrMapper;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.assertj.core.api.Assertions.assertThat;

import org.imec.ivlab.core.TestUtil;
import org.imec.ivlab.core.model.internal.parser.sumehr.Sumehr;
Expand All @@ -21,8 +20,8 @@ public void testKmehrToSumehr() {

Sumehr sumehr = SumehrMapper.kmehrToSumehr(sumehrList.getList().get(0).getKmehrMessage());

assertThat(sumehr.getMedicationEntries(), hasSize(4));
assertThat(sumehr.getHealthCareElements(), hasSize(6));
assertThat(sumehr.getMedicationEntries()).hasSize(4);
assertThat(sumehr.getHealthCareElements()).hasSize(6);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,44 @@
import java.util.Collection;
import java.util.Collections;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.assertj.core.api.Assertions.assertThat;

@org.testng.annotations.Test
public class KmehrExtractorTest {


@Test
public void testGetKmehrEntryListWithURIs() {

KmehrEntryList kmehrEntryList = TestUtil.getKmehrEntryList("10-kmehrs-10-uris.txt");
assertThat(CollectionUtils.size(removeNullValues(kmehrEntryList.getBusinessDataList())), equalTo(10));
assertThat(CollectionUtils.size(removeNullValues(kmehrEntryList.getURIList())), equalTo(10));
assertThat(CollectionUtils.size(removeNullValues(kmehrEntryList.getBusinessDataList()))).isEqualTo(10);
assertThat(CollectionUtils.size(removeNullValues(kmehrEntryList.getURIList()))).isEqualTo(10);

}

@Test
public void testGetKmehrEntryListWithURIsKmehrsNotAfterNewline() {

KmehrEntryList kmehrEntryList = TestUtil.getKmehrEntryList("10-kmehrs-10-uris-and-kmehrs-not-after-newline.txt");
assertThat(CollectionUtils.size(removeNullValues(kmehrEntryList.getBusinessDataList())), equalTo(10));
assertThat(CollectionUtils.size(removeNullValues(kmehrEntryList.getURIList())), equalTo(10));
assertThat(CollectionUtils.size(removeNullValues(kmehrEntryList.getBusinessDataList()))).isEqualTo(10);
assertThat(CollectionUtils.size(removeNullValues(kmehrEntryList.getURIList()))).isEqualTo(10);

}

@Test
public void testGetKmehrEntryListWithoutURIs() {

KmehrEntryList kmehrEntryList = TestUtil.getKmehrEntryList("10-kmehrs-no-uris.txt");
assertThat(CollectionUtils.size(removeNullValues(kmehrEntryList.getBusinessDataList())), equalTo(10));
assertThat(CollectionUtils.size(removeNullValues(kmehrEntryList.getURIList())), equalTo(0));
assertThat(CollectionUtils.size(removeNullValues(kmehrEntryList.getBusinessDataList()))).isEqualTo(10);
assertThat(CollectionUtils.size(removeNullValues(kmehrEntryList.getURIList()))).isEqualTo(0);

}

@Test
public void testGetKmehrEntryListWithoutURIsKmehrsNotAfterNewline() {

KmehrEntryList kmehrEntryList = TestUtil.getKmehrEntryList("10-kmehrs-no-uris-and-kmehrs-not-after-newline.txt");
assertThat(CollectionUtils.size(removeNullValues(kmehrEntryList.getBusinessDataList())), equalTo(10));
assertThat(CollectionUtils.size(removeNullValues(kmehrEntryList.getURIList())), equalTo(0));
assertThat(CollectionUtils.size(removeNullValues(kmehrEntryList.getBusinessDataList()))).isEqualTo(10);
assertThat(CollectionUtils.size(removeNullValues(kmehrEntryList.getURIList()))).isEqualTo(0);

}

Expand Down
Loading

0 comments on commit 33adff1

Please sign in to comment.