Skip to content

Commit aa13a49

Browse files
committed
Unify rescource unzipping
1 parent ca8b90e commit aa13a49

File tree

2 files changed

+5
-32
lines changed

2 files changed

+5
-32
lines changed

src/test/java/org/ohdsi/usagi/indexBuilding/BerkeleyDbBuilderIT.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.junit.jupiter.api.io.TempDir;
77
import org.ohdsi.usagi.BerkeleyDbEngine;
88
import org.ohdsi.usagi.Concept;
9+
import org.ohdsi.usagi.TestUtils;
910
import org.ohdsi.usagi.MapsToRelationship;
1011
import org.ohdsi.usagi.ParentChildRelationShip;
1112
import org.ohdsi.usagi.ui.Global;
@@ -170,15 +171,7 @@ void testBuildIndexWithZipResource() throws IOException {
170171
Path zipVocabFolder = tempDir.resolve("zip_vocab");
171172
Files.createDirectories(zipVocabFolder);
172173

173-
try (ZipInputStream zis = new ZipInputStream(
174-
getClass().getResourceAsStream("/OMOP-vocabularies-minimal.zip"))) {
175-
ZipEntry entry;
176-
while ((entry = zis.getNextEntry()) != null) {
177-
Path filePath = zipVocabFolder.resolve(entry.getName());
178-
Files.copy(zis, filePath);
179-
zis.closeEntry();
180-
}
181-
}
174+
TestUtils.unzipResource("/OMOP-vocabularies-minimal.zip", zipVocabFolder);
182175

183176
// Set up the Global folder for the database in a separate subfolder
184177
Path dbFolder = tempDir.resolve("zip_db");

src/test/java/org/ohdsi/usagi/ui/UsagiMainIT.java

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import org.junit.jupiter.api.Test;
1313
import org.junit.jupiter.api.io.TempDir;
1414

15+
import org.ohdsi.usagi.TestUtils;
16+
1517
import javax.swing.*;
1618
import java.io.File;
1719
import java.io.FileOutputStream;
@@ -60,7 +62,7 @@ private void setupEnvironment(boolean createAuthorFile) throws IOException {
6062
// Unzip OMOP vocabularies
6163
vocabDir = tempDir.resolve("vocab");
6264
Files.createDirectories(vocabDir);
63-
unzipResource("/OMOP-vocabularies-minimal.zip", vocabDir);
65+
TestUtils.unzipResource("/OMOP-vocabularies-minimal.zip", vocabDir);
6466

6567
// Prepare UsagiMain
6668
String[] args = {tempDir.toAbsolutePath().toString()};
@@ -163,26 +165,4 @@ private void runBuildIndexTest() {
163165
restartPane.okButton().click();
164166
}
165167

166-
private void unzipResource(String resourceName, Path targetDir) throws IOException {
167-
try (InputStream is = getClass().getResourceAsStream(resourceName);
168-
ZipInputStream zis = new ZipInputStream(is)) {
169-
ZipEntry entry;
170-
while ((entry = zis.getNextEntry()) != null) {
171-
File newFile = new File(targetDir.toFile(), entry.getName());
172-
if (entry.isDirectory()) {
173-
newFile.mkdirs();
174-
} else {
175-
newFile.getParentFile().mkdirs();
176-
try (FileOutputStream fos = new FileOutputStream(newFile)) {
177-
byte[] buffer = new byte[1024];
178-
int len;
179-
while ((len = zis.read(buffer)) > 0) {
180-
fos.write(buffer, 0, len);
181-
}
182-
}
183-
}
184-
zis.closeEntry();
185-
}
186-
}
187-
}
188168
}

0 commit comments

Comments
 (0)