Search in sources :

Example 36 with ExternalIdFactory

use of com.synopsys.integration.bdio.model.externalid.ExternalIdFactory in project hub-detect by blackducksoftware.

the class GoVendorExtractorTest method test.

@Test
public void test() {
    GoVendorExtractor extractor = new GoVendorExtractor(new Gson(), new ExternalIdFactory());
    Extraction extraction = extractor.extract(new File("src/test/resources/go"), new File("src/test/resources/go/vendor/vendor.json"));
    DependencyGraph graph = extraction.codeLocations.get(0).getDependencyGraph();
    assertEquals(2, graph.getRootDependencies().size());
    boolean foundErrorsPkg = false;
    boolean foundMathPkg = false;
    for (Dependency dep : graph.getRootDependencies()) {
        if ("github.com/pkg/errors".equals(dep.name)) {
            foundErrorsPkg = true;
            assertEquals("github.com/pkg/errors", dep.externalId.name);
            assertEquals("059132a15dd08d6704c67711dae0cf35ab991756", dep.externalId.version);
        }
        if ("github.com/pkg/math".equals(dep.name)) {
            foundMathPkg = true;
            assertEquals("github.com/pkg/math", dep.externalId.name);
            assertEquals("f2ed9e40e245cdeec72c4b642d27ed4553f90667", dep.externalId.version);
        }
    }
    assertTrue(foundErrorsPkg);
    assertTrue(foundMathPkg);
}
Also used : ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) Gson(com.google.gson.Gson) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) File(java.io.File) Test(org.junit.Test)

Example 37 with ExternalIdFactory

use of com.synopsys.integration.bdio.model.externalid.ExternalIdFactory in project hub-detect by blackducksoftware.

the class PackagistTest method packagistParserTest.

@Test
public void packagistParserTest() throws IOException {
    final DetectConfiguration detectConfiguration = Mockito.mock(DetectConfiguration.class);
    Mockito.when(detectConfiguration.getBooleanProperty(DetectProperty.DETECT_PACKAGIST_INCLUDE_DEV_DEPENDENCIES, PropertyAuthority.None)).thenReturn(true);
    final PackagistParser packagistParser = new PackagistParser(new ExternalIdFactory(), detectConfiguration);
    final String composerLockText = testUtil.getResourceAsUTF8String("/packagist/composer.lock");
    final String composerJsonText = testUtil.getResourceAsUTF8String("/packagist/composer.json");
    final PackagistParseResult result = packagistParser.getDependencyGraphFromProject("source", composerJsonText, composerLockText);
    Assert.assertEquals(result.projectName, "clue/graph-composer");
    Assert.assertEquals(result.projectVersion, "1.0.0");
    DependencyGraphResourceTestUtil.assertGraph("/packagist/PackagistTestDependencyNode_graph.json", result.codeLocation.getDependencyGraph());
}
Also used : DetectConfiguration(com.blackducksoftware.integration.hub.detect.configuration.DetectConfiguration) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) Test(org.junit.Test)

Example 38 with ExternalIdFactory

use of com.synopsys.integration.bdio.model.externalid.ExternalIdFactory in project hub-detect by blackducksoftware.

the class GemlockNodeParserTest method testParsingGemfileLock.

@Test
public void testParsingGemfileLock() {
    final String text = testUtils.getResourceAsUTF8String("/rubygems/Gemfile.lock");
    final List<String> gemfileLockContents = Arrays.asList(text.split("\n"));
    final GemlockParser gemlockNodeParser = new GemlockParser(new ExternalIdFactory());
    final DependencyGraph dependencyGraph = gemlockNodeParser.parseProjectDependencies(gemfileLockContents);
    DependencyGraphResourceTestUtil.assertGraph("/rubygems/expectedParser_graph.json", dependencyGraph);
}
Also used : ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Test(org.junit.Test)

Example 39 with ExternalIdFactory

use of com.synopsys.integration.bdio.model.externalid.ExternalIdFactory in project hub-detect by blackducksoftware.

the class GemlockNodeParserTest method testParsingSmallGemfileLock.

@Test
public void testParsingSmallGemfileLock() {
    final String text = testUtils.getResourceAsUTF8String("/rubygems/small_gemfile_lock");
    final List<String> gemfileLockContents = Arrays.asList(text.split("\n"));
    final GemlockParser gemlockNodeParser = new GemlockParser(new ExternalIdFactory());
    final DependencyGraph dependencyGraph = gemlockNodeParser.parseProjectDependencies(gemfileLockContents);
    DependencyGraphResourceTestUtil.assertGraph("/rubygems/expectedSmallParser_graph.json", dependencyGraph);
}
Also used : ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Test(org.junit.Test)

Example 40 with ExternalIdFactory

use of com.synopsys.integration.bdio.model.externalid.ExternalIdFactory in project hub-detect by blackducksoftware.

the class YarnListParserTest method testThatYarnListWithOnlyTopLevelDependenciesIsParsedCorrectly.

@Test
public void testThatYarnListWithOnlyTopLevelDependenciesIsParsedCorrectly() {
    final List<String> designedYarnLock = new ArrayList<>();
    designedYarnLock.add("esprima@5.5.2:");
    designedYarnLock.add("  version \"5.5.2\"");
    designedYarnLock.add("");
    designedYarnLock.add("extsprintf@5.5.2:");
    designedYarnLock.add("  version \"5.5.2\"");
    designedYarnLock.add("");
    final List<String> testLines = new ArrayList<>();
    testLines.add("├─ esprima@3.1.3");
    testLines.add("└─ extsprintf@1.3.0");
    final ExternalIdFactory externalIdFactory = new ExternalIdFactory();
    final YarnLockParser yarnLockParser = new YarnLockParser();
    final YarnListParser yarnListParser = new YarnListParser(externalIdFactory, yarnLockParser);
    final DependencyGraph dependencyGraph = yarnListParser.parseYarnList(designedYarnLock, testLines);
    final List<ExternalId> tempList = new ArrayList<>(dependencyGraph.getRootDependencyExternalIds());
    assertListContainsDependency("esprima", "3.1.3", tempList);
    assertListContainsDependency("extsprintf", "1.3.0", tempList);
}
Also used : ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ArrayList(java.util.ArrayList) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Test(org.junit.Test)

Aggregations

ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)46 Test (org.junit.Test)33 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)17 File (java.io.File)13 ArrayList (java.util.ArrayList)12 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)11 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)10 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)8 DetectFileFinder (com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder)7 Extraction (com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)5 ExtractionId (com.blackducksoftware.integration.hub.detect.detector.ExtractionId)4 TestUtil (com.blackducksoftware.integration.hub.detect.testutils.TestUtil)4 ExecutableOutput (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput)4 DependencyGraphResourceTestUtil (com.blackducksoftware.integration.hub.detect.testutils.DependencyGraphResourceTestUtil)3 ExecutableRunner (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner)3 DirectoryManager (com.blackducksoftware.integration.hub.detect.workflow.file.DirectoryManager)3 Gson (com.google.gson.Gson)3 GsonBuilder (com.google.gson.GsonBuilder)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3