Skip to content

Commit ad7c56e

Browse files
committed
Compiles and passes unit tests
Signed-off-by: Gary O'Neall <gary@sourceauditor.com>
1 parent 3aca0d2 commit ad7c56e

7 files changed

Lines changed: 405 additions & 319 deletions

File tree

src/main/java/org/spdx/storage/simple/InMemSpdxStore.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -415,16 +415,13 @@ public IdType getIdType(String id) {
415415
if (id.startsWith(ANON_PREFIX+GENERATED)) {
416416
return IdType.Anonymous;
417417
}
418-
if (id.startsWith(SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM) |
419-
id.contains(SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM)) {
418+
if (id.contains(SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM)) {
420419
return IdType.LicenseRef;
421420
}
422-
if (id.startsWith(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM) |
423-
id.contains(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM)) {
421+
if (id.contains(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM)) {
424422
return IdType.DocumentRef;
425423
}
426-
if (id.startsWith(SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM) |
427-
id.contains(SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM)) {
424+
if (id.contains(SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM)) {
428425
return IdType.SpdxId;
429426
}
430427
if (id.contains("://spdx.org/licenses/") || LicenseInfoFactory.isSpdxListedLicenseId(id) || LicenseInfoFactory.isSpdxListedExceptionId(id)) {

src/main/java/org/spdx/utility/compare/SpdxItemComparer.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,6 @@ public void addDocumentItem(SpdxDocument spdxDocument,
118118
// Concluded License
119119
if (!LicenseCompareHelper.isLicenseEqual(spdxItem.getLicenseConcluded(),
120120
itemB.getLicenseConcluded(), licenseXlationMap)) {
121-
122-
// DEBUG
123-
AnyLicenseInfo c1 = spdxItem.getLicenseConcluded();
124-
AnyLicenseInfo c2 = itemB.getLicenseConcluded();
125-
126-
127-
// END DEBUG
128121
this.concludedLicenseEquals = false;
129122
this.itemDifferenceFound = true;
130123
}

src/test/java/org/spdx/utility/compare/SpdxComparerTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.Map;
2929
import java.util.Optional;
3030
import java.util.Set;
31-
import java.util.stream.Collectors;
3231
import java.util.stream.Stream;
3332

3433
import org.spdx.core.DefaultModelStore;

src/test/java/org/spdx/utility/compare/SpdxFileComparerTest.java

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,22 @@
2525
import java.util.List;
2626
import java.util.Map;
2727

28-
import org.spdx.library.DefaultModelStore;
29-
import org.spdx.library.InvalidSPDXAnalysisException;
30-
import org.spdx.library.SpdxConstants.SpdxMajorVersion;
31-
import org.spdx.library.model.compat.v2.Checksum;
32-
import org.spdx.library.model.compat.v2.SpdxDocument;
33-
import org.spdx.library.model.compat.v2.SpdxFile;
34-
import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm;
35-
import org.spdx.library.model.compat.v2.enumerations.FileType;
36-
import org.spdx.library.model.compat.v2.license.AnyLicenseInfo;
37-
import org.spdx.library.model.compat.v2.license.InvalidLicenseStringException;
38-
import org.spdx.library.model.compat.v2.license.License;
39-
import org.spdx.library.model.compat.v2.license.LicenseInfoFactory;
28+
import org.spdx.core.DefaultModelStore;
29+
import org.spdx.core.IModelCopyManager;
30+
import org.spdx.core.InvalidSPDXAnalysisException;
31+
import org.spdx.library.LicenseInfoFactory;
32+
import org.spdx.library.ModelCopyManager;
33+
import org.spdx.library.SpdxModelFactory;
34+
import org.spdx.library.model.v2.Checksum;
35+
import org.spdx.library.model.v2.SpdxDocument;
36+
import org.spdx.library.model.v2.SpdxFile;
37+
import org.spdx.library.model.v2.enumerations.ChecksumAlgorithm;
38+
import org.spdx.library.model.v2.enumerations.FileType;
39+
import org.spdx.library.model.v2.license.AnyLicenseInfo;
40+
import org.spdx.library.model.v2.license.InvalidLicenseStringException;
41+
import org.spdx.library.model.v2.license.License;
42+
import org.spdx.storage.IModelStore;
43+
import org.spdx.storage.simple.InMemSpdxStore;
4044

4145
import junit.framework.TestCase;
4246

@@ -54,12 +58,20 @@ public class SpdxFileComparerTest extends TestCase {
5458
File testRDFFile;
5559
SpdxDocument DOCA;
5660
SpdxDocument DOCB;
61+
IModelStore modelStore;
62+
IModelCopyManager copyManager;
63+
static final String DEFAULT_DOCUMENT_URI = "http://default/doc";
64+
5765

5866
/**
5967
* @throws java.lang.Exception
6068
*/
6169
public void setUp() throws Exception {
62-
DefaultModelStore.reset(SpdxMajorVersion.VERSION_2);
70+
super.setUp();
71+
SpdxModelFactory.init();
72+
modelStore = new InMemSpdxStore();
73+
copyManager = new ModelCopyManager();
74+
DefaultModelStore.initialize(modelStore, DEFAULT_DOCUMENT_URI, copyManager);
6375
this.testRDFFile = new File(TEST_RDF_FILE_PATH);
6476
String uri1 = "http://doc/uri1";
6577
DOCA = new SpdxDocument(DefaultModelStore.getDefaultModelStore(), uri1, DefaultModelStore.getDefaultCopyManager(), true);
@@ -77,7 +89,7 @@ public void setUp() throws Exception {
7789
*/
7890
public void tearDown() throws Exception {
7991
super.tearDown();
80-
DefaultModelStore.reset(SpdxMajorVersion.VERSION_3);
92+
DefaultModelStore.initialize(new InMemSpdxStore(), DEFAULT_DOCUMENT_URI, new ModelCopyManager());
8193
}
8294

8395
/**

src/test/java/org/spdx/utility/compare/SpdxItemComparerTest.java

Lines changed: 72 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,24 @@
2121
import java.util.List;
2222
import java.util.Map;
2323

24-
import org.spdx.library.DefaultModelStore;
25-
import org.spdx.library.InvalidSPDXAnalysisException;
26-
import org.spdx.library.SpdxConstants.SpdxMajorVersion;
27-
import org.spdx.library.model.compat.v2.Annotation;
28-
import org.spdx.library.model.compat.v2.GenericModelObject;
29-
import org.spdx.library.model.compat.v2.GenericSpdxElement;
30-
import org.spdx.library.model.compat.v2.GenericSpdxItem;
31-
import org.spdx.library.model.compat.v2.Relationship;
32-
import org.spdx.library.model.compat.v2.SpdxDocument;
33-
import org.spdx.library.model.compat.v2.SpdxElement;
34-
import org.spdx.library.model.compat.v2.SpdxItem;
35-
import org.spdx.library.model.compat.v2.enumerations.AnnotationType;
36-
import org.spdx.library.model.compat.v2.enumerations.RelationshipType;
37-
import org.spdx.library.model.compat.v2.license.AnyLicenseInfo;
38-
import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo;
24+
import org.spdx.core.IModelCopyManager;
25+
import org.spdx.core.InvalidSPDXAnalysisException;
26+
import org.spdx.library.ModelCopyManager;
27+
import org.spdx.library.SpdxModelFactory;
28+
import org.spdx.library.model.v2.Annotation;
29+
import org.spdx.library.model.v2.GenericSpdxElement;
30+
import org.spdx.library.model.v2.GenericSpdxItem;
31+
import org.spdx.library.model.v2.Relationship;
32+
import org.spdx.library.model.v2.SpdxDocument;
33+
import org.spdx.library.model.v2.SpdxElement;
34+
import org.spdx.library.model.v2.SpdxItem;
35+
import org.spdx.library.model.v2.enumerations.AnnotationType;
36+
import org.spdx.library.model.v2.enumerations.RelationshipType;
37+
import org.spdx.library.model.v2.license.AnyLicenseInfo;
38+
import org.spdx.library.model.v2.license.ExtractedLicenseInfo;
39+
import org.spdx.storage.IModelStore;
3940
import org.spdx.storage.IModelStore.IdType;
41+
import org.spdx.storage.simple.InMemSpdxStore;
4042

4143
import junit.framework.TestCase;
4244

@@ -57,21 +59,6 @@ public class SpdxItemComparerTest extends TestCase {
5759
private static final String ATT_TEXTB = "Attribution B";
5860
private static final String[] ATTRIBUTION_TEXTA = new String[] {ATT_TEXTA};
5961
private static final String[] ATTRIBUTION_TEXTB = new String[] {ATT_TEXTB};
60-
private static final Map<String, String> LICENSE_XLATION_MAPAB = new HashMap<>();
61-
62-
static {
63-
LICENSE_XLATION_MAPAB.put("LicenseRef-1", "LicenseRef-4");
64-
LICENSE_XLATION_MAPAB.put("LicenseRef-2", "LicenseRef-5");
65-
LICENSE_XLATION_MAPAB.put("LicenseRef-3", "LicenseRef-6");
66-
}
67-
68-
private static final Map<String, String> LICENSE_XLATION_MAPBA = new HashMap<>();
69-
70-
static {
71-
LICENSE_XLATION_MAPBA.put("LicenseRef-4", "LicenseRef-1");
72-
LICENSE_XLATION_MAPBA.put("LicenseRef-5", "LicenseRef-2");
73-
LICENSE_XLATION_MAPBA.put("LicenseRef-6", "LicenseRef-3");
74-
}
7562

7663
private final Map<SpdxDocument, Map<SpdxDocument, Map<String, String>>> LICENSE_XLATION_MAP = new HashMap<>();
7764

@@ -108,66 +95,93 @@ public class SpdxItemComparerTest extends TestCase {
10895
private Relationship RELATIONSHIP2;
10996
private Relationship RELATIONSHIP3;
11097
private Relationship RELATIONSHIP4;
98+
99+
IModelStore modelStoreA;
100+
IModelStore modelStoreB;
101+
IModelCopyManager copyManager;
102+
String DEFAULT_DOCUMENT_URI = "http://default/doc";
103+
111104

112105
/* (non-Javadoc)
113106
* @see junit.framework.TestCase#setUp()
114107
*/
115108
protected void setUp() throws Exception {
116109
super.setUp();
117-
DefaultModelStore.reset(SpdxMajorVersion.VERSION_2);
118-
GenericModelObject gmo = new GenericModelObject();
119-
LICENSEA1 = new ExtractedLicenseInfo("LicenseRef-1", "License1");
120-
LICENSEA2 = new ExtractedLicenseInfo("LicenseRef-2", "License2");
121-
LICENSEA3 = new ExtractedLicenseInfo("LicenseRef-3", "License3");
122-
LICENSEB1 = new ExtractedLicenseInfo("LicenseRef-4", "License1");
123-
LICENSEB2 = new ExtractedLicenseInfo("LicenseRef-5", "License2");
124-
LICENSEB3 = new ExtractedLicenseInfo("LicenseRef-6", "License3");
110+
SpdxModelFactory.init();
111+
modelStoreA = new InMemSpdxStore();
112+
modelStoreB = new InMemSpdxStore();
113+
copyManager = new ModelCopyManager();
114+
String uri1 = "http://doc/uri1";
115+
DOCA = new SpdxDocument(modelStoreA, uri1, copyManager, true);
116+
String uri2 = "http://doc/uri2";
117+
DOCB = new SpdxDocument(modelStoreB, uri2, copyManager, true);
118+
LICENSEA1 = new ExtractedLicenseInfo(DOCA.getModelStore(), DOCA.getDocumentUri(), "LicenseRef-1", copyManager, true);
119+
LICENSEA1.setExtractedText("License1");
120+
LICENSEA2 = new ExtractedLicenseInfo(DOCA.getModelStore(), DOCA.getDocumentUri(), "LicenseRef-2", copyManager, true);
121+
LICENSEA1.setExtractedText("License2");
122+
LICENSEA3 = new ExtractedLicenseInfo(DOCA.getModelStore(), DOCA.getDocumentUri(), "LicenseRef-3", copyManager, true);
123+
LICENSEA1.setExtractedText("License3");
124+
LICENSEB1 = new ExtractedLicenseInfo(DOCB.getModelStore(), DOCB.getDocumentUri(), "LicenseRef-4", copyManager, true);
125+
LICENSEA1.setExtractedText("License1");
126+
LICENSEB2 = new ExtractedLicenseInfo(DOCB.getModelStore(), DOCB.getDocumentUri(), "LicenseRef-5", copyManager, true);
127+
LICENSEA1.setExtractedText("License2");
128+
LICENSEB3 = new ExtractedLicenseInfo(DOCB.getModelStore(), DOCB.getDocumentUri(), "LicenseRef-6", copyManager, true);
129+
LICENSEA1.setExtractedText("License3");
125130
LICENSE_INFO_FROM_FILESA = new AnyLicenseInfo[] {LICENSEA1, LICENSEA2, LICENSEA3};
126131
LICENSE_INFO_FROM_FILESB = new AnyLicenseInfo[] {LICENSEB1, LICENSEB2, LICENSEB3};
127132

128133
LICENSE_CONCLUDEDA = LICENSEA1;
129134
LICENSE_CONCLUDEDB = LICENSEB1;
130-
ANNOTATION1 = gmo.createAnnotation("Person:Annotator1", AnnotationType.OTHER,
135+
ANNOTATION1 = DOCA.createAnnotation("Person:Annotator1", AnnotationType.OTHER,
131136
"2010-01-29T18:30:22Z", "AnnotationComment1");
132-
ANNOTATION2 = gmo.createAnnotation("Person:Annotator2", AnnotationType.REVIEW,
137+
ANNOTATION2 = DOCA.createAnnotation("Person:Annotator2", AnnotationType.REVIEW,
133138
"2011-01-29T18:30:22Z", "AnnotationComment2");
134-
ANNOTATION3 = gmo.createAnnotation("Person:Annotator3", AnnotationType.OTHER,
139+
ANNOTATION3 = DOCA.createAnnotation("Person:Annotator3", AnnotationType.OTHER,
135140
"2012-01-29T18:30:22Z", "AnnotationComment3");
136-
ANNOTATION4 = gmo.createAnnotation("Person:Annotator4", AnnotationType.REVIEW,
141+
ANNOTATION4 = DOCA.createAnnotation("Person:Annotator4", AnnotationType.REVIEW,
137142
"2013-01-29T18:30:22Z", "AnnotationComment4");
138143
ANNOTATIONSA = new Annotation[] {ANNOTATION1, ANNOTATION2};
139144
ANNOTATIONSB = new Annotation[] {ANNOTATION3, ANNOTATION4};
140-
RELATED_ELEMENT1 = new GenericSpdxElement();
145+
RELATED_ELEMENT1 = new GenericSpdxElement(DOCA.getModelStore(), DOCA.getDocumentUri(),
146+
DOCA.getModelStore().getNextId(IdType.SpdxId), copyManager, true);
141147
RELATED_ELEMENT1.setName("relatedElementName1");
142148
RELATED_ELEMENT1.setComment("related element comment 1");
143-
RELATED_ELEMENT2 = new GenericSpdxElement();
149+
RELATED_ELEMENT2 = new GenericSpdxElement(DOCA.getModelStore(), DOCA.getDocumentUri(),
150+
DOCA.getModelStore().getNextId(IdType.SpdxId), copyManager, true);
144151
RELATED_ELEMENT2.setName("relatedElementName2");
145152
RELATED_ELEMENT2.setComment("related element comment 2");
146-
RELATED_ELEMENT3 = new GenericSpdxElement();
153+
RELATED_ELEMENT3 = new GenericSpdxElement(DOCB.getModelStore(), DOCB.getDocumentUri(),
154+
DOCB.getModelStore().getNextId(IdType.SpdxId), copyManager, true);
147155
RELATED_ELEMENT3.setName("relatedElementName3");
148156
RELATED_ELEMENT3.setComment("related element comment 3");
149-
RELATED_ELEMENT4 = new GenericSpdxElement();
157+
RELATED_ELEMENT4 = new GenericSpdxElement(DOCB.getModelStore(), DOCB.getDocumentUri(),
158+
DOCB.getModelStore().getNextId(IdType.SpdxId), copyManager, true);
150159
RELATED_ELEMENT4.setName("relatedElementName4");
151160
RELATED_ELEMENT4.setComment("related element comment 4");
152-
RELATIONSHIP1 = gmo.createRelationship(RELATED_ELEMENT1,
161+
RELATIONSHIP1 = DOCA.createRelationship(RELATED_ELEMENT1,
153162
RelationshipType.CONTAINS, "Relationship Comment1");
154-
RELATIONSHIP2 = gmo.createRelationship(RELATED_ELEMENT2,
163+
RELATIONSHIP2 = DOCA.createRelationship(RELATED_ELEMENT2,
155164
RelationshipType.DYNAMIC_LINK, "Relationship Comment2");
156-
RELATIONSHIP3 = gmo.createRelationship(RELATED_ELEMENT3,
165+
RELATIONSHIP3 = DOCB.createRelationship(RELATED_ELEMENT3,
157166
RelationshipType.DATA_FILE_OF, "Relationship Comment3");
158-
RELATIONSHIP4 = gmo.createRelationship(RELATED_ELEMENT4,
167+
RELATIONSHIP4 = DOCB.createRelationship(RELATED_ELEMENT4,
159168
RelationshipType.DISTRIBUTION_ARTIFACT, "Relationship Comment4");
160169
RELATIONSHIPSA = new Relationship[] {RELATIONSHIP1, RELATIONSHIP2};
161170
RELATIONSHIPSB = new Relationship[] {RELATIONSHIP3, RELATIONSHIP4};
162-
String uri1 = "http://doc/uri1";
163-
DOCA = new SpdxDocument(uri1);
164-
String uri2 = "http://doc/uri2";
165-
DOCB = new SpdxDocument(uri2);
171+
166172
Map<SpdxDocument, Map<String, String>> bmap = new HashMap<>();
167-
bmap.put(DOCB, LICENSE_XLATION_MAPAB);
173+
Map<String, String> mapAB = new HashMap<>();
174+
mapAB.put(DOCA.getDocumentUri() + "#" + "LicenseRef-1", DOCB.getDocumentUri() + "#" + "LicenseRef-4");
175+
mapAB.put(DOCA.getDocumentUri() + "#" + "LicenseRef-2", DOCB.getDocumentUri() + "#" + "LicenseRef-5");
176+
mapAB.put(DOCA.getDocumentUri() + "#" + "LicenseRef-3", DOCB.getDocumentUri() + "#" + "LicenseRef-6");
177+
bmap.put(DOCB, mapAB);
168178
LICENSE_XLATION_MAP.put(DOCA, bmap);
169179
Map<SpdxDocument, Map<String, String>> amap = new HashMap<>();
170-
amap.put(DOCA, LICENSE_XLATION_MAPBA);
180+
Map<String, String> mapBA = new HashMap<>();
181+
mapBA.put(DOCB.getDocumentUri() + "#" + "LicenseRef-4", DOCA.getDocumentUri() + "#" + "LicenseRef-1");
182+
mapBA.put(DOCB.getDocumentUri() + "#" + "LicenseRef-5", DOCA.getDocumentUri() + "#" + "LicenseRef-2");
183+
mapBA.put(DOCB.getDocumentUri() + "#" + "LicenseRef-6", DOCA.getDocumentUri() + "#" + "LicenseRef-3");
184+
amap.put(DOCA, mapBA);
171185
LICENSE_XLATION_MAP.put(DOCB, amap);
172186
}
173187

@@ -176,7 +190,6 @@ protected void setUp() throws Exception {
176190
*/
177191
protected void tearDown() throws Exception {
178192
super.tearDown();
179-
DefaultModelStore.reset(SpdxMajorVersion.VERSION_3);
180193
}
181194

182195
public void testCompare() throws SpdxCompareException, InvalidSPDXAnalysisException {
@@ -206,8 +219,8 @@ private SpdxItem createGenericItem(SpdxDocument doc, String name, String comment
206219
AnyLicenseInfo[] licenseInfosFromFiles, String copyright, String licenseComments,
207220
String[] attributionText) throws InvalidSPDXAnalysisException {
208221

209-
SpdxItem retval = new GenericSpdxItem(DefaultModelStore.getDefaultModelStore(), DOCA.getDocumentUri(),
210-
DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, DOCA.getDocumentUri()), DefaultModelStore.getDefaultCopyManager(), true);
222+
GenericSpdxItem retval = new GenericSpdxItem(doc.getModelStore(), doc.getDocumentUri(),
223+
doc.getModelStore().getNextId(IdType.Anonymous), doc.getCopyManager(), true);
211224
retval.setName(name);
212225
retval.setComment(comment);
213226
for (Annotation annotation:annotations) {

0 commit comments

Comments
 (0)