|
| 1 | +/* |
| 2 | + * This file is part of CycloneDX Core (Java). |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + * SPDX-License-Identifier: Apache-2.0 |
| 17 | + * Copyright (c) OWASP Foundation. All Rights Reserved. |
| 18 | + */ |
| 19 | +package org.cyclonedx.util; |
| 20 | + |
| 21 | +import org.junit.jupiter.api.Test; |
| 22 | +import java.util.UUID; |
| 23 | + |
| 24 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 25 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 26 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 27 | +import static org.junit.jupiter.api.Assertions.assertNull; |
| 28 | + |
| 29 | +public class BomLinkTest { |
| 30 | + |
| 31 | + @Test |
| 32 | + public void testValidBomLinks() { |
| 33 | + assertTrue(BomLink.isBomLink("urn:cdx:dbd9e325-a02e-4bd1-9a21-5123edd1b27c/1")); |
| 34 | + assertTrue(BomLink.isBomLink("urn:cdx:dbd9e325-a02e-4bd1-9a21-5123edd1b27c/999999999")); |
| 35 | + assertTrue( BomLink. isBomLink( "urn:cdx:dbd9e325-a02e-4bd1-9a21-5123edd1b27c/1#pkg:maven/org.apache.logging.log4j/[email protected]")); |
| 36 | + assertTrue(BomLink.isBomLink("urn:cdx:dbd9e325-a02e-4bd1-9a21-5123edd1b27c/1#foo")); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void testInvalidBomLinks() { |
| 41 | + assertFalse(BomLink.isBomLink("urn:cdx:dbd9e325-a02e-4bd1-9a21-5123edd1b27c/")); |
| 42 | + assertFalse(BomLink.isBomLink("urn:cdx:dbd9e325-a02e-4bd1-9a21-5123edd1b27c")); |
| 43 | + assertFalse(BomLink.isBomLink("urn:cdx:foo/1")); |
| 44 | + assertFalse(BomLink.isBomLink("urn:foo:dbd9e325-a02e-4bd1-9a21-5123edd1b27/1")); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void testParserWithRef() throws Exception { |
| 49 | + BomLink bl = new BomLink( "urn:cdx:dbd9e325-a02e-4bd1-9a21-5123edd1b27c/1#pkg:maven/org.apache.logging.log4j/[email protected]"); |
| 50 | + assertEquals(UUID.fromString("dbd9e325-a02e-4bd1-9a21-5123edd1b27c"), bl.getSerialNumber()); |
| 51 | + assertEquals(1, bl.getVersion()); |
| 52 | + assertEquals( "pkg:maven/org.apache.logging.log4j/[email protected]", bl. getBomRef()); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + public void testParserWithoutRef() throws Exception { |
| 57 | + BomLink bl = new BomLink("urn:cdx:dbd9e325-a02e-4bd1-9a21-5123edd1b27c/1"); |
| 58 | + assertEquals(UUID.fromString("dbd9e325-a02e-4bd1-9a21-5123edd1b27c"), bl.getSerialNumber()); |
| 59 | + assertEquals(1, bl.getVersion()); |
| 60 | + assertNull(bl.getBomRef()); |
| 61 | + } |
| 62 | + |
| 63 | +} |
0 commit comments