1 package org.eclipse.aether.repository;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import static org.junit.Assert.*;
23
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.List;
27 import java.util.Map;
28
29 import org.eclipse.aether.repository.RemoteRepository.Builder;
30 import org.junit.Before;
31 import org.junit.Test;
32
33 public class RemoteRepositoryBuilderTest
34 {
35
36 private RemoteRepository prototype;
37
38 @Before
39 public void init()
40 {
41 prototype = new Builder( "id", "type", "file:void" ).build();
42 }
43
44 @Test
45 public void testReusePrototype()
46 {
47 Builder builder = new Builder( prototype );
48 assertSame( prototype, builder.build() );
49 }
50
51 @Test( expected = NullPointerException.class )
52 public void testPrototypeMandatory()
53 {
54 new Builder( null );
55 }
56
57 @Test
58 public void testSetId()
59 {
60 Builder builder = new Builder( prototype );
61 RemoteRepository repo = builder.setId( prototype.getId() ).build();
62 assertSame( prototype, repo );
63 repo = builder.setId( "new-id" ).build();
64 assertEquals( "new-id", repo.getId() );
65 }
66
67 @Test
68 public void testSetContentType()
69 {
70 Builder builder = new Builder( prototype );
71 RemoteRepository repo = builder.setContentType( prototype.getContentType() ).build();
72 assertSame( prototype, repo );
73 repo = builder.setContentType( "new-type" ).build();
74 assertEquals( "new-type", repo.getContentType() );
75 }
76
77 @Test
78 public void testSetUrl()
79 {
80 Builder builder = new Builder( prototype );
81 RemoteRepository repo = builder.setUrl( prototype.getUrl() ).build();
82 assertSame( prototype, repo );
83 repo = builder.setUrl( "file:new" ).build();
84 assertEquals( "file:new", repo.getUrl() );
85 }
86
87 @Test
88 public void testSetPolicy()
89 {
90 Builder builder = new Builder( prototype );
91 RemoteRepository repo = builder.setPolicy( prototype.getPolicy( false ) ).build();
92 assertSame( prototype, repo );
93 RepositoryPolicy policy = new RepositoryPolicy( true, "never", "fail" );
94 repo = builder.setPolicy( policy ).build();
95 assertEquals( policy, repo.getPolicy( true ) );
96 assertEquals( policy, repo.getPolicy( false ) );
97 }
98
99 @Test
100 public void testSetReleasePolicy()
101 {
102 Builder builder = new Builder( prototype );
103 RemoteRepository repo = builder.setReleasePolicy( prototype.getPolicy( false ) ).build();
104 assertSame( prototype, repo );
105 RepositoryPolicy policy = new RepositoryPolicy( true, "never", "fail" );
106 repo = builder.setReleasePolicy( policy ).build();
107 assertEquals( policy, repo.getPolicy( false ) );
108 assertEquals( prototype.getPolicy( true ), repo.getPolicy( true ) );
109 }
110
111 @Test
112 public void testSetSnapshotPolicy()
113 {
114 Builder builder = new Builder( prototype );
115 RemoteRepository repo = builder.setSnapshotPolicy( prototype.getPolicy( true ) ).build();
116 assertSame( prototype, repo );
117 RepositoryPolicy policy = new RepositoryPolicy( true, "never", "fail" );
118 repo = builder.setSnapshotPolicy( policy ).build();
119 assertEquals( policy, repo.getPolicy( true ) );
120 assertEquals( prototype.getPolicy( false ), repo.getPolicy( false ) );
121 }
122
123 @Test
124 public void testSetProxy()
125 {
126 Builder builder = new Builder( prototype );
127 RemoteRepository repo = builder.setProxy( prototype.getProxy() ).build();
128 assertSame( prototype, repo );
129 Proxy proxy = new Proxy( "http", "localhost", 8080 );
130 repo = builder.setProxy( proxy ).build();
131 assertEquals( proxy, repo.getProxy() );
132 }
133
134 @Test
135 public void testSetAuthentication()
136 {
137 Builder builder = new Builder( prototype );
138 RemoteRepository repo = builder.setAuthentication( prototype.getAuthentication() ).build();
139 assertSame( prototype, repo );
140 Authentication auth = new Authentication()
141 {
142 public void fill( AuthenticationContext context, String key, Map<String, String> data )
143 {
144 }
145
146 public void digest( AuthenticationDigest digest )
147 {
148 }
149 };
150 repo = builder.setAuthentication( auth ).build();
151 assertEquals( auth, repo.getAuthentication() );
152 }
153
154 @Test
155 public void testSetMirroredRepositories()
156 {
157 Builder builder = new Builder( prototype );
158 RemoteRepository repo = builder.setMirroredRepositories( prototype.getMirroredRepositories() ).build();
159 assertSame( prototype, repo );
160 List<RemoteRepository> mirrored = new ArrayList<>( Arrays.asList( repo ) );
161 repo = builder.setMirroredRepositories( mirrored ).build();
162 assertEquals( mirrored, repo.getMirroredRepositories() );
163 }
164
165 @Test
166 public void testAddMirroredRepository()
167 {
168 Builder builder = new Builder( prototype );
169 RemoteRepository repo = builder.addMirroredRepository( null ).build();
170 assertSame( prototype, repo );
171 repo = builder.addMirroredRepository( prototype ).build();
172 assertEquals( Arrays.asList( prototype ), repo.getMirroredRepositories() );
173 }
174
175 @Test
176 public void testSetRepositoryManager()
177 {
178 Builder builder = new Builder( prototype );
179 RemoteRepository repo = builder.setRepositoryManager( prototype.isRepositoryManager() ).build();
180 assertSame( prototype, repo );
181 repo = builder.setRepositoryManager( !prototype.isRepositoryManager() ).build();
182 assertEquals( !prototype.isRepositoryManager(), repo.isRepositoryManager() );
183 }
184
185 }