Esempio n. 1
0
 @After
 public void tearDown() {
   for (File file : new File[] {_fileExisting, _fileText}) {
     if (file.exists()) {
       file.delete();
     }
   }
 }
Esempio n. 2
0
  @Test
  public void testUncompress_withSymbolicLinks() throws IOException, ArchiveException {
    final File inputFile = new File(inputUrl.getPath(), "tarLink.tar.gz");
    final File temporaryDirectory = Files.createTempDir();

    temporaryDirectory.deleteOnExit();

    final List<File> extractedFiles = new Extractor().uncompress(inputFile, temporaryDirectory);

    final File file1 = new File(temporaryDirectory, "file1.txt");
    final File file2 = new File(temporaryDirectory, "file1_link.txt");

    assertTrue(file1.exists());
    assertTrue(file2.exists());

    assertEquals("file1content", new String(FileUtils.readFileToByteArray(file1)));
    assertEquals("file1content", new String(FileUtils.readFileToByteArray(file2)));

    assertTrue(java.nio.file.Files.isSymbolicLink(Paths.get(file2.getPath())));
  }
Esempio n. 3
0
 public void moveToDirectory(File target) {
   if (target.exists() && !target.isDirectory()) {
     throw new RuntimeException(String.format("Target '%s' is not a directory", target));
   }
   try {
     FileUtils.moveFileToDirectory(this, target, true);
   } catch (IOException e) {
     throw new RuntimeException(
         String.format("Could not move test file '%s' to directory '%s'", this, target), e);
   }
 }
  private void assertExpectedFileIO() {
    File realFile = new File(FILE_NAME);
    boolean realFileCreated = realFile.exists();

    if (realFileCreated) {
      realFile.delete();
    }

    assertFalse("Real file created", realFileCreated);
    assertTrue("File not written", testOutput.toString().startsWith("File written"));
  }
Esempio n. 5
0
  private void testUncompress(String fileName) throws IOException, ArchiveException {
    final File inputFile = new File(inputUrl.getPath(), fileName);
    final File temporaryDirectory = Files.createTempDir();

    temporaryDirectory.deleteOnExit();

    final List<File> extractedFiles = new Extractor().uncompress(inputFile, temporaryDirectory);

    assertTrue(new File(temporaryDirectory, "directory1").isDirectory());
    final File file1 = new File(temporaryDirectory, "file1.txt");
    final File file2 = new File(temporaryDirectory, "file2.txt");
    final File file0 = new File(new File(temporaryDirectory, "directory1"), "file0.txt");

    assertTrue(file1.exists());
    assertTrue(file2.exists());
    assertTrue(file0.exists());

    assertEquals("file1content", new String(FileUtils.readFileToByteArray(file1)));
    assertEquals("file2content", new String(FileUtils.readFileToByteArray(file2)));
    assertEquals("file0content", new String(FileUtils.readFileToByteArray(file0)));

    assertEquals(5, extractedFiles.size());
  }
 @Test
 public void test_main_offline() throws IOException {
   File offline = new File("OfflineData.bin");
   if (offline.exists() && !offline.isDirectory()) {
     this.getLogger().info("OfflineData.bin file exists.");
     if (GraphicsEnvironment.isHeadless()) {
       this.binFileReader = new BinFileReader(offline);
     } else {
       this.binFileReader = new BinFileReaderGui(offline);
     }
     do_read_from_bin();
     System.out.println("");
   } else {
     getLogger().warning("No OfflineData.bin file!");
   }
 }
Esempio n. 7
0
  private static void moveFile(String from, String to) throws IOException {
    File fromFile = new File(from);
    File toFile = new File(to);
    if (fromFile.exists()) {
      FileOutputStream fos = new FileOutputStream(toFile);
      FileInputStream fis = new FileInputStream(fromFile);

      byte[] buffer = new byte[1024];
      int len = fis.read(buffer);
      while (len != -1) {
        fos.write(buffer, 0, len);
        len = fis.read(buffer);
      }

      fos.close();
      fis.close();
      fromFile.delete();
    }
  }
Esempio n. 8
0
  private void test_image_picker(WebDriver driver) {
    // Check both files exist
    File f1 = null;
    File f2 = null;
    try {
      ClassLoader cl = ImagePickerTest.class.getClassLoader();
      f1 = new File(cl.getResource("image_picker_1.png").toURI());
      assertTrue(f1.exists());
      f2 = new File(cl.getResource("image_picker_2.png").toURI());
      assertTrue(f2.exists());
    } catch (URISyntaxException e) {
      e.printStackTrace();
    }
    assertNotNull(f1);
    assertNotNull(f2);

    // Login
    CStudioSeleniumUtil.try_login(
        driver, CStudioSeleniumUtil.AUTHOR_USER, CStudioSeleniumUtil.AUTHOR_PASSWORD, true);

    // Navigate to Widget
    CStudioSeleniumUtil.navigate_to_image_picker_widget(driver);

    // Upload right file size
    CStudioSeleniumUtil.click_on(driver, By.id("xf-4$xf-20$imageSrcAltTextTest-imageButton"));

    // Check popup dialog appears
    WebElement popup = driver.findElement(By.id("cstudio-wcm-popup-div_c"));
    assertTrue(popup.isDisplayed());

    WebElement input =
        driver.findElement(By.xpath("/html/body/div[3]/div/div[2]/div/div/div/form/input"));
    input.sendKeys(f1.getAbsolutePath());

    WebElement upload =
        driver.findElement(By.xpath("/html/body/div[3]/div/div[2]/div/div/div/form/input[2]"));
    upload.click();

    new WebDriverWait(driver, CStudioSeleniumUtil.SHORT_TIMEOUT)
        .until(
            new ExpectedCondition<Boolean>() {
              public Boolean apply(WebDriver d) {
                WebElement e = d.findElement(By.id("xf-4$xf-20$imageSrcAltTextTest$xf-206$$a"));
                return e != null && e.getAttribute("class").contains("xforms-alert-inactive");
              }
            });
    WebElement mark = driver.findElement(By.id("xf-4$xf-20$imageSrcAltTextTest$xf-206$$a"));
    assertTrue(mark.getAttribute("class").contains("xforms-alert-inactive"));

    // Delete uploaded image
    CStudioSeleniumUtil.click_on(driver, By.id("xf-4$xf-20$imageSrcAltTextTest-deleteButton"));
    WebElement filename =
        driver.findElement(By.id("xf-4$xf-20$imageSrcAltTextTest$xf-206-filename"));
    assertTrue(filename.getText().equals("250W X 130H"));

    // Upload any image
    CStudioSeleniumUtil.click_on(driver, By.id("xf-4$xf-20$imageSrcTest-imageButton"));

    // Check popup dialog appears
    popup = driver.findElement(By.id("cstudio-wcm-popup-div_c"));
    assertTrue(popup.isDisplayed());

    input = driver.findElement(By.xpath("/html/body/div[3]/div/div[2]/div/div/div/form/input"));
    input.sendKeys(f2.getAbsolutePath());

    upload = driver.findElement(By.xpath("/html/body/div[3]/div/div[2]/div/div/div/form/input[2]"));
    upload.click();

    new WebDriverWait(driver, CStudioSeleniumUtil.SHORT_TIMEOUT)
        .until(
            new ExpectedCondition<Boolean>() {
              public Boolean apply(WebDriver d) {
                WebElement e = d.findElement(By.id("xf-4$xf-20$imageSrcTest$xf-237-filename"));
                return e != null && e.getText().equals("/static-assets/images/image_picker_2.png");
              }
            });

    // Delete uploaded image
    CStudioSeleniumUtil.click_on(driver, By.id("xf-4$xf-20$imageSrcTest-deleteButton"));
    filename = driver.findElement(By.id("xf-4$xf-20$imageSrcTest$xf-237-filename"));
    assertTrue(filename.getText().equals(""));

    // Close driver
    CStudioSeleniumUtil.exit(driver);
  }