1   /* Copyright 2002-2022 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  
20  import java.io.File;
21  import java.io.InputStream;
22  import java.net.URISyntaxException;
23  import java.net.URL;
24  import java.util.regex.Pattern;
25  
26  import org.hamcrest.CoreMatchers;
27  import org.hamcrest.MatcherAssert;
28  import org.junit.Assert;
29  import org.junit.Test;
30  
31  public class ZipJarCrawlerTest {
32  
33      @Test
34      public void testMultiZipClasspath() {
35          CountingLoader crawler = new CountingLoader();
36          new ZipJarCrawler("zipped-data/multizip.zip").feed(Pattern.compile(".*\\.txt$"), crawler,
37                                                             DataContext.getDefault().getDataProvidersManager());
38          Assert.assertEquals(6, crawler.getCount());
39      }
40  
41      @Test
42      public void testMultiZip() throws URISyntaxException {
43          URL url =
44              ZipJarCrawlerTest.class.getClassLoader().getResource("zipped-data/multizip.zip");
45          CountingLoader crawler = new CountingLoader();
46          new ZipJarCrawler(new File(url.toURI().getPath())).feed(Pattern.compile(".*\\.txt$"), crawler,
47                                                                  DataContext.getDefault().getDataProvidersManager());
48          Assert.assertEquals(6, crawler.getCount());
49      }
50  
51      private static class CountingLoader implements DataLoader {
52          private int count = 0;
53          public boolean stillAcceptsData() {
54              return true;
55          }
56          public void loadData(InputStream input, String name) {
57              ++count;
58              MatcherAssert.assertThat(name, CoreMatchers.containsString("!/"));
59          }
60          public int getCount() {
61              return count;
62          }
63      }
64  
65  }