@@ -18,9 +18,9 @@ package example.springdata.mongodb.unwrapping;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* Simple Spring Boot application.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class ApplicationConfiguration {
|
||||
|
||||
}
|
||||
public class ApplicationConfiguration {}
|
||||
|
||||
@@ -18,6 +18,8 @@ package example.springdata.mongodb.unwrapping;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Value object capturing the {@code email} address.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class Email { // might as well be a record type in more recent java versions
|
||||
|
||||
@@ -18,6 +18,8 @@ package example.springdata.mongodb.unwrapping;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Value object capturing the {@code username}.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class UserName { // might as well be a record type in more recent java versions
|
||||
|
||||
@@ -23,14 +23,12 @@ import org.springframework.data.repository.CrudRepository;
|
||||
public interface UserRepository extends CrudRepository<User, String> {
|
||||
|
||||
/**
|
||||
* Use the value type directly.
|
||||
* This will unwrap the values into the target query object.
|
||||
* Use the value type directly. This will unwrap the values into the target query object.
|
||||
*/
|
||||
User findByUserName(UserName userName);
|
||||
|
||||
/**
|
||||
* Use one of the unwrapped properties.
|
||||
* This will drill into the unwrapped using the value for the target query.
|
||||
* Use one of the unwrapped properties. This will drill into the unwrapped using the value for the target query.
|
||||
*/
|
||||
User findByEmailEmail(String email);
|
||||
}
|
||||
|
||||
@@ -19,21 +19,22 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.mongodb.client.model.Filters;
|
||||
import org.bson.Document;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;
|
||||
import org.springframework.data.mongodb.core.MongoOperations;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import com.mongodb.client.model.Filters;
|
||||
|
||||
/**
|
||||
* Integration tests showing unwrapped/embedded document usage.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@SpringBootTest
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@DataMongoTest
|
||||
class UnwrappingIntegrationTests {
|
||||
|
||||
@Autowired UserRepository repository;
|
||||
|
||||
Reference in New Issue
Block a user