ko/archetype/src/main/resources/archetype-resources/src/test/java/TwitterProtocolTest.java
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/ko/archetype/src/main/resources/archetype-resources/src/test/java/TwitterProtocolTest.java Sun Sep 08 11:42:01 2013 +0200
1.3 @@ -0,0 +1,73 @@
1.4 +package ${package};
1.5 +
1.6 +import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
1.7 +import org.apidesign.bck2brwsr.vmtest.Http;
1.8 +import org.apidesign.bck2brwsr.vmtest.VMTest;
1.9 +import org.testng.annotations.Factory;
1.10 +
1.11 +public class TwitterProtocolTest {
1.12 + private TwitterModel page;
1.13 + @Http(@Http.Resource(
1.14 + path = "/search.json",
1.15 + mimeType = "application/json",
1.16 + parameters = {"callback"},
1.17 + content = "$0({\"completed_in\":0.04,\"max_id\":320055706885689344,\"max_id_str\""
1.18 + + ":\"320055706885689344\",\"page\":1,\"query\":\"from%3AJaroslavTulach\",\"refresh_url\":"
1.19 + + "\"?since_id=320055706885689344&q=from%3AJaroslavTulach\","
1.20 + + "\"results\":[{\"created_at\":\"Fri, 05 Apr 2013 06:10:01 +0000\","
1.21 + + "\"from_user\":\"JaroslavTulach\",\"from_user_id\":420944648,\"from_user_id_str\":"
1.22 + + "\"420944648\",\"from_user_name\":\"Jaroslav Tulach\",\"geo\":null,\"id\":320055706885689344,"
1.23 + + "\"id_str\":\"320055706885689344\",\"iso_language_code\":\"en\",\"metadata\":{\"result_type\":"
1.24 + + "\"recent\"},\"profile_image_url\":\"http:\\/\\/a0.twimg.com\\/profile_images\\/1656828312\\/jst_normal.gif\","
1.25 + + "\"profile_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_images\\/1656828312\\/jst_normal.gif\","
1.26 + + "\"source\":\"<a href="http:\\/\\/twitter.com\\/">web<\\/a>\",\"text\":"
1.27 + + "\"@tom_enebo Amzng! Not that I would like #ruby, but I am really glad you guys stabilized the plugin + "
1.28 + + "made it work in #netbeans 7.3! Gd wrk.\",\"to_user\":\"tom_enebo\",\"to_user_id\":14498747,"
1.29 + + "\"to_user_id_str\":\"14498747\",\"to_user_name\":\"tom_enebo\",\"in_reply_to_status_id\":319832359509839872,"
1.30 + + "\"in_reply_to_status_id_str\":\"319832359509839872\"},{\"created_at\":\"Thu, 04 Apr 2013 07:33:06 +0000\","
1.31 + + "\"from_user\":\"JaroslavTulach\",\"from_user_id\":420944648,\"from_user_id_str\":"
1.32 + + "\"420944648\",\"from_user_name\":\"Jaroslav Tulach\",\"geo\":null,\"id\":319714227088678913,"
1.33 + + "\"id_str\":\"319714227088678913\",\"iso_language_code\":\"en\",\"metadata\":{\"result_type\":"
1.34 + + "\"recent\"},\"profile_image_url\":\"http:\\/\\/a0.twimg.com\\/profile_images\\/1656828312\\/jst_normal.gif\","
1.35 + + "\"profile_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_images\\/1656828312\\/jst_normal.gif\","
1.36 + + "\"source\":\"<a href="http:\\/\\/twitter.com\\/">web<\\/a>\",\"text\":"
1.37 + + "\"RT @drkrab: At #erlangfactory @joerl: Frameworks grow in complexity until nobody can use them.\"},"
1.38 + + "{\"created_at\":\"Tue, 02 Apr 2013 07:44:34 +0000\",\"from_user\":\"JaroslavTulach\","
1.39 + + "\"from_user_id\":420944648,\"from_user_id_str\":\"420944648\",\"from_user_name\":\"Jaroslav Tulach\","
1.40 + + "\"geo\":null,\"id\":318992336145248256,\"id_str\":\"318992336145248256\",\"iso_language_code\":\"en\","
1.41 + + "\"metadata\":{\"result_type\":\"recent\"},\"profile_image_url\":"
1.42 + + "\"http:\\/\\/a0.twimg.com\\/profile_images\\/1656828312\\/jst_normal.gif\","
1.43 + + "\"profile_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_images\\/1656828312\\/jst_normal.gif\","
1.44 + + "\"source\":\"<a href="http:\\/\\/twitter.com\\/">web<\\/a>\",\"text\":"
1.45 + + "\"Twitter renamed to twttr http:\\/\\/t.co\\/tqaN4T1xlZ - good, I don't have to rename #bck2brwsr!\"},"
1.46 + + "{\"created_at\":\"Sun, 31 Mar 2013 03:52:04 +0000\",\"from_user\":\"JaroslavTulach\",\"from_user_id\":420944648,"
1.47 + + "\"from_user_id_str\":\"420944648\",\"from_user_name\":\"Jaroslav Tulach\",\"geo\":null,"
1.48 + + "\"id\":318209051223789568,\"id_str\":\"318209051223789568\",\"iso_language_code\":\"en\",\"metadata\":"
1.49 + + "{\"result_type\":\"recent\"},\"profile_image_url\":"
1.50 + + "\"http:\\/\\/a0.twimg.com\\/profile_images\\/1656828312\\/jst_normal.gif\","
1.51 + + "\"profile_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_images\\/1656828312\\/jst_normal.gif\","
1.52 + + "\"source\":\"<a href="http:\\/\\/twitter.com\\/">web<\\/a>\",\"text\":"
1.53 + + "\"Math proofs without words. Ingenious: http:\\/\\/t.co\\/sz7yVbfpGw\"}],\"results_per_page\":100,"
1.54 + + "\"since_id\":0,\"since_id_str\":\"0\"})"
1.55 + ))
1.56 + @BrwsrTest public void readFromTwttr() throws InterruptedException {
1.57 + if (page == null) {
1.58 + page = new TwitterModel();
1.59 + page.applyBindings();
1.60 + page.queryTweets("", "q=xyz");
1.61 + }
1.62 +
1.63 + if (page.getCurrentTweets().isEmpty()) {
1.64 + throw new InterruptedException();
1.65 + }
1.66 +
1.67 + assert 4 == page.getCurrentTweets().size() : "Four tweets: " + page.getCurrentTweets();
1.68 +
1.69 + String firstDate = page.getCurrentTweets().get(0).getCreated_at();
1.70 + assert "Fri, 05 Apr 2013 06:10:01 +0000".equals(firstDate) : "Date is OK: " + firstDate;
1.71 + }
1.72 +
1.73 + @Factory public static Object[] create() {
1.74 + return VMTest.create(TwitterProtocolTest.class);
1.75 + }
1.76 +}