Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TFJ-611 fix direct message resources test case
separate TwitterTest
- Loading branch information
Showing
25 changed files
with
1,927 additions
and
1,302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
twitter4j-core/src/test/java/twitter4j/AccountMethodsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
/* | ||
* Copyright 2007 Yusuke Yamamoto | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package twitter4j; | ||
|
||
import twitter4j.json.DataObjectFactory; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.util.Date; | ||
|
||
/** | ||
* @author Yusuke Yamamoto - yusuke at mac.com | ||
* @since Twitter4J 2.2.4 | ||
*/ | ||
public class AccountMethodsTest extends TwitterTestBase { | ||
public AccountMethodsTest(String name) { | ||
super(name); | ||
} | ||
|
||
|
||
protected void setUp() throws Exception { | ||
super.setUp(); | ||
} | ||
|
||
protected void tearDown() throws Exception { | ||
super.tearDown(); | ||
} | ||
|
||
public void testAccountMethods() throws Exception { | ||
User original = twitter1.verifyCredentials(); | ||
assertNotNull(DataObjectFactory.getRawJSON(original)); | ||
assertEquals(original, DataObjectFactory.createUser(DataObjectFactory.getRawJSON(original))); | ||
if (original.getScreenName().endsWith("new") || | ||
original.getName().endsWith("new")) { | ||
original = twitter1.updateProfile( | ||
"twit4j", "http://yusuke.homeip.net/twitter4j/" | ||
, "location:", "Hi there, I do test a lot!new"); | ||
|
||
} | ||
String newName, newURL, newLocation, newDescription; | ||
String neu = "new"; | ||
newName = original.getName() + neu; | ||
newURL = original.getURL() + neu; | ||
newLocation = new Date().toString(); | ||
newDescription = original.getDescription() + neu; | ||
|
||
User altered = twitter1.updateProfile( | ||
newName, newURL, newLocation, newDescription); | ||
assertNotNull(DataObjectFactory.getRawJSON(altered)); | ||
assertEquals(original, DataObjectFactory.createUser(DataObjectFactory.getRawJSON(original))); | ||
assertEquals(altered, DataObjectFactory.createUser(DataObjectFactory.getRawJSON(altered))); | ||
twitter1.updateProfile(original.getName(), original.getURL().toString(), original.getLocation(), original.getDescription()); | ||
assertEquals(newName, altered.getName()); | ||
assertEquals(newURL, altered.getURL().toString()); | ||
assertEquals(newLocation, altered.getLocation()); | ||
assertEquals(newDescription, altered.getDescription()); | ||
|
||
assertTrue(twitterAPIBestFriend1.existsFriendship(bestFriend1.screenName, bestFriend2.screenName)); | ||
assertFalse(twitter1.existsFriendship(id1.screenName, "al3x")); | ||
|
||
User eu; | ||
eu = twitter1.updateProfileColors("f00", "f0f", "0ff", "0f0", "f0f"); | ||
assertNotNull(DataObjectFactory.getRawJSON(eu)); | ||
assertEquals(eu, DataObjectFactory.createUser(DataObjectFactory.getRawJSON(eu))); | ||
assertEquals("f00", eu.getProfileBackgroundColor()); | ||
assertEquals("f0f", eu.getProfileTextColor()); | ||
assertEquals("0ff", eu.getProfileLinkColor()); | ||
assertEquals("0f0", eu.getProfileSidebarFillColor()); | ||
assertEquals("f0f", eu.getProfileSidebarBorderColor()); | ||
assertTrue(eu.isProfileUseBackgroundImage()); | ||
assertFalse(eu.isShowAllInlineMedia()); | ||
assertTrue(0 <= eu.getListedCount()); | ||
eu = twitter1.updateProfileColors("87bc44", "9ae4e8", "000000", "0000ff", "e0ff92"); | ||
assertNotNull(DataObjectFactory.getRawJSON(eu)); | ||
assertEquals(eu, DataObjectFactory.createUser(DataObjectFactory.getRawJSON(eu))); | ||
assertEquals("87bc44", eu.getProfileBackgroundColor()); | ||
assertEquals("9ae4e8", eu.getProfileTextColor()); | ||
assertEquals("000000", eu.getProfileLinkColor()); | ||
assertEquals("0000ff", eu.getProfileSidebarFillColor()); | ||
assertEquals("e0ff92", eu.getProfileSidebarBorderColor()); | ||
|
||
AccountTotals totals = twitter1.getAccountTotals(); | ||
assertTrue(0 < totals.getFavorites()); | ||
assertTrue(0 < totals.getFollowers()); | ||
assertTrue(0 < totals.getFriends()); | ||
assertTrue(0 < totals.getUpdates()); | ||
assertEquals(totals, DataObjectFactory.createAccountTotals(DataObjectFactory.getRawJSON(totals))); | ||
|
||
AccountSettings settings = twitter1.getAccountSettings(); | ||
assertTrue(settings.isSleepTimeEnabled()); | ||
assertTrue(settings.isGeoEnabled()); | ||
assertEquals("en", settings.getLanguage()); | ||
assertEquals("Rome", settings.getTimeZone().getName()); | ||
assertTrue(settings.isAlwaysUseHttps()); | ||
assertFalse(settings.isDiscoverableByEmail()); | ||
Location[] locations = settings.getTrendLocations(); | ||
assertTrue(0 < locations.length); | ||
|
||
AccountSettings intermSettings = twitter1.updateAccountSettings(1 /* GLOBAL */, true, | ||
"23", "08", "Helsinki", "it"); | ||
assertTrue(intermSettings.isSleepTimeEnabled()); | ||
assertEquals(intermSettings.getSleepStartTime(), "23"); | ||
assertEquals(intermSettings.getSleepEndTime(), "8"); | ||
assertTrue(intermSettings.isGeoEnabled()); | ||
assertEquals("it", intermSettings.getLanguage()); | ||
assertTrue(intermSettings.isAlwaysUseHttps()); | ||
assertFalse(intermSettings.isDiscoverableByEmail()); | ||
assertEquals("Helsinki", intermSettings.getTimeZone().getName()); | ||
Location[] intermLocations = intermSettings.getTrendLocations(); | ||
assertTrue(0 < intermLocations.length); | ||
|
||
AccountSettings lastSettings = twitter1.updateAccountSettings(settings.getTrendLocations()[0].getWoeid(), settings.isSleepTimeEnabled(), | ||
settings.getSleepStartTime(), settings.getSleepStartTime(), settings.getTimeZone().getName(), settings.getLanguage()); | ||
assertEquals(settings.getLanguage(), lastSettings.getLanguage()); | ||
assertEquals(settings.isSleepTimeEnabled(), lastSettings.isSleepTimeEnabled()); | ||
assertEquals(settings.getTimeZone().getName(), lastSettings.getTimeZone().getName()); | ||
assertEquals(settings.getSleepEndTime(), lastSettings.getSleepEndTime()); | ||
} | ||
|
||
public void testAccountProfileImageUpdates() throws Exception { | ||
User user = twitter1.updateProfileImage(new FileInputStream(getRandomlyChosenFile())); | ||
assertNotNull(DataObjectFactory.getRawJSON(user)); | ||
// tile randomly | ||
User user2 = twitter1.updateProfileBackgroundImage(getRandomlyChosenFile(), | ||
(5 < System.currentTimeMillis() % 5)); | ||
assertNotNull(DataObjectFactory.getRawJSON(user2)); | ||
assertEquals(user2, DataObjectFactory.createUser(DataObjectFactory.getRawJSON(user2))); | ||
} | ||
|
||
static final String[] files = {"src/test/resources/t4j-reverse.jpeg", | ||
"src/test/resources/t4j-reverse.png", | ||
"src/test/resources/t4j-reverse.gif", | ||
"src/test/resources/t4j.jpeg", | ||
"src/test/resources/t4j.png", | ||
"src/test/resources/t4j.gif", | ||
}; | ||
|
||
private static File getRandomlyChosenFile() { | ||
int rand = (int) (System.currentTimeMillis() % 6); | ||
File file = new File(files[rand]); | ||
if (!file.exists()) { | ||
file = new File("twitter4j-core/" + files[rand]); | ||
} | ||
return file; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
twitter4j-core/src/test/java/twitter4j/BlockMethodsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2007 Yusuke Yamamoto | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package twitter4j; | ||
|
||
import twitter4j.json.DataObjectFactory; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author Yusuke Yamamoto - yusuke at mac.com | ||
* @since Twitter4J 2.2.4 | ||
*/ | ||
public class BlockMethodsTest extends TwitterTestBase { | ||
public BlockMethodsTest(String name) { | ||
super(name); | ||
} | ||
|
||
protected void setUp() throws Exception { | ||
super.setUp(); | ||
} | ||
|
||
protected void tearDown() throws Exception { | ||
super.tearDown(); | ||
} | ||
|
||
public void testBlockMethods() throws Exception { | ||
User user1 = twitter2.createBlock(id1.screenName); | ||
assertNotNull(DataObjectFactory.getRawJSON(user1)); | ||
assertEquals(user1, DataObjectFactory.createUser(DataObjectFactory.getRawJSON(user1))); | ||
User user2 = twitter2.destroyBlock(id1.screenName); | ||
assertNotNull(DataObjectFactory.getRawJSON(user2)); | ||
assertEquals(user2, DataObjectFactory.createUser(DataObjectFactory.getRawJSON(user2))); | ||
assertFalse(twitter1.existsBlock("twit4j2")); | ||
assertTrue(twitter1.existsBlock("twit4jblock")); | ||
List<User> users = twitter1.getBlockingUsers(); | ||
assertNotNull(DataObjectFactory.getRawJSON(users)); | ||
assertEquals(users.get(0), DataObjectFactory.createUser(DataObjectFactory.getRawJSON(users.get(0)))); | ||
assertEquals(1, users.size()); | ||
assertEquals(39771963, users.get(0).getId()); | ||
users = twitter1.getBlockingUsers(1); | ||
assertNotNull(DataObjectFactory.getRawJSON(users)); | ||
assertEquals(users.get(0), DataObjectFactory.createUser(DataObjectFactory.getRawJSON(users.get(0)))); | ||
assertEquals(1, users.size()); | ||
assertEquals(39771963, users.get(0).getId()); | ||
|
||
IDs ids = twitter1.getBlockingUsersIDs(); | ||
assertNull(DataObjectFactory.getRawJSON(users)); | ||
assertNotNull(DataObjectFactory.getRawJSON(ids)); | ||
assertEquals(1, ids.getIDs().length); | ||
assertEquals(39771963, ids.getIDs()[0]); | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
twitter4j-core/src/test/java/twitter4j/DirectMessageMethodsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2007 Yusuke Yamamoto | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package twitter4j; | ||
|
||
import twitter4j.json.DataObjectFactory; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Yusuke Yamamoto - yusuke at mac.com | ||
* @since Twitter4J 2.2.4 | ||
*/ | ||
public class DirectMessageMethodsTest extends TwitterTestBase { | ||
public DirectMessageMethodsTest(String name) { | ||
super(name); | ||
} | ||
|
||
protected void setUp() throws Exception { | ||
super.setUp(); | ||
} | ||
|
||
protected void tearDown() throws Exception { | ||
super.tearDown(); | ||
} | ||
|
||
public void testDirectMessages() throws Exception { | ||
String expectedReturn = new Date() + ":directmessage test"; | ||
DirectMessage actualReturn = twitter1.sendDirectMessage(id3.id, expectedReturn); | ||
assertTrue(0 <= actualReturn.getId()); | ||
assertNotNull(DataObjectFactory.getRawJSON(actualReturn)); | ||
assertEquals(actualReturn, DataObjectFactory.createDirectMessage(DataObjectFactory.getRawJSON(actualReturn))); | ||
assertEquals(expectedReturn, actualReturn.getText()); | ||
assertEquals(id1.screenName, actualReturn.getSender().getScreenName()); | ||
assertEquals(id3.screenName, actualReturn.getRecipient().getScreenName()); | ||
List<DirectMessage> actualReturnList = twitter3.getDirectMessages(); | ||
assertNotNull(DataObjectFactory.getRawJSON(actualReturnList)); | ||
assertEquals(actualReturnList.get(0), DataObjectFactory.createDirectMessage(DataObjectFactory.getRawJSON(actualReturnList.get(0)))); | ||
assertTrue(1 <= actualReturnList.size()); | ||
try { | ||
actualReturn = twitter1.showDirectMessage(actualReturnList.get(0).getId()); | ||
} catch (TwitterException te) { | ||
// twitter1 is not allowed to access or delete your direct messages | ||
assertEquals(403, te.getStatusCode()); | ||
} | ||
actualReturn = twitter3.showDirectMessage(actualReturnList.get(0).getId()); | ||
assertNotNull(DataObjectFactory.getRawJSON(actualReturn)); | ||
assertEquals(actualReturn, DataObjectFactory.createDirectMessage(DataObjectFactory.getRawJSON(actualReturn))); | ||
assertEquals(actualReturnList.get(0).getId(), actualReturn.getId()); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
twitter4j-core/src/test/java/twitter4j/FavoriteMethodsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2007 Yusuke Yamamoto | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package twitter4j; | ||
|
||
import twitter4j.json.DataObjectFactory; | ||
|
||
/** | ||
* @author Yusuke Yamamoto - yusuke at mac.com | ||
* @since Twitter4J 2.2.4 | ||
*/ | ||
public class FavoriteMethodsTest extends TwitterTestBase { | ||
public FavoriteMethodsTest(String name) { | ||
super(name); | ||
} | ||
|
||
protected void setUp() throws Exception { | ||
super.setUp(); | ||
} | ||
|
||
protected void tearDown() throws Exception { | ||
super.tearDown(); | ||
} | ||
|
||
public void testFavoriteMethods() throws Exception { | ||
Status status = twitter1.getHomeTimeline(new Paging().count(1)).get(0); | ||
assertNotNull(DataObjectFactory.getRawJSON(status)); | ||
assertEquals(status, DataObjectFactory.createStatus(DataObjectFactory.getRawJSON(status))); | ||
status = twitter2.createFavorite(status.getId()); | ||
assertNotNull(DataObjectFactory.getRawJSON(status)); | ||
assertEquals(status, DataObjectFactory.createStatus(DataObjectFactory.getRawJSON(status))); | ||
assertTrue(twitter2.getFavorites().size() > 0); | ||
try { | ||
twitter2.destroyFavorite(status.getId()); | ||
} catch (TwitterException te) { | ||
// sometimes destorying favorite fails with 404 | ||
assertEquals(404, te.getStatusCode()); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.