Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.croz.csmi.dao.connect.facebook
- import org.joda.time.{ DateTime, DateTimeZone, Interval }
- import org.springframework.beans.factory.annotation.Autowired
- import org.springframework.social.facebook.api.Facebook
- import org.springframework.stereotype.Service
- import com.restfb.FacebookClient
- import net.croz.csmi.{ BaseUnitTest, TestContext }
- import net.croz.csmi.domain.configuration.{ FacebookObjectConnectConfiguration, FacebookSearchConnectConfiguration, FacebookUrlConnectConfiguration }
- import net.croz.csmi.domain.connect.facebook.{ FacebookComment, FacebookPost }
- import net.croz.csmi.domain.connect.facebook.FacebookComment
- import net.croz.csmi.domain.connect.facebook.FacebookPost
- import net.croz.csmi.domain.connect.facebook.FacebookComment
- class DefaultFacebookConnectorDaoIntegrationTest extends BaseUnitTest with TestContext {
- val facebook = context getBean (classOf[Facebook])
- val facebookClient = context getBean (classOf[FacebookClient])
- val facebookConnectorDao = new DefaultFacebookConnectorDao(facebookClient, facebook)
- val facebookPost1 = new FacebookPost(
- "316570575177906_316570891844541",
- "316570575177906", "CSMI",
- "Prvi post na stranici",
- (new DateTime(2014, 7, 24, 15, 6, 25, DateTimeZone.forID("Europe/Belgrade"))),
- (new DateTime(2014, 7, 24, 16, 5, 43, DateTimeZone.forID("Europe/Belgrade"))),
- "316570575177906", "Csmitestpage", None, true, 0, 0, "")
- val facebookPost2 = new FacebookPost(
- "316570575177906_316574498510847",
- "316570575177906", "CSMI",
- "Jos jedan post",
- (new DateTime(2014, 7, 24, 15, 13, 14, DateTimeZone.forID("Europe/Belgrade"))),
- (new DateTime(2014, 9, 22, 12, 27, 8, DateTimeZone.forID("Europe/Belgrade"))),
- "316570575177906", "Csmitestpage", None, true, 0, 0, "")
- // Post without message (created with first post)
- val facebookPostEmpty1 = new FacebookPost(
- "316570575177906_316570591844571",
- "316570575177906", "CSMI",
- "",
- (new DateTime(2014, 7, 24, 15, 5, 38, DateTimeZone.forID("Europe/Belgrade"))),
- (new DateTime(2014, 7, 24, 15, 5, 38, DateTimeZone.forID("Europe/Belgrade"))),
- "316570575177906", "Csmitestpage", None, true, 0, 0, "")
- // Post without message (created with first comment)
- val facebookPostEmpty2 = new FacebookPost(
- "316570575177906_316600641841566",
- "316570575177906", "CSMI",
- "",
- (new DateTime(2014, 7, 24, 15, 55, 40, DateTimeZone.forID("Europe/Belgrade"))),
- (new DateTime(2014, 7, 24, 15, 55, 40, DateTimeZone.forID("Europe/Belgrade"))),
- "316570575177906", "Csmitestpage", None, true, 0, 0, "")
- // Post created automatically (when setting birthday)
- val facebookPostEmpty3 = new FacebookPost(
- "316570575177906_352844714883825",
- "316570575177906", "CSMI",
- "",
- (new DateTime(2014, 9, 22, 12, 2, 7, DateTimeZone.forID("Europe/Belgrade"))),
- (new DateTime(2014, 9, 22, 12, 2, 7, DateTimeZone.forID("Europe/Belgrade"))),
- "316570575177906", "Csmitestpage", None, true, 0, 0, "")
- // it should "work" in {
- // val configuration = new FacebookObjectConnectConfiguration(
- // new Interval(new DateTime(2014, 8, 22, 12, 2, 7, DateTimeZone.forID("Europe/Belgrade")),
- // new DateTime()), "VivasBar.hr", "source", "")
- //
- // val posts = facebookConnectorDao.fetchAllPostsFor(configuration)
- // val comments = facebookConnectorDao fetchAllCommentsFor (configuration, posts.map(_.id))
- //
- // comments.foreach { comment =>
- // val user = facebook.userOperations.getUserProfile(comment.fromId)
- // println(user.getGender() + " - " + user.getLocale())
- // }
- // }
- it should "fetch all posts for Csmitestpage" in {
- val configuration = new FacebookObjectConnectConfiguration(1, new Interval(new DateTime(0), new DateTime), "316570575177906", "CSMI", "")
- val posts = facebookConnectorDao fetchAllPostsFor configuration
- posts.foreach(p => println(p.fromGender))
- posts should contain only (facebookPost1, facebookPost2, facebookPostEmpty1, facebookPostEmpty2, facebookPostEmpty3)
- }
- it should "fetch all comments for facebookPost1, facebookPost2" in {
- val configuration = new FacebookUrlConnectConfiguration(1, new Interval(new DateTime(0), new DateTime), "316570575177906", "CSMI", "")
- val comments = facebookConnectorDao fetchAllCommentsFor (configuration, List(facebookPost1.id.toString, facebookPost2.id.toString))
- val facebookComment1 = new FacebookComment(
- "316570891844541_316605608507736",
- "316570575177906", "CSMI", "316570575177906_316570891844541",
- "komentar",
- (new DateTime(2014, 7, 24, 16, 5, 43, DateTimeZone.forID("Europe/Belgrade"))),
- "316570575177906", "Csmitestpage", None, true, 0, "")
- val facebookComment2 = new FacebookComment(
- "316574498510847_316600635174900",
- "316570575177906", "CSMI", "316570575177906_316574498510847",
- "komentar na drugi post",
- (new DateTime(2014, 7, 24, 15, 55, 40, DateTimeZone.forID("Europe/Belgrade"))),
- "316570575177906", "Csmitestpage", None, true, 0, "")
- val facebookComment3 = new FacebookComment(
- "316574498510847_352852151549748",
- "316570575177906", "CSMI", "316570575177906_316574498510847",
- "komentar korisnika",
- (new DateTime(2014, 9, 22, 12, 27, 8, DateTimeZone.forID("Europe/Belgrade"))),
- "100006417347473", "Csmi Integrationtest", Some("male"), true, 0, "")
- val facebookComment4 = new FacebookComment(
- "316574498510847_352884148213215",
- "316570575177906", "CSMI", "316570575177906_316574498510847",
- "komentar",
- (new DateTime(2014, 9, 22, 14, 32, 4, DateTimeZone.forID("Europe/Belgrade"))),
- "1128012474", "Domagoj Krivošić", Some("male"), false, 0, "")
- comments should have size 4
- comments should contain only (facebookComment1, facebookComment2, facebookComment3, facebookComment4)
- }
- it should "fetch facebookPost1, facebookPost2 by ids" in {
- val configuration = new FacebookObjectConnectConfiguration(1, new Interval(new DateTime(0), new DateTime), "316570575177906", "CSMI", "")
- // TODO: actually test if all returned posts are defined
- val posts = facebookConnectorDao fetchPostsBy (configuration, List(facebookPost1.id.toString, facebookPost2.id.toString)) map (_.get)
- posts should have size 2
- posts should contain only (facebookPost1, facebookPost2)
- }
- ignore should "search by" in {
- val configuration = new FacebookSearchConnectConfiguration(1, new Interval((new DateTime).minusMinutes(5), new DateTime), "facebook", "search", "")
- val results = facebookConnectorDao searchBy configuration
- results should not be empty
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement