use of com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryId in project synopsys-detect by blackducksoftware.
the class YarnLockHeaderSectionParserTest method handlesSymbolInName.
@Test
void handlesSymbolInName() {
String line = "@example";
List<String> lines = Arrays.asList(line);
Assertions.assertTrue(yarnLockParser.applies(line));
YarnLockEntryBuilder builder = new YarnLockEntryBuilder();
yarnLockParser.parseSection(builder, lines, 0);
// Complete the builder requirements and build the entry
builder.setVersion("testVersion");
YarnLockEntry entry = builder.build();
List<YarnLockEntryId> ids = entry.getIds();
Assertions.assertEquals(1, ids.size());
Assertions.assertEquals("@example", ids.get(0).getName());
Assertions.assertEquals("", ids.get(0).getVersion());
}
use of com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryId in project synopsys-detect by blackducksoftware.
the class YarnLockKeyValuePairSectionParserTest method doTest.
private void doTest(String line, String versionValue) {
Assertions.assertTrue(yarnLockKeyValuePairElementParser.applies(line));
YarnLockEntryBuilder builder = new YarnLockEntryBuilder();
builder.addId(new YarnLockEntryId("idname", "idversion"));
List<String> lines = Arrays.asList(line);
yarnLockKeyValuePairElementParser.parseSection(builder, lines, 0);
YarnLockEntry entry = builder.build();
Assertions.assertEquals(versionValue, entry.getVersion());
}
use of com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryId in project synopsys-detect by blackducksoftware.
the class YarnTransformerTest method doesntThrowOnMissingExternalId.
@Test
void doesntThrowOnMissingExternalId() throws MissingExternalIdException {
// Ensure components not defined in the graph doesn't cause an exception to be thrown. See IDETECT-1974.
PackageJson rawPackageJson = new PackageJson();
rawPackageJson.dependencies = new HashMap<>();
rawPackageJson.dependencies.put("foo", "fooFuzzyVersion-1.0");
NullSafePackageJson packageJson = new NullSafePackageJson(rawPackageJson);
List<YarnLockEntryId> validYarnLockEntryIds = Collections.singletonList(new YarnLockEntryId("foo", "fooFuzzyVersion-1.0"));
List<YarnLockDependency> validYarnLockDependencies = Collections.singletonList(new YarnLockDependency("yarn", "^1.22.4", false));
List<YarnLockEntry> yarnLockEntries = Collections.singletonList(new YarnLockEntry(false, validYarnLockEntryIds, "1.0", validYarnLockDependencies));
YarnLock yarnLock = new YarnLock(null, true, yarnLockEntries);
YarnLockResult yarnLockResult = new YarnLockResult(packageJson, YarnWorkspaces.EMPTY, yarnLock);
// This should not throw an exception.
List<CodeLocation> codeLocations = createTransformer().generateCodeLocations(yarnLockResult, new ArrayList<>(0), ExcludedIncludedWildcardFilter.EMPTY);
// Sanity check.
assertEquals(1, codeLocations.size());
CodeLocation codeLocation = codeLocations.get(0);
DependencyGraph dependencyGraph = codeLocation.getDependencyGraph();
Assertions.assertNotNull(dependencyGraph, "The dependency graph should not be null.");
assertEquals(1, dependencyGraph.getRootDependencies().size(), "Only 'foo:1.0' should appear in the graph.");
ExternalId fooExternalId = externalIdFactory.createNameVersionExternalId(Forge.NPMJS, "foo", "1.0");
assertTrue(dependencyGraph.hasDependency(fooExternalId), "Missing the only expected dependency.");
}
use of com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryId in project synopsys-detect by blackducksoftware.
the class YarnTransformerTest method addWorkspaceToYarnLockEntries.
private void addWorkspaceToYarnLockEntries(List<YarnLockEntry> yarnLockEntries, NameVersion workspace, String workspaceDepName) {
List<YarnLockDependency> dependencyRefsToWkspDeps = Collections.singletonList(new YarnLockDependency(workspaceDepName, workspace.getVersion(), false));
List<YarnLockEntryId> yarnLockEntryIdsWkspEntryIds = Arrays.asList(new YarnLockEntryId(workspace.getName(), workspace.getVersion()), new YarnLockEntryId(workspace.getName(), "workspace:packages/" + workspace.getName()));
yarnLockEntries.add(new YarnLockEntry(false, yarnLockEntryIdsWkspEntryIds, workspace.getVersion(), dependencyRefsToWkspDeps));
}
use of com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryId in project synopsys-detect by blackducksoftware.
the class YarnTransformerTest method addDependencyOfWorkspaceToYarnLockEntries.
private void addDependencyOfWorkspaceToYarnLockEntries(List<YarnLockEntry> yarnLockEntries, NameVersion workspace, String workspaceDepName) {
List<YarnLockEntryId> wkspDepIds = Collections.singletonList(new YarnLockEntryId(workspaceDepName, workspace.getVersion()));
yarnLockEntries.add(new YarnLockEntry(false, wkspDepIds, workspace.getVersion(), new LinkedList<>()));
}
Aggregations