<commit_before>package org.ops4j.pax.web.itest;

import static org.junit.Assert.assertNotNull;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerMethod;
import org.ops4j.pax.web.samples.authentication.AuthHttpContext;
import org.ops4j.pax.web.samples.authentication.StatusServlet;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.ServiceReference;
import org.osgi.service.http.HttpService;

/**
 * @author <NAME> (tonit)
 * @since Mar 3, 2009
 */
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerMethod.class)
public class AuthenticationTCIntegrationTest extends ITestBase {

	private Bundle installWarBundle;
	private StatusServlet servlet;

	@Configuration
	public static Option[] configure() {
		return configureTomcat();
	}
	
	@Before
	public void setUp() throws BundleException, InterruptedException {
		// initWebListener();
		String bundlePath = "mvn:org.ops4j.pax.web.samples/authentication/"
				+ getProjectVersion();
		installWarBundle = bundleContext.installBundle(bundlePath);
		// waitForWebListener();
		
		servlet = new StatusServlet();
		
		waitForServer("http://127.0.0.1:8282/");
	}

	@After
	public void tearDown() throws BundleException {
		if (installWarBundle != null) {
			installWarBundle.stop();
			installWarBundle.uninstall();
		}
	}

	@Test
	public void testStatus() throws Exception {

		ServiceReference<HttpService> httpServiceRef = bundleContext
				.getServiceReference(HttpService.class);

		assertNotNull(httpServiceRef);
		HttpService httpService = (HttpService) bundleContext
				.getService(httpServiceRef);
		
		httpService.registerServlet("/status", servlet, null, null);

		testWebPath("http://127.0.0.1:8282/status",
				"org.osgi.service.http.authentication.type : null");

		httpService.unregister("/status");
		bundleContext.ungetService(httpServiceRef);
	}

	@Test
	public void testStatusAuth() throws Exception {

		initServletListener(null);

		ServiceReference<HttpService> httpServiceRef = bundleContext
				.getServiceReference(HttpService.class);
		assertNotNull(httpServiceRef);
		HttpService httpService = (HttpService) bundleContext
				.getService(httpServiceRef);
		httpService.registerServlet("/status-with-auth", new StatusServlet(),
				null, new AuthHttpContext());

		waitForServletListener();

		testWebPath("http://127.0.0.1:8282/status-with-auth",
				"org.osgi.service.http.authentication.type : BASIC");
<commit_msg>fixing little issue with running with felix ...<commit_after>package org.ops4j.pax.web.itest;

import static org.junit.Assert.assertNotNull;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerMethod;
import org.ops4j.pax.web.samples.authentication.AuthHttpContext;
import org.ops4j.pax.web.samples.authentication.StatusServlet;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.ServiceReference;
import org.osgi.service.http.HttpService;

/**
 * @author <NAME> (tonit)
 * @since Mar 3, 2009
 */
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerMethod.class)
public class AuthenticationTCIntegrationTest extends ITestBase {

	private Bundle installWarBundle;
	
	@Configuration
	public static Option[] configure() {
		return configureTomcat();
	}
	
	@Before
	public void setUp() throws BundleException, InterruptedException {
		// initWebListener();
		String bundlePath = "mvn:org.ops4j.pax.web.samples/authentication/"
				+ getProjectVersion();
		installWarBundle = bundleContext.installBundle(bundlePath);
		// waitForWebListener();
		
		waitForServer("http://127.0.0.1:8282/");
	}

	@After
	public void tearDown() throws BundleException {
		if (installWarBundle != null) {
			installWarBundle.stop();
			installWarBundle.uninstall();
		}
	}

	@Test
	public void testStatus() throws Exception {

		ServiceReference<HttpService> httpServiceRef = bundleContext
				.getServiceReference(HttpService.class);

		assertNotNull(httpServiceRef);
		HttpService httpService = (HttpService) bundleContext
				.getService(httpServiceRef);
		
		httpService.registerServlet("/status", new StatusServlet(), null, null);

		testWebPath("http://127.0.0.1:8282/status",
				"org.osgi.service.http.authentication.type : null");

		httpService.unregister("/status");
		bundleContext.ungetService(httpServiceRef);
	}

	@Test
	public void testStatusAuth() throws Exception {

		initServletListener(null);

		ServiceReference<HttpService> httpServiceRef = bundleContext
				.getServiceReference(HttpService.class);
		assertNotNull(httpServiceRef);
		HttpService httpService = (HttpService) bundleContext
				.getService(httpServiceRef);
		httpService.registerServlet("/status-with-auth", new StatusServlet(),
				null, new AuthHttpContext());

		waitForServletListener();

		testWebPath("http://127.0.0.1:8282/status-with-auth",
				"org.osgi.service.http.authentication.type : BASIC");

{'fraction_non_alphanumeric': 0.1207183854841696, 'fraction_numerical': 0.016293279022403257, 'mean_word_length': 5.2668213457076565, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2656990', 'n_tokens_mistral': 1868, 'n_tokens_neox': 1682, 'n_words': 290}