Skip to content

Commit 36ab046

Browse files
committed
HHH-8511 add passing test
1 parent 7e30638 commit 36ab046

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.lob;
6+
7+
import java.sql.Clob;
8+
import java.sql.SQLException;
9+
import java.util.List;
10+
import jakarta.persistence.Entity;
11+
import jakarta.persistence.GeneratedValue;
12+
import jakarta.persistence.Id;
13+
import jakarta.persistence.Lob;
14+
import jakarta.persistence.Table;
15+
16+
import org.hibernate.query.Query;
17+
18+
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
19+
import org.hibernate.testing.orm.junit.JiraKey;
20+
import org.junit.Test;
21+
22+
import static org.hamcrest.core.Is.is;
23+
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
24+
import static org.junit.Assert.assertThat;
25+
import static org.junit.Assert.fail;
26+
27+
/**
28+
* @author Andrea Boriero
29+
* @author VladoKuruc
30+
*/
31+
@JiraKey("HHH-8511")
32+
//@RequiresDialect(InformixDialect.class)
33+
public class InformixLobStringTest extends BaseCoreFunctionalTestCase {
34+
35+
private final String value1 = "xxxxxxxxxx".repeat( 20 );
36+
private final String value2 = "yyyyyyyyyy".repeat( 20 );
37+
38+
@Override
39+
protected Class<?>[] getAnnotatedClasses() {
40+
return new Class[] {TestEntity.class};
41+
}
42+
43+
@Override
44+
protected void prepareTest() throws Exception {
45+
TestEntity entity = new TestEntity();
46+
doInHibernate( this::sessionFactory, session -> {
47+
entity.setFirstLobField( value1 );
48+
entity.setSecondLobField( value2 );
49+
entity.setClobField( session.getLobHelper().createClob( value2 ) );
50+
session.persist( entity );
51+
} );
52+
53+
doInHibernate( this::sessionFactory, session -> {
54+
final TestEntity testEntity = session.find( TestEntity.class, entity.getId() );
55+
assertThat( testEntity.getFirstLobField(), is( value1 ) );
56+
} );
57+
}
58+
59+
@Test
60+
@JiraKey("HHH-8511")
61+
public void testHqlQuery() {
62+
doInHibernate( this::sessionFactory, session -> {
63+
final Query query = session.createQuery( "from TestEntity" );
64+
65+
final List<TestEntity> results = query.list();
66+
67+
assertThat( results.size(), is( 1 ) );
68+
69+
final TestEntity testEntity = results.get( 0 );
70+
assertThat( testEntity.getFirstLobField(), is( value1 ) );
71+
assertThat( testEntity.getSecondLobField(), is( value2 ) );
72+
final Clob clobField = testEntity.getClobField();
73+
try {
74+
75+
assertThat( clobField.getSubString( 1, (int) clobField.length() ), is( value2 ) );
76+
}
77+
catch (SQLException e) {
78+
fail( e.getMessage() );
79+
}
80+
} );
81+
}
82+
83+
@Entity(name = "TestEntity")
84+
@Table(name = "TEST_ENTITY")
85+
public static class TestEntity {
86+
@Id
87+
@GeneratedValue
88+
private long id;
89+
90+
@Lob
91+
String firstLobField;
92+
93+
@Lob
94+
String secondLobField;
95+
96+
@Lob
97+
Clob clobField;
98+
99+
public long getId() {
100+
return id;
101+
}
102+
103+
public String getFirstLobField() {
104+
return firstLobField;
105+
}
106+
107+
public void setFirstLobField(String firstLobField) {
108+
this.firstLobField = firstLobField;
109+
}
110+
111+
public String getSecondLobField() {
112+
return secondLobField;
113+
}
114+
115+
public void setSecondLobField(String secondLobField) {
116+
this.secondLobField = secondLobField;
117+
}
118+
119+
public Clob getClobField() {
120+
return clobField;
121+
}
122+
123+
public void setClobField(Clob clobField) {
124+
this.clobField = clobField;
125+
}
126+
}
127+
128+
@Override
129+
protected boolean isCleanupTestDataRequired() {
130+
return true;
131+
}
132+
}

0 commit comments

Comments
 (0)