Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Alzate <[email protected]>
  • Loading branch information
mr-zepol committed Oct 9, 2023
1 parent 06a70ca commit e780164
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/test/java/org/cyclonedx/parsers/AbstractParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,25 @@ void assertMetadata(final Metadata metadata, final Version version) {
assertEquals("[email protected]", metadata.getSupplier().getContacts().get(0).getEmail());
}

void assertMetadata_validTools(final Metadata metadata) {
assertNotNull(metadata);
assertNotNull(metadata.getTimestamp());

assertNull(metadata.getLifecycles());
assertNull(metadata.getLicenseChoice());
assertNull(metadata.getAuthors());
assertNull(metadata.getComponent());
assertNull(metadata.getManufacture());
assertNull(metadata.getAuthors());
assertNull(metadata.getSupplier());
assertNull(metadata.getProperties());
assertNull(metadata.getSupplier());
assertNull(metadata.getTools());

assertEquals(1, metadata.getToolChoice().getComponents().size());
assertEquals(1, metadata.getToolChoice().getServices().size());
}

void assertCommonBomProperties(Bom bom, Version version) {
assertEquals(version.getVersionString(), bom.getSpecVersion());
assertEquals(1, bom.getVersion());
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/org/cyclonedx/parsers/JsonParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,11 @@ public void testParsedObjects15Bom() throws Exception {
//Assert Formulation
assertFormulation(bom, Version.VERSION_15);
}

@Test
public void testParsedObjects15Bom_validTools() throws Exception {
final Bom bom = getJsonBom("1.5/valid-metadata-tool-1.5.json");
assertCommonBomProperties(bom, Version.VERSION_15);
assertMetadata_validTools(bom.getMetadata());
}
}
7 changes: 7 additions & 0 deletions src/test/java/org/cyclonedx/parsers/XmlParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,13 @@ public void testParsedObjects15Bom() throws Exception {
assertFormulation(bom, Version.VERSION_15);
}

@Test
public void testParsedObjects15Bom_validTools() throws Exception {
final Bom bom = getXmlBom("1.5/valid-metadata-tool-1.5.xml");
assertCommonBomProperties(bom, Version.VERSION_15);
assertMetadata_validTools(bom.getMetadata());
}

@Test
public void testParsedObjects14Bom_WithVulnsExtension() throws Exception {
final Bom bom = getXmlBom("valid-ext-vulnerability-1.4.xml");
Expand Down

0 comments on commit e780164

Please sign in to comment.