View Javadoc
1   /*
2    * Copyright (C) 2020, Thomas Wolf <thomas.wolf@paranor.ch> and others
3    *
4    * This program and the accompanying materials are made available under the
5    * terms of the Eclipse Distribution License v. 1.0 which is available at
6    * https://www.eclipse.org/org/documents/edl-v10.php.
7    *
8    * SPDX-License-Identifier: BSD-3-Clause
9    */
10  package org.eclipse.jgit.http.test;
11  
12  import java.util.ArrayList;
13  import java.util.Collection;
14  import java.util.List;
15  
16  import org.eclipse.jgit.junit.http.HttpTestCase;
17  import org.eclipse.jgit.transport.HttpTransport;
18  import org.eclipse.jgit.transport.http.HttpConnectionFactory;
19  import org.eclipse.jgit.transport.http.JDKHttpConnectionFactory;
20  import org.eclipse.jgit.transport.http.apache.HttpClientConnectionFactory;
21  import org.junit.AfterClass;
22  import org.junit.BeforeClass;
23  import org.junit.Ignore;
24  import org.junit.runner.RunWith;
25  import org.junit.runners.Parameterized;
26  import org.junit.runners.Parameterized.Parameters;
27  
28  /**
29   * Abstract test base class for running HTTP-related tests with all connection
30   * factories provided in JGit and with both protocol V0 and V2.
31   */
32  @Ignore
33  @RunWith(Parameterized.class)
34  public abstract class AllProtocolsHttpTestCase extends HttpTestCase {
35  
36  	protected static class TestParameters {
37  
38  		public final HttpConnectionFactory factory;
39  
40  		public final boolean enableProtocolV2;
41  
42  		public TestParameters(HttpConnectionFactory factory,
43  				boolean enableProtocolV2) {
44  			this.factory = factory;
45  			this.enableProtocolV2 = enableProtocolV2;
46  		}
47  
48  		@Override
49  		public String toString() {
50  			return factory.toString() + " protocol "
51  					+ (enableProtocolV2 ? "V2" : "V0");
52  		}
53  	}
54  
55  	@Parameters(name = "{0}")
56  	public static Collection<TestParameters> data() {
57  		// run all tests with both connection factories we have
58  		HttpConnectionFactory[] factories = new HttpConnectionFactory[] {
59  				new JDKHttpConnectionFactory() {
60  
61  					@Override
62  					public String toString() {
63  						return this.getClass().getSuperclass().getName();
64  					}
65  				}, new HttpClientConnectionFactory() {
66  
67  					@Override
68  					public String toString() {
69  						return this.getClass().getSuperclass().getName();
70  					}
71  				} };
72  		List<TestParameters> result = new ArrayList<>();
73  		for (HttpConnectionFactory factory : factories) {
74  			result.add(new TestParameters(factory, false));
75  			result.add(new TestParameters(factory, true));
76  		}
77  		return result;
78  	}
79  
80  	protected final boolean enableProtocolV2;
81  
82  	protected AllProtocolsHttpTestCase(TestParameters params) {
83  		HttpTransport.setConnectionFactory(params.factory);
84  		enableProtocolV2 = params.enableProtocolV2;
85  	}
86  
87  	private static HttpConnectionFactory originalFactory;
88  
89  	@BeforeClass
90  	public static void saveConnectionFactory() {
91  		originalFactory = HttpTransport.getConnectionFactory();
92  	}
93  
94  	@AfterClass
95  	public static void restoreConnectionFactory() {
96  		HttpTransport.setConnectionFactory(originalFactory);
97  	}
98  
99  }