<commit_before>package co.freeside.betamax

import javax.net.ssl.HttpsURLConnection
import org.junit.Rule
import spock.lang.*
import static java.net.HttpURLConnection.HTTP_OK
import static org.apache.http.HttpHeaders.VIA

@Unroll
class SmokeSpec extends Specification {

	@Rule
	Recorder recorder = new ProxyRecorder(sslSupport: true)

	@Betamax(tape = 'smoke spec')
	void '#type response data'() {
		when:
		HttpURLConnection connection = uri.toURL().openConnection()
		connection.setRequestProperty("Accept-Encoding", "gzip")

		then:
		connection.responseCode == HTTP_OK
		connection.getHeaderField(VIA) == "Betamax"
		connection.inputStream.text.contains(expectedContent)

		where:
		type   | uri                                                  | expectedContent
		'txt'  | 'http://httpbin.org/robots.txt'                      | 'User-agent: *'
		'html' | 'http://httpbin.org/html'                            | '<!DOCTYPE html>'
		'json' | 'http://httpbin.org/get'                             | '"url": "http://httpbin.org/get"'
	}

	@Betamax(tape = 'smoke spec')
	void 'gzipped response data'() {
		when:
		HttpURLConnection connection = uri.toURL().openConnection()
		connection.setRequestProperty("Accept-Encoding", "gzip")

		then:
		connection.responseCode == HTTP_OK
		connection.getHeaderField(VIA) == 'Betamax'
		connection.inputStream.text.contains("foo")

		where:
		uri = 'http://httpbin.org/gzip'
	}

	@Betamax(tape = 'smoke spec')
	void 'redirects are followed'() {
		when:
		HttpURLConnection connection = uri.toURL().openConnection()

		then:
		connection.responseCode == HTTP_OK
		connection.getHeaderField(VIA) == 'Betamax'
		connection.inputStream.text.contains('"url": "http://httpbin.org/get"')

		where:
		uri = 'http://httpbin.org/redirect/1'
	}

	@Betamax(tape = 'smoke spec')
	void 'https proxying'() {
//		setup:
//		BetamaxHttpsSupport.configure(http.client)

		when:
		HttpsURLConnection connection = uri.toURL().openConnection()

		then:
		connection.responseCode == HTTP_OK
		connection.inputStream.text.contains('"url": "http://httpbin.org/get"')
		connection.getHeaderField(VIA) == 'Betamax'

		where:
		uri = 'https://httpbin.org/get'
	}

	@Betamax(tape = 'smoke spec')
	void 'can POST to https'() {
//		setup:
//		BetamaxHttpsSupport.configure(http.client)

		when:
		HttpsURLConnection connection = uri.toURL().openConnection()
		connection.requestMethod = "POST"
		connection.doOutput = true
		connection.outputStream.withStream {
			it << 'message=O HAI'
		}

		then:
		connection.responseCode == HTTP_OK
		connection.getHeaderField(VIA) == 'Betamax'
		connection.inputStream.text.contains('"message": "O HAI"')

		where:
		uri = 'https://httpbin.org/post'
	}

	@Ignore("site is no longer there")
	@Issue('https://github.com/robfletcher/betamax/issues/52')
	@Betamax(tape = 'ocsp')
	void 'OCSP messages'() {
		when:
		HttpURLConnection connection = uri.toURL().openConnection()
		connection.requestMethod = "POST"

		then:
		connection.responseCode == HTTP_OK
		connection.getHeaderField(VIA) == 'Betamax'
		connection.inputStream.bytes.length == 2529

		where:<commit_msg>removed some redundant code<commit_after>package co.freeside.betamax

import javax.net.ssl.HttpsURLConnection
import org.junit.Rule
import spock.lang.*
import static java.net.HttpURLConnection.HTTP_OK
import static org.apache.http.HttpHeaders.VIA

@Unroll
class SmokeSpec extends Specification {

	@Rule
	Recorder recorder = new ProxyRecorder(sslSupport: true)

	@Betamax(tape = 'smoke spec')
	void '#type response data'() {
		when:
		HttpURLConnection connection = uri.toURL().openConnection()
		connection.setRequestProperty("Accept-Encoding", "gzip")

		then:
		connection.responseCode == HTTP_OK
		connection.getHeaderField(VIA) == "Betamax"
		connection.inputStream.text.contains(expectedContent)

		where:
		type   | uri                                                  | expectedContent
		'txt'  | 'http://httpbin.org/robots.txt'                      | 'User-agent: *'
		'html' | 'http://httpbin.org/html'                            | '<!DOCTYPE html>'
		'json' | 'http://httpbin.org/get'                             | '"url": "http://httpbin.org/get"'
	}

	@Betamax(tape = 'smoke spec')
	void 'gzipped response data'() {
		when:
		HttpURLConnection connection = uri.toURL().openConnection()
		connection.setRequestProperty("Accept-Encoding", "gzip")

		then:
		connection.responseCode == HTTP_OK
		connection.getHeaderField(VIA) == 'Betamax'
		connection.inputStream.text.contains("foo")

		where:
		uri = 'http://httpbin.org/gzip'
	}

	@Betamax(tape = 'smoke spec')
	void 'redirects are followed'() {
		when:
		HttpURLConnection connection = uri.toURL().openConnection()

		then:
		connection.responseCode == HTTP_OK
		connection.getHeaderField(VIA) == 'Betamax'
		connection.inputStream.text.contains('"url": "http://httpbin.org/get"')

		where:
		uri = 'http://httpbin.org/redirect/1'
	}

	@Betamax(tape = 'smoke spec')
	void 'https proxying'() {
		when:
		HttpsURLConnection connection = uri.toURL().openConnection()

		then:
		connection.responseCode == HTTP_OK
		connection.inputStream.text.contains('"url": "http://httpbin.org/get"')
		connection.getHeaderField(VIA) == 'Betamax'

		where:
		uri = 'https://httpbin.org/get'
	}

	@Betamax(tape = 'smoke spec')
	void 'can POST to https'() {
		when:
		HttpsURLConnection connection = uri.toURL().openConnection()
		connection.requestMethod = "POST"
		connection.doOutput = true
		connection.outputStream.withStream {
			it << 'message=O HAI'
		}

		then:
		connection.responseCode == HTTP_OK
		connection.getHeaderField(VIA) == 'Betamax'
		connection.inputStream.text.contains('"message": "O HAI"')

		where:
		uri = 'https://httpbin.org/post'
	}

	@Ignore("site is no longer there")
	@Issue('https://github.com/robfletcher/betamax/issues/52')
	@Betamax(tape = 'ocsp')
	void 'OCSP messages'() {
		when:
		HttpURLConnection connection = uri.toURL().openConnection()
		connection.requestMethod = "POST"

		then:
		connection.responseCode == HTTP_OK
		connection.getHeaderField(VIA) == 'Betamax'
		connection.inputStream.bytes.length == 2529

		where:
{'fraction_non_alphanumeric': 0.14271717831482691, 'fraction_numerical': 0.0022860875244937948, 'mean_word_length': 3.6898928024502298, 'pattern_counts': {'":': 8, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5563516', 'n_tokens_mistral': 2208, 'n_tokens_neox': 2022, 'n_words': 362}