1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.extension.repository.aether.internal

File SystemHTTPProxyTest.java

 

Code metrics

0
9
1
1
82
49
3
0.33
9
1
3

Classes

Class Line # Actions
SystemHTTPProxyTest 46 9 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.extension.repository.aether.internal;
21   
22    import java.io.IOException;
23    import java.net.URI;
24    import java.net.URISyntaxException;
25   
26    import org.apache.http.client.ClientProtocolException;
27    import org.junit.Rule;
28    import org.junit.Test;
29    import org.xwiki.component.manager.ComponentLookupException;
30    import org.xwiki.extension.ResolveException;
31    import org.xwiki.extension.repository.DefaultExtensionRepositoryDescriptor;
32    import org.xwiki.extension.repository.ExtensionRepository;
33    import org.xwiki.extension.repository.ExtensionRepositoryException;
34    import org.xwiki.extension.repository.ExtensionRepositoryFactory;
35    import org.xwiki.test.annotation.AllComponents;
36    import org.xwiki.test.mockito.MockitoComponentMockingRule;
37   
38    import com.github.tomakehurst.wiremock.junit.WireMockRule;
39   
40    import static com.github.tomakehurst.wiremock.client.RequestPatternBuilder.allRequests;
41    import static com.github.tomakehurst.wiremock.client.WireMock.findAll;
42    import static org.junit.Assert.assertFalse;
43    import static org.junit.Assert.assertTrue;
44   
45    @AllComponents
 
46    public class SystemHTTPProxyTest
47    {
48    @Rule
49    public WireMockRule proxyWireMockRule = new WireMockRule(8888);
50   
51    @Rule
52    public MockitoComponentMockingRule<ExtensionRepositoryFactory> repositoryFactory =
53    new MockitoComponentMockingRule<ExtensionRepositoryFactory>(AetherExtensionRepositoryFactory.class);
54   
 
55  1 toggle @Test
56    public void testProxy() throws ClientProtocolException, IOException, ExtensionRepositoryException,
57    ComponentLookupException, URISyntaxException
58    {
59  1 ExtensionRepository repository =
60    this.repositoryFactory.getComponentUnderTest().createRepository(
61    new DefaultExtensionRepositoryDescriptor("id", "maven", new URI("http://unknownhostforxwikitest")));
62   
63  1 try {
64  1 repository.resolveVersions("groupid:artifactid", 0, -1);
65    } catch (ResolveException e) {
66    // We don't really care if the target artifact exist
67    }
68   
69  1 assertTrue("The repository did not requested the proxy server", findAll(allRequests()).isEmpty());
70   
71  1 System.setProperty("http.proxyHost", "localhost");
72  1 System.setProperty("http.proxyPort", "8888");
73   
74  1 try {
75  1 repository.resolveVersions("groupid:artifactid", 0, -1);
76    } catch (ResolveException e) {
77    // We don't really care if the target artifact exist
78    }
79   
80  1 assertFalse("The repository did not requested the proxy server", findAll(allRequests()).isEmpty());
81    }
82    }