Package org.jboss.forge.addon.resource

Examples of org.jboss.forge.addon.resource.DirectoryResource


   @Test
   public void testEscapes() throws Exception
   {
      File tempDir = OperatingSystemUtils.createTempDir();
      tempDir.deleteOnExit();
      DirectoryResource currentResource = resourceFactory.create(DirectoryResource.class, tempDir);
      Shell shell = test.getShell();
      shell.setCurrentResource(currentResource);
      DirectoryResource child = currentResource.getChildDirectory("Forge 2 Escape");
      child.mkdir();
      child.deleteOnExit();
      Result result = test.execute("cd Forge\\ 2\\ Escape", 10, TimeUnit.SECONDS);
      Assert.assertThat(result.getMessage(), CoreMatchers.nullValue());
      Assert.assertEquals(shell.getCurrentResource(), child);
      currentResource.delete(true);
   }
View Full Code Here


   @Test
   public void testQuotes() throws Exception
   {
      File tempDir = OperatingSystemUtils.createTempDir();
      tempDir.deleteOnExit();
      DirectoryResource currentResource = resourceFactory.create(DirectoryResource.class, tempDir);
      Shell shell = test.getShell();
      shell.setCurrentResource(currentResource);
      FileResource<?> child = currentResource.getChildDirectory("Forge 2 Escape");
      child.mkdir();
      child.deleteOnExit();
      Result result = test.execute("cd \"Forge 2 Escape\"", 10, TimeUnit.SECONDS);
      Assert.assertThat(result.getMessage(), nullValue());
      Assert.assertEquals(shell.getCurrentResource(), child);
      currentResource.delete(true);
   }
View Full Code Here

   @Test(timeout = 10000)
   public void testTransactionTrackChanges() throws Exception
   {
      test.clearScreen();
      DirectoryResource tempDir = factory.create(OperatingSystemUtils.createTempDir()).reify(DirectoryResource.class);
      tempDir.deleteOnExit();

      test.getShell().setCurrentResource(tempDir);
      Assert.assertFalse(test.execute("track-changes", SHELL_TIMEOUT, TimeUnit.SECONDS) instanceof Failed);
      test.waitForStdOutValue("Resource change tracking is ON.", SHELL_TIMEOUT, TimeUnit.SECONDS);

      Assert.assertFalse(test.execute("touch foo.txt", SHELL_TIMEOUT, TimeUnit.SECONDS) instanceof Failed);
      test.waitForStdOutValue("Created  " + tempDir.getFullyQualifiedName() + File.separator + "foo.txt",
               SHELL_TIMEOUT, TimeUnit.SECONDS);

      Assert.assertFalse(test.execute("rm foo.txt", SHELL_TIMEOUT, TimeUnit.SECONDS) instanceof Failed);
      test.waitForStdOutValue("Deleted  " + tempDir.getFullyQualifiedName() + File.separator +
               "foo.txt", SHELL_TIMEOUT,
               TimeUnit.SECONDS);

      Assert.assertFalse(test.execute("track-changes", SHELL_TIMEOUT, TimeUnit.SECONDS) instanceof Failed);
      test.waitForStdOutValue("Resource change tracking is OFF.", SHELL_TIMEOUT, TimeUnit.SECONDS);
View Full Code Here

   @Test(timeout = 10000)
   public void testTransactionTrackChangesExistingTransaction() throws Exception
   {
      test.clearScreen();
      DirectoryResource tempDir = factory.create(OperatingSystemUtils.createTempDir()).reify(DirectoryResource.class);
      tempDir.deleteOnExit();

      test.getShell().setCurrentResource(tempDir);
      Assert.assertFalse(test.execute("transaction-start", SHELL_TIMEOUT, TimeUnit.SECONDS) instanceof Failed);
      Assert.assertFalse(test.execute("track-changes", SHELL_TIMEOUT, TimeUnit.SECONDS) instanceof Failed);

      Assert.assertFalse(test.execute("touch foo.txt", SHELL_TIMEOUT, TimeUnit.SECONDS) instanceof Failed);
      Assert.assertFalse(test.execute("rm foo.txt", SHELL_TIMEOUT, TimeUnit.SECONDS) instanceof Failed);

      test.clearScreen();
      Assert.assertFalse(test.execute("transaction-commit", SHELL_TIMEOUT, TimeUnit.SECONDS) instanceof Failed);
      test.waitForStdOutValue("Created  " + tempDir.getFullyQualifiedName() + File.separator
               + "foo.txt", SHELL_TIMEOUT, TimeUnit.SECONDS);
      test.waitForStdOutValue("Deleted  " + tempDir.getFullyQualifiedName() + File.separator
               + "foo.txt", SHELL_TIMEOUT,
               TimeUnit.SECONDS);

      Assert.assertFalse(test.execute("track-changes", SHELL_TIMEOUT, TimeUnit.SECONDS) instanceof Failed);
      test.waitForStdOutValue("Resource change tracking is OFF.", SHELL_TIMEOUT, TimeUnit.SECONDS);
View Full Code Here

   @Test(timeout = 10000)
   public void testTransactionTrackChangesManualTransaction() throws Exception
   {
      test.clearScreen();
      DirectoryResource tempDir = factory.create(OperatingSystemUtils.createTempDir()).reify(DirectoryResource.class);
      tempDir.deleteOnExit();

      test.getShell().setCurrentResource(tempDir);
      Assert.assertFalse(test.execute("track-changes", SHELL_TIMEOUT, TimeUnit.SECONDS) instanceof Failed);
      Assert.assertFalse(test.execute("transaction-start", SHELL_TIMEOUT, TimeUnit.SECONDS) instanceof Failed);

      Assert.assertFalse(test.execute("touch foo.txt", SHELL_TIMEOUT, TimeUnit.SECONDS) instanceof Failed);
      Assert.assertFalse(test.execute("rm foo.txt", SHELL_TIMEOUT, TimeUnit.SECONDS) instanceof Failed);

      test.clearScreen();
      Assert.assertFalse(test.execute("transaction-commit", SHELL_TIMEOUT, TimeUnit.SECONDS) instanceof Failed);
      test.waitForStdOutValue("Created  " + tempDir.getFullyQualifiedName() + File.separator + "foo.txt",
               SHELL_TIMEOUT, TimeUnit.SECONDS);
      test.waitForStdOutValue("Deleted  " + tempDir.getFullyQualifiedName() + File.separator + "foo.txt",
               SHELL_TIMEOUT,
               TimeUnit.SECONDS);

      test.clearScreen();
      Assert.assertFalse(test.execute("track-changes", SHELL_TIMEOUT, TimeUnit.SECONDS) instanceof Failed);
      test.waitForStdOutValue("Resource change tracking is OFF.", SHELL_TIMEOUT, TimeUnit.SECONDS);
      Assert.assertFalse(test.getStdOut().contains(
               "Modified " + tempDir.getFullyQualifiedName() + File.separator + "foo.txt"));
      Assert.assertFalse(test.getStdOut().contains(
               "Deleted  " + tempDir.getFullyQualifiedName() + File.separator + "foo.txt"));
   }
View Full Code Here

   }

   @Test(timeout = 10000)
   public void testTransactionTrackChangesOff() throws Exception
   {
      DirectoryResource tempDir = factory.create(OperatingSystemUtils.createTempDir()).reify(DirectoryResource.class);
      tempDir.deleteOnExit();

      final AtomicBoolean flag = new AtomicBoolean(false);
      factory.addTransactionListener(new ResourceTransactionListener()
      {
         @Override
         public void transactionStarted(ResourceTransaction transaction)
         {
            flag.set(true);
         }

         @Override
         public void transactionRolledBack(ResourceTransaction transaction)
         {
            flag.set(true);
         }

         @Override
         public void transactionCommitted(ResourceTransaction transaction, Set<ResourceEvent> changeSet)
         {
            flag.set(true);
         }
      });

      test.clearScreen();
      test.getShell().setCurrentResource(tempDir);

      Assert.assertFalse(test.execute("touch foo.txt", SHELL_TIMEOUT, TimeUnit.SECONDS) instanceof Failed);

      Assert.assertFalse(flag.get());

      Assert.assertFalse(test.execute("track-changes", SHELL_TIMEOUT, TimeUnit.SECONDS) instanceof Failed);
      test.waitForStdOutValue("Resource change tracking is ON.", SHELL_TIMEOUT, TimeUnit.SECONDS);

      Assert.assertFalse(test.execute("rm foo.txt", SHELL_TIMEOUT, TimeUnit.SECONDS) instanceof Failed);
      test.waitForStdOutValue("Deleted  " + tempDir.getFullyQualifiedName() + File.separator + "foo.txt",
               SHELL_TIMEOUT,
               TimeUnit.SECONDS);

      Assert.assertTrue(flag.get());
View Full Code Here

   @SuppressWarnings("unchecked")
   @Test(timeout = 10000)
   public void testRmCommand() throws TimeoutException
   {
      File tempDir = OperatingSystemUtils.createTempDir();
      DirectoryResource tempResource = resourceFactory.create(tempDir).reify(DirectoryResource.class);
      tempDir.deleteOnExit();
      FileResource<?> fileTxt = tempResource.getChildOfType(FileResource.class, "file.txt");
      fileTxt.createNewFile();
      fileTxt.deleteOnExit();

      Shell shell = shellTest.getShell();
      shell.setCurrentResource(tempResource);
View Full Code Here

   @Test(timeout = 10000)
   public void testChangeDirCommand() throws TimeoutException
   {
      File tempDir = OperatingSystemUtils.createTempDir();
      DirectoryResource tempResource = resourceFactory.create(tempDir).reify(DirectoryResource.class);
      DirectoryResource childDirectory = tempResource.getChildDirectory("child");
      childDirectory.mkdir();
      childDirectory.deleteOnExit();
      tempDir.deleteOnExit();

      Shell shell = shellTest.getShell();
      shell.setCurrentResource(tempResource);
      Result changeDirResult = shellTest.execute("cd child", 10, TimeUnit.SECONDS);
      Assert.assertNotNull(changeDirResult);
      Assert.assertEquals(childDirectory, shell.getCurrentResource());
      childDirectory.delete();
      tempDir.delete();
   }
View Full Code Here

   @Test(timeout = 10000)
   public void testChangeDirCommandFailed() throws TimeoutException
   {
      File tempDir = OperatingSystemUtils.createTempDir();
      DirectoryResource tempResource = resourceFactory.create(tempDir).reify(DirectoryResource.class);
      tempDir.deleteOnExit();

      Shell shell = shellTest.getShell();
      shell.setCurrentResource(tempResource);
      Result changeDirResult = shellTest.execute("cd child", 10, TimeUnit.SECONDS);
View Full Code Here

   @Test(timeout = 10000)
   public void testChangeDirAbsolute() throws TimeoutException
   {
      File userHome = OperatingSystemUtils.getUserHomeDir();
      File tempDir = OperatingSystemUtils.createTempDir();
      DirectoryResource tempResource = resourceFactory.create(tempDir).reify(DirectoryResource.class);
      tempDir.deleteOnExit();

      Shell shell = shellTest.getShell();
      shell.setCurrentResource(tempResource);
      Result changeDirResult = shellTest.execute("cd " + userHome.getAbsolutePath(), 10, TimeUnit.SECONDS);
View Full Code Here

TOP

Related Classes of org.jboss.forge.addon.resource.DirectoryResource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.