Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Introduced tests on Jongo id generation, spotting regressions in 0.35…
… compared to 0.34 regarding id generation cases
- Loading branch information
Showing
10 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
restx-samplest/src/main/java/samplest/jongo/MongoResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,87 @@ | |||
package samplest.jongo; | |||
|
|||
import com.fasterxml.jackson.annotation.JsonProperty; | |||
import org.bson.types.ObjectId; | |||
import org.jongo.marshall.jackson.oid.Id; | |||
import org.jongo.marshall.jackson.oid.MongoId; | |||
import org.jongo.marshall.jackson.oid.MongoObjectId; | |||
import restx.annotations.POST; | |||
import restx.annotations.RestxResource; | |||
import restx.factory.Component; | |||
import restx.jongo.JongoCollection; | |||
import restx.security.PermitAll; | |||
|
|||
import javax.inject.Named; | |||
|
|||
@RestxResource @Component | |||
public class MongoResource { | |||
public static class ObjectWithIdAnnotation { | |||
// @Id // 0.34 -> OK ; 0.35 -> KO! | |||
@MongoId @JsonProperty("_id") // 0.35 -> KO! | |||
private String id; | |||
private String label; | |||
|
|||
public String getId() { return id; } | |||
public void setId(String id) { this.id = id; } | |||
public String getLabel() { return label; } | |||
public void setLabel(String label) { this.label = label; } | |||
} | |||
public static class ObjectWithObjectIdAnnotation { | |||
// @org.jongo.marshall.jackson.oid.ObjectId @Id // 0.34 -> OK ; 0.35 -> KO! | |||
@MongoId @MongoObjectId @JsonProperty("_id") // 0.35 -> KO! | |||
private String id; | |||
private String label; | |||
|
|||
public String getId() { return id; } | |||
public void setId(String id) { this.id = id; } | |||
public String getLabel() { return label; } | |||
public void setLabel(String label) { this.label = label; } | |||
} | |||
public static class ObjectWithObjectIdType { | |||
// @Id // 0.34 -> OK ; 0.35 -> OK | |||
@MongoId @JsonProperty("_id") // 0.35 -> OK | |||
private ObjectId id; | |||
private String label; | |||
|
|||
public String getId() { return id.toString(); } | |||
public void setId(ObjectId id) { this.id = id; } | |||
public String getLabel() { return label; } | |||
public void setLabel(String label) { this.label = label; } | |||
} | |||
|
|||
private final JongoCollection objectWithIdAnnotationCollection; | |||
private final JongoCollection objectWithObjectIdAnnotationCollection; | |||
private final JongoCollection objectWithObjectIdTypeCollection; | |||
|
|||
public MongoResource( | |||
@Named("objectWithIdAnnotationCollection") JongoCollection objectWithIdAnnotationCollection, | |||
@Named("objectWithObjectIdAnnotationCollection") JongoCollection objectWithObjectIdAnnotationCollection, | |||
@Named("objectWithObjectIdTypeCollection") JongoCollection objectWithObjectIdTypeCollection) { | |||
this.objectWithIdAnnotationCollection = objectWithIdAnnotationCollection; | |||
this.objectWithObjectIdAnnotationCollection = objectWithObjectIdAnnotationCollection; | |||
this.objectWithObjectIdTypeCollection = objectWithObjectIdTypeCollection; | |||
} | |||
|
|||
@POST("/mongo/objectsWithIdAnnotation") | |||
@PermitAll | |||
public ObjectWithIdAnnotation createFoo(ObjectWithIdAnnotation foo) { | |||
this.objectWithIdAnnotationCollection.get().insert(foo); | |||
return foo; | |||
} | |||
|
|||
@POST("/mongo/objectsWithObjectIdAnnotation") | |||
@PermitAll | |||
public ObjectWithObjectIdAnnotation createObjectWithObjectIdAnnotation(ObjectWithObjectIdAnnotation objectWithObjectIdAnnotation) { | |||
this.objectWithObjectIdAnnotationCollection.get().insert(objectWithObjectIdAnnotation); | |||
return objectWithObjectIdAnnotation; | |||
} | |||
|
|||
@POST("/mongo/objectsWithObjectIdType") | |||
@PermitAll | |||
public ObjectWithObjectIdType createObjectWithObjectId(ObjectWithObjectIdType objectWithObjectIdType) { | |||
this.objectWithObjectIdTypeCollection.get().insert(objectWithObjectIdType); | |||
return objectWithObjectIdType; | |||
} | |||
|
|||
|
|||
} |
11 changes: 11 additions & 0 deletions
11
restx-samplest/src/main/resources/specs/mongo/objectsWithIdAnnotation_persistence.spec.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
title: objectsWithIdAnnotation persistence | |||
given: | |||
- time: 2018-02-07T17:01:21.795+02:00 | |||
- collection: objectWithIdAnnotationCollection | |||
sequence: 5167cec5856107c479739654 | |||
wts: | |||
- when: | | |||
POST mongo/objectsWithIdAnnotation | |||
{"label": "FOO"} | |||
then: | | |||
{"_id":"5167cec5856107c479739654","label": "FOO"} |
11 changes: 11 additions & 0 deletions
11
...mplest/src/main/resources/specs/mongo/objectsWithObjectIdAnnotation_persistence.spec.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
title: objectsWithObjectIdAnnotation persistence | |||
given: | |||
- time: 2018-02-07T17:01:21.795+02:00 | |||
- collection: objectWithObjectIdAnnotationCollection | |||
sequence: 5167cec5856107c479739654 | |||
wts: | |||
- when: | | |||
POST mongo/objectsWithObjectIdAnnotation | |||
{"label": "BAR"} | |||
then: | | |||
{"_id":"5167cec5856107c479739654","label": "BAR"} |
11 changes: 11 additions & 0 deletions
11
restx-samplest/src/main/resources/specs/mongo/objectsWithObjectIdType_persistence.spec.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
title: objectsWithObjectId persistence | |||
given: | |||
- time: 2018-02-07T17:01:21.795+02:00 | |||
- collection: objectWithObjectIdTypeCollection | |||
sequence: 5167cec5856107c479739654 | |||
wts: | |||
- when: | | |||
POST mongo/objectsWithObjectIdType | |||
{"label": "BLAH"} | |||
then: | | |||
{"_id":"5167cec5856107c479739654","label": "BLAH"} |
10 changes: 10 additions & 0 deletions
10
restx-samplest/src/test/java/samplest/jongo/MongoResourceSpecsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,10 @@ | |||
package samplest.jongo; | |||
|
|||
import org.junit.runner.RunWith; | |||
import restx.tests.FindSpecsIn; | |||
import restx.jongo.specs.tests.MongoRestxSpecTestsRunner; | |||
|
|||
@RunWith(MongoRestxSpecTestsRunner.class) | |||
@FindSpecsIn("specs/mongo") | |||
public class MongoResourceSpecsTest { | |||
} |