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; import org.gcube.portal.databook.shared.JobStatusType; import org.gcube.portal.databook.shared.Notification; import org.gcube.portal.socialnetworking.model.input.ApplicationId; import org.gcube.portal.socialnetworking.model.input.JobNotificationBean; import org.gcube.portal.socialnetworking.model.input.Message; import org.gcube.portal.socialnetworking.model.input.Recipient; import org.json.JSONArray; import org.json.JSONObject; import org.junit.After; import org.junit.Before; 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 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 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 hashtagsCount = hashtags.getHashtagsCount(); logger.debug("Returned tags " + hashtagsCount); } //@Test public void testMessagesReceived() throws Exception { MessagesClient messagesClient = new MessagesClient(); List receivedMessages = messagesClient.getReceivedMessages(); for (Message workspaceMessage : receivedMessages) { logger.debug("Received message " + workspaceMessage.toString()); } } //@Test public void testMessagesSent() throws Exception { MessagesClient messagesClient = new MessagesClient(); List sentMessages = messagesClient.getSentMessages(); for (Message workspaceMessage : sentMessages) { logger.debug("Sent message was " + workspaceMessage); } } //@Test public void sendMessage() throws Exception{ logger.debug("Sending message "); MessagesClient messagesClient = new MessagesClient(); List rec = Arrays.asList(new Recipient("andrea.rossi")); Message message = new Message( "Test message", "Sending message via client " + System.currentTimeMillis(), new ArrayList(rec)); String idMessage = messagesClient.writeMessage(message); assert(idMessage != null); } //@Test public void testNotifications() throws Exception { NotificationsClient notificationsClient = new NotificationsClient(); List 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 "); } //@Test public void getProfile() throws Exception { PeopleClient getProfile = new PeopleClient(); JSONObject profile = getProfile.getProfile(); logger.debug("Profile retrieved is " + profile); } //@Test public void generateAppToken() throws Exception { TokensClient tokenClient = new TokensClient(); String token = tokenClient.generateApplicationToken(new ApplicationId("test_app")); logger.debug("Generated token is " + token); } //@Test public void getMyVres() throws Exception{ VREsClient myVresClient = new VREsClient(); JSONArray myVres = myVresClient.getMyVRES(); logger.debug("My Vres " + myVres); } @After public void reset(){ ScopeProvider.instance.reset(); SecurityTokenProvider.instance.reset(); } }