<commit_before>/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.felix.dm.test.integration.common;

import static org.ops4j.pax.exam.CoreOptions.bundle;
import static org.ops4j.pax.exam.CoreOptions.bootDelegationPackages;
import static org.ops4j.pax.exam.CoreOptions.cleanCaches;
import static org.ops4j.pax.exam.CoreOptions.junitBundles;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
import static org.ops4j.pax.exam.CoreOptions.systemTimeout;
import static org.ops4j.pax.exam.CoreOptions.vmOption;
import static org.ops4j.pax.exam.CoreOptions.workingDirectory;

import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Hashtable;

import javax.inject.Inject;

import org.apache.felix.dm.test.components.Ensure;
import org.junit.After;
import org.junit.Before;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.OptionUtils;
import org.ops4j.pax.exam.ProbeBuilder;
import org.ops4j.pax.exam.TestProbeBuilder;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
import org.osgi.framework.FrameworkEvent;
import org.osgi.framework.FrameworkListener;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.log.LogService;
import org.slf4j.LoggerFactory;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;

/**
 * Base class for all integration tests.
 */
public abstract class TestBase implements LogService, FrameworkListener {
    // Default OSGI log service level.
    private final static int LOG_LEVEL = LogService.LOG_WARNING;
    
    // Flag used to check if some errors have been logged during the execution of a given test.
    private volatile boolean m_errorsLogged;

    // The name of the system property providing the bundle file to be installed and tested.
    protected static final String TESTBUNDLE_FILE = "project.bundle.file";
    
    // The default bundle jar file name
    protected static final String TESTBUNDLE_FILE_DEF = "target/org.apache.felix.dependencymanager.test-3.0.1-SNAPSHOT.jar";

    // The name of the system property providing the test bundle symbolic name.
    protected static final String TESTBUNDLE_SN = "project.bundle.symbolicName";

    // The default symbolic name for our test bundle
    protected static final String TESTBUNDLE_SN_DEF = "org.apache.felix.dependencymanager.test";

    // The package exported by our test bundle, which we import from all integration tests.
    private static final String TESTBUNDLE_PACKAGE = "org.apache.felix.dm.test.components, org.apache.felix.service.command;status=provisional";

    // The actual JVM option set, extensions may implement a static
    // initializer overwriting this value to have the configuration()
    // method include it when starting the OSGi framework JVM
    protected static String paxRunnerVmOption = null;

    // Bundle context injected by pax-exam for each integration test.
    @Inject
    protected BundleContext context;

    // We implement OSGI log service.
    protected ServiceRegistration logService;
    
    // Flag used to check if our test bundle (src/main/java/**/*) bundle must be started
    // (true for annotation based integration tests)
    private final boolean m_startTestBundle; 
    
    /**
     * Default constructor. By default, we don't start the bundle generated by this project.
     * (the test bundle (src/main/java/...) contains some annotated components only meant to be
     * used by annotation based tests.
     */
    public TestBase() {
        this(false);
    }
    
    /**
     * Creates a new TestBase instance.
     * @param startTestBundle true if the test bundle must be started, false if not.
     */
    public TestBase(boolean startTestBundle) {
        m_startTestBundle = startTestBundle;
    }
 
    /**
     * Pax Exam Configuration.
     */
    @Configuration
    public Option[] configuration() {
        final String testBundle = System.getProperty(TESTBUNDLE_FILE, TESTBUNDLE_FILE_DEF);
        final File testBundleFile = new File(testBundle);
        if (!testBundleFile.canRead()) {
            throw new IllegalArgumentException("Cannot read from test bundle file " + testBundle
                    + " specified in the " + TESTBUNDLE_FILE + " system property");
        }
        
        // Reduce pax exam log level.
        Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
        root.setLevel(Level.WARN);

        final Option[] base = options(
                workingDirectory("target/paxexam/"),
                systemProperty("dm.runtime.log").value("false"),
                systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN"),
                //vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
                systemTimeout(15000),                
                cleanCaches(true),
                junitBundles(),
                bootDelegationPackages("org.netbeans.*"), // For jvisualvm
                mavenBundle("org.apache.felix", "org.apache.felix.metatype", "1.0.8"),
                mavenBundle("org.apache.felix", "org.apache.felix.configadmin", "1.8.0"),
                mavenBundle("org.apache.felix", "org.apache.felix.eventadmin", "1.3.2"),<commit_msg>Use org.apache.felix.configadmin-1.8.1-SNAPSHOT, because the ServiceRaceTest requires the configadmin fix from FELIX-4385.<commit_after>/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.felix.dm.test.integration.common;

import static org.ops4j.pax.exam.CoreOptions.bundle;
import static org.ops4j.pax.exam.CoreOptions.bootDelegationPackages;
import static org.ops4j.pax.exam.CoreOptions.cleanCaches;
import static org.ops4j.pax.exam.CoreOptions.junitBundles;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
import static org.ops4j.pax.exam.CoreOptions.systemTimeout;
import static org.ops4j.pax.exam.CoreOptions.vmOption;
import static org.ops4j.pax.exam.CoreOptions.workingDirectory;

import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Hashtable;

import javax.inject.Inject;

import org.apache.felix.dm.test.components.Ensure;
import org.junit.After;
import org.junit.Before;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.OptionUtils;
import org.ops4j.pax.exam.ProbeBuilder;
import org.ops4j.pax.exam.TestProbeBuilder;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
import org.osgi.framework.FrameworkEvent;
import org.osgi.framework.FrameworkListener;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.log.LogService;
import org.slf4j.LoggerFactory;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;

/**
 * Base class for all integration tests.
 */
public abstract class TestBase implements LogService, FrameworkListener {
    // Default OSGI log service level.
    private final static int LOG_LEVEL = LogService.LOG_WARNING;
    
    // Flag used to check if some errors have been logged during the execution of a given test.
    private volatile boolean m_errorsLogged;

    // The name of the system property providing the bundle file to be installed and tested.
    protected static final String TESTBUNDLE_FILE = "project.bundle.file";
    
    // The default bundle jar file name
    protected static final String TESTBUNDLE_FILE_DEF = "target/org.apache.felix.dependencymanager.test-3.0.1-SNAPSHOT.jar";

    // The name of the system property providing the test bundle symbolic name.
    protected static final String TESTBUNDLE_SN = "project.bundle.symbolicName";

    // The default symbolic name for our test bundle
    protected static final String TESTBUNDLE_SN_DEF = "org.apache.felix.dependencymanager.test";

    // The package exported by our test bundle, which we import from all integration tests.
    private static final String TESTBUNDLE_PACKAGE = "org.apache.felix.dm.test.components, org.apache.felix.service.command;status=provisional";

    // The actual JVM option set, extensions may implement a static
    // initializer overwriting this value to have the configuration()
    // method include it when starting the OSGi framework JVM
    protected static String paxRunnerVmOption = null;

    // Bundle context injected by pax-exam for each integration test.
    @Inject
    protected BundleContext context;

    // We implement OSGI log service.
    protected ServiceRegistration logService;
    
    // Flag used to check if our test bundle (src/main/java/**/*) bundle must be started
    // (true for annotation based integration tests)
    private final boolean m_startTestBundle; 
    
    /**
     * Default constructor. By default, we don't start the bundle generated by this project.
     * (the test bundle (src/main/java/...) contains some annotated components only meant to be
     * used by annotation based tests.
     */
    public TestBase() {
        this(false);
    }
    
    /**
     * Creates a new TestBase instance.
     * @param startTestBundle true if the test bundle must be started, false if not.
     */
    public TestBase(boolean startTestBundle) {
        m_startTestBundle = startTestBundle;
    }
 
    /**
     * Pax Exam Configuration.
     */
    @Configuration
    public Option[] configuration() {
        final String testBundle = System.getProperty(TESTBUNDLE_FILE, TESTBUNDLE_FILE_DEF);
        final File testBundleFile = new File(testBundle);
        if (!testBundleFile.canRead()) {
            throw new IllegalArgumentException("Cannot read from test bundle file " + testBundle
                    + " specified in the " + TESTBUNDLE_FILE + " system property");
        }
        
        // Reduce pax exam log level.
        Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
        root.setLevel(Level.WARN);

        final Option[] base = options(
                workingDirectory("target/paxexam/"),
                systemProperty("dm.runtime.log").value("false"),
                systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN"),
                //vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
                systemTimeout(15000),                
                cleanCaches(true),
                junitBundles(),
                bootDelegationPackages("org.netbeans.*"), // For jvisualvm
                mavenBundle("org.apache.felix", "org.apache.felix.metatype", "1.0.8"),
                mavenBundle("org.apache.felix", "org.apache.felix.configadmin", "1.8.1-SNAPSHOT"),
                mavenBundle("org.apache.felix", "org.apache.felix.eventadmin", "1.3.2"),
{'fraction_non_alphanumeric': 0.09093048799623411, 'fraction_numerical': 0.007139494743448925, 'mean_word_length': 3.3579487179487177, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '145240', 'n_tokens_mistral': 3661, 'n_tokens_neox': 3588, 'n_words': 1059}