Switch MongoDB samples to records.

See #606.
This commit is contained in:
Mark Paluch
2021-04-28 15:18:59 +02:00
parent b44dc3dea1
commit e565f33872
69 changed files with 395 additions and 555 deletions

View File

@@ -15,21 +15,21 @@
*/
package example.springdata.mongodb.security;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.PersistenceConstructor;
/**
* An entity to represent a {@link Person}.
*
* @author Thomas Darimont
*/
@Data
@RequiredArgsConstructor
public class Person {
public record Person(@Id String id, String firstname, String lastname) {
private @Id String id;
private final String firstname;
private final String lastname;
@PersistenceConstructor
public Person {
}
public Person(String firstname, String lastname) {
this(null, firstname, lastname);
}
}

View File

@@ -61,7 +61,7 @@ public class PersonRepositoryIntegrationTest {
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(dave, "x"));
List<Person> persons = repository.findAllForCurrentUserById();
var persons = repository.findAllForCurrentUserById();
assertThat(persons, hasSize(1));
assertThat(persons, contains(dave));
@@ -70,11 +70,11 @@ public class PersonRepositoryIntegrationTest {
@Test
public void adminCallingShouldReturnAllUsers() throws Exception {
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(admin, "x",
var auth = new UsernamePasswordAuthenticationToken(admin, "x",
Collections.singleton(new SimpleGrantedAuthority("ROLE_ADMIN")));
SecurityContextHolder.getContext().setAuthentication(auth);
List<Person> persons = repository.findAllForCurrentUserById();
var persons = repository.findAllForCurrentUserById();
assertThat(persons, hasSize(4));
assertThat(persons, containsInAnyOrder(admin, dave, carter, oliver));