From b99ca1816acf6d6398fb6bd055d1d55ea9ad3243 Mon Sep 17 00:00:00 2001 From: Peter-Josef Meisch Date: Fri, 1 Sep 2023 23:41:54 +0200 Subject: [PATCH] Fix adaption to PersistentProperty change. --- .../convert/MappingElasticsearchConverter.java | 3 ++- .../SimpleElasticsearchPersistentProperty.java | 2 +- .../core/ElasticsearchIntegrationTests.java | 8 ++++++++ .../ReactiveElasticsearchIntegrationTests.java | 14 +++++++++++--- ...leElasticsearchPersistentPropertyUnitTests.java | 12 ++---------- .../ImmutableRepositoryIntegrationTests.java | 5 +++++ 6 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java b/src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java index 70776f67c..8743dddcf 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java @@ -403,7 +403,8 @@ public class MappingElasticsearchConverter for (ElasticsearchPersistentProperty property : entity) { - if (entity.isCreatorArgument(property) || !property.isReadable() || property.isIndexedIndexNameProperty()) { + if (entity.isCreatorArgument(property) || !property.isReadable() || property.isSeqNoPrimaryTermProperty() + || property.isIndexedIndexNameProperty()) { continue; } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java b/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java index fc25d3421..2533677e4 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java @@ -129,7 +129,7 @@ public class SimpleElasticsearchPersistentProperty extends @Override public boolean isReadable() { - return super.isReadable() && !isAnnotationPresent(WriteOnlyProperty.class); + return super.isReadable() && !isAnnotationPresent(WriteOnlyProperty.class); } @Override diff --git a/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchIntegrationTests.java index bfed451f7..a89fe30fe 100755 --- a/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchIntegrationTests.java @@ -4522,6 +4522,14 @@ public abstract class ElasticsearchIntegrationTests { 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 public String getId() { return id; diff --git a/src/test/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchIntegrationTests.java index b9abb2701..5a6c2a740 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchIntegrationTests.java @@ -18,10 +18,8 @@ package org.springframework.data.elasticsearch.core; import static java.util.Collections.*; import static org.assertj.core.api.Assertions.*; 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.Mono; import reactor.test.StepVerifier; @@ -45,6 +43,7 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; import java.util.stream.IntStream; +import org.assertj.core.api.InstanceOfAssertFactories; import org.json.JSONException; import org.junit.jupiter.api.BeforeEach; 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.Pageable; import org.springframework.data.domain.Sort; +import org.springframework.data.elasticsearch.BulkFailureException; import org.springframework.data.elasticsearch.RestStatusException; import org.springframework.data.elasticsearch.annotations.Document; import org.springframework.data.elasticsearch.annotations.Field; @@ -1509,6 +1509,14 @@ public abstract class ReactiveElasticsearchIntegrationTests { 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() { return id; } diff --git a/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentPropertyUnitTests.java b/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentPropertyUnitTests.java index a4ea91486..114a8340d 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentPropertyUnitTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentPropertyUnitTests.java @@ -185,14 +185,6 @@ public class SimpleElasticsearchPersistentPropertyUnitTests { 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 @DisplayName("should require pattern for custom date format") void shouldRequirePatternForCustomDateFormat() { @@ -259,12 +251,12 @@ public class SimpleElasticsearchPersistentPropertyUnitTests { assertThat( persistentEntity.getRequiredPersistentProperty("fieldWithClassBasedConverter").getPropertyValueConverter()) - .isInstanceOf(ClassBasedValueConverter.class); + .isInstanceOf(ClassBasedValueConverter.class); assertThat(persistentEntity.getRequiredPersistentProperty("fieldWithClassBasedDerivedFromAbstractValueConverter") .getPropertyValueConverter()).isInstanceOf(ClassBasedDerivedFromAbstractValueConverter.class); assertThat( persistentEntity.getRequiredPersistentProperty("fieldWithEnumBasedConverter").getPropertyValueConverter()) - .isInstanceOf(EnumBasedValueConverter.class); + .isInstanceOf(EnumBasedValueConverter.class); } // region entities diff --git a/src/test/java/org/springframework/data/elasticsearch/immutable/ImmutableRepositoryIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/immutable/ImmutableRepositoryIntegrationTests.java index 4af74ad2e..acb607439 100644 --- a/src/test/java/org/springframework/data/elasticsearch/immutable/ImmutableRepositoryIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/immutable/ImmutableRepositoryIntegrationTests.java @@ -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.utils.IndexNameProvider; import org.springframework.data.repository.CrudRepository; +import org.springframework.lang.Nullable; /** * @author Young Gu @@ -90,6 +91,10 @@ public abstract class ImmutableRepositoryIntegrationTests { this(null, name); } + public ImmutableEntity withId(@Nullable String id) { + return new ImmutableEntity(id, this.name); + } + public String getId() { return id; }