Skip to content

Commit 2469d34

Browse files
committed
Introduced tests on Jongo id generation, spotting regressions in 0.35 compared to 0.34 regarding id generation cases
1 parent 0e201fd commit 2469d34

File tree

10 files changed

+152
-0
lines changed

10 files changed

+152
-0
lines changed

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@
214214
<artifactId>restx-core-java8</artifactId>
215215
<version>${restx.version}</version>
216216
</dependency>
217+
<dependency>
218+
<groupId>io.restx</groupId>
219+
<artifactId>restx-jongo-specs-tests</artifactId>
220+
<version>${restx.version}</version>
221+
</dependency>
217222
<dependency>
218223
<groupId>io.restx</groupId>
219224
<artifactId>restx-specs-tests-java8</artifactId>

restx-samplest/md.restx.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"io.restx:restx-validation:${restx.version}",
2020
"io.restx:restx-core-annotation-processor:${restx.version}",
2121
"io.restx:restx-factory:${restx.version}",
22+
"io.restx:restx-jongo:${restx.version}",
2223
"io.restx:restx-factory-admin:${restx.version}",
2324
"io.restx:restx-monitor-codahale:${restx.version}",
2425
"io.restx:restx-monitor-admin:${restx.version}",
@@ -34,6 +35,7 @@
3435
],
3536
"test": [
3637
"io.restx:restx-specs-tests:${restx.version}",
38+
"io.restx:restx-jongo-specs-tests:${restx.version}",
3739
"junit:junit:${junit.version}"
3840
]
3941
}

restx-samplest/module.ivy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<dependency org="io.restx" name="restx-validation" rev="latest.integration" conf="default" />
1919
<dependency org="io.restx" name="restx-core-annotation-processor" rev="latest.integration" conf="default" />
2020
<dependency org="io.restx" name="restx-factory" rev="latest.integration" conf="default" />
21+
<dependency org="io.restx" name="restx-jongo" rev="latest.integration" conf="default" />
2122
<dependency org="io.restx" name="restx-factory-admin" rev="latest.integration" conf="default" />
2223
<dependency org="io.restx" name="restx-monitor-codahale" rev="latest.integration" conf="default" />
2324
<dependency org="io.restx" name="restx-monitor-admin" rev="latest.integration" conf="default" />
@@ -29,6 +30,7 @@
2930
<dependency org="ch.qos.logback" name="logback-classic" rev="1.0.13" conf="default" />
3031
<dependency org="io.restx" name="restx-barbarywatch" rev="latest.integration" conf="runtime->default" />
3132
<dependency org="io.restx" name="restx-specs-tests" rev="latest.integration" conf="test->default" />
33+
<dependency org="io.restx" name="restx-jongo-specs-tests" rev="latest.integration" conf="test->default" />
3234
<dependency org="junit" name="junit" rev="4.11" conf="test->default" />
3335
</dependencies>
3436
</ivy-module>

restx-samplest/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
<groupId>io.restx</groupId>
3030
<artifactId>restx-factory</artifactId>
3131
</dependency>
32+
<dependency>
33+
<groupId>io.restx</groupId>
34+
<artifactId>restx-jongo</artifactId>
35+
</dependency>
3236
<dependency>
3337
<groupId>io.restx</groupId>
3438
<artifactId>restx-factory-admin</artifactId>
@@ -76,6 +80,11 @@
7680
<artifactId>restx-specs-tests</artifactId>
7781
<scope>test</scope>
7882
</dependency>
83+
<dependency>
84+
<groupId>io.restx</groupId>
85+
<artifactId>restx-jongo-specs-tests</artifactId>
86+
<scope>test</scope>
87+
</dependency>
7988
<dependency>
8089
<groupId>junit</groupId>
8190
<artifactId>junit</artifactId>

restx-samplest/src/main/java/samplest/AppModule.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,8 @@ public Optional<RestxPrincipal> findAndCheckCredentials(String name, String pass
5959
}, securitySettings);
6060
}
6161

62+
@Provides @Named("mongo.db") String mongoDb() {
63+
return "testing-mongo";
64+
}
65+
6266
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package samplest.jongo;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import org.bson.types.ObjectId;
5+
import org.jongo.marshall.jackson.oid.Id;
6+
import org.jongo.marshall.jackson.oid.MongoId;
7+
import org.jongo.marshall.jackson.oid.MongoObjectId;
8+
import restx.annotations.POST;
9+
import restx.annotations.RestxResource;
10+
import restx.factory.Component;
11+
import restx.jongo.JongoCollection;
12+
import restx.security.PermitAll;
13+
14+
import javax.inject.Named;
15+
16+
@RestxResource @Component
17+
public class MongoResource {
18+
public static class ObjectWithIdAnnotation {
19+
// @Id // 0.34 -> OK ; 0.35 -> KO!
20+
@MongoId @JsonProperty("_id") // 0.35 -> KO!
21+
private String id;
22+
private String label;
23+
24+
public String getId() { return id; }
25+
public void setId(String id) { this.id = id; }
26+
public String getLabel() { return label; }
27+
public void setLabel(String label) { this.label = label; }
28+
}
29+
public static class ObjectWithObjectIdAnnotation {
30+
// @org.jongo.marshall.jackson.oid.ObjectId @Id // 0.34 -> OK ; 0.35 -> KO!
31+
@MongoId @MongoObjectId @JsonProperty("_id") // 0.35 -> KO!
32+
private String id;
33+
private String label;
34+
35+
public String getId() { return id; }
36+
public void setId(String id) { this.id = id; }
37+
public String getLabel() { return label; }
38+
public void setLabel(String label) { this.label = label; }
39+
}
40+
public static class ObjectWithObjectIdType {
41+
// @Id // 0.34 -> OK ; 0.35 -> OK
42+
@MongoId @JsonProperty("_id") // 0.35 -> OK
43+
private ObjectId id;
44+
private String label;
45+
46+
public String getId() { return id.toString(); }
47+
public void setId(ObjectId id) { this.id = id; }
48+
public String getLabel() { return label; }
49+
public void setLabel(String label) { this.label = label; }
50+
}
51+
52+
private final JongoCollection objectWithIdAnnotationCollection;
53+
private final JongoCollection objectWithObjectIdAnnotationCollection;
54+
private final JongoCollection objectWithObjectIdTypeCollection;
55+
56+
public MongoResource(
57+
@Named("objectWithIdAnnotationCollection") JongoCollection objectWithIdAnnotationCollection,
58+
@Named("objectWithObjectIdAnnotationCollection") JongoCollection objectWithObjectIdAnnotationCollection,
59+
@Named("objectWithObjectIdTypeCollection") JongoCollection objectWithObjectIdTypeCollection) {
60+
this.objectWithIdAnnotationCollection = objectWithIdAnnotationCollection;
61+
this.objectWithObjectIdAnnotationCollection = objectWithObjectIdAnnotationCollection;
62+
this.objectWithObjectIdTypeCollection = objectWithObjectIdTypeCollection;
63+
}
64+
65+
@POST("/mongo/objectsWithIdAnnotation")
66+
@PermitAll
67+
public ObjectWithIdAnnotation createFoo(ObjectWithIdAnnotation foo) {
68+
this.objectWithIdAnnotationCollection.get().insert(foo);
69+
return foo;
70+
}
71+
72+
@POST("/mongo/objectsWithObjectIdAnnotation")
73+
@PermitAll
74+
public ObjectWithObjectIdAnnotation createObjectWithObjectIdAnnotation(ObjectWithObjectIdAnnotation objectWithObjectIdAnnotation) {
75+
this.objectWithObjectIdAnnotationCollection.get().insert(objectWithObjectIdAnnotation);
76+
return objectWithObjectIdAnnotation;
77+
}
78+
79+
@POST("/mongo/objectsWithObjectIdType")
80+
@PermitAll
81+
public ObjectWithObjectIdType createObjectWithObjectId(ObjectWithObjectIdType objectWithObjectIdType) {
82+
this.objectWithObjectIdTypeCollection.get().insert(objectWithObjectIdType);
83+
return objectWithObjectIdType;
84+
}
85+
86+
87+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
title: objectsWithIdAnnotation persistence
2+
given:
3+
- time: 2018-02-07T17:01:21.795+02:00
4+
- collection: objectWithIdAnnotationCollection
5+
sequence: 5167cec5856107c479739654
6+
wts:
7+
- when: |
8+
POST mongo/objectsWithIdAnnotation
9+
{"label": "FOO"}
10+
then: |
11+
{"_id":"5167cec5856107c479739654","label": "FOO"}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
title: objectsWithObjectIdAnnotation persistence
2+
given:
3+
- time: 2018-02-07T17:01:21.795+02:00
4+
- collection: objectWithObjectIdAnnotationCollection
5+
sequence: 5167cec5856107c479739654
6+
wts:
7+
- when: |
8+
POST mongo/objectsWithObjectIdAnnotation
9+
{"label": "BAR"}
10+
then: |
11+
{"_id":"5167cec5856107c479739654","label": "BAR"}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
title: objectsWithObjectId persistence
2+
given:
3+
- time: 2018-02-07T17:01:21.795+02:00
4+
- collection: objectWithObjectIdTypeCollection
5+
sequence: 5167cec5856107c479739654
6+
wts:
7+
- when: |
8+
POST mongo/objectsWithObjectIdType
9+
{"label": "BLAH"}
10+
then: |
11+
{"_id":"5167cec5856107c479739654","label": "BLAH"}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package samplest.jongo;
2+
3+
import org.junit.runner.RunWith;
4+
import restx.tests.FindSpecsIn;
5+
import restx.jongo.specs.tests.MongoRestxSpecTestsRunner;
6+
7+
@RunWith(MongoRestxSpecTestsRunner.class)
8+
@FindSpecsIn("specs/mongo")
9+
public class MongoResourceSpecsTest {
10+
}

0 commit comments

Comments
 (0)