예제 #1
0
  public void testImageInsideCollection() throws Exception {
    execute("CRUD.new");
    execute("Collection.new", "viewObject=xava_view_section0_ingredients");
    execute("ImageEditor.changeImage", "newImageProperty=image");
    assertNoErrors();
    assertAction("LoadImage.loadImage");
    String imageUrl = System.getProperty("user.dir") + "/test-images/cake.gif";
    setFileValue("newImage", imageUrl);
    execute("LoadImage.loadImage");
    assertNoErrors();

    HtmlPage page = (HtmlPage) getWebClient().getCurrentWindow().getEnclosedPage();
    URL url = page.getWebResponse().getRequestSettings().getUrl();

    String urlPrefix = url.getProtocol() + "://" + url.getHost() + ":" + url.getPort();

    HtmlImage image = (HtmlImage) page.getElementsByName(decorateId("image")).get(0);
    String imageURL = null;
    if (image.getSrcAttribute().startsWith("/")) {
      imageURL = urlPrefix + image.getSrcAttribute();
    } else {
      String urlBase = Strings.noLastToken(url.getPath(), "/");
      imageURL = urlPrefix + urlBase + image.getSrcAttribute();
    }
    WebResponse response = getWebClient().getPage(imageURL).getWebResponse();
    assertTrue("Image not obtained", response.getContentAsString().length() > 0);
    assertEquals("Result is not an image", "image", response.getContentType());
  }
예제 #2
0
  public void testImagesGallery() throws Exception {
    // We remove oid from product 1 in order to test that images gallery works well in the first
    // attemp.
    Product2.findByNumber(1).setPhotos("");
    XPersistence.commit();
    // Verifying product 1 has no images
    assertTrue("At least 2 products are required to run this test", getListRowCount() >= 2);
    execute("Mode.detailAndFirst");
    assertValue("number", "1");
    execute("Gallery.edit", "galleryProperty=photos");
    assertNoErrors();
    assertMessage("No images");
    assertNoAction("Gallery.maximizeImage");
    assertNoAction("Gallery.minimizeImage");
    assertNoAction("Gallery.removeImage");
    assertEquals(
        "Images count does not match", 0, getForm().getInputsByName("xava.GALLERY.images").size());

    // Canceling the adding of and image
    execute("Gallery.addImage");
    assertNoErrors();
    String imageUrl = System.getProperty("user.dir") + "/test-images/foto_javi.jpg";
    setFileValue("newImage", imageUrl);
    execute("LoadImageIntoGallery.cancel");
    assertNoErrors();
    assertNoAction("Gallery.maximizeImage");
    assertNoAction("Gallery.minimizeImage");
    assertNoAction("Gallery.removeImage");
    assertEquals(
        "Images count does not match", 0, getForm().getInputsByName("xava.GALLERY.images").size());

    // Adding one image
    execute("Gallery.addImage");
    assertNoErrors();
    imageUrl = System.getProperty("user.dir") + "/test-images/foto_javi.jpg";
    setFileValue("newImage", imageUrl);
    execute("LoadImageIntoGallery.loadImage");
    assertNoErrors();
    assertMessage("Image added to the gallery");
    assertAction("Gallery.maximizeImage");
    assertNoAction("Gallery.minimizeImage");
    assertAction("Gallery.removeImage");
    assertEquals(
        "Images count does not match", 1, getForm().getInputsByName("xava.GALLERY.images").size());

    // Returning to the main entity
    execute("Gallery.return");
    // execute("CRUD.save"); It's not needed explicit saving of the main entity
    assertNoErrors();

    // Verifying that product 2 has no images
    execute("Navigation.next");
    assertValue("number", "2");
    execute("Gallery.edit", "galleryProperty=photos");
    assertNoErrors();
    assertMessage("No images");
    assertNoAction("Gallery.maximizeImage");
    assertNoAction("Gallery.minimizeImage");
    assertNoAction("Gallery.removeImage");
    assertEquals(
        "Images count does not match", 0, getForm().getInputsByName("xava.GALLERY.images").size());
    execute("Gallery.return");

    // Verifying that product 1 has the added image
    execute("CRUD.new");
    setValue("number", "1");
    execute("CRUD.refresh");
    assertNoErrors();
    execute("Gallery.edit", "galleryProperty=photos");
    assertNoErrors();
    assertNoMessages();
    assertAction("Gallery.maximizeImage");
    assertNoAction("Gallery.minimizeImage");
    assertAction("Gallery.removeImage");
    assertEquals(
        "Images count does not match", 1, getForm().getInputsByName("xava.GALLERY.images").size());
    String imageOid = getForm().getInputByName("xava.GALLERY.images").getValueAttribute();

    // Maximizing the image
    execute("Gallery.maximizeImage", "oid=" + imageOid);
    assertNoErrors();
    assertNoAction("Gallery.maximizeImage");
    assertAction("Gallery.minimizeImage");
    assertNoAction("Gallery.removeImage");

    // Minimizing the image
    execute("Gallery.minimizeImage");
    assertNoErrors();
    assertAction("Gallery.maximizeImage");
    assertNoAction("Gallery.minimizeImage");
    assertAction("Gallery.removeImage");
    assertEquals(
        "Images count does not match", 1, getForm().getInputsByName("xava.GALLERY.images").size());

    // Verifying read-only
    execute("Gallery.return");
    execute("EditableOnOff.setOff");
    execute("Gallery.edit", "galleryProperty=photos");
    assertNoErrors();
    assertNoMessages();
    assertNoAction("Gallery.addImage");
    assertAction("Gallery.maximizeImage");
    assertNoAction("Gallery.minimizeImage");
    assertNoAction("Gallery.removeImage");
    assertEquals(
        "Images count does not match", 1, getForm().getInputsByName("xava.GALLERY.images").size());
    execute("Return.return");
    execute("EditableOnOff.setOn");

    // Removing the image
    execute("Gallery.edit", "galleryProperty=photos");
    assertEquals(
        "Images count does not match", 1, getForm().getInputsByName("xava.GALLERY.images").size());
    execute("Gallery.removeImage", "oid=" + imageOid);
    assertNoErrors();
    assertNoAction("Gallery.maximizeImage");
    assertNoAction("Gallery.minimizeImage");
    assertNoAction("Gallery.removeImage");
    assertEquals(
        "Images count does not match", 0, getForm().getInputsByName("xava.GALLERY.images").size());

    // Verifying that product 1 has no images
    execute("Gallery.return");
    execute("CRUD.new");
    setValue("number", "1");
    execute("CRUD.refresh");
    assertNoErrors();
    execute("Gallery.edit", "galleryProperty=photos");
    assertNoErrors();
    assertMessage("No images");
    assertEquals(
        "Images count does not match", 0, getForm().getInputsByName("xava.GALLERY.images").size());
  }