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