use of twitter4j.conf.PropertyConfiguration in project twitter4j by yusuke.
the class SiteStreamsTest method testSiteStream.
public void testSiteStream() throws Exception {
InputStream is = SiteStreamsTest.class.getResourceAsStream("/sitestream-test.properties");
if (null == is) {
System.out.println("sitestream-test.properties not found. skipping Site Streams test.");
} else {
Properties props = new Properties();
props.load(is);
is.close();
Configuration yusukeyConf = new PropertyConfiguration(props, "/yusukey");
Configuration twit4jConf = new PropertyConfiguration(props, "/id1");
Configuration twit4j2Conf = new PropertyConfiguration(props, "/id2");
TwitterStream twitterStream = new TwitterStreamFactory(yusukeyConf).getInstance();
twitterStream.addListener(this);
Twitter twit4j = new TwitterFactory(twit4jConf).getInstance();
Twitter twit4j2 = new TwitterFactory(twit4j2Conf).getInstance();
try {
twit4j.destroyBlock(6377362);
} catch (TwitterException ignore) {
}
try {
twit4j2.destroyBlock(6358482);
} catch (TwitterException ignore) {
}
try {
twit4j.createFriendship(6377362);
} catch (TwitterException ignore) {
}
try {
twit4j2.createFriendship(6358482);
} catch (TwitterException ignore) {
}
//twit4j: 6358482
//twit4j2: 6377362
StreamController cs = twitterStream.site(true, 6377362, 4933401);
//expecting onFriendList for twit4j and twit4j2
waitForStatus("onFriendList");
ControlStreamInfo info = cs.getInfo();
assertEquals(2, info.getUsers().length);
cs.addUsers(6358482L);
waitForStatus("new User");
info = cs.getInfo();
assertEquals(3, info.getUsers().length);
StreamController.FriendsIDs ids = cs.getFriendsIDs(4933401L, -1);
assertTrue(ids.getIds().length > 100);
assertEquals("yusuke", ids.getUser().getName());
cs.removeUsers(4933401L);
waitForStatus("remove user");
Status status = twit4j2.updateStatus("@twit4j " + new Date());
//expecting onStatus for twit4j from twit4j
waitForStatus("update status");
twit4j.createFavorite(status.getId());
waitForStatus("crate favorite");
twit4j.destroyFavorite(status.getId());
waitForStatus("destroy favorite");
// unfollow twit4j
twit4j2.destroyFriendship(6358482);
waitForStatus("destroy friendship");
// follow twit4j
twit4j2.createFriendship(6358482);
waitForStatus("create friendship");
// unfollow twit4j2
twit4j.destroyFriendship(6377362);
// follow twit4j2
twit4j.createFriendship(6377362);
waitForStatus("create friendship");
twit4j.retweetStatus(status.getId());
waitForStatus("retweeet status");
DirectMessage dm = twit4j.sendDirectMessage(42419133, "test " + new Date());
waitForStatus("dm");
twitter2.destroyStatus(status.getId());
waitForStatus("destory status");
// twitter1.destroyDirectMessage(dm.getId());
// waitForStatus();
// block twit4j
twit4j2.createBlock(6358482);
waitForStatus("create block");
// unblock twit4j
twit4j2.destroyBlock(6358482);
waitForStatus("destroy block");
try {
twit4j.createFriendship(6377362);
waitForStatus("create friendship");
} catch (TwitterException ignore) {
}
try {
twit4j2.createFriendship(6358482);
waitForStatus("create friendship");
} catch (TwitterException ignore) {
}
twitter1.updateProfile(null, null, new Date().toString(), null);
waitForStatus("update profile");
UserList list = twit4j.createUserList("test", true, "desctription");
waitForStatus("create userlist");
list = twit4j.updateUserList(list.getId(), "test2", true, "description2");
waitForStatus("update userlist");
twit4j.createUserListMember(list.getId(), id2.id);
waitForStatus("create userlist member");
twit4j2.createUserListSubscription(list.getId());
waitForStatus("create userlist subscription");
twit4j2.destroyUserListSubscription(list.getId());
waitForStatus("destroy userlist subscription");
twit4j.destroyUserListMember(list.getId(), id2.id);
waitForStatus("destroy userlist member");
twit4j.destroyUserList(list.getId());
waitForStatus("destroy userlist");
assertReceived("onstatus", "onstatus");
assertReceived("onfriendlist", "onfriendlist");
assertReceived("onFavorite", TwitterMethod.CREATE_FAVORITE);
assertReceived("onUnfavorite", TwitterMethod.DESTROY_FAVORITE);
// assertReceived(TwitterMethod.RETWEET_STATUS);
// assertReceived("onDirectMessage", TwitterMethod.SEND_DIRECT_MESSAGE);
assertReceived("onDeletionNotice-status", TwitterMethod.DESTROY_STATUS);
// assertReceived("onDeletionNotice-directmessage", TwitterMethod.DESTROY_DIRECT_MESSAGE);
assertReceived("onUserListMemberAddition", TwitterMethod.CREATE_LIST_MEMBER);
assertReceived("onUserListMemberDeletion", TwitterMethod.DESTROY_LIST_MEMBER);
assertReceived("onUserListSubscribed", TwitterMethod.SUBSCRIBE_LIST);
assertReceived("onUserListUnsubscribed", TwitterMethod.UNSUBSCRIBE_LIST);
assertReceived("onUserListCreated", TwitterMethod.CREATE_USER_LIST);
assertReceived("onUserListUpdated", TwitterMethod.UPDATE_USER_LIST);
assertReceived("onUserListDestoyed", TwitterMethod.DESTROY_USER_LIST);
assertReceived("onUserProfileUpdated", TwitterMethod.UPDATE_PROFILE);
assertReceived("onBlock", TwitterMethod.CREATE_BLOCK);
assertReceived("onUnblock", TwitterMethod.DESTROY_BLOCK);
assertReceived("onFollow", TwitterMethod.CREATE_FRIENDSHIP);
assertReceived("onUnfollow", TwitterMethod.DESTROY_FRIENDSHIP);
}
}
use of twitter4j.conf.PropertyConfiguration in project twitter4j by yusuke.
the class OAuthTest method testXAuth.
public void testXAuth() throws Exception {
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey(desktopConsumerKey);
builder.setOAuthConsumerSecret(desktopConsumerSecret);
Twitter twitter = new TwitterFactory(builder.build()).getInstance();
try {
twitter.getOAuthAccessToken(id1.screenName, id2.password);
fail("expecting TwitterException");
} catch (TwitterException te) {
// id1 doesn't have access to xAuth
assertEquals(403, te.getStatusCode());
}
InputStream is = OAuthTest.class.getResourceAsStream("/xauth-test.properties");
if (null == is) {
System.out.println("xauth-test.properties not found. skipping xAuth test.");
} else {
Properties props = new Properties();
props.load(is);
Configuration conf = new PropertyConfiguration(props);
twitter = new TwitterFactory(conf).getInstance();
twitter.getOAuthAccessToken(id1.screenName, id1.password);
twitter.updateStatus(new Date() + ": xAuth test.");
twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(conf.getOAuthConsumerKey(), conf.getOAuthConsumerSecret());
twitter.getOAuthAccessToken(id1.screenName, id1.password);
}
}
use of twitter4j.conf.PropertyConfiguration in project twitter4j by yusuke.
the class TwitterTestBase method setUp.
protected void setUp() throws Exception {
super.setUp();
InputStream is = TwitterTestBase.class.getResourceAsStream("/test.properties");
p.load(is);
is.close();
desktopConsumerSecret = p.getProperty("oauth.consumerSecret");
desktopConsumerKey = p.getProperty("oauth.consumerKey");
browserConsumerSecret = p.getProperty("browser.oauth.consumerSecret");
browserConsumerKey = p.getProperty("browser.oauth.consumerKey");
conf1 = new PropertyConfiguration(p, "/id1");
id1 = new TestUserInfo("id1");
conf2 = new PropertyConfiguration(p, "/id2");
id2 = new TestUserInfo("id2");
conf3 = new PropertyConfiguration(p, "/id3");
id3 = new TestUserInfo("id3");
bestFriend1Conf = new PropertyConfiguration(p, "/bestFriend1");
bestFriend1 = new TestUserInfo("bestFriend1");
bestFriend2Conf = new PropertyConfiguration(p, "/bestFriend2");
bestFriend2 = new TestUserInfo("bestFriend2");
numberId = p.getProperty("numberid.user");
numberPass = p.getProperty("numberid.password");
// id1id = Integer.valueOf(p.getProperty("id1id"));
numberIdId = Integer.valueOf(p.getProperty("numberid.id"));
twitter1 = new TwitterFactory(conf1).getInstance();
twitter2 = new TwitterFactory(conf2).getInstance();
twitter3 = new TwitterFactory(conf3).getInstance();
twitterAPIBestFriend1 = new TwitterFactory(bestFriend1Conf).getInstance();
twitterAPIBestFriend2 = new TwitterFactory(bestFriend2Conf).getInstance();
unauthenticated = new TwitterFactory().getInstance();
followsOneWay = p.getProperty("followsOneWay");
}
Aggregations