|
| 1 | +/* |
| 2 | + * Copyright 2024 Red Hat, Inc. and/or its affiliates |
| 3 | + * and other contributors as indicated by the @author tags. |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +package com.redhat.exhort.integration.backend.sbom; |
| 20 | + |
| 21 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 22 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 23 | + |
| 24 | +import java.io.IOException; |
| 25 | + |
| 26 | +import org.junit.jupiter.api.Test; |
| 27 | +import org.junit.jupiter.params.ParameterizedTest; |
| 28 | +import org.junit.jupiter.params.provider.ValueSource; |
| 29 | +import org.spdx.jacksonstore.MultiFormatStore; |
| 30 | +import org.spdx.jacksonstore.MultiFormatStore.Format; |
| 31 | +import org.spdx.library.InvalidSPDXAnalysisException; |
| 32 | +import org.spdx.library.Version; |
| 33 | +import org.spdx.storage.simple.InMemSpdxStore; |
| 34 | + |
| 35 | +import com.redhat.exhort.integration.backend.sbom.spdx.SpdxProcessingException; |
| 36 | +import com.redhat.exhort.integration.backend.sbom.spdx.SpdxWrapper; |
| 37 | + |
| 38 | +public class SpdxWrapperTest { |
| 39 | + |
| 40 | + private static final MultiFormatStore inputStore = |
| 41 | + new MultiFormatStore(new InMemSpdxStore(), Format.JSON_PRETTY); |
| 42 | + |
| 43 | + @ParameterizedTest |
| 44 | + @ValueSource(strings = {Version.TWO_POINT_THREE_VERSION, Version.TWO_POINT_TWO_VERSION}) |
| 45 | + void testVersions(String version) throws InvalidSPDXAnalysisException, IOException { |
| 46 | + var wrapper = |
| 47 | + new SpdxWrapper( |
| 48 | + inputStore, |
| 49 | + this.getClass() |
| 50 | + .getClassLoader() |
| 51 | + .getResourceAsStream("spdx/versions/" + version + ".json")); |
| 52 | + assertNotNull(wrapper); |
| 53 | + assertNotNull(wrapper.getPackages()); |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + void testInvalidDocument() { |
| 58 | + assertThrows( |
| 59 | + SpdxProcessingException.class, |
| 60 | + () -> |
| 61 | + new SpdxWrapper( |
| 62 | + inputStore, |
| 63 | + this.getClass().getClassLoader().getResourceAsStream("cyclonedx/empty-sbom.json"))); |
| 64 | + } |
| 65 | +} |
0 commit comments