Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1773 from mercedes-benz/feature-1172-possibility-…
…to-define-supported-pds-upload-types Improve PDS auto ZIP/TAR handling
- Loading branch information
Showing
40 changed files
with
1,832 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...ain/java/com/mercedesbenz/sechub/commons/model/SecHubDataConfigurationTypeListParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.mercedesbenz.sechub.commons.model; | ||
|
||
import java.util.LinkedHashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.mercedesbenz.sechub.commons.core.util.SimpleStringUtils; | ||
|
||
public class SecHubDataConfigurationTypeListParser { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(SecHubDataConfigurationTypeListParser.class); | ||
|
||
/** | ||
* Parses a given string and returns a result set or <code>null</code>. | ||
* | ||
* @param commaSeparatedList | ||
* @return set or <code>null</code> if the comma separated list did contain | ||
* wrong values or was empty | ||
*/ | ||
public Set<SecHubDataConfigurationType> fetchTypesAsSetOrNull(String commaSeparatedList) { | ||
Set<SecHubDataConfigurationType> set = new LinkedHashSet<>(); | ||
|
||
List<String> list = SimpleStringUtils.createListForCommaSeparatedValues(commaSeparatedList); | ||
for (String entry : list) { | ||
boolean found = false; | ||
for (SecHubDataConfigurationType type : SecHubDataConfigurationType.values()) { | ||
if (type.name().equalsIgnoreCase(entry)) { | ||
found = true; | ||
set.add(type); | ||
break; | ||
} | ||
} | ||
|
||
if (!found) { | ||
LOG.debug("Found invalid data type entry:{}.", entry); | ||
return null; | ||
} | ||
} | ||
if (set.size() == 0) { | ||
LOG.debug("No data types found."); | ||
return null; | ||
} | ||
|
||
return set; | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...java/com/mercedesbenz/sechub/commons/model/SecHubDataConfigurationTypeListParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.mercedesbenz.sechub.commons.model; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.util.Set; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.EnumSource; | ||
import org.junit.jupiter.params.provider.NullAndEmptySource; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
class SecHubDataConfigurationTypeListParserTest { | ||
|
||
private SecHubDataConfigurationTypeListParser parserToTest; | ||
|
||
@BeforeEach | ||
void beforeEach() { | ||
parserToTest = new SecHubDataConfigurationTypeListParser(); | ||
} | ||
|
||
@ParameterizedTest | ||
@NullAndEmptySource | ||
@ValueSource(strings = { " ", ",", " ,", " , ", ",,, , ,,", "x", "x,y", "binary,illegal" }) | ||
void illegal_args_will_return_null_as_result(String string) { | ||
|
||
/* execute */ | ||
Set<SecHubDataConfigurationType> parsed = parserToTest.fetchTypesAsSetOrNull(string); | ||
|
||
/* test */ | ||
assertNull(parsed); | ||
} | ||
|
||
@ParameterizedTest | ||
@EnumSource(SecHubDataConfigurationType.class) | ||
void one_type_name_as_uppercased_results_in_set_with_one_entry(SecHubDataConfigurationType type) { | ||
|
||
/* execute */ | ||
Set<SecHubDataConfigurationType> parsed = parserToTest.fetchTypesAsSetOrNull(type.name().toUpperCase()); | ||
|
||
/* test */ | ||
assertNotNull(parsed); | ||
assertEquals(parsed.size(), 1); | ||
assertEquals(type, parsed.iterator().next()); | ||
} | ||
|
||
@ParameterizedTest | ||
@EnumSource(SecHubDataConfigurationType.class) | ||
void one_type_name_as_lowercased_results_in_set_with_one_entry(SecHubDataConfigurationType type) { | ||
|
||
/* execute */ | ||
Set<SecHubDataConfigurationType> parsed = parserToTest.fetchTypesAsSetOrNull(type.name().toLowerCase()); | ||
|
||
/* test */ | ||
assertNotNull(parsed); | ||
assertEquals(parsed.size(), 1); | ||
assertEquals(type, parsed.iterator().next()); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = { "1:binary", "1:BINARY", "3:NONE,BINARY,source", "2:none,source", "2:source,binary", "2:source , BINARY", | ||
"3:source,binary,NONE,binary" }) | ||
void correct_args_will_return_args_as_set(String data) { | ||
/* prepare */ | ||
String[] splitted = data.split(":"); | ||
String string = splitted[1]; | ||
int expectedAmount = Integer.parseInt(splitted[0]); | ||
|
||
/* execute */ | ||
Set<SecHubDataConfigurationType> parsed = parserToTest.fetchTypesAsSetOrNull(string); | ||
|
||
/* test */ | ||
assertNotNull(parsed); | ||
assertEquals(expectedAmount, parsed.size()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.