2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.odlparent.featuretest;
10 import static org.opendaylight.odlparent.featuretest.Constants.ORG_OPENDAYLIGHT_FEATURETEST_FEATURENAME_PROP;
11 import static org.opendaylight.odlparent.featuretest.Constants.ORG_OPENDAYLIGHT_FEATURETEST_FEATUREVERSION_PROP;
12 import static org.opendaylight.odlparent.featuretest.Constants.ORG_OPENDAYLIGHT_FEATURETEST_URI_PROP;
16 import org.junit.runner.Description;
17 import org.junit.runner.Runner;
18 import org.junit.runner.manipulation.Filter;
19 import org.junit.runner.manipulation.NoTestsRemainException;
20 import org.junit.runner.manipulation.Sorter;
21 import org.junit.runner.notification.RunNotifier;
22 import org.junit.runners.model.InitializationError;
23 import org.ops4j.pax.exam.junit.PaxExam;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 import com.google.common.base.Preconditions;
31 public class PerFeatureRunner extends Runner {
32 private static final Logger LOG = LoggerFactory.getLogger(PerFeatureRunner.class);
33 private final String featureVersion;
34 private final String featureName;
35 final PaxExam delegate;
38 public PerFeatureRunner(final URL repoURL, final String featureName, final String featureVersion, final Class<?> testClass) throws InitializationError {
39 Preconditions.checkNotNull(repoURL);
40 Preconditions.checkNotNull(featureName);
41 Preconditions.checkNotNull(featureVersion);
42 Preconditions.checkNotNull(testClass);
43 System.setProperty(ORG_OPENDAYLIGHT_FEATURETEST_URI_PROP, repoURL.toString());
44 System.setProperty(ORG_OPENDAYLIGHT_FEATURETEST_FEATURENAME_PROP, featureName);
45 System.setProperty(ORG_OPENDAYLIGHT_FEATURETEST_FEATUREVERSION_PROP,featureVersion);
46 this.delegate = new PaxExam(testClass);
47 this.featureName = featureName;
48 this.featureVersion = featureVersion;
49 this.repoURL = repoURL;
53 public Description getDescription() {
54 return Util.convertDescription(repoURL,featureName,featureVersion,delegate.getDescription());
58 public void run(RunNotifier notifier) {
59 LOG.info("About to run test for feature: {} {}", featureName, featureVersion);
60 System.setProperty(ORG_OPENDAYLIGHT_FEATURETEST_URI_PROP, repoURL.toString());
61 System.setProperty(ORG_OPENDAYLIGHT_FEATURETEST_FEATURENAME_PROP, featureName);
62 System.setProperty(ORG_OPENDAYLIGHT_FEATURETEST_FEATUREVERSION_PROP,featureVersion);
63 delegate.run(new PerFeatureRunNotifier(repoURL,featureName, featureVersion,notifier));
68 * @see org.junit.runner.Runner#testCount()
71 public int testCount() {
72 return delegate.testCount();
77 * @throws NoTestsRemainException
78 * @see org.ops4j.pax.exam.junit.PaxExam#filter(org.junit.runner.manipulation.Filter)
80 public void filter(Filter filter) throws NoTestsRemainException {
81 delegate.filter(filter);
86 * @see org.ops4j.pax.exam.junit.PaxExam#sort(org.junit.runner.manipulation.Sorter)
88 public void sort(Sorter sorter) {
89 delegate.sort(sorter);
94 * @see java.lang.Object#toString()
96 public String toString() {
97 return delegate.toString();
101 * @return the repoURL
103 public URL getRepoURL() {
108 * @return the featureName
110 public String getFeatureName() {
115 * @return the featureVersion
117 public String getFeatureVersion() {
118 return featureVersion;