Search in sources :

Example 1 with IOServiceNio2WrapperImpl

use of org.uberfire.io.impl.IOServiceNio2WrapperImpl in project kie-wb-common by kiegroup.

the class RepositoryVisitorTest method repositoryVisitorDiffDeletedTest.

@Test
public void repositoryVisitorDiffDeletedTest() throws IOException {
    final IOServiceNio2WrapperImpl ioService = new IOServiceNio2WrapperImpl();
    final Optional<Source> sourceOptional = new GitConfigExecutor(new InMemorySourceRegistry()).apply(new GitConfigImpl(tempPath.getAbsolutePath(), "master", gitUrl, "users-new", "true"));
    assertTrue(sourceOptional.isPresent());
    final Source source = sourceOptional.get();
    final InputStream pomStream = org.uberfire.java.nio.file.Files.newInputStream(source.getPath().resolve("pom.xml"));
    final MavenProject project = MavenProjectLoader.parseMavenPom(pomStream);
    RepositoryVisitor repositoryVisitor = new RepositoryVisitor(source.getPath(), project.getName());
    System.out.println("Root: " + repositoryVisitor.getRoot().getAbsolutePath());
    Map<String, String> identityHash = repositoryVisitor.getIdentityHash();
    final URI originRepo = URI.create("git://users-new");
    final FileSystem fs = FileSystems.getFileSystem(originRepo);
    ioService.startBatch(fs);
    ioService.write(fs.getPath("/file.txt"), "temp");
    ioService.write(fs.getPath("/pom.xml"), "hi there" + UUID.randomUUID().toString());
    ioService.endBatch();
    ioService.delete(source.getPath().resolve("demo.iml"));
    RepositoryVisitor newRepositoryVisitor = new RepositoryVisitor(source.getPath(), repositoryVisitor.getRoot().getAbsolutePath().trim(), false);
    System.out.println("Root: " + newRepositoryVisitor.getRoot().getAbsolutePath());
    Map<String, String> newIdentityHash = newRepositoryVisitor.getIdentityHash();
    MapDifference<String, String> difference = Maps.difference(identityHash, newIdentityHash);
    Map<String, MapDifference.ValueDifference<String>> entriesDiffering = difference.entriesDiffering();
    System.out.println(" Size of Differences: " + entriesDiffering.size());
    for (String key : entriesDiffering.keySet()) {
        System.out.println("Different Value: " + key);
    }
    assertEquals(1, entriesDiffering.size());
    assertNotNull(entriesDiffering.get("/pom.xml"));
    Map<String, String> deletedFiles = difference.entriesOnlyOnLeft();
    System.out.println(" Size of Deleted Files: " + deletedFiles.size());
    for (String key : deletedFiles.keySet()) {
        System.out.println("Deleted File: " + key);
    }
    assertEquals(1, deletedFiles.size());
    assertNotNull(deletedFiles.get("/demo.iml"));
    Map<String, String> addedFiles = difference.entriesOnlyOnRight();
    System.out.println(" Size of added Files: " + addedFiles.size());
    for (String key : addedFiles.keySet()) {
        System.out.println("Added File: " + key);
    }
    assertEquals(1, addedFiles.size());
    assertNotNull(addedFiles.get("/file.txt"));
}
Also used : GitConfigImpl(org.guvnor.ala.source.git.config.impl.GitConfigImpl) InputStream(java.io.InputStream) RepositoryVisitor(org.guvnor.ala.build.maven.util.RepositoryVisitor) URI(java.net.URI) Source(org.guvnor.ala.source.Source) GitConfigExecutor(org.guvnor.ala.source.git.executor.GitConfigExecutor) InMemorySourceRegistry(org.guvnor.ala.registry.inmemory.InMemorySourceRegistry) MavenProject(org.apache.maven.project.MavenProject) IOServiceNio2WrapperImpl(org.uberfire.io.impl.IOServiceNio2WrapperImpl) FileSystem(org.uberfire.java.nio.file.FileSystem) Test(org.junit.Test)

Aggregations

InputStream (java.io.InputStream)1 URI (java.net.URI)1 MavenProject (org.apache.maven.project.MavenProject)1 RepositoryVisitor (org.guvnor.ala.build.maven.util.RepositoryVisitor)1 InMemorySourceRegistry (org.guvnor.ala.registry.inmemory.InMemorySourceRegistry)1 Source (org.guvnor.ala.source.Source)1 GitConfigImpl (org.guvnor.ala.source.git.config.impl.GitConfigImpl)1 GitConfigExecutor (org.guvnor.ala.source.git.executor.GitConfigExecutor)1 Test (org.junit.Test)1 IOServiceNio2WrapperImpl (org.uberfire.io.impl.IOServiceNio2WrapperImpl)1 FileSystem (org.uberfire.java.nio.file.FileSystem)1