use of com.synopsys.integration.detectable.detectables.clang.dependencyfile.ClangPackageDetailsTransformer in project synopsys-detect by blackducksoftware.
the class DependencyFileDetailGeneratorTest method testDependencyCreatedWithEachForge.
@Test
public void testDependencyCreatedWithEachForge() {
File mockFile = Mockito.mock(File.class);
Mockito.when(mockFile.toString()).thenReturn("Example");
Set<PackageDetails> packages = new HashSet<>();
packages.add(new PackageDetails("testPackageName1", "testPackageVersion1", "testPackageArch1"));
packages.add(new PackageDetails("testPackageName2", "testPackageVersion2", "testPackageArch2"));
ExternalIdFactory externalIdFactory = new ExternalIdFactory();
ClangPackageDetailsTransformer clangPackageDetailsTransformer = new ClangPackageDetailsTransformer(externalIdFactory);
CodeLocation codeLocation = clangPackageDetailsTransformer.toCodeLocation(Arrays.asList(Forge.CENTOS, Forge.FEDORA, Forge.REDHAT), packages);
Set<Dependency> dependencies = codeLocation.getDependencyGraph().getRootDependencies();
assertEquals(6, dependencies.size());
for (Dependency dependency : dependencies) {
System.out.printf("Checking dependency: %s:%s / %s\n", dependency.getName(), dependency.getVersion(), dependency.getExternalId().getForge().getName());
char indexChar = dependency.getName().charAt(15);
assertTrue(indexChar == '1' || indexChar == '2' || indexChar == '3');
String forge = dependency.getExternalId().getForge().getName();
assertTrue("centos".equals(forge) || "fedora".equals(forge) || "redhat".equals(forge));
assertEquals(String.format("testPackageName%c", indexChar), dependency.getName());
assertEquals(String.format("testPackageVersion%c", indexChar), dependency.getVersion());
assertEquals(String.format("testPackageArch%c", indexChar), dependency.getExternalId().getArchitecture());
assertEquals(forge, dependency.getExternalId().getForge().getName());
assertEquals(String.format("testPackageName%c", indexChar), dependency.getExternalId().getName());
assertEquals(String.format("testPackageVersion%c", indexChar), dependency.getExternalId().getVersion());
}
}
use of com.synopsys.integration.detectable.detectables.clang.dependencyfile.ClangPackageDetailsTransformer 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