1 package org.eclipse.aether.internal.impl;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.eclipse.aether.DefaultRepositorySystemSession;
23 import org.eclipse.aether.RepositorySystemSession;
24 import org.eclipse.aether.repository.RemoteRepository;
25 import org.eclipse.aether.transfer.RepositoryOfflineException;
26 import org.junit.Before;
27 import org.junit.Test;
28
29 public class DefaultOfflineControllerTest
30 {
31
32 private DefaultOfflineController controller;
33
34 private RepositorySystemSession newSession( boolean offline, String protocols, String hosts )
35 {
36 DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
37 session.setOffline( offline );
38 session.setConfigProperty( DefaultOfflineController.CONFIG_PROP_OFFLINE_PROTOCOLS, protocols );
39 session.setConfigProperty( DefaultOfflineController.CONFIG_PROP_OFFLINE_HOSTS, hosts );
40 return session;
41 }
42
43 private RemoteRepository newRepo( String url )
44 {
45 return new RemoteRepository.Builder( "central", "default", url ).build();
46 }
47
48 @Before
49 public void setup()
50 {
51 controller = new DefaultOfflineController();
52 }
53
54 @Test( expected = RepositoryOfflineException.class )
55 public void testCheckOffline_Online()
56 throws Exception
57 {
58 controller.checkOffline( newSession( false, null, null ), newRepo( "http://eclipse.org" ) );
59 }
60
61 @Test( expected = RepositoryOfflineException.class )
62 public void testCheckOffline_Offline()
63 throws Exception
64 {
65 controller.checkOffline( newSession( true, null, null ), newRepo( "http://eclipse.org" ) );
66 }
67
68 @Test
69 public void testCheckOffline_Offline_OfflineProtocol()
70 throws Exception
71 {
72 controller.checkOffline( newSession( true, "file", null ), newRepo( "file://repo" ) );
73 controller.checkOffline( newSession( true, "file", null ), newRepo( "FILE://repo" ) );
74 controller.checkOffline( newSession( true, " file , classpath ", null ), newRepo( "file://repo" ) );
75 controller.checkOffline( newSession( true, " file , classpath ", null ), newRepo( "classpath://repo" ) );
76 }
77
78 @Test( expected = RepositoryOfflineException.class )
79 public void testCheckOffline_Offline_OnlineProtocol()
80 throws Exception
81 {
82 controller.checkOffline( newSession( true, "file", null ), newRepo( "http://eclipse.org" ) );
83 }
84
85 @Test
86 public void testCheckOffline_Offline_OfflineHost()
87 throws Exception
88 {
89 controller.checkOffline( newSession( true, null, "localhost" ), newRepo( "http://localhost" ) );
90 controller.checkOffline( newSession( true, null, "localhost" ), newRepo( "http://LOCALHOST" ) );
91 controller.checkOffline( newSession( true, null, " localhost , 127.0.0.1 " ), newRepo( "http://localhost" ) );
92 controller.checkOffline( newSession( true, null, " localhost , 127.0.0.1 " ), newRepo( "http://127.0.0.1" ) );
93 }
94
95 @Test( expected = RepositoryOfflineException.class )
96 public void testCheckOffline_Offline_OnlineHost()
97 throws Exception
98 {
99 controller.checkOffline( newSession( true, null, "localhost" ), newRepo( "http://eclipse.org" ) );
100 }
101
102 }