Fix adaption to PersistentProperty change.

This commit is contained in:
Peter-Josef Meisch 2023-09-01 23:41:54 +02:00
parent 1a24c3c989
commit b99ca1816a
No known key found for this signature in database
GPG Key ID: DE108246970C7708
6 changed files with 29 additions and 15 deletions

View File

@ -403,7 +403,8 @@ public class MappingElasticsearchConverter
for (ElasticsearchPersistentProperty property : entity) { for (ElasticsearchPersistentProperty property : entity) {
if (entity.isCreatorArgument(property) || !property.isReadable() || property.isIndexedIndexNameProperty()) { if (entity.isCreatorArgument(property) || !property.isReadable() || property.isSeqNoPrimaryTermProperty()
|| property.isIndexedIndexNameProperty()) {
continue; continue;
} }

View File

@ -129,7 +129,7 @@ public class SimpleElasticsearchPersistentProperty extends
@Override @Override
public boolean isReadable() { public boolean isReadable() {
return super.isReadable() && !isAnnotationPresent(WriteOnlyProperty.class); return super.isReadable() && !isAnnotationPresent(WriteOnlyProperty.class);
} }
@Override @Override

View File

@ -4522,6 +4522,14 @@ public abstract class ElasticsearchIntegrationTests {
this.seqNoPrimaryTerm = seqNoPrimaryTerm; this.seqNoPrimaryTerm = seqNoPrimaryTerm;
} }
public ImmutableEntity withId(@Nullable String id) {
return new ImmutableEntity(id, this.text, this.seqNoPrimaryTerm);
}
public ImmutableEntity withSeqNoPrimaryTerm(@Nullable SeqNoPrimaryTerm seqNoPrimaryTerm) {
return new ImmutableEntity(this.id, this.text, seqNoPrimaryTerm);
}
@Nullable @Nullable
public String getId() { public String getId() {
return id; return id;

View File

@ -18,10 +18,8 @@ package org.springframework.data.elasticsearch.core;
import static java.util.Collections.*; import static java.util.Collections.*;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.elasticsearch.annotations.FieldType.*; import static org.springframework.data.elasticsearch.annotations.FieldType.*;
import static org.springframework.data.elasticsearch.core.query.StringQuery.MATCH_ALL; import static org.springframework.data.elasticsearch.core.query.StringQuery.*;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.springframework.data.elasticsearch.BulkFailureException;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import reactor.test.StepVerifier; import reactor.test.StepVerifier;
@ -45,6 +43,7 @@ import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.IntStream; import java.util.stream.IntStream;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.json.JSONException; import org.json.JSONException;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
@ -60,6 +59,7 @@ import org.springframework.data.annotation.Version;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.elasticsearch.BulkFailureException;
import org.springframework.data.elasticsearch.RestStatusException; import org.springframework.data.elasticsearch.RestStatusException;
import org.springframework.data.elasticsearch.annotations.Document; import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field; import org.springframework.data.elasticsearch.annotations.Field;
@ -1509,6 +1509,14 @@ public abstract class ReactiveElasticsearchIntegrationTests {
this.seqNoPrimaryTerm = seqNoPrimaryTerm; this.seqNoPrimaryTerm = seqNoPrimaryTerm;
} }
public ImmutableEntity withId(@Nullable String id) {
return new ImmutableEntity(id, this.text, this.seqNoPrimaryTerm);
}
public ImmutableEntity withSeqNoPrimaryTerm(@Nullable SeqNoPrimaryTerm seqNoPrimaryTerm) {
return new ImmutableEntity(this.id, this.text, seqNoPrimaryTerm);
}
public String getId() { public String getId() {
return id; return id;
} }

View File

@ -185,14 +185,6 @@ public class SimpleElasticsearchPersistentPropertyUnitTests {
assertThat(seqNoProperty.isWritable()).isFalse(); assertThat(seqNoProperty.isWritable()).isFalse();
} }
@Test // DATAES-799
void seqNoPrimaryTermPropertyShouldNotBeReadable() {
SimpleElasticsearchPersistentEntity<?> entity = context.getRequiredPersistentEntity(SeqNoPrimaryTermProperty.class);
ElasticsearchPersistentProperty seqNoProperty = entity.getRequiredPersistentProperty("seqNoPrimaryTerm");
assertThat(seqNoProperty.isReadable()).isFalse();
}
@Test // DATAES-924 @Test // DATAES-924
@DisplayName("should require pattern for custom date format") @DisplayName("should require pattern for custom date format")
void shouldRequirePatternForCustomDateFormat() { void shouldRequirePatternForCustomDateFormat() {
@ -259,12 +251,12 @@ public class SimpleElasticsearchPersistentPropertyUnitTests {
assertThat( assertThat(
persistentEntity.getRequiredPersistentProperty("fieldWithClassBasedConverter").getPropertyValueConverter()) persistentEntity.getRequiredPersistentProperty("fieldWithClassBasedConverter").getPropertyValueConverter())
.isInstanceOf(ClassBasedValueConverter.class); .isInstanceOf(ClassBasedValueConverter.class);
assertThat(persistentEntity.getRequiredPersistentProperty("fieldWithClassBasedDerivedFromAbstractValueConverter") assertThat(persistentEntity.getRequiredPersistentProperty("fieldWithClassBasedDerivedFromAbstractValueConverter")
.getPropertyValueConverter()).isInstanceOf(ClassBasedDerivedFromAbstractValueConverter.class); .getPropertyValueConverter()).isInstanceOf(ClassBasedDerivedFromAbstractValueConverter.class);
assertThat( assertThat(
persistentEntity.getRequiredPersistentProperty("fieldWithEnumBasedConverter").getPropertyValueConverter()) persistentEntity.getRequiredPersistentProperty("fieldWithEnumBasedConverter").getPropertyValueConverter())
.isInstanceOf(EnumBasedValueConverter.class); .isInstanceOf(EnumBasedValueConverter.class);
} }
// region entities // region entities

View File

@ -30,6 +30,7 @@ import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest; import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.utils.IndexNameProvider; import org.springframework.data.elasticsearch.utils.IndexNameProvider;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
import org.springframework.lang.Nullable;
/** /**
* @author Young Gu * @author Young Gu
@ -90,6 +91,10 @@ public abstract class ImmutableRepositoryIntegrationTests {
this(null, name); this(null, name);
} }
public ImmutableEntity withId(@Nullable String id) {
return new ImmutableEntity(id, this.name);
}
public String getId() { public String getId() {
return id; return id;
} }