Package slim3demo1.controller.twitter

Examples of slim3demo1.controller.twitter.DeleteControllerTest


    private TwitterService service = new TwitterService();
    private TweetMeta meta = TweetMeta.get();

    @Override
    public Navigation run() throws Exception {
        Tweet tweet = service.getTweet(asKey(meta.key), asLong(meta.version));
        BeanUtil.copy(tweet, request);
        return forward("edit.jsp");
    }
View Full Code Here


public class TwitterService {

    private TweetMeta t = new TweetMeta();

    public Tweet tweet(Map<String, Object> input) {
        Tweet tweet = new Tweet();
        BeanUtil.copy(input, tweet);
        Transaction tx = Datastore.beginTransaction();
        Datastore.put(tx, tweet);
        tx.commit();
        return tweet;
View Full Code Here

        tx.commit();
    }
   
    public void delete(Key key, Long version) {
        Transaction tx = Datastore.beginTransaction();
        Tweet tweet = Datastore.get(tx, t, key, version);
        Datastore.delete(tx, tweet.getKey());
        tx.commit();
    }
View Full Code Here

        tx.commit();
    }

    public void updateTweet(Key key, String content) {
        Transaction tx = Datastore.beginTransaction();
        Tweet tweet = Datastore.get(Tweet.class, key);
        tweet.setContent(content);
        Datastore.put(tx, tweet);
        tx.commit();
    }
View Full Code Here

    }

    public void updateTweet(Key key, Long version, Map<String, Object> input) {
        // TODO Auto-generated method stub
        Transaction tx = Datastore.beginTransaction();
        Tweet tweet = Datastore.get(tx, t, key, version);
        BeanUtil.copy(input, tweet);
        Datastore.put(tx, tweet);
        tx.commit();
    }
View Full Code Here

        tester.start("/twitter/tweet");
        TweetController controller = tester.getController();
        assertThat(controller, is(notNullValue()));
        assertThat(tester.isRedirect(), is(true));
        assertThat(tester.getDestinationPath(), is("/twitter/"));
        Tweet stored = Datastore.query(Tweet.class).asSingle();
        assertThat(stored, is(notNullValue()));
        assertThat(stored.getContent(), is("Hello"));
    }
View Full Code Here

        tester.start("/twitter/delete");
        DeleteController controller = tester.getController();
        assertThat(controller, is(notNullValue()));
        assertThat(tester.isRedirect(), is(true));
        assertThat(tester.getDestinationPath(), is("/twitter/"));
        Tweet stored = Datastore.query(Tweet.class).asSingle();
        assertThat(stored, is(notNullValue()));
        assertThat(stored.getContent(), is("Hello"));
    }
View Full Code Here

    @Test
    public void tweet() throws Exception {
        Map<String, Object> input = new HashMap<String, Object>();
        input.put("content", "Hello");
        String email = "haidm@testmail.com";
        Tweet tweeted = service.tweet(input);
        assertThat(tweeted, is(notNullValue()));
        Tweet stored = Datastore.get(Tweet.class, tweeted.getKey());
        assertThat(stored.getContent(), is("Hello"));
        assertThat(stored.getEmail(), is("haidm@testmail.com"));
    }
View Full Code Here

        assertThat(stored.getEmail(), is("haidm@testmail.com"));
    }

    @Test
    public void getTweetList() throws Exception {
        Tweet tweet = new Tweet();
        tweet.setContent("Hello");
        Datastore.put(tweet);
        List<Tweet> tweetList = service.getTweetList();
        assertThat(tweetList.size(), is(1));
        assertThat(tweetList.get(0).getContent(), is("Hello"));
    }
View Full Code Here

        assertThat(tweetList.get(0).getContent(), is("Hello"));
    }
   
    @Test
    public void deleteTweet () throws Exception {
        Tweet tweet1 = new Tweet();
        tweet1.setContent("Hello");
        Datastore.put(tweet1);
        List<Tweet> tweetList = service.getTweetList();
        assertThat(tweetList.size(), is(1));
        assertThat(tweetList.get(0).getContent(), is("Hello"));
       
        List<Tweet> listTweet = service.getTweetList();
        int listTweetSize = listTweet.size();
        int ranIndex = (new Random()).nextInt(listTweetSize);
        Tweet tweet = listTweet.get(ranIndex);
        System.out.println ("delete Tweet: " + tweet.getEmail() + "; " + tweet.getContent() + "; " + tweet.getKey());
//        listTweet = service.deleteTweet(tweet.getKey());
        assertThat (listTweet.contains(tweet), is (false));
    }
View Full Code Here

TOP

Related Classes of slim3demo1.controller.twitter.DeleteControllerTest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.