streams-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sblack...@apache.org
Subject [1/4] incubator-streams git commit: resolves STREAMS-508
Date Wed, 21 Jun 2017 03:30:01 GMT
Repository: incubator-streams
Updated Branches:
  refs/heads/master c8e56dc55 -> bd91d2687


http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/af636824/streams-contrib/streams-provider-twitter/src/test/java/org/apache/streams/twitter/test/api/TwitterIT.java
----------------------------------------------------------------------
diff --git a/streams-contrib/streams-provider-twitter/src/test/java/org/apache/streams/twitter/test/api/TwitterIT.java
b/streams-contrib/streams-provider-twitter/src/test/java/org/apache/streams/twitter/test/api/TwitterIT.java
new file mode 100644
index 0000000..15b01d6
--- /dev/null
+++ b/streams-contrib/streams-provider-twitter/src/test/java/org/apache/streams/twitter/test/api/TwitterIT.java
@@ -0,0 +1,226 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ *
+ *   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 org.apache.streams.twitter.test.api;
+
+import org.apache.streams.config.ComponentConfigurator;
+import org.apache.streams.config.StreamsConfiguration;
+import org.apache.streams.config.StreamsConfigurator;
+import org.apache.streams.twitter.TwitterConfiguration;
+import org.apache.streams.twitter.api.Account;
+import org.apache.streams.twitter.api.AccountSettings;
+import org.apache.streams.twitter.api.Favorites;
+import org.apache.streams.twitter.api.FavoritesListRequest;
+import org.apache.streams.twitter.api.Followers;
+import org.apache.streams.twitter.api.FollowersIdsRequest;
+import org.apache.streams.twitter.api.FollowersIdsResponse;
+import org.apache.streams.twitter.api.FollowersListRequest;
+import org.apache.streams.twitter.api.FollowersListResponse;
+import org.apache.streams.twitter.api.Friends;
+import org.apache.streams.twitter.api.FriendsIdsRequest;
+import org.apache.streams.twitter.api.FriendsIdsResponse;
+import org.apache.streams.twitter.api.FriendsListRequest;
+import org.apache.streams.twitter.api.FriendsListResponse;
+import org.apache.streams.twitter.api.Statuses;
+import org.apache.streams.twitter.api.StatusesHomeTimelineRequest;
+import org.apache.streams.twitter.api.StatusesLookupRequest;
+import org.apache.streams.twitter.api.StatusesMentionsTimelineRequest;
+import org.apache.streams.twitter.api.StatusesShowRequest;
+import org.apache.streams.twitter.api.Twitter;
+import org.apache.streams.twitter.api.Users;
+import org.apache.streams.twitter.api.UsersLookupRequest;
+import org.apache.streams.twitter.api.UsersShowRequest;
+import org.apache.streams.twitter.pojo.Tweet;
+import org.apache.streams.twitter.pojo.User;
+
+import com.typesafe.config.Config;
+import com.typesafe.config.ConfigFactory;
+import org.apache.juneau.remoteable.RemoteMethod;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.Test;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static java.util.Objects.nonNull;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+/**
+ * Integration Tests for all implemented Twitter endpoints.
+ */
+public class TwitterIT {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(TwitterIT.class);
+
+  private static Config application = ConfigFactory.parseResources("TwitterIT.conf").withFallback(ConfigFactory.load());
+  private static StreamsConfiguration streamsConfiguration = StreamsConfigurator.detectConfiguration(application);
+  private static TwitterConfiguration config = new ComponentConfigurator<>(TwitterConfiguration.class).detectConfiguration(application,
"twitter");
+
+  private static User user;
+  private static AccountSettings settings;
+  private static List<Tweet> statusesHomeTimeline;
+
+  @Test(groups = {"Account","AccountVerifyCredentials"})
+  public void testVerifyCredentials() throws Exception {
+    Account account = Twitter.getInstance(config);
+    nonNull(account);
+    User user = account.verifyCredentials();
+    nonNull(user);
+    nonNull(user.getCreatedAt());
+    TwitterIT.user = user;
+  }
+
+  @Test(dependsOnGroups = {"AccountVerifyCredentials"}, groups = {"Account"})
+  public void testAccountSettings() throws Exception {
+    Account account = Twitter.getInstance(config);
+    nonNull(account);
+    AccountSettings settings = account.settings();
+    nonNull(settings);
+    nonNull(settings.getScreenName());
+    assertEquals(settings.getScreenName(), user.getScreenName());
+    TwitterIT.settings = settings;
+  }
+
+  @Test(dependsOnGroups = {"Account"}, groups = {"Favorites"})
+  public void testFavoritesList() throws Exception {
+    Favorites favorites = Twitter.getInstance(config);
+    nonNull(favorites);
+    List<Tweet> favoritesTweetList = favorites.list(new FavoritesListRequest().withScreenName(user.getScreenName()));
+    nonNull(favoritesTweetList);
+    assertThat("favoritesTweetList.size() > 0", favoritesTweetList.size() > 0);
+  }
+
+  @Test(dependsOnGroups = {"Account"}, groups = {"Followers"})
+  public void testFollowersList() throws Exception {
+    Followers followers = Twitter.getInstance(config);
+    nonNull(followers);
+    FollowersListRequest followersListRequest = new FollowersListRequest();
+    followersListRequest.setId(user.getId());
+    FollowersListResponse followersListResponse = followers.list(followersListRequest);
+    nonNull(followersListResponse);
+    assertThat("followersListResponse.getUsers().size() > 0", followersListResponse.getUsers().size()
> 0);
+  }
+
+  @Test(dependsOnGroups = {"Account"}, groups = {"Followers"})
+  public void testFollowersIds() throws Exception {
+    Followers followers = Twitter.getInstance(config);
+    nonNull(followers);
+    FollowersIdsRequest followersIdsRequest = new FollowersIdsRequest();
+    followersIdsRequest.setId(user.getId());
+    FollowersIdsResponse followersIdsResponse = followers.ids(followersIdsRequest);
+    nonNull(followersIdsResponse);
+    assertThat("followersIdsResponse.getUsers().size() > 0", followersIdsResponse.getIds().size()
> 0);
+  }
+
+  @Test(dependsOnGroups = {"Account"}, groups = {"Friends"})
+  public void testFriendsList() throws Exception {
+    Friends friends = Twitter.getInstance(config);
+    nonNull(friends);
+    FriendsListRequest friendsListRequest = (FriendsListRequest) (new FriendsListRequest().withId(user.getId()));
+    FriendsListResponse friendsListResponse = friends.list(friendsListRequest);
+    nonNull(friendsListResponse);
+    assertThat("friendsListResponse.getUsers().size() > 0", friendsListResponse.getUsers().size()
> 0);
+  }
+
+  @Test(dependsOnGroups = {"Account"}, groups = {"Friends"})
+  public void testFriendsIds() throws Exception {
+    Friends friends = Twitter.getInstance(config);
+    nonNull(friends);
+    FriendsIdsRequest friendsIdsRequest = (FriendsIdsRequest)new FriendsIdsRequest().withId(user.getId());
+    FriendsIdsResponse friendsIdsResponse = friends.ids(friendsIdsRequest);
+    nonNull(friendsIdsResponse);
+    assertThat("friendsIdsResponse.getUsers().size() > 0", friendsIdsResponse.getIds().size()
> 0);
+  }
+
+  @Test(dependsOnGroups = {"Account"}, groups = {"Statuses","StatusesHomeTimeline"})
+  public void testStatusesHomeTimeline() throws Exception {
+    Statuses statuses = Twitter.getInstance(config);
+    nonNull(statuses);
+    StatusesHomeTimelineRequest statusesHomeTimelineRequest = new StatusesHomeTimelineRequest();
+    List<Tweet> statusesHomeTimeline = statuses.homeTimeline(statusesHomeTimelineRequest);
+    nonNull(statusesHomeTimeline);
+    assertThat("statusesHomeTimeline.size() > 0", statusesHomeTimeline.size() > 0);
+    this.statusesHomeTimeline = statusesHomeTimeline;
+  }
+
+  @Test(dependsOnGroups = {"Account"}, groups = {"Statuses"})
+  public void testStatusesMentionsTimeline() throws Exception {
+    Statuses statuses = Twitter.getInstance(config);
+    nonNull(statuses);
+    StatusesMentionsTimelineRequest statusesMentionsTimelineRequest = new StatusesMentionsTimelineRequest();
+    List<Tweet> statusesMentionsTimeline = statuses.mentionsTimeline(statusesMentionsTimelineRequest);
+    nonNull(statusesMentionsTimeline);
+    assertThat("statusesMentionsTimeline.size() > 0", statusesMentionsTimeline.size()
> 0);
+  }
+
+  @Test(dependsOnGroups = {"Account","StatusesHomeTimeline"}, groups = {"Statuses"})
+  public void testStatusesLookup() throws Exception {
+    Statuses statuses = Twitter.getInstance(config);
+    nonNull(statuses);
+    StatusesLookupRequest statusesLookupRequest = new StatusesLookupRequest();
+    statusesLookupRequest.setId(statusesHomeTimeline.stream().map(tweet -> tweet.getId()).collect(Collectors.toList()));
+    List<Tweet> statusesLookup = statuses.lookup(statusesLookupRequest);
+    nonNull(statusesLookup);
+    assertThat("statusesLookup.size() > 0", statusesLookup.size() > 0);
+  }
+
+  @Test(dependsOnGroups = {"Account"}, groups = {"Statuses"})
+  public void testStatusesShow() throws Exception {
+    Statuses statuses = Twitter.getInstance(config);
+    nonNull(statuses);
+    StatusesShowRequest statusesShowRequest = new StatusesShowRequest();
+    statusesShowRequest.setId(user.getStatus().getId());
+    Tweet statusesShow = statuses.show(statusesShowRequest);
+    nonNull(statusesShow);
+    nonNull(statusesShow.getCreatedAt());
+  }
+
+  @Test(dependsOnGroups = {"Account"}, groups = {"Users"})
+  public void testUsersShow() throws Exception {
+    Users users = Twitter.getInstance(config);
+    nonNull(users);
+    User showUser = users.show(new UsersShowRequest().withScreenName(user.getScreenName()));
+    nonNull(showUser);
+    assertEquals( user.getId(), showUser.getId());
+  }
+
+  @Test(dependsOnGroups = {"Account"}, groups = {"Users"})
+  public void testUsersLookupById() throws Exception {
+    Users users = Twitter.getInstance(config);
+    nonNull(users);
+    UsersLookupRequest usersLookupRequest = new UsersLookupRequest();
+    usersLookupRequest.setUserId(statusesHomeTimeline.stream().map(tweet -> tweet.getUser().getId()).collect(Collectors.toList()));
+    List<User> lookupUserById = users.lookup(usersLookupRequest);
+    nonNull(lookupUserById);
+    assertThat("lookupUserById.size() > 0", lookupUserById.size() > 0);
+  }
+
+  @Test(dependsOnGroups = {"Account"}, groups = {"Users"})
+  public void testUsersLookupByScreenName() throws Exception {
+    Users users = Twitter.getInstance(config);
+    nonNull(users);
+    UsersLookupRequest usersLookupRequest = new UsersLookupRequest();
+    usersLookupRequest.setScreenName(statusesHomeTimeline.stream().map(tweet -> tweet.getUser().getScreenName()).collect(Collectors.toList()));
+    List<User> lookupUserByScreenName = users.lookup(usersLookupRequest);
+    nonNull(lookupUserByScreenName);
+    assertThat("lookupUserByScreenName.size() > 0", lookupUserByScreenName.size() >
0);
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/af636824/streams-contrib/streams-provider-twitter/src/test/java/org/apache/streams/twitter/test/api/TwitterOAuthRequestInterceptorTest.java
----------------------------------------------------------------------
diff --git a/streams-contrib/streams-provider-twitter/src/test/java/org/apache/streams/twitter/test/api/TwitterOAuthRequestInterceptorTest.java
b/streams-contrib/streams-provider-twitter/src/test/java/org/apache/streams/twitter/test/api/TwitterOAuthRequestInterceptorTest.java
index 536fb5e..9d3ad4f 100644
--- a/streams-contrib/streams-provider-twitter/src/test/java/org/apache/streams/twitter/test/api/TwitterOAuthRequestInterceptorTest.java
+++ b/streams-contrib/streams-provider-twitter/src/test/java/org/apache/streams/twitter/test/api/TwitterOAuthRequestInterceptorTest.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ *
+ *   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 org.apache.streams.twitter.test.api;
 
 import org.apache.streams.twitter.TwitterOAuthConfiguration;
@@ -23,7 +41,7 @@ import static org.apache.streams.twitter.api.TwitterOAuthRequestInterceptor.enco
 import static org.junit.Assert.assertEquals;
 
 /**
- * Created by sblackmon on 3/26/17.
+ * Unit Tests for twitter request signing.
  */
 public class TwitterOAuthRequestInterceptorTest {
 

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/af636824/streams-contrib/streams-provider-twitter/src/test/resources/TwitterIT.conf
----------------------------------------------------------------------
diff --git a/streams-contrib/streams-provider-twitter/src/test/resources/TwitterIT.conf b/streams-contrib/streams-provider-twitter/src/test/resources/TwitterIT.conf
new file mode 100644
index 0000000..af88ba9
--- /dev/null
+++ b/streams-contrib/streams-provider-twitter/src/test/resources/TwitterIT.conf
@@ -0,0 +1,20 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+twitter {
+  retrySleepMs = 100
+  retryMax = 1
+}

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/af636824/streams-contrib/streams-provider-twitter/src/test/resources/TwitterUserInformationProviderIT.conf
----------------------------------------------------------------------
diff --git a/streams-contrib/streams-provider-twitter/src/test/resources/TwitterUserInformationProviderIT.conf
b/streams-contrib/streams-provider-twitter/src/test/resources/TwitterUserInformationProviderIT.conf
index 3054b9d..f6949cf 100644
--- a/streams-contrib/streams-provider-twitter/src/test/resources/TwitterUserInformationProviderIT.conf
+++ b/streams-contrib/streams-provider-twitter/src/test/resources/TwitterUserInformationProviderIT.conf
@@ -14,7 +14,6 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-
 twitter.info = [
   3424266646
   3277467241


Mime
View raw message