2121import java .util .List ;
2222import 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 ;
3940import org .spdx .storage .IModelStore .IdType ;
41+ import org .spdx .storage .simple .InMemSpdxStore ;
4042
4143import 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