Search in sources :

Example 1 with NpmDependencyTypeFilter

use of com.synopsys.integration.detectable.detectables.npm.cli.parse.NpmDependencyTypeFilter in project synopsys-detect by blackducksoftware.

the class NpmOutputParserTest method npmCliDependencyFinder.

@Test
public void npmCliDependencyFinder() {
    NpmCliParser parser = new NpmCliParser(new ExternalIdFactory(), EnumListFilter.excludeNone());
    String testIn = String.join(System.lineSeparator(), Arrays.asList("{", "   \"name\": \"node-js\",", "   \"version\": \"0.2.0\",", "   \"dependencies\": {", "       \"upper-case\": {", "       \"version\": \"1.1.3\",", "       \"from\": \"upper-case@latest\",", "       \"resolved\": \"https://registry.npmjs.org/upper-case/-/upper-case-1.1.3.tgz\"", "       },", "       \"xml2js\": {", "           \"version\": \"0.4.17\",", "           \"from\": \"xml2js@latest\",", "           \"resolved\": \"https://registry.npmjs.org/xml2js/-/xml2js-0.4.17.tgz\",", "            \"dependencies\": {", "               \"sax\": {", "                   \"version\": \"1.2.2\",", "                   \"from\": \"sax@>=0.6.0\",", "                   \"resolved\": \"https://registry.npmjs.org/sax/-/sax-1.2.2.tgz\"", "               },", "               \"xmlbuilder\": {", "                   \"version\": \"4.2.1\",", "                   \"from\": \"xmlbuilder@>=4.1.0 <5.0.0\",", "                   \"resolved\": \"https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-4.2.1.tgz\",", "                   \"dependencies\": {", "                       \"lodash\": {", "                           \"version\": \"4.17.4\",", "                           \"from\": \"lodash@>=4.0.0 <5.0.0\",", "                           \"resolved\": \"https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz\"", "                       }", "                   }", "               }", "           }", "       }", "   }", "}"));
    NpmDependencyTypeFilter npmDependencyTypeFilter = new NpmDependencyTypeFilter(Collections.emptySet(), Collections.emptySet(), true, true);
    PackageJson packageJson = new PackageJson();
    NpmPackagerResult result = parser.convertNpmJsonFileToCodeLocation(testIn, packageJson);
    Assertions.assertEquals("node-js", result.getProjectName());
    Assertions.assertEquals("0.2.0", result.getProjectVersion());
    NameVersionGraphAssert graphAssert = new NameVersionGraphAssert(Forge.NPMJS, result.getCodeLocation().getDependencyGraph());
    graphAssert.hasRootSize(2);
    graphAssert.hasRootDependency("xml2js", "0.4.17");
    graphAssert.hasRootDependency("upper-case", "1.1.3");
    graphAssert.hasParentChildRelationship("xml2js", "0.4.17", "xmlbuilder", "4.2.1");
    graphAssert.hasParentChildRelationship("xml2js", "0.4.17", "sax", "1.2.2");
    graphAssert.hasParentChildRelationship("xmlbuilder", "4.2.1", "lodash", "4.17.4");
}
Also used : ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) NpmDependencyTypeFilter(com.synopsys.integration.detectable.detectables.npm.cli.parse.NpmDependencyTypeFilter) NameVersionGraphAssert(com.synopsys.integration.detectable.util.graph.NameVersionGraphAssert) PackageJson(com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson) NpmPackagerResult(com.synopsys.integration.detectable.detectables.npm.lockfile.result.NpmPackagerResult) NpmCliParser(com.synopsys.integration.detectable.detectables.npm.cli.parse.NpmCliParser) Test(org.junit.jupiter.api.Test)

Example 2 with NpmDependencyTypeFilter

use of com.synopsys.integration.detectable.detectables.npm.cli.parse.NpmDependencyTypeFilter in project synopsys-detect by blackducksoftware.

the class NpmDependencyTypeFilterTest method includeDevTest.

@Test
void includeDevTest() {
    NpmDependencyTypeFilter filter = createFilter(true, false);
    assertTrue(filter.shouldInclude(NEITHER, true));
    assertTrue(filter.shouldInclude(NEITHER, false));
    assertTrue(filter.shouldInclude(DEV, true));
    assertTrue(filter.shouldInclude(DEV, false));
    assertFalse(filter.shouldInclude(PEER, true));
    assertTrue(filter.shouldInclude(PEER, false));
}
Also used : NpmDependencyTypeFilter(com.synopsys.integration.detectable.detectables.npm.cli.parse.NpmDependencyTypeFilter) Test(org.junit.jupiter.api.Test)

Example 3 with NpmDependencyTypeFilter

use of com.synopsys.integration.detectable.detectables.npm.cli.parse.NpmDependencyTypeFilter in project synopsys-detect by blackducksoftware.

the class NpmDependencyTypeFilterTest method includeNeitherTest.

@Test
void includeNeitherTest() {
    NpmDependencyTypeFilter filter = createFilter(false, false);
    assertTrue(filter.shouldInclude(NEITHER, true));
    assertTrue(filter.shouldInclude(NEITHER, false));
    assertTrue(filter.shouldInclude(DEV, false));
    assertFalse(filter.shouldInclude(DEV, true));
    assertTrue(filter.shouldInclude(PEER, false));
    assertFalse(filter.shouldInclude(PEER, true));
}
Also used : NpmDependencyTypeFilter(com.synopsys.integration.detectable.detectables.npm.cli.parse.NpmDependencyTypeFilter) Test(org.junit.jupiter.api.Test)

Example 4 with NpmDependencyTypeFilter

use of com.synopsys.integration.detectable.detectables.npm.cli.parse.NpmDependencyTypeFilter in project synopsys-detect by blackducksoftware.

the class NpmDependencyTypeFilterTest method includeBothTest.

@Test
void includeBothTest() {
    NpmDependencyTypeFilter filter = createFilter(true, true);
    assertTrue(filter.shouldInclude(NEITHER, true));
    assertTrue(filter.shouldInclude(NEITHER, false));
    assertTrue(filter.shouldInclude(DEV, true));
    assertTrue(filter.shouldInclude(DEV, false));
    assertTrue(filter.shouldInclude(PEER, true));
    assertTrue(filter.shouldInclude(PEER, false));
}
Also used : NpmDependencyTypeFilter(com.synopsys.integration.detectable.detectables.npm.cli.parse.NpmDependencyTypeFilter) Test(org.junit.jupiter.api.Test)

Example 5 with NpmDependencyTypeFilter

use of com.synopsys.integration.detectable.detectables.npm.cli.parse.NpmDependencyTypeFilter in project synopsys-detect by blackducksoftware.

the class NpmDependencyTypeFilterTest method includePeerTest.

@Test
void includePeerTest() {
    NpmDependencyTypeFilter filter = createFilter(false, true);
    assertTrue(filter.shouldInclude(NEITHER, true));
    assertTrue(filter.shouldInclude(NEITHER, false));
    assertFalse(filter.shouldInclude(DEV, true));
    assertTrue(filter.shouldInclude(DEV, false));
    assertTrue(filter.shouldInclude(PEER, true));
    assertTrue(filter.shouldInclude(PEER, false));
}
Also used : NpmDependencyTypeFilter(com.synopsys.integration.detectable.detectables.npm.cli.parse.NpmDependencyTypeFilter) Test(org.junit.jupiter.api.Test)

Aggregations

NpmDependencyTypeFilter (com.synopsys.integration.detectable.detectables.npm.cli.parse.NpmDependencyTypeFilter)5 Test (org.junit.jupiter.api.Test)5 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)1 NpmCliParser (com.synopsys.integration.detectable.detectables.npm.cli.parse.NpmCliParser)1 NpmPackagerResult (com.synopsys.integration.detectable.detectables.npm.lockfile.result.NpmPackagerResult)1 PackageJson (com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson)1 NameVersionGraphAssert (com.synopsys.integration.detectable.util.graph.NameVersionGraphAssert)1