Example usage for java.nio.file Path resolve

List of usage examples for java.nio.file Path resolve

Introduction

In this page you can find the example usage for java.nio.file Path resolve.

Prototype

default Path resolve(String other) 

Source Link

Document

Converts a given path string to a Path and resolves it against this Path in exactly the manner specified by the #resolve(Path) resolve method.

Usage

From source file:net.radai.confusion.spring.SpringAnnotationConfigTest.java

@Test
public void testSpringAnnotationIntegration() throws Exception {
    Path dir = Files.createTempDirectory("test");
    Path targetFile = dir.resolve("confFile");
    try (InputStream is = getClass().getClassLoader().getResourceAsStream("cats.ini");
            OutputStream os = Files.newOutputStream(targetFile, StandardOpenOption.WRITE,
                    StandardOpenOption.CREATE_NEW)) {
        ByteStreams.copy(is, os);/*w w  w .j  a  va  2  s .  c  o m*/
    }
    String absolutePath = targetFile.toFile().getCanonicalPath();
    System.setProperty("confFile", absolutePath);
    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("annotationSpringContext.xml");
    //noinspection unchecked
    SpringAwareConfigurationService<Cats> confService = (SpringAwareConfigurationService<Cats>) context
            .getBean(ConfigurationService.class);
    Jsr330AnnotatedConfigurationConsumerBean consumer = context
            .getBean(Jsr330AnnotatedConfigurationConsumerBean.class);
    //noinspection unchecked
    Assert.assertNotNull(consumer.getConfService());
    Assert.assertNotNull(consumer.getInitialConf());
    Assert.assertTrue(consumer.getCats().isEmpty());

    try (InputStream is = getClass().getClassLoader().getResourceAsStream("cat.ini");
            OutputStream os = Files.newOutputStream(targetFile, StandardOpenOption.WRITE,
                    StandardOpenOption.TRUNCATE_EXISTING)) {
        ByteStreams.copy(is, os);
    }
    Thread.sleep(100);

    //verify event was received
    Assert.assertEquals(1, consumer.getCats().size());
    Assert.assertTrue(consumer.getInitialConf() != consumer.getCats().get(0));
    Assert.assertTrue(confService.getConfiguration() == consumer.getCats().get(0));

    context.close();
}

From source file:de.douglas.maven.plugin.rpmsystemd.rpm.PostInstMojoTest.java

public void testGenerateRpmPostInstFileWithOverwrittenSettings() throws Exception {
    final Path testBaseDir = createDir(postInstTestsBaseDir.resolve("overwrite"));
    createDir(testBaseDir.resolve("target"));

    File pom = getTestFile(postInstSrcDir.resolve("pom-overwrite.xml").toString());

    PostInstMojo postInstMojo = (PostInstMojo) lookupMojo("generate-rpm-postinst-file", pom);
    postInstMojo.execute();//from  w  w w .jav  a  2 s .c o m

    assertTrue("Generated postinst file does not equal expected one", FileUtils.contentEquals(
            postInstSrcDir.resolve("postinst-overwrite-expected").toFile(),
            testBaseDir.resolve("target").resolve("rpm-systemd-maven-plugin").resolve("postinst").toFile()));
}

From source file:de.douglas.maven.plugin.rpmsystemd.systemd.SystemdMojoTest.java

public void testGenerateSystemdFileWithOverwrittenSettings() throws Exception {
    final Path testBaseDir = createDir(systemdTestsBaseDir.resolve("overwrite"));
    createDir(testBaseDir.resolve("target"));

    File pom = getTestFile(systemdSrcDir.resolve("pom-overwrite.xml").toString());

    SystemdMojo systemdMojo = (SystemdMojo) lookupMojo("generate-systemd-file", pom);
    systemdMojo.execute();//  w  w  w.  j  a  v a 2s. c  o  m

    assertTrue("Generated systemd service file does not equal expected one",
            FileUtils.contentEquals(systemdSrcDir.resolve("test-module.service-overwrite-expected").toFile(),
                    testBaseDir.resolve("target").resolve("rpm-systemd-maven-plugin").resolve("some.service")
                            .toFile()));
}

From source file:de.douglas.maven.plugin.rpmsystemd.rpm.PostInstMojoTest.java

public void testGenerateRpmPostInstFileWithDefaultSettings() throws Exception {
    String testPomName = "pom-defaults.xml";

    Path testBaseDir = createDir(postInstTestsBaseDir.resolve("defaults"));
    Path pomPath = testBaseDir.resolve(testPomName);

    Path srcPom = postInstSrcDir.resolve(testPomName);
    Files.copy(srcPom, pomPath, StandardCopyOption.REPLACE_EXISTING);

    createDir(SystemPaths$.MODULE$.generationRootDir(testBaseDir));

    PostInstMojo postInstMojo = (PostInstMojo) lookupMojo(pomPath, "generate-rpm-postinst-file");
    postInstMojo.execute();//from   w  ww  . java 2 s  .c om

    assertTrue("Generated postinst file does not equal expected one", FileUtils.contentEquals(
            postInstSrcDir.resolve("postinst-defaults-expected").toFile(),
            testBaseDir.resolve("target").resolve("rpm-systemd-maven-plugin").resolve("postinst").toFile()));
}

From source file:io.jeo.geopkg.GeoPkgTileTest.java

@Before
public void setUp() throws Exception {
    Path dir = unzip(getClass().getResourceAsStream("ne.gpkg.zip"), newTmpDir());
    geopkg = GeoPackage.open(dir.resolve("ne.gpkg"));
}

From source file:ch.sourcepond.maven.plugin.repobuilder.TargetPathFactory.java

/**
 * @param pRepository//from   ww w  .java  2  s  .c  o  m
 * @param pGroupId
 * @return
 * @throws IOException
 */
private Path createGroupFolders(final Path pRepository, final String pGroupId) {
    Path current = pRepository;
    for (final String token : split(pGroupId, '.')) {
        current = current.resolve(token);
    }
    return current;
}

From source file:de.douglas.maven.plugin.rpmsystemd.systemd.SystemdMojoTest.java

public void testGenerateSystemdFileWithDefaultSettings() throws Exception {
    String testPomName = "pom-defaults.xml";

    Path testBaseDir = createDir(systemdTestsBaseDir.resolve("defaults"));
    Path pomPath = testBaseDir.resolve(testPomName);

    Path srcPom = systemdSrcDir.resolve(testPomName);
    Files.copy(srcPom, pomPath, StandardCopyOption.REPLACE_EXISTING);

    createDir(SystemPaths$.MODULE$.generationRootDir(testBaseDir));

    SystemdMojo systemdMojo = (SystemdMojo) lookupMojo(pomPath, "generate-systemd-file");
    systemdMojo.execute();//from   w ww . j  av a2  s  .c  o m

    assertTrue("Generated systemd service file does not equal expected one",
            FileUtils.contentEquals(systemdSrcDir.resolve("test-module.service-defaults-expected").toFile(),
                    testBaseDir.resolve("target").resolve("rpm-systemd-maven-plugin")
                            .resolve("test-module.service").toFile()));
}

From source file:com.ignorelist.kassandra.steam.scraper.PathResolver.java

private Path resolveAppsDirectory(Path base) throws IllegalStateException {
    Path oldApps = base.resolve("SteamApps");
    if (Files.isDirectory(oldApps)) {
        return oldApps;
    }//from ww w.  j a  va2  s .  c  o m
    Path newApps = base.resolve("steamapps");
    if (Files.isDirectory(newApps)) {
        return newApps;
    }
    throw new IllegalStateException("can't resolve apps directory");
}

From source file:net.radai.confusion.spring.SpringXmlConfTest.java

@Test
public void testSpringXmlIntegration() throws Exception {
    Path dir = Files.createTempDirectory("test");
    Path targetFile = dir.resolve("confFile");
    try (InputStream is = getClass().getClassLoader().getResourceAsStream("cats.ini");
            OutputStream os = Files.newOutputStream(targetFile, StandardOpenOption.WRITE,
                    StandardOpenOption.CREATE_NEW)) {
        ByteStreams.copy(is, os);/*ww w  .  j ava2  s .  c o m*/
    }
    String absolutePath = targetFile.toFile().getCanonicalPath();
    System.setProperty("confFile", absolutePath);
    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("xmlSpringContext.xml");
    //noinspection unchecked
    SpringAwareConfigurationService<Cats> confService = (SpringAwareConfigurationService<Cats>) context
            .getBean(ConfigurationService.class);
    TraditionalConfigurationConsumerBean consumer = context.getBean(TraditionalConfigurationConsumerBean.class);
    //noinspection unchecked
    SimpleConfigurationService<Cats> delegate = (SimpleConfigurationService<Cats>) ReflectionTestUtils
            .getField(confService, "delegate");
    Assert.assertNotNull(confService.getConfiguration());
    Assert.assertTrue(delegate.isStarted());
    Assert.assertTrue(consumer.getConf() == confService.getConfiguration());
    Assert.assertTrue(consumer.getConfService() == confService);
    Assert.assertTrue(consumer.getCats().isEmpty());

    try (InputStream is = getClass().getClassLoader().getResourceAsStream("cat.ini");
            OutputStream os = Files.newOutputStream(targetFile, StandardOpenOption.WRITE,
                    StandardOpenOption.TRUNCATE_EXISTING)) {
        ByteStreams.copy(is, os);
    }
    Thread.sleep(100);

    //verify event was received
    Assert.assertEquals(1, consumer.getCats().size());
    Assert.assertTrue(consumer.getConf() != consumer.getCats().get(0));
    Assert.assertTrue(confService.getConfiguration() == consumer.getCats().get(0));

    context.close();
    Assert.assertFalse(delegate.isStarted());
}

From source file:grakn.core.distribution.GraknGraqlCommands_WithARunningGraknE2E.java

/**
 * make sure Grakn is properly writing logs inside grakn.log file
 *///from   ww w. j  a  va 2  s.  c o  m
@Test
public void logMessagesArePrintedInLogFile() throws IOException {
    Path logsPath = getLogsPath();
    Path graknLogFilePath = logsPath.resolve("grakn.log");
    String logsString = new String(Files.readAllBytes(graknLogFilePath), StandardCharsets.UTF_8);
    assertThat(logsString, containsString("Grakn started"));
}