Skip to content

Commit faefc6f

Browse files
authored
Clean up SpecsHelperIntegrationTest (#339)
1 parent 737b0ae commit faefc6f

File tree

1 file changed

+42
-27
lines changed

1 file changed

+42
-27
lines changed

Diff for: build-info-extractor/src/test/java/org/jfrog/build/extractor/clientConfiguration/util/spec/SpecsHelperIntegrationTest.java

+42-27
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,22 @@
33
import com.fasterxml.jackson.databind.DeserializationFeature;
44
import com.fasterxml.jackson.databind.ObjectMapper;
55
import org.apache.commons.io.FileUtils;
6-
import org.apache.commons.lang.StringUtils;
76
import org.jfrog.build.IntegrationTestsBase;
87
import org.jfrog.build.api.Artifact;
98
import org.jfrog.build.api.Dependency;
10-
import org.jfrog.build.extractor.clientConfiguration.util.EditPropertiesHelper;
11-
import org.testng.Assert;
129
import org.testng.Reporter;
1310
import org.testng.annotations.AfterMethod;
1411
import org.testng.annotations.BeforeMethod;
1512
import org.testng.annotations.DataProvider;
1613
import org.testng.annotations.Test;
1714

1815
import java.io.File;
19-
import java.io.FileFilter;
2016
import java.io.IOException;
2117
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;
2322

2423
/**
2524
* Integration tests for the SpecHelper.
@@ -30,7 +29,7 @@
3029
public class SpecsHelperIntegrationTest extends IntegrationTestsBase {
3130
private static final String TEST_SPACE = "bi_specs_test_space";
3231
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);
3433

3534
private static final String INTEGRATION_TESTS = "/integration/tests";
3635
private static final String DEFAULT_SPEC_PATH = "/integration/default";
@@ -43,28 +42,28 @@ protected void cleanup() throws IOException {
4342
}
4443

4544
@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);
4847

4948
// Upload artifacts.
5049
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);
5352

5453
// 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);
5756

5857
// Verify expected results
59-
verifyExpected(expected, tempWorkspace);
58+
verifyExpected(specTest.expected, tempWorkspace);
6059
}
6160

6261
/**
6362
* This data provider goes over all cases in "resources/integration/tests/" and creates triplets of upload and download fileSpecs,
6463
* and an 'expected' json file that lists all the expected downloaded files.
6564
* If the current case is missing a download or upload fileSpec, the corresponding default fileSpec ("resources/integration/default/") is used instead.
6665
* The created triplets are then provided to 'integrationTests' for testing.
67-
* */
66+
*/
6867
@DataProvider
6968
private Object[][] testCases() throws IOException, URISyntaxException {
7069
ObjectMapper mapper = new ObjectMapper();
@@ -79,7 +78,7 @@ private Object[][] testCases() throws IOException, URISyntaxException {
7978
Set<String> testPaths = new HashSet<>();
8079
listTestPaths(searchPath, testPaths);
8180

82-
Object[][] tests = new Object[testPaths.size()][4];
81+
SingleSpecTest[][] tests = new SingleSpecTest[testPaths.size()][4];
8382
int i = 0;
8483
for (String testPath : testPaths) {
8584
String uploadSpec = defaultUpload;
@@ -95,7 +94,7 @@ private Object[][] testCases() throws IOException, URISyntaxException {
9594
}
9695
try {
9796
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)};
9998
} catch (IOException e) {
10099
throw new IOException("Caught error during parsing expected results at path: " + testPath, e);
101100
}
@@ -105,22 +104,16 @@ private Object[][] testCases() throws IOException, URISyntaxException {
105104
}
106105

107106
/**
108-
* Add all paths containing tests to testPaths from the provided path
107+
* Add all paths containing tests to testPaths from the provided path.
109108
*
110-
* @param path
111-
* @param testPaths
112-
* @throws IOException
109+
* @param path - The search path
110+
* @param testPaths - The results
113111
*/
114-
private void listTestPaths(File path, Set<String> testPaths) throws IOException {
112+
private void listTestPaths(File path, Set<String> testPaths) {
115113
if (path == null) {
116114
return;
117115
}
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);
124117

125118
if (files == null) {
126119
return;
@@ -133,4 +126,26 @@ public boolean accept(File pathname) {
133126
listTestPaths(f, testPaths);
134127
}
135128
}
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+
}
136151
}

0 commit comments

Comments
 (0)