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

File SystemHTTPProxyTest.java

 

Code metrics

0
9
1
1
78
45
3
0.33
9
1
3

Classes

Class Line # Actions
SystemHTTPProxyTest 44 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.xwiki.internal;
21   
22    import java.net.URI;
23    import java.net.URISyntaxException;
24   
25    import org.junit.Rule;
26    import org.junit.Test;
27    import org.xwiki.component.manager.ComponentLookupException;
28    import org.xwiki.extension.ResolveException;
29    import org.xwiki.extension.repository.DefaultExtensionRepositoryDescriptor;
30    import org.xwiki.extension.repository.ExtensionRepository;
31    import org.xwiki.extension.repository.ExtensionRepositoryException;
32    import org.xwiki.extension.repository.ExtensionRepositoryFactory;
33    import org.xwiki.test.annotation.AllComponents;
34    import org.xwiki.test.mockito.MockitoComponentMockingRule;
35   
36    import com.github.tomakehurst.wiremock.junit.WireMockRule;
37   
38    import static com.github.tomakehurst.wiremock.client.RequestPatternBuilder.allRequests;
39    import static com.github.tomakehurst.wiremock.client.WireMock.findAll;
40    import static org.junit.Assert.assertFalse;
41    import static org.junit.Assert.assertTrue;
42   
43    @AllComponents
 
44    public class SystemHTTPProxyTest
45    {
46    @Rule
47    public WireMockRule proxyWireMockRule = new WireMockRule(8888);
48   
49    @Rule
50    public MockitoComponentMockingRule<ExtensionRepositoryFactory> repositoryFactory =
51    new MockitoComponentMockingRule<ExtensionRepositoryFactory>(XWikiExtensionRepositoryFactory.class);
52   
 
53  1 toggle @Test
54    public void testProxy() throws ExtensionRepositoryException, ComponentLookupException, URISyntaxException
55    {
56  1 ExtensionRepository repository = this.repositoryFactory.getComponentUnderTest()
57    .createRepository(new DefaultExtensionRepositoryDescriptor("id", "xwiki", new URI("http://host")));
58   
59  1 try {
60  1 repository.resolveVersions("id", 0, -1);
61    } catch (ResolveException e) {
62    // We don't really care if the target artifact exist
63    }
64   
65  1 assertTrue("The repository did not requested the proxy server", findAll(allRequests()).isEmpty());
66   
67  1 System.setProperty("http.proxyHost", "localhost");
68  1 System.setProperty("http.proxyPort", "8888");
69   
70  1 try {
71  1 repository.resolveVersions("id", 0, -1);
72    } catch (ResolveException e) {
73    // We don't really care if the target artifact exist
74    }
75   
76  1 assertFalse("The repository did not requested the proxy server", findAll(allRequests()).isEmpty());
77    }
78    }