1   /* Copyright 2002-2025 CS GROUP
2    * Licensed to CS GROUP (CS) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * CS licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.orekit.data;
18  
19  import org.hamcrest.CoreMatchers;
20  import org.hamcrest.MatcherAssert;
21  import org.junit.jupiter.api.Assertions;
22  import org.junit.jupiter.api.Test;
23  
24  import java.io.File;
25  import java.io.InputStream;
26  import java.net.URISyntaxException;
27  import java.net.URL;
28  import java.util.regex.Pattern;
29  
30  public class ZipJarCrawlerTest {
31  
32      @Test
33      public void testMultiZipClasspath() {
34          CountingLoader crawler = new CountingLoader();
35          new ZipJarCrawler("zipped-data/multizip.zip").feed(Pattern.compile(".*\\.txt$"), crawler,
36                                                             DataContext.getDefault().getDataProvidersManager());
37          Assertions.assertEquals(6, crawler.getCount());
38      }
39  
40      @Test
41      public void testMultiZip() throws URISyntaxException {
42          URL url =
43              ZipJarCrawlerTest.class.getClassLoader().getResource("zipped-data/multizip.zip");
44          CountingLoader crawler = new CountingLoader();
45          new ZipJarCrawler(new File(url.toURI().getPath())).feed(Pattern.compile(".*\\.txt$"), crawler,
46                                                                  DataContext.getDefault().getDataProvidersManager());
47          Assertions.assertEquals(6, crawler.getCount());
48      }
49  
50      private static class CountingLoader implements DataLoader {
51          private int count = 0;
52          public boolean stillAcceptsData() {
53              return true;
54          }
55          public void loadData(InputStream input, String name) {
56              ++count;
57              MatcherAssert.assertThat(name, CoreMatchers.containsString("!/"));
58          }
59          public int getCount() {
60              return count;
61          }
62      }
63  
64  }