Search in sources :

Example 1 with ClangPackageDetailsTransformer

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());
    }
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) File(java.io.File) PackageDetails(com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails) HashSet(java.util.HashSet) ClangPackageDetailsTransformer(com.synopsys.integration.detectable.detectables.clang.dependencyfile.ClangPackageDetailsTransformer) Test(org.junit.jupiter.api.Test)

Example 2 with ClangPackageDetailsTransformer

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());
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ArrayList(java.util.ArrayList) Forge(com.synopsys.integration.bdio.model.Forge) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) File(java.io.File) PackageDetails(com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails) ClangPackageDetailsTransformer(com.synopsys.integration.detectable.detectables.clang.dependencyfile.ClangPackageDetailsTransformer) HashSet(java.util.HashSet)

Aggregations

Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)2 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)2 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)2 ClangPackageDetailsTransformer (com.synopsys.integration.detectable.detectables.clang.dependencyfile.ClangPackageDetailsTransformer)2 PackageDetails (com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails)2 File (java.io.File)2 HashSet (java.util.HashSet)2 Forge (com.synopsys.integration.bdio.model.Forge)1 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)1 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1