Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#79 #90

Merged
merged 4 commits into from
Jun 8, 2016
Merged

#79 #90

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ in Maven `provided` scope to cut transitive dependencies.

## Core Features

- [Spring Data extensions] [Spring Data extensions (1.4+)]
- Spring Data extensions
- Useful AOP aspects
- Common exception classes
- Web & MVC extensions
Expand Down
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,6 @@
<artifactId>el-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.fakemongo</groupId>
<artifactId>fongo</artifactId>
<version>2.0.7</version>
<scope>test</scope>
</dependency>
</dependencies>

<dependencyManagement>
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/org/ameba/app/BaseConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,16 @@

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.mongodb.config.EnableMongoAuditing;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;

/**
* A BaseConfiguration enables auto configuration of Spring Data JPA and MongoDB Auditing and instantiates a JSR-303 ValidatorFactory.
* A BaseConfiguration enables instantiates a JSR-303 ValidatorFactory.
*
* @author <a href="mailto:[email protected]">Heiko Scherrer</a>
* @version 1.1
* @since 1.0
*/
@Configuration
@EnableJpaAuditing
@EnableMongoAuditing
public class BaseConfiguration {

/**
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/org/ameba/integration/mongodb/BaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.ameba.integration.mongodb;

import java.time.ZonedDateTime;
import java.util.Date;

import org.ameba.integration.TypedEntity;
import org.springframework.data.annotation.CreatedDate;
Expand All @@ -26,7 +26,9 @@
import org.springframework.data.mongodb.core.mapping.Field;

/**
* A BaseEntity is a base superclass for MongoDB document entities.
* A BaseEntity is a base superclass for MongoDB document entities that defined useful fields for optimistic locking, unique persisted key,
* and timestamps for last change or insertion date. To active the latter feature the Spring application context need to enable Spring Data
* MongoDB MongoAuditingRegistrar. One approach to do this is to add {@code @EnableMongoAuditing} on a Spring configuration class.
*
* @author <a href="mailto:[email protected]">Heiko Scherrer</a>
* @version 1.0
Expand All @@ -52,14 +54,14 @@ public class BaseEntity implements TypedEntity<String> {
/** Timestamp when the document was inserted. */
@Field(FIELD_CREATED)
@CreatedDate
private ZonedDateTime createDt;
private Date createDt;
/** Field name of the timestamp when the document was inserted. */
public static final String FIELD_CREATED = "_created";

/** Timestamp when the document was updated the last time. */
@Field(FIELD_UPDATED)
@LastModifiedDate
private ZonedDateTime lastModifiedDt;
private Date lastModifiedDt;
/** Field name of the timestamp when the document was updated the last time. */
public static final String FIELD_UPDATED = "_updated";

Expand Down Expand Up @@ -95,7 +97,7 @@ void setPk(String pk) {
*
* @return Creation date
*/
public ZonedDateTime getCreateDt() {
public Date getCreateDt() {
return createDt;
}

Expand All @@ -104,7 +106,7 @@ public ZonedDateTime getCreateDt() {
*
* @return Last modified date
*/
public ZonedDateTime getLastModifiedDt() {
public Date getLastModifiedDt() {
return lastModifiedDt;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.ameba.integration.jpa;

import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

/**
Expand All @@ -26,6 +27,7 @@
* @since 1.6
*/
@Configuration
@EnableJpaAuditing
@EnableJpaRepositories(basePackageClasses = IntegrationTestConfig.class)
public class IntegrationTestConfig {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@

import static org.assertj.core.api.Assertions.assertThat;

import com.github.fakemongo.Fongo;
import com.mongodb.BasicDBObject;
import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import org.ameba.app.BaseConfiguration;
import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.config.AbstractMongoConfiguration;
import org.springframework.data.mongodb.config.EnableMongoAuditing;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.test.context.ContextConfiguration;
Expand All @@ -39,10 +41,10 @@
* @since 1.0
*/
@RunWith(SpringRunner.class)
//@EnableMongoAuditing
@ContextConfiguration(/*classes = AbstractMongoDBIntegrationTests.TestConfig.class, */locations = "classpath:infrastructure.xml")
@ContextConfiguration(classes = {AbstractMongoDBIntegrationTests.TestConfig.class, BaseConfiguration.class})
public abstract class AbstractMongoDBIntegrationTests {

@EnableMongoAuditing
@Configuration
@EnableMongoRepositories(basePackageClasses = AbstractMongoDBIntegrationTests.class, considerNestedRepositories = true)
static class TestConfig extends AbstractMongoConfiguration {
Expand All @@ -54,7 +56,7 @@ protected String getDatabaseName() {

@Override
public Mongo mongo() throws Exception {
return new Fongo(getDatabaseName()).getMongo();
return new MongoClient();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public void testPk() {
assertThat(all).hasSize(1);
assertThat(all.get(0).isNew()).isFalse();
assertThat(all.get(0).getPk()).isNotNull();
// assertThat(all.get(0).getCreateDt()).isNotNull();
// assertThat(all.get(0).getLastModifiedDt()).isNotNull();
assertThat(all.get(0).getCreateDt()).isNotNull();
assertThat(all.get(0).getLastModifiedDt()).isNotNull();
assertThat(all.get(0)).extracting("ol").contains(0L);
}
}