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);
}
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"));
}
Aggregations