Search in sources :

Example 6 with NullSafePackageJson

use of com.synopsys.integration.detectable.detectables.yarn.packagejson.NullSafePackageJson 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.");
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) NullSafePackageJson(com.synopsys.integration.detectable.detectables.yarn.packagejson.NullSafePackageJson) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) YarnLock(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock) YarnLockResult(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockResult) YarnLockEntryId(com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryId) YarnLockEntry(com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntry) YarnLockDependency(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency) NullSafePackageJson(com.synopsys.integration.detectable.detectables.yarn.packagejson.NullSafePackageJson) WorkspacePackageJson(com.synopsys.integration.detectable.detectables.yarn.packagejson.WorkspacePackageJson) PackageJson(com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Aggregations

NullSafePackageJson (com.synopsys.integration.detectable.detectables.yarn.packagejson.NullSafePackageJson)6 PackageJson (com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson)3 WorkspacePackageJson (com.synopsys.integration.detectable.detectables.yarn.packagejson.WorkspacePackageJson)3 YarnLock (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock)3 YarnLockDependency (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency)2 YarnLockResult (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockResult)2 YarnLockEntry (com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntry)2 YarnLockEntryId (com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryId)2 YarnWorkspace (com.synopsys.integration.detectable.detectables.yarn.workspace.YarnWorkspace)2 YarnWorkspaces (com.synopsys.integration.detectable.detectables.yarn.workspace.YarnWorkspaces)2 IOException (java.io.IOException)2 Test (org.junit.jupiter.api.Test)2 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)1 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)1 UnitTest (com.synopsys.integration.detectable.annotations.UnitTest)1 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)1 Extraction (com.synopsys.integration.detectable.extraction.Extraction)1 ExcludedIncludedWildcardFilter (com.synopsys.integration.util.ExcludedIncludedWildcardFilter)1 NameVersion (com.synopsys.integration.util.NameVersion)1 File (java.io.File)1