2017-10-24 15:39:29 +02:00
|
|
|
package org.gcube.portal.social_networking_client_library;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
import org.gcube.portal.databook.shared.EnhancedFeed;
|
2018-02-19 16:27:09 +01:00
|
|
|
import org.gcube.portal.databook.shared.Feed;
|
2017-10-24 15:39:29 +02:00
|
|
|
import org.gcube.portal.databook.shared.JobStatusType;
|
|
|
|
import org.gcube.portal.databook.shared.Notification;
|
2018-02-19 16:35:01 +01:00
|
|
|
import org.gcube.social_networking.social_networking_client_library.FullTextSearchClient;
|
|
|
|
import org.gcube.social_networking.social_networking_client_library.HashTagClient;
|
|
|
|
import org.gcube.social_networking.social_networking_client_library.MessageClient;
|
|
|
|
import org.gcube.social_networking.social_networking_client_library.NotificationClient;
|
|
|
|
import org.gcube.social_networking.social_networking_client_library.PeopleClient;
|
|
|
|
import org.gcube.social_networking.social_networking_client_library.PostClient;
|
|
|
|
import org.gcube.social_networking.social_networking_client_library.TokenClient;
|
|
|
|
import org.gcube.social_networking.social_networking_client_library.UserClient;
|
|
|
|
import org.gcube.social_networking.social_networking_client_library.VREClient;
|
|
|
|
import org.gcube.social_networking.socialnetworking.model.beans.ApplicationId;
|
|
|
|
import org.gcube.social_networking.socialnetworking.model.beans.JobNotificationBean;
|
|
|
|
import org.gcube.social_networking.socialnetworking.model.beans.Message;
|
|
|
|
import org.gcube.social_networking.socialnetworking.model.beans.MyVRE;
|
|
|
|
import org.gcube.social_networking.socialnetworking.model.beans.PostInputBean;
|
|
|
|
import org.gcube.social_networking.socialnetworking.model.beans.Recipient;
|
|
|
|
import org.gcube.social_networking.socialnetworking.model.beans.UserProfile;
|
|
|
|
import org.gcube.social_networking.socialnetworking.model.beans.UserProfileExtended;
|
2017-10-24 15:39:29 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
public class TestClientServices {
|
2018-02-16 19:22:14 +01:00
|
|
|
|
2017-10-24 15:39:29 +02:00
|
|
|
private static Logger logger = LoggerFactory.getLogger(TestClientServices.class);
|
2018-02-16 19:22:14 +01:00
|
|
|
|
2018-02-19 16:35:01 +01:00
|
|
|
//@Before
|
2017-10-24 15:39:29 +02:00
|
|
|
public void setContextAndToken(){
|
2018-02-16 19:22:14 +01:00
|
|
|
|
2017-10-24 15:39:29 +02:00
|
|
|
ScopeProvider.instance.set("/gcube/devNext/NextNext");
|
2018-02-19 16:27:09 +01:00
|
|
|
SecurityTokenProvider.instance.set("...");
|
2018-02-16 19:22:14 +01:00
|
|
|
|
2017-10-24 15:39:29 +02:00
|
|
|
}
|
|
|
|
|
2018-02-16 19:22:14 +01:00
|
|
|
//@Test
|
2017-10-24 15:39:29 +02:00
|
|
|
public void testSearch() throws Exception {
|
|
|
|
FullTextSearchClient search = new FullTextSearchClient();
|
2018-02-16 19:22:14 +01:00
|
|
|
ArrayList<EnhancedFeed> result = search.search("looking for test", 0, 10);
|
|
|
|
|
2017-10-24 15:39:29 +02:00
|
|
|
for (EnhancedFeed enhancedFeed : result) {
|
|
|
|
logger.debug("Returned feed " + enhancedFeed);
|
|
|
|
}
|
|
|
|
}
|
2018-02-16 19:22:14 +01:00
|
|
|
|
|
|
|
//@Test
|
|
|
|
public void testSearchEmptyList() throws Exception {
|
|
|
|
FullTextSearchClient search = new FullTextSearchClient();
|
|
|
|
ArrayList<EnhancedFeed> result = search.search("tipiterotipirè", 0, 10);
|
|
|
|
|
|
|
|
for (EnhancedFeed enhancedFeed : result) {
|
|
|
|
logger.debug("Returned feed " + enhancedFeed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//@Test
|
2017-10-24 15:39:29 +02:00
|
|
|
public void testHashTags() throws Exception {
|
2018-02-19 16:27:09 +01:00
|
|
|
HashTagClient hashtags = new HashTagClient();
|
2017-10-24 15:39:29 +02:00
|
|
|
Map<String, Integer> hashtagsCount = hashtags.getHashtagsCount();
|
2018-02-16 19:22:14 +01:00
|
|
|
logger.debug("Returned tags " + hashtagsCount);
|
2017-10-24 15:39:29 +02:00
|
|
|
}
|
2018-02-16 19:22:14 +01:00
|
|
|
|
2018-02-17 20:08:15 +01:00
|
|
|
//@Test
|
2018-02-16 19:22:14 +01:00
|
|
|
public void testMessagesReceived() throws Exception {
|
2018-02-19 16:27:09 +01:00
|
|
|
MessageClient messagesClient = new MessageClient();
|
2018-02-17 18:51:38 +01:00
|
|
|
List<Message> receivedMessages = messagesClient.getReceivedMessages();
|
|
|
|
for (Message workspaceMessage : receivedMessages) {
|
2017-10-24 15:39:29 +02:00
|
|
|
logger.debug("Received message " + workspaceMessage.toString());
|
|
|
|
}
|
2018-02-16 19:22:14 +01:00
|
|
|
}
|
2018-02-17 18:51:38 +01:00
|
|
|
|
2018-02-16 19:22:14 +01:00
|
|
|
//@Test
|
|
|
|
public void testMessagesSent() throws Exception {
|
2018-02-19 16:27:09 +01:00
|
|
|
MessageClient messagesClient = new MessageClient();
|
2018-02-17 18:51:38 +01:00
|
|
|
List<Message> sentMessages = messagesClient.getSentMessages();
|
|
|
|
for (Message workspaceMessage : sentMessages) {
|
2017-10-24 15:39:29 +02:00
|
|
|
logger.debug("Sent message was " + workspaceMessage);
|
|
|
|
}
|
2018-02-16 19:22:14 +01:00
|
|
|
}
|
2018-02-17 18:51:38 +01:00
|
|
|
|
2018-02-16 19:22:14 +01:00
|
|
|
//@Test
|
|
|
|
public void sendMessage() throws Exception{
|
2017-10-24 15:39:29 +02:00
|
|
|
logger.debug("Sending message ");
|
2018-02-19 16:27:09 +01:00
|
|
|
MessageClient messagesClient = new MessageClient();
|
2017-10-24 15:39:29 +02:00
|
|
|
List<Recipient> rec = Arrays.asList(new Recipient("andrea.rossi"));
|
2018-02-17 18:51:38 +01:00
|
|
|
Message message = new Message(
|
2018-02-16 19:22:14 +01:00
|
|
|
"Test message",
|
2017-10-24 15:39:29 +02:00
|
|
|
"Sending message via client " + System.currentTimeMillis(),
|
|
|
|
new ArrayList<Recipient>(rec));
|
2018-02-16 19:22:14 +01:00
|
|
|
String idMessage = messagesClient.writeMessage(message);
|
2017-10-24 15:39:29 +02:00
|
|
|
assert(idMessage != null);
|
|
|
|
}
|
|
|
|
|
2018-02-16 19:22:14 +01:00
|
|
|
//@Test
|
2017-10-24 15:39:29 +02:00
|
|
|
public void testNotifications() throws Exception {
|
2018-02-19 16:27:09 +01:00
|
|
|
NotificationClient notificationsClient = new NotificationClient();
|
2018-02-16 19:22:14 +01:00
|
|
|
List<Notification> latestNotifications = notificationsClient.getNotifications(1, 2);
|
2017-10-24 15:39:29 +02:00
|
|
|
for (Notification notification : latestNotifications) {
|
|
|
|
logger.debug("Notification is " + notification);
|
|
|
|
}
|
|
|
|
}
|
2018-02-16 19:22:14 +01:00
|
|
|
|
|
|
|
//@Test
|
2017-10-24 15:39:29 +02:00
|
|
|
public void sendJobNotification() throws Exception {
|
2018-02-19 16:27:09 +01:00
|
|
|
NotificationClient notificationsClient = new NotificationClient();
|
2018-02-16 19:22:14 +01:00
|
|
|
JobNotificationBean notification = new JobNotificationBean(
|
|
|
|
"costantino.perciante",
|
|
|
|
UUID.randomUUID().toString(),
|
|
|
|
"SmartExecutor Social Indexer",
|
|
|
|
"SmartExecutor",
|
|
|
|
JobStatusType.SUCCEEDED,
|
|
|
|
"all ok");
|
2017-10-24 15:39:29 +02:00
|
|
|
notificationsClient.sendJobNotification(notification);
|
2018-02-16 19:22:14 +01:00
|
|
|
logger.debug("Sent job notification ");
|
|
|
|
}
|
2018-02-17 18:51:38 +01:00
|
|
|
|
2018-02-17 20:08:15 +01:00
|
|
|
//@Test
|
|
|
|
public void getProfile() throws Exception {
|
|
|
|
PeopleClient getProfile = new PeopleClient();
|
2018-02-19 16:27:09 +01:00
|
|
|
UserProfile profile = getProfile.getProfile();
|
2018-02-17 20:08:15 +01:00
|
|
|
logger.debug("Profile retrieved is " + profile);
|
|
|
|
}
|
|
|
|
|
|
|
|
//@Test
|
|
|
|
public void generateAppToken() throws Exception {
|
2018-02-19 16:27:09 +01:00
|
|
|
TokenClient tokenClient = new TokenClient();
|
|
|
|
String token = tokenClient.generateApplicationToken(new ApplicationId("org.gcube.datacatalogue.GRSFNotifier"));
|
2018-02-17 20:08:15 +01:00
|
|
|
logger.debug("Generated token is " + token);
|
|
|
|
}
|
|
|
|
|
|
|
|
//@Test
|
|
|
|
public void getMyVres() throws Exception{
|
2018-02-19 16:27:09 +01:00
|
|
|
VREClient myVresClient = new VREClient();
|
|
|
|
List<MyVRE> myVres = myVresClient.getMyVRES(false);
|
2018-02-17 20:08:15 +01:00
|
|
|
logger.debug("My Vres " + myVres);
|
|
|
|
}
|
|
|
|
|
2018-02-19 16:27:09 +01:00
|
|
|
//@Test
|
|
|
|
public void UsersClientTests() throws Exception{
|
|
|
|
|
|
|
|
UserClient userClient = new UserClient();
|
|
|
|
|
|
|
|
// Requires user token bound to the root context
|
|
|
|
// List<String> administrators = userClient.getAllUsernamesByGlobalRole("administrator");
|
|
|
|
//
|
|
|
|
// assert(administrators != null && !administrators.isEmpty());
|
|
|
|
|
|
|
|
// logger.debug("Administrators are " + administrators);
|
|
|
|
|
|
|
|
List<String> vreManagers = userClient.getAllUsernamesByLocalRole("vre-manager");
|
|
|
|
|
|
|
|
assert(vreManagers != null && !vreManagers.isEmpty());
|
|
|
|
|
|
|
|
logger.debug("Vre Managers are " + vreManagers);
|
|
|
|
|
|
|
|
String myEmail = userClient.getEmail();
|
|
|
|
|
|
|
|
assert(myEmail != null && !myEmail.isEmpty());
|
|
|
|
|
|
|
|
logger.debug("My email is " + myEmail);
|
|
|
|
|
|
|
|
String fullname = userClient.getFullName();
|
|
|
|
|
|
|
|
assert(fullname != null && !fullname.isEmpty());
|
|
|
|
|
|
|
|
logger.debug("My fullname is " + fullname);
|
|
|
|
|
|
|
|
String industry = userClient.getCustomAttribute("Industry");
|
|
|
|
|
|
|
|
assert(industry != null && !industry.isEmpty());
|
|
|
|
|
|
|
|
logger.debug("My Industry is " + industry);
|
|
|
|
|
|
|
|
List<String> usernamesInThisContext = userClient.getAllUsernamesContext();
|
|
|
|
|
|
|
|
assert(usernamesInThisContext != null && !usernamesInThisContext.isEmpty());
|
|
|
|
|
|
|
|
logger.debug("List of usernames in this context is " + usernamesInThisContext);
|
|
|
|
|
|
|
|
Map<String, String> usernamesFullnameInThisContext = userClient.getAllUsernamesFullnamesContext();
|
|
|
|
|
|
|
|
assert(usernamesFullnameInThisContext != null && !usernamesFullnameInThisContext.isEmpty());
|
|
|
|
|
|
|
|
logger.debug("List of tuples usernames/fullnames in this context is " + usernamesFullnameInThisContext);
|
|
|
|
|
|
|
|
UserProfileExtended profile = userClient.getProfile();
|
|
|
|
|
|
|
|
assert(profile != null);
|
|
|
|
|
|
|
|
logger.debug("My wonderful profile is " + profile);
|
|
|
|
|
|
|
|
// Requires application token bound to the root context
|
|
|
|
// Boolean userExists = userClient.userExists("andrea.rossi");
|
|
|
|
//
|
|
|
|
// assert(userExists != null && userExists == true);
|
|
|
|
//
|
|
|
|
// logger.debug("does Andrea Rossi exist? " + userExists);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//@Test
|
|
|
|
public void getUserPostsSinceDate() throws Exception{
|
|
|
|
|
|
|
|
PostClient postClient = new PostClient();
|
|
|
|
List<Feed> sinceLastYearPost = postClient.getUserPostsSinceDate(System.currentTimeMillis() - 1000 * 60 * 60 * 24 * 12);
|
|
|
|
logger.debug("Posts are " + sinceLastYearPost);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//@Test
|
|
|
|
public void getAllUserPosts() throws Exception{
|
|
|
|
|
|
|
|
PostClient postClient = new PostClient();
|
|
|
|
List<Feed> allposts = postClient.getAllUserPosts();
|
|
|
|
logger.debug("All posts are " + allposts);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//@Test
|
|
|
|
public void getUserPostsQuantity() throws Exception{
|
|
|
|
|
|
|
|
PostClient postClient = new PostClient();
|
|
|
|
List<Feed> quantityPosts = postClient.getUserPostsQuantity(3);
|
|
|
|
logger.debug("Some posts are " + quantityPosts);
|
|
|
|
}
|
|
|
|
|
|
|
|
//@Test
|
|
|
|
public void writeUserPost() throws Exception{
|
|
|
|
|
|
|
|
PostClient postClient = new PostClient();
|
|
|
|
PostInputBean toWrite = new PostInputBean("Testing social networking rest client", null, null, null, null, null, false, null);
|
|
|
|
Feed written = postClient.writeUserPost(toWrite);
|
|
|
|
logger.debug("Written post is " + written);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//@Test
|
|
|
|
public void getAllApplicationPosts() throws Exception{
|
|
|
|
|
|
|
|
TokenClient tokenClient = new TokenClient();
|
|
|
|
String token = tokenClient.generateApplicationToken(new ApplicationId("org.gcube.datacatalogue.GRSFNotifier"));
|
|
|
|
logger.debug("Generated token is " + token);
|
|
|
|
|
|
|
|
String currentToken = SecurityTokenProvider.instance.get();
|
|
|
|
SecurityTokenProvider.instance.set(token);
|
|
|
|
|
|
|
|
PostClient postClient = new PostClient();
|
|
|
|
List<Feed> applicationPosts = postClient.getAllApplicationPosts();
|
|
|
|
logger.debug("Application posts are " + applicationPosts);
|
|
|
|
|
|
|
|
SecurityTokenProvider.instance.set(currentToken);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//@Test
|
|
|
|
public void writeApplicationPost() throws Exception{
|
|
|
|
|
|
|
|
TokenClient tokenClient = new TokenClient();
|
|
|
|
String token = tokenClient.generateApplicationToken(new ApplicationId("org.gcube.datacatalogue.GRSFNotifier"));
|
|
|
|
logger.debug("Generated token is " + token);
|
|
|
|
|
|
|
|
String currentToken = SecurityTokenProvider.instance.get();
|
|
|
|
SecurityTokenProvider.instance.set(token);
|
|
|
|
|
|
|
|
PostClient postClient = new PostClient();
|
|
|
|
PostInputBean toWrite = new PostInputBean("Testing social networking rest client [via application token] #apptoken #rest #client #java", null, null, null, null, null, false, null);
|
|
|
|
Feed written = postClient.writeApplicationPost(toWrite);
|
|
|
|
logger.debug("Written post is " + written);
|
|
|
|
|
|
|
|
SecurityTokenProvider.instance.set(currentToken);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//@Test
|
|
|
|
public void getPostsVRE() throws Exception{
|
|
|
|
|
|
|
|
PostClient postClient = new PostClient();
|
|
|
|
List<Feed> vrePosts = postClient.getPostsVRE();
|
|
|
|
logger.debug("VRE posts are " + vrePosts);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//@Test
|
|
|
|
public void getHashtagPosts() throws Exception{
|
|
|
|
|
|
|
|
PostClient postClient = new PostClient();
|
|
|
|
List<Feed> postsWithHashtag = postClient.getHashtagPosts("#connect");
|
|
|
|
logger.debug("Posts with hashtag #connect are " + postsWithHashtag);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//@Test
|
|
|
|
public void getUserLikedPost() throws Exception{
|
|
|
|
|
|
|
|
PostClient postClient = new PostClient();
|
|
|
|
List<Feed> postsLiked = postClient.getUserLikedPost();
|
|
|
|
logger.debug("Posts liked are " + postsLiked);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//@Test
|
|
|
|
public void getUserLikedPostIds() throws Exception{
|
|
|
|
|
|
|
|
PostClient postClient = new PostClient();
|
|
|
|
List<String> postsLikedIds = postClient.getUserLikedPostIds();
|
|
|
|
logger.debug("Posts liked's ids are " + postsLikedIds);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-19 16:35:01 +01:00
|
|
|
//@After
|
2018-02-16 19:22:14 +01:00
|
|
|
public void reset(){
|
|
|
|
ScopeProvider.instance.reset();
|
|
|
|
SecurityTokenProvider.instance.reset();
|
2017-10-24 15:39:29 +02:00
|
|
|
}
|
|
|
|
}
|