Package: PathsProvider

PathsProvider

nameinstructionbranchcomplexitylinemethod
PathsProvider()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
buildNoResultArray(File)
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
buildResultArray(File)
M: 0 C: 25
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
computeExternalPaths(String)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
computePaths(String[])
M: 14 C: 16
53%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 2 C: 3
60%
M: 0 C: 1
100%
computePathsNoResultFiles(String[])
M: 0 C: 30
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
externalFiles(File)
M: 0 C: 83
100%
M: 0 C: 8
100%
M: 0 C: 5
100%
M: 0 C: 12
100%
M: 0 C: 1
100%
searchForFiles(File)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
searchForFilesNoResult(File)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
searchForFilesOption(File, boolean)
M: 0 C: 38
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 8
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * #%~
3: * Overture Testing Framework
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.core.testing;
23:
24: import java.io.File;
25: import java.util.Collection;
26: import java.util.List;
27: import java.util.Vector;
28:
29: import org.apache.commons.io.FileUtils;
30: import org.apache.commons.io.filefilter.DirectoryFileFilter;
31: import org.apache.commons.io.filefilter.RegexFileFilter;
32:
33: /**
34: * Input/Result handler for the test framework. Should be used in parametric constructors of test cases. Provides paths
35: * for test inputs (typically VDM sources) and results (JSON files)
36: *
37: * @author ldc
38: */
39: public class PathsProvider
40: {
41:
42:         /** The Constant RESULT_EXTENSION. */
43:         public final static String RESULT_EXTENSION = ".result";
44:
45:         /** Path to the results folder for external test inputs */
46:         private final static String RESULTS_EXTERNAL = "src/test/resources/external";
47:
48:         /** The Constant VDM_EXTENSION_REGEX. */
49:         public final static String VDM_EXTENSION_REGEX = "((.*)\\.vdm(pp|rt|sl))|(.*(PP|SL|RT))";
50:
51:         private final static String EXTERNAL_VDM_EXTENSION_REGEX = "(.*)\\.(vdm|vpp)";
52:
53:         /**
54:          * Processes (recursively) a folder of source inputs. The source input files must have one of the
55:          * three VDM extensions (,vdmsl, .vdmpp, .vdmrt). <br>
56:          * <br>
57:          * ex: Test.vdmsl, Test.vdmsl.RESULT
58:          *
59:          * @param root
60:          * the path(s) to the root(s) folder of the test inputs
61:          * @return the a collection of test model file and result paths in the form of {filename ,filepath} arrays
62:          */
63:         public static Collection<Object[]> computePathsNoResultFiles(String... root)
64:         {
65:                 File dir;
66:                 Collection<Object[]> r = searchForFilesNoResult(new File(root[0]));
67:
68:•                for (int i = 1; i < root.length; i++)
69:                 {
70:                         dir = new File(root[i]);
71:                         r.addAll(searchForFilesNoResult(dir));
72:                 }
73:                 return r;
74:         }
75:
76:         /**
77:          * Processes (recursively) a folder of source inputs and result files. The source input files must have one of the
78:          * three VDM extensions (,vdmsl, .vdmpp, .vdmrt). The result files must be in the same folder as the respective
79:          * inputs and have the same name including the extension but also have .RESULT as a second extension. <br>
80:          * <br>
81:          * ex: Test.vdmsl, Test.vdmsl.RESULT
82:          *
83:          * @param root
84:          * the path(s) to the root(s) folder of the test inputs
85:          * @return the a collection of test model file and result paths in the form of {filename ,filepath, resultpath}
86:          * arrays
87:          */
88:         public static Collection<Object[]> computePaths(String... root)
89:         {
90:                 File dir;
91:                 Collection<Object[]> r = searchForFiles(new File(root[0]));
92:
93:•                for (int i = 1; i < root.length; i++)
94:                 {
95:                         dir = new File(root[i]);
96:                         r.addAll(searchForFiles(dir));
97:                 }
98:                 return r;
99:         }
100:
101:         /**
102:          * Processes (recursively) a folder with external test inputs. <br>
103:          * <br>
104:          * The results for these testing are <b>not</b> stored in the external directory but under each plugin's
105:          * <code>RESULTS_EXTERNAL</code> folder. If you use these testing, please keep that folder pure.
106:          *
107:          * @param root
108:          * the root folder of the external testing
109:          * @return
110:          */
111:         public static Collection<Object[]> computeExternalPaths(String root)
112:         {
113:                 Collection<Object[]> r = externalFiles(new File(root));
114:
115:                 return r;
116:         }
117:
118:         private static Collection<Object[]> externalFiles(File dir)
119:         {
120:                 Collection<File> files = FileUtils.listFiles(dir, new RegexFileFilter(EXTERNAL_VDM_EXTENSION_REGEX), DirectoryFileFilter.DIRECTORY);
121:
122:                 List<Object[]> paths = new Vector<Object[]>();
123:
124:•                for (File file : files)
125:                 {
126:•                        if (!(file.getPath().contains("sltest")
127:•                                        || file.getPath().contains("pptest") || file.getPath().contains("rttest")))
128:                         {
129:                                 continue;
130:                         }
131:
132:                         paths.add(new Object[] {
133:                                         file.getName(),
134:                                         file.getPath(),
135:                                         (RESULTS_EXTERNAL
136:                                                         + file.getPath().substring(dir.getPath().length(), file.getPath().length()) + RESULT_EXTENSION).replace('\\', '/').replace('/', File.separatorChar) });
137:
138:                 }
139:
140:                 return paths;
141:         }
142:
143:         private static Collection<Object[]> searchForFiles(File file)
144:         {
145:                 return searchForFilesOption(file, true);
146:         }
147:
148:         private static Collection<Object[]> searchForFilesNoResult(File file)
149:         {
150:                 return searchForFilesOption(file, false);
151:         }
152:
153:         private static Collection<Object[]> searchForFilesOption(File dir,
154:                         boolean resultFile)
155:         {
156:                 Collection<File> files = FileUtils.listFiles(dir, new RegexFileFilter(VDM_EXTENSION_REGEX), DirectoryFileFilter.DIRECTORY);
157:
158:                 List<Object[]> paths = new Vector<Object[]>();
159:
160:•                for (File file : files)
161:                 {
162:•                        if (resultFile)
163:                         {
164:                                 paths.add(buildResultArray(file));
165:                         } else
166:                         {
167:                                 paths.add(buildNoResultArray(file));
168:                         }
169:                 }
170:
171:                 return paths;
172:         }
173:
174:         private static Object[] buildResultArray(File file)
175:         {
176:                 return new Object[] { file.getName(), file.getPath(),
177:                                 file.getPath() + RESULT_EXTENSION };
178:         }
179:
180:         private static Object[] buildNoResultArray(File file)
181:         {
182:                 return new Object[] { file.getName(), file.getPath() };
183:         }
184:
185: }