From cf126d2d42770d9e3684f60e77142715b1dc551f Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Fri, 7 Jul 2023 13:09:51 +0200 Subject: [PATCH] Remove lombok annotations. Closes #1557 --- ...eChangeIdGenerationImmutableUnitTests.java | 460 +++++++++++++--- ...AggregateTemplateHsqlIntegrationTests.java | 315 +++++++++-- ...angeExecutorContextImmutableUnitTests.java | 147 +++++- ...gregateChangeExecutorContextUnitTests.java | 6 +- ...JdbcAggregateTemplateIntegrationTests.java | 490 ++++++++++++++---- .../core/JdbcAggregateTemplateUnitTests.java | 171 ++++-- .../jdbc/core/PropertyPathTestingUtils.java | 9 +- .../convert/BasicJdbcConverterUnitTests.java | 88 +++- .../DefaultDataAccessStrategyUnitTests.java | 12 +- .../convert/EntityRowMapperUnitTests.java | 339 +++++++++--- .../convert/SqlParametersFactoryTest.java | 98 +++- .../PostgresDialectIntegrationTests.java | 101 +++- .../BasicJdbcPersistentPropertyUnitTests.java | 99 +++- .../PersistentPropertyPathTestUtils.java | 11 +- .../model/DefaultNamingStrategyUnitTests.java | 61 ++- .../data/jdbc/mybatis/DummyEntity.java | 9 +- ...ositoryBeforeSaveHsqlIntegrationTests.java | 179 +++++-- ...RepositoryConcurrencyIntegrationTests.java | 96 ++-- ...toryEmbeddedImmutableIntegrationTests.java | 122 ++++- ...dbcRepositoryEmbeddedIntegrationTests.java | 113 ++-- ...dedNotInAggregateRootIntegrationTests.java | 87 +++- ...mbeddedWithCollectionIntegrationTests.java | 58 ++- ...EmbeddedWithReferenceIntegrationTests.java | 84 ++- ...epositoryIdGenerationIntegrationTests.java | 140 ++++- .../JdbcRepositoryIntegrationTests.java | 365 +++++++++++-- ...oryPropertyConversionIntegrationTests.java | 76 ++- ...oryResultSetExtractorIntegrationTests.java | 86 ++- ...anuallyAssignedIdHsqlIntegrationTests.java | 51 +- ...sitoryWithCollectionsIntegrationTests.java | 27 +- ...bcRepositoryWithListsIntegrationTests.java | 102 +++- ...dbcRepositoryWithMapsIntegrationTests.java | 29 +- .../SimpleJdbcRepositoryEventsUnitTests.java | 66 ++- ...yMappingConfigurationIntegrationTests.java | 28 +- ...nableJdbcAuditingHsqlIntegrationTests.java | 74 ++- ...TransactionManagerRefIntegrationTests.java | 11 +- ...nableJdbcRepositoriesIntegrationTests.java | 11 +- .../query/PartTreeJdbcQueryUnitTests.java | 11 +- .../QueryAnnotationHsqlIntegrationTests.java | 8 +- .../data/r2dbc/config/AuditingUnitTests.java | 57 +- .../data/r2dbc/config/H2IntegrationTests.java | 7 - .../convert/EntityRowMapperUnitTests.java | 27 +- .../MappingR2dbcConverterUnitTests.java | 80 ++- .../MySqlMappingR2dbcConverterUnitTests.java | 16 +- ...ostgresMappingR2dbcConverterUnitTests.java | 34 +- .../r2dbc/core/PostgresIntegrationTests.java | 47 +- ...stgresReactiveDataAccessStrategyTests.java | 30 +- .../core/R2dbcEntityTemplateUnitTests.java | 207 +++++--- ...ReactiveDataAccessStrategyTestSupport.java | 68 ++- .../dialect/DialectResolverUnitTests.java | 6 +- .../documentation/QueryByExampleTests.java | 49 +- ...stractR2dbcRepositoryIntegrationTests.java | 123 +++-- ...oryWithMixedCaseNamesIntegrationTests.java | 63 ++- ...ertingR2dbcRepositoryIntegrationTests.java | 20 +- .../H2R2dbcRepositoryIntegrationTests.java | 43 +- ...stgresR2dbcRepositoryIntegrationTests.java | 40 +- .../query/PartTreeR2dbcQueryUnitTests.java | 3 - ...SimpleR2dbcRepositoryIntegrationTests.java | 166 ++++-- ...SimpleR2dbcRepositoryIntegrationTests.java | 31 +- .../data/r2dbc/testing/ExternalDatabase.java | 55 +- .../r2dbc/testing/MariaDbTestSupport.java | 19 +- .../r2dbc/testing/MySqlDbTestSupport.java | 2 - .../BasicRelationalConverterUnitTests.java | 26 +- .../core/conversion/DbActionTestSupport.java | 11 +- .../DeleteBatchingAggregateChangeTest.java | 21 +- ...RelationalEntityDeleteWriterUnitTests.java | 44 +- ...RelationalEntityInsertWriterUnitTests.java | 20 +- ...RelationalEntityUpdateWriterUnitTests.java | 18 +- .../RelationalEntityWriterUnitTests.java | 160 ++++-- .../SaveBatchingAggregateChangeTest.java | 233 ++++++++- ...RelationalPersistentPropertyUnitTests.java | 264 +++++++++- .../query/CriteriaFactoryUnitTests.java | 12 +- .../query/RelationalExampleMapperTests.java | 62 ++- 72 files changed, 4934 insertions(+), 1370 deletions(-) diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/AggregateChangeIdGenerationImmutableUnitTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/AggregateChangeIdGenerationImmutableUnitTests.java index e4443e0d..f9b55696 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/AggregateChangeIdGenerationImmutableUnitTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/AggregateChangeIdGenerationImmutableUnitTests.java @@ -15,15 +15,22 @@ */ package org.springframework.data.jdbc.core; -import static java.util.Arrays.*; -import static java.util.Collections.*; -import static org.assertj.core.api.Assertions.*; -import static org.assertj.core.api.SoftAssertions.*; -import static org.mockito.Mockito.*; - -import lombok.AllArgsConstructor; -import lombok.Value; -import lombok.With; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.springframework.data.annotation.Id; +import org.springframework.data.jdbc.core.convert.DataAccessStrategy; +import org.springframework.data.jdbc.core.convert.JdbcConverter; +import org.springframework.data.mapping.PersistentPropertyPath; +import org.springframework.data.mapping.PersistentPropertyPaths; +import org.springframework.data.relational.core.conversion.DbAction; +import org.springframework.data.relational.core.conversion.IdValueSource; +import org.springframework.data.relational.core.conversion.MutableAggregateChange; +import org.springframework.data.relational.core.conversion.RootAggregateChange; +import org.springframework.data.relational.core.mapping.Column; +import org.springframework.data.relational.core.mapping.Embedded; +import org.springframework.data.relational.core.mapping.RelationalMappingContext; +import org.springframework.data.relational.core.mapping.RelationalPersistentProperty; +import org.springframework.lang.Nullable; import java.util.HashMap; import java.util.List; @@ -32,22 +39,11 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import org.springframework.data.annotation.Id; -import org.springframework.data.jdbc.core.convert.DataAccessStrategy; -import org.springframework.data.jdbc.core.convert.JdbcConverter; -import org.springframework.data.mapping.PersistentPropertyPath; -import org.springframework.data.mapping.PersistentPropertyPaths; -import org.springframework.data.relational.core.conversion.RootAggregateChange; -import org.springframework.data.relational.core.conversion.DbAction; -import org.springframework.data.relational.core.conversion.IdValueSource; -import org.springframework.data.relational.core.conversion.MutableAggregateChange; -import org.springframework.data.relational.core.mapping.Column; -import org.springframework.data.relational.core.mapping.Embedded; -import org.springframework.data.relational.core.mapping.RelationalMappingContext; -import org.springframework.data.relational.core.mapping.RelationalPersistentProperty; -import org.springframework.lang.Nullable; +import static java.util.Arrays.*; +import static java.util.Collections.*; +import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.SoftAssertions.*; +import static org.mockito.Mockito.*; /** * Unit tests for the {@link MutableAggregateChange} testing the setting of generated ids in aggregates consisting of @@ -220,7 +216,7 @@ public class AggregateChangeIdGenerationImmutableUnitTests { .extracting(c -> c.id) // .containsExactly(2); // softly.assertThat(entity.contentSet.stream() // - .flatMap(c -> c.tagSet.stream())) // + .flatMap(c -> c.tagSet.stream())) // .extracting(t -> t.id) // .containsExactlyInAnyOrder(3, 4); // }); @@ -288,8 +284,8 @@ public class AggregateChangeIdGenerationImmutableUnitTests { .extracting(c -> c.id) // .containsExactly(2, 3); // softly.assertThat(entity.contentList.stream() // - .flatMap(c -> c.tagList.stream()) // - ).extracting(t -> t.id) // + .flatMap(c -> c.tagList.stream()) // + ).extracting(t -> t.id) // .containsExactly(4, 5, 6); // }); } @@ -324,13 +320,13 @@ public class AggregateChangeIdGenerationImmutableUnitTests { .extracting(Map.Entry::getKey, e -> e.getValue().id) // .containsExactly(tuple("one", 2), tuple("two", 3)); // softly.assertThat(entity.contentMap.values().stream() // - .flatMap(c -> c.tagMap.entrySet().stream())) // + .flatMap(c -> c.tagMap.entrySet().stream())) // .extracting(Map.Entry::getKey, e -> e.getValue().id) // .containsExactly( // tuple("111", 4), // tuple("222", 5), // tuple("333", 6) // - ); // + ); // }); } @@ -412,7 +408,7 @@ public class AggregateChangeIdGenerationImmutableUnitTests { } DbAction.Insert createDeepInsert(String propertyName, Object value, Object key, - @Nullable DbAction.Insert parentInsert) { + @Nullable DbAction.Insert parentInsert) { PersistentPropertyPath propertyPath = toPath( parentInsert.getPropertyPath().toDotPath() + "." + propertyName); @@ -430,18 +426,19 @@ public class AggregateChangeIdGenerationImmutableUnitTests { .orElseThrow(() -> new IllegalArgumentException("No matching path found")); } - @Value - @With - @AllArgsConstructor - private static class DummyEntity { + private static final class DummyEntity { - @Id Integer rootId; - Content single; - Set contentSet; - List contentList; - Map contentMap; - List contentNoIdList; - @Embedded(onEmpty = Embedded.OnEmpty.USE_NULL, prefix = "fooBar") ContentNoId embedded; + @Id + private final + Integer rootId; + private final Content single; + private final Set contentSet; + private final List contentList; + private final Map contentMap; + private final List contentNoIdList; + @Embedded(onEmpty = Embedded.OnEmpty.USE_NULL, prefix = "fooBar") + private final + ContentNoId embedded; DummyEntity() { @@ -453,18 +450,139 @@ public class AggregateChangeIdGenerationImmutableUnitTests { contentNoIdList = emptyList(); embedded = new ContentNoId(); } + + public DummyEntity(Integer rootId, Content single, Set contentSet, List contentList, Map contentMap, List contentNoIdList, ContentNoId embedded) { + this.rootId = rootId; + this.single = single; + this.contentSet = contentSet; + this.contentList = contentList; + this.contentMap = contentMap; + this.contentNoIdList = contentNoIdList; + this.embedded = embedded; + } + + public Integer getRootId() { + return this.rootId; + } + + public Content getSingle() { + return this.single; + } + + public Set getContentSet() { + return this.contentSet; + } + + public List getContentList() { + return this.contentList; + } + + public Map getContentMap() { + return this.contentMap; + } + + public List getContentNoIdList() { + return this.contentNoIdList; + } + + public ContentNoId getEmbedded() { + return this.embedded; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof DummyEntity)) return false; + final DummyEntity other = (DummyEntity) o; + final Object this$rootId = this.getRootId(); + final Object other$rootId = other.getRootId(); + if (this$rootId == null ? other$rootId != null : !this$rootId.equals(other$rootId)) return false; + final Object this$single = this.getSingle(); + final Object other$single = other.getSingle(); + if (this$single == null ? other$single != null : !this$single.equals(other$single)) return false; + final Object this$contentSet = this.getContentSet(); + final Object other$contentSet = other.getContentSet(); + if (this$contentSet == null ? other$contentSet != null : !this$contentSet.equals(other$contentSet)) + return false; + final Object this$contentList = this.getContentList(); + final Object other$contentList = other.getContentList(); + if (this$contentList == null ? other$contentList != null : !this$contentList.equals(other$contentList)) + return false; + final Object this$contentMap = this.getContentMap(); + final Object other$contentMap = other.getContentMap(); + if (this$contentMap == null ? other$contentMap != null : !this$contentMap.equals(other$contentMap)) + return false; + final Object this$contentNoIdList = this.getContentNoIdList(); + final Object other$contentNoIdList = other.getContentNoIdList(); + if (this$contentNoIdList == null ? other$contentNoIdList != null : !this$contentNoIdList.equals(other$contentNoIdList)) + return false; + final Object this$embedded = this.getEmbedded(); + final Object other$embedded = other.getEmbedded(); + if (this$embedded == null ? other$embedded != null : !this$embedded.equals(other$embedded)) return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $rootId = this.getRootId(); + result = result * PRIME + ($rootId == null ? 43 : $rootId.hashCode()); + final Object $single = this.getSingle(); + result = result * PRIME + ($single == null ? 43 : $single.hashCode()); + final Object $contentSet = this.getContentSet(); + result = result * PRIME + ($contentSet == null ? 43 : $contentSet.hashCode()); + final Object $contentList = this.getContentList(); + result = result * PRIME + ($contentList == null ? 43 : $contentList.hashCode()); + final Object $contentMap = this.getContentMap(); + result = result * PRIME + ($contentMap == null ? 43 : $contentMap.hashCode()); + final Object $contentNoIdList = this.getContentNoIdList(); + result = result * PRIME + ($contentNoIdList == null ? 43 : $contentNoIdList.hashCode()); + final Object $embedded = this.getEmbedded(); + result = result * PRIME + ($embedded == null ? 43 : $embedded.hashCode()); + return result; + } + + public String toString() { + return "AggregateChangeIdGenerationImmutableUnitTests.DummyEntity(rootId=" + this.getRootId() + ", single=" + this.getSingle() + ", contentSet=" + this.getContentSet() + ", contentList=" + this.getContentList() + ", contentMap=" + this.getContentMap() + ", contentNoIdList=" + this.getContentNoIdList() + ", embedded=" + this.getEmbedded() + ")"; + } + + public DummyEntity withRootId(Integer rootId) { + return this.rootId == rootId ? this : new DummyEntity(rootId, this.single, this.contentSet, this.contentList, this.contentMap, this.contentNoIdList, this.embedded); + } + + public DummyEntity withSingle(Content single) { + return this.single == single ? this : new DummyEntity(this.rootId, single, this.contentSet, this.contentList, this.contentMap, this.contentNoIdList, this.embedded); + } + + public DummyEntity withContentSet(Set contentSet) { + return this.contentSet == contentSet ? this : new DummyEntity(this.rootId, this.single, contentSet, this.contentList, this.contentMap, this.contentNoIdList, this.embedded); + } + + public DummyEntity withContentList(List contentList) { + return this.contentList == contentList ? this : new DummyEntity(this.rootId, this.single, this.contentSet, contentList, this.contentMap, this.contentNoIdList, this.embedded); + } + + public DummyEntity withContentMap(Map contentMap) { + return this.contentMap == contentMap ? this : new DummyEntity(this.rootId, this.single, this.contentSet, this.contentList, contentMap, this.contentNoIdList, this.embedded); + } + + public DummyEntity withContentNoIdList(List contentNoIdList) { + return this.contentNoIdList == contentNoIdList ? this : new DummyEntity(this.rootId, this.single, this.contentSet, this.contentList, this.contentMap, contentNoIdList, this.embedded); + } + + public DummyEntity withEmbedded(ContentNoId embedded) { + return this.embedded == embedded ? this : new DummyEntity(this.rootId, this.single, this.contentSet, this.contentList, this.contentMap, this.contentNoIdList, embedded); + } } - @Value - @With - @AllArgsConstructor - private static class Content { + private static final class Content { - @Id Integer id; - Tag single; - Set tagSet; - List tagList; - Map tagMap; + @Id + private final + Integer id; + private final Tag single; + private final Set tagSet; + private final List tagList; + private final Map tagMap; Content() { @@ -474,16 +592,105 @@ public class AggregateChangeIdGenerationImmutableUnitTests { tagList = emptyList(); tagMap = emptyMap(); } + + public Content(Integer id, Tag single, Set tagSet, List tagList, Map tagMap) { + this.id = id; + this.single = single; + this.tagSet = tagSet; + this.tagList = tagList; + this.tagMap = tagMap; + } + + public Integer getId() { + return this.id; + } + + public Tag getSingle() { + return this.single; + } + + public Set getTagSet() { + return this.tagSet; + } + + public List getTagList() { + return this.tagList; + } + + public Map getTagMap() { + return this.tagMap; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof Content)) return false; + final Content other = (Content) o; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false; + final Object this$single = this.getSingle(); + final Object other$single = other.getSingle(); + if (this$single == null ? other$single != null : !this$single.equals(other$single)) return false; + final Object this$tagSet = this.getTagSet(); + final Object other$tagSet = other.getTagSet(); + if (this$tagSet == null ? other$tagSet != null : !this$tagSet.equals(other$tagSet)) return false; + final Object this$tagList = this.getTagList(); + final Object other$tagList = other.getTagList(); + if (this$tagList == null ? other$tagList != null : !this$tagList.equals(other$tagList)) return false; + final Object this$tagMap = this.getTagMap(); + final Object other$tagMap = other.getTagMap(); + if (this$tagMap == null ? other$tagMap != null : !this$tagMap.equals(other$tagMap)) return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.getId(); + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + final Object $single = this.getSingle(); + result = result * PRIME + ($single == null ? 43 : $single.hashCode()); + final Object $tagSet = this.getTagSet(); + result = result * PRIME + ($tagSet == null ? 43 : $tagSet.hashCode()); + final Object $tagList = this.getTagList(); + result = result * PRIME + ($tagList == null ? 43 : $tagList.hashCode()); + final Object $tagMap = this.getTagMap(); + result = result * PRIME + ($tagMap == null ? 43 : $tagMap.hashCode()); + return result; + } + + public String toString() { + return "AggregateChangeIdGenerationImmutableUnitTests.Content(id=" + this.getId() + ", single=" + this.getSingle() + ", tagSet=" + this.getTagSet() + ", tagList=" + this.getTagList() + ", tagMap=" + this.getTagMap() + ")"; + } + + public Content withId(Integer id) { + return this.id == id ? this : new Content(id, this.single, this.tagSet, this.tagList, this.tagMap); + } + + public Content withSingle(Tag single) { + return this.single == single ? this : new Content(this.id, single, this.tagSet, this.tagList, this.tagMap); + } + + public Content withTagSet(Set tagSet) { + return this.tagSet == tagSet ? this : new Content(this.id, this.single, tagSet, this.tagList, this.tagMap); + } + + public Content withTagList(List tagList) { + return this.tagList == tagList ? this : new Content(this.id, this.single, this.tagSet, tagList, this.tagMap); + } + + public Content withTagMap(Map tagMap) { + return this.tagMap == tagMap ? this : new Content(this.id, this.single, this.tagSet, this.tagList, tagMap); + } } - @Value - @With - @AllArgsConstructor - private static class ContentNoId { - @Column("single") Tag single; - Set tagSet; - List tagList; - Map tagMap; + private static final class ContentNoId { + @Column("single") + private final + Tag single; + private final Set tagSet; + private final List tagList; + private final Map tagMap; ContentNoId() { @@ -492,20 +699,143 @@ public class AggregateChangeIdGenerationImmutableUnitTests { tagList = emptyList(); tagMap = emptyMap(); } + + public ContentNoId(Tag single, Set tagSet, List tagList, Map tagMap) { + this.single = single; + this.tagSet = tagSet; + this.tagList = tagList; + this.tagMap = tagMap; + } + + public Tag getSingle() { + return this.single; + } + + public Set getTagSet() { + return this.tagSet; + } + + public List getTagList() { + return this.tagList; + } + + public Map getTagMap() { + return this.tagMap; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof ContentNoId)) return false; + final ContentNoId other = (ContentNoId) o; + final Object this$single = this.getSingle(); + final Object other$single = other.getSingle(); + if (this$single == null ? other$single != null : !this$single.equals(other$single)) return false; + final Object this$tagSet = this.getTagSet(); + final Object other$tagSet = other.getTagSet(); + if (this$tagSet == null ? other$tagSet != null : !this$tagSet.equals(other$tagSet)) return false; + final Object this$tagList = this.getTagList(); + final Object other$tagList = other.getTagList(); + if (this$tagList == null ? other$tagList != null : !this$tagList.equals(other$tagList)) return false; + final Object this$tagMap = this.getTagMap(); + final Object other$tagMap = other.getTagMap(); + if (this$tagMap == null ? other$tagMap != null : !this$tagMap.equals(other$tagMap)) return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $single = this.getSingle(); + result = result * PRIME + ($single == null ? 43 : $single.hashCode()); + final Object $tagSet = this.getTagSet(); + result = result * PRIME + ($tagSet == null ? 43 : $tagSet.hashCode()); + final Object $tagList = this.getTagList(); + result = result * PRIME + ($tagList == null ? 43 : $tagList.hashCode()); + final Object $tagMap = this.getTagMap(); + result = result * PRIME + ($tagMap == null ? 43 : $tagMap.hashCode()); + return result; + } + + public String toString() { + return "AggregateChangeIdGenerationImmutableUnitTests.ContentNoId(single=" + this.getSingle() + ", tagSet=" + this.getTagSet() + ", tagList=" + this.getTagList() + ", tagMap=" + this.getTagMap() + ")"; + } + + public ContentNoId withSingle(Tag single) { + return this.single == single ? this : new ContentNoId(single, this.tagSet, this.tagList, this.tagMap); + } + + public ContentNoId withTagSet(Set tagSet) { + return this.tagSet == tagSet ? this : new ContentNoId(this.single, tagSet, this.tagList, this.tagMap); + } + + public ContentNoId withTagList(List tagList) { + return this.tagList == tagList ? this : new ContentNoId(this.single, this.tagSet, tagList, this.tagMap); + } + + public ContentNoId withTagMap(Map tagMap) { + return this.tagMap == tagMap ? this : new ContentNoId(this.single, this.tagSet, this.tagList, tagMap); + } } - @Value - @With - @AllArgsConstructor - private static class Tag { + private static final class Tag { - @Id Integer id; + @Id + private final + Integer id; - String name; + private final String name; Tag(String name) { id = null; this.name = name; } + + public Tag(Integer id, String name) { + this.id = id; + this.name = name; + } + + public Integer getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof Tag)) return false; + final Tag other = (Tag) o; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false; + final Object this$name = this.getName(); + final Object other$name = other.getName(); + if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.getId(); + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + final Object $name = this.getName(); + result = result * PRIME + ($name == null ? 43 : $name.hashCode()); + return result; + } + + public String toString() { + return "AggregateChangeIdGenerationImmutableUnitTests.Tag(id=" + this.getId() + ", name=" + this.getName() + ")"; + } + + public Tag withId(Integer id) { + return this.id == id ? this : new Tag(id, this.name); + } + + public Tag withName(String name) { + return this.name == name ? this : new Tag(this.id, name); + } } } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/ImmutableAggregateTemplateHsqlIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/ImmutableAggregateTemplateHsqlIntegrationTests.java index 4714b5cc..ef46c9c2 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/ImmutableAggregateTemplateHsqlIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/ImmutableAggregateTemplateHsqlIntegrationTests.java @@ -18,11 +18,6 @@ package org.springframework.data.jdbc.core; import static java.util.Collections.*; import static org.assertj.core.api.Assertions.*; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.Value; -import lombok.With; - import org.assertj.core.api.SoftAssertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -300,45 +295,307 @@ public class ImmutableAggregateTemplateHsqlIntegrationTests { "Accelerates to 99% of light speed. Destroys almost everything. See https://what-if.xkcd.com/1/"); } - @Value - @With - static class LegoSet { + static final class LegoSet { - @Id Long id; - String name; - Manual manual; - Author author; + @Id private final Long id; + private final String name; + private final Manual manual; + private final Author author; + + public LegoSet(Long id, String name, Manual manual, Author author) { + this.id = id; + this.name = name; + this.manual = manual; + this.author = author; + } + + public Long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public Manual getManual() { + return this.manual; + } + + public Author getAuthor() { + return this.author; + } + + public boolean equals(final Object o) { + if (o == this) + return true; + if (!(o instanceof LegoSet)) + return false; + final LegoSet other = (LegoSet) o; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) + return false; + final Object this$name = this.getName(); + final Object other$name = other.getName(); + if (this$name == null ? other$name != null : !this$name.equals(other$name)) + return false; + final Object this$manual = this.getManual(); + final Object other$manual = other.getManual(); + if (this$manual == null ? other$manual != null : !this$manual.equals(other$manual)) + return false; + final Object this$author = this.getAuthor(); + final Object other$author = other.getAuthor(); + if (this$author == null ? other$author != null : !this$author.equals(other$author)) + return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.getId(); + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + final Object $name = this.getName(); + result = result * PRIME + ($name == null ? 43 : $name.hashCode()); + final Object $manual = this.getManual(); + result = result * PRIME + ($manual == null ? 43 : $manual.hashCode()); + final Object $author = this.getAuthor(); + result = result * PRIME + ($author == null ? 43 : $author.hashCode()); + return result; + } + + public String toString() { + return "ImmutableAggregateTemplateHsqlIntegrationTests.LegoSet(id=" + this.getId() + ", name=" + this.getName() + + ", manual=" + this.getManual() + ", author=" + this.getAuthor() + ")"; + } + + public LegoSet withId(Long id) { + return this.id == id ? this : new LegoSet(id, this.name, this.manual, this.author); + } + + public LegoSet withName(String name) { + return this.name == name ? this : new LegoSet(this.id, name, this.manual, this.author); + } + + public LegoSet withManual(Manual manual) { + return this.manual == manual ? this : new LegoSet(this.id, this.name, manual, this.author); + } + + public LegoSet withAuthor(Author author) { + return this.author == author ? this : new LegoSet(this.id, this.name, this.manual, author); + } } - @Value - @With - static class Manual { + static final class Manual { - @Id Long id; - String content; + @Id private final Long id; + private final String content; + + public Manual(Long id, String content) { + this.id = id; + this.content = content; + } + + public Long getId() { + return this.id; + } + + public String getContent() { + return this.content; + } + + public boolean equals(final Object o) { + if (o == this) + return true; + if (!(o instanceof Manual)) + return false; + final Manual other = (Manual) o; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) + return false; + final Object this$content = this.getContent(); + final Object other$content = other.getContent(); + if (this$content == null ? other$content != null : !this$content.equals(other$content)) + return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.getId(); + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + final Object $content = this.getContent(); + result = result * PRIME + ($content == null ? 43 : $content.hashCode()); + return result; + } + + public String toString() { + return "ImmutableAggregateTemplateHsqlIntegrationTests.Manual(id=" + this.getId() + ", content=" + + this.getContent() + ")"; + } + + public Manual withId(Long id) { + return this.id == id ? this : new Manual(id, this.content); + } + + public Manual withContent(String content) { + return this.content == content ? this : new Manual(this.id, content); + } } - @Value - @With - static class Author { + static final class Author { - @Id Long id; - String name; + @Id private final Long id; + private final String name; + + public Author(Long id, String name) { + this.id = id; + this.name = name; + } + + public Long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public boolean equals(final Object o) { + if (o == this) + return true; + if (!(o instanceof Author)) + return false; + final Author other = (Author) o; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) + return false; + final Object this$name = this.getName(); + final Object other$name = other.getName(); + if (this$name == null ? other$name != null : !this$name.equals(other$name)) + return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.getId(); + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + final Object $name = this.getName(); + result = result * PRIME + ($name == null ? 43 : $name.hashCode()); + return result; + } + + public String toString() { + return "ImmutableAggregateTemplateHsqlIntegrationTests.Author(id=" + this.getId() + ", name=" + this.getName() + + ")"; + } + + public Author withId(Long id) { + return this.id == id ? this : new Author(id, this.name); + } + + public Author withName(String name) { + return this.name == name ? this : new Author(this.id, name); + } } - @Data - @AllArgsConstructor static class Root { @Id private Long id; private String name; private NonRoot reference; + + public Root(Long id, String name, NonRoot reference) { + this.id = id; + this.name = name; + this.reference = reference; + } + + public Long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public NonRoot getReference() { + return this.reference; + } + + public void setId(Long id) { + this.id = id; + } + + public void setName(String name) { + this.name = name; + } + + public void setReference(NonRoot reference) { + this.reference = reference; + } } - @Value - @With - static class NonRoot { - @Id Long id; - String name; + static final class NonRoot { + @Id private final Long id; + private final String name; + + public NonRoot(Long id, String name) { + this.id = id; + this.name = name; + } + + public Long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public boolean equals(final Object o) { + if (o == this) + return true; + if (!(o instanceof NonRoot)) + return false; + final NonRoot other = (NonRoot) o; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) + return false; + final Object this$name = this.getName(); + final Object other$name = other.getName(); + if (this$name == null ? other$name != null : !this$name.equals(other$name)) + return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.getId(); + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + final Object $name = this.getName(); + result = result * PRIME + ($name == null ? 43 : $name.hashCode()); + return result; + } + + public String toString() { + return "ImmutableAggregateTemplateHsqlIntegrationTests.NonRoot(id=" + this.getId() + ", name=" + this.getName() + + ")"; + } + + public NonRoot withId(Long id) { + return this.id == id ? this : new NonRoot(id, this.name); + } + + public NonRoot withName(String name) { + return this.name == name ? this : new NonRoot(this.id, name); + } } static class WithCopyConstructor { diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateChangeExecutorContextImmutableUnitTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateChangeExecutorContextImmutableUnitTests.java index 031aaa23..56decf35 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateChangeExecutorContextImmutableUnitTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateChangeExecutorContextImmutableUnitTests.java @@ -15,16 +15,6 @@ */ package org.springframework.data.jdbc.core; -import static java.util.Collections.*; -import static org.assertj.core.api.Assertions.*; -import static org.mockito.Mockito.*; - -import lombok.AllArgsConstructor; -import lombok.Value; -import lombok.With; - -import java.util.List; - import org.junit.jupiter.api.Test; import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Version; @@ -42,6 +32,12 @@ import org.springframework.data.relational.core.mapping.RelationalMappingContext import org.springframework.data.relational.core.mapping.RelationalPersistentProperty; import org.springframework.lang.Nullable; +import java.util.List; + +import static java.util.Collections.*; +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.*; + /** * Test for the {@link JdbcAggregateChangeExecutionContext} when operating on immutable classes. * @@ -181,17 +177,16 @@ public class JdbcAggregateChangeExecutorContextImmutableUnitTests { .orElseThrow(() -> new IllegalArgumentException("No matching path found")); } - @Value - @AllArgsConstructor - @With - private static class DummyEntity { + private static final class DummyEntity { - @Id Long id; - @Version long version; + @Id + private final Long id; + @Version + private final long version; - Content content; + private final Content content; - List list; + private final List list; DummyEntity() { @@ -200,17 +195,123 @@ public class JdbcAggregateChangeExecutorContextImmutableUnitTests { content = null; list = null; } + + public DummyEntity(Long id, long version, Content content, List list) { + this.id = id; + this.version = version; + this.content = content; + this.list = list; + } + + public Long getId() { + return this.id; + } + + public long getVersion() { + return this.version; + } + + public Content getContent() { + return this.content; + } + + public List getList() { + return this.list; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof DummyEntity)) return false; + final DummyEntity other = (DummyEntity) o; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false; + if (this.getVersion() != other.getVersion()) return false; + final Object this$content = this.getContent(); + final Object other$content = other.getContent(); + if (this$content == null ? other$content != null : !this$content.equals(other$content)) return false; + final Object this$list = this.getList(); + final Object other$list = other.getList(); + if (this$list == null ? other$list != null : !this$list.equals(other$list)) return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.getId(); + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + final long $version = this.getVersion(); + result = result * PRIME + (int) ($version >>> 32 ^ $version); + final Object $content = this.getContent(); + result = result * PRIME + ($content == null ? 43 : $content.hashCode()); + final Object $list = this.getList(); + result = result * PRIME + ($list == null ? 43 : $list.hashCode()); + return result; + } + + public String toString() { + return "JdbcAggregateChangeExecutorContextImmutableUnitTests.DummyEntity(id=" + this.getId() + ", version=" + this.getVersion() + ", content=" + this.getContent() + ", list=" + this.getList() + ")"; + } + + public DummyEntity withId(Long id) { + return this.id == id ? this : new DummyEntity(id, this.version, this.content, this.list); + } + + public DummyEntity withVersion(long version) { + return this.version == version ? this : new DummyEntity(this.id, version, this.content, this.list); + } + + public DummyEntity withContent(Content content) { + return this.content == content ? this : new DummyEntity(this.id, this.version, content, this.list); + } + + public DummyEntity withList(List list) { + return this.list == list ? this : new DummyEntity(this.id, this.version, this.content, list); + } } - @Value - @AllArgsConstructor - @With - private static class Content { - @Id Long id; + private static final class Content { + @Id + private final Long id; Content() { id = null; } + + public Content(Long id) { + this.id = id; + } + + public Long getId() { + return this.id; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof Content)) return false; + final Content other = (Content) o; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.getId(); + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + return result; + } + + public String toString() { + return "JdbcAggregateChangeExecutorContextImmutableUnitTests.Content(id=" + this.getId() + ")"; + } + + public Content withId(Long id) { + return this.id == id ? this : new Content(id); + } } } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateChangeExecutorContextUnitTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateChangeExecutorContextUnitTests.java index 439d8507..1030e452 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateChangeExecutorContextUnitTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateChangeExecutorContextUnitTests.java @@ -20,8 +20,6 @@ import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.*; import static org.springframework.data.jdbc.core.convert.JdbcIdentifierBuilder.*; -import lombok.Value; - import java.util.ArrayList; import java.util.List; @@ -287,9 +285,7 @@ public class JdbcAggregateChangeExecutorContextUnitTests { @Id Long id; } - @Value - private static class ContentImmutableId { - @Id Long id; + record ContentImmutableId(@Id Long id) { } } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateIntegrationTests.java index f0cfa10e..0ad8dd99 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateIntegrationTests.java @@ -22,11 +22,6 @@ import static org.assertj.core.api.SoftAssertions.*; import static org.springframework.data.jdbc.testing.TestDatabaseFeatures.Feature.*; import static org.springframework.test.context.TestExecutionListeners.MergeMode.*; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.Value; -import lombok.With; - import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Collections; @@ -35,6 +30,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.function.Function; import java.util.stream.IntStream; @@ -188,11 +184,11 @@ class JdbcAggregateTemplateIntegrationTests { private static LegoSet createLegoSet(String name) { LegoSet entity = new LegoSet(); - entity.setName(name); + entity.name = (name); Manual manual = new Manual(); - manual.setContent("Accelerates to 99% of light speed; Destroys almost everything. See https://what-if.xkcd.com/1/"); - entity.setManual(manual); + manual.content = ("Accelerates to 99% of light speed; Destroys almost everything. See https://what-if.xkcd.com/1/"); + entity.manual = (manual); return entity; } @@ -205,15 +201,15 @@ class JdbcAggregateTemplateIntegrationTests { assertThat(legoSet.manual.id).describedAs("id of stored manual").isNotNull(); - LegoSet reloadedLegoSet = template.findById(legoSet.getId(), LegoSet.class); + LegoSet reloadedLegoSet = template.findById(legoSet.id, LegoSet.class); assertThat(reloadedLegoSet.manual).isNotNull(); assertSoftly(softly -> { - softly.assertThat(reloadedLegoSet.manual.getId()) // - .isEqualTo(legoSet.getManual().getId()) // + softly.assertThat(reloadedLegoSet.manual.id) // + .isEqualTo(legoSet.manual.id) // .isNotNull(); - softly.assertThat(reloadedLegoSet.manual.getContent()).isEqualTo(legoSet.getManual().getContent()); + softly.assertThat(reloadedLegoSet.manual.content).isEqualTo(legoSet.manual.content); }); } @@ -228,7 +224,7 @@ class JdbcAggregateTemplateIntegrationTests { assertThat(reloadedLegoSets) // .extracting("id", "manual.id", "manual.content") // - .containsExactly(tuple(legoSet.getId(), legoSet.getManual().getId(), legoSet.getManual().getContent())); + .containsExactly(tuple(legoSet.id, legoSet.manual.id, legoSet.manual.content)); } @Test // DATAJDBC-101 @@ -277,38 +273,36 @@ class JdbcAggregateTemplateIntegrationTests { .containsExactly("Frozen", "Star", null); } - @Test // - @EnabledOnFeature({ SUPPORTS_QUOTED_IDS}) + @EnabledOnFeature({ SUPPORTS_QUOTED_IDS }) void findByNonPropertySortFails() { - assertThatThrownBy(() -> template.findAll(LegoSet.class, - Sort.by("somethingNotExistant"))).isInstanceOf(InvalidPersistentPropertyPath.class); + assertThatThrownBy(() -> template.findAll(LegoSet.class, Sort.by("somethingNotExistant"))) + .isInstanceOf(InvalidPersistentPropertyPath.class); } - @Test // DATAJDBC-112 @EnabledOnFeature(SUPPORTS_QUOTED_IDS) void saveAndLoadManyEntitiesByIdWithReferencedEntity() { template.save(legoSet); - Iterable reloadedLegoSets = template.findAllById(singletonList(legoSet.getId()), LegoSet.class); + Iterable reloadedLegoSets = template.findAllById(singletonList(legoSet.id), LegoSet.class); assertThat(reloadedLegoSets).hasSize(1).extracting("id", "manual.id", "manual.content") - .contains(tuple(legoSet.getId(), legoSet.getManual().getId(), legoSet.getManual().getContent())); + .contains(tuple(legoSet.id, legoSet.manual.id, legoSet.manual.content)); } @Test // DATAJDBC-112 @EnabledOnFeature(SUPPORTS_QUOTED_IDS) void saveAndLoadAnEntityWithReferencedNullEntity() { - legoSet.setManual(null); + legoSet.manual = (null); template.save(legoSet); - LegoSet reloadedLegoSet = template.findById(legoSet.getId(), LegoSet.class); + LegoSet reloadedLegoSet = template.findById(legoSet.id, LegoSet.class); assertThat(reloadedLegoSet.manual).isNull(); } @@ -378,7 +372,8 @@ class JdbcAggregateTemplateIntegrationTests { }); } - @Test // GH-537 + @Test + // GH-537 void saveAndDeleteAllByAggregateRootsWithVersion() { AggregateWithImmutableVersion aggregate1 = new AggregateWithImmutableVersion(null, null); @@ -397,7 +392,8 @@ class JdbcAggregateTemplateIntegrationTests { assertThat(template.count(AggregateWithImmutableVersion.class)).isEqualTo(0); } - @Test // GH-1395 + @Test + // GH-1395 void insertAndUpdateAllByAggregateRootsWithVersion() { AggregateWithImmutableVersion aggregate1 = new AggregateWithImmutableVersion(null, null); @@ -412,8 +408,8 @@ class JdbcAggregateTemplateIntegrationTests { AggregateWithImmutableVersion twiceSavedAggregate2 = template.save(savedAggregatesIterator.next()); AggregateWithImmutableVersion twiceSavedAggregate3 = template.save(savedAggregatesIterator.next()); - savedAggregatesIterator = template.updateAll( - List.of(savedAggregate1, twiceSavedAggregate2, twiceSavedAggregate3)).iterator(); + savedAggregatesIterator = template.updateAll(List.of(savedAggregate1, twiceSavedAggregate2, twiceSavedAggregate3)) + .iterator(); assertThat(savedAggregatesIterator.next().version).isEqualTo(1); assertThat(savedAggregatesIterator.next().version).isEqualTo(2); @@ -426,17 +422,17 @@ class JdbcAggregateTemplateIntegrationTests { @EnabledOnFeature({ SUPPORTS_QUOTED_IDS, SUPPORTS_GENERATED_IDS_IN_REFERENCED_ENTITIES }) void updateReferencedEntityFromNull() { - legoSet.setManual(null); + legoSet.manual = (null); template.save(legoSet); Manual manual = new Manual(); - manual.setId(23L); - manual.setContent("Some content"); - legoSet.setManual(manual); + manual.id = (23L); + manual.content = ("Some content"); + legoSet.manual = (manual); template.save(legoSet); - LegoSet reloadedLegoSet = template.findById(legoSet.getId(), LegoSet.class); + LegoSet reloadedLegoSet = template.findById(legoSet.id, LegoSet.class); assertThat(reloadedLegoSet.manual.content).isEqualTo("Some content"); } @@ -447,11 +443,11 @@ class JdbcAggregateTemplateIntegrationTests { template.save(legoSet); - legoSet.setManual(null); + legoSet.manual = (null); template.save(legoSet); - LegoSet reloadedLegoSet = template.findById(legoSet.getId(), LegoSet.class); + LegoSet reloadedLegoSet = template.findById(legoSet.id, LegoSet.class); SoftAssertions softly = new SoftAssertions(); @@ -461,11 +457,12 @@ class JdbcAggregateTemplateIntegrationTests { softly.assertAll(); } - @Test // DATAJDBC-438 + @Test + // DATAJDBC-438 void updateFailedRootDoesNotExist() { LegoSet entity = new LegoSet(); - entity.setId(100L); // does not exist in the database + entity.id = (100L); // does not exist in the database assertThatExceptionOfType(DbActionExecutionException.class) // .isThrownBy(() -> template.save(entity)) // @@ -479,12 +476,12 @@ class JdbcAggregateTemplateIntegrationTests { template.save(legoSet); Manual manual = new Manual(); - manual.setContent("other content"); - legoSet.setManual(manual); + manual.content = ("other content"); + legoSet.manual = (manual); template.save(legoSet); - LegoSet reloadedLegoSet = template.findById(legoSet.getId(), LegoSet.class); + LegoSet reloadedLegoSet = template.findById(legoSet.id, LegoSet.class); assertSoftly(softly -> { @@ -499,11 +496,11 @@ class JdbcAggregateTemplateIntegrationTests { template.save(legoSet); - legoSet.manual.setContent("new content"); + legoSet.manual.content = ("new content"); template.save(legoSet); - LegoSet reloadedLegoSet = template.findById(legoSet.getId(), LegoSet.class); + LegoSet reloadedLegoSet = template.findById(legoSet.id, LegoSet.class); assertThat(reloadedLegoSet.manual.content).isEqualTo("new content"); } @@ -565,7 +562,7 @@ class JdbcAggregateTemplateIntegrationTests { assertThat(legoSet.manual.id).describedAs("id of stored manual").isNotNull(); - LegoSet reloadedLegoSet = template.findById(legoSet.getId(), LegoSet.class); + LegoSet reloadedLegoSet = template.findById(legoSet.id, LegoSet.class); assertThat(reloadedLegoSet.alternativeInstructions).isNull(); } @@ -580,7 +577,7 @@ class JdbcAggregateTemplateIntegrationTests { assertThat(legoSet.manual.id).describedAs("id of stored manual").isNotNull(); - LegoSet reloadedLegoSet = template.findById(legoSet.getId(), LegoSet.class); + LegoSet reloadedLegoSet = template.findById(legoSet.id, LegoSet.class); assertSoftly(softly -> { @@ -736,7 +733,8 @@ class JdbcAggregateTemplateIntegrationTests { assertThat(reloaded.digits).isEqualTo(new HashSet<>(asList("one", "two", "three"))); } - @Test // DATAJDBC-327 + @Test + // DATAJDBC-327 void saveAndLoadAnEntityWithByteArray() { ByteArrayOwner owner = new ByteArrayOwner(); @@ -811,7 +809,8 @@ class JdbcAggregateTemplateIntegrationTests { assertThat(count("CHAIN0")).isEqualTo(0); } - @Test // DATAJDBC-223 + @Test + // DATAJDBC-223 void saveAndLoadLongChainOfListsWithoutIds() { NoIdListChain4 saved = template.save(createNoIdTree()); @@ -822,7 +821,8 @@ class JdbcAggregateTemplateIntegrationTests { assertThat(reloaded).isEqualTo(saved); } - @Test // DATAJDBC-223 + @Test + // DATAJDBC-223 void shouldDeleteChainOfListsWithoutIds() { NoIdListChain4 saved = template.save(createNoIdTree()); @@ -838,7 +838,8 @@ class JdbcAggregateTemplateIntegrationTests { }); } - @Test // DATAJDBC-223 + @Test + // DATAJDBC-223 void saveAndLoadLongChainOfMapsWithoutIds() { NoIdMapChain4 saved = template.save(createNoIdMapTree()); @@ -849,7 +850,8 @@ class JdbcAggregateTemplateIntegrationTests { assertThat(reloaded).isEqualTo(saved); } - @Test // DATAJDBC-223 + @Test + // DATAJDBC-223 void shouldDeleteChainOfMapsWithoutIds() { NoIdMapChain4 saved = template.save(createNoIdMapTree()); @@ -880,14 +882,15 @@ class JdbcAggregateTemplateIntegrationTests { .isEqualTo("from-db"); } - @Test // DATAJDBC-219 Test that immutable version attribute works as expected. + @Test + // DATAJDBC-219 Test that immutable version attribute works as expected. void saveAndUpdateAggregateWithImmutableVersion() { AggregateWithImmutableVersion aggregate = new AggregateWithImmutableVersion(null, null); aggregate = template.save(aggregate); assertThat(aggregate.version).isEqualTo(0L); - Long id = aggregate.getId(); + Long id = aggregate.id; AggregateWithImmutableVersion reloadedAggregate = template.findById(id, aggregate.getClass()); assertThat(reloadedAggregate.getVersion()).describedAs("version field should initially have the value 0") @@ -911,7 +914,8 @@ class JdbcAggregateTemplateIntegrationTests { .isInstanceOf(OptimisticLockingFailureException.class); } - @Test // GH-1137 + @Test + // GH-1137 void testUpdateEntityWithVersionDoesNotTriggerAnewConstructorInvocation() { AggregateWithImmutableVersion aggregateWithImmutableVersion = new AggregateWithImmutableVersion(null, null); @@ -939,7 +943,8 @@ class JdbcAggregateTemplateIntegrationTests { .containsOnly(new ConstructorInvocation(savedRoot.id, updatedRoot.version)); } - @Test // DATAJDBC-219 Test that a delete with a version attribute works as expected. + @Test + // DATAJDBC-219 Test that a delete with a version attribute works as expected. void deleteAggregateWithVersion() { AggregateWithImmutableVersion aggregate = new AggregateWithImmutableVersion(null, null); @@ -948,17 +953,15 @@ class JdbcAggregateTemplateIntegrationTests { aggregate = template.save(aggregate); // Should have an ID and a version of 1. - final Long id = aggregate.getId(); + final Long id = aggregate.id; - assertThatThrownBy( - () -> template.delete(new AggregateWithImmutableVersion(id, 0L))) - .describedAs("deleting an aggregate with an outdated version should raise an exception") - .isInstanceOf(OptimisticLockingFailureException.class); + assertThatThrownBy(() -> template.delete(new AggregateWithImmutableVersion(id, 0L))) + .describedAs("deleting an aggregate with an outdated version should raise an exception") + .isInstanceOf(OptimisticLockingFailureException.class); - assertThatThrownBy( - () -> template.delete(new AggregateWithImmutableVersion(id, 2L))) - .describedAs("deleting an aggregate with a future version should raise an exception") - .isInstanceOf(OptimisticLockingFailureException.class); + assertThatThrownBy(() -> template.delete(new AggregateWithImmutableVersion(id, 2L))) + .describedAs("deleting an aggregate with a future version should raise an exception") + .isInstanceOf(OptimisticLockingFailureException.class); // This should succeed template.delete(aggregate); @@ -967,41 +970,48 @@ class JdbcAggregateTemplateIntegrationTests { aggregate = template.save(aggregate); // This should succeed, as version will not be used. - template.deleteById(aggregate.getId(), AggregateWithImmutableVersion.class); + template.deleteById(aggregate.id, AggregateWithImmutableVersion.class); } - @Test // DATAJDBC-219 + @Test + // DATAJDBC-219 void saveAndUpdateAggregateWithLongVersion() { saveAndUpdateAggregateWithVersion(new AggregateWithLongVersion(), Number::longValue); } - @Test // DATAJDBC-219 + @Test + // DATAJDBC-219 void saveAndUpdateAggregateWithPrimitiveLongVersion() { saveAndUpdateAggregateWithPrimitiveVersion(new AggregateWithPrimitiveLongVersion(), Number::longValue); } - @Test // DATAJDBC-219 + @Test + // DATAJDBC-219 void saveAndUpdateAggregateWithIntegerVersion() { saveAndUpdateAggregateWithVersion(new AggregateWithIntegerVersion(), Number::intValue); } - @Test // DATAJDBC-219 + @Test + // DATAJDBC-219 void saveAndUpdateAggregateWithPrimitiveIntegerVersion() { saveAndUpdateAggregateWithPrimitiveVersion(new AggregateWithPrimitiveIntegerVersion(), Number::intValue); } - @Test // DATAJDBC-219 + @Test + // DATAJDBC-219 void saveAndUpdateAggregateWithShortVersion() { saveAndUpdateAggregateWithVersion(new AggregateWithShortVersion(), Number::shortValue); } - @Test // DATAJDBC-219 + @Test + // DATAJDBC-219 void saveAndUpdateAggregateWithPrimitiveShortVersion() { saveAndUpdateAggregateWithPrimitiveVersion(new AggregateWithPrimitiveShortVersion(), Number::shortValue); } - @Test // GH-1254 + @Test + // GH-1254 void saveAndUpdateAggregateWithIdAndNullVersion() { PersistableVersionedAggregate aggregate = new PersistableVersionedAggregate(); @@ -1037,7 +1047,8 @@ class JdbcAggregateTemplateIntegrationTests { assertThat(loaded.testTime).isEqualTo(entity.testTime); } - @Test // DATAJDBC-637 + @Test + // DATAJDBC-637 void saveAndLoadDateTimeWithMicrosecondPrecision() { WithLocalDateTime entity = new WithLocalDateTime(); @@ -1051,7 +1062,8 @@ class JdbcAggregateTemplateIntegrationTests { assertThat(loaded.testTime).isEqualTo(entity.testTime); } - @Test // GH-777 + @Test + // GH-777 void insertWithIdOnly() { WithIdOnly entity = new WithIdOnly(); @@ -1059,7 +1071,8 @@ class JdbcAggregateTemplateIntegrationTests { assertThat(template.save(entity).id).isNotNull(); } - @Test // GH-1309 + @Test + // GH-1309 void updateIdOnlyAggregate() { WithIdOnly entity = new WithIdOnly(); @@ -1069,7 +1082,8 @@ class JdbcAggregateTemplateIntegrationTests { template.save(entity); } - @Test // GH-637 + @Test + // GH-637 void insertOnlyPropertyDoesNotGetUpdated() { WithInsertOnly entity = new WithInsertOnly(); @@ -1088,11 +1102,11 @@ class JdbcAggregateTemplateIntegrationTests { void readEnumArray() { EnumArrayOwner entity = new EnumArrayOwner(); - entity.digits = new Color[]{Color.BLUE}; + entity.digits = new Color[] { Color.BLUE }; template.save(entity); - assertThat(template.findById(entity.id, EnumArrayOwner.class).digits).isEqualTo(new Color[]{Color.BLUE}); + assertThat(template.findById(entity.id, EnumArrayOwner.class).digits).isEqualTo(new Color[] { Color.BLUE }); } private void saveAndUpdateAggregateWithVersion(VersionedAggregate aggregate, @@ -1110,13 +1124,13 @@ class JdbcAggregateTemplateIntegrationTests { template.save(aggregate); - VersionedAggregate reloadedAggregate = template.findById(aggregate.getId(), aggregate.getClass()); + VersionedAggregate reloadedAggregate = template.findById(aggregate.id, aggregate.getClass()); assertThat(reloadedAggregate.getVersion()) // .withFailMessage("version field should initially have the value 0") .isEqualTo(toConcreteNumber.apply(initialId)); template.save(reloadedAggregate); - VersionedAggregate updatedAggregate = template.findById(aggregate.getId(), aggregate.getClass()); + VersionedAggregate updatedAggregate = template.findById(aggregate.id, aggregate.getClass()); assertThat(updatedAggregate.getVersion()) // .withFailMessage("version field should increment by one with each save") .isEqualTo(toConcreteNumber.apply(initialId + 1)); @@ -1189,10 +1203,10 @@ class JdbcAggregateTemplateIntegrationTests { List digits = new ArrayList<>(); } - @Data static class LegoSet { - @Column("id1") @Id private Long id; + @Column("id1") + @Id private Long id; private String name; @@ -1200,10 +1214,10 @@ class JdbcAggregateTemplateIntegrationTests { @Column("alternative") private Manual alternativeInstructions; } - @Data static class Manual { - @Column("id2") @Id private Long id; + @Column("id2") + @Id private Long id; private String content; } @@ -1211,7 +1225,8 @@ class JdbcAggregateTemplateIntegrationTests { @SuppressWarnings("unused") static class OneToOneParent { - @Column("id3") @Id private Long id; + @Column("id3") + @Id private Long id; private String content; private ChildNoId child; @@ -1225,7 +1240,8 @@ class JdbcAggregateTemplateIntegrationTests { @SuppressWarnings("unused") static class ListParent { - @Column("id4") @Id private Long id; + @Column("id4") + @Id private Long id; String name; @MappedCollection(idColumn = "LIST_PARENT") List content = new ArrayList<>(); } @@ -1233,7 +1249,8 @@ class JdbcAggregateTemplateIntegrationTests { @Table("LIST_PARENT") static class ListParentAllArgs { - @Column("id4") @Id private final Long id; + @Column("id4") + @Id private final Long id; private final String name; @MappedCollection(idColumn = "LIST_PARENT") private final List content = new ArrayList<>(); @@ -1321,67 +1338,209 @@ class JdbcAggregateTemplateIntegrationTests { /** * One may think of ChainN as a chain with N further elements */ - @EqualsAndHashCode static class NoIdListChain0 { String zeroValue; + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + NoIdListChain0 that = (NoIdListChain0) o; + return Objects.equals(zeroValue, that.zeroValue); + } + + @Override + public int hashCode() { + return Objects.hash(zeroValue); + } } - @EqualsAndHashCode static class NoIdListChain1 { String oneValue; List chain0 = new ArrayList<>(); + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + NoIdListChain1 that = (NoIdListChain1) o; + return Objects.equals(oneValue, that.oneValue) && Objects.equals(chain0, that.chain0); + } + + @Override + public int hashCode() { + return Objects.hash(oneValue, chain0); + } } - @EqualsAndHashCode static class NoIdListChain2 { String twoValue; List chain1 = new ArrayList<>(); + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + NoIdListChain2 that = (NoIdListChain2) o; + return Objects.equals(twoValue, that.twoValue) && Objects.equals(chain1, that.chain1); + } + + @Override + public int hashCode() { + return Objects.hash(twoValue, chain1); + } } - @EqualsAndHashCode static class NoIdListChain3 { String threeValue; List chain2 = new ArrayList<>(); + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + NoIdListChain3 that = (NoIdListChain3) o; + return Objects.equals(threeValue, that.threeValue) && Objects.equals(chain2, that.chain2); + } + + @Override + public int hashCode() { + return Objects.hash(threeValue, chain2); + } } - @EqualsAndHashCode static class NoIdListChain4 { @Id Long four; String fourValue; List chain3 = new ArrayList<>(); + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + NoIdListChain4 that = (NoIdListChain4) o; + return Objects.equals(four, that.four) && Objects.equals(fourValue, that.fourValue) + && Objects.equals(chain3, that.chain3); + } + + @Override + public int hashCode() { + return Objects.hash(four, fourValue, chain3); + } } /** * One may think of ChainN as a chain with N further elements */ - @EqualsAndHashCode static class NoIdMapChain0 { String zeroValue; + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + NoIdMapChain0 that = (NoIdMapChain0) o; + return Objects.equals(zeroValue, that.zeroValue); + } + + @Override + public int hashCode() { + return Objects.hash(zeroValue); + } } - @EqualsAndHashCode static class NoIdMapChain1 { String oneValue; Map chain0 = new HashMap<>(); + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + NoIdMapChain1 that = (NoIdMapChain1) o; + return Objects.equals(oneValue, that.oneValue) && Objects.equals(chain0, that.chain0); + } + + @Override + public int hashCode() { + return Objects.hash(oneValue, chain0); + } } - @EqualsAndHashCode static class NoIdMapChain2 { String twoValue; Map chain1 = new HashMap<>(); + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + NoIdMapChain2 that = (NoIdMapChain2) o; + return Objects.equals(twoValue, that.twoValue) && Objects.equals(chain1, that.chain1); + } + + @Override + public int hashCode() { + return Objects.hash(twoValue, chain1); + } } - @EqualsAndHashCode static class NoIdMapChain3 { String threeValue; Map chain2 = new HashMap<>(); + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + NoIdMapChain3 that = (NoIdMapChain3) o; + return Objects.equals(threeValue, that.threeValue) && Objects.equals(chain2, that.chain2); + } + + @Override + public int hashCode() { + return Objects.hash(threeValue, chain2); + } } - @EqualsAndHashCode static class NoIdMapChain4 { @Id Long four; String fourValue; Map chain3 = new HashMap<>(); + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + NoIdMapChain4 that = (NoIdMapChain4) o; + return Objects.equals(four, that.four) && Objects.equals(fourValue, that.fourValue) + && Objects.equals(chain3, that.chain3); + } + + @Override + public int hashCode() { + return Objects.hash(four, fourValue, chain3); + } } @SuppressWarnings("unused") @@ -1391,7 +1550,6 @@ class JdbcAggregateTemplateIntegrationTests { @ReadOnlyProperty String readOnly; } - @Data static abstract class VersionedAggregate { @Id private Long id; @@ -1401,7 +1559,6 @@ class JdbcAggregateTemplateIntegrationTests { abstract void setVersion(Number newVersion); } - @Data @Table("VERSIONED_AGGREGATE") static class PersistableVersionedAggregate implements Persistable { @@ -1413,15 +1570,29 @@ class JdbcAggregateTemplateIntegrationTests { public boolean isNew() { return getId() == null; } + + public Long getId() { + return this.id; + } + + public Long getVersion() { + return this.version; + } + + public void setId(Long id) { + this.id = id; + } + + public void setVersion(Long version) { + this.version = version; + } } - @Value - @With @Table("VERSIONED_AGGREGATE") - static class AggregateWithImmutableVersion { + static final class AggregateWithImmutableVersion { - @Id Long id; - @Version Long version; + @Id private final Long id; + @Version private final Long version; private final static List constructorInvocations = new ArrayList<>(); @@ -1435,17 +1606,107 @@ class JdbcAggregateTemplateIntegrationTests { this.id = id; this.version = version; } + + public Long getId() { + return this.id; + } + + public Long getVersion() { + return this.version; + } + + public boolean equals(final Object o) { + if (o == this) + return true; + if (!(o instanceof AggregateWithImmutableVersion)) + return false; + final AggregateWithImmutableVersion other = (AggregateWithImmutableVersion) o; + final Object this$id = this.id; + final Object other$id = other.id; + if (this$id == null ? other$id != null : !this$id.equals(other$id)) + return false; + final Object this$version = this.getVersion(); + final Object other$version = other.getVersion(); + if (this$version == null ? other$version != null : !this$version.equals(other$version)) + return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.id; + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + final Object $version = this.getVersion(); + result = result * PRIME + ($version == null ? 43 : $version.hashCode()); + return result; + } + + public String toString() { + return "JdbcAggregateTemplateIntegrationTests.AggregateWithImmutableVersion(id=" + this.id + ", version=" + + this.getVersion() + ")"; + } + + public AggregateWithImmutableVersion withId(Long id) { + return this.id == id ? this : new AggregateWithImmutableVersion(id, this.version); + } + + public AggregateWithImmutableVersion withVersion(Long version) { + return this.version == version ? this : new AggregateWithImmutableVersion(this.id, version); + } } - @Value - @EqualsAndHashCode - private static class ConstructorInvocation { + private static final class ConstructorInvocation { - Long id; - Long version; + private final Long id; + private final Long version; + + public ConstructorInvocation(Long id, Long version) { + this.id = id; + this.version = version; + } + + public Long getId() { + return this.id; + } + + public Long getVersion() { + return this.version; + } + + public String toString() { + return "JdbcAggregateTemplateIntegrationTests.ConstructorInvocation(id=" + this.id + ", version=" + + this.getVersion() + ")"; + } + + public boolean equals(final Object o) { + if (o == this) + return true; + if (!(o instanceof ConstructorInvocation)) + return false; + final ConstructorInvocation other = (ConstructorInvocation) o; + final Object this$id = this.id; + final Object other$id = other.id; + if (this$id == null ? other$id != null : !this$id.equals(other$id)) + return false; + final Object this$version = this.getVersion(); + final Object other$version = other.getVersion(); + if (this$version == null ? other$version != null : !this$version.equals(other$version)) + return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.id; + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + final Object $version = this.getVersion(); + result = result * PRIME + ($version == null ? 43 : $version.hashCode()); + return result; + } } - @Data @Table("VERSIONED_AGGREGATE") static class AggregateWithLongVersion extends VersionedAggregate { @@ -1455,6 +1716,10 @@ class JdbcAggregateTemplateIntegrationTests { void setVersion(Number newVersion) { this.version = (Long) newVersion; } + + public Long getVersion() { + return this.version; + } } @Table("VERSIONED_AGGREGATE") @@ -1473,7 +1738,6 @@ class JdbcAggregateTemplateIntegrationTests { } } - @Data @Table("VERSIONED_AGGREGATE") static class AggregateWithIntegerVersion extends VersionedAggregate { @@ -1483,6 +1747,10 @@ class JdbcAggregateTemplateIntegrationTests { void setVersion(Number newVersion) { this.version = (Integer) newVersion; } + + public Integer getVersion() { + return this.version; + } } @Table("VERSIONED_AGGREGATE") @@ -1501,7 +1769,6 @@ class JdbcAggregateTemplateIntegrationTests { } } - @Data @Table("VERSIONED_AGGREGATE") static class AggregateWithShortVersion extends VersionedAggregate { @@ -1511,6 +1778,10 @@ class JdbcAggregateTemplateIntegrationTests { void setVersion(Number newVersion) { this.version = (Short) newVersion; } + + public Short getVersion() { + return this.version; + } } @Table("VERSIONED_AGGREGATE") @@ -1544,8 +1815,7 @@ class JdbcAggregateTemplateIntegrationTests { @Table static class WithInsertOnly { @Id Long id; - @InsertOnlyProperty - String insertOnly; + @InsertOnlyProperty String insertOnly; } @Configuration diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateUnitTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateUnitTests.java index 560fc29b..d95c3e0c 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateUnitTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateUnitTests.java @@ -15,15 +15,6 @@ */ package org.springframework.data.jdbc.core; -import static java.util.Arrays.*; -import static java.util.Collections.*; -import static org.assertj.core.api.Assertions.*; -import static org.mockito.Mockito.*; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.RequiredArgsConstructor; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -50,6 +41,11 @@ import org.springframework.data.relational.core.mapping.event.BeforeConvertCallb import org.springframework.data.relational.core.mapping.event.BeforeDeleteCallback; import org.springframework.data.relational.core.mapping.event.BeforeSaveCallback; +import static java.util.Arrays.*; +import static java.util.Collections.*; +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.*; + /** * Unit tests for {@link JdbcAggregateTemplate}. * @@ -63,10 +59,14 @@ public class JdbcAggregateTemplateUnitTests { JdbcAggregateTemplate template; - @Mock DataAccessStrategy dataAccessStrategy; - @Mock ApplicationEventPublisher eventPublisher; - @Mock RelationResolver relationResolver; - @Mock EntityCallbacks callbacks; + @Mock + DataAccessStrategy dataAccessStrategy; + @Mock + ApplicationEventPublisher eventPublisher; + @Mock + RelationResolver relationResolver; + @Mock + EntityCallbacks callbacks; @BeforeEach public void setUp() { @@ -129,7 +129,8 @@ public class JdbcAggregateTemplateUnitTests { verifyNoInteractions(eventPublisher); } - @Test // GH-1137 + @Test + // GH-1137 void savePreparesInstanceWithInitialVersion_onInsert() { EntityWithVersion entity = new EntityWithVersion(1L); @@ -144,7 +145,8 @@ public class JdbcAggregateTemplateUnitTests { assertThat(afterConvert.getVersion()).isEqualTo(0L); } - @Test // GH-1137 + @Test + // GH-1137 void savePreparesInstanceWithInitialVersion_onInsert_whenVersionPropertyIsImmutable() { EntityWithImmutableVersion entity = new EntityWithImmutableVersion(1L, null); @@ -159,7 +161,8 @@ public class JdbcAggregateTemplateUnitTests { assertThat(afterConvert.getVersion()).isEqualTo(0L); } - @Test // GH-1137 + @Test + // GH-1137 void savePreparesInstanceWithInitialVersion_onInsert_whenVersionPropertyIsPrimitiveType() { EntityWithPrimitiveVersion entity = new EntityWithPrimitiveVersion(1L); @@ -174,7 +177,8 @@ public class JdbcAggregateTemplateUnitTests { assertThat(afterConvert.getVersion()).isEqualTo(1L); } - @Test // GH-1137 + @Test + // GH-1137 void savePreparesInstanceWithInitialVersion_onInsert__whenVersionPropertyIsImmutableAndPrimitiveType() { EntityWithImmutablePrimitiveVersion entity = new EntityWithImmutablePrimitiveVersion(1L, 0L); @@ -190,7 +194,8 @@ public class JdbcAggregateTemplateUnitTests { assertThat(afterConvert.getVersion()).isEqualTo(1L); } - @Test // GH-1137 + @Test + // GH-1137 void savePreparesChangeWithPreviousVersion_onUpdate() { when(dataAccessStrategy.updateWithVersion(any(), any(), any())).thenReturn(true); @@ -207,7 +212,8 @@ public class JdbcAggregateTemplateUnitTests { assertThat(aggregateChange.getPreviousVersion()).isEqualTo(1L); } - @Test // GH-1137 + @Test + // GH-1137 void savePreparesInstanceWithNextVersion_onUpdate() { when(dataAccessStrategy.updateWithVersion(any(), any(), any())).thenReturn(true); @@ -224,7 +230,8 @@ public class JdbcAggregateTemplateUnitTests { assertThat(afterConvert.getVersion()).isEqualTo(2L); } - @Test // GH-1137 + @Test + // GH-1137 void savePreparesInstanceWithNextVersion_onUpdate_whenVersionPropertyIsImmutable() { when(dataAccessStrategy.updateWithVersion(any(), any(), any())).thenReturn(true); @@ -239,7 +246,8 @@ public class JdbcAggregateTemplateUnitTests { assertThat(afterConvert.getVersion()).isEqualTo(2L); } - @Test // GH-1137 + @Test + // GH-1137 void deletePreparesChangeWithPreviousVersion_onDeleteByInstance() { EntityWithImmutableVersion entity = new EntityWithImmutableVersion(1L, 1L); @@ -337,48 +345,131 @@ public class JdbcAggregateTemplateUnitTests { template.deleteAllById(emptyList(), SampleEntity.class); } - @Data - @AllArgsConstructor private static class SampleEntity { - @Column("id1") @Id private Long id; + @Column("id1") + @Id + private Long id; private String name; + + public SampleEntity(Long id, String name) { + this.id = id; + this.name = name; + } + + public Long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public void setId(Long id) { + this.id = id; + } + + public void setName(String name) { + this.name = name; + } } - @Data - @RequiredArgsConstructor private static class EntityWithVersion { - @Column("id1") @Id private final Long id; + @Column("id1") + @Id + private final Long id; - @Version private Long version; + @Version + private Long version; + + public EntityWithVersion(Long id) { + this.id = id; + } + + public Long getId() { + return this.id; + } + + public Long getVersion() { + return this.version; + } + + public void setVersion(Long version) { + this.version = version; + } } - @Data - @RequiredArgsConstructor private static class EntityWithImmutableVersion { - @Column("id1") @Id private final Long id; + @Column("id1") + @Id + private final Long id; - @Version private final Long version; + @Version + private final Long version; + + public EntityWithImmutableVersion(Long id, Long version) { + this.id = id; + this.version = version; + } + + public Long getId() { + return this.id; + } + + public Long getVersion() { + return this.version; + } } - @Data - @RequiredArgsConstructor private static class EntityWithPrimitiveVersion { - @Column("id1") @Id private final Long id; + @Column("id1") + @Id + private final Long id; - @Version private long version; + @Version + private long version; + + public EntityWithPrimitiveVersion(Long id) { + this.id = id; + } + + public Long getId() { + return this.id; + } + + public long getVersion() { + return this.version; + } + + public void setVersion(long version) { + this.version = version; + } } - @Data - @RequiredArgsConstructor private static class EntityWithImmutablePrimitiveVersion { - @Column("id1") @Id private final Long id; + @Column("id1") + @Id + private final Long id; - @Version private final long version; + @Version + private final long version; + + public EntityWithImmutablePrimitiveVersion(Long id, long version) { + this.id = id; + this.version = version; + } + + public Long getId() { + return this.id; + } + + public long getVersion() { + return this.version; + } } } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/PropertyPathTestingUtils.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/PropertyPathTestingUtils.java index 8670a672..5d0f7d7f 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/PropertyPathTestingUtils.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/PropertyPathTestingUtils.java @@ -16,8 +16,6 @@ package org.springframework.data.jdbc.core; * limitations under the License. */ -import lombok.experimental.UtilityClass; - import org.springframework.data.mapping.PersistentPropertyPath; import org.springframework.data.mapping.PersistentPropertyPaths; import org.springframework.data.relational.core.mapping.RelationalMappingContext; @@ -28,8 +26,11 @@ import org.springframework.data.relational.core.mapping.RelationalPersistentProp * * @author Jens Schauder */ -@UtilityClass -public class PropertyPathTestingUtils { +public final class PropertyPathTestingUtils { + + private PropertyPathTestingUtils() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } public static PersistentPropertyPath toPath(String path, Class source, RelationalMappingContext context) { diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/BasicJdbcConverterUnitTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/BasicJdbcConverterUnitTests.java index 98e87fa6..4dc22631 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/BasicJdbcConverterUnitTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/BasicJdbcConverterUnitTests.java @@ -19,8 +19,6 @@ import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.SoftAssertions.*; import static org.mockito.Mockito.*; -import lombok.Data; - import java.sql.Array; import java.sql.Timestamp; import java.time.Instant; @@ -161,7 +159,6 @@ public class BasicJdbcConverterUnitTests { softly.assertThat(converter.getColumnType(property)).describedAs(propertyName).isEqualTo(expected); } - @Data @SuppressWarnings("unused") private static class DummyEntity { @@ -184,6 +181,91 @@ public class BasicJdbcConverterUnitTests { private final List listOfEntity; private final OtherEntity[] arrayOfEntity; + private DummyEntity(Long id, SomeEnum someEnum, LocalDateTime localDateTime, LocalDate localDate, + LocalTime localTime, ZonedDateTime zonedDateTime, OffsetDateTime offsetDateTime, Instant instant, Date date, + Timestamp timestamp, AggregateReference reference, UUID uuid, List listOfString, + String[] arrayOfString, List listOfEntity, OtherEntity[] arrayOfEntity) { + this.id = id; + this.someEnum = someEnum; + this.localDateTime = localDateTime; + this.localDate = localDate; + this.localTime = localTime; + this.zonedDateTime = zonedDateTime; + this.offsetDateTime = offsetDateTime; + this.instant = instant; + this.date = date; + this.timestamp = timestamp; + this.reference = reference; + this.uuid = uuid; + this.listOfString = listOfString; + this.arrayOfString = arrayOfString; + this.listOfEntity = listOfEntity; + this.arrayOfEntity = arrayOfEntity; + } + + public Long getId() { + return this.id; + } + + public SomeEnum getSomeEnum() { + return this.someEnum; + } + + public LocalDateTime getLocalDateTime() { + return this.localDateTime; + } + + public LocalDate getLocalDate() { + return this.localDate; + } + + public LocalTime getLocalTime() { + return this.localTime; + } + + public ZonedDateTime getZonedDateTime() { + return this.zonedDateTime; + } + + public OffsetDateTime getOffsetDateTime() { + return this.offsetDateTime; + } + + public Instant getInstant() { + return this.instant; + } + + public Date getDate() { + return this.date; + } + + public Timestamp getTimestamp() { + return this.timestamp; + } + + public AggregateReference getReference() { + return this.reference; + } + + public UUID getUuid() { + return this.uuid; + } + + public List getListOfString() { + return this.listOfString; + } + + public String[] getArrayOfString() { + return this.arrayOfString; + } + + public List getListOfEntity() { + return this.listOfEntity; + } + + public OtherEntity[] getArrayOfEntity() { + return this.arrayOfEntity; + } } @SuppressWarnings("unused") diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategyUnitTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategyUnitTests.java index f578e252..ddbd1922 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategyUnitTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategyUnitTests.java @@ -19,8 +19,6 @@ import static java.util.Collections.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; -import lombok.RequiredArgsConstructor; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.data.annotation.Id; @@ -114,15 +112,21 @@ class DefaultDataAccessStrategyUnitTests { verify(insertStrategyFactory).batchInsertStrategy(IdValueSource.GENERATED, null); } - @RequiredArgsConstructor private static class DummyEntity { @Id private final Long id; + + public DummyEntity(Long id) { + this.id = id; + } } - @RequiredArgsConstructor private static class DummyEntityWithoutIdAnnotation { private final Long id; + + public DummyEntityWithoutIdAnnotation(Long id) { + this.id = id; + } } } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/EntityRowMapperUnitTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/EntityRowMapperUnitTests.java index 89056653..c2cba6c5 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/EntityRowMapperUnitTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/EntityRowMapperUnitTests.java @@ -15,35 +15,6 @@ */ package org.springframework.data.jdbc.core.convert; -import static java.util.Arrays.*; -import static java.util.Collections.*; -import static org.assertj.core.api.Assertions.*; -import static org.assertj.core.api.SoftAssertions.*; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.*; - -import lombok.AllArgsConstructor; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.RequiredArgsConstructor; -import lombok.Value; -import lombok.With; - -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import javax.naming.OperationNotSupportedException; - import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; import org.mockito.invocation.InvocationOnMock; @@ -66,6 +37,26 @@ import org.springframework.data.repository.query.Param; import org.springframework.util.Assert; import org.springframework.util.LinkedCaseInsensitiveMap; +import javax.naming.OperationNotSupportedException; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static java.util.Arrays.*; +import static java.util.Collections.*; +import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.SoftAssertions.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; + /** * Tests the extraction of entities from a {@link ResultSet} by the {@link EntityRowMapper}. * @@ -82,12 +73,7 @@ public class EntityRowMapperUnitTests { static final long ID_FOR_ENTITY_REFERENCING_MAP = 42L; static final long ID_FOR_ENTITY_REFERENCING_LIST = 4711L; static final long ID_FOR_ENTITY_NOT_REFERENCING_MAP = 23L; - static final NamingStrategy X_APPENDING_NAMINGSTRATEGY = new NamingStrategy() { - @Override - public String getColumnName(RelationalPersistentProperty property) { - return NamingStrategy.super.getColumnName(property).concat("x"); - } - }; + static final NamingStrategy X_APPENDING_NAMINGSTRATEGY=new NamingStrategy(){@Override public String getColumnName(RelationalPersistentProperty property){return NamingStrategy.super.getColumnName(property).concat("x");}}; @Test // DATAJDBC-113 void simpleEntitiesGetProperlyExtracted() throws SQLException { @@ -647,55 +633,235 @@ public class EntityRowMapperUnitTests { // Model classes to be used in tests - @With - @RequiredArgsConstructor static class TrivialImmutable { - @Id private final Long id; + @Id + private final Long id; private final String name; + + public TrivialImmutable(Long id, String name) { + this.id = id; + this.name = name; + } + + public TrivialImmutable withId(Long id) { + return this.id == id ? this : new TrivialImmutable(id, this.name); + } + + public TrivialImmutable withName(String name) { + return this.name == name ? this : new TrivialImmutable(this.id, name); + } } - @EqualsAndHashCode - @NoArgsConstructor - @AllArgsConstructor - @Getter static class Trivial { - @Id Long id; + @Id + Long id; String name; + + public Trivial(Long id, String name) { + this.id = id; + this.name = name; + } + + public Trivial() { + } + + public Long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof Trivial)) return false; + final Trivial other = (Trivial) o; + if (!other.canEqual((Object) this)) return false; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false; + final Object this$name = this.getName(); + final Object other$name = other.getName(); + if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false; + return true; + } + + protected boolean canEqual(final Object other) { + return other instanceof Trivial; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.getId(); + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + final Object $name = this.getName(); + result = result * PRIME + ($name == null ? 43 : $name.hashCode()); + return result; + } } - @EqualsAndHashCode - @NoArgsConstructor - @AllArgsConstructor - @Getter static class TrivialMapPropertiesToNullIfNotNeeded { - @Id Long id; + @Id + Long id; int age; String phone; Boolean isSupreme; long referenceToCustomer; + + public TrivialMapPropertiesToNullIfNotNeeded(Long id, int age, String phone, Boolean isSupreme, long referenceToCustomer) { + this.id = id; + this.age = age; + this.phone = phone; + this.isSupreme = isSupreme; + this.referenceToCustomer = referenceToCustomer; + } + + public TrivialMapPropertiesToNullIfNotNeeded() { + } + + public Long getId() { + return this.id; + } + + public int getAge() { + return this.age; + } + + public String getPhone() { + return this.phone; + } + + public Boolean getIsSupreme() { + return this.isSupreme; + } + + public long getReferenceToCustomer() { + return this.referenceToCustomer; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof TrivialMapPropertiesToNullIfNotNeeded)) return false; + final TrivialMapPropertiesToNullIfNotNeeded other = (TrivialMapPropertiesToNullIfNotNeeded) o; + if (!other.canEqual((Object) this)) return false; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false; + if (this.getAge() != other.getAge()) return false; + final Object this$phone = this.getPhone(); + final Object other$phone = other.getPhone(); + if (this$phone == null ? other$phone != null : !this$phone.equals(other$phone)) return false; + final Object this$isSupreme = this.getIsSupreme(); + final Object other$isSupreme = other.getIsSupreme(); + if (this$isSupreme == null ? other$isSupreme != null : !this$isSupreme.equals(other$isSupreme)) + return false; + if (this.getReferenceToCustomer() != other.getReferenceToCustomer()) return false; + return true; + } + + protected boolean canEqual(final Object other) { + return other instanceof TrivialMapPropertiesToNullIfNotNeeded; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.getId(); + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + result = result * PRIME + this.getAge(); + final Object $phone = this.getPhone(); + result = result * PRIME + ($phone == null ? 43 : $phone.hashCode()); + final Object $isSupreme = this.getIsSupreme(); + result = result * PRIME + ($isSupreme == null ? 43 : $isSupreme.hashCode()); + final long $referenceToCustomer = this.getReferenceToCustomer(); + result = result * PRIME + (int) ($referenceToCustomer >>> 32 ^ $referenceToCustomer); + return result; + } } - @EqualsAndHashCode - @NoArgsConstructor - @AllArgsConstructor - @Getter static class WithReference { - @Id Long id; + @Id + Long id; String name; AggregateReference trivialId; + + public WithReference(Long id, String name, AggregateReference trivialId) { + this.id = id; + this.name = name; + this.trivialId = trivialId; + } + + public WithReference() { + } + + public Long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public AggregateReference getTrivialId() { + return this.trivialId; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof WithReference)) return false; + final WithReference other = (WithReference) o; + if (!other.canEqual((Object) this)) return false; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false; + final Object this$name = this.getName(); + final Object other$name = other.getName(); + if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false; + final Object this$trivialId = this.getTrivialId(); + final Object other$trivialId = other.getTrivialId(); + if (this$trivialId == null ? other$trivialId != null : !this$trivialId.equals(other$trivialId)) + return false; + return true; + } + + protected boolean canEqual(final Object other) { + return other instanceof WithReference; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.getId(); + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + final Object $name = this.getName(); + result = result * PRIME + ($name == null ? 43 : $name.hashCode()); + final Object $trivialId = this.getTrivialId(); + result = result * PRIME + ($trivialId == null ? 43 : $trivialId.hashCode()); + return result; + } } - @With - @RequiredArgsConstructor - static class WithReferenceImmutable { + record WithReferenceImmutable( + @Id Long id, String name, + AggregateReference trivialId){ - @Id private final Long id; - private final String name; - private final AggregateReference trivialId; + public WithReferenceImmutable withId(Long id) { + return this.id == id ? this : new WithReferenceImmutable(id, this.name, this.trivialId); + } + + public WithReferenceImmutable withName(String name) { + return this.name == name ? this : new WithReferenceImmutable(this.id, name, this.trivialId); + } + + public WithReferenceImmutable withTrivialId(AggregateReference trivialId) { + return this.trivialId == trivialId ? this : new WithReferenceImmutable(this.id, this.name, trivialId); + } } static class OneToOne { @@ -705,13 +871,25 @@ public class EntityRowMapperUnitTests { Trivial child; } - @With - @RequiredArgsConstructor - static class OneToOneImmutable { + record OneToOneImmutable( - private final @Id Long id; - private final String name; - private final TrivialImmutable child; + @Id Long id, String name, TrivialImmutable child) { + + OneToOneImmutable() { + this(null, null, null); + } + + public OneToOneImmutable withId(Long id) { + return this.id == id ? this : new OneToOneImmutable(id, name, child); + } + + public OneToOneImmutable withName(String name) { + return this.name == name ? this : new OneToOneImmutable(id, name, child); + } + + public OneToOneImmutable withChild(TrivialImmutable child) { + return this.child == child ? this : new OneToOneImmutable(id, name, child); + } } static class OneToSet { @@ -817,15 +995,10 @@ public class EntityRowMapperUnitTests { @Embedded.Nullable ImmutablePrimitiveValue embeddedImmutablePrimitiveValue; } - @Value - static class ImmutableValue { - Object value; - String name; + record ImmutableValue(Object value, String name) { } - @Value - static class ImmutablePrimitiveValue { - int value; + record ImmutablePrimitiveValue(int value) { } static class WithDeepNestedEmbeddable { @@ -1190,12 +1363,16 @@ public class EntityRowMapperUnitTests { } } - @AllArgsConstructor private static class Fixture { final ResultSet resultSet; final List> expectations; + public Fixture(ResultSet resultSet, List> expectations) { + this.resultSet = resultSet; + this.expectations = expectations; + } + public void assertOn(T result) { assertSoftly(softly -> { @@ -1209,15 +1386,19 @@ public class EntityRowMapperUnitTests { } } - @AllArgsConstructor private static class Expectation { final Function extractor; final Object expectedValue; final String sourceColumn; + + public Expectation(Function extractor, Object expectedValue, String sourceColumn) { + this.extractor = extractor; + this.expectedValue = expectedValue; + this.sourceColumn = sourceColumn; + } } - @Getter private static class WithAtValue { @Id private final Long id; @@ -1228,5 +1409,13 @@ public class EntityRowMapperUnitTests { this.id = id; this.computed = computed; } + + public Long getId() { + return this.id; + } + + public String getComputed() { + return this.computed; + } } } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlParametersFactoryTest.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlParametersFactoryTest.java index d3843c76..a54383b3 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlParametersFactoryTest.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlParametersFactoryTest.java @@ -21,11 +21,6 @@ import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.*; import static org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategyUnitTests.*; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.RequiredArgsConstructor; -import lombok.Value; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -91,7 +86,8 @@ class SqlParametersFactoryTest { assertThat(sqlParameterSource.getValue("DUMMYENTITYROOT")).isEqualTo(rawId); } - @Test // DATAJDBC-146 + @Test + // DATAJDBC-146 void identifiersGetAddedAsParameters() { long id = 4711L; @@ -105,7 +101,8 @@ class SqlParametersFactoryTest { assertThat(sqlParameterSource.getValue("reference")).isEqualTo(reference); } - @Test // DATAJDBC-146 + @Test + // DATAJDBC-146 void additionalIdentifierForIdDoesNotLeadToDuplicateParameters() { long id = 4711L; @@ -117,7 +114,8 @@ class SqlParametersFactoryTest { assertThat(sqlParameterSource.getValue("id")).isEqualTo(id); } - @Test // DATAJDBC-235 + @Test + // DATAJDBC-235 void considersConfiguredWriteConverter() { SqlParametersFactory sqlParametersFactory = createSqlParametersFactoryWithConverters( @@ -131,7 +129,8 @@ class SqlParametersFactoryTest { assertThat(sqlParameterSource.getValue("flag")).isEqualTo("T"); } - @Test // DATAJDBC-412 + @Test + // DATAJDBC-412 void considersConfiguredWriteConverterForIdValueObjects_onWrite() { SqlParametersFactory sqlParametersFactory = createSqlParametersFactoryWithConverters( @@ -148,7 +147,8 @@ class SqlParametersFactoryTest { assertThat(sqlParameterSource.getValue("value")).isEqualTo(value); } - @Test // GH-1405 + @Test + // GH-1405 void parameterNamesGetSanitized() { WithIllegalCharacters entity = new WithIllegalCharacters(23L, "aValue"); @@ -174,16 +174,63 @@ class SqlParametersFactoryTest { } } - @Data private static class WithValueObjectId { @Id private final IdValue id; String value; + + private WithValueObjectId(IdValue id) { + this.id = id; + } + + public IdValue getId() { + return this.id; + } + + public String getValue() { + return this.value; + } + + public void setValue(String value) { + this.value = value; + } } - @Value - private static class IdValue { - String id; + private static final class IdValue { + private final String id; + + public IdValue(String id) { + this.id = id; + } + + public String getId() { + return this.id; + } + + public boolean equals(final Object o) { + if (o == this) + return true; + if (!(o instanceof IdValue)) + return false; + final IdValue other = (IdValue) o; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) + return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.getId(); + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + return result; + } + + public String toString() { + return "SqlParametersFactoryTest.IdValue(id=" + this.getId() + ")"; + } } @WritingConverter @@ -208,33 +255,48 @@ class SqlParametersFactoryTest { } } - @AllArgsConstructor private static class EntityWithBoolean { @Id Long id; boolean flag; + + public EntityWithBoolean(Long id, boolean flag) { + this.id = id; + this.flag = flag; + } } - @RequiredArgsConstructor // DATAJDBC-349 + // DATAJDBC-349 private static class DummyEntityRoot { @Id private final IdValue id; List dummyEntities = new ArrayList<>(); + + public DummyEntityRoot(IdValue id) { + this.id = id; + } } - @RequiredArgsConstructor private static class DummyEntity { @Id private final Long id; + + public DummyEntity(Long id) { + this.id = id; + } } - @AllArgsConstructor private static class WithIllegalCharacters { @Column("i.d") @Id Long id; @Column("val&ue") String value; + + public WithIllegalCharacters(Long id, String value) { + this.id = id; + this.value = value; + } } private SqlParametersFactory createSqlParametersFactoryWithConverters(List converters) { diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/dialect/PostgresDialectIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/dialect/PostgresDialectIntegrationTests.java index 8bd253d6..969a73f9 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/dialect/PostgresDialectIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/dialect/PostgresDialectIntegrationTests.java @@ -2,11 +2,6 @@ package org.springframework.data.jdbc.core.dialect; import static org.assertj.core.api.Assertions.*; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.Value; - import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; @@ -17,7 +12,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfSystemProperty; import org.junit.jupiter.api.extension.ExtendWith; import org.postgresql.util.PGobject; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -133,21 +127,98 @@ public class PostgresDialectIntegrationTests { } } - @Value @Table("customers") - public static class Customer { + public static final class Customer { - @Id Long id; - String name; - JsonHolder personData; - PGobject sessionData; + @Id private final Long id; + private final String name; + private final JsonHolder personData; + private final PGobject sessionData; + + public Customer(Long id, String name, JsonHolder personData, PGobject sessionData) { + this.id = id; + this.name = name; + this.personData = personData; + this.sessionData = sessionData; + } + + public Long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public JsonHolder getPersonData() { + return this.personData; + } + + public PGobject getSessionData() { + return this.sessionData; + } + + public boolean equals(final Object o) { + if (o == this) + return true; + if (!(o instanceof Customer)) + return false; + final Customer other = (Customer) o; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) + return false; + final Object this$name = this.getName(); + final Object other$name = other.getName(); + if (this$name == null ? other$name != null : !this$name.equals(other$name)) + return false; + final Object this$personData = this.getPersonData(); + final Object other$personData = other.getPersonData(); + if (this$personData == null ? other$personData != null : !this$personData.equals(other$personData)) + return false; + final Object this$sessionData = this.getSessionData(); + final Object other$sessionData = other.getSessionData(); + if (this$sessionData == null ? other$sessionData != null : !this$sessionData.equals(other$sessionData)) + return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.getId(); + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + final Object $name = this.getName(); + result = result * PRIME + ($name == null ? 43 : $name.hashCode()); + final Object $personData = this.getPersonData(); + result = result * PRIME + ($personData == null ? 43 : $personData.hashCode()); + final Object $sessionData = this.getSessionData(); + result = result * PRIME + ($sessionData == null ? 43 : $sessionData.hashCode()); + return result; + } + + public String toString() { + return "PostgresDialectIntegrationTests.Customer(id=" + this.getId() + ", name=" + this.getName() + + ", personData=" + this.getPersonData() + ", sessionData=" + this.getSessionData() + ")"; + } } - @Data - @NoArgsConstructor - @AllArgsConstructor public static class JsonHolder { String content; + + public JsonHolder(String content) { + this.content = content; + } + + public JsonHolder() {} + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } } interface CustomerRepository extends CrudRepository {} diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/mapping/BasicJdbcPersistentPropertyUnitTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/mapping/BasicJdbcPersistentPropertyUnitTests.java index 499d9da0..d2afb165 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/mapping/BasicJdbcPersistentPropertyUnitTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/mapping/BasicJdbcPersistentPropertyUnitTests.java @@ -15,19 +15,7 @@ */ package org.springframework.data.jdbc.core.mapping; -import static org.assertj.core.api.Assertions.*; -import static org.assertj.core.api.SoftAssertions.*; -import static org.springframework.data.relational.core.sql.SqlIdentifier.*; - import junit.framework.AssertionFailedError; -import lombok.Data; - -import java.time.LocalDateTime; -import java.time.ZonedDateTime; -import java.util.Date; -import java.util.List; -import java.util.UUID; - import org.junit.jupiter.api.Test; import org.springframework.data.annotation.Id; import org.springframework.data.mapping.PersistentPropertyPath; @@ -39,6 +27,16 @@ import org.springframework.data.relational.core.mapping.RelationalMappingContext import org.springframework.data.relational.core.mapping.RelationalPersistentEntity; import org.springframework.data.relational.core.mapping.RelationalPersistentProperty; +import java.time.LocalDateTime; +import java.time.ZonedDateTime; +import java.util.Date; +import java.util.List; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.SoftAssertions.*; +import static org.springframework.data.relational.core.sql.SqlIdentifier.*; + /** * Unit tests for the {@link BasicRelationalPersistentProperty}. * @@ -141,11 +139,11 @@ public class BasicJdbcPersistentPropertyUnitTests { ALPHA } - @Data @SuppressWarnings("unused") private static class DummyEntity { - @Id private final Long id; + @Id + private final Long id; private final SomeEnum someEnum; private final LocalDateTime localDateTime; private final ZonedDateTime zonedDateTime; @@ -154,11 +152,22 @@ public class BasicJdbcPersistentPropertyUnitTests { private final UUID uuid; @MappedCollection(idColumn = "dummy_column_name", - keyColumn = "dummy_key_column_name") private List someList; + keyColumn = "dummy_key_column_name") + private List someList; // DATACMNS-106 private @Column("dummy_name") String name; + private DummyEntity(Long id, SomeEnum someEnum, LocalDateTime localDateTime, ZonedDateTime zonedDateTime, AggregateReference reference, List listField, UUID uuid) { + this.id = id; + this.someEnum = someEnum; + this.localDateTime = localDateTime; + this.zonedDateTime = zonedDateTime; + this.reference = reference; + this.listField = listField; + this.uuid = uuid; + } + @Column("dummy_last_updated_at") public LocalDateTime getLocalDateTime() { return localDateTime; @@ -171,15 +180,71 @@ public class BasicJdbcPersistentPropertyUnitTests { public List getListGetter() { return null; } + + public Long getId() { + return this.id; + } + + public SomeEnum getSomeEnum() { + return this.someEnum; + } + + public ZonedDateTime getZonedDateTime() { + return this.zonedDateTime; + } + + public AggregateReference getReference() { + return this.reference; + } + + public List getListField() { + return this.listField; + } + + public UUID getUuid() { + return this.uuid; + } + + public List getSomeList() { + return this.someList; + } + + public String getName() { + return this.name; + } + + public void setSomeList(List someList) { + this.someList = someList; + } + + public void setName(String name) { + this.name = name; + } } - @Data private static class WithCollections { - @Column(value = "some_value") List someList; + @Column(value = "some_value") + List someList; @Column(value = "some_value") // @MappedCollection(idColumn = "override_id", keyColumn = "override_key") // List overrideList; + + public List getSomeList() { + return this.someList; + } + + public List getOverrideList() { + return this.overrideList; + } + + public void setSomeList(List someList) { + this.someList = someList; + } + + public void setOverrideList(List overrideList) { + this.overrideList = overrideList; + } } } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/mapping/PersistentPropertyPathTestUtils.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/mapping/PersistentPropertyPathTestUtils.java index ebcf54a9..3ebad2fa 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/mapping/PersistentPropertyPathTestUtils.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/mapping/PersistentPropertyPathTestUtils.java @@ -15,8 +15,6 @@ */ package org.springframework.data.jdbc.core.mapping; -import lombok.experimental.UtilityClass; - import org.springframework.data.mapping.PersistentPropertyPath; import org.springframework.data.relational.core.mapping.RelationalMappingContext; import org.springframework.data.relational.core.mapping.RelationalPersistentProperty; @@ -24,11 +22,14 @@ import org.springframework.data.relational.core.mapping.RelationalPersistentProp /** * @author Jens Schauder */ -@UtilityClass -public class PersistentPropertyPathTestUtils { +public final class PersistentPropertyPathTestUtils { + + private PersistentPropertyPathTestUtils() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } public static PersistentPropertyPath getPath(RelationalMappingContext context, - String path, Class baseType) { + String path, Class baseType) { return context.findPersistentPropertyPaths(baseType, p -> p.isEntity()) // .filter(p -> p.toDotPath().equals(path)) // diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/mapping/model/DefaultNamingStrategyUnitTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/mapping/model/DefaultNamingStrategyUnitTests.java index f3cd1717..f0516915 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/mapping/model/DefaultNamingStrategyUnitTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/mapping/model/DefaultNamingStrategyUnitTests.java @@ -15,21 +15,18 @@ */ package org.springframework.data.jdbc.mapping.model; -import static org.assertj.core.api.Assertions.*; - -import lombok.Data; - -import java.time.LocalDateTime; -import java.util.List; - import org.junit.jupiter.api.Test; - import org.springframework.data.annotation.Id; import org.springframework.data.jdbc.core.mapping.JdbcMappingContext; import org.springframework.data.relational.core.mapping.DefaultNamingStrategy; import org.springframework.data.relational.core.mapping.NamingStrategy; import org.springframework.data.relational.core.mapping.RelationalPersistentEntity; +import java.time.LocalDateTime; +import java.util.List; + +import static org.assertj.core.api.Assertions.*; + /** * Unit tests for the default {@link NamingStrategy}. * @@ -78,19 +75,59 @@ public class DefaultNamingStrategyUnitTests { assertThat(target.getSchema()).isEqualTo(""); } - @Data private static class DummyEntity { - @Id private int id; + @Id + private int id; private LocalDateTime createdAt; private List dummySubEntities; + + public int getId() { + return this.id; + } + + public LocalDateTime getCreatedAt() { + return this.createdAt; + } + + public List getDummySubEntities() { + return this.dummySubEntities; + } + + public void setId(int id) { + this.id = id; + } + + public void setCreatedAt(LocalDateTime createdAt) { + this.createdAt = createdAt; + } + + public void setDummySubEntities(List dummySubEntities) { + this.dummySubEntities = dummySubEntities; + } } - @Data private static class DummySubEntity { - @Id private int id; + @Id + private int id; private LocalDateTime createdAt; + + public int getId() { + return this.id; + } + + public LocalDateTime getCreatedAt() { + return this.createdAt; + } + + public void setId(int id) { + this.id = id; + } + + public void setCreatedAt(LocalDateTime createdAt) { + this.createdAt = createdAt; + } } } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/mybatis/DummyEntity.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/mybatis/DummyEntity.java index 1d140912..089b74cb 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/mybatis/DummyEntity.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/mybatis/DummyEntity.java @@ -15,8 +15,6 @@ */ package org.springframework.data.jdbc.mybatis; -import lombok.With; - import org.apache.ibatis.type.Alias; import org.springframework.data.annotation.Id; @@ -26,11 +24,16 @@ import org.springframework.data.annotation.Id; @Alias("DummyEntity") class DummyEntity { - @With @Id final Long id; + @Id + final Long id; final String name; public DummyEntity(Long id, String name) { this.id = id; this.name = name; } + + public DummyEntity withId(Long id) { + return this.id == id ? this : new DummyEntity(id, this.name); + } } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryBeforeSaveHsqlIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryBeforeSaveHsqlIntegrationTests.java index 9ca36dd8..1aaa2f01 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryBeforeSaveHsqlIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryBeforeSaveHsqlIntegrationTests.java @@ -15,15 +15,6 @@ */ package org.springframework.data.jdbc.repository; -import static org.assertj.core.api.Assertions.*; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.Value; -import lombok.With; - -import java.util.List; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; @@ -43,6 +34,10 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; +import java.util.List; + +import static org.assertj.core.api.Assertions.*; + /** * Integration tests for the {@link BeforeSaveCallback}. * @@ -57,7 +52,8 @@ public class JdbcRepositoryBeforeSaveHsqlIntegrationTests { @Import(TestConfiguration.class) static class Config { - @Autowired JdbcRepositoryFactory factory; + @Autowired + JdbcRepositoryFactory factory; @Bean Class testClass() { @@ -65,11 +61,16 @@ public class JdbcRepositoryBeforeSaveHsqlIntegrationTests { } } - @Autowired NamedParameterJdbcTemplate template; - @Autowired ImmutableEntityRepository immutableWithManualIdEntityRepository; - @Autowired MutableEntityRepository mutableEntityRepository; - @Autowired MutableWithImmutableIdEntityRepository mutableWithImmutableIdEntityRepository; - @Autowired ImmutableWithMutableIdEntityRepository immutableWithMutableIdEntityRepository; + @Autowired + NamedParameterJdbcTemplate template; + @Autowired + ImmutableEntityRepository immutableWithManualIdEntityRepository; + @Autowired + MutableEntityRepository mutableEntityRepository; + @Autowired + MutableWithImmutableIdEntityRepository mutableWithImmutableIdEntityRepository; + @Autowired + ImmutableWithMutableIdEntityRepository immutableWithMutableIdEntityRepository; @Test // GH-1199 public void immutableEntity() { @@ -135,42 +136,150 @@ public class JdbcRepositoryBeforeSaveHsqlIntegrationTests { assertThat(reloaded.getName()).isEqualTo("fromBeforeSaveCallback"); } - private interface ImmutableEntityRepository extends ListCrudRepository {} - - @Value - @With - static class ImmutableEntity { - @Id Long id; - String name; + private interface ImmutableEntityRepository extends ListCrudRepository { } - private interface MutableEntityRepository extends ListCrudRepository {} + static final class ImmutableEntity { + @Id + private final + Long id; + private final String name; + + public ImmutableEntity(Long id, String name) { + this.id = id; + this.name = name; + } + + public Long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof ImmutableEntity)) return false; + final ImmutableEntity other = (ImmutableEntity) o; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false; + final Object this$name = this.getName(); + final Object other$name = other.getName(); + if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.getId(); + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + final Object $name = this.getName(); + result = result * PRIME + ($name == null ? 43 : $name.hashCode()); + return result; + } + + public String toString() { + return "JdbcRepositoryBeforeSaveHsqlIntegrationTests.ImmutableEntity(id=" + this.getId() + ", name=" + this.getName() + ")"; + } + + public ImmutableEntity withId(Long id) { + return this.id == id ? this : new ImmutableEntity(id, this.name); + } + + public ImmutableEntity withName(String name) { + return this.name == name ? this : new ImmutableEntity(this.id, name); + } + } + + private interface MutableEntityRepository extends ListCrudRepository { + } - @Data - @AllArgsConstructor static class MutableEntity { - @Id private Long id; + @Id + private Long id; private String name; + + public MutableEntity(Long id, String name) { + this.id = id; + this.name = name; + } + + public Long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public void setId(Long id) { + this.id = id; + } + + public void setName(String name) { + this.name = name; + } } private interface MutableWithImmutableIdEntityRepository - extends ListCrudRepository {} + extends ListCrudRepository { + } - @Data - @AllArgsConstructor static class MutableWithImmutableIdEntity { - @Id private final Long id; + @Id + private final Long id; private String name; + + public MutableWithImmutableIdEntity(Long id, String name) { + this.id = id; + this.name = name; + } + + public Long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } } private interface ImmutableWithMutableIdEntityRepository - extends ListCrudRepository {} + extends ListCrudRepository { + } - @Data - @AllArgsConstructor static class ImmutableWithMutableIdEntity { - @Id private Long id; - @With private final String name; + @Id + private Long id; + private final String name; + + public ImmutableWithMutableIdEntity(Long id, String name) { + this.id = id; + this.name = name; + } + + public Long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public void setId(Long id) { + this.id = id; + } + + public ImmutableWithMutableIdEntity withName(String name) { + return this.name == name ? this : new ImmutableWithMutableIdEntity(this.id, name); + } } @Configuration diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryConcurrencyIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryConcurrencyIntegrationTests.java index f4b33f4d..565289c4 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryConcurrencyIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryConcurrencyIntegrationTests.java @@ -15,28 +15,13 @@ */ package org.springframework.data.jdbc.repository; -import static org.assertj.core.api.Assertions.*; - import junit.framework.AssertionFailedError; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.With; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.StringJoiner; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.CountDownLatch; -import java.util.function.UnaryOperator; - import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.platform.commons.util.ExceptionUtils; -import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -48,10 +33,19 @@ import org.springframework.data.jdbc.testing.TestConfiguration; import org.springframework.data.repository.CrudRepository; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.test.context.junit.jupiter.SpringExtension; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.support.TransactionTemplate; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.StringJoiner; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.CountDownLatch; +import java.util.function.UnaryOperator; + +import static org.assertj.core.api.Assertions.*; + /** * Tests that highly concurrent update operations of an entity don't cause deadlocks. * @@ -65,7 +59,8 @@ public class JdbcRepositoryConcurrencyIntegrationTests { @Import(TestConfiguration.class) static class Config { - @Autowired JdbcRepositoryFactory factory; + @Autowired + JdbcRepositoryFactory factory; @Bean Class testClass() { @@ -78,9 +73,12 @@ public class JdbcRepositoryConcurrencyIntegrationTests { } } - @Autowired NamedParameterJdbcTemplate template; - @Autowired DummyEntityRepository repository; - @Autowired PlatformTransactionManager transactionManager; + @Autowired + NamedParameterJdbcTemplate template; + @Autowired + DummyEntityRepository repository; + @Autowired + PlatformTransactionManager transactionManager; List concurrencyEntities; DummyEntity entity; @@ -155,7 +153,7 @@ public class JdbcRepositoryConcurrencyIntegrationTests { CountDownLatch startLatch = new CountDownLatch(concurrencyEntities.size() + 1); // latch for all threads to wait on. CountDownLatch doneLatch = new CountDownLatch(concurrencyEntities.size() + 1); // latch for main thread to wait on - // until all threads are done. + // until all threads are done. UnaryOperator updateAction = e -> { try { return repository.save(e); @@ -188,7 +186,7 @@ public class JdbcRepositoryConcurrencyIntegrationTests { CountDownLatch startLatch = new CountDownLatch(concurrencyEntities.size() + 1); // latch for all threads to wait on. CountDownLatch doneLatch = new CountDownLatch(concurrencyEntities.size() + 1); // latch for main thread to wait on - // until all threads are done. + // until all threads are done. UnaryOperator updateAction = e -> { try { @@ -218,7 +216,7 @@ public class JdbcRepositoryConcurrencyIntegrationTests { } private void executeInParallel(CountDownLatch startLatch, CountDownLatch doneLatch, - UnaryOperator deleteAction, DummyEntity entity) { + UnaryOperator deleteAction, DummyEntity entity) { // delete new Thread(() -> { try { @@ -255,22 +253,56 @@ public class JdbcRepositoryConcurrencyIntegrationTests { return new DummyEntity(null, "Entity Name", new ArrayList<>()); } - interface DummyEntityRepository extends CrudRepository {} + interface DummyEntityRepository extends CrudRepository { + } - @Getter - @AllArgsConstructor static class DummyEntity { - @Id private Long id; - @With String name; - @With final List content; + @Id + private Long id; + String name; + final List content; + public DummyEntity(Long id, String name, List content) { + this.id = id; + this.name = name; + this.content = content; + } + + public Long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public List getContent() { + return this.content; + } + + public DummyEntity withName(String name) { + return this.name == name ? this : new DummyEntity(this.id, name, this.content); + } + + public DummyEntity withContent(List content) { + return this.content == content ? this : new DummyEntity(this.id, this.name, content); + } } - @AllArgsConstructor static class Element { - @Id private Long id; - @With final Long content; + @Id + private Long id; + final Long content; + + public Element(Long id, Long content) { + this.id = id; + this.content = content; + } + + public Element withContent(Long content) { + return this.content == content ? this : new Element(this.id, content); + } } } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedImmutableIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedImmutableIntegrationTests.java index 140cd6e0..cee893c4 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedImmutableIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedImmutableIntegrationTests.java @@ -15,11 +15,6 @@ */ package org.springframework.data.jdbc.repository; -import static org.assertj.core.api.Assertions.*; - -import lombok.Value; -import lombok.With; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; @@ -37,6 +32,8 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.annotation.Transactional; +import static org.assertj.core.api.Assertions.*; + /** * Very simple use cases for creation and usage of JdbcRepositories with {@link Embedded} annotation in Entities. * @@ -86,20 +83,115 @@ public class JdbcRepositoryEmbeddedImmutableIntegrationTests { interface DummyEntityRepository extends CrudRepository {} - @Value - @With - static class DummyEntity { + static final class DummyEntity { - @Id Long id; + @Id + private final Long id; - @Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "PREFIX_") Embeddable prefixedEmbeddable; + @Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "PREFIX_") + private final Embeddable prefixedEmbeddable; + + public DummyEntity(Long id, Embeddable prefixedEmbeddable) { + this.id = id; + this.prefixedEmbeddable = prefixedEmbeddable; + } + + public Long getId() { + return this.id; + } + + public Embeddable getPrefixedEmbeddable() { + return this.prefixedEmbeddable; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof DummyEntity)) return false; + final DummyEntity other = (DummyEntity) o; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false; + final Object this$prefixedEmbeddable = this.getPrefixedEmbeddable(); + final Object other$prefixedEmbeddable = other.getPrefixedEmbeddable(); + if (this$prefixedEmbeddable == null ? other$prefixedEmbeddable != null : !this$prefixedEmbeddable.equals(other$prefixedEmbeddable)) + return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.getId(); + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + final Object $prefixedEmbeddable = this.getPrefixedEmbeddable(); + result = result * PRIME + ($prefixedEmbeddable == null ? 43 : $prefixedEmbeddable.hashCode()); + return result; + } + + public String toString() { + return "JdbcRepositoryEmbeddedImmutableIntegrationTests.DummyEntity(id=" + this.getId() + ", prefixedEmbeddable=" + this.getPrefixedEmbeddable() + ")"; + } + + public DummyEntity withId(Long id) { + return this.id == id ? this : new DummyEntity(id, this.prefixedEmbeddable); + } + + public DummyEntity withPrefixedEmbeddable(Embeddable prefixedEmbeddable) { + return this.prefixedEmbeddable == prefixedEmbeddable ? this : new DummyEntity(this.id, prefixedEmbeddable); + } } - @Value - @With - private static class Embeddable { + private static final class Embeddable { - Long attr1; - String attr2; + private final Long attr1; + private final String attr2; + + public Embeddable(Long attr1, String attr2) { + this.attr1 = attr1; + this.attr2 = attr2; + } + + public Long getAttr1() { + return this.attr1; + } + + public String getAttr2() { + return this.attr2; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof Embeddable)) return false; + final Embeddable other = (Embeddable) o; + final Object this$attr1 = this.getAttr1(); + final Object other$attr1 = other.getAttr1(); + if (this$attr1 == null ? other$attr1 != null : !this$attr1.equals(other$attr1)) return false; + final Object this$attr2 = this.getAttr2(); + final Object other$attr2 = other.getAttr2(); + if (this$attr2 == null ? other$attr2 != null : !this$attr2.equals(other$attr2)) return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $attr1 = this.getAttr1(); + result = result * PRIME + ($attr1 == null ? 43 : $attr1.hashCode()); + final Object $attr2 = this.getAttr2(); + result = result * PRIME + ($attr2 == null ? 43 : $attr2.hashCode()); + return result; + } + + public String toString() { + return "JdbcRepositoryEmbeddedImmutableIntegrationTests.Embeddable(attr1=" + this.getAttr1() + ", attr2=" + this.getAttr2() + ")"; + } + + public Embeddable withAttr1(Long attr1) { + return this.attr1 == attr1 ? this : new Embeddable(attr1, this.attr2); + } + + public Embeddable withAttr2(String attr2) { + return this.attr2 == attr2 ? this : new Embeddable(this.attr1, attr2); + } } } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedIntegrationTests.java index 957b4c16..cd4bd3be 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedIntegrationTests.java @@ -18,12 +18,9 @@ package org.springframework.data.jdbc.repository; import static java.util.Arrays.*; import static org.assertj.core.api.Assertions.*; -import lombok.AllArgsConstructor; -import lombok.Data; +import java.util.List; -import lombok.NoArgsConstructor; import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; @@ -33,9 +30,7 @@ import org.springframework.context.annotation.Import; import org.springframework.data.annotation.Id; import org.springframework.data.domain.Sort; import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory; -import org.springframework.data.jdbc.testing.EnabledOnFeature; import org.springframework.data.jdbc.testing.TestConfiguration; -import org.springframework.data.jdbc.testing.TestDatabaseFeatures; import org.springframework.data.relational.core.mapping.Column; import org.springframework.data.relational.core.mapping.Embedded; import org.springframework.data.relational.core.mapping.Embedded.OnEmpty; @@ -49,8 +44,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.jdbc.JdbcTestUtils; import org.springframework.transaction.annotation.Transactional; -import java.util.List; - /** * Very simple use cases for creation and usage of JdbcRepositories with test {@link Embedded} annotation in Entities. * @@ -85,7 +78,9 @@ public class JdbcRepositoryEmbeddedIntegrationTests { } @Bean - WithDotColumnRepo withDotColumnRepo() { return factory.getRepository(WithDotColumnRepo.class);} + WithDotColumnRepo withDotColumnRepo() { + return factory.getRepository(WithDotColumnRepo.class); + } } @@ -250,11 +245,12 @@ public class JdbcRepositoryEmbeddedIntegrationTests { Person second = new Person(null, "Alex", "LA", new PersonContacts("aaa@example.com", "+2 222 2222 22 22")); Person third = new Person(null, "Sarah", "NY", new PersonContacts("ggg@example.com", "+3 333 3333 33 33")); - personRepository.saveAll(List.of(first, second, third)); + List people = (List)personRepository.saveAll(List.of(first, second, third)); - Iterable fetchedPersons = personRepository.findAll(Sort.by(new Sort.Order(Sort.Direction.ASC, "personContacts.email"))); + Iterable fetchedPersons = personRepository + .findAll(Sort.by(new Sort.Order(Sort.Direction.ASC, "personContacts.email"))); - Assertions.assertThat(fetchedPersons).containsExactly(second, first, third); + Assertions.assertThat(fetchedPersons).containsExactly(people.get(1), people.get(0), people.get(2)); } @Test // GH-1286 @@ -264,11 +260,12 @@ public class JdbcRepositoryEmbeddedIntegrationTests { WithDotColumn second = new WithDotColumn(null, "Istanbul"); WithDotColumn third = new WithDotColumn(null, "Tokyo"); - withDotColumnRepo.saveAll(List.of(first, second, third)); + List saved = (List) withDotColumnRepo.saveAll(List.of(first, second, third)); - Iterable fetchedPersons = withDotColumnRepo.findAll(Sort.by(new Sort.Order(Sort.Direction.ASC, "address"))); + Iterable fetchedPersons = withDotColumnRepo + .findAll(Sort.by(new Sort.Order(Sort.Direction.ASC, "address"))); - Assertions.assertThat(fetchedPersons).containsExactly(second, first, third); + Assertions.assertThat(fetchedPersons).containsExactly(saved.get(1), saved.get(0), saved.get(2)); } private static DummyEntity createDummyEntity() { @@ -299,42 +296,20 @@ public class JdbcRepositoryEmbeddedIntegrationTests { interface PersonRepository extends PagingAndSortingRepository, CrudRepository {} - interface WithDotColumnRepo extends PagingAndSortingRepository, CrudRepository {} + interface WithDotColumnRepo + extends PagingAndSortingRepository, CrudRepository {} - @Data - @AllArgsConstructor - @NoArgsConstructor - static class WithDotColumn { - - @Id - private Integer id; - @Column("address.city") - private String address; + record WithDotColumn(@Id Integer id, @Column("address.city") String address) { } - @Data - @AllArgsConstructor - @NoArgsConstructor @Table("SORT_EMBEDDED_ENTITY") - static class Person { - @Id - private Long id; - private String firstName; - private String address; - - @Embedded.Nullable - private PersonContacts personContacts; + record Person(@Id Long id, String firstName, String address, @Embedded.Nullable PersonContacts personContacts) { } - @Data - @AllArgsConstructor - @NoArgsConstructor - static class PersonContacts { - private String email; - private String phoneNumber; - } + record PersonContacts(String email, String phoneNumber) { + } + - @Data static class DummyEntity { @Id Long id; @@ -342,17 +317,63 @@ public class JdbcRepositoryEmbeddedIntegrationTests { @Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "PREFIX_") CascadedEmbeddable prefixedEmbeddable; @Embedded(onEmpty = OnEmpty.USE_NULL) CascadedEmbeddable embeddable; + + public Long getId() { + return this.id; + } + + public CascadedEmbeddable getPrefixedEmbeddable() { + return this.prefixedEmbeddable; + } + + public CascadedEmbeddable getEmbeddable() { + return this.embeddable; + } + + public void setId(Long id) { + this.id = id; + } + + public void setPrefixedEmbeddable(CascadedEmbeddable prefixedEmbeddable) { + this.prefixedEmbeddable = prefixedEmbeddable; + } + + public void setEmbeddable(CascadedEmbeddable embeddable) { + this.embeddable = embeddable; + } } - @Data static class CascadedEmbeddable { String test; @Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "PREFIX2_") Embeddable embeddable; + + public String getTest() { + return this.test; + } + + public Embeddable getEmbeddable() { + return this.embeddable; + } + + public void setTest(String test) { + this.test = test; + } + + public void setEmbeddable(Embeddable embeddable) { + this.embeddable = embeddable; + } } - @Data static class Embeddable { Long attr; + + public Long getAttr() { + return this.attr; + } + + public void setAttr(Long attr) { + this.attr = attr; + } } } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests.java index 554c62a6..ce7919cf 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests.java @@ -15,14 +15,6 @@ */ package org.springframework.data.jdbc.repository; -import static java.util.Arrays.*; -import static org.assertj.core.api.Assertions.*; -import static org.springframework.test.context.TestExecutionListeners.MergeMode.*; - -import lombok.Data; - -import java.sql.SQLException; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; @@ -47,6 +39,12 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.jdbc.JdbcTestUtils; import org.springframework.transaction.annotation.Transactional; +import java.sql.SQLException; + +import static java.util.Arrays.*; +import static org.assertj.core.api.Assertions.*; +import static org.springframework.test.context.TestExecutionListeners.MergeMode.*; + /** * Very simple use cases for creation and usage of JdbcRepositories with test {@link Embedded} annotation in Entities. * @@ -245,26 +243,85 @@ public class JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests { } - @Data static class DummyEntity { - @Column("ID") @Id Long id; + @Column("ID") + @Id + Long id; String test; - @Column("ID") DummyEntity2 dummyEntity2; + @Column("ID") + DummyEntity2 dummyEntity2; + + public Long getId() { + return this.id; + } + + public String getTest() { + return this.test; + } + + public DummyEntity2 getDummyEntity2() { + return this.dummyEntity2; + } + + public void setId(Long id) { + this.id = id; + } + + public void setTest(String test) { + this.test = test; + } + + public void setDummyEntity2(DummyEntity2 dummyEntity2) { + this.dummyEntity2 = dummyEntity2; + } } - @Data static class DummyEntity2 { - @Column("ID") @Id Long id; + @Column("ID") + @Id + Long id; String test; - @Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "prefix_") Embeddable embeddable; + @Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "prefix_") + Embeddable embeddable; + + public Long getId() { + return this.id; + } + + public String getTest() { + return this.test; + } + + public Embeddable getEmbeddable() { + return this.embeddable; + } + + public void setId(Long id) { + this.id = id; + } + + public void setTest(String test) { + this.test = test; + } + + public void setEmbeddable(Embeddable embeddable) { + this.embeddable = embeddable; + } } - @Data static class Embeddable { Long attr; + + public Long getAttr() { + return this.attr; + } + + public void setAttr(Long attr) { + this.attr = attr; + } } } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedWithCollectionIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedWithCollectionIntegrationTests.java index 95989ffe..f60f161b 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedWithCollectionIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedWithCollectionIntegrationTests.java @@ -18,8 +18,6 @@ package org.springframework.data.jdbc.repository; import static java.util.Arrays.*; import static org.assertj.core.api.Assertions.*; -import lombok.Data; - import java.sql.SQLException; import java.util.ArrayList; import java.util.List; @@ -36,8 +34,8 @@ import org.springframework.data.jdbc.testing.TestConfiguration; import org.springframework.data.relational.core.dialect.Dialect; import org.springframework.data.relational.core.mapping.Column; import org.springframework.data.relational.core.mapping.Embedded; -import org.springframework.data.relational.core.mapping.MappedCollection; import org.springframework.data.relational.core.mapping.Embedded.OnEmpty; +import org.springframework.data.relational.core.mapping.MappedCollection; import org.springframework.data.relational.core.sql.SqlIdentifier; import org.springframework.data.repository.CrudRepository; import org.springframework.jdbc.core.JdbcTemplate; @@ -254,24 +252,70 @@ public class JdbcRepositoryEmbeddedWithCollectionIntegrationTests { interface DummyEntityRepository extends CrudRepository {} - @Data private static class DummyEntity { - @Column("ID") @Id Long id; + @Column("ID") + @Id Long id; String test; @Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "PREFIX_") Embeddable embeddable; + + public Long getId() { + return this.id; + } + + public String getTest() { + return this.test; + } + + public Embeddable getEmbeddable() { + return this.embeddable; + } + + public void setId(Long id) { + this.id = id; + } + + public void setTest(String test) { + this.test = test; + } + + public void setEmbeddable(Embeddable embeddable) { + this.embeddable = embeddable; + } } - @Data private static class Embeddable { @MappedCollection(idColumn = "ID", keyColumn = "ORDER_KEY") List list = new ArrayList<>(); String test; + + public List getList() { + return this.list; + } + + public String getTest() { + return this.test; + } + + public void setList(List list) { + this.list = list; + } + + public void setTest(String test) { + this.test = test; + } } - @Data private static class DummyEntity2 { String test; + + public String getTest() { + return this.test; + } + + public void setTest(String test) { + this.test = test; + } } } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedWithReferenceIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedWithReferenceIntegrationTests.java index cf1d6d72..533bb351 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedWithReferenceIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedWithReferenceIntegrationTests.java @@ -19,8 +19,6 @@ import static java.util.Arrays.*; import static org.assertj.core.api.Assertions.*; import static org.springframework.test.context.TestExecutionListeners.MergeMode.*; -import lombok.Data; - import java.util.List; import org.junit.jupiter.api.Test; @@ -269,37 +267,107 @@ public class JdbcRepositoryEmbeddedWithReferenceIntegrationTests { } - @Data private static class DummyEntity { - @Column("ID") @Id Long id; + @Column("ID") + @Id Long id; String test; @Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "PREFIX_") Embeddable embeddable; @Embedded(onEmpty = OnEmpty.USE_NULL) Embeddable2 embeddable2; + + public Long getId() { + return this.id; + } + + public String getTest() { + return this.test; + } + + public Embeddable getEmbeddable() { + return this.embeddable; + } + + public Embeddable2 getEmbeddable2() { + return this.embeddable2; + } + + public void setId(Long id) { + this.id = id; + } + + public void setTest(String test) { + this.test = test; + } + + public void setEmbeddable(Embeddable embeddable) { + this.embeddable = embeddable; + } + + public void setEmbeddable2(Embeddable2 embeddable2) { + this.embeddable2 = embeddable2; + } } - @Data private static class Embeddable { @Column("ID") DummyEntity2 dummyEntity2; String test; + + public DummyEntity2 getDummyEntity2() { + return this.dummyEntity2; + } + + public String getTest() { + return this.test; + } + + public void setDummyEntity2(DummyEntity2 dummyEntity2) { + this.dummyEntity2 = dummyEntity2; + } + + public void setTest(String test) { + this.test = test; + } } - @Data private static class Embeddable2 { @Column("ID") DummyEntity2 dummyEntity2; + + public DummyEntity2 getDummyEntity2() { + return this.dummyEntity2; + } + + public void setDummyEntity2(DummyEntity2 dummyEntity2) { + this.dummyEntity2 = dummyEntity2; + } } - @Data private static class DummyEntity2 { - @Column("ID") @Id Long id; + @Column("ID") + @Id Long id; String test; + + public Long getId() { + return this.id; + } + + public String getTest() { + return this.test; + } + + public void setId(Long id) { + this.id = id; + } + + public void setTest(String test) { + this.test = test; + } } } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIdGenerationIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIdGenerationIntegrationTests.java index 996a4908..caa5be1a 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIdGenerationIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIdGenerationIntegrationTests.java @@ -15,18 +15,8 @@ */ package org.springframework.data.jdbc.repository; -import static org.assertj.core.api.Assertions.*; - -import lombok.Data; -import lombok.Value; -import lombok.With; -import lombok.experimental.FieldDefaults; - -import java.util.concurrent.atomic.AtomicLong; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -44,6 +34,10 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; +import java.util.concurrent.atomic.AtomicLong; + +import static org.assertj.core.api.Assertions.*; + /** * Testing special cases for id generation with {@link SimpleJdbcRepository}. * @@ -119,26 +113,128 @@ public class JdbcRepositoryIdGenerationIntegrationTests { private interface ImmutableWithManualIdEntityRepository extends CrudRepository {} - @Value - @FieldDefaults(makeFinal = false) - static class ReadOnlyIdEntity { + static final class ReadOnlyIdEntity { - @Id Long id; - String name; + @Id + private final Long id; + private final String name; + + public ReadOnlyIdEntity(Long id, String name) { + this.id = id; + this.name = name; + } + + public Long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof ReadOnlyIdEntity)) return false; + final ReadOnlyIdEntity other = (ReadOnlyIdEntity) o; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false; + final Object this$name = this.getName(); + final Object other$name = other.getName(); + if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.getId(); + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + final Object $name = this.getName(); + result = result * PRIME + ($name == null ? 43 : $name.hashCode()); + return result; + } + + public String toString() { + return "JdbcRepositoryIdGenerationIntegrationTests.ReadOnlyIdEntity(id=" + this.getId() + ", name=" + this.getName() + ")"; + } } - @Data static class PrimitiveIdEntity { - @Id private long id; + @Id + private long id; String name; + + public long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public void setId(long id) { + this.id = id; + } + + public void setName(String name) { + this.name = name; + } } - @Value - @With - static class ImmutableWithManualIdEntity { - @Id Long id; - String name; + static final class ImmutableWithManualIdEntity { + @Id + private final Long id; + private final String name; + + public ImmutableWithManualIdEntity(Long id, String name) { + this.id = id; + this.name = name; + } + + public Long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof ImmutableWithManualIdEntity)) return false; + final ImmutableWithManualIdEntity other = (ImmutableWithManualIdEntity) o; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false; + final Object this$name = this.getName(); + final Object other$name = other.getName(); + if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.getId(); + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + final Object $name = this.getName(); + result = result * PRIME + ($name == null ? 43 : $name.hashCode()); + return result; + } + + public String toString() { + return "JdbcRepositoryIdGenerationIntegrationTests.ImmutableWithManualIdEntity(id=" + this.getId() + ", name=" + this.getName() + ")"; + } + + public ImmutableWithManualIdEntity withId(Long id) { + return this.id == id ? this : new ImmutableWithManualIdEntity(id, this.name); + } + + public ImmutableWithManualIdEntity withName(String name) { + return this.name == name ? this : new ImmutableWithManualIdEntity(this.id, name); + } } @Configuration diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java index 567eb573..be10a19f 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java @@ -21,10 +21,6 @@ import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.SoftAssertions.*; import static org.springframework.test.context.TestExecutionListeners.MergeMode.*; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.Value; - import java.io.IOException; import java.sql.ResultSet; import java.time.Instant; @@ -36,6 +32,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.stream.Stream; @@ -83,8 +80,8 @@ import org.springframework.data.repository.core.support.PropertiesBasedNamedQuer import org.springframework.data.repository.query.ExtensionAwareQueryMethodEvaluationContextProvider; import org.springframework.data.repository.query.FluentQuery; import org.springframework.data.repository.query.Param; -import org.springframework.data.spel.spi.EvaluationContextExtension; import org.springframework.data.repository.query.QueryByExampleExecutor; +import org.springframework.data.spel.spi.EvaluationContextExtension; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; @@ -94,8 +91,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.jdbc.JdbcTestUtils; import org.springframework.transaction.annotation.Transactional; -import lombok.Data; - /** * Very simple use cases for creation and usage of JdbcRepositories. * @@ -1387,13 +1382,12 @@ public class JdbcRepositoryIntegrationTests { List findAllByOrderByIdAsc(); } - interface WithDelimitedColumnRepository extends CrudRepository { } + interface WithDelimitedColumnRepository extends CrudRepository {} @Configuration @Import(TestConfiguration.class) static class Config { - @Autowired JdbcRepositoryFactory factory; @Bean @@ -1412,7 +1406,9 @@ public class JdbcRepositoryIntegrationTests { } @Bean - WithDelimitedColumnRepository withDelimitedColumnRepository() { return factory.getRepository(WithDelimitedColumnRepository.class); } + WithDelimitedColumnRepository withDelimitedColumnRepository() { + return factory.getRepository(WithDelimitedColumnRepository.class); + } @Bean NamedQueries namedQueries() throws IOException { @@ -1430,12 +1426,14 @@ public class JdbcRepositoryIntegrationTests { @Bean public ExtensionAwareQueryMethodEvaluationContextProvider extensionAware(List exts) { - ExtensionAwareQueryMethodEvaluationContextProvider extensionAwareQueryMethodEvaluationContextProvider = new ExtensionAwareQueryMethodEvaluationContextProvider(exts); + ExtensionAwareQueryMethodEvaluationContextProvider extensionAwareQueryMethodEvaluationContextProvider = new ExtensionAwareQueryMethodEvaluationContextProvider( + exts); factory.setEvaluationContextProvider(extensionAwareQueryMethodEvaluationContextProvider); return extensionAwareQueryMethodEvaluationContextProvider; } + @Bean public EvaluationContextExtension evaluationContextExtension() { return new MyIdContextProvider(); @@ -1443,37 +1441,235 @@ public class JdbcRepositoryIntegrationTests { } - @Value - static class Root { + static final class Root { - @Id Long id; - String name; - Intermediate intermediate; - @MappedCollection(idColumn = "ROOT_ID", keyColumn = "ROOT_KEY") List intermediates; + @Id private final Long id; + private final String name; + private final Intermediate intermediate; + @MappedCollection(idColumn = "ROOT_ID", keyColumn = "ROOT_KEY") private final List intermediates; + + public Root(Long id, String name, Intermediate intermediate, List intermediates) { + this.id = id; + this.name = name; + this.intermediate = intermediate; + this.intermediates = intermediates; + } + + public Long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public Intermediate getIntermediate() { + return this.intermediate; + } + + public List getIntermediates() { + return this.intermediates; + } + + public boolean equals(final Object o) { + if (o == this) + return true; + if (!(o instanceof Root)) + return false; + final Root other = (Root) o; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) + return false; + final Object this$name = this.getName(); + final Object other$name = other.getName(); + if (this$name == null ? other$name != null : !this$name.equals(other$name)) + return false; + final Object this$intermediate = this.getIntermediate(); + final Object other$intermediate = other.getIntermediate(); + if (this$intermediate == null ? other$intermediate != null : !this$intermediate.equals(other$intermediate)) + return false; + final Object this$intermediates = this.getIntermediates(); + final Object other$intermediates = other.getIntermediates(); + if (this$intermediates == null ? other$intermediates != null : !this$intermediates.equals(other$intermediates)) + return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.getId(); + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + final Object $name = this.getName(); + result = result * PRIME + ($name == null ? 43 : $name.hashCode()); + final Object $intermediate = this.getIntermediate(); + result = result * PRIME + ($intermediate == null ? 43 : $intermediate.hashCode()); + final Object $intermediates = this.getIntermediates(); + result = result * PRIME + ($intermediates == null ? 43 : $intermediates.hashCode()); + return result; + } + + public String toString() { + return "JdbcRepositoryIntegrationTests.Root(id=" + this.getId() + ", name=" + this.getName() + ", intermediate=" + + this.getIntermediate() + ", intermediates=" + this.getIntermediates() + ")"; + } } - @Data @Table("WITH_DELIMITED_COLUMN") static class WithDelimitedColumn { @Id Long id; @Column("ORG.XTUNIT.IDENTIFIER") String identifier; - @Column ("STYPE") String type; + @Column("STYPE") String type; + + public Long getId() { + return this.id; + } + + public String getIdentifier() { + return this.identifier; + } + + public String getType() { + return this.type; + } + + public void setId(Long id) { + this.id = id; + } + + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + public void setType(String type) { + this.type = type; + } } - @Value - static class Intermediate { + static final class Intermediate { - @Id Long id; - String name; - Leaf leaf; - @MappedCollection(idColumn = "INTERMEDIATE_ID", keyColumn = "INTERMEDIATE_KEY") List leaves; + @Id private final Long id; + private final String name; + private final Leaf leaf; + @MappedCollection(idColumn = "INTERMEDIATE_ID", keyColumn = "INTERMEDIATE_KEY") private final List leaves; + + public Intermediate(Long id, String name, Leaf leaf, List leaves) { + this.id = id; + this.name = name; + this.leaf = leaf; + this.leaves = leaves; + } + + public Long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public Leaf getLeaf() { + return this.leaf; + } + + public List getLeaves() { + return this.leaves; + } + + public boolean equals(final Object o) { + if (o == this) + return true; + if (!(o instanceof Intermediate)) + return false; + final Intermediate other = (Intermediate) o; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) + return false; + final Object this$name = this.getName(); + final Object other$name = other.getName(); + if (this$name == null ? other$name != null : !this$name.equals(other$name)) + return false; + final Object this$leaf = this.getLeaf(); + final Object other$leaf = other.getLeaf(); + if (this$leaf == null ? other$leaf != null : !this$leaf.equals(other$leaf)) + return false; + final Object this$leaves = this.getLeaves(); + final Object other$leaves = other.getLeaves(); + if (this$leaves == null ? other$leaves != null : !this$leaves.equals(other$leaves)) + return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.getId(); + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + final Object $name = this.getName(); + result = result * PRIME + ($name == null ? 43 : $name.hashCode()); + final Object $leaf = this.getLeaf(); + result = result * PRIME + ($leaf == null ? 43 : $leaf.hashCode()); + final Object $leaves = this.getLeaves(); + result = result * PRIME + ($leaves == null ? 43 : $leaves.hashCode()); + return result; + } + + public String toString() { + return "JdbcRepositoryIntegrationTests.Intermediate(id=" + this.getId() + ", name=" + this.getName() + ", leaf=" + + this.getLeaf() + ", leaves=" + this.getLeaves() + ")"; + } } - @Value - static class Leaf { + static final class Leaf { - @Id Long id; - String name; + @Id private final Long id; + private final String name; + + public Leaf(Long id, String name) { + this.id = id; + this.name = name; + } + + public Long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public boolean equals(final Object o) { + if (o == this) + return true; + if (!(o instanceof Leaf)) + return false; + final Leaf other = (Leaf) o; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) + return false; + final Object this$name = this.getName(); + final Object other$name = other.getName(); + if (this$name == null ? other$name != null : !this$name.equals(other$name)) + return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.getId(); + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + final Object $name = this.getName(); + result = result * PRIME + ($name == null ? 43 : $name.hashCode()); + return result; + } + + public String toString() { + return "JdbcRepositoryIntegrationTests.Leaf(id=" + this.getId() + ", name=" + this.getName() + ")"; + } } static class MyEventListener implements ApplicationListener> { @@ -1507,8 +1703,6 @@ public class JdbcRepositoryIntegrationTests { } } - @Data - @NoArgsConstructor static class DummyEntity { String name; @@ -1522,6 +1716,77 @@ public class JdbcRepositoryIntegrationTests { public DummyEntity(String name) { this.name = name; } + + public DummyEntity() {} + + public String getName() { + return this.name; + } + + public Instant getPointInTime() { + return this.pointInTime; + } + + public OffsetDateTime getOffsetDateTime() { + return this.offsetDateTime; + } + + public Long getIdProp() { + return this.idProp; + } + + public boolean isFlag() { + return this.flag; + } + + public AggregateReference getRef() { + return this.ref; + } + + public Direction getDirection() { + return this.direction; + } + + public void setName(String name) { + this.name = name; + } + + public void setPointInTime(Instant pointInTime) { + this.pointInTime = pointInTime; + } + + public void setOffsetDateTime(OffsetDateTime offsetDateTime) { + this.offsetDateTime = offsetDateTime; + } + + public void setIdProp(Long idProp) { + this.idProp = idProp; + } + + public void setFlag(boolean flag) { + this.flag = flag; + } + + public void setRef(AggregateReference ref) { + this.ref = ref; + } + + public void setDirection(Direction direction) { + this.direction = direction; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + DummyEntity that = (DummyEntity) o; + return flag == that.flag && Objects.equals(name, that.name) && Objects.equals(pointInTime, that.pointInTime) && Objects.equals(offsetDateTime, that.offsetDateTime) && Objects.equals(idProp, that.idProp) && Objects.equals(ref, that.ref) && direction == that.direction; + } + + @Override + public int hashCode() { + return Objects.hash(name, pointInTime, offsetDateTime, idProp, flag, ref, direction); + } } enum Direction { @@ -1532,9 +1797,41 @@ public class JdbcRepositoryIntegrationTests { String getName(); } - @Value - static class DtoProjection { - String name; + static final class DtoProjection { + private final String name; + + public DtoProjection(String name) { + this.name = name; + } + + public String getName() { + return this.name; + } + + public boolean equals(final Object o) { + if (o == this) + return true; + if (!(o instanceof DtoProjection)) + return false; + final DtoProjection other = (DtoProjection) o; + final Object this$name = this.getName(); + final Object other$name = other.getName(); + if (this$name == null ? other$name != null : !this$name.equals(other$name)) + return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $name = this.getName(); + result = result * PRIME + ($name == null ? 43 : $name.hashCode()); + return result; + } + + public String toString() { + return "JdbcRepositoryIntegrationTests.DtoProjection(name=" + this.getName() + ")"; + } } static class CustomRowMapper implements RowMapper { diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryPropertyConversionIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryPropertyConversionIntegrationTests.java index fbf78c79..30b78658 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryPropertyConversionIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryPropertyConversionIntegrationTests.java @@ -20,8 +20,6 @@ import static org.assertj.core.api.Assertions.*; import static org.springframework.data.jdbc.testing.TestDatabaseFeatures.Feature.*; import static org.springframework.test.context.TestExecutionListeners.MergeMode.*; -import lombok.Data; - import java.math.BigDecimal; import java.math.BigInteger; import java.text.SimpleDateFormat; @@ -188,7 +186,6 @@ public class JdbcRepositoryPropertyConversionIntegrationTests { } } - @Data static class EntityWithColumnsRequiringConversions { boolean bool; @@ -201,11 +198,82 @@ public class JdbcRepositoryPropertyConversionIntegrationTests { @Id private LocalDateTime idTimestamp; @MappedCollection(idColumn = "ID_TIMESTAMP") Set relation; + + public boolean isBool() { + return this.bool; + } + + public SomeEnum getSomeEnum() { + return this.someEnum; + } + + public BigDecimal getBigDecimal() { + return this.bigDecimal; + } + + public BigInteger getBigInteger() { + return this.bigInteger; + } + + public Date getDate() { + return this.date; + } + + public LocalDateTime getLocalDateTime() { + return this.localDateTime; + } + + public LocalDateTime getIdTimestamp() { + return this.idTimestamp; + } + + public Set getRelation() { + return this.relation; + } + + public void setBool(boolean bool) { + this.bool = bool; + } + + public void setSomeEnum(SomeEnum someEnum) { + this.someEnum = someEnum; + } + + public void setBigDecimal(BigDecimal bigDecimal) { + this.bigDecimal = bigDecimal; + } + + public void setBigInteger(BigInteger bigInteger) { + this.bigInteger = bigInteger; + } + + public void setDate(Date date) { + this.date = date; + } + + public void setLocalDateTime(LocalDateTime localDateTime) { + this.localDateTime = localDateTime; + } + + public void setIdTimestamp(LocalDateTime idTimestamp) { + this.idTimestamp = idTimestamp; + } + + public void setRelation(Set relation) { + this.relation = relation; + } } // DATAJDBC-349 - @Data static class EntityWithColumnsRequiringConversionsRelation { String data; + + public String getData() { + return this.data; + } + + public void setData(String data) { + this.data = data; + } } } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryResultSetExtractorIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryResultSetExtractorIntegrationTests.java index 51976ec5..401af630 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryResultSetExtractorIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryResultSetExtractorIntegrationTests.java @@ -15,19 +15,6 @@ */ package org.springframework.data.jdbc.repository; -import static org.assertj.core.api.Assertions.*; - -import lombok.AllArgsConstructor; -import lombok.Data; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Types; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; @@ -46,10 +33,18 @@ import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; -import org.springframework.test.context.junit4.rules.SpringClassRule; -import org.springframework.test.context.junit4.rules.SpringMethodRule; import org.springframework.transaction.annotation.Transactional; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Types; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.assertj.core.api.Assertions.*; + /** * Very simple use cases for creation and usage of {@link ResultSetExtractor}s in JdbcRepository. * @@ -138,21 +133,70 @@ public class JdbcRepositoryResultSetExtractorIntegrationTests { List findAllPeopleWithAddresses(); } - @Data - @AllArgsConstructor static class Person { - @Id private Long id; + @Id + private Long id; private String name; private List
addresses; + + public Person(Long id, String name, List
addresses) { + this.id = id; + this.name = name; + this.addresses = addresses; + } + + public Long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public List
getAddresses() { + return this.addresses; + } + + public void setId(Long id) { + this.id = id; + } + + public void setName(String name) { + this.name = name; + } + + public void setAddresses(List
addresses) { + this.addresses = addresses; + } } - @Data - @AllArgsConstructor static class Address { - @Id private Long id; + @Id + private Long id; private String street; + + public Address(Long id, String street) { + this.id = id; + this.street = street; + } + + public Long getId() { + return this.id; + } + + public String getStreet() { + return this.street; + } + + public void setId(Long id) { + this.id = id; + } + + public void setStreet(String street) { + this.street = street; + } } static class PersonResultSetExtractor implements ResultSetExtractor> { diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithCollectionsAndManuallyAssignedIdHsqlIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithCollectionsAndManuallyAssignedIdHsqlIntegrationTests.java index 7a0f3746..88c1d4b6 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithCollectionsAndManuallyAssignedIdHsqlIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithCollectionsAndManuallyAssignedIdHsqlIntegrationTests.java @@ -15,17 +15,7 @@ */ package org.springframework.data.jdbc.repository; -import static org.assertj.core.api.Assertions.*; - import junit.framework.AssertionFailedError; -import lombok.Data; -import lombok.RequiredArgsConstructor; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.atomic.AtomicLong; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; @@ -44,6 +34,13 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.annotation.Transactional; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.atomic.AtomicLong; + +import static org.assertj.core.api.Assertions.*; + /** * Very simple use cases for creation and usage of JdbcRepositories. * @@ -229,20 +226,46 @@ public class JdbcRepositoryWithCollectionsAndManuallyAssignedIdHsqlIntegrationTe interface DummyEntityRepository extends CrudRepository {} - @Data static class DummyEntity { - @Id private Long id; + @Id + private Long id; String name; Set content = new HashSet<>(); + public Long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public Set getContent() { + return this.content; + } + + public void setId(Long id) { + this.id = id; + } + + public void setName(String name) { + this.name = name; + } + + public void setContent(Set content) { + this.content = content; + } } - @RequiredArgsConstructor static class Element { - @Id private Long id; + @Id + private Long id; String content; + + public Element() { + } } } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithCollectionsIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithCollectionsIntegrationTests.java index 542277e3..28a35022 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithCollectionsIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithCollectionsIntegrationTests.java @@ -20,8 +20,6 @@ import static org.springframework.data.jdbc.testing.TestDatabaseFeatures.Feature import static org.springframework.test.context.TestExecutionListeners.MergeMode.*; import junit.framework.AssertionFailedError; -import lombok.Data; -import lombok.RequiredArgsConstructor; import java.util.HashMap; import java.util.HashSet; @@ -210,16 +208,37 @@ public class JdbcRepositoryWithCollectionsIntegrationTests { } } - @Data static class DummyEntity { String name; Set content = new HashSet<>(); @Id private Long id; + public String getName() { + return this.name; + } + + public Set getContent() { + return this.content; + } + + public Long getId() { + return this.id; + } + + public void setName(String name) { + this.name = name; + } + + public void setContent(Set content) { + this.content = content; + } + + public void setId(Long id) { + this.id = id; + } } - @RequiredArgsConstructor static class Element { String content; diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithListsIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithListsIntegrationTests.java index 0dbac16f..47331152 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithListsIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithListsIntegrationTests.java @@ -21,9 +21,6 @@ import static org.springframework.data.jdbc.testing.TestDatabaseFeatures.Feature import static org.springframework.test.context.TestExecutionListeners.MergeMode.*; import junit.framework.AssertionFailedError; -import lombok.Data; -import lombok.RequiredArgsConstructor; -import lombok.Value; import java.util.ArrayList; import java.util.HashMap; @@ -247,36 +244,121 @@ public class JdbcRepositoryWithListsIntegrationTests { } } - @Data static class DummyEntity { String name; List content = new ArrayList<>(); @Id private Long id; + public String getName() { + return this.name; + } + + public List getContent() { + return this.content; + } + + public Long getId() { + return this.id; + } + + public void setName(String name) { + this.name = name; + } + + public void setContent(List content) { + this.content = content; + } + + public void setId(Long id) { + this.id = id; + } } - @RequiredArgsConstructor static class Element { String content; @Id private Long id; + + public Element() {} } - @Data static class Root { @Id private Long id; List intermediates = new ArrayList<>(); + + public Long getId() { + return this.id; + } + + public List getIntermediates() { + return this.intermediates; + } + + public void setId(Long id) { + this.id = id; + } + + public void setIntermediates(List intermediates) { + this.intermediates = intermediates; + } } - @Data static class Intermediate { @Id private Long id; List leaves = new ArrayList<>(); + + public Long getId() { + return this.id; + } + + public List getLeaves() { + return this.leaves; + } + + public void setId(Long id) { + this.id = id; + } + + public void setLeaves(List leaves) { + this.leaves = leaves; + } } - @Value - static class Leaf { - String name; + static final class Leaf { + private final String name; + + public Leaf(String name) { + this.name = name; + } + + public String getName() { + return this.name; + } + + public boolean equals(final Object o) { + if (o == this) + return true; + if (!(o instanceof Leaf)) + return false; + final Leaf other = (Leaf) o; + final Object this$name = this.getName(); + final Object other$name = other.getName(); + if (this$name == null ? other$name != null : !this$name.equals(other$name)) + return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $name = this.getName(); + result = result * PRIME + ($name == null ? 43 : $name.hashCode()); + return result; + } + + public String toString() { + return "JdbcRepositoryWithListsIntegrationTests.Leaf(name=" + this.getName() + ")"; + } } } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithMapsIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithMapsIntegrationTests.java index 280e038d..43a7baf6 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithMapsIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithMapsIntegrationTests.java @@ -20,8 +20,6 @@ import static org.springframework.data.jdbc.testing.TestDatabaseFeatures.Feature import static org.springframework.test.context.TestExecutionListeners.MergeMode.*; import junit.framework.AssertionFailedError; -import lombok.Data; -import lombok.RequiredArgsConstructor; import java.util.HashMap; import java.util.Map; @@ -213,20 +211,43 @@ public class JdbcRepositoryWithMapsIntegrationTests { interface DummyEntityRepository extends CrudRepository {} - @Data static class DummyEntity { @Id private Long id; String name; Map content = new HashMap<>(); + public Long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public Map getContent() { + return this.content; + } + + public void setId(Long id) { + this.id = id; + } + + public void setName(String name) { + this.name = name; + } + + public void setContent(Map content) { + this.content = content; + } } - @RequiredArgsConstructor static class Element { @Id private Long id; String content; + + public Element() {} } } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/SimpleJdbcRepositoryEventsUnitTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/SimpleJdbcRepositoryEventsUnitTests.java index 2ae89eaa..6c7d076a 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/SimpleJdbcRepositoryEventsUnitTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/SimpleJdbcRepositoryEventsUnitTests.java @@ -15,20 +15,6 @@ */ package org.springframework.data.jdbc.repository; -import static java.util.Arrays.*; -import static org.assertj.core.api.Assertions.*; -import static org.assertj.core.groups.Tuple.tuple; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.*; - -import lombok.RequiredArgsConstructor; -import lombok.Value; -import lombok.With; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.stubbing.Answer; @@ -62,6 +48,16 @@ import org.springframework.jdbc.core.namedparam.SqlParameterSource; import org.springframework.jdbc.support.KeyHolder; import org.springframework.lang.Nullable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import static java.util.Arrays.*; +import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.groups.Tuple.tuple; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; + /** * Unit tests for application events via {@link SimpleJdbcRepository}. * @@ -302,11 +298,43 @@ class SimpleJdbcRepositoryEventsUnitTests { interface DummyEntityRepository extends CrudRepository, PagingAndSortingRepository {} - @Value - @With - @RequiredArgsConstructor - static class DummyEntity { - @Id Long id; + static final class DummyEntity { + @Id + private final Long id; + + public DummyEntity(Long id) { + this.id = id; + } + + public Long getId() { + return this.id; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof DummyEntity)) return false; + final DummyEntity other = (DummyEntity) o; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.getId(); + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + return result; + } + + public String toString() { + return "SimpleJdbcRepositoryEventsUnitTests.DummyEntity(id=" + this.getId() + ")"; + } + + public DummyEntity withId(Long id) { + return this.id == id ? this : new DummyEntity(id); + } } static class CollectingEventPublisher implements ApplicationEventPublisher { diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/StringBasedJdbcQueryMappingConfigurationIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/StringBasedJdbcQueryMappingConfigurationIntegrationTests.java index ae459e5e..707ef54d 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/StringBasedJdbcQueryMappingConfigurationIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/StringBasedJdbcQueryMappingConfigurationIntegrationTests.java @@ -18,9 +18,6 @@ package org.springframework.data.jdbc.repository; import static java.util.Collections.*; import static org.assertj.core.api.Assertions.*; -import lombok.AllArgsConstructor; -import lombok.Data; - import java.sql.ResultSet; import java.sql.SQLException; import java.util.Arrays; @@ -28,7 +25,6 @@ import java.util.List; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -122,12 +118,31 @@ public class StringBasedJdbcQueryMappingConfigurationIntegrationTests { } } - @Data - @AllArgsConstructor public static class Car { @Id private Long id; private String model; + + public Car(Long id, String model) { + this.id = id; + this.model = model; + } + + public Long getId() { + return this.id; + } + + public String getModel() { + return this.model; + } + + public void setId(Long id) { + this.id = id; + } + + public void setModel(String model) { + this.model = model; + } } static class CarResultSetExtractor implements ResultSetExtractor> { @@ -163,7 +178,6 @@ public class StringBasedJdbcQueryMappingConfigurationIntegrationTests { @Query(value = "select model from car", rowMapperRef = "CustomRowMapperBean") List findByNameWithRowMapperBean(); - @Query(value = "select * from car", resultSetExtractorClass = RowMapperResultSetExtractor.class) RowMapper customFindAllWithRowMapper(); diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/config/EnableJdbcAuditingHsqlIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/config/EnableJdbcAuditingHsqlIntegrationTests.java index 59670f54..a4001357 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/config/EnableJdbcAuditingHsqlIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/config/EnableJdbcAuditingHsqlIntegrationTests.java @@ -17,10 +17,9 @@ package org.springframework.data.jdbc.repository.config; import static org.assertj.core.api.Assertions.*; -import lombok.Data; - import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.Objects; import java.util.Optional; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; @@ -236,7 +235,6 @@ public class EnableJdbcAuditingHsqlIntegrationTests { interface AuditingAnnotatedDummyEntityRepository extends CrudRepository {} - @Data static class AuditingAnnotatedDummyEntity { @Id long id; @@ -244,16 +242,84 @@ public class EnableJdbcAuditingHsqlIntegrationTests { @CreatedDate LocalDateTime createdDate; @LastModifiedBy String lastModifiedBy; @LastModifiedDate LocalDateTime lastModifiedDate; + + public long getId() { + return this.id; + } + + public String getCreatedBy() { + return this.createdBy; + } + + public LocalDateTime getCreatedDate() { + return this.createdDate; + } + + public String getLastModifiedBy() { + return this.lastModifiedBy; + } + + public LocalDateTime getLastModifiedDate() { + return this.lastModifiedDate; + } + + public void setId(long id) { + this.id = id; + } + + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + public void setCreatedDate(LocalDateTime createdDate) { + this.createdDate = createdDate; + } + + public void setLastModifiedBy(String lastModifiedBy) { + this.lastModifiedBy = lastModifiedBy; + } + + public void setLastModifiedDate(LocalDateTime lastModifiedDate) { + this.lastModifiedDate = lastModifiedDate; + } } interface DummyEntityRepository extends CrudRepository {} - @Data static class DummyEntity { @Id private Long id; // not actually used, exists just to avoid empty value list during insert. String name; + + public Long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public void setId(Long id) { + this.id = id; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + DummyEntity that = (DummyEntity) o; + return Objects.equals(id, that.id) && Objects.equals(name, that.name); + } + + @Override + public int hashCode() { + return Objects.hash(id, name); + } } @ComponentScan("org.springframework.data.jdbc.testing") diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/config/EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/config/EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests.java index b4c580bb..e3fc94a9 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/config/EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/config/EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests.java @@ -17,8 +17,6 @@ package org.springframework.data.jdbc.repository.config; import static org.assertj.core.api.Assertions.*; -import lombok.Data; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.NoSuchBeanDefinitionException; @@ -52,9 +50,16 @@ public class EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests { } - @Data static class DummyEntity { @Id private Long id; + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } } @ComponentScan("org.springframework.data.jdbc.testing") diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/config/EnableJdbcRepositoriesIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/config/EnableJdbcRepositoriesIntegrationTests.java index 99f075a9..dc5db486 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/config/EnableJdbcRepositoriesIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/config/EnableJdbcRepositoriesIntegrationTests.java @@ -18,8 +18,6 @@ package org.springframework.data.jdbc.repository.config; import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.*; -import lombok.Data; - import java.lang.reflect.Field; import java.util.Optional; @@ -133,9 +131,16 @@ public class EnableJdbcRepositoriesIntegrationTests { } - @Data static class DummyEntity { @Id private Long id; + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } } @ComponentScan("org.springframework.data.jdbc.testing") diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/query/PartTreeJdbcQueryUnitTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/query/PartTreeJdbcQueryUnitTests.java index 55587979..74b92b47 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/query/PartTreeJdbcQueryUnitTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/query/PartTreeJdbcQueryUnitTests.java @@ -19,8 +19,6 @@ import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.SoftAssertions.*; import static org.mockito.Mockito.*; -import lombok.AllArgsConstructor; - import java.lang.reflect.Method; import java.util.Collection; import java.util.Collections; @@ -795,15 +793,10 @@ public class PartTreeJdbcQueryUnitTests { AggregateReference hobbyReference; } - @AllArgsConstructor - static class Address { - String street; - String city; + record Address(String street, String city) { } - @AllArgsConstructor - static class AnotherEmbedded { - @MappedCollection(idColumn = "ID", keyColumn = "ORDER_KEY") List list; + record AnotherEmbedded(@MappedCollection(idColumn = "ID", keyColumn = "ORDER_KEY") List list) { } static class Hobby { diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/query/QueryAnnotationHsqlIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/query/QueryAnnotationHsqlIntegrationTests.java index 91c53d7c..88cbba52 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/query/QueryAnnotationHsqlIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/query/QueryAnnotationHsqlIntegrationTests.java @@ -18,8 +18,6 @@ package org.springframework.data.jdbc.repository.query; import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.SoftAssertions.*; -import lombok.Value; - import java.time.LocalDateTime; import java.util.Date; import java.util.List; @@ -347,11 +345,7 @@ public class QueryAnnotationHsqlIntegrationTests { @Query("SELECT 'one' one, 'two' two, 3 three FROM (VALUES (0)) as tableName") ImmutableTuple immutableTuple(); - @Value - class ImmutableTuple { - String one; - String two; - int three; + record ImmutableTuple(String one, String two, int three) { } } } diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/config/AuditingUnitTests.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/config/AuditingUnitTests.java index e45d7331..152ab00c 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/config/AuditingUnitTests.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/config/AuditingUnitTests.java @@ -15,15 +15,7 @@ */ package org.springframework.data.r2dbc.config; -import static org.assertj.core.api.Assertions.*; - -import lombok.Data; -import reactor.core.publisher.Mono; - -import java.time.LocalDateTime; - import org.junit.jupiter.api.Test; - import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.data.annotation.CreatedDate; @@ -35,6 +27,11 @@ import org.springframework.data.mapping.callback.ReactiveEntityCallbacks; import org.springframework.data.r2dbc.mapping.R2dbcMappingContext; import org.springframework.data.r2dbc.mapping.event.BeforeConvertCallback; import org.springframework.data.relational.core.sql.SqlIdentifier; +import reactor.core.publisher.Mono; + +import java.time.LocalDateTime; + +import static org.assertj.core.api.Assertions.*; /** * Unit tests for {@link EnableR2dbcAuditing} @@ -84,13 +81,47 @@ class AuditingUnitTests { context.close(); } - @Data class Entity { - @Id Long id; - @CreatedDate LocalDateTime created; - @LastModifiedDate LocalDateTime modified; - @LastModifiedBy String modifiedBy; + @Id + Long id; + @CreatedDate + LocalDateTime created; + @LastModifiedDate + LocalDateTime modified; + @LastModifiedBy + String modifiedBy; + public Long getId() { + return this.id; + } + + public LocalDateTime getCreated() { + return this.created; + } + + public LocalDateTime getModified() { + return this.modified; + } + + public String getModifiedBy() { + return this.modifiedBy; + } + + public void setId(Long id) { + this.id = id; + } + + public void setCreated(LocalDateTime created) { + this.created = created; + } + + public void setModified(LocalDateTime modified) { + this.modified = modified; + } + + public void setModifiedBy(String modifiedBy) { + this.modifiedBy = modifiedBy; + } } } diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/config/H2IntegrationTests.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/config/H2IntegrationTests.java index eab6f29f..2a421bfd 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/config/H2IntegrationTests.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/config/H2IntegrationTests.java @@ -16,16 +16,12 @@ package org.springframework.data.r2dbc.config; import io.r2dbc.spi.ConnectionFactory; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; 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.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -107,10 +103,7 @@ class H2IntegrationTests { Mono selectCount(); } - @Data @Table("legoset") - @AllArgsConstructor - @NoArgsConstructor static class LegoSet { @Id Integer id; String name; diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/convert/EntityRowMapperUnitTests.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/convert/EntityRowMapperUnitTests.java index 50b22182..5d7acaaf 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/convert/EntityRowMapperUnitTests.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/convert/EntityRowMapperUnitTests.java @@ -1,25 +1,22 @@ package org.springframework.data.r2dbc.convert; -import static org.assertj.core.api.Assertions.*; -import static org.mockito.Mockito.*; - import io.r2dbc.spi.R2dbcType; import io.r2dbc.spi.Row; import io.r2dbc.spi.RowMetadata; import io.r2dbc.spi.test.MockColumnMetadata; import io.r2dbc.spi.test.MockRowMetadata; -import lombok.RequiredArgsConstructor; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.data.r2dbc.core.DefaultReactiveDataAccessStrategy; +import org.springframework.data.r2dbc.dialect.PostgresDialect; import java.util.EnumSet; import java.util.List; import java.util.Set; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.junit.jupiter.MockitoExtension; - -import org.springframework.data.r2dbc.core.DefaultReactiveDataAccessStrategy; -import org.springframework.data.r2dbc.dialect.PostgresDialect; +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.*; /** * Unit tests for {@link EntityRowMapper}. @@ -135,14 +132,20 @@ class EntityRowMapperUnitTests { String id; } - @RequiredArgsConstructor static class SimpleEntityConstructorCreation { final String id; + + public SimpleEntityConstructorCreation(String id) { + this.id = id; + } } - @RequiredArgsConstructor static class ConversionWithConstructorCreation { final long id; + + public ConversionWithConstructorCreation(long id) { + this.id = id; + } } static class EntityWithCollection { diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/convert/MappingR2dbcConverterUnitTests.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/convert/MappingR2dbcConverterUnitTests.java index d77dcbab..84880df2 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/convert/MappingR2dbcConverterUnitTests.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/convert/MappingR2dbcConverterUnitTests.java @@ -15,28 +15,13 @@ */ package org.springframework.data.r2dbc.convert; -import static org.assertj.core.api.Assertions.*; -import static org.mockito.Mockito.*; - import io.r2dbc.spi.R2dbcType; import io.r2dbc.spi.Row; import io.r2dbc.spi.test.MockColumnMetadata; import io.r2dbc.spi.test.MockRow; import io.r2dbc.spi.test.MockRowMetadata; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; - -import java.time.Instant; -import java.time.LocalDateTime; -import java.util.Arrays; -import java.util.Collections; -import java.util.Map; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - import org.springframework.beans.factory.annotation.Value; import org.springframework.core.convert.converter.Converter; import org.springframework.dao.InvalidDataAccessApiUsageException; @@ -52,6 +37,15 @@ import org.springframework.data.relational.core.mapping.RelationalMappingContext import org.springframework.data.relational.core.sql.SqlIdentifier; import org.springframework.r2dbc.core.Parameter; +import java.time.Instant; +import java.time.LocalDateTime; +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.*; + /** * Unit tests for {@link MappingR2dbcConverter}. * @@ -266,43 +260,73 @@ public class MappingR2dbcConverterUnitTests { assertThat(row).containsEntry(SqlIdentifier.unquoted("id"), Parameter.from(42L)); } - @AllArgsConstructor static class Person { - @Id String id; + @Id + String id; String firstname, lastname; Instant instant; LocalDateTime localDateTime; + + public Person(String id, String firstname, String lastname, Instant instant, LocalDateTime localDateTime) { + this.id = id; + this.firstname = firstname; + this.lastname = lastname; + this.instant = instant; + this.localDateTime = localDateTime; + } } - @Getter - @Setter - @RequiredArgsConstructor static class ConstructorAndPropertyPopulation { final String firstname; String lastname; + + public ConstructorAndPropertyPopulation(String firstname) { + this.firstname = firstname; + } + + public String getFirstname() { + return this.firstname; + } + + public String getLastname() { + return this.lastname; + } + + public void setLastname(String lastname) { + this.lastname = lastname; + } } - @AllArgsConstructor static class WithEnum { - @Id String id; + @Id + String id; Condition condition; + + public WithEnum(String id, Condition condition) { + this.id = id; + this.condition = condition; + } } enum Condition { Mint, Used } - @AllArgsConstructor static class PersonWithConversions { - @Id String id; + @Id + String id; Map nested; NonMappableEntity unsupported; + + public PersonWithConversions(String id, Map nested, NonMappableEntity unsupported) { + this.id = id; + this.nested = nested; + this.unsupported = unsupported; + } } - @RequiredArgsConstructor - static class WithPrimitiveId { - - @Id final long id; + record WithPrimitiveId ( + @Id long id){ } static class CustomConversionPerson { diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/convert/MySqlMappingR2dbcConverterUnitTests.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/convert/MySqlMappingR2dbcConverterUnitTests.java index 6266b4b6..e4389fe4 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/convert/MySqlMappingR2dbcConverterUnitTests.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/convert/MySqlMappingR2dbcConverterUnitTests.java @@ -21,7 +21,6 @@ import io.r2dbc.spi.R2dbcType; import io.r2dbc.spi.test.MockColumnMetadata; import io.r2dbc.spi.test.MockRow; import io.r2dbc.spi.test.MockRowMetadata; -import lombok.Value; import java.util.ArrayList; import java.util.Collections; @@ -29,7 +28,6 @@ import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - import org.springframework.data.convert.CustomConversions; import org.springframework.data.r2dbc.dialect.MySqlDialect; import org.springframework.data.r2dbc.mapping.OutboundRow; @@ -101,19 +99,15 @@ class MySqlMappingR2dbcConverterUnitTests { OutboundRowAssert.assertThat(row).containsColumnWithValue("state", (byte) 3); } - @Value - private static class BooleanMapping { + record BooleanMapping( - Integer id; - boolean flag1; - boolean flag2; + Integer id, boolean flag1, boolean flag2) { } - @Value - private static class WithByte { + record WithByte ( - Integer id; - byte state; + Integer id, + byte state){ } } diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/convert/PostgresMappingR2dbcConverterUnitTests.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/convert/PostgresMappingR2dbcConverterUnitTests.java index 8e9b8c2f..0c5af02d 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/convert/PostgresMappingR2dbcConverterUnitTests.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/convert/PostgresMappingR2dbcConverterUnitTests.java @@ -22,7 +22,6 @@ import io.r2dbc.spi.R2dbcType; import io.r2dbc.spi.test.MockColumnMetadata; import io.r2dbc.spi.test.MockRow; import io.r2dbc.spi.test.MockRowMetadata; -import lombok.AllArgsConstructor; import java.util.ArrayList; import java.util.Arrays; @@ -32,7 +31,6 @@ import java.util.Set; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.ConditionalConverter; import org.springframework.core.convert.converter.GenericConverter; @@ -134,28 +132,19 @@ class PostgresMappingR2dbcConverterUnitTests { assertThat(parameter.getValue()).isInstanceOf(Json.class); } - @AllArgsConstructor - static class JsonPerson { - - @Id Long id; - - Json jsonValue; + record JsonPerson( + @Id Long id, + Json jsonValue) { } - @AllArgsConstructor - static class ConvertedJson { - - @Id Long id; - - String jsonString; - - byte[] jsonBytes; + record ConvertedJson( + @Id Long id, + String jsonString, + byte[] jsonBytes) { } - @AllArgsConstructor - static class WithJsonHolder { - - JsonHolder holder; + record WithJsonHolder( + JsonHolder holder) { } @ReadingConverter @@ -200,10 +189,7 @@ class PostgresMappingR2dbcConverterUnitTests { } } - @AllArgsConstructor - private static class JsonHolder { - - private final Json json; + record JsonHolder(Json json) { } diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/core/PostgresIntegrationTests.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/core/PostgresIntegrationTests.java index eec02e52..03a94373 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/core/PostgresIntegrationTests.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/core/PostgresIntegrationTests.java @@ -35,8 +35,6 @@ import io.r2dbc.postgresql.codec.Polygon; import io.r2dbc.postgresql.extension.CodecRegistrar; import io.r2dbc.spi.Blob; import io.r2dbc.spi.ConnectionFactory; -import lombok.AllArgsConstructor; -import lombok.Data; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -46,6 +44,7 @@ import java.nio.charset.StandardCharsets; import java.time.Duration; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.concurrent.CompletableFuture; import javax.sql.DataSource; @@ -224,7 +223,7 @@ public class PostgresIntegrationTests extends R2dbcIntegrationTestSupport { .as(StepVerifier::create) // .consumeNextWith(actual -> { - assertThat(actual.getInterval()).isEqualTo(entityWithInterval.interval); + assertThat(actual.interval).isEqualTo(entityWithInterval.interval); }).verifyComplete(); } @@ -257,8 +256,8 @@ public class PostgresIntegrationTests extends R2dbcIntegrationTestSupport { CompletableFuture cf = Mono.from(actual.byteBlob.stream()).map(Unpooled::wrappedBuffer) .map(ByteBufUtil::getBytes).toFuture(); - assertThat(actual.getByteArray()).isEqualTo(content); - assertThat(getBytes(Unpooled.wrappedBuffer(actual.getByteBuffer()))).isEqualTo(content); + assertThat(actual.byteArray).isEqualTo(content); + assertThat(getBytes(Unpooled.wrappedBuffer(actual.byteBuffer))).isEqualTo(content); assertThat(cf.join()).isEqualTo(content); }).verifyComplete(); @@ -278,21 +277,23 @@ public class PostgresIntegrationTests extends R2dbcIntegrationTestSupport { CompletableFuture cf = Mono.from(actual.byteBlob.stream()).map(Unpooled::wrappedBuffer) .map(ByteBufUtil::getBytes).toFuture(); - assertThat(actual.getByteArray()).isEqualTo("foo".getBytes(StandardCharsets.UTF_8)); - assertThat(getBytes(Unpooled.wrappedBuffer(actual.getByteBuffer()))).isEqualTo(content); + assertThat(actual.byteArray).isEqualTo("foo".getBytes(StandardCharsets.UTF_8)); + assertThat(getBytes(Unpooled.wrappedBuffer(actual.byteBuffer))).isEqualTo(content); assertThat(cf.join()).isEqualTo(content); }).verifyComplete(); } - @Data - @AllArgsConstructor static class EntityWithEnum { @Id long id; State myState; + + public EntityWithEnum(long id, State myState) { + this.id = id; + this.myState = myState; + } } @Table("with_arrays") - @AllArgsConstructor static class EntityWithArrays { @Id Integer id; @@ -300,9 +301,17 @@ public class PostgresIntegrationTests extends R2dbcIntegrationTestSupport { int[] primitiveArray; int[][] multidimensionalArray; List collectionArray; + + public EntityWithArrays(Integer id, Integer[] boxedArray, int[] primitiveArray, int[][] multidimensionalArray, + List collectionArray) { + this.id = id; + this.boxedArray = boxedArray; + this.primitiveArray = primitiveArray; + this.multidimensionalArray = multidimensionalArray; + this.collectionArray = collectionArray; + } } - @Data static class GeoType { @Id Integer id; @@ -319,9 +328,21 @@ public class PostgresIntegrationTests extends R2dbcIntegrationTestSupport { org.springframework.data.geo.Circle springDataCircle; org.springframework.data.geo.Point springDataPoint; org.springframework.data.geo.Polygon springDataPolygon; + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + GeoType geoType = (GeoType) o; + return Objects.equals(id, geoType.id) && Objects.equals(thePoint, geoType.thePoint) && Objects.equals(theBox, geoType.theBox) && Objects.equals(theCircle, geoType.theCircle) && Objects.equals(theLine, geoType.theLine) && Objects.equals(theLseg, geoType.theLseg) && Objects.equals(thePath, geoType.thePath) && Objects.equals(thePolygon, geoType.thePolygon) && Objects.equals(springDataBox, geoType.springDataBox) && Objects.equals(springDataCircle, geoType.springDataCircle) && Objects.equals(springDataPoint, geoType.springDataPoint) && Objects.equals(springDataPolygon, geoType.springDataPolygon); + } + + @Override + public int hashCode() { + return Objects.hash(id, thePoint, theBox, theCircle, theLine, theLseg, thePath, thePolygon, springDataBox, springDataCircle, springDataPoint, springDataPolygon); + } } - @Data @Table("with_interval") static class EntityWithInterval { @@ -331,7 +352,6 @@ public class PostgresIntegrationTests extends R2dbcIntegrationTestSupport { } - @Data @Table("with_blobs") static class WithBlobs { @@ -342,5 +362,4 @@ public class PostgresIntegrationTests extends R2dbcIntegrationTestSupport { Blob byteBlob; } - } diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/core/PostgresReactiveDataAccessStrategyTests.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/core/PostgresReactiveDataAccessStrategyTests.java index 7928429f..8014e08b 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/core/PostgresReactiveDataAccessStrategyTests.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/core/PostgresReactiveDataAccessStrategyTests.java @@ -15,10 +15,15 @@ */ package org.springframework.data.r2dbc.core; -import static org.springframework.data.r2dbc.testing.Assertions.*; - import io.r2dbc.postgresql.codec.Interval; -import lombok.RequiredArgsConstructor; +import org.junit.jupiter.api.Test; +import org.springframework.core.convert.converter.Converter; +import org.springframework.data.convert.ReadingConverter; +import org.springframework.data.convert.WritingConverter; +import org.springframework.data.r2dbc.convert.EnumWriteSupport; +import org.springframework.data.r2dbc.dialect.PostgresDialect; +import org.springframework.data.r2dbc.mapping.OutboundRow; +import org.springframework.data.relational.core.sql.SqlIdentifier; import java.time.Duration; import java.util.ArrayList; @@ -28,14 +33,7 @@ import java.util.EnumSet; import java.util.List; import java.util.Set; -import org.junit.jupiter.api.Test; -import org.springframework.core.convert.converter.Converter; -import org.springframework.data.convert.ReadingConverter; -import org.springframework.data.convert.WritingConverter; -import org.springframework.data.r2dbc.convert.EnumWriteSupport; -import org.springframework.data.r2dbc.dialect.PostgresDialect; -import org.springframework.data.r2dbc.mapping.OutboundRow; -import org.springframework.data.relational.core.sql.SqlIdentifier; +import static org.springframework.data.r2dbc.testing.Assertions.*; /** * {@link PostgresDialect} specific tests for {@link ReactiveDataAccessStrategy}. @@ -217,16 +215,22 @@ public class PostgresReactiveDataAccessStrategyTests extends ReactiveDataAccessS assertThat(outboundRow).withColumn("enum_list").isEmpty().hasType(MyEnum[].class); } - @RequiredArgsConstructor static class WithMultidimensionalArray { final int[][] myarray; + + public WithMultidimensionalArray(int[][] myarray) { + this.myarray = myarray; + } } - @RequiredArgsConstructor static class WithIntegerCollection { final List myarray; + + public WithIntegerCollection(List myarray) { + this.myarray = myarray; + } } static class WithArray { diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplateUnitTests.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplateUnitTests.java index d7cf608c..26581dde 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplateUnitTests.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplateUnitTests.java @@ -15,28 +15,13 @@ */ package org.springframework.data.r2dbc.core; -import static org.assertj.core.api.Assertions.*; -import static org.mockito.Mockito.*; - import io.r2dbc.spi.R2dbcType; import io.r2dbc.spi.test.MockColumnMetadata; import io.r2dbc.spi.test.MockResult; import io.r2dbc.spi.test.MockRow; import io.r2dbc.spi.test.MockRowMetadata; -import lombok.Value; -import lombok.With; -import org.springframework.data.relational.core.mapping.InsertOnlyProperty; -import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; - -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - import org.springframework.beans.factory.ObjectFactory; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.Id; @@ -55,6 +40,7 @@ import org.springframework.data.r2dbc.mapping.event.BeforeSaveCallback; import org.springframework.data.r2dbc.mapping.event.ReactiveAuditingEntityCallback; import org.springframework.data.r2dbc.testing.StatementRecorder; import org.springframework.data.relational.core.mapping.Column; +import org.springframework.data.relational.core.mapping.InsertOnlyProperty; import org.springframework.data.relational.core.query.Criteria; import org.springframework.data.relational.core.query.Query; import org.springframework.data.relational.core.query.Update; @@ -63,6 +49,16 @@ import org.springframework.lang.Nullable; import org.springframework.r2dbc.core.DatabaseClient; import org.springframework.r2dbc.core.Parameter; import org.springframework.util.CollectionUtils; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.*; /** * Unit tests for {@link R2dbcEntityTemplate}. @@ -325,7 +321,7 @@ public class R2dbcEntityTemplateUnitTests { entityTemplate.insert(new VersionedPerson("id", 0, "bar")).as(StepVerifier::create) // .assertNext(actual -> { - assertThat(actual.getVersion()).isEqualTo(1); + assertThat(actual.version()).isEqualTo(1); }) // .verifyComplete(); @@ -366,7 +362,7 @@ public class R2dbcEntityTemplateUnitTests { entityTemplate.insert(new VersionedPersonWithPrimitiveId(0, 0, "bar")).as(StepVerifier::create) // .assertNext(actual -> { - assertThat(actual.getVersion()).isEqualTo(1); + assertThat(actual.version()).isEqualTo(1); }) // .verifyComplete(); @@ -396,8 +392,8 @@ public class R2dbcEntityTemplateUnitTests { entityTemplate.insert(new WithAuditingAndOptimisticLocking(null, 0, "Walter", null, null)) // .as(StepVerifier::create) // .assertNext(actual -> { - assertThat(actual.getVersion()).isEqualTo(1); - assertThat(actual.getCreatedDate()).isNotNull(); + assertThat(actual.version()).isEqualTo(1); + assertThat(actual.createdDate()).isNotNull(); }) // .verifyComplete(); @@ -425,9 +421,9 @@ public class R2dbcEntityTemplateUnitTests { entityTemplate.update(new WithAuditingAndOptimisticLocking(null, 2, "Walter", null, null)) // .as(StepVerifier::create) // .assertNext(actual -> { - assertThat(actual.getVersion()).isEqualTo(3); - assertThat(actual.getCreatedDate()).isNull(); - assertThat(actual.getLastModifiedDate()).isNotNull(); + assertThat(actual.version()).isEqualTo(3); + assertThat(actual.createdDate()).isNull(); + assertThat(actual.lastModifiedDate()).isNotNull(); }) // .verifyComplete(); @@ -477,7 +473,7 @@ public class R2dbcEntityTemplateUnitTests { entityTemplate.update(new VersionedPerson("id", 1, "bar")).as(StepVerifier::create) // .assertNext(actual -> { - assertThat(actual.getVersion()).isEqualTo(2); + assertThat(actual.version()).isEqualTo(2); }) // .verifyComplete(); @@ -565,92 +561,135 @@ public class R2dbcEntityTemplateUnitTests { .containsEntry(1, Parameter.from(23L)); } - @Value - static class WithoutId { - - String name; + record WithoutId(String name){ } - @Value - @With - static class Person { - + record Person ( @Id - String id; + String id, @Column("THE_NAME") - String name; + String name, - String description; + String description){ public static Person empty() { return new Person(null, null, null); } + + public Person withId(String id) { + return this.id == id ? this : new Person(id, this.name, this.description); + } + + public Person withName(String name) { + return this.name == name ? this : new Person(this.id, name, this.description); + } + + public Person withDescription(String description) { + return this.description == description ? this : new Person(this.id, this.name, description); + } } - @Value - @With - private static class VersionedPerson { + record VersionedPerson( + @Id + String id, + @Version + long version, + String name){ + + public VersionedPerson withId(String id) { + return this.id == id ? this : new VersionedPerson(id, this.version, this.name); + } + + public VersionedPerson withVersion(long version) { + return this.version == version ? this : new VersionedPerson(this.id, version, this.name); + } + + public VersionedPerson withName(String name) { + return this.name == name ? this : new VersionedPerson(this.id, this.version, name); + } + } + + record PersonWithPrimitiveId ( + @Id + int id, + String name + ){ + public PersonWithPrimitiveId withId(int id) { + return this.id == id ? this : new PersonWithPrimitiveId(id, this.name); + } + + public PersonWithPrimitiveId withName(String name) { + return this.name == name ? this : new PersonWithPrimitiveId(this.id, name); + } + } + + record VersionedPersonWithPrimitiveId ( @Id - String id; + int id, @Version - long version; + long version, - String name; + String name){ + + public VersionedPersonWithPrimitiveId withId(int id) { + return this.id == id ? this : new VersionedPersonWithPrimitiveId(id, this.version, this.name); + } + + public VersionedPersonWithPrimitiveId withVersion(long version) { + return this.version == version ? this : new VersionedPersonWithPrimitiveId(this.id, version, this.name); + } + + public VersionedPersonWithPrimitiveId withName(String name) { + return this.name == name ? this : new VersionedPersonWithPrimitiveId(this.id, this.version, name); + } } - @Value - @With - private static class PersonWithPrimitiveId { + record WithAuditingAndOptimisticLocking( - @Id - int id; + @Id + String id, - String name; + @Version + long version, + + String name, + + @CreatedDate + LocalDateTime createdDate, + @LastModifiedDate + LocalDateTime lastModifiedDate) { + public WithAuditingAndOptimisticLocking withId(String id) { + return this.id == id ? this : new WithAuditingAndOptimisticLocking(id, version, name, createdDate, lastModifiedDate); + } + + public WithAuditingAndOptimisticLocking withVersion(long version) { + return this.version == version ? this : new WithAuditingAndOptimisticLocking(id, version, name, createdDate, lastModifiedDate); + } + + public WithAuditingAndOptimisticLocking withName(String name) { + return this.name == name ? this : new WithAuditingAndOptimisticLocking(id, version, name, createdDate, lastModifiedDate); + } + + public WithAuditingAndOptimisticLocking withCreatedDate(LocalDateTime createdDate) { + return this.createdDate == createdDate ? this : new WithAuditingAndOptimisticLocking(id, version, name, createdDate, lastModifiedDate); + } + + public WithAuditingAndOptimisticLocking withLastModifiedDate(LocalDateTime lastModifiedDate) { + return this.lastModifiedDate == lastModifiedDate ? this : new WithAuditingAndOptimisticLocking(id, version, name, createdDate, lastModifiedDate); + } } - @Value - @With - private static class VersionedPersonWithPrimitiveId { - + record WithInsertOnly ( @Id - int id; + Long id, - @Version - long version; - - String name; - } - - @Value - @With - private static class WithAuditingAndOptimisticLocking { - - @Id - String id; - - @Version - long version; - - String name; - - @CreatedDate - LocalDateTime createdDate; - @LastModifiedDate - LocalDateTime lastModifiedDate; - } - - @Value - private static class WithInsertOnly { - @Id - Long id; - - String name; + String name, @InsertOnlyProperty - String insertOnly; + String insertOnly){ } static class ValueCapturingEntityCallback { @@ -705,7 +744,7 @@ public class R2dbcEntityTemplateUnitTests { Person person = Person.empty() // .withId("after-save") // - .withName(entity.getName()); + .withName(entity.name()); return Mono.just(person); } @@ -720,7 +759,7 @@ public class R2dbcEntityTemplateUnitTests { capture(entity); Person person = Person.empty() // .withId("after-convert") // - .withName(entity.getName()); + .withName(entity.name()); return Mono.just(person); } diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/core/ReactiveDataAccessStrategyTestSupport.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/core/ReactiveDataAccessStrategyTestSupport.java index 3ce36b9a..5f6c78e2 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/core/ReactiveDataAccessStrategyTestSupport.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/core/ReactiveDataAccessStrategyTestSupport.java @@ -19,12 +19,10 @@ import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.*; import io.r2dbc.spi.Parameters; -import io.r2dbc.spi.R2dbcType; import io.r2dbc.spi.Row; import io.r2dbc.spi.RowMetadata; import io.r2dbc.spi.test.MockColumnMetadata; import io.r2dbc.spi.test.MockRowMetadata; -import lombok.Data; import java.math.BigDecimal; import java.math.BigInteger; @@ -38,7 +36,6 @@ import java.util.function.BiConsumer; import java.util.function.Function; import org.junit.jupiter.api.Test; - import org.springframework.data.annotation.ReadOnlyProperty; import org.springframework.data.r2dbc.dialect.R2dbcDialect; import org.springframework.data.relational.core.sql.SqlIdentifier; @@ -56,130 +53,127 @@ public abstract class ReactiveDataAccessStrategyTestSupport { @Test // gh-85 void shouldReadAndWriteString() { - testType(PrimitiveTypes::setString, PrimitiveTypes::getString, "foo", "string"); + testType((pt, s) -> pt.string = s, pt -> pt.string, "foo", "string"); } @Test // gh-85 void shouldReadAndWriteCharacter() { - testType(PrimitiveTypes::setCharacter, PrimitiveTypes::getCharacter, 'f', "character"); + testType((pt, c) -> pt.character = c, pt -> pt.character, 'f', "character"); } @Test // gh-85 void shouldReadAndWriteBoolean() { - testType(PrimitiveTypes::setBooleanValue, PrimitiveTypes::isBooleanValue, true, "boolean_value"); + testType((pt, b) -> pt.booleanValue = b, pt -> pt.booleanValue, true, "boolean_value"); } @Test // gh-85 void shouldReadAndWriteBoxedBoolean() { - testType(PrimitiveTypes::setBoxedBooleanValue, PrimitiveTypes::getBoxedBooleanValue, true, "boxed_boolean_value"); + testType((pt, b) -> pt.boxedBooleanValue = b, pt -> pt.boxedBooleanValue, true, "boxed_boolean_value"); } @Test // gh-85 void shouldReadAndWriteByte() { - testType(PrimitiveTypes::setByteValue, PrimitiveTypes::getByteValue, (byte) 123, "byte_value"); + testType((pt, b) -> pt.byteValue = b, pt -> pt.byteValue, (byte) 123, "byte_value"); } @Test // gh-85 void shouldReadAndWriteBoxedByte() { - testType(PrimitiveTypes::setBoxedByteValue, PrimitiveTypes::getBoxedByteValue, (byte) 123, "boxed_byte_value"); + testType((pt, b) -> pt.boxedByteValue = b, pt -> pt.boxedByteValue, (byte) 123, "boxed_byte_value"); } @Test // gh-85 void shouldReadAndWriteShort() { - testType(PrimitiveTypes::setShortValue, PrimitiveTypes::getShortValue, (short) 123, "short_value"); + testType((pt, s) -> pt.shortValue = s, pt -> pt.shortValue, (short) 123, "short_value"); } @Test // gh-85 void shouldReadAndWriteBoxedShort() { - testType(PrimitiveTypes::setBoxedShortValue, PrimitiveTypes::getBoxedShortValue, (short) 123, "boxed_short_value"); + testType((pt, b) -> pt.boxedShortValue = b, pt -> pt.boxedShortValue, (short) 123, "boxed_short_value"); } @Test // gh-85 void shouldReadAndWriteInteger() { - testType(PrimitiveTypes::setIntValue, PrimitiveTypes::getIntValue, 123, "int_value"); + testType((pt, i) -> pt.intValue = i, pt -> pt.intValue, 123, "int_value"); } @Test // gh-85 void shouldReadAndWriteBoxedInteger() { - testType(PrimitiveTypes::setBoxedIntegerValue, PrimitiveTypes::getBoxedIntegerValue, 123, "boxed_integer_value"); + testType((pt, b) -> pt.boxedIntegerValue = b, pt -> pt.boxedIntegerValue, 123, "boxed_integer_value"); } @Test // gh-85 void shouldReadAndWriteLong() { - testType(PrimitiveTypes::setLongValue, PrimitiveTypes::getLongValue, 123L, "long_value"); + testType((pt, l) -> pt.longValue = l, pt -> pt.longValue, 123L, "long_value"); } @Test // gh-85 void shouldReadAndWriteBoxedLong() { - testType(PrimitiveTypes::setBoxedLongValue, PrimitiveTypes::getBoxedLongValue, 123L, "boxed_long_value"); + testType((pt, b) -> pt.boxedLongValue = b, pt -> pt.boxedLongValue, 123L, "boxed_long_value"); } @Test // gh-85 void shouldReadAndWriteFloat() { - testType(PrimitiveTypes::setFloatValue, PrimitiveTypes::getFloatValue, 0.1f, "float_value"); + testType((pt, f) -> pt.floatValue = f, pt -> pt.floatValue, 0.1f, "float_value"); } @Test // gh-85 void shouldReadAndWriteBoxedFloat() { - testType(PrimitiveTypes::setBoxedFloatValue, PrimitiveTypes::getBoxedFloatValue, 0.1f, "boxed_float_value"); + testType((pt, b) -> pt.boxedFloatValue = b, pt -> pt.boxedFloatValue, 0.1f, "boxed_float_value"); } @Test // gh-85 void shouldReadAndWriteDouble() { - testType(PrimitiveTypes::setDoubleValue, PrimitiveTypes::getDoubleValue, 0.1, "double_value"); + testType((pt, d) -> pt.doubleValue = d, pt -> pt.doubleValue, 0.1, "double_value"); } @Test // gh-85 void shouldReadAndWriteBoxedDouble() { - testType(PrimitiveTypes::setBoxedDoubleValue, PrimitiveTypes::getBoxedDoubleValue, 0.1, "boxed_double_value"); + testType((pt, b) -> pt.boxedDoubleValue = b, pt -> pt.boxedDoubleValue, 0.1, "boxed_double_value"); } @Test // gh-85 void shouldReadAndWriteBigInteger() { - testType(PrimitiveTypes::setBigInteger, PrimitiveTypes::getBigInteger, BigInteger.TEN, "big_integer"); + testType((pt, b) -> pt.bigInteger = b, pt -> pt.bigInteger, BigInteger.TEN, "big_integer"); } @Test // gh-85 void shouldReadAndWriteBigDecimal() { - testType(PrimitiveTypes::setBigDecimal, PrimitiveTypes::getBigDecimal, new BigDecimal("100.123"), "big_decimal"); + testType((pt, b) -> pt.bigDecimal = b, pt -> pt.bigDecimal, new BigDecimal("100.123"), "big_decimal"); } @Test // gh-85 void shouldReadAndWriteLocalDate() { - testType(PrimitiveTypes::setLocalDate, PrimitiveTypes::getLocalDate, LocalDate.now(), "local_date"); + testType((pt, l) -> pt.localDate = l, pt -> pt.localDate, LocalDate.now(), "local_date"); } @Test // gh-85 void shouldReadAndWriteLocalTime() { - testType(PrimitiveTypes::setLocalTime, PrimitiveTypes::getLocalTime, LocalTime.now(), "local_time"); + testType((pt, l) -> pt.localTime = l, pt -> pt.localTime, LocalTime.now(), "local_time"); } @Test // gh-85 void shouldReadAndWriteLocalDateTime() { - testType(PrimitiveTypes::setLocalDateTime, PrimitiveTypes::getLocalDateTime, LocalDateTime.now(), - "local_date_time"); + testType((pt, l) -> pt.localDateTime = l, pt -> pt.localDateTime, LocalDateTime.now(), "local_date_time"); } @Test // gh-85 void shouldReadAndWriteZonedDateTime() { - testType(PrimitiveTypes::setZonedDateTime, PrimitiveTypes::getZonedDateTime, ZonedDateTime.now(), - "zoned_date_time"); + testType((pt, z) -> pt.zonedDateTime = z, pt -> pt.zonedDateTime, ZonedDateTime.now(), "zoned_date_time"); } @Test // gh-85 void shouldReadAndWriteOffsetDateTime() { - testType(PrimitiveTypes::setOffsetDateTime, PrimitiveTypes::getOffsetDateTime, OffsetDateTime.now(), - "offset_date_time"); + testType((pt, o) -> pt.offsetDateTime = o, pt -> pt.offsetDateTime, OffsetDateTime.now(), "offset_date_time"); } @Test // gh-85 void shouldReadAndWriteUuid() { - testType(PrimitiveTypes::setUuid, PrimitiveTypes::getUuid, UUID.randomUUID(), "uuid"); + testType((pt, u) -> pt.uuid = u, pt -> pt.uuid, UUID.randomUUID(), "uuid"); } @Test // gh-186 void shouldReadAndWriteBinary() { - testType(PrimitiveTypes::setBinary, PrimitiveTypes::getBinary, "hello".getBytes(), "binary"); + testType((pt, b) -> pt.binary = b, pt -> pt.binary, "hello".getBytes(), "binary"); } @Test // gh-354 @@ -187,9 +181,9 @@ public abstract class ReactiveDataAccessStrategyTestSupport { TypeWithReadOnlyFields toSave = new TypeWithReadOnlyFields(); - toSave.setWritableField("writable"); - toSave.setReadOnlyField("readonly"); - toSave.setReadOnlyArrayField("readonly_array".getBytes()); + toSave.writableField = "writable"; + toSave.readOnlyField = "readonly"; + toSave.readOnlyArrayField = "readonly_array".getBytes(); assertThat(getStrategy().getOutboundRow(toSave)).containsOnlyKeys(SqlIdentifier.unquoted("writable_field")); } @@ -200,7 +194,9 @@ public abstract class ReactiveDataAccessStrategyTestSupport { ReactiveDataAccessStrategy strategy = getStrategy(); Row rowMock = mock(Row.class); RowMetadata metadataMock = MockRowMetadata.builder() - .columnMetadata(MockColumnMetadata.builder().name(fieldname).type(Parameters.in(testValue.getClass()).getType()).build()).build(); + .columnMetadata( + MockColumnMetadata.builder().name(fieldname).type(Parameters.in(testValue.getClass()).getType()).build()) + .build(); PrimitiveTypes toSave = new PrimitiveTypes(); setter.accept(toSave, testValue); @@ -215,7 +211,6 @@ public abstract class ReactiveDataAccessStrategyTestSupport { assertThat(getter.apply(loaded)).isEqualTo(testValue); } - @Data static class PrimitiveTypes { String string; @@ -251,7 +246,6 @@ public abstract class ReactiveDataAccessStrategyTestSupport { UUID uuid; } - @Data static class TypeWithReadOnlyFields { String writableField; @ReadOnlyProperty String readOnlyField; diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/dialect/DialectResolverUnitTests.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/dialect/DialectResolverUnitTests.java index 5fffdd8b..b8556778 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/dialect/DialectResolverUnitTests.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/dialect/DialectResolverUnitTests.java @@ -11,7 +11,6 @@ import io.r2dbc.postgresql.PostgresqlConnectionFactory; import io.r2dbc.spi.Connection; import io.r2dbc.spi.ConnectionFactory; import io.r2dbc.spi.ConnectionFactoryMetadata; -import lombok.RequiredArgsConstructor; import java.util.Optional; @@ -61,10 +60,7 @@ public class DialectResolverUnitTests { .isEqualTo(ExternalDialect.INSTANCE); } - @RequiredArgsConstructor - static class ExternalConnectionFactory implements ConnectionFactory { - - private final String name; + record ExternalConnectionFactory(String name) implements ConnectionFactory { @Override public Publisher create() { diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/documentation/QueryByExampleTests.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/documentation/QueryByExampleTests.java index f77966b0..7d209d51 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/documentation/QueryByExampleTests.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/documentation/QueryByExampleTests.java @@ -15,21 +15,19 @@ */ package org.springframework.data.r2dbc.documentation; -import static org.mockito.Mockito.*; -import static org.springframework.data.domain.ExampleMatcher.*; -import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.endsWith; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import reactor.core.publisher.Flux; -import reactor.test.StepVerifier; - import org.junit.jupiter.api.Test; import org.springframework.data.annotation.Id; import org.springframework.data.domain.Example; import org.springframework.data.domain.ExampleMatcher; import org.springframework.data.r2dbc.repository.R2dbcRepository; +import reactor.core.publisher.Flux; +import reactor.test.StepVerifier; + +import java.util.Objects; + +import static org.mockito.Mockito.*; +import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.endsWith; +import static org.springframework.data.domain.ExampleMatcher.*; /** * Code to demonstrate Query By Example in reference documentation. @@ -52,7 +50,7 @@ public class QueryByExampleTests { // tag::example[] Employee employee = new Employee(); // <1> - employee.setName("Frodo"); + employee.name= "Frodo"; Example example = Example.of(employee); // <2> @@ -79,8 +77,8 @@ public class QueryByExampleTests { // tag::example-2[] Employee employee = new Employee(); - employee.setName("Baggins"); - employee.setRole("ring bearer"); + employee.name = "Baggins"; + employee.role = "ring bearer"; ExampleMatcher matcher = matching() // <1> .withMatcher("name", endsWith()) // <2> @@ -100,14 +98,33 @@ public class QueryByExampleTests { .verifyComplete(); } - @Data - @NoArgsConstructor - @AllArgsConstructor public class Employee { private @Id Integer id; private String name; private String role; + + public Employee(Integer id, String name, String role) { + this.id = id; + this.name = name; + this.role = role; + } + + public Employee() { + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Employee employee = (Employee) o; + return Objects.equals(id, employee.id) && Objects.equals(name, employee.name) && Objects.equals(role, employee.role); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, role); + } } public interface EmployeeRepository extends R2dbcRepository {} diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/AbstractR2dbcRepositoryIntegrationTests.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/AbstractR2dbcRepositoryIntegrationTests.java index f00c3b7b..b89711c8 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/AbstractR2dbcRepositoryIntegrationTests.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/AbstractR2dbcRepositoryIntegrationTests.java @@ -15,25 +15,7 @@ */ package org.springframework.data.r2dbc.repository; -import static org.assertj.core.api.Assertions.*; - import io.r2dbc.spi.ConnectionFactory; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.Value; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Hooks; -import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; - -import java.util.Arrays; -import java.util.Map; -import java.util.stream.IntStream; - -import javax.sql.DataSource; - import org.assertj.core.api.Condition; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -53,6 +35,17 @@ import org.springframework.data.repository.reactive.ReactiveCrudRepository; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.r2dbc.connection.R2dbcTransactionManager; import org.springframework.transaction.reactive.TransactionalOperator; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Hooks; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; + +import javax.sql.DataSource; +import java.util.Arrays; +import java.util.Map; +import java.util.stream.IntStream; + +import static org.assertj.core.api.Assertions.*; /** * Abstract base class for integration tests for {@link LegoSetRepository} using {@link R2dbcRepositoryFactory}. @@ -469,10 +462,7 @@ public abstract class AbstractR2dbcRepositoryIntegrationTests extends R2dbcInteg String getName(); } - @Getter - @Setter @Table("legoset") - @NoArgsConstructor public static class LegoSet extends Lego implements Buildable { String name; Integer manual; @@ -489,25 +479,98 @@ public abstract class AbstractR2dbcRepositoryIntegrationTests extends R2dbcInteg this(id, name, manual); this.flag = flag; } + + public LegoSet() { + } + + public String getName() { + return this.name; + } + + public Integer getManual() { + return this.manual; + } + + public boolean isFlag() { + return this.flag; + } + + public void setName(String name) { + this.name = name; + } + + public void setManual(Integer manual) { + this.manual = manual; + } + + public void setFlag(boolean flag) { + this.flag = flag; + } } - @AllArgsConstructor - @NoArgsConstructor - @Getter - @Setter static class Lego { - @Id Integer id; + @Id + Integer id; + + public Lego(Integer id) { + this.id = id; + } + + public Lego() { + } + + public Integer getId() { + return this.id; + } + + public void setId(Integer id) { + this.id = id; + } } - @Value - static class LegoDto { - String name; - String unknown; + static final class LegoDto { + private final String name; + private final String unknown; public LegoDto(String name, String unknown) { this.name = name; this.unknown = unknown; } + + public String getName() { + return this.name; + } + + public String getUnknown() { + return this.unknown; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof LegoDto)) return false; + final LegoDto other = (LegoDto) o; + final Object this$name = this.getName(); + final Object other$name = other.getName(); + if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false; + final Object this$unknown = this.getUnknown(); + final Object other$unknown = other.getUnknown(); + if (this$unknown == null ? other$unknown != null : !this$unknown.equals(other$unknown)) return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $name = this.getName(); + result = result * PRIME + ($name == null ? 43 : $name.hashCode()); + final Object $unknown = this.getUnknown(); + result = result * PRIME + ($unknown == null ? 43 : $unknown.hashCode()); + return result; + } + + public String toString() { + return "AbstractR2dbcRepositoryIntegrationTests.LegoDto(name=" + this.getName() + ", unknown=" + this.getUnknown() + ")"; + } } interface Named { diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/AbstractR2dbcRepositoryWithMixedCaseNamesIntegrationTests.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/AbstractR2dbcRepositoryWithMixedCaseNamesIntegrationTests.java index f8b1c973..b8f501d8 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/AbstractR2dbcRepositoryWithMixedCaseNamesIntegrationTests.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/AbstractR2dbcRepositoryWithMixedCaseNamesIntegrationTests.java @@ -15,21 +15,7 @@ */ package org.springframework.data.r2dbc.repository; -import static org.assertj.core.api.Assertions.*; - import io.r2dbc.spi.ConnectionFactory; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import reactor.test.StepVerifier; - -import java.time.Duration; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -import javax.sql.DataSource; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -42,6 +28,15 @@ import org.springframework.data.relational.core.mapping.Table; import org.springframework.data.repository.reactive.ReactiveCrudRepository; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.lang.Nullable; +import reactor.test.StepVerifier; + +import javax.sql.DataSource; +import java.time.Duration; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + +import static org.assertj.core.api.Assertions.*; /** * Abstract base class for integration tests for {@link LegoSetRepository} with table and column names that contain @@ -120,19 +115,19 @@ public abstract class AbstractR2dbcRepositoryWithMixedCaseNamesIntegrationTests interface LegoSetRepository extends ReactiveCrudRepository {} - @Getter - @Setter @Table("LegoSet") - @NoArgsConstructor public static class LegoSet { @Nullable @Column("Id") - @Id Integer id; + @Id + Integer id; - @Column("Name") String name; + @Column("Name") + String name; - @Column("Manual") Integer manual; + @Column("Manual") + Integer manual; @PersistenceCreator LegoSet(@Nullable Integer id, String name, Integer manual) { @@ -141,6 +136,9 @@ public abstract class AbstractR2dbcRepositoryWithMixedCaseNamesIntegrationTests this.manual = manual; } + public LegoSet() { + } + @Override public boolean equals(@Nullable Object o) { if (this == o) @@ -156,5 +154,30 @@ public abstract class AbstractR2dbcRepositoryWithMixedCaseNamesIntegrationTests public int hashCode() { return Objects.hash(id, name, manual); } + + @Nullable + public Integer getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public Integer getManual() { + return this.manual; + } + + public void setId(@Nullable Integer id) { + this.id = id; + } + + public void setName(String name) { + this.name = name; + } + + public void setManual(Integer manual) { + this.manual = manual; + } } } diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/ConvertingR2dbcRepositoryIntegrationTests.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/ConvertingR2dbcRepositoryIntegrationTests.java index 5ed5e727..3c6de5ea 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/ConvertingR2dbcRepositoryIntegrationTests.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/ConvertingR2dbcRepositoryIntegrationTests.java @@ -19,9 +19,6 @@ import static org.assertj.core.api.Assertions.*; import io.r2dbc.spi.ConnectionFactory; import io.r2dbc.spi.Row; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; import reactor.test.StepVerifier; import java.util.Arrays; @@ -111,7 +108,7 @@ public class ConvertingR2dbcRepositoryIntegrationTests { public void shouldInsertAndReadItems() { ConvertedEntity entity = new ConvertedEntity(); - entity.setName("name"); + entity.name = "name"; repository.save(entity) // .as(StepVerifier::create) // @@ -121,7 +118,7 @@ public class ConvertingR2dbcRepositoryIntegrationTests { repository.findAll() // .as(StepVerifier::create) // .consumeNextWith(actual -> { - assertThat(actual.getName()).isEqualTo("read: prefixed: name"); + assertThat(actual.name).isEqualTo("read: prefixed: name"); }).verifyComplete(); } @@ -129,9 +126,6 @@ public class ConvertingR2dbcRepositoryIntegrationTests { } - @AllArgsConstructor - @NoArgsConstructor - @Data static class ConvertedEntity { @Id Integer id; String name; @@ -147,11 +141,11 @@ public class ConvertingR2dbcRepositoryIntegrationTests { OutboundRow outboundRow = new OutboundRow(); - if (convertedEntity.getId() != null) { - outboundRow.put("id", Parameter.from(convertedEntity.getId())); + if (convertedEntity.id != null) { + outboundRow.put("id", Parameter.from(convertedEntity.id)); } - outboundRow.put("name", Parameter.from("prefixed: " + convertedEntity.getName())); + outboundRow.put("name", Parameter.from("prefixed: " + convertedEntity.name)); return outboundRow; } @@ -166,8 +160,8 @@ public class ConvertingR2dbcRepositoryIntegrationTests { public ConvertedEntity convert(Row source) { ConvertedEntity entity = new ConvertedEntity(); - entity.setId(source.get("id", Integer.class)); - entity.setName("read: " + source.get("name", String.class)); + entity.id = source.get("id", Integer.class); + entity.name = "read: " + source.get("name", String.class); return entity; } diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/H2R2dbcRepositoryIntegrationTests.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/H2R2dbcRepositoryIntegrationTests.java index d639454e..be7786e7 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/H2R2dbcRepositoryIntegrationTests.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/H2R2dbcRepositoryIntegrationTests.java @@ -15,27 +15,11 @@ */ package org.springframework.data.r2dbc.repository; -import static org.assertj.core.api.Assertions.*; - import io.r2dbc.spi.ConnectionFactory; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import javax.sql.DataSource; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.reactivestreams.Publisher; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan.Filter; @@ -52,6 +36,16 @@ import org.springframework.data.relational.core.sql.SqlIdentifier; import org.springframework.data.repository.reactive.ReactiveCrudRepository; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; + +import javax.sql.DataSource; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import static org.assertj.core.api.Assertions.*; /** * Integration tests for {@link LegoSetRepository} using {@link R2dbcRepositoryFactory} against H2. @@ -218,12 +212,21 @@ public class H2R2dbcRepositoryIntegrationTests extends AbstractR2dbcRepositoryIn interface IdOnlyEntityRepository extends ReactiveCrudRepository {} - @Getter - @Setter @Table("id_only") - @NoArgsConstructor static class IdOnlyEntity { - @Id Integer id; + @Id + Integer id; + + public IdOnlyEntity() { + } + + public Integer getId() { + return this.id; + } + + public void setId(Integer id) { + this.id = id; + } } static class AfterConvertCallbackRecorder implements AfterConvertCallback { diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/PostgresR2dbcRepositoryIntegrationTests.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/PostgresR2dbcRepositoryIntegrationTests.java index 59732a3f..c995059d 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/PostgresR2dbcRepositoryIntegrationTests.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/PostgresR2dbcRepositoryIntegrationTests.java @@ -15,24 +15,11 @@ */ package org.springframework.data.r2dbc.repository; -import static org.assertj.core.api.Assertions.*; - import io.r2dbc.postgresql.codec.Json; import io.r2dbc.spi.ConnectionFactory; -import lombok.AllArgsConstructor; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; - -import java.util.Collections; -import java.util.Map; - -import javax.sql.DataSource; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.RegisterExtension; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan.Filter; @@ -51,6 +38,15 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.r2dbc.core.DatabaseClient; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; + +import javax.sql.DataSource; +import java.util.Collections; +import java.util.Map; + +import static org.assertj.core.api.Assertions.*; /** * Integration tests for {@link LegoSetRepository} using {@link R2dbcRepositoryFactory} against Postgres. @@ -175,25 +171,35 @@ public class PostgresR2dbcRepositoryIntegrationTests extends AbstractR2dbcReposi }).verifyComplete(); } - @AllArgsConstructor static class WithJson { - @Id Long id; + @Id + Long id; Json jsonValue; + + public WithJson(Long id, Json jsonValue) { + this.id = id; + this.jsonValue = jsonValue; + } } interface WithJsonRepository extends ReactiveCrudRepository { } - @AllArgsConstructor @Table("with_hstore") static class WithHStore { - @Id Long id; + @Id + Long id; Map hstoreValue; + + public WithHStore(Long id, Map hstoreValue) { + this.id = id; + this.hstoreValue = hstoreValue; + } } interface WithHStoreRepository extends ReactiveCrudRepository { diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/query/PartTreeR2dbcQueryUnitTests.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/query/PartTreeR2dbcQueryUnitTests.java index a92180a2..99c5410b 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/query/PartTreeR2dbcQueryUnitTests.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/query/PartTreeR2dbcQueryUnitTests.java @@ -19,7 +19,6 @@ import static org.mockito.Mockito.*; import io.r2dbc.spi.ConnectionFactory; import io.r2dbc.spi.ConnectionFactoryMetadata; -import lombok.Data; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -1005,7 +1004,6 @@ class PartTreeR2dbcQueryUnitTests { } @Table("users") - @Data private static class User { private @Id Long id; @@ -1017,7 +1015,6 @@ class PartTreeR2dbcQueryUnitTests { } @Table("users") - @Data private static class WithoutId { private String firstName; diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/support/AbstractSimpleR2dbcRepositoryIntegrationTests.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/support/AbstractSimpleR2dbcRepositoryIntegrationTests.java index 380c629f..917ab83c 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/support/AbstractSimpleR2dbcRepositoryIntegrationTests.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/support/AbstractSimpleR2dbcRepositoryIntegrationTests.java @@ -15,25 +15,6 @@ */ package org.springframework.data.r2dbc.repository.support; -import static org.assertj.core.api.Assertions.*; -import static org.springframework.data.domain.ExampleMatcher.*; -import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.*; -import static org.springframework.data.domain.ExampleMatcher.StringMatcher.*; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import javax.sql.DataSource; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -56,6 +37,21 @@ import org.springframework.data.relational.repository.support.MappingRelationalE import org.springframework.data.repository.query.FluentQuery; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.r2dbc.core.DatabaseClient; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; + +import javax.sql.DataSource; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +import static org.assertj.core.api.Assertions.*; +import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.*; +import static org.springframework.data.domain.ExampleMatcher.StringMatcher.*; +import static org.springframework.data.domain.ExampleMatcher.*; /** * Abstract integration tests for {@link SimpleR2dbcRepository} to be ran against various databases. @@ -982,56 +978,160 @@ public abstract class AbstractSimpleR2dbcRepositoryIntegrationTests extends R2db .verifyComplete(); } - @Data @Table("legoset") - @AllArgsConstructor - @NoArgsConstructor static class LegoSet { - @Id int id; + @Id + int id; String name; Integer manual; + + public LegoSet(int id, String name, Integer manual) { + this.id = id; + this.name = name; + this.manual = manual; + } + + public LegoSet() { + } + + public int getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public Integer getManual() { + return this.manual; + } + + public void setId(int id) { + this.id = id; + } + + public void setName(String name) { + this.name = name; + } + + public void setManual(Integer manual) { + this.manual = manual; + } } interface LegoSetProjection { String getName(); } - @Data @Table("legoset") - @AllArgsConstructor - @NoArgsConstructor static class LegoSetWithNonScalarId { - @Id Integer id; + @Id + Integer id; String name; Integer manual; String extra; + + public LegoSetWithNonScalarId(Integer id, String name, Integer manual, String extra) { + this.id = id; + this.name = name; + this.manual = manual; + this.extra = extra; + } + + public LegoSetWithNonScalarId() { + } + + public Integer getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public Integer getManual() { + return this.manual; + } + + public String getExtra() { + return this.extra; + } + + public void setId(Integer id) { + this.id = id; + } + + public void setName(String name) { + this.name = name; + } + + public void setManual(Integer manual) { + this.manual = manual; + } + + public void setExtra(String extra) { + this.extra = extra; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + LegoSetWithNonScalarId that = (LegoSetWithNonScalarId) o; + return Objects.equals(id, that.id) && Objects.equals(name, that.name) && Objects.equals(manual, that.manual) && Objects.equals(extra, that.extra); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, manual, extra); + } } - @Data @Table("legoset") - @NoArgsConstructor static class LegoSetVersionable extends LegoSet { - @Version Integer version; + @Version + Integer version; LegoSetVersionable(int id, String name, Integer manual, Integer version) { super(id, name, manual); this.version = version; } + + public LegoSetVersionable() { + } + + public Integer getVersion() { + return this.version; + } + + public void setVersion(Integer version) { + this.version = version; + } } - @Data @Table("legoset") - @NoArgsConstructor static class LegoSetPrimitiveVersionable extends LegoSet { - @Version int version; + @Version + int version; LegoSetPrimitiveVersionable(int id, String name, Integer manual, int version) { super(id, name, manual); this.version = version; } + + public LegoSetPrimitiveVersionable() { + } + + public int getVersion() { + return this.version; + } + + public void setVersion(int version) { + this.version = version; + } } } diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/support/H2SimpleR2dbcRepositoryIntegrationTests.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/support/H2SimpleR2dbcRepositoryIntegrationTests.java index 9fdd915b..1cb4721b 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/support/H2SimpleR2dbcRepositoryIntegrationTests.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/support/H2SimpleR2dbcRepositoryIntegrationTests.java @@ -15,17 +15,7 @@ */ package org.springframework.data.r2dbc.repository.support; -import static org.assertj.core.api.Assertions.*; - import io.r2dbc.spi.ConnectionFactory; -import lombok.AllArgsConstructor; -import lombok.Data; -import reactor.test.StepVerifier; - -import java.util.Map; - -import javax.sql.DataSource; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; @@ -43,6 +33,12 @@ import org.springframework.data.relational.repository.query.RelationalEntityInfo import org.springframework.data.relational.repository.support.MappingRelationalEntityInformation; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; +import reactor.test.StepVerifier; + +import javax.sql.DataSource; +import java.util.Map; + +import static org.assertj.core.api.Assertions.*; /** * Integration tests for {@link SimpleR2dbcRepository} against H2. @@ -121,13 +117,22 @@ public class H2SimpleR2dbcRepositoryIntegrationTests extends AbstractSimpleR2dbc }); } - @Data - @AllArgsConstructor static class AlwaysNew implements Persistable { - @Id Long id; + @Id + Long id; String name; + public AlwaysNew(Long id, String name) { + this.id = id; + this.name = name; + } + + @Override + public Long getId() { + return id; + } + @Override public boolean isNew() { return true; diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/testing/ExternalDatabase.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/testing/ExternalDatabase.java index ffef7451..621edac2 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/testing/ExternalDatabase.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/testing/ExternalDatabase.java @@ -15,8 +15,6 @@ */ package org.springframework.data.r2dbc.testing; -import lombok.Builder; - import java.io.IOException; import java.net.InetSocketAddress; import java.net.Socket; @@ -111,7 +109,6 @@ public abstract class ExternalDatabase implements BeforeAllCallback { /** * Provided (unmanaged resource) database connection coordinates. */ - @Builder public static class ProvidedDatabase extends ExternalDatabase { private final String hostname; @@ -121,6 +118,16 @@ public abstract class ExternalDatabase implements BeforeAllCallback { private final String database; private final String jdbcUrl; + public ProvidedDatabase(String hostname, int port, String username, String password, String database, + String jdbcUrl) { + this.hostname = hostname; + this.port = port; + this.username = username; + this.password = password; + this.database = database; + this.jdbcUrl = jdbcUrl; + } + public static ProvidedDatabaseBuilder builder() { return new ProvidedDatabaseBuilder(); } @@ -264,4 +271,46 @@ public abstract class ExternalDatabase implements BeforeAllCallback { throw new UnsupportedOperationException(getClass().getSimpleName()); } } + + static class ProvidedDatabaseBuilder { + private String hostname; + private int port; + private String username; + private String password; + private String database; + private String jdbcUrl; + + public ProvidedDatabaseBuilder hostname(String hostname) { + this.hostname = hostname; + return this; + } + + public ProvidedDatabaseBuilder port(Integer port) { + this.port = port; + return this; + } + + public ProvidedDatabaseBuilder username(String username) { + this.username = username; + return this; + } + + public ProvidedDatabaseBuilder password(String password) { + this.password = password; + return this; + } + + public ProvidedDatabaseBuilder database(String database) { + this.database = database; + return this; + } + public ProvidedDatabaseBuilder jdbcUrl(String jdbcUrl) { + this.jdbcUrl = jdbcUrl; + return this; + } + + public ProvidedDatabase build() { + return new ProvidedDatabase(hostname, port, username, password, database, jdbcUrl); + } + } } diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/testing/MariaDbTestSupport.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/testing/MariaDbTestSupport.java index c2d1b8c1..a4512a05 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/testing/MariaDbTestSupport.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/testing/MariaDbTestSupport.java @@ -17,8 +17,8 @@ package org.springframework.data.r2dbc.testing; import io.r2dbc.spi.ConnectionFactory; import io.r2dbc.spi.ConnectionFactoryOptions; -import lombok.SneakyThrows; +import java.sql.SQLException; import java.util.function.Supplier; import java.util.stream.Stream; @@ -152,16 +152,19 @@ public class MariaDbTestSupport { /** * Creates a new {@link DataSource} configured from the {@link ExternalDatabase}. */ - @SneakyThrows public static DataSource createDataSource(ExternalDatabase database) { - MariaDbDataSource dataSource = new MariaDbDataSource(); + try { + MariaDbDataSource dataSource = new MariaDbDataSource(); - dataSource.setUser(database.getUsername()); - dataSource.setPassword(database.getPassword()); - dataSource.setUrl( - String.format("jdbc:mariadb://%s:%d/%s?", database.getHostname(), database.getPort(), database.getDatabase())); + dataSource.setUser(database.getUsername()); + dataSource.setUrl(String.format("jdbc:mariadb://%s:%d/%s?", database.getHostname(), database.getPort(), + database.getDatabase())); + dataSource.setPassword(database.getPassword()); - return dataSource; + return dataSource; + } catch (SQLException e) { + throw new RuntimeException(e); + } } } diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/testing/MySqlDbTestSupport.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/testing/MySqlDbTestSupport.java index f988967a..576b2f25 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/testing/MySqlDbTestSupport.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/testing/MySqlDbTestSupport.java @@ -18,7 +18,6 @@ package org.springframework.data.r2dbc.testing; import io.asyncer.r2dbc.mysql.MySqlConnectionFactoryProvider; import io.r2dbc.spi.ConnectionFactory; import io.r2dbc.spi.ConnectionFactoryOptions; -import lombok.SneakyThrows; import java.util.function.Supplier; import java.util.stream.Stream; @@ -147,7 +146,6 @@ public class MySqlDbTestSupport { /** * Creates a new {@link DataSource} configured from the {@link ExternalDatabase}. */ - @SneakyThrows public static DataSource createDataSource(ExternalDatabase database) { MysqlDataSource dataSource = new MysqlDataSource(); diff --git a/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/BasicRelationalConverterUnitTests.java b/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/BasicRelationalConverterUnitTests.java index f74c758e..e058cb32 100644 --- a/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/BasicRelationalConverterUnitTests.java +++ b/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/BasicRelationalConverterUnitTests.java @@ -17,9 +17,6 @@ package org.springframework.data.relational.core.conversion; import static org.assertj.core.api.Assertions.*; -import lombok.Data; -import lombok.Value; - import java.util.Arrays; import java.util.List; import java.util.Set; @@ -49,7 +46,7 @@ class BasicRelationalConverterUnitTests { @BeforeEach public void before() throws Exception { - Set converters = ConverterBuilder.writing(MyValue.class, String.class, MyValue::getFoo) + Set converters = ConverterBuilder.writing(MyValue.class, String.class, MyValue::foo) .andReading(MyValue::new).getConverters(); CustomConversions conversions = new CustomConversions(CustomConversions.StoreConversions.NONE, converters); @@ -71,7 +68,7 @@ class BasicRelationalConverterUnitTests { RelationalPersistentProperty property = entity.getRequiredPersistentProperty("flag"); accessor.setProperty(property, "1"); - assertThat(instance.isFlag()).isTrue(); + assertThat(instance.flag).isTrue(); } @Test // DATAJDBC-235 @@ -93,8 +90,7 @@ class BasicRelationalConverterUnitTests { @Test // GH-1046 void shouldConvertArrayElementsToTargetElementType() throws NoSuchMethodException { - TypeInformation typeInformation = TypeInformation - .fromReturnTypeOf(EntityWithArray.class.getMethod("getFloats")); + TypeInformation typeInformation = TypeInformation.fromReturnTypeOf(EntityWithArray.class.getMethod("floats")); Double[] value = { 1.2d, 1.3d, 1.4d }; Object result = converter.readValue(value, typeInformation); assertThat(result).isEqualTo(Arrays.asList(1.2f, 1.3f, 1.4f)); @@ -109,7 +105,7 @@ class BasicRelationalConverterUnitTests { WithConstructorCreation result = converter.createInstance(entity, it -> "bar"); - assertThat(result.getFoo()).isEqualTo("bar"); + assertThat(result.foo).isEqualTo("bar"); } @Test // DATAJDBC-516 @@ -128,27 +124,19 @@ class BasicRelationalConverterUnitTests { assertThat(result).isEqualTo(new MyValue("hello-world")); } - @Data - static class EntityWithArray { - List floats; + record EntityWithArray(List floats) { } - @Data static class MyEntity { boolean flag; } - @Value - static class WithConstructorCreation { - String foo; + record WithConstructorCreation(String foo) { } - @Value - static class MyValue { - String foo; + record MyValue(String foo) { } - @Value static class MyEntityWithConvertibleProperty { MyValue myValue; diff --git a/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/DbActionTestSupport.java b/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/DbActionTestSupport.java index 1679eb03..b17f6de1 100644 --- a/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/DbActionTestSupport.java +++ b/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/DbActionTestSupport.java @@ -15,18 +15,19 @@ */ package org.springframework.data.relational.core.conversion; -import lombok.experimental.UtilityClass; - import org.springframework.lang.Nullable; /** * Utility class for analyzing DbActions in tests. - * + * * @author Jens Schauder * @author Chirag Tailor */ -@UtilityClass -class DbActionTestSupport { +final class DbActionTestSupport { + + private DbActionTestSupport() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } static String extractPath(DbAction action) { diff --git a/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/DeleteBatchingAggregateChangeTest.java b/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/DeleteBatchingAggregateChangeTest.java index 6828f2a6..e5e1f73a 100644 --- a/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/DeleteBatchingAggregateChangeTest.java +++ b/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/DeleteBatchingAggregateChangeTest.java @@ -11,8 +11,6 @@ import org.junit.jupiter.api.Test; import org.springframework.data.annotation.Id; import org.springframework.data.relational.core.mapping.RelationalMappingContext; -import lombok.Value; - /** * Unit tests for {@link DeleteBatchingAggregateChange}. * @@ -200,25 +198,16 @@ class DeleteBatchingAggregateChangeTest { .map(dbAction -> (DbAction.BatchWithValue, Object>) dbAction).collect(Collectors.toList()); } - @Value - static class Root { + record Root( - @Id Long id; - Intermediate intermediate; + @Id Long id, Intermediate intermediate) { } - @Value - static class Intermediate { + record Intermediate( - @Id Long id; - String name; - Leaf leaf; + @Id Long id, String name, Leaf leaf) { } - @Value - static class Leaf { - - @Id Long id; - String name; + record Leaf(@Id Long id, String name) { } } diff --git a/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/RelationalEntityDeleteWriterUnitTests.java b/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/RelationalEntityDeleteWriterUnitTests.java index 2a36b4c0..a4c45d06 100644 --- a/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/RelationalEntityDeleteWriterUnitTests.java +++ b/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/RelationalEntityDeleteWriterUnitTests.java @@ -15,14 +15,6 @@ */ package org.springframework.data.relational.core.conversion; -import static org.assertj.core.api.Assertions.*; - -import lombok.Data; -import lombok.RequiredArgsConstructor; - -import java.util.ArrayList; -import java.util.List; - import org.assertj.core.groups.Tuple; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -37,6 +29,11 @@ import org.springframework.data.relational.core.conversion.DbAction.DeleteAllRoo import org.springframework.data.relational.core.conversion.DbAction.DeleteRoot; import org.springframework.data.relational.core.mapping.RelationalMappingContext; +import java.util.ArrayList; +import java.util.List; + +import static org.assertj.core.api.Assertions.*; + /** * Unit tests for the {@link org.springframework.data.relational.core.conversion.RelationalEntityDeleteWriter} * @@ -152,37 +149,54 @@ public class RelationalEntityDeleteWriterUnitTests { return actions; } - @Data private static class SomeEntity { @Id final Long id; OtherEntity other; // should not trigger own Dbaction String name; + + private SomeEntity(Long id) { + this.id = id; + } } - @Data private class OtherEntity { @Id final Long id; YetAnother yetAnother; + + private OtherEntity(Long id) { + this.id = id; + } } - @Data private class YetAnother { @Id final Long id; + + private YetAnother(Long id) { + this.id = id; + } } - @Data private class SingleEntity { @Id final Long id; String name; + + private SingleEntity(Long id) { + this.id = id; + } } - @RequiredArgsConstructor private static class WithReadOnlyReference { - @Id final Long id; - @ReadOnlyProperty OtherEntity other; + @Id + final Long id; + @ReadOnlyProperty + OtherEntity other; + + public WithReadOnlyReference(Long id) { + this.id = id; + } } } diff --git a/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/RelationalEntityInsertWriterUnitTests.java b/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/RelationalEntityInsertWriterUnitTests.java index ea5db326..fd11cadb 100644 --- a/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/RelationalEntityInsertWriterUnitTests.java +++ b/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/RelationalEntityInsertWriterUnitTests.java @@ -17,8 +17,6 @@ package org.springframework.data.relational.core.conversion; import static org.assertj.core.api.Assertions.*; -import lombok.RequiredArgsConstructor; - import java.util.ArrayList; import java.util.List; @@ -44,7 +42,7 @@ public class RelationalEntityInsertWriterUnitTests { @Test // DATAJDBC-112 public void newEntityGetsConvertedToOneInsert() { - SingleReferenceEntity entity = new SingleReferenceEntity(null); + SingleReferenceEntity entity = new SingleReferenceEntity(null, null, null); RootAggregateChange aggregateChange = MutableAggregateChange.forSave(entity); new RelationalEntityInsertWriter(context).write(entity, aggregateChange); @@ -60,7 +58,7 @@ public class RelationalEntityInsertWriterUnitTests { @Test // DATAJDBC-282 public void existingEntityGetsNotConvertedToDeletePlusUpdate() { - SingleReferenceEntity entity = new SingleReferenceEntity(SOME_ENTITY_ID); + SingleReferenceEntity entity = new SingleReferenceEntity(SOME_ENTITY_ID, null, null); RootAggregateChange aggregateChange = MutableAggregateChange.forSave(entity); @@ -81,17 +79,13 @@ public class RelationalEntityInsertWriterUnitTests { return actions; } - @RequiredArgsConstructor - static class SingleReferenceEntity { + record SingleReferenceEntity( - @Id final Long id; - Element other; - // should not trigger own Dbaction - String name; + @Id Long id, Element other, + // should not trigger own Dbaction + String name) { } - @RequiredArgsConstructor - private static class Element { - @Id final Long id; + record Element(@Id Long id) { } } diff --git a/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/RelationalEntityUpdateWriterUnitTests.java b/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/RelationalEntityUpdateWriterUnitTests.java index 882efc19..c4f2c3f3 100644 --- a/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/RelationalEntityUpdateWriterUnitTests.java +++ b/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/RelationalEntityUpdateWriterUnitTests.java @@ -17,8 +17,6 @@ package org.springframework.data.relational.core.conversion; import static org.assertj.core.api.Assertions.*; -import lombok.RequiredArgsConstructor; - import java.util.ArrayList; import java.util.List; @@ -44,7 +42,7 @@ public class RelationalEntityUpdateWriterUnitTests { @Test // DATAJDBC-112 public void existingEntityGetsConvertedToDeletePlusUpdate() { - SingleReferenceEntity entity = new SingleReferenceEntity(SOME_ENTITY_ID); + SingleReferenceEntity entity = new SingleReferenceEntity(SOME_ENTITY_ID, null, null); RootAggregateChange aggregateChange = MutableAggregateChange.forSave(entity); @@ -66,18 +64,14 @@ public class RelationalEntityUpdateWriterUnitTests { return actions; } - @RequiredArgsConstructor - static class SingleReferenceEntity { + record SingleReferenceEntity( - @Id final Long id; - Element other; - // should not trigger own Dbaction - String name; + @Id Long id, Element other, + // should not trigger own Dbaction + String name) { } - @RequiredArgsConstructor - private static class Element { - @Id final Long id; + record Element(@Id Long id) { } } diff --git a/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/RelationalEntityWriterUnitTests.java b/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/RelationalEntityWriterUnitTests.java index ad39927b..a2c31368 100644 --- a/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/RelationalEntityWriterUnitTests.java +++ b/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/RelationalEntityWriterUnitTests.java @@ -15,18 +15,6 @@ */ package org.springframework.data.relational.core.conversion; -import static org.assertj.core.api.Assertions.*; - -import lombok.Data; -import lombok.RequiredArgsConstructor; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; @@ -44,6 +32,15 @@ import org.springframework.data.relational.core.mapping.RelationalMappingContext import org.springframework.data.relational.core.mapping.RelationalPersistentProperty; import org.springframework.lang.Nullable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static org.assertj.core.api.Assertions.*; + /** * Unit tests for the {@link RelationalEntityWriter} * @@ -780,142 +777,207 @@ public class RelationalEntityWriterUnitTests { return persistentPropertyPaths.filter(p -> p.toDotPath().equals(path)).stream().findFirst().orElse(null); } - @RequiredArgsConstructor - @Data static class EntityWithReferencesToPrimitiveIdEntity { @Id final Long id; PrimitiveLongIdEntity primitiveLongIdEntity; List primitiveLongIdEntities = new ArrayList<>(); PrimitiveIntIdEntity primitiveIntIdEntity; List primitiveIntIdEntities = new ArrayList<>(); + + EntityWithReferencesToPrimitiveIdEntity(Long id) { + this.id = id; + } } - @Data static class PrimitiveLongIdEntity { @Id long id; } - @Data static class PrimitiveIntIdEntity { @Id int id; } - @RequiredArgsConstructor static class SingleReferenceEntity { - @Id final Long id; + @Id + final Long id; Element other; // should not trigger own DbAction String name; + + public SingleReferenceEntity(Long id) { + this.id = id; + } } - @RequiredArgsConstructor static class EmbeddedReferenceEntity { - @Id final Long id; - @Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "prefix_") Element other; + @Id + final Long id; + @Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "prefix_") + Element other; + + public EmbeddedReferenceEntity(Long id) { + this.id = id; + } } - @RequiredArgsConstructor static class EmbeddedReferenceChainEntity { - @Id final Long id; - @Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "prefix_") ElementReference other; + @Id + final Long id; + @Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "prefix_") + ElementReference other; + + public EmbeddedReferenceChainEntity(Long id) { + this.id = id; + } } - @RequiredArgsConstructor static class RootWithEmbeddedReferenceChainEntity { - @Id final Long id; + @Id + final Long id; EmbeddedReferenceChainEntity other; + + public RootWithEmbeddedReferenceChainEntity(Long id) { + this.id = id; + } } - @RequiredArgsConstructor static class ReferenceWoIdEntity { - @Id final Long id; + @Id + final Long id; NoIdElement other; // should not trigger own DbAction String name; + + public ReferenceWoIdEntity(Long id) { + this.id = id; + } } - @RequiredArgsConstructor private static class CascadingReferenceMiddleElement { - @Id final Long id; + @Id + final Long id; final Set element = new HashSet<>(); + + public CascadingReferenceMiddleElement(Long id) { + this.id = id; + } } - @RequiredArgsConstructor private static class CascadingReferenceEntity { - @Id final Long id; + @Id + final Long id; final Set other = new HashSet<>(); + + public CascadingReferenceEntity(Long id) { + this.id = id; + } } - @RequiredArgsConstructor private static class SetContainer { - @Id final Long id; + @Id + final Long id; Set elements = new HashSet<>(); + + public SetContainer(Long id) { + this.id = id; + } } - @RequiredArgsConstructor private static class ListMapContainer { - @Id final Long id; + @Id + final Long id; List maps = new ArrayList<>(); + + public ListMapContainer(Long id) { + this.id = id; + } } - @RequiredArgsConstructor private static class MapContainer { - @Id final Long id; + @Id + final Long id; Map elements = new HashMap<>(); + + public MapContainer(Long id) { + this.id = id; + } } - @RequiredArgsConstructor private static class ListContainer { - @Id final Long id; + @Id + final Long id; List elements = new ArrayList<>(); + + public ListContainer(Long id) { + this.id = id; + } } - @RequiredArgsConstructor private static class Element { - @Id final Long id; + @Id + final Long id; + + public Element(Long id) { + this.id = id; + } } - @RequiredArgsConstructor private static class ElementReference { final Element element; + + public ElementReference(Element element) { + this.element = element; + } } - @RequiredArgsConstructor private static class NoIdListMapContainer { - @Id final Long id; + @Id + final Long id; List maps = new ArrayList<>(); + + public NoIdListMapContainer(Long id) { + this.id = id; + } } - @RequiredArgsConstructor private static class NoIdMapContainer { Map elements = new HashMap<>(); + + public NoIdMapContainer() { + } } - @RequiredArgsConstructor private static class NoIdElement { // empty classes feel weird. String name; + + public NoIdElement() { + } } - @RequiredArgsConstructor private static class WithReadOnlyReference { - @Id final Long id; + @Id + final Long id; @ReadOnlyProperty Element readOnly; + + public WithReadOnlyReference(Long id) { + this.id = id; + } } } diff --git a/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/SaveBatchingAggregateChangeTest.java b/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/SaveBatchingAggregateChangeTest.java index e7805a10..2ff2a8b1 100644 --- a/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/SaveBatchingAggregateChangeTest.java +++ b/spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/SaveBatchingAggregateChangeTest.java @@ -15,21 +15,19 @@ */ package org.springframework.data.relational.core.conversion; -import static java.util.Collections.*; -import static org.assertj.core.api.Assertions.*; - -import lombok.Value; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - import org.assertj.core.groups.Tuple; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.data.annotation.Id; import org.springframework.data.relational.core.mapping.RelationalMappingContext; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import static java.util.Collections.*; +import static org.assertj.core.api.Assertions.*; + /** * Unit tests for {@link SaveBatchingAggregateChange}. * @@ -515,33 +513,214 @@ class SaveBatchingAggregateChangeTest { .map(dbAction -> (DbAction.BatchWithValue, Object>) dbAction).collect(Collectors.toList()); } - @Value - static class RootWithSameLengthReferences { + static final class RootWithSameLengthReferences { - @Id Long id; - Intermediate one; - Intermediate two; + @Id + private final Long id; + private final Intermediate one; + private final Intermediate two; + + public RootWithSameLengthReferences(Long id, Intermediate one, Intermediate two) { + this.id = id; + this.one = one; + this.two = two; + } + + public Long getId() { + return this.id; + } + + public Intermediate getOne() { + return this.one; + } + + public Intermediate getTwo() { + return this.two; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof RootWithSameLengthReferences)) return false; + final RootWithSameLengthReferences other = (RootWithSameLengthReferences) o; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false; + final Object this$one = this.getOne(); + final Object other$one = other.getOne(); + if (this$one == null ? other$one != null : !this$one.equals(other$one)) return false; + final Object this$two = this.getTwo(); + final Object other$two = other.getTwo(); + if (this$two == null ? other$two != null : !this$two.equals(other$two)) return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.getId(); + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + final Object $one = this.getOne(); + result = result * PRIME + ($one == null ? 43 : $one.hashCode()); + final Object $two = this.getTwo(); + result = result * PRIME + ($two == null ? 43 : $two.hashCode()); + return result; + } + + public String toString() { + return "SaveBatchingAggregateChangeTest.RootWithSameLengthReferences(id=" + this.getId() + ", one=" + this.getOne() + ", two=" + this.getTwo() + ")"; + } } - @Value - static class Root { + static final class Root { - @Id Long id; - Intermediate intermediate; + @Id + private final Long id; + private final Intermediate intermediate; + + public Root(Long id, Intermediate intermediate) { + this.id = id; + this.intermediate = intermediate; + } + + public Long getId() { + return this.id; + } + + public Intermediate getIntermediate() { + return this.intermediate; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof Root)) return false; + final Root other = (Root) o; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false; + final Object this$intermediate = this.getIntermediate(); + final Object other$intermediate = other.getIntermediate(); + if (this$intermediate == null ? other$intermediate != null : !this$intermediate.equals(other$intermediate)) + return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.getId(); + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + final Object $intermediate = this.getIntermediate(); + result = result * PRIME + ($intermediate == null ? 43 : $intermediate.hashCode()); + return result; + } + + public String toString() { + return "SaveBatchingAggregateChangeTest.Root(id=" + this.getId() + ", intermediate=" + this.getIntermediate() + ")"; + } } - @Value - static class Intermediate { + static final class Intermediate { - @Id Long id; - String name; - Leaf leaf; + @Id + private final Long id; + private final String name; + private final Leaf leaf; + + public Intermediate(Long id, String name, Leaf leaf) { + this.id = id; + this.name = name; + this.leaf = leaf; + } + + public Long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public Leaf getLeaf() { + return this.leaf; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof Intermediate)) return false; + final Intermediate other = (Intermediate) o; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false; + final Object this$name = this.getName(); + final Object other$name = other.getName(); + if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false; + final Object this$leaf = this.getLeaf(); + final Object other$leaf = other.getLeaf(); + if (this$leaf == null ? other$leaf != null : !this$leaf.equals(other$leaf)) return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.getId(); + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + final Object $name = this.getName(); + result = result * PRIME + ($name == null ? 43 : $name.hashCode()); + final Object $leaf = this.getLeaf(); + result = result * PRIME + ($leaf == null ? 43 : $leaf.hashCode()); + return result; + } + + public String toString() { + return "SaveBatchingAggregateChangeTest.Intermediate(id=" + this.getId() + ", name=" + this.getName() + ", leaf=" + this.getLeaf() + ")"; + } } - @Value - static class Leaf { + static final class Leaf { - @Id Long id; - String name; + @Id + private final Long id; + private final String name; + + public Leaf(Long id, String name) { + this.id = id; + this.name = name; + } + + public Long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof Leaf)) return false; + final Leaf other = (Leaf) o; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false; + final Object this$name = this.getName(); + final Object other$name = other.getName(); + if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.getId(); + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + final Object $name = this.getName(); + result = result * PRIME + ($name == null ? 43 : $name.hashCode()); + return result; + } + + public String toString() { + return "SaveBatchingAggregateChangeTest.Leaf(id=" + this.getId() + ", name=" + this.getName() + ")"; + } } } diff --git a/spring-data-relational/src/test/java/org/springframework/data/relational/core/mapping/BasicRelationalPersistentPropertyUnitTests.java b/spring-data-relational/src/test/java/org/springframework/data/relational/core/mapping/BasicRelationalPersistentPropertyUnitTests.java index 1ecb663d..68f92fc1 100644 --- a/spring-data-relational/src/test/java/org/springframework/data/relational/core/mapping/BasicRelationalPersistentPropertyUnitTests.java +++ b/spring-data-relational/src/test/java/org/springframework/data/relational/core/mapping/BasicRelationalPersistentPropertyUnitTests.java @@ -15,11 +15,12 @@ */ package org.springframework.data.relational.core.mapping; -import static org.assertj.core.api.Assertions.*; -import static org.springframework.data.relational.core.sql.SqlIdentifier.*; - import junit.framework.AssertionFailedError; -import lombok.Data; +import org.assertj.core.api.SoftAssertions; +import org.junit.jupiter.api.Test; +import org.springframework.data.annotation.Id; +import org.springframework.data.mapping.PersistentPropertyPath; +import org.springframework.data.relational.core.mapping.Embedded.OnEmpty; import java.time.LocalDateTime; import java.time.ZonedDateTime; @@ -27,11 +28,8 @@ import java.util.Date; import java.util.List; import java.util.function.BiConsumer; -import org.assertj.core.api.SoftAssertions; -import org.junit.jupiter.api.Test; -import org.springframework.data.annotation.Id; -import org.springframework.data.mapping.PersistentPropertyPath; -import org.springframework.data.relational.core.mapping.Embedded.OnEmpty; +import static org.assertj.core.api.Assertions.*; +import static org.springframework.data.relational.core.sql.SqlIdentifier.*; /** * Unit tests for the {@link BasicRelationalPersistentProperty}. @@ -152,11 +150,11 @@ public class BasicRelationalPersistentPropertyUnitTests { softly.assertAll(); } - @Data @SuppressWarnings("unused") private static class DummyEntity { - @Id private final Long id; + @Id + private final Long id; private final SomeEnum someEnum; private final LocalDateTime localDateTime; private final ZonedDateTime zonedDateTime; @@ -168,7 +166,8 @@ public class BasicRelationalPersistentPropertyUnitTests { private final OtherEntity[] arrayOfEntity; @MappedCollection(idColumn = "dummy_column_name", - keyColumn = "dummy_key_column_name") private List someList; + keyColumn = "dummy_key_column_name") + private List someList; // DATACMNS-106 private @Column("dummy_name") String name; @@ -178,14 +177,17 @@ public class BasicRelationalPersistentPropertyUnitTests { public static String littleBobbyTablesValue = "--; DROP ALL TABLES;--"; @Column(value = "#{T(org.springframework.data.relational.core.mapping." + "BasicRelationalPersistentPropertyUnitTests$DummyEntity" - + ").spelExpression1Value}") private String spelExpression1; + + ").spelExpression1Value}") + private String spelExpression1; @Column(value = "#{T(org.springframework.data.relational.core.mapping." + "BasicRelationalPersistentPropertyUnitTests$DummyEntity" - + ").littleBobbyTablesValue}") private String littleBobbyTables; + + ").littleBobbyTablesValue}") + private String littleBobbyTables; @Column( - value = "--; DROP ALL TABLES;--") private String poorDeveloperProgrammaticallyAskingToShootThemselvesInTheFoot; + value = "--; DROP ALL TABLES;--") + private String poorDeveloperProgrammaticallyAskingToShootThemselvesInTheFoot; // DATAJDBC-111 private @Embedded(onEmpty = OnEmpty.USE_NULL) EmbeddableEntity embeddableEntity; @@ -193,6 +195,17 @@ public class BasicRelationalPersistentPropertyUnitTests { // DATAJDBC-111 private @Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "prefix") EmbeddableEntity prefixedEmbeddableEntity; + public DummyEntity(Long id, SomeEnum someEnum, LocalDateTime localDateTime, ZonedDateTime zonedDateTime, List listOfString, String[] arrayOfString, List listOfEntity, OtherEntity[] arrayOfEntity) { + this.id = id; + this.someEnum = someEnum; + this.localDateTime = localDateTime; + this.zonedDateTime = zonedDateTime; + this.listOfString = listOfString; + this.arrayOfString = arrayOfString; + this.listOfEntity = listOfEntity; + this.arrayOfEntity = arrayOfEntity; + } + @Column("dummy_last_updated_at") public LocalDateTime getLocalDateTime() { return localDateTime; @@ -205,6 +218,190 @@ public class BasicRelationalPersistentPropertyUnitTests { public List getListGetter() { return null; } + + public Long getId() { + return this.id; + } + + public SomeEnum getSomeEnum() { + return this.someEnum; + } + + public ZonedDateTime getZonedDateTime() { + return this.zonedDateTime; + } + + public List getListOfString() { + return this.listOfString; + } + + public String[] getArrayOfString() { + return this.arrayOfString; + } + + public List getListOfEntity() { + return this.listOfEntity; + } + + public OtherEntity[] getArrayOfEntity() { + return this.arrayOfEntity; + } + + public List getSomeList() { + return this.someList; + } + + public String getName() { + return this.name; + } + + public String getSpelExpression1() { + return this.spelExpression1; + } + + public String getLittleBobbyTables() { + return this.littleBobbyTables; + } + + public String getPoorDeveloperProgrammaticallyAskingToShootThemselvesInTheFoot() { + return this.poorDeveloperProgrammaticallyAskingToShootThemselvesInTheFoot; + } + + public EmbeddableEntity getEmbeddableEntity() { + return this.embeddableEntity; + } + + public EmbeddableEntity getPrefixedEmbeddableEntity() { + return this.prefixedEmbeddableEntity; + } + + public void setSomeList(List someList) { + this.someList = someList; + } + + public void setName(String name) { + this.name = name; + } + + public void setSpelExpression1(String spelExpression1) { + this.spelExpression1 = spelExpression1; + } + + public void setLittleBobbyTables(String littleBobbyTables) { + this.littleBobbyTables = littleBobbyTables; + } + + public void setPoorDeveloperProgrammaticallyAskingToShootThemselvesInTheFoot(String poorDeveloperProgrammaticallyAskingToShootThemselvesInTheFoot) { + this.poorDeveloperProgrammaticallyAskingToShootThemselvesInTheFoot = poorDeveloperProgrammaticallyAskingToShootThemselvesInTheFoot; + } + + public void setEmbeddableEntity(EmbeddableEntity embeddableEntity) { + this.embeddableEntity = embeddableEntity; + } + + public void setPrefixedEmbeddableEntity(EmbeddableEntity prefixedEmbeddableEntity) { + this.prefixedEmbeddableEntity = prefixedEmbeddableEntity; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof DummyEntity)) return false; + final DummyEntity other = (DummyEntity) o; + if (!other.canEqual((Object) this)) return false; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false; + final Object this$someEnum = this.getSomeEnum(); + final Object other$someEnum = other.getSomeEnum(); + if (this$someEnum == null ? other$someEnum != null : !this$someEnum.equals(other$someEnum)) return false; + final Object this$localDateTime = this.getLocalDateTime(); + final Object other$localDateTime = other.getLocalDateTime(); + if (this$localDateTime == null ? other$localDateTime != null : !this$localDateTime.equals(other$localDateTime)) + return false; + final Object this$zonedDateTime = this.getZonedDateTime(); + final Object other$zonedDateTime = other.getZonedDateTime(); + if (this$zonedDateTime == null ? other$zonedDateTime != null : !this$zonedDateTime.equals(other$zonedDateTime)) + return false; + final Object this$listOfString = this.getListOfString(); + final Object other$listOfString = other.getListOfString(); + if (this$listOfString == null ? other$listOfString != null : !this$listOfString.equals(other$listOfString)) + return false; + if (!java.util.Arrays.deepEquals(this.getArrayOfString(), other.getArrayOfString())) return false; + final Object this$listOfEntity = this.getListOfEntity(); + final Object other$listOfEntity = other.getListOfEntity(); + if (this$listOfEntity == null ? other$listOfEntity != null : !this$listOfEntity.equals(other$listOfEntity)) + return false; + if (!java.util.Arrays.deepEquals(this.getArrayOfEntity(), other.getArrayOfEntity())) return false; + final Object this$someList = this.getSomeList(); + final Object other$someList = other.getSomeList(); + if (this$someList == null ? other$someList != null : !this$someList.equals(other$someList)) return false; + final Object this$name = this.getName(); + final Object other$name = other.getName(); + if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false; + final Object this$spelExpression1 = this.getSpelExpression1(); + final Object other$spelExpression1 = other.getSpelExpression1(); + if (this$spelExpression1 == null ? other$spelExpression1 != null : !this$spelExpression1.equals(other$spelExpression1)) + return false; + final Object this$littleBobbyTables = this.getLittleBobbyTables(); + final Object other$littleBobbyTables = other.getLittleBobbyTables(); + if (this$littleBobbyTables == null ? other$littleBobbyTables != null : !this$littleBobbyTables.equals(other$littleBobbyTables)) + return false; + final Object this$poorDeveloperProgrammaticallyAskingToShootThemselvesInTheFoot = this.getPoorDeveloperProgrammaticallyAskingToShootThemselvesInTheFoot(); + final Object other$poorDeveloperProgrammaticallyAskingToShootThemselvesInTheFoot = other.getPoorDeveloperProgrammaticallyAskingToShootThemselvesInTheFoot(); + if (this$poorDeveloperProgrammaticallyAskingToShootThemselvesInTheFoot == null ? other$poorDeveloperProgrammaticallyAskingToShootThemselvesInTheFoot != null : !this$poorDeveloperProgrammaticallyAskingToShootThemselvesInTheFoot.equals(other$poorDeveloperProgrammaticallyAskingToShootThemselvesInTheFoot)) + return false; + final Object this$embeddableEntity = this.getEmbeddableEntity(); + final Object other$embeddableEntity = other.getEmbeddableEntity(); + if (this$embeddableEntity == null ? other$embeddableEntity != null : !this$embeddableEntity.equals(other$embeddableEntity)) + return false; + final Object this$prefixedEmbeddableEntity = this.getPrefixedEmbeddableEntity(); + final Object other$prefixedEmbeddableEntity = other.getPrefixedEmbeddableEntity(); + if (this$prefixedEmbeddableEntity == null ? other$prefixedEmbeddableEntity != null : !this$prefixedEmbeddableEntity.equals(other$prefixedEmbeddableEntity)) + return false; + return true; + } + + protected boolean canEqual(final Object other) { + return other instanceof DummyEntity; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.getId(); + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + final Object $someEnum = this.getSomeEnum(); + result = result * PRIME + ($someEnum == null ? 43 : $someEnum.hashCode()); + final Object $localDateTime = this.getLocalDateTime(); + result = result * PRIME + ($localDateTime == null ? 43 : $localDateTime.hashCode()); + final Object $zonedDateTime = this.getZonedDateTime(); + result = result * PRIME + ($zonedDateTime == null ? 43 : $zonedDateTime.hashCode()); + final Object $listOfString = this.getListOfString(); + result = result * PRIME + ($listOfString == null ? 43 : $listOfString.hashCode()); + result = result * PRIME + java.util.Arrays.deepHashCode(this.getArrayOfString()); + final Object $listOfEntity = this.getListOfEntity(); + result = result * PRIME + ($listOfEntity == null ? 43 : $listOfEntity.hashCode()); + result = result * PRIME + java.util.Arrays.deepHashCode(this.getArrayOfEntity()); + final Object $someList = this.getSomeList(); + result = result * PRIME + ($someList == null ? 43 : $someList.hashCode()); + final Object $name = this.getName(); + result = result * PRIME + ($name == null ? 43 : $name.hashCode()); + final Object $spelExpression1 = this.getSpelExpression1(); + result = result * PRIME + ($spelExpression1 == null ? 43 : $spelExpression1.hashCode()); + final Object $littleBobbyTables = this.getLittleBobbyTables(); + result = result * PRIME + ($littleBobbyTables == null ? 43 : $littleBobbyTables.hashCode()); + final Object $poorDeveloperProgrammaticallyAskingToShootThemselvesInTheFoot = this.getPoorDeveloperProgrammaticallyAskingToShootThemselvesInTheFoot(); + result = result * PRIME + ($poorDeveloperProgrammaticallyAskingToShootThemselvesInTheFoot == null ? 43 : $poorDeveloperProgrammaticallyAskingToShootThemselvesInTheFoot.hashCode()); + final Object $embeddableEntity = this.getEmbeddableEntity(); + result = result * PRIME + ($embeddableEntity == null ? 43 : $embeddableEntity.hashCode()); + final Object $prefixedEmbeddableEntity = this.getPrefixedEmbeddableEntity(); + result = result * PRIME + ($prefixedEmbeddableEntity == null ? 43 : $prefixedEmbeddableEntity.hashCode()); + return result; + } + + public String toString() { + return "BasicRelationalPersistentPropertyUnitTests.DummyEntity(id=" + this.getId() + ", someEnum=" + this.getSomeEnum() + ", localDateTime=" + this.getLocalDateTime() + ", zonedDateTime=" + this.getZonedDateTime() + ", listOfString=" + this.getListOfString() + ", arrayOfString=" + java.util.Arrays.deepToString(this.getArrayOfString()) + ", listOfEntity=" + this.getListOfEntity() + ", arrayOfEntity=" + java.util.Arrays.deepToString(this.getArrayOfEntity()) + ", someList=" + this.getSomeList() + ", name=" + this.getName() + ", spelExpression1=" + this.getSpelExpression1() + ", littleBobbyTables=" + this.getLittleBobbyTables() + ", poorDeveloperProgrammaticallyAskingToShootThemselvesInTheFoot=" + this.getPoorDeveloperProgrammaticallyAskingToShootThemselvesInTheFoot() + ", embeddableEntity=" + this.getEmbeddableEntity() + ", prefixedEmbeddableEntity=" + this.getPrefixedEmbeddableEntity() + ")"; + } } static class WithMappedCollection { @@ -218,9 +415,44 @@ public class BasicRelationalPersistentPropertyUnitTests { } // DATAJDBC-111 - @Data private static class EmbeddableEntity { private final String embeddedTest; + + public EmbeddableEntity(String embeddedTest) { + this.embeddedTest = embeddedTest; + } + + public String getEmbeddedTest() { + return this.embeddedTest; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof EmbeddableEntity)) return false; + final EmbeddableEntity other = (EmbeddableEntity) o; + if (!other.canEqual((Object) this)) return false; + final Object this$embeddedTest = this.getEmbeddedTest(); + final Object other$embeddedTest = other.getEmbeddedTest(); + if (this$embeddedTest == null ? other$embeddedTest != null : !this$embeddedTest.equals(other$embeddedTest)) + return false; + return true; + } + + protected boolean canEqual(final Object other) { + return other instanceof EmbeddableEntity; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $embeddedTest = this.getEmbeddedTest(); + result = result * PRIME + ($embeddedTest == null ? 43 : $embeddedTest.hashCode()); + return result; + } + + public String toString() { + return "BasicRelationalPersistentPropertyUnitTests.EmbeddableEntity(embeddedTest=" + this.getEmbeddedTest() + ")"; + } } @SuppressWarnings("unused") diff --git a/spring-data-relational/src/test/java/org/springframework/data/relational/repository/query/CriteriaFactoryUnitTests.java b/spring-data-relational/src/test/java/org/springframework/data/relational/repository/query/CriteriaFactoryUnitTests.java index 159e10f4..0e3c6de9 100644 --- a/spring-data-relational/src/test/java/org/springframework/data/relational/repository/query/CriteriaFactoryUnitTests.java +++ b/spring-data-relational/src/test/java/org/springframework/data/relational/repository/query/CriteriaFactoryUnitTests.java @@ -17,15 +17,12 @@ package org.springframework.data.relational.repository.query; import static org.assertj.core.api.Assertions.*; -import lombok.Data; -import lombok.SneakyThrows; import java.lang.reflect.Method; import java.util.Arrays; import java.util.List; import org.junit.jupiter.api.Test; - import org.springframework.data.projection.SpelAwareProxyProjectionFactory; import org.springframework.data.relational.core.query.Criteria; import org.springframework.data.repository.Repository; @@ -72,10 +69,14 @@ public class CriteriaFactoryUnitTests { assertThat(criteria.getValue()).isEqualTo(Arrays.asList("foo", "bar")); } - @SneakyThrows private QueryMethod getQueryMethod(String methodName, Class... parameterTypes) { - Method method = UserRepository.class.getMethod(methodName, parameterTypes); + Method method = null; + try { + method = UserRepository.class.getMethod(methodName, parameterTypes); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } return new QueryMethod(method, new DefaultRepositoryMetadata(UserRepository.class), new SpelAwareProxyProjectionFactory()); } @@ -91,7 +92,6 @@ public class CriteriaFactoryUnitTests { User findAllByNameIn(String[] names); } - @Data static class User { String name; diff --git a/spring-data-relational/src/test/java/org/springframework/data/relational/repository/query/RelationalExampleMapperTests.java b/spring-data-relational/src/test/java/org/springframework/data/relational/repository/query/RelationalExampleMapperTests.java index f1c60b2a..34d5c986 100644 --- a/spring-data-relational/src/test/java/org/springframework/data/relational/repository/query/RelationalExampleMapperTests.java +++ b/spring-data-relational/src/test/java/org/springframework/data/relational/repository/query/RelationalExampleMapperTests.java @@ -16,17 +16,6 @@ package org.springframework.data.relational.repository.query; -import static org.assertj.core.api.Assertions.*; -import static org.springframework.data.domain.ExampleMatcher.*; -import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.*; -import static org.springframework.data.domain.ExampleMatcher.StringMatcher.*; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.Objects; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.data.annotation.Id; @@ -35,6 +24,13 @@ import org.springframework.data.domain.ExampleMatcher; import org.springframework.data.relational.core.mapping.RelationalMappingContext; import org.springframework.data.relational.core.query.Query; +import java.util.Objects; + +import static org.assertj.core.api.Assertions.*; +import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.*; +import static org.springframework.data.domain.ExampleMatcher.StringMatcher.*; +import static org.springframework.data.domain.ExampleMatcher.*; + /** * Verify that the {@link RelationalExampleMapper} properly turns {@link Example}s into {@link Query}'s. * @@ -422,19 +418,55 @@ public class RelationalExampleMapperTests { "(secret = 'I have the ring!')"); } - @Data - @AllArgsConstructor - @NoArgsConstructor static class Person { - @Id String id; + @Id + String id; String firstname; String lastname; String secret; + public Person(String id, String firstname, String lastname, String secret) { + this.id = id; + this.firstname = firstname; + this.lastname = lastname; + this.secret = secret; + } + + public Person() { + } + // Override default visibility of getting the secret. private String getSecret() { return this.secret; } + + public String getId() { + return this.id; + } + + public String getFirstname() { + return this.firstname; + } + + public String getLastname() { + return this.lastname; + } + + public void setId(String id) { + this.id = id; + } + + public void setFirstname(String firstname) { + this.firstname = firstname; + } + + public void setLastname(String lastname) { + this.lastname = lastname; + } + + public void setSecret(String secret) { + this.secret = secret; + } } }