|
1 | 1 | package org.spdx.library.model.license; |
| 2 | +import java.io.ByteArrayInputStream; |
| 3 | +import java.io.IOException; |
| 4 | +import java.io.InputStream; |
2 | 5 | import java.util.List; |
3 | 6 | import java.util.Optional; |
4 | 7 |
|
|
7 | 10 | import org.spdx.library.SpdxConstants; |
8 | 11 |
|
9 | 12 | import junit.framework.TestCase; |
| 13 | +import org.spdx.storage.listedlicense.SpdxListedLicenseModelStore; |
10 | 14 |
|
11 | 15 | /** |
12 | 16 | * Copyright (c) 2019 Source Auditor Inc. |
@@ -120,7 +124,9 @@ public void testGetExceptionbyIdLocal() throws InvalidSPDXAnalysisException { |
120 | 124 | } |
121 | 125 |
|
122 | 126 | public void testGetExceptionIds() throws InvalidSPDXAnalysisException { |
123 | | - assertTrue(ListedLicenses.getListedLicenses().getSpdxListedExceptionIds().size() >= NUM_3_7_EXCEPTION); |
| 127 | + List<String> result = ListedLicenses.getListedLicenses().getSpdxListedExceptionIds(); |
| 128 | + assertTrue(result.size() >= NUM_3_7_EXCEPTION); |
| 129 | + assertTrue(result.contains("389-exception")); |
124 | 130 | } |
125 | 131 |
|
126 | 132 | public void testListedLicenseIdCaseSensitive() { |
@@ -154,4 +160,47 @@ public void testGetExceptionIdProperty() throws InvalidSPDXAnalysisException { |
154 | 160 | assertTrue(idProp.get() instanceof String); |
155 | 161 | assertEquals(id, idProp.get()); |
156 | 162 | } |
| 163 | + |
| 164 | + public void testLicenseListInitializeListedLicenses() throws InvalidSPDXAnalysisException { |
| 165 | + try { |
| 166 | + ListedLicenses.initializeListedLicenses(new SpdxListedLicenseModelStore() { |
| 167 | + @Override |
| 168 | + public InputStream getTocInputStream() throws IOException { |
| 169 | + return ListedLicensesTest.class.getResourceAsStream("licenses.json"); |
| 170 | + } |
| 171 | + |
| 172 | + @Override |
| 173 | + public InputStream getExceptionTocInputStream() throws IOException { |
| 174 | + return ListedLicensesTest.class.getResourceAsStream("exceptions.json"); |
| 175 | + } |
| 176 | + |
| 177 | + @Override |
| 178 | + public InputStream getLicenseInputStream(String licenseId) throws IOException { |
| 179 | + throw new UnsupportedOperationException("this shouldn't be used in tests"); |
| 180 | + } |
| 181 | + |
| 182 | + @Override |
| 183 | + public InputStream getExceptionInputStream(String exceptionId) throws IOException { |
| 184 | + throw new UnsupportedOperationException("this shouldn't be used in tests"); |
| 185 | + } |
| 186 | + |
| 187 | + @Override |
| 188 | + public void close() throws Exception { |
| 189 | + // Nothing to do for the either the in-memory or the web store |
| 190 | + } |
| 191 | + }); |
| 192 | + List<String> licenseIds = ListedLicenses.getListedLicenses().getSpdxListedLicenseIds(); |
| 193 | + assertEquals(1, licenseIds.size()); |
| 194 | + assertFalse(licenseIds.contains("Apache-2.0")); |
| 195 | + assertTrue(licenseIds.contains("TEST")); |
| 196 | + |
| 197 | + List<String> exceptionIds = ListedLicenses.getListedLicenses().getSpdxListedExceptionIds(); |
| 198 | + assertEquals(1, licenseIds.size()); |
| 199 | + assertFalse(exceptionIds.contains("389-exception")); |
| 200 | + assertTrue(exceptionIds.contains("TEST-exception")); |
| 201 | + } finally { |
| 202 | + // since ListedLicenses in a singleton, reset it after running this test |
| 203 | + ListedLicenses.resetListedLicenses(); |
| 204 | + } |
| 205 | + } |
157 | 206 | } |
0 commit comments