66import cbit .vcell .parser .ExpressionException ;
77import cbit .vcell .solver .SolverException ;
88import cbit .vcell .xml .XmlParseException ;
9- import org .apache .commons .compress .archivers .tar .TarArchiveEntry ;
10- import org .apache .commons .compress .archivers .tar .TarArchiveInputStream ;
119import org .junit .jupiter .api .Test ;
12- import org .vcell .sbml .SbmlException ;
1310
14- import javax .xml .stream .XMLStreamException ;
1511import java .beans .PropertyVetoException ;
16- import java .io .* ;
17- import java .nio . charset . StandardCharsets ;
12+ import java .io .File ;
13+ import java .io . IOException ;
1814import java .nio .file .Files ;
1915import java .nio .file .Path ;
20- import java .util .Objects ;
2116import java .util .UUID ;
22- import java .util .stream .Collectors ;
23- import java .util .zip .GZIPInputStream ;
2417
2518import static org .junit .jupiter .api .Assertions .*;
2619import static org .vcell .libvcell .SolverUtils .sbmlToFiniteVolumeInput ;
2720import static org .vcell .libvcell .SolverUtils .vcmlToFiniteVolumeInput ;
28- import static org .vcell .libvcell .ModelUtils .sbml_to_vcml ;
29- import static org .vcell .libvcell .ModelUtils .vcml_to_sbml ;
30- import static org .vcell .libvcell .ModelUtils .vcml_to_vcml ;
21+ import static org .vcell .libvcell .TestUtils .*;
3122
32- public class EntrypointsTest {
23+ public class SolverEntrypointsTest {
3324
3425 @ Test
3526 public void testSbmlToFiniteVolumeInput () throws PropertyVetoException , SolverException , ExpressionException , MappingException , VCLoggerException , IOException {
@@ -66,7 +57,7 @@ public void testVcmlToFiniteVolumeInput_field_data() throws SolverException, Exp
6657 File output_dir = new File (parent_dir , "output_dir" );
6758 File ext_data_dir = new File (parent_dir , "test2_lsm_DEMO" );
6859 assertEquals (0 , countFiles (ext_data_dir ));
69- extractTgz (EntrypointsTest .class .getResourceAsStream ("/test2_lsm_DEMO.tgz" ), parent_dir );
60+ extractTgz (SolverEntrypointsTest .class .getResourceAsStream ("/test2_lsm_DEMO.tgz" ), parent_dir );
7061 listFilesInDirectory (ext_data_dir );
7162 assertEquals (10 , countFiles (ext_data_dir ));
7263
@@ -87,7 +78,7 @@ public void testVcmlToFiniteVolumeInput_field_data_not_found() throws SolverExce
8778 File ext_data_dir_MISSPELLED = new File (parent_dir , "test2_lsm_DEMO_MISSPELLED" );
8879 assertEquals (0 , countFiles (ext_data_dir ));
8980 assertEquals (0 , countFiles (ext_data_dir_MISSPELLED ));
90- extractTgz (EntrypointsTest .class .getResourceAsStream ("/test2_lsm_DEMO.tgz" ), parent_dir );
81+ extractTgz (SolverEntrypointsTest .class .getResourceAsStream ("/test2_lsm_DEMO.tgz" ), parent_dir );
9182 Files .move (ext_data_dir .toPath (), ext_data_dir_MISSPELLED .toPath ()).toFile ();
9283 assertEquals (0 , countFiles (ext_data_dir ));
9384 listFilesInDirectory (ext_data_dir_MISSPELLED );
@@ -112,34 +103,6 @@ public void testVcmlToFiniteVolumeInput() throws SolverException, ExpressionExce
112103 assertEquals (4 , countFiles (output_dir ));
113104 }
114105
115- @ Test
116- public void test_sbml_to_vcml () throws MappingException , IOException , XmlParseException , VCLoggerException {
117- String sbmlContent = getFileContentsAsString ("/TinySpatialProject_Application0.xml" );
118- File parent_dir = Files .createTempDirectory ("sbmlToVcml" ).toFile ();
119- File vcml_temp_file = new File (parent_dir , "temp.vcml" );
120- sbml_to_vcml (sbmlContent , vcml_temp_file .toPath ());
121- assert (vcml_temp_file .exists ());
122- }
123-
124- @ Test
125- public void test_vcml_to_sbml () throws MappingException , IOException , XmlParseException , XMLStreamException , SbmlException {
126- String vcmlContent = getFileContentsAsString ("/TinySpatialProject_Application0.vcml" );
127- File parent_dir = Files .createTempDirectory ("vcmlToSbml" ).toFile ();
128- File sbml_temp_file = new File (parent_dir , "temp.sbml" );
129- String applicationName = "unnamed_spatialGeom" ;
130- vcml_to_sbml (vcmlContent , applicationName , sbml_temp_file .toPath ());
131- assert (sbml_temp_file .exists ());
132- }
133-
134- @ Test
135- public void test_vcml_to_vcml () throws MappingException , IOException , XmlParseException , XMLStreamException , SbmlException {
136- String vcmlContent = getFileContentsAsString ("/TinySpatialProject_Application0.vcml" );
137- File parent_dir = Files .createTempDirectory ("vcmlToVcml" ).toFile ();
138- File vcml_temp_file = new File (parent_dir , "temp.vcml" );
139- vcml_to_vcml (vcmlContent , vcml_temp_file .toPath ());
140- assert (vcml_temp_file .exists ());
141- }
142-
143106 @ Test
144107 public void testVcmlToFiniteVolumeInput_bad_simname () throws IOException {
145108 String vcmlContent = getFileContentsAsString ("/TinySpatialProject_Application0.vcml" );
@@ -177,75 +140,4 @@ public void testVcmlToFiniteVolumeInput_sbml_instead() throws IOException {
177140 assertEquals ("expecting VCML content, not SBML" , exc .getMessage ());
178141 }
179142
180- private static String getFileContentsAsString (String filename ) throws IOException {
181- try (InputStream inputStream = EntrypointsTest .class .getResourceAsStream (filename )) {
182- if (inputStream == null ) {
183- throw new FileNotFoundException ("file not found! " + filename );
184- }
185- return new BufferedReader (new InputStreamReader (inputStream , StandardCharsets .UTF_8 ))
186- .lines ().collect (Collectors .joining ("\n " ));
187- }
188- }
189-
190- private static byte [] getFileContentsAsBytes (String filename ) throws IOException {
191- try (InputStream inputStream = EntrypointsTest .class .getResourceAsStream (filename )) {
192- if (inputStream == null ) {
193- throw new FileNotFoundException ("file not found! " + filename );
194- }
195- try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream ()) {
196- byte [] buffer = new byte [1024 ];
197- int length ;
198- while ((length = inputStream .read (buffer )) != -1 ) {
199- byteArrayOutputStream .write (buffer , 0 , length );
200- }
201- return byteArrayOutputStream .toByteArray ();
202- }
203- }
204- }
205-
206- private int countFiles (File dir ) {
207- File [] files = dir .listFiles ();
208- if (files == null ) {
209- return 0 ;
210- }
211- return Objects .requireNonNull (dir .listFiles ()).length ;
212- }
213-
214- private void listFilesInDirectory (File dir ) {
215- File [] files = dir .listFiles ();
216- if (files != null ) {
217- for (File file : files ) {
218- System .out .println (file .getAbsolutePath ());
219- }
220- }
221- }
222-
223- public static void extractTgz (InputStream tgzFileStream , File outputDir ) throws IOException {
224- try (GZIPInputStream gis = new GZIPInputStream (tgzFileStream );
225- TarArchiveInputStream tis = new TarArchiveInputStream (gis )) {
226-
227- TarArchiveEntry entry ;
228- while ((entry = tis .getNextTarEntry ()) != null ) {
229- File outputFile = new File (outputDir , entry .getName ());
230- if (entry .isDirectory ()) {
231- if (!outputFile .exists ()) {
232- outputFile .mkdirs ();
233- }
234- } else {
235- File parent = outputFile .getParentFile ();
236- if (!parent .exists ()) {
237- parent .mkdirs ();
238- }
239- try (OutputStream os = Files .newOutputStream (outputFile .toPath ())) {
240- byte [] buffer = new byte [1024 ];
241- int len ;
242- while ((len = tis .read (buffer )) != -1 ) {
243- os .write (buffer , 0 , len );
244- }
245- }
246- }
247- }
248- }
249- }
250-
251143}
0 commit comments