Fix checkstyle warnings
[odlparent.git] / features-test / src / main / java / org / opendaylight / odlparent / featuretest / PerFeatureRunner.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.odlparent.featuretest;
9
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;
13
14 import java.net.URL;
15
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;
26
27 import com.google.common.base.Preconditions;
28
29
30
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;
36     final URL repoURL;
37
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;
50     }
51
52     @Override
53     public Description getDescription() {
54         return Util.convertDescription(repoURL,featureName,featureVersion,delegate.getDescription());
55     }
56
57     @Override
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));
64     }
65
66     /**
67      * @return
68      * @see org.junit.runner.Runner#testCount()
69      */
70     @Override
71     public int testCount() {
72         return delegate.testCount();
73     }
74
75     /**
76      * @param filter
77      * @throws NoTestsRemainException
78      * @see org.ops4j.pax.exam.junit.PaxExam#filter(org.junit.runner.manipulation.Filter)
79      */
80     public void filter(Filter filter) throws NoTestsRemainException {
81         delegate.filter(filter);
82     }
83
84     /**
85      * @param sorter
86      * @see org.ops4j.pax.exam.junit.PaxExam#sort(org.junit.runner.manipulation.Sorter)
87      */
88     public void sort(Sorter sorter) {
89         delegate.sort(sorter);
90     }
91
92     /**
93      * @return
94      * @see java.lang.Object#toString()
95      */
96     public String toString() {
97         return delegate.toString();
98     }
99
100     /**
101      * @return the repoURL
102      */
103     public URL getRepoURL() {
104         return repoURL;
105     }
106
107     /**
108      * @return the featureName
109      */
110     public String getFeatureName() {
111         return featureName;
112     }
113
114     /**
115      * @return the featureVersion
116      */
117     public String getFeatureVersion() {
118         return featureVersion;
119     }
120
121
122
123 }