use of com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmYamlTransformer in project synopsys-detect by blackducksoftware.
the class PnpmYamlTransformerTest method testParseFileDependencies.
@Test
public void testParseFileDependencies() throws IntegrationException {
PnpmLockYaml pnpmLockYaml = createPnpmLockYaml();
PnpmYamlTransformer transformer = createTransformer(PnpmDependencyType.DEV, PnpmDependencyType.OPTIONAL);
DependencyGraph dependencyGraph = transformer.generateCodeLocation(pnpmLockYamlFile, pnpmLockYaml, projectNameVersion, linkedPackageResolver).getDependencyGraph();
NameVersionGraphAssert graphAssert = new NameVersionGraphAssert(Forge.NPMJS, dependencyGraph);
graphAssert.hasRootSize(2);
graphAssert.hasDependency("fileDep", "1.0.0");
}
use of com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmYamlTransformer in project synopsys-detect by blackducksoftware.
the class PnpmLockYamlParserTest method testParse.
@Test
public void testParse() throws IOException, IntegrationException {
File pnpmLockYaml = FunctionalTestFiles.asFile("/pnpm/pnpm-lock.yaml");
EnumListFilter<PnpmDependencyType> dependencyTypeFilter = EnumListFilter.excludeNone();
PnpmLockYamlParser pnpmLockYamlParser = new PnpmLockYamlParser(new PnpmYamlTransformer(dependencyTypeFilter));
PnpmLinkedPackageResolver pnpmLinkedPackageResolver = new PnpmLinkedPackageResolver(FunctionalTestFiles.asFile("/pnpm"), new PackageJsonFiles(new PackageJsonReader(new Gson())));
List<CodeLocation> codeLocations = pnpmLockYamlParser.parse(pnpmLockYaml, new NameVersion("project", "version"), pnpmLinkedPackageResolver);
Assertions.assertEquals(2, codeLocations.size());
// Did we correctly identify root project package in "importers"?
Assertions.assertTrue(codeLocations.stream().map(CodeLocation::getExternalId).filter(Optional::isPresent).map(Optional::get).anyMatch(externalId -> externalId.getName().equals("project") && externalId.getVersion().equals("version")));
// Do all code locations have a source path?
Assertions.assertAll(codeLocations.stream().map(codeLocation -> () -> Assertions.assertTrue(codeLocation.getSourcePath().isPresent(), String.format("Expected source path to be present for all code locations. But code location with id %s does not have one set.", codeLocation.getExternalId().map(ExternalId::createExternalId).orElse("N/A")))));
// Did we generate a unique source path for each code location?
Map<String, List<File>> collect = codeLocations.stream().map(CodeLocation::getSourcePath).filter(Optional::isPresent).map(Optional::get).collect(Collectors.groupingBy(File::getAbsolutePath));
Assertions.assertAll(collect.entrySet().stream().map(codeLocationGrouping -> () -> {
int numberOfCodeLocations = codeLocationGrouping.getValue().size();
Assertions.assertEquals(1, numberOfCodeLocations, String.format("Expected unique code locations paths. But found %d with that same path of %s", numberOfCodeLocations, codeLocationGrouping.getKey()));
}));
}
use of com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmYamlTransformer in project synopsys-detect by blackducksoftware.
the class PnpmYamlTransformerTest method testExcludeDevDependencies.
@Test
public void testExcludeDevDependencies() throws IntegrationException {
PnpmYamlTransformer transformer = createTransformer(PnpmDependencyType.DEV);
PnpmLockYaml pnpmLockYaml = createPnpmLockYaml();
DependencyGraph dependencyGraph = transformer.generateCodeLocation(pnpmLockYamlFile, pnpmLockYaml, projectNameVersion, linkedPackageResolver).getDependencyGraph();
NameVersionGraphAssert graphAssert = new NameVersionGraphAssert(Forge.NPMJS, dependencyGraph);
graphAssert.hasRootSize(3);
graphAssert.hasNoDependency("devDep", "2.0.0");
}
use of com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmYamlTransformer in project synopsys-detect by blackducksoftware.
the class PnpmYamlTransformerTest method testExcludeDependencies.
@Test
public void testExcludeDependencies() throws IntegrationException {
PnpmLockYaml pnpmLockYaml = createPnpmLockYaml();
PnpmYamlTransformer transformer = createTransformer(PnpmDependencyType.APP);
DependencyGraph dependencyGraph = transformer.generateCodeLocation(pnpmLockYamlFile, pnpmLockYaml, projectNameVersion, linkedPackageResolver).getDependencyGraph();
NameVersionGraphAssert graphAssert = new NameVersionGraphAssert(Forge.NPMJS, dependencyGraph);
graphAssert.hasRootSize(2);
}
use of com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmYamlTransformer in project synopsys-detect by blackducksoftware.
the class PnpmYamlTransformerTest method testThrowExceptionOnNullPackagesSection.
@Test
public void testThrowExceptionOnNullPackagesSection() {
PnpmLockYaml pnpmLockYaml = createPnpmLockYaml();
PnpmYamlTransformer transformer = createTransformer();
pnpmLockYaml.packages = null;
assertThrows(IntegrationException.class, () -> transformer.generateCodeLocation(pnpmLockYamlFile, pnpmLockYaml, projectNameVersion, linkedPackageResolver));
}
Aggregations