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.junit.jupiter.api.Assertions;
20 import org.junit.jupiter.api.Test;
21 import org.orekit.errors.OrekitException;
22
23 import java.io.File;
24 import java.io.FileNotFoundException;
25 import java.net.MalformedURLException;
26 import java.net.URL;
27 import java.util.regex.Pattern;
28
29 public class NetworkCrawlerTest extends AbstractListCrawlerTest<URL> {
30
31 protected URL input(String resource) {
32 return NetworkCrawlerTest.class.getClassLoader().getResource(resource);
33 }
34
35 protected NetworkCrawler build(String... inputs) {
36 URL[] converted = new URL[inputs.length];
37 for (int i = 0; i < inputs.length; ++i) {
38 converted[i] = input(inputs[i]);
39 }
40 final NetworkCrawler nc = new NetworkCrawler(converted);
41 nc.setTimeout(20);
42 return nc;
43 }
44
45 @Test
46 public void noElement() throws MalformedURLException {
47 try {
48 File existing = new File(input("regular-data").getPath());
49 File inexistent = new File(existing.getParent(), "inexistant-directory");
50 new NetworkCrawler(inexistent.toURI().toURL()).feed(Pattern.compile(".*"), new CountingLoader(),
51 DataContext.getDefault().getDataProvidersManager());
52 Assertions.fail("an exception should have been thrown");
53 } catch (OrekitException oe) {
54 Assertions.assertTrue(oe.getCause() instanceof FileNotFoundException);
55 Assertions.assertTrue(oe.getLocalizedMessage().contains("inexistant-directory"));
56 }
57 }
58
59 // WARNING!
60 // the following test is commented out by default, as it does connect to the web
61 // if you want to enable it, you will have uncomment it and to either set the proxy
62 // settings according to your local network or remove the proxy authentication
63 // settings if you have a transparent connection to internet
64 // @Test
65 // public void remote() throws java.net.MalformedURLException {
66 //
67 // System.setProperty("http.proxyHost", "proxy.your.domain.com");
68 // System.setProperty("http.proxyPort", "8080");
69 // System.setProperty("http.nonProxyHosts", "localhost|*.your.domain.com");
70 // java.net.Authenticator.setDefault(new AuthenticatorDialog());
71 // CountingLoader loader = new CountingLoader();
72 // NetworkCrawler crawler =
73 // new NetworkCrawler(new URL("http://hpiers.obspm.fr/eoppc/bul/bulc/UTC-TAI.history"));
74 // crawler.setTimeout(1000);
75 // crawler.feed(Pattern.compile(".*\\.history"), loader);
76 // Assertions.assertEquals(1, loader.getCount());
77 //
78 // }
79
80 }