Esempio n. 1
0
 @Test
 public void sortByExample4() {
   List<Integer> example = asList(1, 3, 5, 2, 4, 6);
   final List<String> expected = asList("1", "3", "5", "2", "4", "6");
   assertEquals(
       expected,
       Algorithms.sortByExample(
           example,
           Strings.<Integer>string(),
           asList("6", "5", "4", "3", "2", "1"),
           Functions.<String>identity()));
   assertEquals(
       asList("3", "5", "4"),
       Algorithms.sortByExample(
           example,
           Strings.<Integer>string(),
           asList("5", "4", "3"),
           Functions.<String>identity()));
   assertEquals(
       expected,
       Algorithms.sortByExample(
           example,
           Strings.<Integer>string(),
           asList("1", "2", "3", "4", "5", "6", "7", "8", "9"),
           Functions.<String>identity()));
 }
Esempio n. 2
0
 @Test
 public void deleteFile() throws Exception {
   Assume.assumeTrue(Functions.isWindows());
   Class<?> c;
   try {
     c = Class.forName("java.nio.file.FileSystemException");
   } catch (ClassNotFoundException x) {
     throw new AssumptionViolatedException("prior to JDK 7", x);
   }
   File d = Util.createTempDir();
   try {
     File f = new File(d, "f");
     OutputStream os = new FileOutputStream(f);
     try {
       Util.deleteFile(f);
       fail("should not have been deletable");
     } catch (IOException x) {
       assertEquals(c, x.getClass());
     } finally {
       os.close();
     }
   } finally {
     Util.deleteRecursive(d);
   }
 }
Esempio n. 3
0
  @Test
  public void testIsSymlink() throws IOException, InterruptedException {
    Assume.assumeTrue(!Functions.isWindows());

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    StreamTaskListener l = new StreamTaskListener(baos);
    File d = Util.createTempDir();
    try {
      new FilePath(new File(d, "original")).touch(0);
      assertFalse(Util.isSymlink(new File(d, "original")));
      Util.createSymlink(d, "original", "link", l);

      assertTrue(Util.isSymlink(new File(d, "link")));

      // test linking to another directory
      File dir = new File(d, "dir");
      assertTrue("Couldn't create " + dir, dir.mkdir());
      assertFalse(Util.isSymlink(new File(d, "dir")));

      File anotherDir = new File(d, "anotherDir");
      assertTrue("Couldn't create " + anotherDir, anotherDir.mkdir());

      Util.createSymlink(d, "dir", "anotherDir/symlinkDir", l);
      // JENKINS-12331: either a bug in createSymlink or this isn't supposed to work:
      // assertTrue(Util.isSymlink(new File(d,"anotherDir/symlinkDir")));
    } finally {
      Util.deleteRecursive(d);
    }
  }
Esempio n. 4
0
  @Test
  public void testSymlink() throws Exception {
    Assume.assumeTrue(!Functions.isWindows());

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    StreamTaskListener l = new StreamTaskListener(baos);
    File d = Util.createTempDir();
    try {
      new FilePath(new File(d, "a")).touch(0);
      assertNull(Util.resolveSymlink(new File(d, "a")));
      Util.createSymlink(d, "a", "x", l);
      assertEquals("a", Util.resolveSymlink(new File(d, "x")));

      // test a long name
      StringBuilder buf = new StringBuilder(768);
      for (int i = 0; i < 768; i++) buf.append((char) ('0' + (i % 10)));
      Util.createSymlink(d, buf.toString(), "x", l);

      String log = baos.toString();
      if (log.length() > 0) System.err.println("log output: " + log);

      assertEquals(buf.toString(), Util.resolveSymlink(new File(d, "x")));

      // test linking from another directory
      File anotherDir = new File(d, "anotherDir");
      assertTrue("Couldn't create " + anotherDir, anotherDir.mkdir());

      Util.createSymlink(d, "a", "anotherDir/link", l);
      assertEquals("a", Util.resolveSymlink(new File(d, "anotherDir/link")));

      // JENKINS-12331: either a bug in createSymlink or this isn't supposed to work:
      // assertTrue(Util.isSymlink(new File(d,"anotherDir/link")));

      File external = File.createTempFile("something", "");
      try {
        Util.createSymlink(d, external.getAbsolutePath(), "outside", l);
        assertEquals(external.getAbsolutePath(), Util.resolveSymlink(new File(d, "outside")));
      } finally {
        assertTrue(external.delete());
      }
    } finally {
      Util.deleteRecursive(d);
    }
  }
Esempio n. 5
0
File: LFT.java Progetto: qarocks/SPW
  @Test
  public void LFTMain() throws Exception {
    JavascriptExecutor js = (JavascriptExecutor) webDriver;
    selenium.open(baseUrl);
    selenium.type("id=id_username", sender);
    selenium.type("id=id_password", "123abc");
    selenium.click("css=input[type=\"submit\"]");

    selenium.waitForPageToLoad("2000");

    System.out.println("First: The page title is " + selenium.getTitle());
    // code to upload file

    driver.findElement(By.linkText("Compose")).click();

    selenium.waitForPageToLoad("3000");

    // Runtime.getRuntime().exec("C:\\Users\\Sneha\\Desktop\\IE.exe");
    Runtime.getRuntime().exec("C:\\Users\\Sneha\\Desktop\\silver_autoit.exe");

    Functions.MyWaitfunc(driver, "//*[@id='uploader_browse']");
    WebElement ele = driver.findElement(By.xpath("//*[@id='uploader_browse']"));
    ele.click();

    // ele.sendKeys("C:\\Users\\Sneha\\Desktop\\Lighthouse.jpg");

    // send secure mail
    // driver.findElement(By.id("secure")).click();

    driver.findElement(By.id("addrin")).sendKeys(recipient);

    driver.findElement(By.id("id_subject")).sendKeys(stringToTest_tc001);

    String torun = "document.getElementById('tinymce').innerHTML='Hi there!'";

    driver.findElement(By.id("addrsubmit")).click();

    /*selenium.waitForPageToLoad("3000");

    		Thread.sleep(100);
    		js.executeScript(torun);

    		System.out.println((String)js.executeScript("return document.title"));

    */

    driver.switchTo().frame("id_body_ifr");

    selenium.typeKeys("//body[@id='tinymce']", "Finally wohoooo!!");
    driver.switchTo().defaultContent();

    driver.findElement(By.id("submitter")).click();

    /* code only if it is LFT

    String per_done="//html/body/div/div[2]/div[4]/form/fieldset/div[9]/div/div/div/div[2]/table[2]/tbody/tr/td[3]/span";
    NoSuchElementException e1 = null;

    // code to wait for file to be uploaded
    for (int second = 0;; second++) {

    	if (second >= 60) {fail("timeout");}
    	try { if (driver.findElement(By.xpath(per_done)).getText().equalsIgnoreCase("548 KB")) break; } catch (Exception e) {}
    	Thread.sleep(1000);


    }
    */
    // mail body

    /* code to run if LFT
    //System.out.println((String)js.
    if((this.doesWebElementExist(driver,By.xpath(per_done))) && (driver.findElement(By.xpath(per_done)).getText().equalsIgnoreCase("548 KB")))

    	{//driver.findElement(By.id("submitter")).click();
    	}

    else
    	throw e1;

    */

    /* this section if confirm dialog pops up!

    this.MyWaitfunc("//html/body/div[4]/div[11]/div/button/span");

          if(driver.findElement(By.xpath("//html/body/div[4]/div[11]/div/button/span")).isDisplayed())

    	driver.findElement(By.xpath("//html/body/div[4]/div[11]/div/button/span")).click();
    else
    	System.out.println("Confirm dialog not up yet!");
    */

    // to check if mail was sent successfully

    String success_str_xpath = "//html/body/div/div[2]/div[3]/ul/li";

    Functions.MyWaitfunc(driver, success_str_xpath);
    if ((Functions.doesWebElementExist(driver, By.xpath(success_str_xpath)))
        && (driver
            .findElement(By.xpath(success_str_xpath))
            .getText()
            .contains("Successfully sent the email")))
      System.out.println("SUCCESS:Mail successfully sent !");
    else {
      System.out.println("FAIL:Mail NOT SENT !");
      System.out.println(driver.findElement(By.xpath(success_str_xpath)).getText());
      Exception e1 = null;
      throw e1;
    }
  }