Skip to content

Commit

Permalink
Introduced tests on Jongo id generation, spotting regressions in 0.35…
Browse files Browse the repository at this point in the history
… compared to 0.34 regarding id generation cases
  • Loading branch information
fcamblor committed Feb 8, 2018
1 parent 0e201fd commit f48e937
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Expand Up @@ -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>
Expand Down
14 changes: 14 additions & 0 deletions restx-samplest/pom.xml
Expand Up @@ -29,6 +29,15 @@
<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-jongo</artifactId>
<version>${restx.version}</version>
</dependency>
<dependency>
<groupId>io.restx</groupId>
<artifactId>restx-factory-admin</artifactId>
Expand Down Expand Up @@ -76,6 +85,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>
Expand Down
4 changes: 4 additions & 0 deletions restx-samplest/src/main/java/samplest/AppModule.java
Expand Up @@ -59,4 +59,8 @@ public Optional<RestxPrincipal> findAndCheckCredentials(String name, String pass
}, securitySettings);
}

@Provides @Named("mongo.db") String mongoDb() {
return "testing-mongo";
}

}
87 changes: 87 additions & 0 deletions restx-samplest/src/main/java/samplest/jongo/MongoResource.java
@@ -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 f48e937

Please sign in to comment.