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