<commit_before>package org.osgi.test.cases.upnp.tbc;

import org.osgi.framework.ServiceRegistration;
import org.osgi.service.http.HttpService;
import org.osgi.service.upnp.UPnPDevice;
import org.osgi.test.cases.upnp.tbc.device.discovery.ServicesListener;
import org.osgi.test.cases.upnp.tbc.export.UPnPExportedDevice;
import org.osgi.test.support.compatibility.DefaultTestBundleControl;

/**
 * 
 * 
 */
public class UPnPControl extends DefaultTestBundleControl {
	private HttpService			http;
	private TestStarter			start;

	public void prepare() throws Exception {
		log("Prepare for UPnP Test Case");
		http = (HttpService) getService(HttpService.class);
		UPnPConstants.init();
		//UPnPConstants.HTTP_PORT = ((Integer)
		// httpRef.getProperty("openPort")).intValue();
		UPnPConstants.HTTP_PORT = Integer.parseInt(System.getProperty(
				"org.osgi.service.http.port", "80"));
		log("Register Service Listener to listen for service changes");
		ServicesListener listener = new ServicesListener(getContext());
		listener.open();
		log("Start the UPnP Test Starter");
		start = new TestStarter(http, this);
		
		listener.waitFor(3);
	}

	public void unprepare() throws Exception {
		start.stop();
		ungetService(http);
	}

	//==========================================TEST
	// METHODS====================================================================//
	public void testDiscovery() {
		new UPnPTester(UPnPTester.DISCOVERY, ServicesListener
				.getUPnPDevice(), getContext());
	}

	public void testControl() {
		new UPnPTester(UPnPTester.CONTROL, ServicesListener
				.getUPnPDevice(), getContext());
	}

	public void testEvent() {
		new UPnPTester(UPnPTester.EVENTING, ServicesListener
				.getUPnPDevice(), getContext());
	}

	public void testExport() {
		log("Creating new device and making it UPnP device");
		UPnPExportedDevice ex_device = UPnPExportedDevice.newUPnPTestervice();
		ServiceRegistration sr = getContext().registerService(
				UPnPDevice.class.getName(),
				ex_device, ex_device.getDescriptions(null));
		try {
			Thread.sleep(4000);
		}
		catch (Exception er) {
			// ignored
		}
		try {
			new UPnPTester(UPnPTester.EXPORT, ServicesListener
					.getUPnPDevice(), getContext());
		}
		finally {
			sr.unregister();
		}
	}
}<commit_msg>Changed prepare for commit with only once guard<commit_after>package org.osgi.test.cases.upnp.tbc;

import org.osgi.framework.ServiceRegistration;
import org.osgi.service.http.HttpService;
import org.osgi.service.upnp.UPnPDevice;
import org.osgi.test.cases.upnp.tbc.device.discovery.ServicesListener;
import org.osgi.test.cases.upnp.tbc.export.UPnPExportedDevice;
import org.osgi.test.support.compatibility.DefaultTestBundleControl;

/**
 * 
 * 
 */
public class UPnPControl extends DefaultTestBundleControl {
	private static HttpService	http;
	private static TestStarter	start;
	private static boolean		inited	= false;

	public void setUp() throws Exception {
		if (!inited) {
			inited = true;
			log("Prepare for UPnP Test Case");
			http = (HttpService) getService(HttpService.class);
			UPnPConstants.init();
			// UPnPConstants.HTTP_PORT = ((Integer)
			// httpRef.getProperty("openPort")).intValue();
			UPnPConstants.HTTP_PORT = Integer.parseInt(System.getProperty(
					"org.osgi.service.http.port", "80"));
			log("Register Service Listener to listen for service changes");
			ServicesListener listener = new ServicesListener(getContext());
			listener.open();
			log("Start the UPnP Test Starter");
			start = new TestStarter(http, this);
			listener.waitFor(3);
		}
	}

	public void unprepare() throws Exception {
		start.stop();
		ungetService(http);
	}

	// ==========================================TEST
	// METHODS====================================================================//
	public void testDiscovery() {
		new UPnPTester(UPnPTester.DISCOVERY, ServicesListener.getUPnPDevice(),
				getContext());
	}

	public void testControl() {
		new UPnPTester(UPnPTester.CONTROL, ServicesListener.getUPnPDevice(),
				getContext());
	}

	public void testEvent() {
		new UPnPTester(UPnPTester.EVENTING, ServicesListener.getUPnPDevice(),
				getContext());
	}

	public void testExport() {
		log("Creating new device and making it UPnP device");
		UPnPExportedDevice ex_device = UPnPExportedDevice.newUPnPTestervice();
		ServiceRegistration sr = getContext().registerService(
				UPnPDevice.class.getName(), ex_device,
				ex_device.getDescriptions(null));
		try {
			Thread.sleep(4000);
		}
		catch (Exception er) {
			// ignored
		}
		try {
			new UPnPTester(UPnPTester.EXPORT, ServicesListener.getUPnPDevice(),
					getContext());
		}
		finally {
			sr.unregister();
		}
	}
}
{'fraction_non_alphanumeric': 0.1637263339070568, 'fraction_numerical': 0.0030120481927710845, 'mean_word_length': 4.782338308457711, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '1795130', 'n_tokens_mistral': 1621, 'n_tokens_neox': 1461, 'n_words': 286}