<commit_before>package com.yevster.spdxtra;

import static org.junit.Assert.assertEquals;

import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.jena.ext.com.google.common.collect.Sets;
import org.apache.jena.query.Dataset;
import org.apache.jena.query.DatasetFactory;
import org.apache.jena.rdf.model.RDFNode;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.Statement;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import com.yevster.spdxtra.NoneNoAssertionOrValue.AbsentValue;
import com.yevster.spdxtra.model.Checksum;
import com.yevster.spdxtra.model.Creator;
import com.yevster.spdxtra.model.FileType;
import com.yevster.spdxtra.model.SpdxFile;
import com.yevster.spdxtra.model.SpdxPackage;
import com.yevster.spdxtra.model.write.License;
import com.yevster.spdxtra.util.MiscUtils;

public class TestFileOperations {
	private static final String baseUrl = "http://www.example.org/baseUrl";
	private static final String packageSpdxId = "SPDXRef-PKG";
	private static final String packageUri = baseUrl + "#" + packageSpdxId;

	private SpdxPackage pkg;
	private Dataset dataset;

	@Before
	public void setUp() {
		dataset = DatasetFactory.createTxnMem();
		final String docSpdxId = "SPDXRef-Document";
		Write.applyUpdatesInOneTransaction(dataset,
				Write.New.document(baseUrl, docSpdxId, "My Document", Creator.person("<NAME>", Optional.empty())),
				Write.Document.addDescribedPackage(baseUrl, docSpdxId, packageSpdxId, "The packagy package"));
		reloadPackage();
	}

	public void reloadPackage() {
		pkg = new SpdxPackage(Read.lookupResourceByUri(dataset, packageUri).get());
	}

	@Test
	public void testAddFileToPackage() {
		assertEquals("Newly-created package should have no files", 0, pkg.getFiles().count());
		final String fileName = "./foo/bar/whatevs.txt";
		final String expectedFileUrl = baseUrl + "#myFile";
		final String mockSha1 = "abc135875aeffffff";
		final String mockMd5 = DigestUtils.md5Hex("My sum");
		final String mockSha256 = DigestUtils.sha256Hex("My sum");
		final String extractedLicense = "This is the extracting license. Once this was in a file. Now it is here.";
		final String copyrightText = "Copyright (C) 2016 Aweomsness Awesome, Inc.";
		final String comment = "No comment. Carry on. Wait, this is a comment. Curses!";
		final String artifactOfHomepage = "http://example.org/epic/fail";
		final String artifactOfName = "Epic Failure 1,9";
		final String licenseName = "El nombre";

		Write.applyUpdatesInOneTransaction(dataset, Write.Package.addFile(baseUrl, packageSpdxId, "myFile", fileName),
				Write.File.fileTypes(expectedFileUrl, FileType.OTHER, FileType.APPLICATION),
				Write.File.concludedLicense(expectedFileUrl, License.NONE),
				Write.File.checksums(expectedFileUrl, mockSha1, Checksum.md5(mockMd5)),
				Write.File.licenseInfoInFile(expectedFileUrl, License.extracted(extractedLicense, licenseName, baseUrl, "LicenseRef-el")),
				Write.File.artifactOf(expectedFileUrl, artifactOfName, null));
		reloadPackage();
		List<SpdxFile> allFilesInPackage = pkg.getFiles().collect(Collectors.toList());
		assertEquals("Expected to one file in package after adding one file.", 1, allFilesInPackage.size());
		SpdxFile file = allFilesInPackage.get(0);
<commit_msg>Fixed the cardinality of the license in file writing (test fix)<commit_after>package com.yevster.spdxtra;

import static org.junit.Assert.assertEquals;

import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.jena.ext.com.google.common.collect.Sets;
import org.apache.jena.query.Dataset;
import org.apache.jena.query.DatasetFactory;
import org.apache.jena.rdf.model.RDFNode;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.Statement;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import com.yevster.spdxtra.NoneNoAssertionOrValue.AbsentValue;
import com.yevster.spdxtra.model.Checksum;
import com.yevster.spdxtra.model.Creator;
import com.yevster.spdxtra.model.FileType;
import com.yevster.spdxtra.model.SpdxFile;
import com.yevster.spdxtra.model.SpdxPackage;
import com.yevster.spdxtra.model.write.License;
import com.yevster.spdxtra.util.MiscUtils;

public class TestFileOperations {
	private static final String baseUrl = "http://www.example.org/baseUrl";
	private static final String packageSpdxId = "SPDXRef-PKG";
	private static final String packageUri = baseUrl + "#" + packageSpdxId;

	private SpdxPackage pkg;
	private Dataset dataset;

	@Before
	public void setUp() {
		dataset = DatasetFactory.createTxnMem();
		final String docSpdxId = "SPDXRef-Document";
		Write.applyUpdatesInOneTransaction(dataset,
				Write.New.document(baseUrl, docSpdxId, "My Document", Creator.person("<NAME>", Optional.empty())),
				Write.Document.addDescribedPackage(baseUrl, docSpdxId, packageSpdxId, "The packagy package"));
		reloadPackage();
	}

	public void reloadPackage() {
		pkg = new SpdxPackage(Read.lookupResourceByUri(dataset, packageUri).get());
	}

	@Test
	public void testAddFileToPackage() {
		assertEquals("Newly-created package should have no files", 0, pkg.getFiles().count());
		final String fileName = "./foo/bar/whatevs.txt";
		final String expectedFileUrl = baseUrl + "#myFile";
		final String mockSha1 = "abc135875aeffffff";
		final String mockMd5 = DigestUtils.md5Hex("My sum");
		final String mockSha256 = DigestUtils.sha256Hex("My sum");
		final String extractedLicense = "This is the extracting license. Once this was in a file. Now it is here.";
		final String copyrightText = "Copyright (C) 2016 Aweomsness Awesome, Inc.";
		final String comment = "No comment. Carry on. Wait, this is a comment. Curses!";
		final String artifactOfHomepage = "http://example.org/epic/fail";
		final String artifactOfName = "Epic Failure 1,9";
		final String licenseName = "El nombre";

		Write.applyUpdatesInOneTransaction(dataset, Write.Package.addFile(baseUrl, packageSpdxId, "myFile", fileName),
				Write.File.fileTypes(expectedFileUrl, FileType.OTHER, FileType.APPLICATION),
				Write.File.concludedLicense(expectedFileUrl, License.NONE),
				Write.File.checksums(expectedFileUrl, mockSha1, Checksum.md5(mockMd5)),
				Write.File.addLicenseInfoInFile(expectedFileUrl, License.extracted(extractedLicense, licenseName, baseUrl, "LicenseRef-el")),
				Write.File.artifactOf(expectedFileUrl, artifactOfName, null));
		reloadPackage();
		List<SpdxFile> allFilesInPackage = pkg.getFiles().collect(Collectors.toList());
		assertEquals("Expected to one file in package after adding one file.", 1, allFilesInPackage.size());
		SpdxFile file = allFilesInPackage.get(0);

{'fraction_non_alphanumeric': 0.11638368886953998, 'fraction_numerical': 0.00783630822812364, 'mean_word_length': 5.58261700095511, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7147872', 'n_tokens_mistral': 2344, 'n_tokens_neox': 2210, 'n_words': 490}