Permalink
Browse files

Introduced tests on Jongo id generation, spotting regressions in 0.35…

… compared to 0.34 regarding id generation cases
  • Loading branch information...
fcamblor committed Feb 7, 2018
1 parent 0e201fd commit 2469d34c9104b7c7ff322ed97b6e56f66ff97630
View
@@ -214,6 +214,11 @@
<artifactId>restx-core-java8</artifactId>
<version>${restx.version}</version>
</dependency>
<dependency>
<groupId>io.restx</groupId>
<artifactId>restx-jongo-specs-tests</artifactId>
<version>${restx.version}</version>
</dependency>
<dependency>
<groupId>io.restx</groupId>
<artifactId>restx-specs-tests-java8</artifactId>
@@ -19,6 +19,7 @@
"io.restx:restx-validation:${restx.version}",
"io.restx:restx-core-annotation-processor:${restx.version}",
"io.restx:restx-factory:${restx.version}",
"io.restx:restx-jongo:${restx.version}",
"io.restx:restx-factory-admin:${restx.version}",
"io.restx:restx-monitor-codahale:${restx.version}",
"io.restx:restx-monitor-admin:${restx.version}",
@@ -34,6 +35,7 @@
],
"test": [
"io.restx:restx-specs-tests:${restx.version}",
"io.restx:restx-jongo-specs-tests:${restx.version}",
"junit:junit:${junit.version}"
]
}
@@ -18,6 +18,7 @@
<dependency org="io.restx" name="restx-validation" rev="latest.integration" conf="default" />
<dependency org="io.restx" name="restx-core-annotation-processor" rev="latest.integration" conf="default" />
<dependency org="io.restx" name="restx-factory" rev="latest.integration" conf="default" />
<dependency org="io.restx" name="restx-jongo" rev="latest.integration" conf="default" />
<dependency org="io.restx" name="restx-factory-admin" rev="latest.integration" conf="default" />
<dependency org="io.restx" name="restx-monitor-codahale" rev="latest.integration" conf="default" />
<dependency org="io.restx" name="restx-monitor-admin" rev="latest.integration" conf="default" />
@@ -29,6 +30,7 @@
<dependency org="ch.qos.logback" name="logback-classic" rev="1.0.13" conf="default" />
<dependency org="io.restx" name="restx-barbarywatch" rev="latest.integration" conf="runtime->default" />
<dependency org="io.restx" name="restx-specs-tests" rev="latest.integration" conf="test->default" />
<dependency org="io.restx" name="restx-jongo-specs-tests" rev="latest.integration" conf="test->default" />
<dependency org="junit" name="junit" rev="4.11" conf="test->default" />
</dependencies>
</ivy-module>
View
@@ -29,6 +29,10 @@
<groupId>io.restx</groupId>
<artifactId>restx-factory</artifactId>
</dependency>
<dependency>
<groupId>io.restx</groupId>
<artifactId>restx-jongo</artifactId>
</dependency>
<dependency>
<groupId>io.restx</groupId>
<artifactId>restx-factory-admin</artifactId>
@@ -76,6 +80,11 @@
<artifactId>restx-specs-tests</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.restx</groupId>
<artifactId>restx-jongo-specs-tests</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -59,4 +59,8 @@ public BasicPrincipalAuthenticator basicPrincipalAuthenticator(SecuritySettings
}, securitySettings);
}
@Provides @Named("mongo.db") String mongoDb() {
return "testing-mongo";
}
}
@@ -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;
}
}
@@ -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"}
@@ -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"}
@@ -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"}
@@ -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 {
}

0 comments on commit 2469d34

Please sign in to comment.