use of com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails in project synopsys-detect by blackducksoftware.
the class ApkPackageManagerTest method canParsePackages.
@Test
public void canParsePackages() throws ExecutableRunnerException, NotOwnedByAnyPkgException {
StringBuilder sb = new StringBuilder();
sb.append("garbage\n");
sb.append("nonsense\n");
sb.append("this line has the is owned by substring\n");
sb.append(" is owned by \n");
// This is the one valid line; rest should be discarded
sb.append("/usr/include/stdlib.h is owned by musl-dev-1.1.18-r3\n");
sb.append("/usr/include/stdlib.h is owned by .musl-dev-1.1.18-r99\n");
String pkgMgrOwnedByOutput = sb.toString();
ApkArchitectureResolver architectureResolver = Mockito.mock(ApkArchitectureResolver.class);
Mockito.when(architectureResolver.resolveArchitecture(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(Optional.of("x86_64"));
ApkPackageManagerResolver apkPackageManagerResolver = new ApkPackageManagerResolver(architectureResolver);
ClangPackageManagerInfo apk = new ClangPackageManagerInfoFactory().apk();
List<PackageDetails> pkgs = apkPackageManagerResolver.resolvePackages(apk, null, null, pkgMgrOwnedByOutput);
Assertions.assertEquals(1, pkgs.size());
Assertions.assertEquals("musl-dev", pkgs.get(0).getPackageName());
Assertions.assertEquals("1.1.18-r3", pkgs.get(0).getPackageVersion());
Assertions.assertEquals("x86_64", pkgs.get(0).getPackageArch());
}
use of com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails in project synopsys-detect by blackducksoftware.
the class ClangPackageDetailsTransformerTest method doTest.
private void doTest(Forge forge) {
ExternalIdFactory externalIdFactory = Mockito.mock(ExternalIdFactory.class);
ClangPackageDetailsTransformer transformer = new ClangPackageDetailsTransformer(externalIdFactory);
Forge codeLocationForge = null;
List<Forge> dependencyForges = new ArrayList<>();
dependencyForges.add(forge);
File rootDir = null;
Set<PackageDetails> packages = new HashSet<>();
final String packageName = "testPkgName";
final String packageVersion = "1:testPkgVersion";
final String packageArch = "testArch";
PackageDetails pkg = new PackageDetails(packageName, packageVersion, packageArch);
packages.add(pkg);
ExternalId externalId = new ExternalId(forge);
externalId.setName(packageName);
externalId.setVersion(packageVersion);
externalId.setArchitecture(packageArch);
// The real test is: Does this get called: (if not, test will fail)
Mockito.when(externalIdFactory.createArchitectureExternalId(forge, packageName, packageVersion, packageArch)).thenReturn(externalId);
CodeLocation codeLocation = transformer.toCodeLocation(dependencyForges, packages);
assertEquals(1, codeLocation.getDependencyGraph().getRootDependencies().size());
Dependency generatedDependency = codeLocation.getDependencyGraph().getRootDependencies().iterator().next();
assertEquals(packageName, generatedDependency.getName());
assertEquals(packageVersion, generatedDependency.getVersion());
assertEquals(forge, generatedDependency.getExternalId().getForge());
String expectedExternalId = String.format("%s/%s/%s", packageName, packageVersion, packageArch);
assertEquals(expectedExternalId, generatedDependency.getExternalId().createExternalId());
}
Aggregations