Skip to content

Commit b0905c5

Browse files
committed
Add more provider constructors
1 parent ab716c0 commit b0905c5

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

src/main/java/com/imsweb/staging/ExternalStagingFileDataProvider.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import java.io.InputStream;
99
import java.io.InputStreamReader;
1010
import java.nio.charset.StandardCharsets;
11+
import java.nio.file.Files;
12+
import java.nio.file.Path;
13+
import java.nio.file.Paths;
1114
import java.util.HashMap;
1215
import java.util.HashSet;
1316
import java.util.Map;
@@ -44,6 +47,28 @@ public class ExternalStagingFileDataProvider extends StagingDataProvider {
4447
private final Map<String, StagingSchema> _schemas = new HashMap<>();
4548
private final Map<String, GlossaryDefinition> _glossaryTerms = new HashMap<>();
4649

50+
/**
51+
* Constructor loads all schemas and sets up table cache
52+
* @param zipFilePath full path to algorithm zip file
53+
* @throws IOException exception for file operations
54+
*/
55+
public ExternalStagingFileDataProvider(Path zipFilePath) throws IOException {
56+
super();
57+
58+
try (InputStream is = Files.newInputStream(zipFilePath)) {
59+
init(is);
60+
}
61+
}
62+
63+
/**
64+
* Constructor loads all schemas and sets up table cache
65+
* @param zipFileName full path to algorithm zip file
66+
* @throws IOException exception for file operations
67+
*/
68+
public ExternalStagingFileDataProvider(String zipFileName) throws IOException {
69+
this(Paths.get(zipFileName));
70+
}
71+
4772
/**
4873
* Constructor loads all schemas and sets up table cache
4974
* @param is InputStream pointing the zip file

src/test/java/com/imsweb/staging/ExternalStagingFileDataProviderTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22

33
import java.io.IOException;
44
import java.io.InputStream;
5+
import java.nio.file.Path;
6+
import java.nio.file.Paths;
57

68
import org.junit.jupiter.api.BeforeAll;
9+
import org.junit.jupiter.api.Test;
10+
11+
import static org.assertj.core.api.Assertions.assertThat;
12+
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
713

814
class ExternalStagingFileDataProviderTest extends FileDataProviderTest {
915

@@ -21,4 +27,34 @@ public Staging getStaging() {
2127
return _STAGING;
2228
}
2329

30+
@Test
31+
void testConstructorWithPath() throws IOException {
32+
Path zipPath = Paths.get("src/test/resources/external_algorithm.zip");
33+
ExternalStagingFileDataProvider provider = new ExternalStagingFileDataProvider(zipPath);
34+
35+
assertThat(provider.getAlgorithm()).isNotBlank();
36+
assertThat(provider.getVersion()).isNotBlank();
37+
assertThat(provider.getSchemaIds()).isNotEmpty();
38+
assertThat(provider.getTableIds()).isNotEmpty();
39+
}
40+
41+
@Test
42+
void testConstructorWithString() throws IOException {
43+
String zipFileName = "src/test/resources/external_algorithm.zip";
44+
ExternalStagingFileDataProvider provider = new ExternalStagingFileDataProvider(zipFileName);
45+
46+
assertThat(provider.getAlgorithm()).isNotBlank();
47+
assertThat(provider.getVersion()).isNotBlank();
48+
assertThat(provider.getSchemaIds()).isNotEmpty();
49+
assertThat(provider.getTableIds()).isNotEmpty();
50+
}
51+
52+
@Test
53+
void testInvalidPathThrowsException() {
54+
Path invalidPath = Paths.get("src/test/resources/missing.zip");
55+
assertThatThrownBy(() -> new ExternalStagingFileDataProvider(invalidPath))
56+
.isInstanceOf(IOException.class)
57+
.hasMessageContaining("missing.zip");
58+
}
59+
2460
}

0 commit comments

Comments
 (0)