|
31 | 31 | import org.junit.jupiter.api.Test; |
32 | 32 |
|
33 | 33 | import java.util.Arrays; |
| 34 | +import java.util.Collections; |
34 | 35 | import java.util.List; |
35 | 36 |
|
| 37 | +import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; |
36 | 38 | import static org.assertj.core.api.Assertions.assertThat; |
37 | 39 |
|
38 | 40 | /** |
@@ -202,6 +204,54 @@ public void testV15_XML_SerializeAuthorString() throws Exception { |
202 | 204 | // VERSION 1.6 TESTS - Both 'author' (deprecated) and 'authors' exist |
203 | 205 | // ============================================================================ |
204 | 206 |
|
| 207 | + @Test |
| 208 | + @DisplayName("v1.6 XML: Serialize component with null authors list") |
| 209 | + public void testV16_XML_SerializeNullAuthorsList() throws Exception { |
| 210 | + Component component = createComponentWithAuthorsList( |
| 211 | + null |
| 212 | + ); |
| 213 | + Bom bom = createBom(component); |
| 214 | + |
| 215 | + BomXmlGenerator generator = BomGeneratorFactory.createXml(Version.VERSION_16, bom); |
| 216 | + String xml = generator.toXmlString(); |
| 217 | + |
| 218 | + assertThat(xml).isEqualTo(/* language=XML */ """ |
| 219 | + <?xml version="1.0" encoding="UTF-8"?> |
| 220 | + <bom serialNumber="urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79" version="1" xmlns="http://cyclonedx.org/schema/bom/1.6"> |
| 221 | + <components> |
| 222 | + <component type="library"> |
| 223 | + <name>test-lib</name> |
| 224 | + <version>1.0.0</version> |
| 225 | + </component> |
| 226 | + </components> |
| 227 | + </bom> |
| 228 | + """); |
| 229 | + } |
| 230 | + |
| 231 | + @Test |
| 232 | + @DisplayName("v1.6 XML: Serialize component with empty authors list") |
| 233 | + public void testV16_XML_SerializeEmptyAuthorsList() throws Exception { |
| 234 | + Component component = createComponentWithAuthorsList( |
| 235 | + Collections.emptyList() |
| 236 | + ); |
| 237 | + Bom bom = createBom(component); |
| 238 | + |
| 239 | + BomXmlGenerator generator = BomGeneratorFactory.createXml(Version.VERSION_16, bom); |
| 240 | + String xml = generator.toXmlString(); |
| 241 | + |
| 242 | + assertThat(xml).isEqualTo(/* language=XML */ """ |
| 243 | + <?xml version="1.0" encoding="UTF-8"?> |
| 244 | + <bom serialNumber="urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79" version="1" xmlns="http://cyclonedx.org/schema/bom/1.6"> |
| 245 | + <components> |
| 246 | + <component type="library"> |
| 247 | + <name>test-lib</name> |
| 248 | + <version>1.0.0</version> |
| 249 | + </component> |
| 250 | + </components> |
| 251 | + </bom> |
| 252 | + """); |
| 253 | + } |
| 254 | + |
205 | 255 | @Test |
206 | 256 | @DisplayName("v1.6 XML: Serialize component with ONLY author string (deprecated field)") |
207 | 257 | public void testV16_XML_SerializeOnlyAuthorString() throws Exception { |
@@ -421,6 +471,50 @@ public void testV16_JSON_SerializeOnlyAuthorString() throws Exception { |
421 | 471 | assertThat(json).doesNotContain("\"authors\""); |
422 | 472 | } |
423 | 473 |
|
| 474 | + @Test |
| 475 | + @DisplayName("v1.6 JSON: Serialize component with null authors list") |
| 476 | + public void testV16_JSON_SerializeNullAuthorsList() throws Exception { |
| 477 | + Component component = createComponentWithAuthorsList( |
| 478 | + null |
| 479 | + ); |
| 480 | + Bom bom = createBom(component); |
| 481 | + |
| 482 | + BomJsonGenerator generator = BomGeneratorFactory.createJson(Version.VERSION_16, bom); |
| 483 | + String json = generator.toJsonString(); |
| 484 | + |
| 485 | + assertThatJson(json) |
| 486 | + .inPath("$.components[0]") |
| 487 | + .isEqualTo(/* language=JSON */ """ |
| 488 | + { |
| 489 | + "type": "library", |
| 490 | + "name": "test-lib", |
| 491 | + "version": "1.0.0" |
| 492 | + } |
| 493 | + """); |
| 494 | + } |
| 495 | + |
| 496 | + @Test |
| 497 | + @DisplayName("v1.6 JSON: Serialize component with empty authors list") |
| 498 | + public void testV16_JSON_SerializeEmptyAuthorsList() throws Exception { |
| 499 | + Component component = createComponentWithAuthorsList( |
| 500 | + Collections.emptyList() |
| 501 | + ); |
| 502 | + Bom bom = createBom(component); |
| 503 | + |
| 504 | + BomJsonGenerator generator = BomGeneratorFactory.createJson(Version.VERSION_16, bom); |
| 505 | + String json = generator.toJsonString(); |
| 506 | + |
| 507 | + assertThatJson(json) |
| 508 | + .inPath("$.components[0]") |
| 509 | + .isEqualTo(/* language=JSON */ """ |
| 510 | + { |
| 511 | + "type": "library", |
| 512 | + "name": "test-lib", |
| 513 | + "version": "1.0.0" |
| 514 | + } |
| 515 | + """); |
| 516 | + } |
| 517 | + |
424 | 518 | @Test |
425 | 519 | @DisplayName("v1.6 JSON: Serialize component with ONLY authors list") |
426 | 520 | public void testV16_JSON_SerializeOnlyAuthorsList() throws Exception { |
|
0 commit comments