Skip to content

Commit d962055

Browse files
Merge branch 'master' into submit_collection_endpoint
2 parents 0e3102b + 70f19f6 commit d962055

File tree

13 files changed

+188
-156
lines changed

13 files changed

+188
-156
lines changed

.github/workflows/ci-build.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ jobs:
1313
matrix:
1414
java_version:
1515
- 11
16-
# Errors with `java.lang.IllegalArgumentException: ArquillianServletRunnerEE9 not found. Could not determine ContextRoot from ProtocolMetadata, please contact DeployableContainer developer.`
17-
# Bumping various Arquillian dependencies does not fix, leave as just Java 11
18-
# - 17
16+
- 21
1917

2018
steps:
2119
- name: Setup Java

.github/workflows/release-build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
- name: Set up JDK 11
1717
uses: actions/setup-java@v4
1818
with:
19+
distribution: 'temurin'
1920
java-version: 11
2021

2122
- name: Cache maven dependencies
@@ -64,7 +65,7 @@ jobs:
6465
if: ${{ github.ref == 'refs/heads/master' }}
6566

6667
- name: Create/update release
67-
uses: johnwbyrd/update-release@v1.0.0
68+
uses: IsaacShelton/update-existing-release@v1.3.4
6869
with:
6970
token: ${{ secrets.GITHUB_TOKEN }}
7071
files: ./datagateway-download-api-${{ env.VERSION }}-distro.zip

pom.xml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
<dependency>
127127
<groupId>org.jboss.arquillian</groupId>
128128
<artifactId>arquillian-bom</artifactId>
129-
<version>1.7.0.Final</version>
129+
<version>1.9.5.Final</version>
130130
<scope>import</scope>
131131
<type>pom</type>
132132
</dependency>
@@ -153,14 +153,14 @@
153153
<version>1.2.13</version>
154154
</dependency>
155155
<dependency>
156-
<groupId>junit</groupId>
157-
<artifactId>junit</artifactId>
158-
<version>4.13.2</version>
156+
<groupId>org.junit.jupiter</groupId>
157+
<artifactId>junit-jupiter</artifactId>
158+
<version>5.13.1</version>
159159
<scope>test</scope>
160160
</dependency>
161161
<dependency>
162-
<groupId>org.jboss.arquillian.junit</groupId>
163-
<artifactId>arquillian-junit-container</artifactId>
162+
<groupId>org.jboss.arquillian.junit5</groupId>
163+
<artifactId>arquillian-junit5-container</artifactId>
164164
<scope>test</scope>
165165
</dependency>
166166
<!-- required for @Transactional annotation -->
@@ -208,13 +208,13 @@
208208
<dependency>
209209
<groupId>org.omnifaces.arquillian</groupId>
210210
<artifactId>arquillian-glassfish-server-embedded</artifactId>
211-
<version>1.4</version>
211+
<version>1.8</version>
212212
<scope>test</scope>
213213
</dependency>
214214
<dependency>
215215
<groupId>org.glassfish.main.extras</groupId>
216216
<artifactId>glassfish-embedded-all</artifactId>
217-
<version>7.0.5</version>
217+
<version>7.0.25</version>
218218
<scope>test</scope>
219219
</dependency>
220220
<dependency>
@@ -242,9 +242,11 @@
242242
GlassFish to retarget the derby log file -->
243243
<plugin>
244244
<artifactId>maven-surefire-plugin</artifactId>
245-
<version>2.19.1</version>
245+
<version>3.5.3</version>
246246
<configuration>
247-
<argLine>-Xmx768m -XX:MaxMetaspaceSize=256m</argLine>
247+
<!-- Required for jdk 17+ -->
248+
<argLine>--add-opens java.base/java.lang=ALL-UNNAMED</argLine>
249+
248250
<systemPropertyVariables>
249251
<java.util.logging.config.file>
250252
${project.build.testOutputDirectory}/logging.properties

src/main/java/org/icatproject/topcat/repository/CacheRepository.java

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class CacheRepository {
2727
@PersistenceContext(unitName = "topcat")
2828
EntityManager em;
2929

30-
private static final Logger logger = LoggerFactory.getLogger(ConfVarRepository.class);
30+
private static final Logger logger = LoggerFactory.getLogger(CacheRepository.class);
3131

3232
public Object get(String key, Long seconds){
3333
Cache cache = getCache(key);
@@ -80,27 +80,32 @@ public void remove(String key) {
8080

8181
@Schedule(hour="*", minute="0")
8282
public void prune(){
83-
Properties properties = Properties.getInstance();
84-
Integer maxCacheSize = Integer.valueOf(properties.getProperty("maxCacheSize", "10000"));
85-
86-
TypedQuery<Cache> query = em.createQuery("select cache from Cache cache order by cache.lastAccessTime desc", Cache.class);
87-
query.setMaxResults(maxCacheSize);
88-
89-
List<Cache> caches;
90-
int page = 1;
91-
while(true){
92-
query.setFirstResult(maxCacheSize * page);
93-
caches = query.getResultList();
94-
if(caches.size() > 0){
95-
for(Cache cache : caches){
96-
em.remove(cache);
83+
try {
84+
Properties properties = Properties.getInstance();
85+
Integer maxCacheSize = Integer.valueOf(properties.getProperty("maxCacheSize", "10000"));
86+
87+
TypedQuery<Cache> query = em.createQuery("select cache from Cache cache order by cache.lastAccessTime desc", Cache.class);
88+
query.setMaxResults(maxCacheSize);
89+
90+
List<Cache> caches;
91+
int page = 1;
92+
while(true){
93+
query.setFirstResult(maxCacheSize * page);
94+
caches = query.getResultList();
95+
if(caches.size() > 0){
96+
for(Cache cache : caches){
97+
em.remove(cache);
98+
}
99+
} else {
100+
break;
97101
}
98-
} else {
99-
break;
100102
}
101-
}
102103

103-
em.flush();
104+
em.flush();
105+
} catch (RuntimeException e) {
106+
// Catch exceptions to prevent the EJBTimerService from crashing
107+
logger.error("Unhandled exception in prune()", e);
108+
}
104109
}
105110

106111
private Cache getCache(String key){

src/test/java/org/icatproject/topcat/AdminResourceTest.java

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,46 @@
11
package org.icatproject.topcat;
22

3-
import java.util.*;
3+
import java.net.URLEncoder;
4+
import java.util.ArrayList;
45
import java.util.Date;
5-
import java.io.File;
6-
import java.lang.reflect.*;
6+
import java.util.HashMap;
7+
import java.util.List;
8+
import java.util.Map;
9+
10+
import jakarta.inject.Inject;
11+
import jakarta.json.JsonObject;
12+
import jakarta.ejb.EJB;
13+
import jakarta.ws.rs.core.Response;
714

815
import org.jboss.arquillian.container.test.api.Deployment;
9-
import org.jboss.arquillian.junit.Arquillian;
16+
import org.jboss.arquillian.junit5.container.annotation.ArquillianTest;
1017
import org.jboss.shrinkwrap.api.ShrinkWrap;
1118
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
1219
import org.jboss.shrinkwrap.api.spec.JavaArchive;
1320

14-
import static org.junit.Assert.*;
15-
import org.junit.*;
16-
import org.junit.runner.RunWith;
17-
import jakarta.inject.Inject;
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertFalse;
23+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
24+
import static org.junit.jupiter.api.Assertions.assertNotNull;
25+
import static org.junit.jupiter.api.Assertions.assertNull;
26+
import static org.junit.jupiter.api.Assertions.fail;
1827

19-
import jakarta.json.*;
20-
import jakarta.ws.rs.core.Response;
21-
import jakarta.ejb.EJB;
28+
import org.junit.jupiter.api.BeforeAll;
29+
import org.junit.jupiter.api.BeforeEach;
30+
import org.junit.jupiter.api.Test;
2231

2332
import org.icatproject.topcat.httpclient.HttpClient;
24-
import org.icatproject.topcat.domain.*;
25-
import org.icatproject.topcat.exceptions.BadRequestException;
33+
import org.icatproject.topcat.domain.Download;
34+
import org.icatproject.topcat.domain.DownloadStatus;
35+
import org.icatproject.topcat.domain.DownloadType;
2636
import org.icatproject.topcat.exceptions.ForbiddenException;
27-
28-
import java.net.URLEncoder;
29-
3037
import org.icatproject.topcat.repository.CacheRepository;
3138
import org.icatproject.topcat.repository.ConfVarRepository;
3239
import org.icatproject.topcat.repository.DownloadRepository;
3340
import org.icatproject.topcat.repository.DownloadTypeRepository;
3441
import org.icatproject.topcat.web.rest.AdminResource;
3542

36-
import java.sql.*;
37-
38-
@RunWith(Arquillian.class)
43+
@ArquillianTest
3944
public class AdminResourceTest {
4045

4146
/*
@@ -71,12 +76,12 @@ public static JavaArchive createDeployment() {
7176
private static String adminSessionId;
7277
private static String nonAdminSessionId;
7378

74-
@BeforeClass
79+
@BeforeAll
7580
public static void beforeAll() {
7681
TestHelpers.installTrustManager();
7782
}
7883

79-
@Before
84+
@BeforeEach
8085
public void setup() throws Exception {
8186
HttpClient httpClient = new HttpClient("https://localhost:8181/icat");
8287

@@ -194,7 +199,7 @@ public void testDownloadAPI() throws Exception {
194199
downloads = (List<Download>) response.getEntity();
195200

196201
testDownload = findDownload(downloads, testDownload.getId());
197-
assertTrue(testDownload.getIsDeleted() != currentDeleted);
202+
assertNotEquals(testDownload.getIsDeleted(), currentDeleted);
198203

199204
// Test that getDownloadStatus() etc. produce an error response for a non-admin
200205
// user
@@ -206,7 +211,6 @@ public void testDownloadAPI() throws Exception {
206211
+ (String) response.getEntity());
207212
fail("AdminResource.getDownloads did not raise exception for non-admin user");
208213
} catch (ForbiddenException fe) {
209-
assertTrue(true);
210214
}
211215

212216
try {
@@ -217,7 +221,6 @@ public void testDownloadAPI() throws Exception {
217221
+ (String) response.getEntity());
218222
fail("AdminResource.setDownloadStatus did not raise exception for non-admin user");
219223
} catch (ForbiddenException fe) {
220-
assertTrue(true);
221224
}
222225

223226
try {
@@ -228,7 +231,6 @@ public void testDownloadAPI() throws Exception {
228231
+ (String) response.getEntity());
229232
fail("AdminResource.deleteDownload did not raise exception for non-admin user");
230233
} catch (ForbiddenException fe) {
231-
assertTrue(true);
232234
}
233235
} finally {
234236
// Remove the test download from the repository
@@ -308,7 +310,7 @@ public void testSetDownloadTypeStatus() throws Exception {
308310
if (dt != null) {
309311
System.out.println(
310312
"DEBUG: AdminRT final download type status is {" + dt.getDisabled() + "," + dt.getMessage() + "}");
311-
assertTrue(disabled != dt.getDisabled());
313+
assertNotEquals(disabled, dt.getDisabled());
312314
assertEquals(message, dt.getMessage());
313315
}
314316

@@ -322,7 +324,6 @@ public void testSetDownloadTypeStatus() throws Exception {
322324
+ (String) response.getEntity());
323325
fail("AdminResource.setDownloadTypeStatus did not raise exception for non-admin user");
324326
} catch (ForbiddenException fe) {
325-
assertTrue(true);
326327
}
327328

328329
// Finally, ought to reset the disabled status to the original value!
@@ -406,7 +407,6 @@ public void testClearCachedSize() throws Exception {
406407
+ (String) response.getEntity());
407408
fail("AdminResource.clearCachedSize did not raise exception for non-admin user");
408409
} catch (ForbiddenException fe) {
409-
assertTrue(true);
410410
}
411411
}
412412

@@ -437,7 +437,6 @@ public void testSetConfVar() throws Exception {
437437
+ (String) response.getEntity());
438438
fail("AdminResource.setConfVar did not raise exception for non-admin user");
439439
} catch (ForbiddenException fe) {
440-
assertTrue(true);
441440
}
442441
}
443442

src/test/java/org/icatproject/topcat/CacheRepositoryTest.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
package org.icatproject.topcat;
22

3-
import java.util.*;
4-
import java.lang.reflect.*;
3+
import jakarta.inject.Inject;
54

65
import org.jboss.arquillian.container.test.api.Deployment;
7-
import org.jboss.arquillian.junit.Arquillian;
6+
import org.jboss.arquillian.junit5.container.annotation.ArquillianTest;
87
import org.jboss.shrinkwrap.api.ShrinkWrap;
98
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
109
import org.jboss.shrinkwrap.api.spec.JavaArchive;
11-
import static org.junit.Assert.*;
12-
import org.junit.*;
13-
import org.junit.runner.RunWith;
14-
import jakarta.inject.Inject;
1510

11+
import static org.junit.jupiter.api.Assertions.assertEquals;
12+
import static org.junit.jupiter.api.Assertions.assertNull;
1613

17-
import jakarta.ejb.EJB;
14+
import org.junit.jupiter.api.Test;
1815

1916
import org.icatproject.topcat.domain.Cache;
2017
import org.icatproject.topcat.repository.CacheRepository;
2118

22-
@RunWith(Arquillian.class)
19+
@ArquillianTest
2320
public class CacheRepositoryTest {
2421

2522
@Deployment
@@ -44,6 +41,6 @@ public void testRemove() {
4441
String key = "test:remove";
4542
cacheRepository.put(key, "Hello World");
4643
cacheRepository.remove(key);
47-
assertEquals(null,cacheRepository.get(key));
44+
assertNull(cacheRepository.get(key));
4845
}
49-
}
46+
}

src/test/java/org/icatproject/topcat/FacilityMapTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package org.icatproject.topcat;
22

3-
import static org.junit.Assert.*;
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertThrows;
45

56
import java.util.HashMap;
67
import java.util.Map;
78

89
import org.icatproject.topcat.exceptions.InternalException;
9-
import org.junit.*;
10-
import org.junit.function.ThrowingRunnable;
10+
import org.junit.jupiter.api.Test;
11+
import org.junit.jupiter.api.function.Executable;
1112

1213
public class FacilityMapTest {
1314

@@ -153,7 +154,7 @@ public void testGetIcatUrlFailure() throws InternalException{
153154

154155
FacilityMap facilityMap = new FacilityMap(props);
155156

156-
ThrowingRunnable runnable = () -> {facilityMap.getIcatUrl(null);};
157+
Executable runnable = () -> {facilityMap.getIcatUrl(null);};
157158
assertThrows(InternalException.class, runnable);
158159
}
159160
}

0 commit comments

Comments
 (0)