aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AllProtocolsHttpTestCase.java
blob: c6931ad5b9ae0eb65d60619759781a72ea19d084 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
 * Copyright (C) 2020, Thomas Wolf <thomas.wolf@paranor.ch> and others
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Distribution License v. 1.0 which is available at
 * https://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */
package org.eclipse.jgit.http.test;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.eclipse.jgit.junit.http.HttpTestCase;
import org.eclipse.jgit.transport.HttpTransport;
import org.eclipse.jgit.transport.http.HttpConnectionFactory;
import org.eclipse.jgit.transport.http.JDKHttpConnectionFactory;
import org.eclipse.jgit.transport.http.apache.HttpClientConnectionFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

/**
 * Abstract test base class for running HTTP-related tests with all connection
 * factories provided in JGit and with both protocol V0 and V2.
 */
@Ignore
@RunWith(Parameterized.class)
public abstract class AllProtocolsHttpTestCase extends HttpTestCase {

	protected static class TestParameters {

		public final HttpConnectionFactory factory;

		public final boolean enableProtocolV2;

		public TestParameters(HttpConnectionFactory factory,
				boolean enableProtocolV2) {
			this.factory = factory;
			this.enableProtocolV2 = enableProtocolV2;
		}

		@Override
		public String toString() {
			return factory.toString() + " protocol "
					+ (enableProtocolV2 ? "V2" : "V0");
		}
	}

	@Parameters(name = "{0}")
	public static Collection<TestParameters> data() {
		// run all tests with both connection factories we have
		HttpConnectionFactory[] factories = new HttpConnectionFactory[] {
				new JDKHttpConnectionFactory() {

					@Override
					public String toString() {
						return this.getClass().getSuperclass().getName();
					}
				}, new HttpClientConnectionFactory() {

					@Override
					public String toString() {
						return this.getClass().getSuperclass().getName();
					}
				} };
		List<TestParameters> result = new ArrayList<>();
		for (HttpConnectionFactory factory : factories) {
			result.add(new TestParameters(factory, false));
			result.add(new TestParameters(factory, true));
		}
		return result;
	}

	protected final boolean enableProtocolV2;

	protected AllProtocolsHttpTestCase(TestParameters params) {
		HttpTransport.setConnectionFactory(params.factory);
		enableProtocolV2 = params.enableProtocolV2;
	}

	private static HttpConnectionFactory originalFactory;

	@BeforeClass
	public static void saveConnectionFactory() {
		originalFactory = HttpTransport.getConnectionFactory();
	}

	@AfterClass
	public static void restoreConnectionFactory() {
		HttpTransport.setConnectionFactory(originalFactory);
	}

}