package org.gcube.social_networking.socialutillibrary; import java.util.List; import org.gcube.socialnetworking.socialtoken.SocialMessageParser; import org.gcube.socialnetworking.socialtoken.URLToken; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class TestUnit { private static final Logger logger = LoggerFactory.getLogger(MessageParserTest.class); //@Test public void testHashtag() { String text = "Dear members, The item 'ADSDTest4CWP' has been just published by Leonardo Candela. " + "You can find it here: http://data.d4science.org/ctlg/CWP_Secretariat/adsdtest4cwp " + "#Area #Geospatial #Periodicity-When_updates_are_available "; List hashtags = Utils.getHashTags(text); System.out.println("Hashtags are " + hashtags); } //@Test public void extractUrl(){ String url = " test http://2001:db8:0:1:1:1:1:1:8080/group/preeco/what-if?p_p_id=simul_WAR_simulfishgrowthportlet&p_p_lifecycle=0 "; String result = Utils.extractURL(url); System.out.println("urls are " + result); } @Test public void test(){ String urlString = "http://2001:db8:0:1:1:1:1:1:8080/group/preeco/what-if?p_p_id=simul_WAR_simulfishgrowthportlet&p_p_lifecycle=0"; String[] ends = new String[] {".", ",", ";",":",")","]","}",""}; for(String s : ends) { URLToken urlToken = new URLToken(urlString+s, "\n", 0, 0); logger.debug(urlToken.getTokenReplacement()); } } protected String findFirstLink(String message) { try { SocialMessageParser messageParser = new SocialMessageParser(message); List urlTokens = messageParser.getURLTokens(); return urlTokens.get(0).getExtractedURL().toString(); }catch (Exception e) { return null; } } @Test public void testTest() { String text = "Hello (https://doodle.com/poll/not-existing-poll)"; logger.debug(findFirstLink(text)); text = "post \"a text with #hashtag);\""; SocialMessageParser messageParser = new SocialMessageParser(text); logger.debug(messageParser.getParsedMessage()); } }