Exemplo n.º 1
0
  public void testGetPhotosetsViaMockService() throws Exception {

    Photo photo1 = (Photo) EasyMock.createStrictMock(Photo.class);
    EasyMock.expect(photo1.getId()).andReturn("dummyId1");
    Photo photo2 = (Photo) EasyMock.createStrictMock(Photo.class);
    EasyMock.expect(photo2.getId()).andReturn("dummyId2");

    List photosetsPhotos1 = new ArrayList();
    photosetsPhotos1.add(photo1);
    List photosetsPhotos2 = new ArrayList();
    photosetsPhotos2.add(photo2);

    PhotosetsInterface photosetsInterface =
        (PhotosetsInterface) EasyMock.createStrictMock(PhotosetsInterface.class);
    EasyMock.expect(photosetsInterface.getPhotos("711101")).andReturn(photosetsPhotos1);
    EasyMock.expect(photosetsInterface.getPhotos("711155")).andReturn(photosetsPhotos2);

    PhotosInterface photosInterface =
        (PhotosInterface) EasyMock.createStrictMock(PhotosInterface.class);
    EasyMock.expect(photosInterface.getSizes("dummyId1")).andReturn(new ArrayList());
    EasyMock.expect(photosInterface.getSizes("dummyId2")).andReturn(new ArrayList());

    Flickr flickr = (Flickr) EasyMock.createStrictMock(Flickr.class);
    EasyMock.expect(flickr.getPhotosetsInterface()).andReturn(photosetsInterface);
    EasyMock.expect(flickr.getPhotosInterface()).andReturn(photosInterface);

    EasyMock.replay(new Object[] {flickr, photosetsInterface, photosInterface, photo1, photo2});

    FlickrFacade flickrFacade = new FlickrFacade(flickr);
    List photos = flickrFacade.getPhotosFromPhotosets(PHOTOSET_IDS_CSV);
    assertNotNull(photos);
    assertTrue(photos.size() == 2);

    EasyMock.verify(new Object[] {flickr, photosetsInterface, photosInterface, photo1, photo2});
  }
Exemplo n.º 2
0
  public void testGetPhotosViaMockServiceHandlesIOException() throws Exception {

    Photo photo = (Photo) EasyMock.createStrictMock(Photo.class);
    EasyMock.expect(photo.getId()).andReturn("dummyId1");
    EasyMock.expect(photo.getId()).andReturn("dummyId2");
    PhotosInterface photosInterface =
        (PhotosInterface) EasyMock.createStrictMock(PhotosInterface.class);
    EasyMock.expect(photosInterface.getInfo("31670708", null)).andReturn(photo);
    EasyMock.expect(photosInterface.getSizes("dummyId1")).andThrow(new IOException());
    EasyMock.expect(photosInterface.getInfo("31671077", null)).andReturn(photo);
    EasyMock.expect(photosInterface.getSizes("dummyId2")).andThrow(new IOException());
    Flickr flickr = (Flickr) EasyMock.createStrictMock(Flickr.class);
    EasyMock.expect(flickr.getPhotosInterface()).andReturn(photosInterface);

    EasyMock.replay(new Object[] {flickr, photosInterface, photo});

    FlickrFacade flickrFacade = new FlickrFacade(flickr);
    try {
      List photos = flickrFacade.getPhotos(PHOTO_IDS_CSV);
      assertNotNull(photos);
      assertTrue(photos.size() == 0);
    } catch (Exception e) {
      fail("Thrown exception should've been handled by FlickrFacade: " + e);
    }

    EasyMock.verify(new Object[] {flickr, photosInterface, photo});
  }
Exemplo n.º 3
0
  public void testGetPhotosViaMockService() throws Exception {
    Photo photo = (Photo) EasyMock.createStrictMock(Photo.class);
    EasyMock.expect(photo.getId()).andReturn("dummyId1");
    EasyMock.expect(photo.getId()).andReturn("dummyId2");
    PhotosInterface photosInterface =
        (PhotosInterface) EasyMock.createStrictMock(PhotosInterface.class);
    EasyMock.expect(photosInterface.getInfo("31670708", null)).andReturn(photo);
    EasyMock.expect(photosInterface.getSizes("dummyId1")).andReturn(new ArrayList());
    EasyMock.expect(photosInterface.getInfo("31671077", null)).andReturn(photo);
    EasyMock.expect(photosInterface.getSizes("dummyId2")).andReturn(new ArrayList());
    Flickr flickr = (Flickr) EasyMock.createStrictMock(Flickr.class);
    EasyMock.expect(flickr.getPhotosInterface()).andReturn(photosInterface);

    EasyMock.replay(new Object[] {flickr, photosInterface, photo});

    FlickrFacade flickrFacade = new FlickrFacade(flickr);
    List photos = flickrFacade.getPhotos(PHOTO_IDS_CSV);
    assertNotNull(photos);
    assertTrue(photos.size() == PHOTO_IDS_CSV.split(",").length);

    EasyMock.verify(new Object[] {flickr, photosInterface, photo});
  }
Exemplo n.º 4
0
  public void showActivityBB(
      String city,
      double v1x,
      double v1y,
      double v3x,
      double v3y,
      Calendar start,
      Calendar end,
      String output_file)
      throws IOException {

    PrintWriter out = new PrintWriter(new FileWriter(new File(output_file)));

    PhotosInterface pi = f.getPhotosInterface();
    SearchParameters params = new SearchParameters();
    params.setMinTakenDate(start.getTime());
    params.setMaxTakenDate(end.getTime());
    System.out.println(String.valueOf(v1x));
    params.setBBox(
        String.valueOf(v1x), String.valueOf(v1y), String.valueOf(v3x), String.valueOf(v3y));
    params.setHasGeo(true);

    int counter = 0;

    PhotoList list = null;
    try {
      list = pi.search(params, picXpage, 1);
    } catch (FlickrException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    } catch (SAXException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    System.out.println(
        "\nRetrievind data around of "
            + city
            + "from "
            + ""
            + start.getTime()
            + " to "
            + end.getTime());
    System.out.println(list.getTotal() + " pictures being retrieved...");

    for (int k = 1; k <= list.getPages(); k++) {
      try {
        list = pi.search(params, picXpage, k);
      } catch (FlickrException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      } catch (SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      for (int i = 0; i < list.getPerPage(); i++) {

        Photo x = (Photo) list.get(i);
        String description, title = "";
        try {
          x = pi.getInfo(x.getId(), x.getSecret());
        } catch (SAXException e1) {
          // TODO Auto-generated catch block
          e1.printStackTrace();
        } catch (FlickrException e1) {
          // TODO Auto-generated catch block
          e1.printStackTrace();
        }
        // String description=x.getDescription().replace('\n', ' ');
        // String title=x.getTitle().replace('\n', ' ');
        String date =
            DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, Locale.ITALY)
                .format(x.getDateTaken());
        GeoData geo = x.getGeoData();
        String username = x.getOwner().getUsername();
        description = (x.getDescription());
        if (description != null) description = description.replace('\n', ' ');
        title = (x.getTitle());
        if (title != null) title = title.replace('\n', ' ');
        if (geo != null) {
          // out.println(username+"*"+geo.getLatitude()+"*"+geo.getLongitude()+"*"+geo.getAccuracy()+"*"+date);
          if (description != null)
            try {
              // Convert from Unicode to UTF-8
              // String string = "abc\u5639\u563b";
              byte[] utf8 = description.getBytes("UTF-8");

              // Convert from UTF-8 to Unicode
              description = new String(utf8, "UTF-8");
              System.out.println(description);
            } catch (UnsupportedEncodingException e) {
              System.out.println(e);
            }

          out.println(
              username
                  + "\t"
                  + title
                  + "\t"
                  + description
                  + "\t"
                  + geo.getLatitude()
                  + "\t"
                  + geo.getLongitude()
                  + "\t"
                  + geo.getAccuracy()
                  + "\t"
                  + date);
          counter++;
        } else {
          try {
            Iterator<Exif> iter = pi.getExif(x.getId(), x.getSecret()).iterator();
            while (iter.hasNext()) {
              Exif exif = iter.next();
              String raw = exif.getLabel() + " " + exif.getRaw();
              if (raw.contains("atitude")
                  || raw.contains("ongitude")) // avoid 1st letter for case sensitive
              System.out.println("!!! " + exif.getLabel() + " " + exif.getRaw());
            }
          } catch (Exception e) {

          }
          System.out.println("broken picture @ page= " + k + " pic= " + i);
        }
      }
      System.out.println(
          (100 * k) / list.getPages()
              + "% Complete. Pictures "
              + counter
              + " on "
              + list.getTotal());
    }
    out.close();
  }