Java Code Examples for org.apache.jena.rdf.model.Resource#asNode()

The following examples show how to use org.apache.jena.rdf.model.Resource#asNode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestAnnotation.java    From tools with Apache License 2.0 6 votes vote down vote up
/**
 * Test method for {@link org.spdx.rdfparser.model.Annotation#setAnnotationDate(java.lang.String)}.
 * @throws InvalidSPDXAnalysisException
 */
@Test
public void testSetDate() throws InvalidSPDXAnalysisException {
	Annotation a = new Annotation(ANNOTATOR1, OTHER_ANNOTATION, date, COMMENT1);
	assertEquals(ANNOTATOR1, a.getAnnotator());
	assertEquals(OTHER_ANNOTATION, a.getAnnotationType());
	assertEquals(date, a.getAnnotationDate());
	assertEquals(COMMENT1, a.getComment());
	final Model model = ModelFactory.createDefaultModel();
	IModelContainer modelContainer = new ModelContainerForTest(model, "http://testnamespace.com");
	Resource r = a.createResource(modelContainer);
	a.setAnnotationDate(oldDate);
	assertEquals(oldDate, a.getAnnotationDate());
	Annotation copy = new Annotation(modelContainer, r.asNode());
	assertEquals(oldDate, copy.getAnnotationDate());
}
 
Example 2
Source File: SpdxPackageVerificationCode.java    From tools with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a resource from this SPDX Verification Code
 * @param model
 * @return
 */
public Resource createResource(Model model) {
	this.model = model;
	Resource type = model.createResource(SpdxRdfConstants.SPDX_NAMESPACE +
			SpdxRdfConstants.CLASS_SPDX_VERIFICATIONCODE);
	Resource r = model.createResource(type);
	if (this.excludedFileNames.size() > 0) {
		Property excludedFileProp = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, 
				SpdxRdfConstants.PROP_VERIFICATIONCODE_IGNORED_FILES);
		for (int i = 0; i < this.excludedFileNames.size(); i++) {
			r.addProperty(excludedFileProp, this.excludedFileNames.get(i));
		}
	}
	if (this.value != null  && !this.value.isEmpty()) {
		Property valueProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_VERIFICATIONCODE_VALUE);
		r.addProperty(valueProperty, this.value);
	}
	this.verificationCodeNode = r.asNode();
	this.verificationCodeResource = r;
	return r;
}
 
Example 3
Source File: TestSpdxPackage.java    From tools with Apache License 2.0 6 votes vote down vote up
/**
 * Test method for {@link org.spdx.rdfparser.model.SpdxPackage#setVersionInfo(java.lang.String)}.
 * @throws InvalidSPDXAnalysisException 
 */
@Test
public void testSetVersionInfo() throws InvalidSPDXAnalysisException {
	Annotation[] annotations = new Annotation[] {ANNOTATION1};
	Relationship[] relationships = new Relationship[] {RELATIONSHIP1};
	Checksum[] checksums = new Checksum[] {CHECKSUM1, CHECKSUM2};
	SpdxFile[] files = new SpdxFile[] {FILE1, FILE2};
	AnyLicenseInfo[] licenseFromFiles = new AnyLicenseInfo[] {LICENSE2};

	SpdxPackage pkg = new SpdxPackage(PKG_NAME1, PKG_COMMENT1, 
			annotations, relationships,	LICENSE1, licenseFromFiles, 
			COPYRIGHT_TEXT1, LICENSE_COMMENT1, LICENSE3, checksums,
			DESCRIPTION1, DOWNLOAD_LOCATION1, files,
			HOMEPAGE1, ORIGINATOR1, PACKAGEFILENAME1, 
			VERIFICATION_CODE1, SOURCEINFO1, SUMMARY1, SUPPLIER1, VERSION1);
	
	assertEquals(VERSION1, pkg.getVersionInfo());
	Resource r = pkg.createResource(modelContainer);
	assertEquals(VERSION1, pkg.getVersionInfo());
	SpdxPackage pkg2 = new SpdxPackage(modelContainer, r.asNode());
	assertEquals(VERSION1, pkg2.getVersionInfo());
	pkg.setVersionInfo(VERSION2);
	assertEquals(VERSION2, pkg2.getVersionInfo());
	assertEquals(VERSION2, pkg.getVersionInfo());
}
 
Example 4
Source File: TestSpdxSnippet.java    From tools with Apache License 2.0 6 votes vote down vote up
/**
 * Test method for {@link org.spdx.rdfparser.model.SpdxSnippet#setSnippetFromFile(org.spdx.rdfparser.model.SpdxFile)}.
 * @throws InvalidSPDXAnalysisException 
 */
@Test
public void testSetSnippetFromFile() throws InvalidSPDXAnalysisException {
	SpdxSnippet snippet = new SpdxSnippet("snippetName", null, null, null, 
			COMPLEX_LICENSE, NON_STD_LICENSES, SpdxRdfConstants.NOASSERTION_VALUE,
			null, FROM_FILE1, BYTE_RANGE1, LINE_RANGE1);
	assertTrue(FROM_FILE1.equivalent(snippet.getSnippetFromFile()));
	Resource sr = snippet.createResource(modelContainer);
	SpdxSnippet snCopy = new SpdxSnippet(modelContainer, sr.asNode());
	assertTrue(FROM_FILE1.equivalent(snCopy.getSnippetFromFile()));
	assertTrue(FROM_FILE1.equivalent(snippet.getSnippetFromFile()));
	snCopy.setSnippetFromFile(FROM_FILE2);
	assertTrue(FROM_FILE2.equivalent(snCopy.getSnippetFromFile()));
	assertTrue(FROM_FILE2.equivalent(snippet.getSnippetFromFile()));
	// setting the from file should also set the reference file in the pointers
	assertTrue(FROM_FILE2.equivalent(snCopy.getByteRange().getStartPointer().getReference()));
	assertTrue(FROM_FILE2.equivalent(snCopy.getByteRange().getEndPointer().getReference()));
	assertTrue(FROM_FILE2.equivalent(snCopy.getLineRange().getStartPointer().getReference()));
	assertTrue(FROM_FILE2.equivalent(snCopy.getLineRange().getEndPointer().getReference()));
	assertTrue(FROM_FILE2.equivalent(snippet.getByteRange().getStartPointer().getReference()));
	assertTrue(FROM_FILE2.equivalent(snippet.getByteRange().getEndPointer().getReference()));
	assertTrue(FROM_FILE2.equivalent(snippet.getLineRange().getStartPointer().getReference()));
	assertTrue(FROM_FILE2.equivalent(snippet.getLineRange().getEndPointer().getReference()));
}
 
Example 5
Source File: TestRdfModelObject.java    From tools with Apache License 2.0 6 votes vote down vote up
@Test
public void testSpecialValues() throws InvalidSPDXAnalysisException {
	final Model model = ModelFactory.createDefaultModel();
	IModelContainer modelContainer = new ModelContainerForTest(model, "http://testnamespace.com");
	Resource r = model.createResource();
	EmptyRdfModelObject empty = new EmptyRdfModelObject(modelContainer, r.asNode());
	// None
	empty.setPropertyValue(TEST_NAMESPACE, TEST_PROPNAME1, SpdxRdfConstants.NONE_VALUE);
	String result = empty.findUriPropertyValue(TEST_NAMESPACE, TEST_PROPNAME1);
	assertEquals(SpdxRdfConstants.URI_VALUE_NONE, result);
	result = empty.findSinglePropertyValue(TEST_NAMESPACE, TEST_PROPNAME1);
	assertEquals(SpdxRdfConstants.NONE_VALUE, result);
	// NoAssertion
	empty.setPropertyValue(TEST_NAMESPACE, TEST_PROPNAME2, SpdxRdfConstants.NOASSERTION_VALUE);
	result = empty.findUriPropertyValue(TEST_NAMESPACE, TEST_PROPNAME2);
	assertEquals(SpdxRdfConstants.URI_VALUE_NOASSERTION, result);
	result = empty.findSinglePropertyValue(TEST_NAMESPACE, TEST_PROPNAME2);
	assertEquals(SpdxRdfConstants.NOASSERTION_VALUE, result);
}
 
Example 6
Source File: TestExternalDocumentRef.java    From tools with Apache License 2.0 6 votes vote down vote up
/**
 * Test method for {@link org.spdx.rdfparser.model.ExternalDocumentRef#setSpdxDocument(org.spdx.rdfparser.model.SpdxDocument)}.
 * @throws InvalidSPDXAnalysisException
 */
@Test
public void testSetSpdxDocument() throws InvalidSPDXAnalysisException {
	SpdxDocumentContainer container1 = new SpdxDocumentContainer(DOCUMENT_URI1);
	SpdxDocument doc1 = container1.getSpdxDocument();
	doc1.setName("DocumentName");
	ExternalDocumentRef edf = new ExternalDocumentRef(DOCUMENT_URI2, CHECKSUM1,
			DOCUMENT_ID1);
	Model model = ModelFactory.createDefaultModel();
	IModelContainer modelContainer = new ModelContainerForTest(model, "http://testnamespace.com");
	Resource r = edf.createResource(modelContainer);
	edf.setSpdxDocument(doc1);
	assertEquals(DOCUMENT_URI1, edf.getSpdxDocumentNamespace());
	assertEquals(doc1.getName(), edf.getSpdxDocument().getName());
	ExternalDocumentRef edf2 = new ExternalDocumentRef(modelContainer, r.asNode());
	assertEquals(DOCUMENT_URI1, edf2.getSpdxDocumentNamespace());
	SpdxDocumentContainer container2 = new SpdxDocumentContainer(DOCUMENT_URI2);
	SpdxDocument doc2 = container2.getSpdxDocument();
	doc2.setName("name2");
	edf2.setSpdxDocument(doc2);
	assertEquals(DOCUMENT_URI2, edf2.getSpdxDocumentNamespace());
	assertEquals(doc2.getName(), edf2.getSpdxDocument().getName());
	assertEquals(DOCUMENT_URI2, edf.getSpdxDocumentNamespace());
}
 
Example 7
Source File: TestRdfModelObject.java    From tools with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetFindPropertyValueReferenceType() throws InvalidSPDXAnalysisException, URISyntaxException {
	final Model model = ModelFactory.createDefaultModel();
	IModelContainer modelContainer = new ModelContainerForTest(model, "http://testnamespace.com");
	Resource r = model.createResource();
	EmptyRdfModelObject empty = new EmptyRdfModelObject(modelContainer, r.asNode());
	ReferenceType ref1 = new ReferenceType(new URI(SpdxRdfConstants.SPDX_LISTED_REFERENCE_TYPES_PREFIX + "cpe22Type"), null, null, null);
	ReferenceType ref2 = new ReferenceType(new URI(SpdxRdfConstants.SPDX_LISTED_REFERENCE_TYPES_PREFIX + "maven"), null, null, null);
	ref1.createResource(modelContainer);
	ReferenceType result = empty.findReferenceTypePropertyValue(TEST_NAMESPACE, TEST_PROPNAME2);
	assertTrue(result == null);
	empty.setPropertyValue(TEST_NAMESPACE, TEST_PROPNAME2, ref1);
	result = empty.findReferenceTypePropertyValue(TEST_NAMESPACE, TEST_PROPNAME2);
	assertEquals(ref1, result);
	empty.setPropertyValue(TEST_NAMESPACE, TEST_PROPNAME2, ref2);
	result = empty.findReferenceTypePropertyValue(TEST_NAMESPACE, TEST_PROPNAME2);
	assertEquals(ref2, result);
}
 
Example 8
Source File: TestSpdxItem.java    From tools with Apache License 2.0 6 votes vote down vote up
/**
 * Test method for {@link org.spdx.rdfparser.model.SpdxItem#setLicenseComments(java.lang.String)}.
 * @throws InvalidSPDXAnalysisException
 */
@Test
public void testSetLicenseComment() throws InvalidSPDXAnalysisException {
	Annotation[] annotations = new Annotation[] {ANNOTATION1, ANNOTATION2};
	Relationship[] relationships = new Relationship[] {RELATIONSHIP1, RELATIONSHIP2};
	SpdxItem item = new SpdxItem(ELEMENT_NAME1, ELEMENT_COMMENT1,
			annotations, relationships, LICENSE1, LICENSES,
			COPYRIGHT_TEXT1, LICENSE_COMMENT1);
	assertEquals(ELEMENT_NAME1, item.getName());
	assertEquals(ELEMENT_COMMENT1, item.getComment());
	assertTrue(UnitTestHelper.isArraysEqual(annotations, item.getAnnotations()));
	assertTrue(UnitTestHelper.isArraysEqual(relationships, item.getRelationships()));
	assertEquals(LICENSE1, item.getLicenseConcluded());
	assertTrue(UnitTestHelper.isArraysEqual(LICENSES, item.getLicenseInfoFromFiles()));
	assertEquals(COPYRIGHT_TEXT1, item.getCopyrightText());
	assertEquals(LICENSE_COMMENT1, item.getLicenseComments());
	Resource r = item.createResource(modelContainer);
	item.setLicenseComments(LICENSE_COMMENT2);
	assertEquals(LICENSE_COMMENT2, item.getLicenseComments());
	SpdxItem item2= new SpdxItem(modelContainer, r.asNode());
	assertEquals(LICENSE_COMMENT2, item2.getLicenseComments());
}
 
Example 9
Source File: TestExtractedLicenseInfo.java    From tools with Apache License 2.0 6 votes vote down vote up
/**
 * Test method for {@link org.spdx.rdfparser.license.ExtractedLicenseInfo#setComment(java.lang.String)}.
 * @throws InvalidSPDXAnalysisException 
 */
@Test
public void testSetComment() throws InvalidSPDXAnalysisException {
	ExtractedLicenseInfo lic = new ExtractedLicenseInfo(ID1, TEXT1);
	lic.setComment(COMMENT1);
	Resource licResource = lic.createResource(modelContainer);
	ExtractedLicenseInfo lic2 = new ExtractedLicenseInfo(modelContainer, licResource.asNode());
	lic2.setComment(COMMENT2);
	assertEquals(ID1, lic2.getLicenseId());
	assertEquals(TEXT1, lic2.getExtractedText());
	assertEquals(COMMENT2, lic2.getComment());
	StringWriter writer = new StringWriter();
	model.write(writer);
	@SuppressWarnings("unused")
	String rdfstring = writer.toString();
	ExtractedLicenseInfo lic3 = new ExtractedLicenseInfo(modelContainer, licResource.asNode());
	assertEquals(COMMENT2, lic3.getComment());	
}
 
Example 10
Source File: TestSpdxPackage.java    From tools with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddExternalRefs() throws InvalidSPDXAnalysisException {
	Annotation[] annotations = new Annotation[] {ANNOTATION1};
	Relationship[] relationships = new Relationship[] {RELATIONSHIP1};
	Checksum[] checksums = new Checksum[] {CHECKSUM1, CHECKSUM2};
	SpdxFile[] files = new SpdxFile[] {FILE1, FILE2};
	AnyLicenseInfo[] licenseFromFiles = new AnyLicenseInfo[] {LICENSE2};
	ExternalRef[] externalRefs1 = new ExternalRef[] {EXTERNAL_REF1};
	ExternalRef[] externalRefs2 = new ExternalRef[] {EXTERNAL_REF2, EXTERNAL_REF1};

	SpdxPackage pkg = new SpdxPackage(PKG_NAME1, PKG_COMMENT1, 
			annotations, relationships,	LICENSE1, licenseFromFiles, 
			COPYRIGHT_TEXT1, LICENSE_COMMENT1, LICENSE3, checksums,
			DESCRIPTION1, DOWNLOAD_LOCATION1, files,
			HOMEPAGE1, ORIGINATOR1, PACKAGEFILENAME1, 
			VERIFICATION_CODE1, SOURCEINFO1, SUMMARY1, SUPPLIER1,
			VERSION1, false, externalRefs1);
	
	assertTrue(UnitTestHelper.isArraysEquivalent(externalRefs1, pkg.getExternalRefs()));
	Resource r = pkg.createResource(modelContainer);
	assertTrue(UnitTestHelper.isArraysEquivalent(externalRefs1, pkg.getExternalRefs()));
	SpdxPackage pkg2 = new SpdxPackage(modelContainer, r.asNode());
	assertTrue(UnitTestHelper.isArraysEquivalent(externalRefs1, pkg2.getExternalRefs()));
	pkg.addExternalRef(EXTERNAL_REF2);
	assertTrue(UnitTestHelper.isArraysEquivalent(externalRefs2, pkg.getExternalRefs()));
	assertTrue(UnitTestHelper.isArraysEquivalent(externalRefs2, pkg2.getExternalRefs()));
}
 
Example 11
Source File: TestLicenseException.java    From tools with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetLicenseExceptionId() throws InvalidSPDXAnalysisException {
	LicenseException le = new LicenseException(EXCEPTION_ID1,
			EXCEPTION_NAME1, EXCEPTION_TEXT1, EXCEPTION_SEEALSO1,
			EXCEPTION_COMMENT1);
	assertEquals(EXCEPTION_ID1, le.getLicenseExceptionId());
	assertEquals(EXCEPTION_NAME1, le.getName());
	assertEquals(EXCEPTION_TEXT1, le.getLicenseExceptionText());
	assertStringsEquals(EXCEPTION_SEEALSO1, le.getSeeAlso());
	assertEquals(EXCEPTION_COMMENT1, le.getComment());
	le.setLicenseExceptionId(EXCEPTION_ID2);
	assertEquals(EXCEPTION_ID2, le.getLicenseExceptionId());
	assertEquals(EXCEPTION_NAME1, le.getName());
	assertEquals(EXCEPTION_TEXT1, le.getLicenseExceptionText());
	assertStringsEquals(EXCEPTION_SEEALSO1, le.getSeeAlso());
	assertEquals(EXCEPTION_COMMENT1, le.getComment());
	Resource leResource = le.createResource(testContainer);
	LicenseException le2 = new LicenseException(testContainer, leResource.asNode());
	assertEquals(EXCEPTION_ID2, le2.getLicenseExceptionId());
	assertEquals(EXCEPTION_NAME1, le2.getName());
	assertEquals(EXCEPTION_TEXT1, le2.getLicenseExceptionText());
	assertStringsEquals(EXCEPTION_SEEALSO1, le2.getSeeAlso());
	assertEquals(EXCEPTION_COMMENT1, le2.getComment());
	le2.setLicenseExceptionId(EXCEPTION_ID1);
	assertEquals(EXCEPTION_ID1, le2.getLicenseExceptionId());
	assertEquals(EXCEPTION_NAME1, le2.getName());
	assertEquals(EXCEPTION_TEXT1, le2.getLicenseExceptionText());
	assertStringsEquals(EXCEPTION_SEEALSO1, le2.getSeeAlso());
	assertEquals(EXCEPTION_COMMENT1, le2.getComment());
}
 
Example 12
Source File: TestSpdxFile.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for {@link org.spdx.rdfparser.model.SpdxFile#setArtifactOf(org.spdx.rdfparser.model.DoapProject[])}.
 * @throws InvalidSPDXAnalysisException 
 */
@SuppressWarnings("deprecation")
@Test
public void testSetArtifactOf() throws InvalidSPDXAnalysisException {
	DoapProject project1 = new DoapProject("Artifactof Project", "http://project.home.page/this");
	DoapProject project2 = new DoapProject("Artifactof Project2", "http://another.home.page/this");
	DoapProject project3 = new DoapProject("Artifactof Project3", "http://yea.home.page/this");
	DoapProject project4 = new DoapProject("Artifactof Project4", "http://ok.home.page/this");
	DoapProject[] artifactOfs1 = new DoapProject[] {project1, project2, project3};
	DoapProject[] artifactOfs2 = new DoapProject[] {project2, project4};
	DoapProject[] artifactOfSingle = new DoapProject[] {project4};
	
	model = ModelFactory.createDefaultModel();
	IModelContainer modelContainer = new ModelContainerForTest(model, "http://somethingunique.com/something");
	SpdxFile file = new SpdxFile("filename", null, null, null, 
			COMPLEX_LICENSE, CONJUNCTIVE_LICENSES, SpdxRdfConstants.NOASSERTION_VALUE, null,
			null, new Checksum[] {new Checksum(ChecksumAlgorithm.checksumAlgorithm_sha1,
					"1123456789abcdef0123456789abcdef01234567")}, null, null, artifactOfs1);
	DoapProject[] result = file.getArtifactOf();
	assertTrue(UnitTestHelper.isArraysEqual(artifactOfs1, result));
	file.setArtifactOf(artifactOfs2);
	result = file.getArtifactOf();
	assertTrue(UnitTestHelper.isArraysEqual(artifactOfs2, result));
	Resource r = file.createResource(modelContainer);
	SpdxFile file2 = new SpdxFile(modelContainer, r.asNode());
	result = file2.getArtifactOf();
	assertTrue(UnitTestHelper.isArraysEqual(artifactOfs2, result));
	file2.setArtifactOf(artifactOfSingle);
	result = file2.getArtifactOf();
	assertTrue(UnitTestHelper.isArraysEqual(artifactOfSingle, result));
	result = file.getArtifactOf();
	assertTrue(UnitTestHelper.isArraysEqual(artifactOfSingle, result));
}
 
Example 13
Source File: SPDXChecksum.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a resource from this SPDX Checksum
 * @param model
 * @return
 */
public Resource createResource(Model model) {
	this.model = model;
	Resource type = model.createResource(SpdxRdfConstants.SPDX_NAMESPACE +
			SpdxRdfConstants.CLASS_SPDX_CHECKSUM);
	
	Resource r;
	try {
		r = findSpdxChecksum(model, this);
	} catch (InvalidSPDXAnalysisException e) {
		// if we run into an error finding the checksum, we'll just create a new one
		r = null;
	}		// prevent duplicate checksum objects
	if (r == null) {
		r = model.createResource(type);
	}
	if (algorithm != null) {
		Property algProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, 
				SpdxRdfConstants.PROP_CHECKSUM_ALGORITHM);
		Resource algResource = model.createResource(ALGORITHM_TO_URI.get(algorithm));
		r.addProperty(algProperty, algResource);
	}
	if (this.value != null) {
		Property valueProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_CHECKSUM_VALUE);
		r.addProperty(valueProperty, this.value);
	}
	this.checksumNode = r.asNode();
	this.checksumResource = r;
	return r;
}
 
Example 14
Source File: TestSpdxElement.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for {@link org.spdx.rdfparser.model.SpdxElement#populateModel()}.
 * @throws InvalidSPDXAnalysisException
 */
@Test
public void testPopulateModel() throws InvalidSPDXAnalysisException {
	Annotation[] annotations = new Annotation[] {ANNOTATION1, ANNOTATION2};
	Relationship[] relationships = new Relationship[] {RELATIONSHIP1, RELATIONSHIP2};
	SpdxElement element1 = new SpdxElement(ELEMENT_NAME1, ELEMENT_COMMENT1,
			annotations, relationships);
	Resource r = element1.createResource(modelContainer);
	SpdxElement element2 = new SpdxElement(modelContainer, r.asNode());
	assertEquals(element1.getName(), element2.getName());
	assertEquals(element1.getComment(), element2.getComment());
	assertTrue(UnitTestHelper.isArraysEqual(element1.getAnnotations(), element2.getAnnotations()));
	assertTrue(UnitTestHelper.isArraysEqual(element1.getRelationships(),  element2.getRelationships()));
}
 
Example 15
Source File: TestSpdxPackage.java    From tools with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetExternalRefs() throws InvalidSPDXAnalysisException {
	Annotation[] annotations = new Annotation[] {ANNOTATION1};
	Relationship[] relationships = new Relationship[] {RELATIONSHIP1};
	Checksum[] checksums = new Checksum[] {CHECKSUM1, CHECKSUM2};
	SpdxFile[] files = new SpdxFile[] {FILE1, FILE2};
	AnyLicenseInfo[] licenseFromFiles = new AnyLicenseInfo[] {LICENSE2};
	ExternalRef[] externalRefs1 = new ExternalRef[] {EXTERNAL_REF1};
	ExternalRef[] externalRefs2 = new ExternalRef[] {EXTERNAL_REF2, EXTERNAL_REF1};

	SpdxPackage pkg = new SpdxPackage(PKG_NAME1, PKG_COMMENT1, 
			annotations, relationships,	LICENSE1, licenseFromFiles, 
			COPYRIGHT_TEXT1, LICENSE_COMMENT1, LICENSE3, checksums,
			DESCRIPTION1, DOWNLOAD_LOCATION1, files,
			HOMEPAGE1, ORIGINATOR1, PACKAGEFILENAME1, 
			VERIFICATION_CODE1, SOURCEINFO1, SUMMARY1, SUPPLIER1,
			VERSION1, false, externalRefs1);
	
	assertTrue(UnitTestHelper.isArraysEquivalent(externalRefs1, pkg.getExternalRefs()));
	Resource r = pkg.createResource(modelContainer);
	assertTrue(UnitTestHelper.isArraysEquivalent(externalRefs1, pkg.getExternalRefs()));
	SpdxPackage pkg2 = new SpdxPackage(modelContainer, r.asNode());
	assertTrue(UnitTestHelper.isArraysEquivalent(externalRefs1, pkg2.getExternalRefs()));
	pkg.setExternalRefs(externalRefs2);
	assertTrue(UnitTestHelper.isArraysEquivalent(externalRefs2, pkg.getExternalRefs()));
	assertTrue(UnitTestHelper.isArraysEquivalent(externalRefs2, pkg2.getExternalRefs()));
}
 
Example 16
Source File: TestRelationship.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for {@link org.spdx.rdfparser.model.Relationship#Relationship(org.spdx.rdfparser.IModelContainer, org.apache.jena.graph.Node)}.
 * @throws InvalidSPDXAnalysisException
 */
@Test
public void testRelationshipIModelContainerNode() throws InvalidSPDXAnalysisException {
	RelationshipType relationshipType1  = RelationshipType.DESCENDANT_OF;
	String comment1 = "Comment1";
	Relationship relationship = new Relationship(RELATED_ELEMENT1, relationshipType1, comment1);
	assertEquals(RELATED_ELEMENT1, relationship.getRelatedSpdxElement());
	assertEquals(relationshipType1, relationship.getRelationshipType());
	assertEquals(comment1, relationship.getComment());
	Resource r = relationship.createResource(modelContainer);
	Relationship result = new Relationship(modelContainer, r.asNode());
	assertEquals(RELATED_ELEMENT1, result.getRelatedSpdxElement());
	assertEquals(relationshipType1, result.getRelationshipType());
	assertEquals(comment1, result.getComment());
}
 
Example 17
Source File: TestLicenseException.java    From tools with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetLicenseExceptionTemplate() throws InvalidSPDXAnalysisException {
	LicenseException le = new LicenseException(EXCEPTION_ID1,
			EXCEPTION_NAME1, EXCEPTION_TEXT1, EXCEPTION_TEMPLATE1, EXCEPTION_SEEALSO1,
			EXCEPTION_COMMENT1);
	assertEquals(EXCEPTION_ID1, le.getLicenseExceptionId());
	assertEquals(EXCEPTION_NAME1, le.getName());
	assertEquals(EXCEPTION_TEXT1, le.getLicenseExceptionText());
	assertStringsEquals(EXCEPTION_SEEALSO1, le.getSeeAlso());
	assertEquals(EXCEPTION_COMMENT1, le.getComment());
	assertEquals(EXCEPTION_TEMPLATE1, le.getLicenseExceptionTemplate());
	le.setLicenseExceptionTemplate(EXCEPTION_TEMPLATE2);
	assertEquals(EXCEPTION_ID1, le.getLicenseExceptionId());
	assertEquals(EXCEPTION_NAME1, le.getName());
	assertEquals(EXCEPTION_TEMPLATE2, le.getLicenseExceptionTemplate());
	assertStringsEquals(EXCEPTION_SEEALSO1, le.getSeeAlso());
	assertEquals(EXCEPTION_COMMENT1, le.getComment());
	Resource leResource = le.createResource(testContainer);
	LicenseException le2 = new LicenseException(testContainer, leResource.asNode());
	assertEquals(EXCEPTION_ID1, le2.getLicenseExceptionId());
	assertEquals(EXCEPTION_NAME1, le2.getName());
	assertEquals(EXCEPTION_TEMPLATE2, le2.getLicenseExceptionTemplate());
	assertStringsEquals(EXCEPTION_SEEALSO1, le2.getSeeAlso());
	assertEquals(EXCEPTION_COMMENT1, le2.getComment());
	le2.setLicenseExceptionTemplate(EXCEPTION_TEMPLATE1);
	assertEquals(EXCEPTION_TEMPLATE1, le2.getLicenseExceptionTemplate());
	assertEquals(EXCEPTION_ID1, le2.getLicenseExceptionId());
	assertEquals(EXCEPTION_NAME1, le2.getName());
	assertEquals(EXCEPTION_TEMPLATE1, le2.getLicenseExceptionTemplate());
	assertStringsEquals(EXCEPTION_SEEALSO1, le2.getSeeAlso());
	assertEquals(EXCEPTION_COMMENT1, le2.getComment());
}
 
Example 18
Source File: TestRdfModelObject.java    From tools with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetFindPropertyValueExternalRefs() throws InvalidSPDXAnalysisException, URISyntaxException {
	final Model model = ModelFactory.createDefaultModel();
	IModelContainer modelContainer = new ModelContainerForTest(model, "http://testnamespace.com");
	Resource r = model.createResource();
	EmptyRdfModelObject empty = new EmptyRdfModelObject(modelContainer, r.asNode());
	ReferenceType refType1 = new ReferenceType(new URI(SpdxRdfConstants.SPDX_LISTED_REFERENCE_TYPES_PREFIX + "cpe22Type"), null, null, null);
	ReferenceType refType2 = new ReferenceType(new URI(SpdxRdfConstants.SPDX_LISTED_REFERENCE_TYPES_PREFIX + "maven"), null, null, null);
	ReferenceCategory refCat1 = ReferenceCategory.referenceCategory_packageManager;
	ReferenceCategory refCat2 = ReferenceCategory.referenceCategory_security;
	String refLocator1 = "Reference locator 1";
	String refLocator2 = "Reference locator 2";
	String comment1 = "Comment1";
	String comment2 = "Comment2";
	ExternalRef ref1 = new ExternalRef(refCat1, refType1, refLocator1, comment1);
	ExternalRef ref2 = new ExternalRef(refCat2, refType2, refLocator2, comment2);
	ref1.createResource(modelContainer);
	ref2.createResource(modelContainer);
	ExternalRef[] result = empty.findExternalRefPropertyValues(TEST_NAMESPACE, TEST_PROPNAME1);
	assertEquals(0, result.length);
	empty.setPropertyValue(TEST_NAMESPACE, TEST_PROPNAME1, new ExternalRef[] {ref1});
	result = empty.findExternalRefPropertyValues(TEST_NAMESPACE, TEST_PROPNAME1);
	assertEquals(1, result.length);
	assertEquals(ref1, result[0]);
	empty.setPropertyValue(TEST_NAMESPACE, TEST_PROPNAME1, new ExternalRef[] {ref1, ref2});
	result = empty.findExternalRefPropertyValues(TEST_NAMESPACE, TEST_PROPNAME1);
	assertEquals(2, result.length);
	if (ref1.equals(result[0])) {
		assertEquals(ref2, result[1]);
	} else {
		assertEquals(ref1, result[1]);
		assertEquals(ref2, result[0]);
	}
	empty.setPropertyValue(TEST_NAMESPACE, TEST_PROPNAME1, new ExternalRef[] {});	
	result = empty.findExternalRefPropertyValues(TEST_NAMESPACE, TEST_PROPNAME1);
	result = empty.findExternalRefPropertyValues(TEST_NAMESPACE, TEST_PROPNAME1);
	assertEquals(0, result.length);
}
 
Example 19
Source File: TestSPDXChecksum.java    From tools with Apache License 2.0 5 votes vote down vote up
@Test
public void testVerify() throws InvalidSPDXAnalysisException {
	SPDXChecksum checksum = new SPDXChecksum("SHA1", "0123456789abcdef0123456789abcdef01234567");
	List<String> verify = checksum.verify();
	assertEquals(0, verify.size());
	Resource chcksumResource = checksum.createResource(model);
	SPDXChecksum comp = new SPDXChecksum(model, chcksumResource.asNode());
	verify = comp.verify();
	assertEquals(0, verify.size());
}
 
Example 20
Source File: TestExternalDocumentRef.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for {@link org.spdx.rdfparser.model.ExternalDocumentRef#populateModel()}.
 * @throws InvalidSPDXAnalysisException
 */
@Test
public void testPopulateModel() throws InvalidSPDXAnalysisException {
	ExternalDocumentRef edf = new ExternalDocumentRef(DOCUMENT_URI1, CHECKSUM1,
			DOCUMENT_ID1);
	Model model = ModelFactory.createDefaultModel();
	IModelContainer modelContainer = new ModelContainerForTest(model, "http://testnamespace.com");
	assertEquals(DOCUMENT_URI1, edf.getSpdxDocumentNamespace());
	assertTrue(CHECKSUM1.equivalent(edf.getChecksum()));
	Resource r = edf.createResource(modelContainer);
	ExternalDocumentRef copy = new ExternalDocumentRef(modelContainer, r.asNode());
	assertEquals(DOCUMENT_URI1, copy.getSpdxDocumentNamespace());
	assertTrue(CHECKSUM1.equivalent(copy.getChecksum()));
}