social-service-client/src/test/java/org/gcube/portal/social_networking_client_li.../TestClientServices.java

123 lines
4.0 KiB
Java

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.homelibrary.home.workspace.sharing.WorkspaceMessage;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portal.databook.shared.EnhancedFeed;
import org.gcube.portal.databook.shared.JobStatusType;
import org.gcube.portal.databook.shared.Notification;
import org.gcube.portal.socialnetworking.model.input.JobNotificationBean;
import org.gcube.portal.socialnetworking.model.input.MessageInputBean;
import org.gcube.portal.socialnetworking.model.input.Recipient;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestClientServices {
private static Logger logger = LoggerFactory.getLogger(TestClientServices.class);
@Before
public void setContextAndToken(){
ScopeProvider.instance.set("/gcube/devNext/NextNext");
SecurityTokenProvider.instance.set("d423aed7-e9e2-424a-b9e7-2bbbd151d9c4-98187548");
}
//@Test
public void testSearch() throws Exception {
FullTextSearchClient search = new FullTextSearchClient();
ArrayList<EnhancedFeed> result = search.search("looking for test", 0, 10);
for (EnhancedFeed enhancedFeed : result) {
logger.debug("Returned feed " + enhancedFeed);
}
}
//@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
public void testHashTags() throws Exception {
HashTagsClient hashtags = new HashTagsClient();
Map<String, Integer> hashtagsCount = hashtags.getHashtagsCount();
logger.debug("Returned tags " + hashtagsCount);
}
@Test
public void testMessagesReceived() throws Exception {
MessagesClient messagesClient = new MessagesClient();
List<WorkspaceMessage> receivedMessages = messagesClient.getReceivedMessages();
for (WorkspaceMessage workspaceMessage : receivedMessages) {
logger.debug("Received message " + workspaceMessage.toString());
}
}
//@Test
public void testMessagesSent() throws Exception {
MessagesClient messagesClient = new MessagesClient();
List<WorkspaceMessage> sentMessages = messagesClient.getSentMessages();
for (WorkspaceMessage workspaceMessage : sentMessages) {
logger.debug("Sent message was " + workspaceMessage);
}
}
//@Test
public void sendMessage() throws Exception{
logger.debug("Sending message ");
MessagesClient messagesClient = new MessagesClient();
List<Recipient> rec = Arrays.asList(new Recipient("andrea.rossi"));
MessageInputBean message = new MessageInputBean(
"Test message",
"Sending message via client " + System.currentTimeMillis(),
new ArrayList<Recipient>(rec));
String idMessage = messagesClient.writeMessage(message);
assert(idMessage != null);
}
//@Test
public void testNotifications() throws Exception {
NotificationsClient notificationsClient = new NotificationsClient();
List<Notification> latestNotifications = notificationsClient.getNotifications(1, 2);
for (Notification notification : latestNotifications) {
logger.debug("Notification is " + notification);
}
}
//@Test
public void sendJobNotification() throws Exception {
NotificationsClient notificationsClient = new NotificationsClient();
JobNotificationBean notification = new JobNotificationBean(
"costantino.perciante",
UUID.randomUUID().toString(),
"SmartExecutor Social Indexer",
"SmartExecutor",
JobStatusType.SUCCEEDED,
"all ok");
notificationsClient.sendJobNotification(notification);
logger.debug("Sent job notification ");
}
@After
public void reset(){
ScopeProvider.instance.reset();
SecurityTokenProvider.instance.reset();
}
}