Skip to content

Commit 1eb7655

Browse files
kinowmr-c
authored andcommitted
Fix MongoDB test
Had to add a new dependency for the embedded MongoDB server used for tests. The version of MongoDB used for tests (embedded) also needs to be defined now. And MongoDB/SpringData integration appears to be more strict. A query like { obj.property: ?0 } failed, and took me a long time to recognize that it was missing quotes, so { 'obj.property': ?0 } fixed it. Finally, there was also an issue with serialization. For some reason now the Mongo repository was failing to serialize a response for Workflow. The object contained a final String that was used for the base URL of permanent links, and Mongo/Spring/etc wanted a way to set that value in the constructor. Tried the @PersistenceConstructor annotation but that didn't work. In the end it was easy to fix it by making the final String now a constant
1 parent 510e3f4 commit 1eb7655

File tree

5 files changed

+48
-13
lines changed

5 files changed

+48
-13
lines changed

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@
130130
<version>1.10.19</version>
131131
<scope>test</scope>
132132
</dependency>
133+
<dependency>
134+
<groupId>de.flapdoodle.embed</groupId>
135+
<artifactId>de.flapdoodle.embed.mongo</artifactId>
136+
<scope>test</scope>
137+
</dependency>
133138
</dependencies>
134139

135140
<build>

src/main/java/org/commonwl/view/workflow/QueuedWorkflowRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public interface QueuedWorkflowRepository extends PagingAndSortingRepository<Que
1717
* @param retrievedFrom Details of where the queued workflow is from
1818
* @return The queued workflow
1919
*/
20-
@Query("{tempRepresentation.retrievedFrom: ?0}")
20+
@Query("{\"tempRepresentation.retrievedFrom\": ?0}")
2121
QueuedWorkflow findByRetrievedFrom(GitDetails retrievedFrom);
2222

2323
/**

src/main/java/org/commonwl/view/workflow/Workflow.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
package org.commonwl.view.workflow;
2121

22-
import java.util.Date;
23-
import java.util.Map;
24-
22+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
23+
import com.fasterxml.jackson.annotation.JsonInclude;
24+
import com.fasterxml.jackson.annotation.JsonProperty;
2525
import org.commonwl.view.WebConfig;
2626
import org.commonwl.view.WebConfig.Format;
2727
import org.commonwl.view.cwl.CWLElement;
@@ -32,9 +32,8 @@
3232
import org.springframework.data.mongodb.core.mapping.Document;
3333
import org.springframework.format.annotation.DateTimeFormat;
3434

35-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
36-
import com.fasterxml.jackson.annotation.JsonInclude;
37-
import com.fasterxml.jackson.annotation.JsonProperty;
35+
import java.util.Date;
36+
import java.util.Map;
3837

3938
/**
4039
* Representation of a workflow
@@ -78,7 +77,7 @@ public class Workflow {
7877
// DOT graph of the contents
7978
private String visualisationDot;
8079

81-
private final String permaLinkBase = "https://w3id.org/cwl/view";
80+
private static final String PERMANENT_LINK_BASE_URL = "https://w3id.org/cwl/view";
8281

8382
private String licenseLink;
8483

@@ -244,7 +243,7 @@ public String getPermalink() {
244243
* Permalink for a particular representation of this workflow. Note that
245244
* resolving the permalink will use the official deployment of the CWL Viewer.
246245
*
247-
* @see {@link https://w3id.org/cwl/view}
246+
* @see <a href="https://w3id.org/cwl/view">https://w3id.org/cwl/view</a>
248247
* @param format
249248
* Format of representation, or <code>null</code> for format-neutral
250249
* permalink that supports content negotiation.
@@ -263,7 +262,7 @@ public String getPermalink(WebConfig.Format format) {
263262
if (format != null) {
264263
formatPart = formatPartSep + "format=" + format.name();
265264
}
266-
return permaLinkBase + "/git/" + lastCommit +
265+
return PERMANENT_LINK_BASE_URL + "/git/" + lastCommit +
267266
"/" + retrievedFrom.getPath() + packedPart + formatPart;
268267
}
269268

@@ -275,7 +274,7 @@ public String getPermalink(WebConfig.Format format) {
275274
@JsonProperty(value = "@id", index = 0)
276275
public String getIdentifier() {
277276
String packedPart = (retrievedFrom.getPackedId() != null) ? "#" + retrievedFrom.getPackedId() : "";
278-
return permaLinkBase + "/git/" + lastCommit + "/" + retrievedFrom.getPath() + packedPart;
277+
return PERMANENT_LINK_BASE_URL + "/git/" + lastCommit + "/" + retrievedFrom.getPath() + packedPart;
279278

280279
}
281280

src/main/resources/application.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ singleFileSizeLimit = 5242880
2626
# File size limit for the contents of the research object bundle (not counting external links)
2727
totalFileSizeLimit = 1073741824
2828

29+
# Newer versions of Spring disallow pattern matching like '/workflows/**/*.git/{branch}/**', due
30+
# to the "No more pattern data allowed after {*...} or ** pattern element" error. This reverts to
31+
# the old behaviour.
32+
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
33+
2934
#=======================
3035
# Git API settings
3136
#=======================

src/test/java/org/commonwl/view/workflow/QueuedWorkflowRepositoryTest.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
package org.commonwl.view.workflow;
22

3+
import org.commonwl.view.CwlViewerApplication;
34
import org.commonwl.view.MongoConfig;
5+
import org.commonwl.view.WebConfig;
46
import org.commonwl.view.git.GitDetails;
57
import org.junit.jupiter.api.Test;
68
import org.springframework.beans.factory.annotation.Autowired;
79
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;
10+
import org.springframework.boot.test.context.SpringBootTest;
11+
import org.springframework.test.context.ActiveProfiles;
812
import org.springframework.test.context.ContextConfiguration;
913

1014
import static org.junit.jupiter.api.Assertions.assertNotNull;
1115
import static org.junit.jupiter.api.Assertions.assertNull;
1216

13-
@DataMongoTest
14-
@ContextConfiguration(classes={MongoConfig.class})
17+
// N.B. "To use embedded mongo, the spring.mongodb.embedded.version property must now be set."
18+
// https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.6-Release-Notes#embedded-mongo
19+
@SpringBootTest(
20+
properties={"spring.mongodb.embedded.version=3.2.2"},
21+
classes={MongoConfig.class, WebConfig.class, CwlViewerApplication.class, QueuedWorkflowRepository.class}
22+
)
1523
public class QueuedWorkflowRepositoryTest {
1624

1725
@Autowired
@@ -51,4 +59,22 @@ public void deleteQueuedWorkflowByRetrievedFromTest() {
5159

5260
}
5361

62+
@Test
63+
public void deleteQueuedWorkflowByRetrievedFromTest2() {
64+
// create stub queued workflow
65+
GitDetails gitDetails = new GitDetails("test_repo_url", "test_branch", "test_path");
66+
gitDetails.setPackedId("test_packedId");
67+
68+
Workflow workflow = new Workflow();
69+
workflow.setRetrievedFrom(gitDetails);
70+
71+
QueuedWorkflow queuedWorkflow = new QueuedWorkflow();
72+
queuedWorkflow.setTempRepresentation(workflow);
73+
74+
// save queued workflow
75+
repository.save(queuedWorkflow);
76+
77+
assertNotNull(workflow);
78+
}
79+
5480
}

0 commit comments

Comments
 (0)