1
2
3
4
5
6
7 package org.mule.tck;
8
9 import java.io.IOException;
10 import java.net.URI;
11 import java.net.URISyntaxException;
12 import java.net.URL;
13 import java.util.ArrayList;
14 import java.util.Iterator;
15
16 import org.apache.commons.logging.Log;
17 import org.apache.commons.logging.LogFactory;
18 import org.junit.runner.Description;
19 import org.junit.runner.manipulation.Filter;
20 import org.junit.runner.manipulation.NoTestsRemainException;
21 import org.junit.runners.Parameterized;
22 import org.mule.util.FileUtils;
23 import org.mule.util.StringUtils;
24
25
26
27
28
29
30
31
32 public class MuleParameterized extends Parameterized
33 {
34
35
36
37 private static ArrayList<String> excludedTests = new ArrayList<String>();
38
39 protected static transient Log logger = LogFactory.getLog(org.mule.tck.MuleParameterized.class);
40
41 public MuleParameterized(Class<?> klass) throws Throwable
42 {
43 super(klass);
44 getExcluded();
45 try
46 {
47 filter(excludeFilter);
48 }
49
50
51
52 catch (NoTestsRemainException e)
53 {
54
55 }
56 }
57
58
59
60
61 public void getExcluded()
62 {
63 try
64 {
65 URL fileUrl = this.getClass().getClassLoader().getResource("mule-test-exclusions.txt");
66
67 if (fileUrl != null)
68 {
69
70 URI fileUri = new URI(StringUtils.removeStart(fileUrl.toString(), "jar:"));
71
72
73 @SuppressWarnings("unchecked")
74 Iterator<String> lines = FileUtils.lineIterator(FileUtils.newFile(fileUri));
75
76 ArrayList<String> s = new ArrayList<String>();
77 String line;
78 while (lines.hasNext())
79 {
80 line = StringUtils.trimToEmpty(lines.next());
81 if (!(line.startsWith("#")) && !line.equals("") && line.length() > 0)
82 {
83 s.add(line);
84 logger.info("adding test to the list of exclusions : " + line);
85 }
86 }
87 excludedTests = s;
88 }
89 else
90 {
91 logger.info("did not find test exclusions file");
92 }
93 }
94 catch (IOException ioex)
95 {
96
97 }
98 catch (URISyntaxException e)
99 {
100
101 }
102 }
103
104 private static Filter excludeFilter = new Filter()
105 {
106
107
108
109
110
111
112 @Override
113 public boolean shouldRun(Description description)
114 {
115 for (String excludedTest : excludedTests)
116 {
117
118
119
120
121
122 if (description.getChildren().get(0).toString().contains(excludedTest))
123 {
124 logger.info("skipping test : " + description.getChildren().get(0).toString());
125 return false;
126 }
127 }
128 return true;
129 }
130
131 @Override
132 public String describe()
133 {
134 return "excludes tests from mule-test-exclusions.txt";
135 }
136 };
137 }