javaquery/demo-twitter/src/test/java/org/apidesign/bck2brwsr/demo/twitter/TwitterProtocolTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 26 Apr 2013 13:51:15 +0200
branchmodel
changeset 1024 9af5b2f49cb0
parent 954 6448c284fe21
child 1055 0d7b63408a1e
permissions -rw-r--r--
Twitter demo rewritten to use net.java.html.json annotations
jaroslav@947
     1
/**
jaroslav@947
     2
 * Back 2 Browser Bytecode Translator
jaroslav@947
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@947
     4
 *
jaroslav@947
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@947
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@947
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@947
     8
 *
jaroslav@947
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@947
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@947
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@947
    12
 * GNU General Public License for more details.
jaroslav@947
    13
 *
jaroslav@947
    14
 * You should have received a copy of the GNU General Public License
jaroslav@947
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@947
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@947
    17
 */
jaroslav@947
    18
package org.apidesign.bck2brwsr.demo.twitter;
jaroslav@947
    19
jaroslav@1024
    20
import net.java.html.json.Context;
jaroslav@947
    21
import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
jaroslav@947
    22
import org.apidesign.bck2brwsr.vmtest.Http;
jaroslav@947
    23
import org.apidesign.bck2brwsr.vmtest.VMTest;
jaroslav@947
    24
import org.testng.annotations.Factory;
jaroslav@947
    25
jaroslav@947
    26
/**
jaroslav@947
    27
 *
jaroslav@947
    28
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@947
    29
 */
jaroslav@947
    30
public class TwitterProtocolTest {
jaroslav@947
    31
    private TwitterModel page;
jaroslav@947
    32
    @Http(@Http.Resource(
jaroslav@954
    33
        path = "/search.json",
jaroslav@947
    34
        mimeType = "application/json",
jaroslav@954
    35
        parameters = {"callback"},
jaroslav@954
    36
        content = "$0({\"completed_in\":0.04,\"max_id\":320055706885689344,\"max_id_str\""
jaroslav@947
    37
        + ":\"320055706885689344\",\"page\":1,\"query\":\"from%3AJaroslavTulach\",\"refresh_url\":"
jaroslav@947
    38
        + "\"?since_id=320055706885689344&q=from%3AJaroslavTulach\","
jaroslav@947
    39
        + "\"results\":[{\"created_at\":\"Fri, 05 Apr 2013 06:10:01 +0000\","
jaroslav@947
    40
        + "\"from_user\":\"JaroslavTulach\",\"from_user_id\":420944648,\"from_user_id_str\":"
jaroslav@947
    41
        + "\"420944648\",\"from_user_name\":\"Jaroslav Tulach\",\"geo\":null,\"id\":320055706885689344,"
jaroslav@947
    42
        + "\"id_str\":\"320055706885689344\",\"iso_language_code\":\"en\",\"metadata\":{\"result_type\":"
jaroslav@947
    43
        + "\"recent\"},\"profile_image_url\":\"http:\\/\\/a0.twimg.com\\/profile_images\\/1656828312\\/jst_normal.gif\","
jaroslav@947
    44
        + "\"profile_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_images\\/1656828312\\/jst_normal.gif\","
jaroslav@947
    45
        + "\"source\":\"&lt;a href=&quot;http:\\/\\/twitter.com\\/&quot;&gt;web&lt;\\/a&gt;\",\"text\":"
jaroslav@947
    46
        + "\"@tom_enebo Amzng! Not that I would like #ruby, but I am really glad you guys stabilized the plugin + "
jaroslav@947
    47
        + "made it work in #netbeans 7.3! Gd wrk.\",\"to_user\":\"tom_enebo\",\"to_user_id\":14498747,"
jaroslav@947
    48
        + "\"to_user_id_str\":\"14498747\",\"to_user_name\":\"tom_enebo\",\"in_reply_to_status_id\":319832359509839872,"
jaroslav@947
    49
        + "\"in_reply_to_status_id_str\":\"319832359509839872\"},{\"created_at\":\"Thu, 04 Apr 2013 07:33:06 +0000\","
jaroslav@947
    50
        + "\"from_user\":\"JaroslavTulach\",\"from_user_id\":420944648,\"from_user_id_str\":"
jaroslav@947
    51
        + "\"420944648\",\"from_user_name\":\"Jaroslav Tulach\",\"geo\":null,\"id\":319714227088678913,"
jaroslav@947
    52
        + "\"id_str\":\"319714227088678913\",\"iso_language_code\":\"en\",\"metadata\":{\"result_type\":"
jaroslav@947
    53
        + "\"recent\"},\"profile_image_url\":\"http:\\/\\/a0.twimg.com\\/profile_images\\/1656828312\\/jst_normal.gif\","
jaroslav@947
    54
        + "\"profile_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_images\\/1656828312\\/jst_normal.gif\","
jaroslav@947
    55
        + "\"source\":\"&lt;a href=&quot;http:\\/\\/twitter.com\\/&quot;&gt;web&lt;\\/a&gt;\",\"text\":"
jaroslav@947
    56
        + "\"RT @drkrab: At #erlangfactory @joerl: Frameworks grow in complexity until nobody can use them.\"},"
jaroslav@947
    57
        + "{\"created_at\":\"Tue, 02 Apr 2013 07:44:34 +0000\",\"from_user\":\"JaroslavTulach\","
jaroslav@947
    58
        + "\"from_user_id\":420944648,\"from_user_id_str\":\"420944648\",\"from_user_name\":\"Jaroslav Tulach\","
jaroslav@947
    59
        + "\"geo\":null,\"id\":318992336145248256,\"id_str\":\"318992336145248256\",\"iso_language_code\":\"en\","
jaroslav@947
    60
        + "\"metadata\":{\"result_type\":\"recent\"},\"profile_image_url\":"
jaroslav@947
    61
        + "\"http:\\/\\/a0.twimg.com\\/profile_images\\/1656828312\\/jst_normal.gif\","
jaroslav@947
    62
        + "\"profile_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_images\\/1656828312\\/jst_normal.gif\","
jaroslav@947
    63
        + "\"source\":\"&lt;a href=&quot;http:\\/\\/twitter.com\\/&quot;&gt;web&lt;\\/a&gt;\",\"text\":"
jaroslav@947
    64
        + "\"Twitter renamed to twttr http:\\/\\/t.co\\/tqaN4T1xlZ - good, I don't have to rename #bck2brwsr!\"},"
jaroslav@947
    65
        + "{\"created_at\":\"Sun, 31 Mar 2013 03:52:04 +0000\",\"from_user\":\"JaroslavTulach\",\"from_user_id\":420944648,"
jaroslav@947
    66
        + "\"from_user_id_str\":\"420944648\",\"from_user_name\":\"Jaroslav Tulach\",\"geo\":null,"
jaroslav@947
    67
        + "\"id\":318209051223789568,\"id_str\":\"318209051223789568\",\"iso_language_code\":\"en\",\"metadata\":"
jaroslav@947
    68
        + "{\"result_type\":\"recent\"},\"profile_image_url\":"
jaroslav@947
    69
        + "\"http:\\/\\/a0.twimg.com\\/profile_images\\/1656828312\\/jst_normal.gif\","
jaroslav@947
    70
        + "\"profile_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_images\\/1656828312\\/jst_normal.gif\","
jaroslav@947
    71
        + "\"source\":\"&lt;a href=&quot;http:\\/\\/twitter.com\\/&quot;&gt;web&lt;\\/a&gt;\",\"text\":"
jaroslav@947
    72
        + "\"Math proofs without words. Ingenious: http:\\/\\/t.co\\/sz7yVbfpGw\"}],\"results_per_page\":100,"
jaroslav@954
    73
        + "\"since_id\":0,\"since_id_str\":\"0\"})"
jaroslav@947
    74
    ))
jaroslav@947
    75
    @BrwsrTest public void readFromTwttr() throws InterruptedException {
jaroslav@947
    76
        if (page == null) {
jaroslav@1024
    77
            page = new TwitterModel(Context.findDefault(TwitterProtocolTest.class));
jaroslav@947
    78
            page.applyBindings();
jaroslav@954
    79
            page.queryTweets("", "q=xyz");
jaroslav@947
    80
        }
jaroslav@947
    81
jaroslav@947
    82
        if (page.getCurrentTweets().isEmpty()) {
jaroslav@947
    83
            throw new InterruptedException();
jaroslav@947
    84
        }
jaroslav@947
    85
jaroslav@947
    86
        assert 4 == page.getCurrentTweets().size() : "Four tweets: " + page.getCurrentTweets();
jaroslav@948
    87
        
jaroslav@948
    88
        String firstDate = page.getCurrentTweets().get(0).getCreated_at();
jaroslav@948
    89
        assert "Fri, 05 Apr 2013 06:10:01 +0000".equals(firstDate) : "Date is OK: " + firstDate;
jaroslav@947
    90
    }
jaroslav@947
    91
    
jaroslav@947
    92
    @Factory public static Object[] create() {
jaroslav@947
    93
        return VMTest.create(TwitterProtocolTest.class);
jaroslav@947
    94
    }
jaroslav@947
    95
}