예제 #1
0
  @Test
  public void addSimpleTest() {

    // we prepare the service implementing add-simple
    ImageServiceImpl imageService = new ImageServiceImpl();
    ImageDaoImpl dao = new ImageDaoImpl();
    dao.setSessionManager(sessionManager);
    imageService.setDao(dao);

    // we prepare the resource to send
    File imageFile =
        new File(this.getClass().getClassLoader().getResource("piwigo_org.png").getPath());
    //	File imageFile = new File("piwigo_org.png");
    Integer categoryTest = 98;
    String title = "title" + System.currentTimeMillis();
    try {
      imageService.addSimple(imageFile, categoryTest, title);
    } catch (JiwigoException e) {
      Assert.fail("An exception was thrown while trying to send the pictures" + e.getMessage());
    }

    // the image should be sent, let's check if piwigo added it to the category.
    boolean found = false;
    List<Image> listByCategory;
    try {
      listByCategory = imageService.listByCategory(categoryTest, true);
      for (Image image : listByCategory) {
        if (image.getName().equals(title)) {
          found = true;
          break;
        }
      }
    } catch (Exception e) {
      Assert.fail(
          "An exception was thrown while trying to fetch the pictures from category "
              + categoryTest
              + "exception was : "
              + e.getMessage());
    }
    Assert.assertTrue("The picture just sent could not be found", found);
  }