3
3
import com .fasterxml .jackson .databind .DeserializationFeature ;
4
4
import com .fasterxml .jackson .databind .ObjectMapper ;
5
5
import org .apache .commons .io .FileUtils ;
6
- import org .apache .commons .lang .StringUtils ;
7
6
import org .jfrog .build .IntegrationTestsBase ;
8
7
import org .jfrog .build .api .Artifact ;
9
8
import org .jfrog .build .api .Dependency ;
10
- import org .jfrog .build .extractor .clientConfiguration .util .EditPropertiesHelper ;
11
- import org .testng .Assert ;
12
9
import org .testng .Reporter ;
13
10
import org .testng .annotations .AfterMethod ;
14
11
import org .testng .annotations .BeforeMethod ;
15
12
import org .testng .annotations .DataProvider ;
16
13
import org .testng .annotations .Test ;
17
14
18
15
import java .io .File ;
19
- import java .io .FileFilter ;
20
16
import java .io .IOException ;
21
17
import java .net .URISyntaxException ;
22
- import java .util .*;
18
+ import java .util .HashMap ;
19
+ import java .util .HashSet ;
20
+ import java .util .List ;
21
+ import java .util .Set ;
23
22
24
23
/**
25
24
* Integration tests for the SpecHelper.
30
29
public class SpecsHelperIntegrationTest extends IntegrationTestsBase {
31
30
private static final String TEST_SPACE = "bi_specs_test_space" ;
32
31
private static final File tempWorkspace = new File (System .getProperty ("java.io.tmpdir" ), TEST_SPACE );
33
- private SpecsHelper specsHelper = new SpecsHelper (log );
32
+ private final SpecsHelper specsHelper = new SpecsHelper (log );
34
33
35
34
private static final String INTEGRATION_TESTS = "/integration/tests" ;
36
35
private static final String DEFAULT_SPEC_PATH = "/integration/default" ;
@@ -43,28 +42,28 @@ protected void cleanup() throws IOException {
43
42
}
44
43
45
44
@ Test (dataProvider = "testCases" )
46
- public void integrationTests (String testName , String uploadSpec , String downloadSpec , Expected expected ) throws Exception {
47
- Reporter .log ("Running test: " + testName , true );
45
+ public void integrationTests (SingleSpecTest specTest ) throws Exception {
46
+ Reporter .log ("Running test: " + specTest . testPath , false );
48
47
49
48
// Upload artifacts.
50
49
File uploadFromPath = new File (this .getClass ().getResource ("/workspace" ).toURI ()).getCanonicalFile ();
51
- List <Artifact > uploaded = specsHelper .uploadArtifactsBySpec (uploadSpec , uploadFromPath , new HashMap <String , String >(), buildInfoClientBuilder );
52
- Reporter .log ("Uploaded " + uploaded .size () + " artifacts" , true );
50
+ List <Artifact > uploaded = specsHelper .uploadArtifactsBySpec (specTest . uploadSpec , uploadFromPath , new HashMap <>(), buildInfoClientBuilder );
51
+ Reporter .log ("Uploaded " + uploaded .size () + " artifacts" , false );
53
52
54
53
// Download artifacts to compare against the expected result.
55
- List <Dependency > downloaded = specsHelper .downloadArtifactsBySpec (downloadSpec , dependenciesClient , tempWorkspace .getPath ());
56
- Reporter .log ("Downloaded " + downloaded .size () + " artifacts" , true );
54
+ List <Dependency > downloaded = specsHelper .downloadArtifactsBySpec (specTest . downloadSpec , dependenciesClient , tempWorkspace .getPath ());
55
+ Reporter .log ("Downloaded " + downloaded .size () + " artifacts" , false );
57
56
58
57
// Verify expected results
59
- verifyExpected (expected , tempWorkspace );
58
+ verifyExpected (specTest . expected , tempWorkspace );
60
59
}
61
60
62
61
/**
63
62
* This data provider goes over all cases in "resources/integration/tests/" and creates triplets of upload and download fileSpecs,
64
63
* and an 'expected' json file that lists all the expected downloaded files.
65
64
* If the current case is missing a download or upload fileSpec, the corresponding default fileSpec ("resources/integration/default/") is used instead.
66
65
* The created triplets are then provided to 'integrationTests' for testing.
67
- * * /
66
+ */
68
67
@ DataProvider
69
68
private Object [][] testCases () throws IOException , URISyntaxException {
70
69
ObjectMapper mapper = new ObjectMapper ();
@@ -79,7 +78,7 @@ private Object[][] testCases() throws IOException, URISyntaxException {
79
78
Set <String > testPaths = new HashSet <>();
80
79
listTestPaths (searchPath , testPaths );
81
80
82
- Object [][] tests = new Object [testPaths .size ()][4 ];
81
+ SingleSpecTest [][] tests = new SingleSpecTest [testPaths .size ()][4 ];
83
82
int i = 0 ;
84
83
for (String testPath : testPaths ) {
85
84
String uploadSpec = defaultUpload ;
@@ -95,7 +94,7 @@ private Object[][] testCases() throws IOException, URISyntaxException {
95
94
}
96
95
try {
97
96
Expected expected = mapper .readValue (new File (testPath , EXPECTED ), Expected .class );
98
- tests [i ] = new Object []{testPath , uploadSpec , downloadSpec , expected };
97
+ tests [i ] = new SingleSpecTest []{new SingleSpecTest ( testPath , uploadSpec , downloadSpec , expected ) };
99
98
} catch (IOException e ) {
100
99
throw new IOException ("Caught error during parsing expected results at path: " + testPath , e );
101
100
}
@@ -105,22 +104,16 @@ private Object[][] testCases() throws IOException, URISyntaxException {
105
104
}
106
105
107
106
/**
108
- * Add all paths containing tests to testPaths from the provided path
107
+ * Add all paths containing tests to testPaths from the provided path.
109
108
*
110
- * @param path
111
- * @param testPaths
112
- * @throws IOException
109
+ * @param path - The search path
110
+ * @param testPaths - The results
113
111
*/
114
- private void listTestPaths (File path , Set <String > testPaths ) throws IOException {
112
+ private void listTestPaths (File path , Set <String > testPaths ) {
115
113
if (path == null ) {
116
114
return ;
117
115
}
118
- File [] files = path .listFiles (new FileFilter () {
119
- @ Override
120
- public boolean accept (File pathname ) {
121
- return pathname .isDirectory ();
122
- }
123
- });
116
+ File [] files = path .listFiles (File ::isDirectory );
124
117
125
118
if (files == null ) {
126
119
return ;
@@ -133,4 +126,26 @@ public boolean accept(File pathname) {
133
126
listTestPaths (f , testPaths );
134
127
}
135
128
}
129
+
130
+ /**
131
+ * This class represents a single SpecsHelper integration test
132
+ */
133
+ private static class SingleSpecTest {
134
+ private final String testPath ;
135
+ private final String uploadSpec ;
136
+ private final String downloadSpec ;
137
+ private final Expected expected ;
138
+
139
+ private SingleSpecTest (String testPath , String uploadSpec , String downloadSpec , Expected expected ) {
140
+ this .testPath = testPath ;
141
+ this .uploadSpec = uploadSpec ;
142
+ this .downloadSpec = downloadSpec ;
143
+ this .expected = expected ;
144
+ }
145
+
146
+ @ Override
147
+ public String toString () {
148
+ return testPath ;
149
+ }
150
+ }
136
151
}
0 commit comments