Search in sources :

Example 6 with DirectoryManager

use of com.synopsys.integration.detect.workflow.file.DirectoryManager in project synopsys-detect by blackducksoftware.

the class RapidModeGenerateJsonOperationTest method test.

@Test
void test(@TempDir Path tempPath) throws IOException, DetectUserFriendlyException {
    Gson gson = Mockito.mock(Gson.class);
    File tempDir = tempPath.toFile();
    File scanDir = new File(tempDir, "scan");
    DirectoryOptions directoryOptions = new DirectoryOptions(null, null, null, scanDir.toPath(), null, null);
    DetectRunId detectRunId = new DetectRunId("testId");
    DirectoryManager directoryManager = new DirectoryManager(directoryOptions, detectRunId);
    RapidModeGenerateJsonOperation op = new RapidModeGenerateJsonOperation(gson, directoryManager);
    NameVersion projectNameVersion = new NameVersion("testName", "testVersion");
    List<DeveloperScanComponentResultView> results = new LinkedList<>();
    DeveloperScanComponentResultView resultView = Mockito.mock(DeveloperScanComponentResultView.class);
    results.add(resultView);
    String mockedResultsJsonString = "mocked json string for results";
    Mockito.when(gson.toJson(results)).thenReturn(mockedResultsJsonString);
    File generatedFile = op.generateJsonFile(projectNameVersion, results);
    String expectedFilename = String.format("%s_%s_BlackDuck_DeveloperMode_Result.json", projectNameVersion.getName(), projectNameVersion.getVersion());
    String expectedPath = new File(scanDir, expectedFilename).getAbsolutePath();
    assertEquals(expectedPath, generatedFile.getAbsolutePath());
    String generatedString = FileUtils.readFileToString(generatedFile);
    assertEquals(mockedResultsJsonString, generatedString);
}
Also used : DeveloperScanComponentResultView(com.synopsys.integration.blackduck.api.manual.view.DeveloperScanComponentResultView) DirectoryOptions(com.synopsys.integration.detect.workflow.file.DirectoryOptions) DetectRunId(com.synopsys.integration.detect.workflow.DetectRunId) NameVersion(com.synopsys.integration.util.NameVersion) DirectoryManager(com.synopsys.integration.detect.workflow.file.DirectoryManager) Gson(com.google.gson.Gson) File(java.io.File) LinkedList(java.util.LinkedList) Test(org.junit.jupiter.api.Test)

Example 7 with DirectoryManager

use of com.synopsys.integration.detect.workflow.file.DirectoryManager in project synopsys-detect by blackducksoftware.

the class BdioCodeLocationCreatorTest method testCreateFromDetectCodeLocations.

// TODO: This test seems suspiciously long and like it might not be testing much. -jp
@Test
public void testCreateFromDetectCodeLocations() throws IOException, DetectUserFriendlyException {
    File sourceDir = new File("src/test/resource");
    CodeLocationNameManager codeLocationNameManager = Mockito.mock(CodeLocationNameManager.class);
    DirectoryManager directoryManager = Mockito.mock(DirectoryManager.class);
    Mockito.when(directoryManager.getSourceDirectory()).thenReturn(sourceDir);
    EventSystem eventSystem = Mockito.mock(EventSystem.class);
    CreateBdioCodeLocationsFromDetectCodeLocationsOperation creator = new CreateBdioCodeLocationsFromDetectCodeLocationsOperation(codeLocationNameManager, directoryManager);
    NameVersion projectNameVersion = new NameVersion("testName", "testVersion");
    DependencyGraph dependencyGraph = Mockito.mock(DependencyGraph.class);
    Set<Dependency> dependencies = new HashSet<>();
    Dependency dependency = Mockito.mock(Dependency.class);
    dependencies.add(dependency);
    Mockito.when(dependencyGraph.getRootDependencies()).thenReturn(dependencies);
    ExternalId externalId = new ExternalId(Forge.MAVEN);
    externalId.setName("testExternalIdName");
    externalId.setVersion("testExternalIdVersion");
    externalId.setArchitecture("testExternalIdArch");
    DetectCodeLocation detectCodeLocation = DetectCodeLocation.forCreator(dependencyGraph, sourceDir, externalId, "testCreator");
    List<DetectCodeLocation> detectCodeLocations = new ArrayList<>();
    detectCodeLocations.add(detectCodeLocation);
    Mockito.when(codeLocationNameManager.createCodeLocationName(detectCodeLocation, sourceDir, projectNameVersion.getName(), projectNameVersion.getVersion(), "", "")).thenReturn("testCodeLocationName");
    BdioCodeLocationResult result = creator.transformDetectCodeLocations(detectCodeLocations, "", "", projectNameVersion);
    assertEquals("testCodeLocationName", result.getBdioCodeLocations().get(0).getCodeLocationName());
    File resultDir = result.getBdioCodeLocations().get(0).getDetectCodeLocation().getSourcePath();
    assertTrue(resultDir.getCanonicalPath().contains("test"));
    assertTrue(resultDir.getCanonicalPath().contains("resource"));
}
Also used : NameVersion(com.synopsys.integration.util.NameVersion) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) DirectoryManager(com.synopsys.integration.detect.workflow.file.DirectoryManager) ArrayList(java.util.ArrayList) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) EventSystem(com.synopsys.integration.detect.workflow.event.EventSystem) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

DirectoryManager (com.synopsys.integration.detect.workflow.file.DirectoryManager)7 File (java.io.File)6 Test (org.junit.jupiter.api.Test)4 Gson (com.google.gson.Gson)2 SimpleFileFinder (com.synopsys.integration.common.util.finder.SimpleFileFinder)2 PropertyConfiguration (com.synopsys.integration.configuration.config.PropertyConfiguration)2 SimplePathResolver (com.synopsys.integration.configuration.property.types.path.SimplePathResolver)2 DetectConfigurationFactory (com.synopsys.integration.detect.configuration.DetectConfigurationFactory)2 DetectPropertyConfiguration (com.synopsys.integration.detect.configuration.DetectPropertyConfiguration)2 InstalledToolLocator (com.synopsys.integration.detect.tool.cache.InstalledToolLocator)2 DetectDirectoryFileFilter (com.synopsys.integration.detect.util.finder.DetectDirectoryFileFilter)2 DirectoryOptions (com.synopsys.integration.detect.workflow.file.DirectoryOptions)2 NameVersion (com.synopsys.integration.util.NameVersion)2 ArrayList (java.util.ArrayList)2 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)1 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)1 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)1 DeveloperScanComponentResultView (com.synopsys.integration.blackduck.api.manual.view.DeveloperScanComponentResultView)1 PathResolver (com.synopsys.integration.configuration.property.types.path.PathResolver)1 MapPropertySource (com.synopsys.integration.configuration.source.MapPropertySource)1