Skip to content

Commit b342a62

Browse files
cigalybeikov
authored andcommitted
HHH-19464 Test case adapted from https://hibernate.atlassian.net/browse/HHH-19464
1 parent 7bce152 commit b342a62

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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.lob;
8+
9+
import org.hibernate.bugs.TestEntity;
10+
import org.hibernate.engine.jdbc.env.internal.NonContextualLobCreator;
11+
import org.hibernate.testing.orm.junit.DomainModel;
12+
import org.hibernate.testing.orm.junit.JiraKey;
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 java.io.File;
18+
import java.io.IOException;
19+
import java.io.InputStream;
20+
import java.sql.Blob;
21+
import java.sql.SQLException;
22+
import java.util.jar.JarEntry;
23+
import java.util.jar.JarFile;
24+
25+
import static org.junit.jupiter.api.Assertions.assertEquals;
26+
27+
@DomainModel(annotatedClasses = TestEntity.class)
28+
@SessionFactory
29+
@JiraKey( "HHH-19464" )
30+
class JarFileEntryBlobTest {
31+
32+
@Test
33+
void hibernate_blob_streaming(SessionFactoryScope scope) throws Exception {
34+
final var zipFilePath = getClass().getClassLoader().getResource( "org/hibernate/orm/test/lob/JarFileEntryBlobTest.zip" );
35+
File file = new File( zipFilePath.toURI() );
36+
37+
try (JarFile jarFile = new JarFile( file )) {
38+
JarEntry entry = jarFile.getJarEntry( "pizza.png" );
39+
long size = entry.getSize();
40+
scope.inTransaction( entityManager -> {
41+
try {
42+
InputStream is = jarFile.getInputStream( entry );
43+
Blob blob = NonContextualLobCreator.INSTANCE.wrap(
44+
NonContextualLobCreator.INSTANCE.createBlob( is, size )
45+
);
46+
TestEntity e = new TestEntity();
47+
e.setId( 1L );
48+
e.setData( blob );
49+
50+
entityManager.persist( e );
51+
}
52+
catch (IOException e) {
53+
throw new RuntimeException( e );
54+
}
55+
}
56+
);
57+
58+
scope.inStatelessSession( session -> {
59+
final var entity = session.get( TestEntity.class, 1L );
60+
try {
61+
assertEquals( size, entity.getData().length() );
62+
}
63+
catch (SQLException e) {
64+
throw new RuntimeException( e );
65+
}
66+
} );
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)