-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed wrong example json and added unit test #1744
- added unit test for problem found in PR - changed example configuration
- Loading branch information
Showing
2 changed files
with
79 additions
and
2 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
77 changes: 77 additions & 0 deletions
77
sechub-doc/src/test/java/com/mercedesbenz/sechub/ExampleFilesValidTest.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,77 @@ | ||
package com.mercedesbenz.sechub; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.mercedesbenz.sechub.commons.pds.PDSDefaultParameterKeyConstants; | ||
import com.mercedesbenz.sechub.pds.config.PDSProductParameterDefinition; | ||
import com.mercedesbenz.sechub.pds.config.PDSProductParameterSetup; | ||
import com.mercedesbenz.sechub.pds.config.PDSProductSetup; | ||
import com.mercedesbenz.sechub.pds.config.PDSServerConfiguration; | ||
import com.mercedesbenz.sechub.test.TestFileReader; | ||
|
||
/** | ||
* In our asciidoc files we have multiple references to example files. Inside | ||
* this test we check some of them to contain expected values. | ||
* | ||
* @author Albert Tregnaghi | ||
* | ||
*/ | ||
class ExampleFilesValidTest { | ||
|
||
@Test | ||
void check_pds_config_example1_can_be_loaded_and_is_valid() throws Exception { | ||
|
||
/* execute */ | ||
String json = TestFileReader.loadTextFile("src/docs/asciidoc/documents/pds/product_delegation_server_config_example1.json"); | ||
PDSServerConfiguration configuration = PDSServerConfiguration.fromJSON(json); | ||
|
||
/* test */ | ||
assertNotNull(configuration); | ||
List<PDSProductSetup> products = configuration.getProducts(); | ||
assertEquals(2, products.size()); | ||
PDSProductSetup productSetup1 = null; | ||
PDSProductSetup productSetup2 = null; | ||
|
||
for (PDSProductSetup setup : products) { | ||
if ("PRODUCT_1".equals(setup.getId())) { | ||
productSetup1 = setup; | ||
} else if ("PRODUCT_2".equals(setup.getId())) { | ||
productSetup2 = setup; | ||
} else { | ||
fail("Unexpeted product found: " + setup.getId()); | ||
} | ||
} | ||
|
||
// check both setup are found | ||
assertNotNull(productSetup1); | ||
assertNotNull(productSetup2); | ||
|
||
// make same spear checks | ||
assertDefaultValue(productSetup1, false, PDSDefaultParameterKeyConstants.PARAM_KEY_PDS_CONFIG_SUPPORTED_DATATYPES, "source"); | ||
assertDefaultValue(productSetup2, true, PDSDefaultParameterKeyConstants.PARAM_KEY_PDS_CONFIG_SUPPORTED_DATATYPES, "none"); | ||
} | ||
|
||
private void assertDefaultValue(PDSProductSetup setup, boolean isMandatory, String parameterKey, String expectedDefault) { | ||
PDSProductParameterSetup parameters = setup.getParameters(); | ||
List<PDSProductParameterDefinition> list = null; | ||
if (isMandatory) { | ||
list = parameters.getMandatory(); | ||
} else { | ||
list = parameters.getOptional(); | ||
} | ||
|
||
for (PDSProductParameterDefinition definition : list) { | ||
if (parameterKey.equals(definition.getKey())) { | ||
assertEquals(expectedDefault, definition.getDefault(), " Product:" + setup.getId() + " has unexpectedd default value"); | ||
return; | ||
} | ||
} | ||
fail("No parameter with key:" + parameterKey + " found in (" + (isMandatory ? "mandatory" : "optional") + " configuration of product:" + setup.getId() | ||
+ " !"); | ||
} | ||
|
||
} |