Skip to content

Commit 7be2362

Browse files
dreab8beikov
authored andcommitted
HHH-17320 Add test for issue
1 parent b781594 commit 7be2362

File tree

2 files changed

+170
-0
lines changed

2 files changed

+170
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.orm.test.annotations.basic;
8+
9+
import java.util.HashSet;
10+
import java.util.Set;
11+
12+
import org.hibernate.testing.orm.junit.DomainModel;
13+
import org.hibernate.testing.orm.junit.SessionFactory;
14+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
15+
import org.junit.jupiter.api.Test;
16+
17+
import jakarta.persistence.Entity;
18+
import jakarta.persistence.Id;
19+
import jakarta.persistence.Table;
20+
21+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
22+
23+
@DomainModel(
24+
annotatedClasses = {
25+
SetAsBasicTest.Post.class
26+
}
27+
)
28+
@SessionFactory
29+
public class SetAsBasicTest {
30+
31+
@Test
32+
public void testPersist(SessionFactoryScope scope) {
33+
Integer postId = 1;
34+
scope.inTransaction(
35+
session -> {
36+
Set<String> tags = new HashSet<>();
37+
tags.add( "tag1" );
38+
39+
Post post = new Post( postId, "post", tags );
40+
session.persist( post );
41+
}
42+
);
43+
44+
scope.inTransaction(
45+
session -> {
46+
Post post = session.find( Post.class, postId );
47+
Set<String> tags = post.getTags();
48+
assertThat( tags ).isNotNull();
49+
assertThat( tags.size() ).isEqualTo( 1 );
50+
assertThat( tags.stream().findFirst().get() ).isEqualTo( "tag1" );
51+
}
52+
);
53+
}
54+
55+
@Entity
56+
@Table(name = "post")
57+
public static class Post {
58+
@Id
59+
public Integer id;
60+
61+
public String name;
62+
63+
Set<String> tags;
64+
65+
public Post() {
66+
}
67+
68+
public Post(Integer id, String name, Set<String> tags) {
69+
this.id = id;
70+
this.name = name;
71+
this.tags = tags;
72+
}
73+
74+
public Integer getId() {
75+
return id;
76+
}
77+
78+
public String getName() {
79+
return name;
80+
}
81+
82+
public Set<String> getTags() {
83+
return tags;
84+
}
85+
}
86+
87+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package org.hibernate.orm.test.annotations.basic;
2+
3+
import java.util.TreeMap;
4+
5+
import org.hibernate.testing.orm.junit.DomainModel;
6+
import org.hibernate.testing.orm.junit.JiraKey;
7+
import org.hibernate.testing.orm.junit.SessionFactory;
8+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
9+
import org.junit.jupiter.api.Test;
10+
11+
import jakarta.persistence.Entity;
12+
import jakarta.persistence.Id;
13+
14+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
15+
16+
@JiraKey("HHH-17320")
17+
@DomainModel(
18+
annotatedClasses = {
19+
TreeMapAsBasicTypeTest.Customer.class
20+
}
21+
)
22+
@SessionFactory
23+
public class TreeMapAsBasicTypeTest {
24+
25+
@Test
26+
public void testPersist(SessionFactoryScope scope) {
27+
Long cutomerId = 1l;
28+
scope.inTransaction(
29+
session -> {
30+
TreeMap<String, Integer> data = new TreeMap<>();
31+
data.put( "key", 1 );
32+
TreeMap<String, String> data2 = new TreeMap<>();
33+
data2.put( "key2", "2" );
34+
Customer c = new Customer( cutomerId, data, data2 );
35+
session.persist( c );
36+
}
37+
);
38+
39+
scope.inTransaction(
40+
session -> {
41+
Customer customer = session.find( Customer.class, cutomerId );
42+
TreeMap<String, Integer> data = customer.getData();
43+
assertThat( data ).isNotNull();
44+
assertThat( data.get( "key" ) ).isEqualTo( 1 );
45+
TreeMap<String, String> data2 = customer.getData2();
46+
assertThat( data2 ).isNotNull();
47+
assertThat( data2.get( "key2" ) ).isEqualTo( "2" );
48+
}
49+
);
50+
}
51+
52+
@Entity(name = "Customer")
53+
public static class Customer {
54+
55+
@Id
56+
private Long id;
57+
58+
private TreeMap<String, Integer> data;
59+
60+
private TreeMap<String, String> data2;
61+
62+
public Customer() {
63+
}
64+
65+
public Customer(Long id, TreeMap<String, Integer> data, TreeMap<String, String> data2) {
66+
this.id = id;
67+
this.data = data;
68+
this.data2 = data2;
69+
}
70+
71+
public Long getId() {
72+
return id;
73+
}
74+
75+
public TreeMap<String, Integer> getData() {
76+
return data;
77+
}
78+
79+
public TreeMap<String, String> getData2() {
80+
return data2;
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)