Java Code Examples for org.apache.jena.rdf.model.ModelFactory#createDefaultModel()

The following examples show how to use org.apache.jena.rdf.model.ModelFactory#createDefaultModel() . 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: TestRdfModelObject.java    From tools with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddSetPropertyUriValues() 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());
	String uri1 = "http://this.is.a#uri";
	String uri2 = "http://this.is.a#uri2";
	String[] uris = new String[] {uri1, uri2};
	String[] result = empty.findUriPropertyValues(TEST_NAMESPACE, TEST_PROPNAME1);
	assertEquals(0, result.length);
	empty.addPropertyUriValue(TEST_NAMESPACE, TEST_PROPNAME1, uri1);
	result = empty.findUriPropertyValues(TEST_NAMESPACE, TEST_PROPNAME1);
	assertEquals(1, result.length);
	assertEquals(uri1, result[0]);
	empty.addPropertyUriValue(TEST_NAMESPACE, TEST_PROPNAME1, uri2);
	result = empty.findUriPropertyValues(TEST_NAMESPACE, TEST_PROPNAME1);
	assertTrue(UnitTestHelper.isArraysEqual(uris, result));
}
 
Example 2
Source File: OneM2MContentInstanceMapper.java    From SDA with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static void main(String[] args) throws IOException {

		File f = new File("/Users/rosenc/Documents/business/[2015]icbms/json_sample1.txt");
		BufferedReader br = new BufferedReader(new FileReader(f));
		String line = null;
		String s = "";
		while ((line = br.readLine()) != null) {
			s = s + line + "\n";
		}

		System.out.println(s);
		Gson gson = new Gson();
		OneM2MContentInstanceDTO cont = gson.fromJson(s, OneM2MContentInstanceDTO.class);
		OneM2MContentInstanceMapper mapper = new OneM2MContentInstanceMapper(cont);

		Model model = ModelFactory.createDefaultModel();
		model.add(mapper.from());
		System.out.println("content type ; " + mapper.getContentType());
		// 스트링 변환부분
		RDFDataMgr.write(System.out, model, RDFFormat.NTRIPLES);
		// System.out.println(mapper.getTypedContent("2k42kk"));
		// mapper.getTypedContent("2.4");

	}
 
Example 3
Source File: TestSpdxFile.java    From tools with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoassertionCopyright() throws InvalidSPDXAnalysisException {
	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, null);
	Resource fileResource = file.createResource(modelContainer);
	Node p = model.getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_FILE_COPYRIGHT).asNode();
	Triple m = Triple.createMatch(null, p, null);
	ExtendedIterator<Triple> tripleIter = model.getGraph().find(m);	
	while (tripleIter.hasNext()) {
		Triple t = tripleIter.next();
		assertTrue(t.getObject().isURI());
		assertEquals(SpdxRdfConstants.URI_VALUE_NOASSERTION, t.getObject().getURI());
	}
	SpdxFile file2 = new SpdxFile(modelContainer, fileResource.asNode());
	assertEquals(SpdxRdfConstants.NOASSERTION_VALUE, file2.getCopyrightText());
}
 
Example 4
Source File: PrefixNSService.java    From RDFUnit with Apache License 2.0 6 votes vote down vote up
private static BiMap<String, String> createPrefixNsBidiMap() {

            BiMap<String, String> dualMap = HashBiMap.create();
            Model prefixModel = ModelFactory.createDefaultModel();

            try (InputStream is = PrefixNSService.class.getResourceAsStream(Resources.PREFIXES)) {
                prefixModel.read(is, null, "TURTLE");
            } catch (IOException e) {
                throw new IllegalArgumentException("Cannot read prefixes.ttl from resources", e);
            }

            // Update Prefix Service
            Map<String, String> prf = prefixModel.getNsPrefixMap();
            for (Map.Entry<String, String> entry : prf.entrySet()) {
                // Use local filed and NOT accessor method (synchronized)
                dualMap.put(entry.getKey(), entry.getValue());
            }

            return dualMap;
        }
 
Example 5
Source File: TestSPDXFile.java    From tools with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoassertionCopyright() throws InvalidSPDXAnalysisException {
	model = ModelFactory.createDefaultModel();
	SPDXDocument doc = new SPDXDocument(model);
	doc.createSpdxAnalysis("http://somethingunique");
	SPDXFile file = new SPDXFile("filename", "BINARY", "sha1", COMPLEX_LICENSE, CONJUNCTIVE_LICENSES, "", SpdxRdfConstants.NOASSERTION_VALUE, new DOAPProject[0]);
	Resource fileResource = file.createResource(doc, doc.getDocumentNamespace() + doc.getNextSpdxElementRef());
	Node p = model.getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_FILE_COPYRIGHT).asNode();
	Triple m = Triple.createMatch(null, p, null);
	ExtendedIterator<Triple> tripleIter = model.getGraph().find(m);	
	while (tripleIter.hasNext()) {
		Triple t = tripleIter.next();
		assertTrue(t.getObject().isURI());
		assertEquals(SpdxRdfConstants.URI_VALUE_NOASSERTION, t.getObject().getURI());
	}
	SPDXFile file2 = new SPDXFile(modelContainer, fileResource.asNode());
	assertEquals(SpdxRdfConstants.NOASSERTION_VALUE, file2.getCopyright());
}
 
Example 6
Source File: TestRdfModelObject.java    From tools with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddRelationshipPropertyValues() 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());
	Relationship[] result = empty.findRelationshipPropertyValues(TEST_NAMESPACE, TEST_PROPNAME1);
	assertEquals(0, result.length);
	String elementName1 = "element name 1";
	String elementComment1 = "element comment 1";
	SpdxElement element1 = new SpdxElement(elementName1, elementComment1, null, null);
	RelationshipType relType1 = RelationshipType.BUILD_TOOL_OF;
	String relComment1 = "Relationship Comment 1";
	Relationship relationship1 = new Relationship(element1, relType1, relComment1);
	empty.addPropertyValue(TEST_NAMESPACE, TEST_PROPNAME1, relationship1);
	result = empty.findRelationshipPropertyValues(TEST_NAMESPACE, TEST_PROPNAME1);
	assertEquals(1, result.length);
	assertEquals(relationship1, result[0]);
}
 
Example 7
Source File: SkolemizerTest.java    From Processor with Apache License 2.0 6 votes vote down vote up
/**
 * Test of build method, of class Skolemizer.
 */
@Test
public void testBuild_Model()
{
    Model expected = ModelFactory.createDefaultModel();
    Resource expAbsolute = expected.createResource(baseUriBuilder.clone().path(absoluteId).build().toString()).
            addProperty(RDF.type, absolutePathClass).
            addLiteral(DCTerms.identifier, absoluteId);
    Resource expRelative = expected.createResource(absolutePathBuilder.clone().path(relativeId).build().toString()).
            addProperty(RDF.type, relativePathClass).
            addLiteral(DCTerms.identifier, relativeId);
    Resource expThing = expected.createResource(absolutePathBuilder.clone().path(thingTitle).fragment(thingFragment).build().toString()).
            addProperty(RDF.type, thingClass).
            addLiteral(DCTerms.title, thingTitle);
    Resource expImported = expected.createResource(absolutePathBuilder.clone().path(thingTitle).fragment(thingFragment).build().toString()).
            addProperty(RDF.type, importedClass).
            addLiteral(DCTerms.title, thingTitle);
    Resource expRestricted = expected.createResource(UriBuilder.fromUri(restrictionValue).clone().path(restrictedId).build().toString()).
            addProperty(RDF.type, restrictedClass).
            addLiteral(DCTerms.identifier, restrictedId);        
    expRelative.addProperty(FOAF.primaryTopic, expThing);
    expThing.addProperty(FOAF.isPrimaryTopicOf, expRelative);
    
    Model result = skolemizer.build(input);
    assertTrue(result.isIsomorphicWith(expected));
}
 
Example 8
Source File: SPDXDocumentFactory.java    From tools with Apache License 2.0 6 votes vote down vote up
/**
 * Create an SPDX Document from a file
 * @param fileNameOrUrl local file name or Url containing the SPDX data.  Can be in RDF/XML or RDFa format
 * @return SPDX Document initialized with the exsiting data
 * @throws IOException
 * @throws InvalidSPDXAnalysisException
 */
public static SPDXDocument creatSpdxDocument(String fileNameOrUrl) throws IOException, InvalidSPDXAnalysisException {
	try {
		Class.forName("net.rootdev.javardfa.jena.RDFaReader");
	} catch(java.lang.ClassNotFoundException e) {}  // do nothing

	Model model = ModelFactory.createDefaultModel();

	InputStream spdxRdfInput = FileManager.get().open(fileNameOrUrl);
	if (spdxRdfInput == null)
		throw new FileNotFoundException("Unable to open \"" + fileNameOrUrl + "\" for reading");

	model.read(spdxRdfInput, figureBaseUri(fileNameOrUrl), fileType(fileNameOrUrl));

	return new SPDXDocument(model);
}
 
Example 9
Source File: TestSPDXDocument.java    From tools with Apache License 2.0 6 votes vote down vote up
@Test
public void testSpdxDocVersions() throws InvalidSPDXAnalysisException {
	Model model = ModelFactory.createDefaultModel();
	SPDXDocument doc = new SPDXDocument(model);
	String testDocUri = "https://olex.openlogic.com/spdxdoc/package_versions/download/4832?path=openlogic/zlib/1.2.3/zlib-1.2.3-all-src.zip&amp;package_version_id=1082";
	doc.createSpdxAnalysis(testDocUri, SPDXDocument.POINT_NINE_SPDX_VERSION);
	assertEquals(SPDXDocument.POINT_NINE_SPDX_VERSION, doc.getSpdxVersion());
	if (doc.getDataLicense() != null) {
		fail("No license should exist for current data license");
	}
	// 1.0
	model = ModelFactory.createDefaultModel();
	doc = new SPDXDocument(model);
	doc.createSpdxAnalysis(testDocUri, SPDXDocument.ONE_DOT_ZERO_SPDX_VERSION);
	assertEquals(SPDXDocument.ONE_DOT_ZERO_SPDX_VERSION, doc.getSpdxVersion());
	assertEquals(SpdxRdfConstants.SPDX_DATA_LICENSE_ID_VERSION_1_0, doc.getDataLicense().getLicenseId());
	
	// current version
	model = ModelFactory.createDefaultModel();
	doc = new SPDXDocument(model);
	doc.createSpdxAnalysis(testDocUri);
	assertEquals(SPDXDocument.CURRENT_SPDX_VERSION, doc.getSpdxVersion());
	assertEquals(SpdxRdfConstants.SPDX_DATA_LICENSE_ID, doc.getDataLicense().getLicenseId());
}
 
Example 10
Source File: TestWithExceptionOperator.java    From tools with Apache License 2.0 6 votes vote down vote up
/**
 * Test method for {@link org.spdx.rdfparser.license.WithExceptionOperator#setException(org.spdx.rdfparser.license.LicenseException)}.
 * @throws InvalidSPDXAnalysisException 
 */
@Test
public void testSetException() throws InvalidSPDXAnalysisException {
	WithExceptionOperator weo1 = new WithExceptionOperator(license1, exception1);
	model = ModelFactory.createDefaultModel();
	weo1.createResource(modelContainer);
	ExtractedLicenseInfo lic1 = (ExtractedLicenseInfo)weo1.getLicense();
	LicenseException le1 = weo1.getException();
	assertEquals(LICENSE_ID1, lic1.getLicenseId());
	assertEquals(LICENSE_TEXT1, lic1.getExtractedText());
	assertEquals(EXCEPTION_ID1, le1.getLicenseExceptionId());
	assertEquals(EXCEPTION_TEXT1, le1.getLicenseExceptionText());
	assertEquals(EXCEPTION_NAME1, le1.getName());
	weo1.setException(exception2);
	lic1 = (ExtractedLicenseInfo)weo1.getLicense();
	le1 = weo1.getException();
	assertEquals(LICENSE_ID1, lic1.getLicenseId());
	assertEquals(LICENSE_TEXT1, lic1.getExtractedText());
	assertEquals(EXCEPTION_ID2, le1.getLicenseExceptionId());
	assertEquals(EXCEPTION_TEXT2, le1.getLicenseExceptionText());
	assertEquals(EXCEPTION_NAME2, le1.getName());
}
 
Example 11
Source File: TestRdfModelObject.java    From tools with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddElementsPropertyValue() 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());
	SpdxElement[] result = empty.findMultipleElementPropertyValues(TEST_NAMESPACE, TEST_PROPNAME1);
	assertEquals(0, result.length);
	String elementName1 = "element name 1";
	String elementComment1 = "element comment 1";
	SpdxElement element1 = new SpdxElement(elementName1, elementComment1, null, null);
	empty.addPropertyValue(TEST_NAMESPACE, TEST_PROPNAME1, element1);
	result = empty.findMultipleElementPropertyValues(TEST_NAMESPACE, TEST_PROPNAME1);
	assertEquals(1, result.length);
	assertEquals(element1, result[0]);
	String elementName2 = "element name 2";
	String elementComment2 = "element comment 2";
	SpdxElement element2 = new SpdxElement(elementName2, elementComment2, null, null);
	empty.addPropertyValue(TEST_NAMESPACE, TEST_PROPNAME1, element2);
	result = empty.findMultipleElementPropertyValues(TEST_NAMESPACE, TEST_PROPNAME1);
	assertEquals(2, result.length);
	assertTrue(UnitTestHelper.isArraysEquivalent(new SpdxElement[] {element1,  element2}, result));
}
 
Example 12
Source File: TestSPDXFile.java    From tools with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetFileDependencies() throws InvalidSPDXAnalysisException {
	model = ModelFactory.createDefaultModel();
	SPDXDocument doc = new SPDXDocument(model);
	doc.createSpdxAnalysis("http://somethingunique");
	String FileDependencyName1  = "Dependency1";
	String FileDependencyName2 = "dependencies/Dependency2";
	String FileDependencyName3 = "Depenedency3";
	String COMMENT1 = "comment";
	SPDXFile file = new SPDXFile("filename", "BINARY", "sha1", COMPLEX_LICENSE, CONJUNCTIVE_LICENSES, "", SpdxRdfConstants.NOASSERTION_VALUE, new DOAPProject[0], COMMENT1);
	SPDXFile fileDependency1 = new SPDXFile(FileDependencyName1, "BINARY", "sha1", COMPLEX_LICENSE, CONJUNCTIVE_LICENSES, "", SpdxRdfConstants.NOASSERTION_VALUE, new DOAPProject[0], COMMENT1);
	SPDXFile fileDependency2 = new SPDXFile(FileDependencyName2, "BINARY", "sha1", COMPLEX_LICENSE, CONJUNCTIVE_LICENSES, "", SpdxRdfConstants.NOASSERTION_VALUE, new DOAPProject[0], COMMENT1);
	SPDXFile fileDependency3 = new SPDXFile(FileDependencyName3, "BINARY", "sha1", COMPLEX_LICENSE, CONJUNCTIVE_LICENSES, "", SpdxRdfConstants.NOASSERTION_VALUE, new DOAPProject[0], COMMENT1);
	Resource fileResource = file.createResource(doc, doc.getDocumentNamespace() + doc.getNextSpdxElementRef());
	Resource fileDependencyResource1 = fileDependency1.createResource(doc, doc.getDocumentNamespace() + doc.getNextSpdxElementRef());
	Resource fileDependencyResource2 = fileDependency2.createResource(doc, doc.getDocumentNamespace() + doc.getNextSpdxElementRef());
	Resource fileDependencyResource3 = fileDependency3.createResource(doc, doc.getDocumentNamespace() + doc.getNextSpdxElementRef());
	SPDXFile[] fileDependencies = new SPDXFile[] {fileDependency1, fileDependency2, fileDependency3};
	SPDXFile[] noDependencies = file.getFileDependencies();
	assertEquals(0, noDependencies.length);
	file.setFileDependencies(fileDependencies, doc);
	SPDXFile[] result = file.getFileDependencies();
	assertFileArraysEqual(fileDependencies, result);
	SPDXFile file2 = new SPDXFile(modelContainer, fileResource.asNode());
	result = file2.getFileDependencies();
	assertFileArraysEqual(fileDependencies, result);
}
 
Example 13
Source File: TestRdfModelObject.java    From tools with Apache License 2.0 5 votes vote down vote up
@Test
public void testFindSetPropertyDaopValue() 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());
	DoapProject p1 = new DoapProject("Name1", "http://home.page/one");
	DoapProject p2 = new DoapProject("Name2", "http://home.page/two");
	p2.createResource(modelContainer);
	DoapProject[] projects = new DoapProject[] {p1, p2};
	empty.setPropertyValue(TEST_NAMESPACE, TEST_PROPNAME1, projects);
	DoapProject[] result = empty.findMultipleDoapPropertyValues(TEST_NAMESPACE, TEST_PROPNAME1);
	assertTrue(UnitTestHelper.isArraysEqual(projects, result));
}
 
Example 14
Source File: TestRelationship.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
	model = ModelFactory.createDefaultModel();
	modelContainer = new ModelContainerForTest(model, DOCUMENT_NAMESPACE);
	RELATED_ELEMENT1 = new SpdxElement("relatedElementName1",
			"related element comment 1", null, null);
	RELATED_ELEMENT2 = new SpdxElement("relatedElementName2",
			"related element comment 2", null, null);
}
 
Example 15
Source File: TestRdfModelObject.java    From tools with Apache License 2.0 5 votes vote down vote up
@Test
public void testFindSetAnnotationsPropertyValue() 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());
	Annotation[] result = empty.findAnnotationPropertyValues(TEST_NAMESPACE, TEST_PROPNAME1);
	assertEquals(0, result.length);
	String annotator1 = "Annotator 1";
	AnnotationType annType1 = AnnotationType.annotationType_other;
	DateFormat format = new SimpleDateFormat(SpdxRdfConstants.SPDX_DATE_FORMAT);
	String annDate1 = format.format(new Date());
	String annComment1 = "Annotation Comment 1";
	Annotation an1 = new Annotation(annotator1, annType1, annDate1, annComment1);
	String annotator2 = "Annotator 2";
	AnnotationType annType2 = AnnotationType.annotationType_review;
	String annDate2 = format.format(new Date(10101));
	String annComment2 = "Annotation Comment 2";
	Annotation an2 = new Annotation(annotator2, annType2, annDate2, annComment2);
	empty.setPropertyValues(TEST_NAMESPACE, TEST_PROPNAME1, new Annotation[] {an1});
	result = empty.findAnnotationPropertyValues(TEST_NAMESPACE, TEST_PROPNAME1);
	assertEquals(1, result.length);
	assertEquals(an1, result[0]);
	empty.setPropertyValues(TEST_NAMESPACE, TEST_PROPNAME1, new Annotation[] {an1, an2});
	result = empty.findAnnotationPropertyValues(TEST_NAMESPACE, TEST_PROPNAME1);
	assertEquals(2, result.length);
	if (result[0].equals(an1)) {
		assertEquals(result[1], an2);
	} else {
		assertEquals(result[0], an2);
	}
	empty.setPropertyValues(TEST_NAMESPACE, TEST_PROPNAME1, new Annotation[] {});
	result = empty.findAnnotationPropertyValues(TEST_NAMESPACE, TEST_PROPNAME1);
	assertEquals(0, result.length);
}
 
Example 16
Source File: TestOrLaterOperator.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for {@link org.spdx.rdfparser.license.OrLaterOperator#setLicense(org.spdx.rdfparser.license.SimpleLicensingInfo)}.
 * @throws InvalidSPDXAnalysisException 
 */
@Test
public void testSetLicense() throws InvalidSPDXAnalysisException {
	OrLaterOperator olo1 = new OrLaterOperator(license1);
	model = ModelFactory.createDefaultModel();
	olo1.createResource(modelContainer);
	ExtractedLicenseInfo lic1 = (ExtractedLicenseInfo)olo1.getLicense();
	assertEquals(LICENSE_ID1, lic1.getLicenseId());
	assertEquals(LICENSE_TEXT1, lic1.getExtractedText());
	olo1.setLicense(license2);
	lic1 = (ExtractedLicenseInfo)olo1.getLicense();
	assertEquals(LICENSE_ID2, lic1.getLicenseId());
	assertEquals(LICENSE_TEXT2, lic1.getExtractedText());
}
 
Example 17
Source File: TestSpdxConstantElement.java    From tools with Apache License 2.0 4 votes vote down vote up
/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
	model = ModelFactory.createDefaultModel();
	modelContainer = new ModelContainerForTest(model, "http://testnamespace.com");
}
 
Example 18
Source File: TestSpdxListedLicense.java    From tools with Apache License 2.0 4 votes vote down vote up
@Test
public void testSetFsfLibre() throws InvalidSPDXAnalysisException {
	model = ModelFactory.createDefaultModel();
	String name = "name";
	String id = "AFL-3.0";
	String text = "text";
	String[] sourceUrls = new String[] {"source url1", "source url2"};
	String notes = "notes";
	String standardLicenseHeader = "Standard license header";
	String template = "template";
	String licenseHtml = "<html>html</html>";
	String deprecatedVersion = "3.2";
	SpdxListedLicense stdl = new SpdxListedLicense(name, id, text,
			sourceUrls, notes, standardLicenseHeader, template, false, false, licenseHtml, false, null);
	assertFalse(stdl.isFsfLibre());
	stdl.setFsfLibre(true);
	assertTrue(stdl.isFsfLibre());
	Resource licResource = stdl.createResource(modelContainer);
	SpdxListedLicense compLic = new SpdxListedLicense(modelContainer, licResource.asNode());
	assertTrue(stdl.isFsfLibre());
	compLic.setFsfLibre(false);
	assertFalse(compLic.isFsfLibre());
	SpdxListedLicense compLic2 = new SpdxListedLicense(modelContainer, licResource.asNode());
	assertFalse(compLic2.isFsfLibre());
	List<String> verify = stdl.verify();
	assertEquals(0, verify.size());
	verify = compLic.verify();
	assertEquals(0, verify.size());
	
	// Test for null value
	SpdxListedLicense stdl2 = new SpdxListedLicense(name, id, text,
			sourceUrls, notes, standardLicenseHeader, template, false, null, licenseHtml, true, deprecatedVersion);
	assertTrue(stdl2.getFsfLibre() == null);
	assertFalse(stdl2.isFsfLibre());
	assertFalse(stdl2.isNotFsfLibre());
	Resource licResource2 = stdl2.createResource(modelContainer);
	SpdxListedLicense compLic3 = new SpdxListedLicense(modelContainer, licResource2.asNode());
	assertTrue(compLic3.getFsfLibre() == null);
	assertFalse(compLic3.isFsfLibre());
	assertFalse(compLic3.isNotFsfLibre());
	compLic3.setFsfLibre(false);
	assertFalse(compLic3.getFsfLibre() == null);
	assertFalse(compLic3.isFsfLibre());
	assertTrue(compLic3.isNotFsfLibre());
	SpdxListedLicense compLic4 = new SpdxListedLicense(modelContainer, licResource2.asNode());
	assertFalse(compLic4.getFsfLibre() == null);
	assertFalse(compLic4.isFsfLibre());		
	assertTrue(compLic4.isNotFsfLibre());
}
 
Example 19
Source File: TestSpdxFile.java    From tools with Apache License 2.0 4 votes vote down vote up
/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
	NON_STD_LICENSES = new ExtractedLicenseInfo[NONSTD_IDS.length];
	for (int i = 0; i < NONSTD_IDS.length; i++) {
		NON_STD_LICENSES[i] = new ExtractedLicenseInfo(NONSTD_IDS[i], NONSTD_TEXTS[i]);
	}
	
	STANDARD_LICENSES = new SpdxListedLicense[STD_IDS.length];
	for (int i = 0; i < STD_IDS.length; i++) {
		STANDARD_LICENSES[i] = new SpdxListedLicense("Name "+String.valueOf(i), 
				STD_IDS[i], STD_TEXTS[i], new String[] {"URL "+String.valueOf(i)}, "Notes "+String.valueOf(i), 
				"LicHeader "+String.valueOf(i), "Template "+String.valueOf(i), true);
	}
	
	DISJUNCTIVE_LICENSES = new DisjunctiveLicenseSet[3];
	CONJUNCTIVE_LICENSES = new ConjunctiveLicenseSet[2];
	
	DISJUNCTIVE_LICENSES[0] = new DisjunctiveLicenseSet(new AnyLicenseInfo[] {
			NON_STD_LICENSES[0], NON_STD_LICENSES[1], STANDARD_LICENSES[1]
	});
	CONJUNCTIVE_LICENSES[0] = new ConjunctiveLicenseSet(new AnyLicenseInfo[] {
			STANDARD_LICENSES[0], NON_STD_LICENSES[0], STANDARD_LICENSES[1]
	});
	CONJUNCTIVE_LICENSES[1] = new ConjunctiveLicenseSet(new AnyLicenseInfo[] {
			DISJUNCTIVE_LICENSES[0], NON_STD_LICENSES[2]
	});
	DISJUNCTIVE_LICENSES[1] = new DisjunctiveLicenseSet(new AnyLicenseInfo[] {
			CONJUNCTIVE_LICENSES[1], NON_STD_LICENSES[0], STANDARD_LICENSES[0]
	});
	DISJUNCTIVE_LICENSES[2] = new DisjunctiveLicenseSet(new AnyLicenseInfo[] {
			DISJUNCTIVE_LICENSES[1], CONJUNCTIVE_LICENSES[0], STANDARD_LICENSES[2]
	});
	COMPLEX_LICENSE = new ConjunctiveLicenseSet(new AnyLicenseInfo[] {
			DISJUNCTIVE_LICENSES[2], NON_STD_LICENSES[2], CONJUNCTIVE_LICENSES[1]
	});
	model = ModelFactory.createDefaultModel();
	modelContainer = new ModelContainerForTest(model, "http://testnamespace.com");
	NON_STD_LICENSES_RESOURCES = new Resource[NON_STD_LICENSES.length];
	for (int i = 0; i < NON_STD_LICENSES.length; i++) {
		NON_STD_LICENSES_RESOURCES[i] = NON_STD_LICENSES[i].createResource(modelContainer);
	}
	STANDARD_LICENSES_RESOURCES = new Resource[STANDARD_LICENSES.length];
	for (int i = 0; i < STANDARD_LICENSES.length; i++) {
		STANDARD_LICENSES_RESOURCES[i] = STANDARD_LICENSES[i].createResource(modelContainer);
	}
	CONJUNCTIVE_LICENSES_RESOURCES = new Resource[CONJUNCTIVE_LICENSES.length];
	for (int i = 0; i < CONJUNCTIVE_LICENSES.length; i++) {
		CONJUNCTIVE_LICENSES_RESOURCES[i] = CONJUNCTIVE_LICENSES[i].createResource(modelContainer);
	}
	DISJUNCTIVE_LICENSES_RESOURCES = new Resource[DISJUNCTIVE_LICENSES.length];
	for (int i = 0; i < DISJUNCTIVE_LICENSES.length; i++) {
		DISJUNCTIVE_LICENSES_RESOURCES[i] = DISJUNCTIVE_LICENSES[i].createResource(modelContainer);
	}
	COMPLEX_LICENSE_RESOURCE = COMPLEX_LICENSE.createResource(modelContainer);
}
 
Example 20
Source File: TestSPDXDocument.java    From tools with Apache License 2.0 4 votes vote down vote up
@Test
public void testSetOriginator() throws InvalidSPDXAnalysisException {
	Model model = ModelFactory.createDefaultModel();
	SPDXDocument doc = new SPDXDocument(model);
	String testDocUri = "https://olex.openlogic.com/spdxdoc/package_versions/download/4832?path=openlogic/zlib/1.2.3/zlib-1.2.3-all-src.zip&amp;package_version_id=1082";
	doc.createSpdxAnalysis(testDocUri);
	String testPkgUri = "https://olex.openlogic.com/package_versions/download/4832?path=openlogic/zlib/1.2.3/zlib-1.2.3-all-src.zip&amp;uniquepackagename";
	doc.createSpdxPackage(testPkgUri);
	// add the required fields		
	SPDXPackage pkg = doc.getSpdxPackage();
	pkg.setConcludedLicenses(new SpdxNoneLicense());
	pkg.setDeclaredCopyright("Copyright");
	pkg.setDeclaredLicense(new SpdxNoAssertionLicense());
	pkg.setDeclaredName("Name");
	pkg.setDescription("Description");
	pkg.setDownloadUrl("None");
	pkg.setFileName("a/b/filename.tar.gz");
	SPDXFile testFile = new SPDXFile("filename", "BINARY", "0123456789abcdef0123456789abcdef01234567",
			new SpdxNoneLicense(), new AnyLicenseInfo[] {new SpdxNoneLicense()}, "license comment",
			"file copyright", new DOAPProject[0]);
	List<String> verify = testFile.verify();
	assertEquals(0, verify.size());
	pkg.setFiles(new SPDXFile[]{testFile});
	pkg.setLicenseInfoFromFiles(new AnyLicenseInfo[] {new SpdxNoneLicense()});
	pkg.setSha1("0123456789abcdef0123456789abcdef01234567");
	pkg.setShortDescription("Short description");
	pkg.setSourceInfo("Source info");
	String[] skippedFiles = new String[] {"skipped1", "skipped2"};
	pkg.setVerificationCode(
			new SpdxPackageVerificationCode("0123456789abcdef0123456789abcdef01234567",
					skippedFiles));
	
	// person
	String personString = "Person: somone";
	pkg.setOriginator(personString);
	verify = pkg.verify();
	assertEquals(0, verify.size());
	assertEquals(personString, pkg.getOriginator());
	// organization
	String organizationString = "Organization: org";
	pkg.setOriginator(organizationString);
	verify = pkg.verify();
	assertEquals(0, verify.size());
	assertEquals(organizationString, pkg.getOriginator());
	// NOASSERTION
	pkg.setOriginator(SpdxRdfConstants.NOASSERTION_VALUE);
	verify = pkg.verify();
	assertEquals(0, verify.size());
	assertEquals(SpdxRdfConstants.NOASSERTION_VALUE, pkg.getOriginator());
	// invalid
	String invalidString = "NotAPersonOrOrganization";
	try {
		pkg.setOriginator(invalidString);
		fail("Should not have been able to set this as an originator string");
	} catch (InvalidSPDXAnalysisException e) {
		// ignore
	}
}