Skip to content

Commit

Permalink
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
fcamblor committed Feb 25, 2018
1 parent 0e201fd commit 2469d34
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Expand Up @@ -214,6 +214,11 @@
<artifactId>restx-core-java8</artifactId> <artifactId>restx-core-java8</artifactId>
<version>${restx.version}</version> <version>${restx.version}</version>
</dependency> </dependency>
<dependency>
<groupId>io.restx</groupId>
<artifactId>restx-jongo-specs-tests</artifactId>
<version>${restx.version}</version>
</dependency>
<dependency> <dependency>
<groupId>io.restx</groupId> <groupId>io.restx</groupId>
<artifactId>restx-specs-tests-java8</artifactId> <artifactId>restx-specs-tests-java8</artifactId>
Expand Down
2 changes: 2 additions & 0 deletions restx-samplest/md.restx.json
Expand Up @@ -19,6 +19,7 @@
"io.restx:restx-validation:${restx.version}", "io.restx:restx-validation:${restx.version}",
"io.restx:restx-core-annotation-processor:${restx.version}", "io.restx:restx-core-annotation-processor:${restx.version}",
"io.restx:restx-factory:${restx.version}", "io.restx:restx-factory:${restx.version}",
"io.restx:restx-jongo:${restx.version}",
"io.restx:restx-factory-admin:${restx.version}", "io.restx:restx-factory-admin:${restx.version}",
"io.restx:restx-monitor-codahale:${restx.version}", "io.restx:restx-monitor-codahale:${restx.version}",
"io.restx:restx-monitor-admin:${restx.version}", "io.restx:restx-monitor-admin:${restx.version}",
Expand All @@ -34,6 +35,7 @@
], ],
"test": [ "test": [
"io.restx:restx-specs-tests:${restx.version}", "io.restx:restx-specs-tests:${restx.version}",
"io.restx:restx-jongo-specs-tests:${restx.version}",
"junit:junit:${junit.version}" "junit:junit:${junit.version}"
] ]
} }
Expand Down
2 changes: 2 additions & 0 deletions restx-samplest/module.ivy
Expand Up @@ -18,6 +18,7 @@
<dependency org="io.restx" name="restx-validation" rev="latest.integration" conf="default" /> <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-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-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-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-codahale" rev="latest.integration" conf="default" />
<dependency org="io.restx" name="restx-monitor-admin" rev="latest.integration" conf="default" /> <dependency org="io.restx" name="restx-monitor-admin" rev="latest.integration" conf="default" />
Expand All @@ -29,6 +30,7 @@
<dependency org="ch.qos.logback" name="logback-classic" rev="1.0.13" conf="default" /> <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-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-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" /> <dependency org="junit" name="junit" rev="4.11" conf="test->default" />
</dependencies> </dependencies>
</ivy-module> </ivy-module>
9 changes: 9 additions & 0 deletions restx-samplest/pom.xml
Expand Up @@ -29,6 +29,10 @@
<groupId>io.restx</groupId> <groupId>io.restx</groupId>
<artifactId>restx-factory</artifactId> <artifactId>restx-factory</artifactId>
</dependency> </dependency>
<dependency>
<groupId>io.restx</groupId>
<artifactId>restx-jongo</artifactId>
</dependency>
<dependency> <dependency>
<groupId>io.restx</groupId> <groupId>io.restx</groupId>
<artifactId>restx-factory-admin</artifactId> <artifactId>restx-factory-admin</artifactId>
Expand Down Expand Up @@ -76,6 +80,11 @@
<artifactId>restx-specs-tests</artifactId> <artifactId>restx-specs-tests</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>io.restx</groupId>
<artifactId>restx-jongo-specs-tests</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <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); }, 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 2469d34

Please sign in to comment.