Skip to content

Commit 7babd7a

Browse files
committed
Replaces broken test with a working one.
See #1046, #498 Original pull request #1144
1 parent 9aa67f5 commit 7babd7a

File tree

3 files changed

+57
-38
lines changed

3 files changed

+57
-38
lines changed

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateIntegrationTests.java

+54-13
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,20 @@
1515
*/
1616
package org.springframework.data.jdbc.core;
1717

18+
import static java.util.Arrays.*;
1819
import static java.util.Collections.*;
1920
import static org.assertj.core.api.Assertions.*;
2021
import static org.assertj.core.api.SoftAssertions.*;
2122
import static org.springframework.data.jdbc.testing.TestDatabaseFeatures.Feature.*;
2223
import static org.springframework.test.context.TestExecutionListeners.MergeMode.*;
2324

25+
import lombok.Data;
26+
import lombok.EqualsAndHashCode;
27+
import lombok.Value;
28+
import lombok.With;
29+
2430
import java.time.LocalDateTime;
2531
import java.util.ArrayList;
26-
import java.util.Arrays;
2732
import java.util.Collections;
2833
import java.util.HashMap;
2934
import java.util.HashSet;
@@ -44,6 +49,7 @@
4449
import org.springframework.dao.IncorrectUpdateSemanticsDataAccessException;
4550
import org.springframework.dao.OptimisticLockingFailureException;
4651
import org.springframework.data.annotation.Id;
52+
import org.springframework.data.annotation.PersistenceConstructor;
4753
import org.springframework.data.annotation.ReadOnlyProperty;
4854
import org.springframework.data.annotation.Version;
4955
import org.springframework.data.domain.PageRequest;
@@ -56,6 +62,7 @@
5662
import org.springframework.data.jdbc.testing.TestDatabaseFeatures;
5763
import org.springframework.data.relational.core.conversion.DbActionExecutionException;
5864
import org.springframework.data.relational.core.mapping.Column;
65+
import org.springframework.data.relational.core.mapping.MappedCollection;
5966
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
6067
import org.springframework.data.relational.core.mapping.Table;
6168
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
@@ -64,11 +71,6 @@
6471
import org.springframework.test.context.junit.jupiter.SpringExtension;
6572
import org.springframework.transaction.annotation.Transactional;
6673

67-
import lombok.Data;
68-
import lombok.EqualsAndHashCode;
69-
import lombok.Value;
70-
import lombok.With;
71-
7274
/**
7375
* Integration tests for {@link JdbcAggregateTemplate}.
7476
*
@@ -502,6 +504,21 @@ public void saveAndLoadAnEntityWithListOfElementsWithoutId() {
502504
assertThat(reloaded.content).extracting(e -> e.content).containsExactly("content");
503505
}
504506

507+
@Test // GH-498 DATAJDBC-273
508+
@EnabledOnFeature(SUPPORTS_QUOTED_IDS)
509+
public void saveAndLoadAnEntityWithListOfElementsInConstructor() {
510+
511+
ElementNoId element = new ElementNoId();
512+
element.content = "content";
513+
ListParentAllArgs entity = new ListParentAllArgs("name", asList(element));
514+
515+
entity = template.save(entity);
516+
517+
ListParentAllArgs reloaded = template.findById(entity.id, ListParentAllArgs.class);
518+
519+
assertThat(reloaded.content).extracting(e -> e.content).containsExactly("content");
520+
}
521+
505522
@Test // DATAJDBC-259
506523
@EnabledOnFeature(SUPPORTS_ARRAYS)
507524
public void saveAndLoadAnEntityWithArray() {
@@ -544,7 +561,7 @@ public void saveAndLoadAnEntityWithMultidimensionalArray() {
544561
public void saveAndLoadAnEntityWithList() {
545562

546563
ListOwner arrayOwner = new ListOwner();
547-
arrayOwner.digits.addAll(Arrays.asList("one", "two", "three"));
564+
arrayOwner.digits.addAll(asList("one", "two", "three"));
548565

549566
ListOwner saved = template.save(arrayOwner);
550567

@@ -554,15 +571,15 @@ public void saveAndLoadAnEntityWithList() {
554571

555572
assertThat(reloaded).isNotNull();
556573
assertThat(reloaded.id).isEqualTo(saved.id);
557-
assertThat(reloaded.digits).isEqualTo(Arrays.asList("one", "two", "three"));
574+
assertThat(reloaded.digits).isEqualTo(asList("one", "two", "three"));
558575
}
559576

560577
@Test // GH-1033
561578
@EnabledOnFeature(SUPPORTS_ARRAYS)
562579
public void saveAndLoadAnEntityWithListOfDouble() {
563580

564581
DoubleListOwner doubleListOwner = new DoubleListOwner();
565-
doubleListOwner.digits.addAll(Arrays.asList(1.2, 1.3, 1.4));
582+
doubleListOwner.digits.addAll(asList(1.2, 1.3, 1.4));
566583

567584
DoubleListOwner saved = template.save(doubleListOwner);
568585

@@ -572,15 +589,15 @@ public void saveAndLoadAnEntityWithListOfDouble() {
572589

573590
assertThat(reloaded).isNotNull();
574591
assertThat(reloaded.id).isEqualTo(saved.id);
575-
assertThat(reloaded.digits).isEqualTo(Arrays.asList(1.2, 1.3, 1.4));
592+
assertThat(reloaded.digits).isEqualTo(asList(1.2, 1.3, 1.4));
576593
}
577594

578595
@Test // GH-1033, GH-1046
579596
@EnabledOnFeature(SUPPORTS_ARRAYS)
580597
public void saveAndLoadAnEntityWithListOfFloat() {
581598

582599
FloatListOwner floatListOwner = new FloatListOwner();
583-
final List<Float> values = Arrays.asList(1.2f, 1.3f, 1.4f);
600+
final List<Float> values = asList(1.2f, 1.3f, 1.4f);
584601
floatListOwner.digits.addAll(values);
585602

586603
FloatListOwner saved = template.save(floatListOwner);
@@ -599,7 +616,7 @@ public void saveAndLoadAnEntityWithListOfFloat() {
599616
public void saveAndLoadAnEntityWithSet() {
600617

601618
SetOwner setOwner = new SetOwner();
602-
setOwner.digits.addAll(Arrays.asList("one", "two", "three"));
619+
setOwner.digits.addAll(asList("one", "two", "three"));
603620

604621
SetOwner saved = template.save(setOwner);
605622

@@ -609,7 +626,7 @@ public void saveAndLoadAnEntityWithSet() {
609626

610627
assertThat(reloaded).isNotNull();
611628
assertThat(reloaded.id).isEqualTo(saved.id);
612-
assertThat(reloaded.digits).isEqualTo(new HashSet<>(Arrays.asList("one", "two", "three")));
629+
assertThat(reloaded.digits).isEqualTo(new HashSet<>(asList("one", "two", "three")));
613630
}
614631

615632
@Test // DATAJDBC-327
@@ -1011,13 +1028,37 @@ static class ChildNoId {
10111028
private String content;
10121029
}
10131030

1031+
@Table("LIST_PARENT")
10141032
static class ListParent {
10151033

10161034
@Column("id4") @Id private Long id;
10171035
String name;
1036+
@MappedCollection(idColumn = "LIST_PARENT")
10181037
List<ElementNoId> content = new ArrayList<>();
10191038
}
10201039

1040+
@Table("LIST_PARENT")
1041+
static class ListParentAllArgs {
1042+
1043+
@Column("id4") @Id
1044+
private final Long id;
1045+
private final String name;
1046+
@MappedCollection(idColumn = "LIST_PARENT")
1047+
private final List<ElementNoId> content = new ArrayList<>();
1048+
1049+
@PersistenceConstructor
1050+
ListParentAllArgs(Long id, String name, List<ElementNoId> content) {
1051+
1052+
this.id = id;
1053+
this.name = name;
1054+
this.content.addAll(content);
1055+
}
1056+
1057+
ListParentAllArgs(String name, List<ElementNoId> content) {
1058+
this(null, name, content);
1059+
}
1060+
}
1061+
10211062
static class ElementNoId {
10221063
private String content;
10231064
}

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/EntityRowMapperUnitTests.java

-22
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444

4545
import javax.naming.OperationNotSupportedException;
4646

47-
import org.junit.jupiter.api.Disabled;
4847
import org.junit.jupiter.api.Test;
4948
import org.mockito.ArgumentMatchers;
5049
import org.mockito.invocation.InvocationOnMock;
@@ -282,19 +281,6 @@ public void handlesMixedProperties() throws SQLException {
282281
.containsSequence("111", "222", "333");
283282
}
284283

285-
@Disabled("Assertion was updated for correctness and now this test fails. Unclear what it is intended to test and if it is still necessary.")
286-
@Test // DATAJDBC-273
287-
public void handlesNonSimplePropertyInConstructor() throws SQLException {
288-
289-
ResultSet rs = mockResultSet(singletonList("ID"), //
290-
ID_FOR_ENTITY_REFERENCING_LIST);
291-
rs.next();
292-
293-
EntityWithListInConstructor extracted = createRowMapper(EntityWithListInConstructor.class).mapRow(rs, 1);
294-
295-
assertThat(extracted.content).containsExactly(new Trivial(1L, "one"), new Trivial(2L, "two"));
296-
}
297-
298284
@Test // DATAJDBC-359
299285
public void chainedEntitiesWithoutId() throws SQLException {
300286

@@ -787,14 +773,6 @@ MixedProperties withThree(String three) {
787773
}
788774
}
789775

790-
@AllArgsConstructor
791-
static class EntityWithListInConstructor {
792-
793-
@Id final Long id;
794-
795-
final List<Trivial> content;
796-
}
797-
798776
static class NoIdChain0 {
799777
String zeroValue;
800778
}

spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.core/JdbcAggregateTemplateIntegrationTests-postgres.sql

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ DROP TABLE MANUAL;
22
DROP TABLE LEGO_SET;
33
DROP TABLE ONE_TO_ONE_PARENT;
44
DROP TABLE Child_No_Id;
5-
DROP TABLE LIST_PARENT;
65
DROP TABLE element_no_id;
6+
DROP TABLE "LIST_PARENT";
77
DROP TABLE ARRAY_OWNER;
88
DROP TABLE BYTE_ARRAY_OWNER;
99
DROP TABLE CHAIN4;
@@ -42,7 +42,7 @@ CREATE TABLE Child_No_Id
4242
content VARCHAR(30)
4343
);
4444

45-
CREATE TABLE LIST_PARENT
45+
CREATE TABLE "LIST_PARENT"
4646
(
4747
"id4" SERIAL PRIMARY KEY,
4848
NAME VARCHAR(100)
@@ -52,7 +52,7 @@ CREATE TABLE element_no_id
5252
(
5353
content VARCHAR(100),
5454
LIST_PARENT_key BIGINT,
55-
LIST_PARENT INTEGER
55+
"LIST_PARENT" INTEGER
5656
);
5757

5858
CREATE TABLE "ARRAY_OWNER"

0 commit comments

Comments
 (0)